Guest User

Untitled

a guest
Oct 28th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. package greatblitz.testmod.common.container;
  2.  
  3. import greatblitz.testmod.tileentity.TileEntityTestBlock;
  4. import net.minecraft.entity.player.EntityPlayer;
  5. import net.minecraft.entity.player.InventoryPlayer;
  6. import net.minecraft.inventory.Container;
  7. import net.minecraft.inventory.Slot;
  8. import net.minecraft.item.ItemStack;
  9. import net.minecraftforge.items.CapabilityItemHandler;
  10. import net.minecraftforge.items.IItemHandler;
  11. import net.minecraftforge.items.SlotItemHandler;
  12.  
  13. public class ContainerTileEntityTestBlock extends Container{
  14.  
  15. private TileEntityTestBlock te;
  16.  
  17. public ContainerTileEntityTestBlock(InventoryPlayer inv, TileEntityTestBlock te) {
  18. this.te = te;
  19. IItemHandler ish = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
  20.  
  21. this.addSlotToContainer(new SlotItemHandler(ish, 0, 29, 15));
  22. this.addSlotToContainer(new SlotItemHandler(ish, 1, 29, 52));
  23. this.addSlotToContainer(new SlotItemHandler(ish, 2, 129, 37));
  24. bindPlayerInventory(inv);
  25.  
  26. }
  27.  
  28. @Override
  29. public boolean canInteractWith(EntityPlayer playerIn) {
  30. // TODO Auto-generated method stub
  31. return true;
  32. }
  33.  
  34. protected void bindPlayerInventory(InventoryPlayer playerInventory) {
  35. for (int i = 0; i < 3; ++i) {
  36. for (int j = 0; j < 9; ++j) {
  37. this.addSlotToContainer(new Slot(playerInventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
  38. }
  39. }
  40.  
  41. for (int k = 0; k < 9; ++k) {
  42. this.addSlotToContainer(new Slot(playerInventory, k, 8 + k * 18, 142));
  43. }
  44. }
  45.  
  46. @Override
  47. public ItemStack transferStackInSlot(EntityPlayer playerIn, int fromSlot) {
  48. ItemStack previous = null;
  49. Slot slot = (Slot) this.inventorySlots.get(fromSlot);
  50.  
  51. if (slot != null && slot.getHasStack()) {
  52. ItemStack current = slot.getStack();
  53. previous = current.copy();
  54.  
  55. if (fromSlot < 3) {
  56. // From TE Inventory to Player Inventory
  57. if (!this.mergeItemStack(current, 3, 45, true))
  58. return null;
  59. } else {
  60. // From Player Inventory to TE Inventory
  61. if (!this.mergeItemStack(current, 0, 3, false))
  62. return null;
  63. }
  64.  
  65. if (current.stackSize == 0)
  66. slot.putStack((ItemStack) null);
  67. else
  68. slot.onSlotChanged();
  69.  
  70. if (current.stackSize == previous.stackSize)
  71. return null;
  72. slot.onPickupFromSlot(playerIn, current);
  73. }
  74. return previous;
  75. }
  76.  
  77. }
Advertisement
Add Comment
Please, Sign In to add comment