Guest User

Untitled

a guest
Jul 10th, 2016
90
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package ed.enderdeath.mod.AnvilDragon;
  2.  
  3. import com.sun.istack.internal.Nullable;
  4.  
  5. import cpw.mods.fml.common.FMLCommonHandler;
  6. import net.minecraft.entity.player.EntityPlayer;
  7. import net.minecraft.init.Blocks;
  8. import net.minecraft.init.Items;
  9. import net.minecraft.inventory.IInventory;
  10. import net.minecraft.inventory.InventoryCrafting;
  11. import net.minecraft.inventory.Slot;
  12. import net.minecraft.item.Item;
  13. import net.minecraft.item.ItemHoe;
  14. import net.minecraft.item.ItemPickaxe;
  15. import net.minecraft.item.ItemStack;
  16. import net.minecraft.item.ItemSword;
  17. import net.minecraft.stats.AchievementList;
  18. import net.minecraftforge.common.ForgeHooks;
  19. import net.minecraftforge.common.MinecraftForge;
  20. import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
  21.  
  22. public class DragonSlotCrafting extends Slot {
  23. /** The craft matrix inventory linked to this result slot. */
  24. private final InventoryCrafting craftMatrix;
  25. /** The player that is using the GUI where this slot resides. */
  26. private final EntityPlayer thePlayer;
  27. /** The number of items that have been crafted so far. Gets passed to ItemStack.onCrafting before being reset. */
  28. private int amountCrafted;
  29.  
  30. public DragonSlotCrafting(EntityPlayer player, InventoryCrafting craftingInventory, IInventory inventoryIn, int slotIndex, int xPosition, int yPosition)
  31. {
  32. super(inventoryIn, slotIndex, xPosition, yPosition);
  33. this.thePlayer = player;
  34. this.craftMatrix = craftingInventory;
  35.  
  36. }
  37.  
  38. /**
  39. * Check if the stack is a valid item for this slot. Always true beside for the armor slots.
  40. */
  41. @Override
  42. public boolean isItemValid(@Nullable ItemStack stack)
  43. {
  44. return false;
  45. }
  46.  
  47. /**
  48. * Decrease the size of the stack in slot (first int arg) by the amount of the second int arg. Returns the new
  49. * stack.
  50. */
  51. @Override
  52. public ItemStack decrStackSize(int amount)
  53. {
  54. if (this.getHasStack())
  55. {
  56. this.amountCrafted += Math.min(amount, this.getStack().stackSize);
  57. }
  58. return super.decrStackSize(amount);
  59. }
  60.  
  61. /**
  62. * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. Typically increases an
  63. * internal count then calls onCrafting(item).
  64. */
  65. @Override
  66. protected void onCrafting(ItemStack stack, int amount)
  67. {
  68. this.amountCrafted += amount;
  69. this.onCrafting(stack);
  70. }
  71.  
  72. /**
  73. * Appelé quand on craft, permet de gérer les achievements
  74. */
  75. @Override
  76. protected void onCrafting(ItemStack stack)
  77. {
  78. if (this.amountCrafted > 0)
  79. {
  80. stack.onCrafting(this.thePlayer.worldObj, this.thePlayer, this.amountCrafted);
  81. }
  82. this.amountCrafted = 0;
  83.  
  84. if (stack.getItem() == Item.getItemFromBlock(Blocks.bookshelf))
  85. {
  86. this.thePlayer.addStat(AchievementList.bookcase, 1);
  87. }
  88. }
  89.  
  90. /**
  91. * Appelée quand le j
  92. *
  93. * oueur retire l'item du slot, permet de retirer le composants utilisés pour le craft
  94. */
  95.  
  96. public void onPickupFromSlot(EntityPlayer p_82870_1_, ItemStack p_82870_2_)
  97. {
  98. FMLCommonHandler.instance().firePlayerCraftingEvent(p_82870_1_, p_82870_2_, craftMatrix);
  99. this.onCrafting(p_82870_2_);
  100.  
  101. for (int i = 0; i < this.craftMatrix.getSizeInventory(); ++i)
  102. {
  103. ItemStack itemstack1 = this.craftMatrix.getStackInSlot(i);
  104.  
  105. if (itemstack1 != null)
  106. {
  107. this.craftMatrix.decrStackSize(i, 1);
  108.  
  109. if (itemstack1.getItem().hasContainerItem(itemstack1))
  110. {
  111. ItemStack itemstack2 = itemstack1.getItem().getContainerItem(itemstack1);
  112.  
  113. if (itemstack2 != null && itemstack2.isItemStackDamageable() && itemstack2.getItemDamage() > itemstack2.getMaxDamage())
  114. {
  115. MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(thePlayer, itemstack2));
  116. continue;
  117. }
  118.  
  119. if (!itemstack1.getItem().doesContainerItemLeaveCraftingGrid(itemstack1) || !this.thePlayer.inventory.addItemStackToInventory(itemstack2))
  120. {
  121. if (this.craftMatrix.getStackInSlot(i) == null)
  122. {
  123. this.craftMatrix.setInventorySlotContents(i, itemstack2);
  124. }
  125. else
  126. {
  127. this.thePlayer.dropPlayerItemWithRandomChoice(itemstack2, false);
  128. }
  129. }
  130. }
  131. }
  132. }
  133.  
  134. }
  135.  
  136. }
RAW Paste Data