Advertisement
Guest User

Untitled

a guest
Jul 5th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.78 KB | None | 0 0
  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. * Check if the stack is a valid item for this slot. Always true beside for the armor slots.
  39. */
  40. @Override
  41. public boolean isItemValid(@Nullable ItemStack stack)
  42. {
  43. return false;
  44. }
  45.  
  46. /**
  47. * Decrease the size of the stack in slot (first int arg) by the amount of the second int arg. Returns the new
  48. * stack.
  49. */
  50. @Override
  51. public ItemStack decrStackSize(int amount)
  52. {
  53. if (this.getHasStack())
  54. {
  55. this.amountCrafted += Math.min(amount, this.getStack().stackSize);
  56. }
  57. return super.decrStackSize(amount);
  58. }
  59.  
  60. /**
  61. * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. Typically increases an
  62. * internal count then calls onCrafting(item).
  63. */
  64. @Override
  65. protected void onCrafting(ItemStack stack, int amount)
  66. {
  67. this.amountCrafted += amount;
  68. this.onCrafting(stack);
  69. }
  70.  
  71. /**
  72. * Appelé quand on craft, permet de gérer les achievements
  73. */
  74. @Override
  75. protected void onCrafting(ItemStack stack)
  76. {
  77. if (this.amountCrafted > 0)
  78. {
  79. stack.onCrafting(this.thePlayer.worldObj, this.thePlayer, this.amountCrafted);
  80. }
  81. this.amountCrafted = 0;
  82.  
  83. if (stack.getItem() == Item.getItemFromBlock(Blocks.bookshelf))
  84. {
  85. this.thePlayer.addStat(AchievementList.bookcase, 1);
  86. }
  87. }
  88.  
  89. /**
  90. * Appelée quand le j
  91. *
  92. * oueur retire l'item du slot, permet de retirer le composants utilisés pour le craft
  93. */
  94.  
  95. public void onPickupFromSlot(EntityPlayer p_82870_1_, ItemStack p_82870_2_)
  96. {
  97. FMLCommonHandler.instance().firePlayerCraftingEvent(p_82870_1_, p_82870_2_, craftMatrix);
  98. this.onCrafting(p_82870_2_);
  99.  
  100. for (int i = 0; i < this.craftMatrix.getSizeInventory(); ++i)
  101. {
  102. ItemStack itemstack1 = this.craftMatrix.getStackInSlot(i);
  103.  
  104. if (itemstack1 != null)
  105. {
  106. this.craftMatrix.decrStackSize(i, 1);
  107.  
  108. if (itemstack1.getItem().hasContainerItem(itemstack1))
  109. {
  110. ItemStack itemstack2 = itemstack1.getItem().getContainerItem(itemstack1);
  111.  
  112. if (itemstack2 != null && itemstack2.isItemStackDamageable() && itemstack2.getItemDamage() > itemstack2.getMaxDamage())
  113. {
  114. MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(thePlayer, itemstack2));
  115. continue;
  116. }
  117.  
  118. if (!itemstack1.getItem().doesContainerItemLeaveCraftingGrid(itemstack1) || !this.thePlayer.inventory.addItemStackToInventory(itemstack2))
  119. {
  120. if (this.craftMatrix.getStackInSlot(i) == null)
  121. {
  122. this.craftMatrix.setInventorySlotContents(i, itemstack2);
  123. }
  124. else
  125. {
  126. this.thePlayer.dropPlayerItemWithRandomChoice(itemstack2, false);
  127. }
  128. }
  129. }
  130. }
  131. }
  132.  
  133. }
  134.  
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement