Guest User

Untitled

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