| 1 | package net.minecraft.inventory;
|
| 2 |
|
| 3 | import net.minecraft.entity.player.EntityPlayer;
|
| 4 | import net.minecraft.init.Items;
|
| 5 | import net.minecraft.item.ItemStack;
|
| 6 |
|
| 7 | public class ContainerBeacon extends Container
|
| 8 | {
|
| 9 | private IInventory tileBeacon;
|
| 10 |
|
| 11 | /**
|
| 12 | * This beacon's slot where you put in Emerald, Diamond, Gold or Iron Ingot.
|
| 13 | */
|
| 14 | private final ContainerBeacon.BeaconSlot beaconSlot;
|
| 15 |
|
| 16 | public ContainerBeacon(IInventory playerInventory, IInventory tileBeaconIn)
|
| 17 | {
|
| 18 | this.tileBeacon = tileBeaconIn;
|
| 19 | this.addSlotToContainer(this.beaconSlot = new ContainerBeacon.BeaconSlot(tileBeaconIn, 0, 136, 110));
|
| 20 | int i = 36;
|
| 21 | int j = 137;
|
| 22 |
|
| 23 | for (int k = 0; k < 3; ++k)
|
| 24 | {
|
| 25 | for (int l = 0; l < 9; ++l)
|
| 26 | {
|
| 27 | this.addSlotToContainer(new Slot(playerInventory, l + k * 9 + 9, i + l * 18, j + k * 18));
|
| 28 | }
|
| 29 | }
|
| 30 |
|
| 31 | for (int i1 = 0; i1 < 9; ++i1)
|
| 32 | {
|
| 33 | this.addSlotToContainer(new Slot(playerInventory, i1, i + i1 * 18, 58 + j));
|
| 34 | }
|
| 35 | }
|
| 36 |
|
| 37 | public void onCraftGuiOpened(ICrafting listener)
|
| 38 | {
|
| 39 | super.onCraftGuiOpened(listener);
|
| 40 | listener.sendAllWindowProperties(this, this.tileBeacon);
|
| 41 | }
|
| 42 |
|
| 43 | public void updateProgressBar(int id, int data)
|
| 44 | {
|
| 45 | this.tileBeacon.setField(id, data);
|
| 46 | }
|
| 47 |
|
| 48 | public IInventory func_180611_e()
|
| 49 | {
|
| 50 | return this.tileBeacon;
|
| 51 | }
|
| 52 |
|
| 53 | /**
|
| 54 | * Called when the container is closed.
|
| 55 | */
|
| 56 | public void onContainerClosed(EntityPlayer playerIn)
|
| 57 | {
|
| 58 | super.onContainerClosed(playerIn);
|
| 59 |
|
| 60 | if (playerIn != null && !playerIn.worldObj.isRemote)
|
| 61 | {
|
| 62 | ItemStack itemstack = this.beaconSlot.decrStackSize(this.beaconSlot.getSlotStackLimit());
|
| 63 |
|
| 64 | if (itemstack != null)
|
| 65 | {
|
| 66 | playerIn.dropPlayerItemWithRandomChoice(itemstack, false);
|
| 67 | }
|
| 68 | }
|
| 69 | }
|
| 70 |
|
| 71 | public boolean canInteractWith(EntityPlayer playerIn)
|
| 72 | {
|
| 73 | return this.tileBeacon.isUseableByPlayer(playerIn);
|
| 74 | }
|
| 75 |
|
| 76 | /**
|
| 77 | * Take a stack from the specified inventory slot.
|
| 78 | */
|
| 79 | public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
|
| 80 | {
|
| 81 | ItemStack itemstack = null;
|
| 82 | Slot slot = (Slot)this.inventorySlots.get(index);
|
| 83 |
|
| 84 | if (slot != null && slot.getHasStack())
|
| 85 | {
|
| 86 | ItemStack itemstack1 = slot.getStack();
|
| 87 | itemstack = itemstack1.copy();
|
| 88 |
|
| 89 | if (index == 0)
|
| 90 | {
|
| 91 | if (!this.mergeItemStack(itemstack1, 1, 37, true))
|
| 92 | {
|
| 93 | return null;
|
| 94 | }
|
| 95 |
|
| 96 | slot.onSlotChange(itemstack1, itemstack);
|
| 97 | }
|
| 98 | else if (!this.beaconSlot.getHasStack() && this.beaconSlot.isItemValid(itemstack1) && itemstack1.stackSize == 1)
|
| 99 | {
|
| 100 | if (!this.mergeItemStack(itemstack1, 0, 1, false))
|
| 101 | {
|
| 102 | return null;
|
| 103 | }
|
| 104 | }
|
| 105 | else if (index >= 1 && index < 28)
|
| 106 | {
|
| 107 | if (!this.mergeItemStack(itemstack1, 28, 37, false))
|
| 108 | {
|
| 109 | return null;
|
| 110 | }
|
| 111 | }
|
| 112 | else if (index >= 28 && index < 37)
|
| 113 | {
|
| 114 | if (!this.mergeItemStack(itemstack1, 1, 28, false))
|
| 115 | {
|
| 116 | return null;
|
| 117 | }
|
| 118 | }
|
| 119 | else if (!this.mergeItemStack(itemstack1, 1, 37, false))
|
| 120 | {
|
| 121 | return null;
|
| 122 | }
|
| 123 |
|
| 124 | if (itemstack1.stackSize == 0)
|
| 125 | {
|
| 126 | slot.putStack((ItemStack)null);
|
| 127 | }
|
| 128 | else
|
| 129 | {
|
| 130 | slot.onSlotChanged();
|
| 131 | }
|
| 132 |
|
| 133 | if (itemstack1.stackSize == itemstack.stackSize)
|
| 134 | {
|
| 135 | return null;
|
| 136 | }
|
| 137 |
|
| 138 | slot.onPickupFromSlot(playerIn, itemstack1);
|
| 139 | }
|
| 140 |
|
| 141 | return itemstack;
|
| 142 | }
|
| 143 |
|
| 144 | class BeaconSlot extends Slot
|
| 145 | {
|
| 146 | public BeaconSlot(IInventory p_i1801_2_, int p_i1801_3_, int p_i1801_4_, int p_i1801_5_)
|
| 147 | {
|
| 148 | super(p_i1801_2_, p_i1801_3_, p_i1801_4_, p_i1801_5_);
|
| 149 | }
|
| 150 |
|
| 151 | public boolean isItemValid(ItemStack stack)
|
| 152 | {
|
| 153 | return stack == null ? false : stack.getItem() == Items.emerald || stack.getItem() == Items.diamond || stack.getItem() == Items.gold_ingot || stack.getItem() == Items.iron_ingot;
|
| 154 | }
|
| 155 |
|
| 156 | public int getSlotStackLimit()
|
| 157 | {
|
| 158 | return 1;
|
| 159 | }
|
| 160 | }
|
| 161 | }
|
| 162 |
|