Advertisement
Guest User

Container Carpenter Bench

a guest
Aug 24th, 2014
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. package minefantasy.mf2.block.crafting;
  2.  
  3. import minefantasy.mf2.block.tileentity.TileEntityCarpenter;
  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.  
  10.  
  11. public class ContainerCarpenterBench extends Container {
  12.  
  13. protected TileEntityCarpenter tec;
  14. protected int PLAYER_INVENTORY_ROWS = 3;
  15. protected int PLAYER_INVENTORY_COLUMNS = 9;
  16.  
  17. public ContainerCarpenterBench(TileEntityCarpenter te,
  18. InventoryPlayer player_inventory) {
  19.  
  20. this.tec = te;
  21. addSlots(player_inventory);
  22.  
  23. }
  24.  
  25. @Override
  26. public boolean canInteractWith(EntityPlayer player) {
  27. return tec.isUseableByPlayer(player);
  28. }
  29.  
  30. protected void addSlots(InventoryPlayer player_inventory) {
  31.  
  32. this.addSlotToContainer(new Slot(tec, 0, 10, 23));
  33.  
  34. int x = 0;
  35. // Add the player's inventory slots to the container
  36.  
  37.  
  38. //Slots 9-35
  39. for (int inventoryRowIndex = 0; inventoryRowIndex < PLAYER_INVENTORY_ROWS; ++inventoryRowIndex) {
  40. for (int inventoryColumnIndex = 0; inventoryColumnIndex < PLAYER_INVENTORY_COLUMNS; ++inventoryColumnIndex) {
  41. x++;
  42. System.out.println(x + ": " + (int)(inventoryColumnIndex + inventoryRowIndex * 9 + 9));
  43. this.addSlotToContainer(new Slot(player_inventory,
  44. inventoryColumnIndex + inventoryRowIndex * 9 + 9,
  45. 7 + inventoryColumnIndex * 18,
  46. 83 + inventoryRowIndex * 18));
  47. }
  48. }
  49.  
  50. //slots 0-8
  51. // Add the player's action bar slots to the container
  52. for (int actionBarSlotIndex = 0; actionBarSlotIndex < PLAYER_INVENTORY_COLUMNS; ++actionBarSlotIndex) {
  53. this.addSlotToContainer(new Slot(player_inventory,
  54. actionBarSlotIndex, 7 + actionBarSlotIndex * 18, 177));
  55. }
  56. }
  57. @Override
  58. public ItemStack transferStackInSlot(EntityPlayer player, int sn)
  59. {
  60. ItemStack itemstack = null;
  61. Slot slot = (Slot)this.inventorySlots.get(sn);
  62.  
  63. if (slot != null && slot.getHasStack())
  64. {
  65. ItemStack itemstack1 = slot.getStack();
  66. itemstack = itemstack1.copy();
  67.  
  68. if (sn < 9)
  69. {
  70. if (!this.mergeItemStack(itemstack1, 9, 36, true))
  71. {
  72. return null;
  73. }
  74. }
  75. else if (!this.mergeItemStack(itemstack1, 0, 9, false))
  76. {
  77. return null;
  78. }
  79.  
  80. if (itemstack1.stackSize == 0)
  81. {
  82. slot.putStack((ItemStack)null);
  83. }
  84. else
  85. {
  86. slot.onSlotChanged();
  87. }
  88. }
  89.  
  90. return itemstack;
  91. }
  92.  
  93.  
  94.  
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement