Guest User

Untitled

a guest
Mar 1st, 2017
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.19 KB | None | 0 0
  1. public class SlotAssemblyTable extends Slot {
  2.  
  3.  
  4. private final InventoryCrafting craftMatrix;
  5. /** The player that is using the GUI where this slot resides. */
  6. private final EntityPlayer player;
  7. /** The number of items that have been crafted so far. Gets passed to ItemStack.onCrafting before being reset. */
  8. private int amountCrafted;
  9.  
  10. public SlotAssemblyTable(EntityPlayer par1EntityPlayer, InventoryCrafting par2IInventory, IInventory par3IInventory, int par4, int par5, int par6)
  11. {
  12. super(par3IInventory, par4, par5, par6);
  13. this.player = par1EntityPlayer;
  14. this.craftMatrix = par2IInventory;
  15. }
  16.  
  17. @Override
  18. public boolean isItemValid(ItemStack par1ItemStack)
  19. {
  20. return false;
  21. }
  22.  
  23. @Override
  24. public ItemStack decrStackSize(int par1)
  25. {
  26. if (this.getHasStack())
  27. {
  28. this.amountCrafted += Math.min(par1, this.getStack().getCount());
  29. }
  30. return super.decrStackSize(par1);
  31. }
  32.  
  33. @Override
  34. protected void onCrafting(ItemStack par1ItemStack, int par2)
  35. {
  36. this.amountCrafted += par2;
  37. this.onCrafting(par1ItemStack);
  38. }
  39.  
  40. @Override
  41. protected void onSwapCraft(int p_190900_1_)
  42. {
  43. this.amountCrafted += p_190900_1_;
  44. }
  45.  
  46. /**
  47. * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood.
  48. */
  49. @Override
  50. protected void onCrafting(ItemStack stack)
  51. {
  52. if (this.amountCrafted > 0)
  53. {
  54. stack.onCrafting(this.player.world, this.player, this.amountCrafted);
  55. net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerCraftingEvent(this.player, stack, craftMatrix);
  56. }
  57. this.amountCrafted = 0;
  58. }
  59.  
  60. @Override
  61. public ItemStack onTake(EntityPlayer thePlayer, ItemStack stack)
  62. {
  63. this.onCrafting(stack);
  64. net.minecraftforge.common.ForgeHooks.setCraftingPlayer(thePlayer);
  65. NonNullList<ItemStack> nonnulllist = CraftingManager.getInstance().getRemainingItems(this.craftMatrix, thePlayer.world);
  66. net.minecraftforge.common.ForgeHooks.setCraftingPlayer(null);
  67.  
  68. for (int i = 0; i < nonnulllist.size(); ++i)
  69. {
  70. ItemStack itemstack = this.craftMatrix.getStackInSlot(i);
  71. ItemStack itemstack1 = (ItemStack)nonnulllist.get(i);
  72.  
  73. if (!itemstack.isEmpty())
  74. {
  75. this.craftMatrix.decrStackSize(i, 1);
  76. itemstack = this.craftMatrix.getStackInSlot(i);
  77. }
  78.  
  79. if (!itemstack1.isEmpty())
  80. {
  81. if (itemstack.isEmpty())
  82. {
  83. this.craftMatrix.setInventorySlotContents(i, itemstack1);
  84. }
  85. else if (ItemStack.areItemsEqual(itemstack, itemstack1) && ItemStack.areItemStackTagsEqual(itemstack, itemstack1))
  86. {
  87. itemstack1.grow(itemstack.getCount());
  88. this.craftMatrix.setInventorySlotContents(i, itemstack1);
  89. }
  90. else if (!this.player.inventory.addItemStackToInventory(itemstack1))
  91. {
  92. this.player.dropItem(itemstack1, false);
  93. }
  94. }
  95. }
  96.  
  97. return stack;
  98. }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment