Advertisement
Guest User

Untitled

a guest
Jan 5th, 2014
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. package RUMatter.containers;
  2.  
  3. import net.minecraft.client.Minecraft;
  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 RUMatter.tileEntities.TileEntityRUChest;
  10.  
  11. public class ContainerRUChest extends Container {
  12.  
  13. TileEntityRUChest tile;
  14.  
  15. public ContainerRUChest(InventoryPlayer inv, TileEntityRUChest tile) {
  16. this.tile = tile;
  17.  
  18. for (int i = 0; i < 3; i++) {
  19. for (int j = 0; j < 3; j++) {
  20. addSlotToContainer(new Slot(tile, j + i * 3, 62 + j * 18, 17 + i * 18));
  21. }
  22. }
  23.  
  24. bindPlayerInventory(inv);
  25. }
  26.  
  27. @Override
  28. public boolean canInteractWith(EntityPlayer entityplayer) {
  29. return tile.isUseableByPlayer(entityplayer);
  30. }
  31.  
  32. protected void bindPlayerInventory(InventoryPlayer inventoryPlayer) {
  33. for (int i = 0; i < 3; i++) {
  34. for (int j = 0; j < 9; j++) {
  35. addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
  36. }
  37. }
  38.  
  39. for (int i = 0; i < 9; i++) {
  40. addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 142));
  41. }
  42. }
  43.  
  44. @Override
  45. public ItemStack transferStackInSlot(EntityPlayer player, int slot) {
  46. ItemStack stack = null;
  47. Slot slotObject = (Slot) inventorySlots.get(slot);
  48.  
  49. //null checks and checks if the item can be stacked (maxStackSize > 1)
  50. if (slotObject != null && slotObject.getHasStack()) {
  51. ItemStack stackInSlot = slotObject.getStack();
  52. stack = stackInSlot.copy();
  53.  
  54. //merges the item into player inventory since its in the tileEntity
  55. if (slot < 9) {
  56. if (!this.mergeItemStack(stackInSlot, 0, 35, true)) {
  57. return null;
  58. }
  59. }
  60. //places it into the tileEntity is possible since its in the player inventory
  61. else if (!this.mergeItemStack(stackInSlot, 0, 9, false)) {
  62. return null;
  63. }
  64.  
  65. if (stackInSlot.stackSize == 0) {
  66. slotObject.putStack(null);
  67. } else {
  68. slotObject.onSlotChanged();
  69. }
  70.  
  71. if (stackInSlot.stackSize == stack.stackSize) {
  72. return null;
  73. }
  74. slotObject.onPickupFromSlot(player, stackInSlot);
  75. }
  76. return stack;
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement