package net.minecraft.server; import java.util.Random; // CraftBukkit start import java.util.List; import org.bukkit.craftbukkit.entity.CraftHumanEntity; import org.bukkit.entity.HumanEntity; // CraftBukkit end public class TileEntityDispenser extends TileEntityLootable { private static final Random a = new Random(); private NonNullList<ItemStack> items; // CraftBukkit start - add fields and methods public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>(); private int maxStack = MAX_STACK; public List<ItemStack> getContents() { return this.items; } public void onOpen(CraftHumanEntity who) { transaction.add(who); } public void onClose(CraftHumanEntity who) { transaction.remove(who); } public List<HumanEntity> getViewers() { return transaction; } @Override public int getMaxStackSize() { return maxStack; } public void setMaxStackSize(int size) { maxStack = size; } // CraftBukkit end protected TileEntityDispenser(TileEntityTypes<?> tileentitytypes) { super(tileentitytypes); this.items = NonNullList.a(9, ItemStack.a); } public TileEntityDispenser() { this(TileEntityTypes.DISPENSER); } @Override public int getSize() { return 9; } public int h() { this.d((EntityHuman) null); int i = -1; int j = 1; for (int k = 0; k < this.items.size(); ++k) { if (!((ItemStack) this.items.get(k)).isEmpty() && TileEntityDispenser.a.nextInt(j++) == 0) { i = k; } } return i; } public int addItem(ItemStack itemstack) { for (int i = 0; i < this.items.size(); ++i) { if (((ItemStack) this.items.get(i)).isEmpty()) { this.setItem(i, itemstack); return i; } } return -1; } @Override protected IChatBaseComponent getContainerName() { return new ChatMessage("container.dispenser", new Object[0]); } @Override public void load(NBTTagCompound nbttagcompound) { super.load(nbttagcompound); this.items = NonNullList.a(this.getSize(), ItemStack.a); if (!this.d(nbttagcompound)) { ContainerUtil.b(nbttagcompound, this.items); } } @Override public NBTTagCompound save(NBTTagCompound nbttagcompound) { super.save(nbttagcompound); if (!this.e(nbttagcompound)) { ContainerUtil.a(nbttagcompound, this.items); } return nbttagcompound; } @Override protected NonNullList<ItemStack> f() { return this.items; } @Override protected void a(NonNullList<ItemStack> nonnulllist) { this.items = nonnulllist; } @Override protected Container createContainer(int i, PlayerInventory playerinventory) { return new ContainerDispenser(i, playerinventory, this); } }