ItemStackBuilder.java 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package me.km.api;
  2. import net.minecraft.block.Block;
  3. import net.minecraft.item.Item;
  4. import net.minecraft.item.ItemStack;
  5. import net.minecraft.util.math.BlockPos;
  6. import net.minecraft.world.World;
  7. public class ItemStackBuilder
  8. {
  9. private final ItemStack stack;
  10. public ItemStackBuilder(Block b, int amount)
  11. {
  12. stack = new ItemStack(b, amount);
  13. }
  14. public ItemStackBuilder(Block b, int amount, int meta)
  15. {
  16. stack = new ItemStack(b, amount, meta);
  17. }
  18. public ItemStackBuilder(Item i, int amount)
  19. {
  20. stack = new ItemStack(i, amount);
  21. }
  22. public ItemStackBuilder(Item i, int amount, int meta)
  23. {
  24. stack = new ItemStack(i, amount, meta);
  25. }
  26. public ItemStackBuilder(ItemStack stack, int amount)
  27. {
  28. this.stack = stack.copy();
  29. this.stack.setCount(amount);
  30. }
  31. public ItemStack build()
  32. {
  33. return stack;
  34. }
  35. public void drop(World w, BlockPos l)
  36. {
  37. Block.spawnAsEntity(w, l, stack);
  38. }
  39. public ItemStackBuilder setName(String name)
  40. {
  41. stack.setStackDisplayName(name);
  42. return this;
  43. }
  44. public ItemStackBuilder addToName(String name)
  45. {
  46. stack.setStackDisplayName(stack.getDisplayName() + name);
  47. return this;
  48. }
  49. public ItemStackBuilder addLore(String line)
  50. {
  51. //TODO
  52. return this;
  53. }
  54. public ItemStackBuilder addLimitedLore(String whole, int limit, String addition)
  55. {
  56. //TODO
  57. /*ItemMeta meta = stack.getItemMeta();
  58. meta.setLore(Utils.buildLimitedLore(whole, limit, addition));
  59. stack.setItemMeta(meta);*/
  60. return this;
  61. }
  62. public ItemStackBuilder addLimitedLore(String whole, String addition)
  63. {
  64. return addLimitedLore(whole, 25, addition);
  65. }
  66. public ItemStackBuilder hideTags()
  67. {
  68. //TODO
  69. /*stack.setTagCompound(nbt);
  70. ItemMeta meta = stack.getItemMeta();
  71. meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
  72. meta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS);
  73. meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
  74. stack.setItemMeta(meta);*/
  75. return this;
  76. }
  77. public ItemStackBuilder addGlow()
  78. {
  79. //TODO
  80. //stack.addUnsafeEnchantment(Enchantment.LUCK, 1);
  81. return this;
  82. }
  83. }