13
0
geforkt von Mirrors/Paper
Paper/src/main/java/net/minecraft/server/TileEntityDispenser.java

169 Zeilen
4.3 KiB
Java

2011-02-23 03:37:56 +01:00
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
2011-02-23 03:37:56 +01:00
public class TileEntityDispenser extends TileEntity implements IInventory {
private ItemStack[] items = new ItemStack[9];
2011-02-23 03:37:56 +01:00
private Random b = new Random();
// CraftBukkit start
public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
private int maxStack = MAX_STACK;
2011-02-23 03:37:56 +01:00
public ItemStack[] getContents() {
return this.items;
2011-02-23 03:37:56 +01:00
}
public void onOpen(CraftHumanEntity who) {
transaction.add(who);
}
public void onClose(CraftHumanEntity who) {
transaction.remove(who);
}
public List<HumanEntity> getViewers() {
return transaction;
}
public void setMaxStackSize(int size) {
maxStack = size;
}
2011-02-23 03:37:56 +01:00
// CraftBukkit end
public TileEntityDispenser() {}
public int getSize() {
2011-02-23 03:37:56 +01:00
return 9;
}
public ItemStack getItem(int i) {
return this.items[i];
2011-02-23 03:37:56 +01:00
}
public ItemStack splitStack(int i, int j) {
if (this.items[i] != null) {
2011-02-23 03:37:56 +01:00
ItemStack itemstack;
if (this.items[i].count <= j) {
itemstack = this.items[i];
this.items[i] = null;
this.update();
2011-02-23 03:37:56 +01:00
return itemstack;
} else {
itemstack = this.items[i].a(j);
if (this.items[i].count == 0) {
this.items[i] = null;
2011-02-23 03:37:56 +01:00
}
this.update();
2011-02-23 03:37:56 +01:00
return itemstack;
}
} else {
return null;
}
}
2012-03-01 11:49:23 +01:00
public ItemStack splitWithoutUpdate(int i) {
if (this.items[i] != null) {
ItemStack itemstack = this.items[i];
this.items[i] = null;
return itemstack;
} else {
return null;
}
}
2012-07-29 09:33:13 +02:00
public int i() {
2011-02-23 03:37:56 +01:00
int i = -1;
int j = 1;
for (int k = 0; k < this.items.length; ++k) {
2011-05-26 14:48:22 +02:00
if (this.items[k] != null && this.b.nextInt(j++) == 0) {
if (this.items[k].count == 0) continue; // CraftBukkit
2011-02-23 03:37:56 +01:00
i = k;
}
}
2011-05-08 11:56:40 +02:00
2012-07-29 09:33:13 +02:00
return i;
2011-02-23 03:37:56 +01:00
}
public void setItem(int i, ItemStack itemstack) {
this.items[i] = itemstack;
if (itemstack != null && itemstack.count > this.getMaxStackSize()) {
itemstack.count = this.getMaxStackSize();
2011-02-23 03:37:56 +01:00
}
this.update();
2011-02-23 03:37:56 +01:00
}
2012-07-29 09:33:13 +02:00
public int a(ItemStack itemstack) {
for (int i = 0; i < this.items.length; ++i) {
if (this.items[i] == null || this.items[i].id == 0) {
this.items[i] = itemstack;
return i;
}
}
return -1;
}
public String getName() {
2012-03-01 11:49:23 +01:00
return "container.dispenser";
2011-02-23 03:37:56 +01:00
}
public void a(NBTTagCompound nbttagcompound) {
super.a(nbttagcompound);
NBTTagList nbttaglist = nbttagcompound.getList("Items");
2011-02-23 03:37:56 +01:00
this.items = new ItemStack[this.getSize()];
2011-02-23 03:37:56 +01:00
for (int i = 0; i < nbttaglist.size(); ++i) {
NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.get(i);
int j = nbttagcompound1.getByte("Slot") & 255;
2011-02-23 03:37:56 +01:00
if (j >= 0 && j < this.items.length) {
2011-09-15 02:23:52 +02:00
this.items[j] = ItemStack.a(nbttagcompound1);
2011-02-23 03:37:56 +01:00
}
}
}
public void b(NBTTagCompound nbttagcompound) {
super.b(nbttagcompound);
NBTTagList nbttaglist = new NBTTagList();
for (int i = 0; i < this.items.length; ++i) {
if (this.items[i] != null) {
2011-02-23 03:37:56 +01:00
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
nbttagcompound1.setByte("Slot", (byte) i);
2012-02-29 22:31:04 +01:00
this.items[i].save(nbttagcompound1);
nbttaglist.add(nbttagcompound1);
2011-02-23 03:37:56 +01:00
}
}
nbttagcompound.set("Items", nbttaglist);
2011-02-23 03:37:56 +01:00
}
public int getMaxStackSize() {
return maxStack; // CraftBukkit
2011-02-23 03:37:56 +01:00
}
2011-09-15 02:23:52 +02:00
public boolean a(EntityHuman entityhuman) {
2011-07-08 14:25:53 +02:00
return this.world.getTileEntity(this.x, this.y, this.z) != this ? false : entityhuman.e((double) this.x + 0.5D, (double) this.y + 0.5D, (double) this.z + 0.5D) <= 64.0D;
2011-02-23 03:37:56 +01:00
}
2011-09-15 02:23:52 +02:00
2012-07-29 09:33:13 +02:00
public void startOpen() {}
2011-09-15 02:23:52 +02:00
2012-07-29 09:33:13 +02:00
public void f() {}
2011-02-23 03:37:56 +01:00
}