2012-01-17 17:08:54 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
2012-02-29 19:56:35 +01:00
|
|
|
// CraftBukkit start
|
|
|
|
import org.bukkit.craftbukkit.entity.CraftHumanEntity;
|
|
|
|
import org.bukkit.entity.HumanEntity;
|
|
|
|
import org.bukkit.event.inventory.BrewEvent;
|
|
|
|
// CraftBukkit end
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
public class TileEntityBrewingStand extends TileEntity implements IWorldInventory {
|
2012-01-17 17:08:54 +01:00
|
|
|
|
2013-03-20 21:09:23 +01:00
|
|
|
private static final int[] a = new int[] { 3};
|
|
|
|
private static final int[] b = new int[] { 0, 1, 2};
|
|
|
|
public ItemStack[] items = new ItemStack[4]; // CraftBukkit - private -> public
|
|
|
|
public int brewTime; // CraftBukkit - private -> public
|
|
|
|
private int e;
|
|
|
|
private int f;
|
|
|
|
private String g;
|
2013-04-12 01:28:15 +02:00
|
|
|
private int lastTick = MinecraftServer.currentTick; // CraftBukkit
|
2012-01-17 17:08:54 +01:00
|
|
|
|
|
|
|
public TileEntityBrewingStand() {}
|
|
|
|
|
|
|
|
// CraftBukkit start
|
2012-07-22 08:18:00 +02:00
|
|
|
public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
|
2013-03-13 23:33:27 +01:00
|
|
|
private int maxStack = 64;
|
2012-02-29 19:56:35 +01:00
|
|
|
|
|
|
|
public void onOpen(CraftHumanEntity who) {
|
|
|
|
transaction.add(who);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onClose(CraftHumanEntity who) {
|
|
|
|
transaction.remove(who);
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<HumanEntity> getViewers() {
|
|
|
|
return transaction;
|
|
|
|
}
|
|
|
|
|
2012-01-17 17:08:54 +01:00
|
|
|
public ItemStack[] getContents() {
|
2012-02-29 22:31:04 +01:00
|
|
|
return this.items;
|
2012-01-17 17:08:54 +01:00
|
|
|
}
|
2012-03-14 15:00:54 +01:00
|
|
|
|
|
|
|
public void setMaxStackSize(int size) {
|
|
|
|
maxStack = size;
|
|
|
|
}
|
2012-01-17 17:08:54 +01:00
|
|
|
// CraftBukkit end
|
|
|
|
|
|
|
|
public String getName() {
|
2013-03-20 21:09:23 +01:00
|
|
|
return this.c() ? this.g : "container.brewing";
|
2013-03-13 23:33:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean c() {
|
2013-03-20 21:09:23 +01:00
|
|
|
return this.g != null && this.g.length() > 0;
|
2013-03-13 23:33:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void a(String s) {
|
2013-03-20 21:09:23 +01:00
|
|
|
this.g = s;
|
2012-01-17 17:08:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getSize() {
|
2012-02-29 22:31:04 +01:00
|
|
|
return this.items.length;
|
2012-01-17 17:08:54 +01:00
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
public void h() {
|
2013-04-12 01:28:15 +02:00
|
|
|
// CraftBukkit start - Use wall time instead of ticks for brewing
|
|
|
|
int elapsedTicks = Math.max(1, MinecraftServer.currentTick - this.lastTick);
|
|
|
|
this.lastTick = MinecraftServer.currentTick;
|
|
|
|
|
2012-02-29 22:31:04 +01:00
|
|
|
if (this.brewTime > 0) {
|
2013-04-12 01:28:15 +02:00
|
|
|
this.brewTime -= elapsedTicks;
|
|
|
|
if (this.brewTime <= 0) { // == -> <=
|
|
|
|
// CraftBukkit end
|
2012-11-06 13:05:28 +01:00
|
|
|
this.u();
|
2012-01-17 17:08:54 +01:00
|
|
|
this.update();
|
2013-03-13 23:33:27 +01:00
|
|
|
} else if (!this.l()) {
|
2012-02-29 22:31:04 +01:00
|
|
|
this.brewTime = 0;
|
2012-01-17 17:08:54 +01:00
|
|
|
this.update();
|
2013-03-20 21:09:23 +01:00
|
|
|
} else if (this.f != this.items[3].id) {
|
2012-02-29 22:31:04 +01:00
|
|
|
this.brewTime = 0;
|
2012-01-17 17:08:54 +01:00
|
|
|
this.update();
|
|
|
|
}
|
2013-03-13 23:33:27 +01:00
|
|
|
} else if (this.l()) {
|
2012-02-29 22:31:04 +01:00
|
|
|
this.brewTime = 400;
|
2013-03-20 21:09:23 +01:00
|
|
|
this.f = this.items[3].id;
|
2012-01-17 17:08:54 +01:00
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
int i = this.j();
|
2012-01-17 17:08:54 +01:00
|
|
|
|
2013-03-20 21:09:23 +01:00
|
|
|
if (i != this.e) {
|
|
|
|
this.e = i;
|
2013-03-13 23:33:27 +01:00
|
|
|
this.world.setData(this.x, this.y, this.z, i, 2);
|
2012-01-17 17:08:54 +01:00
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
super.h();
|
2012-01-17 17:08:54 +01:00
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
public int x_() {
|
2012-02-29 22:31:04 +01:00
|
|
|
return this.brewTime;
|
2012-01-17 17:08:54 +01:00
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
private boolean l() {
|
2012-02-29 22:31:04 +01:00
|
|
|
if (this.items[3] != null && this.items[3].count > 0) {
|
|
|
|
ItemStack itemstack = this.items[3];
|
2012-01-17 17:08:54 +01:00
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
if (!Item.byId[itemstack.id].w()) {
|
2012-01-17 17:08:54 +01:00
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
boolean flag = false;
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; ++i) {
|
2012-02-29 22:31:04 +01:00
|
|
|
if (this.items[i] != null && this.items[i].id == Item.POTION.id) {
|
|
|
|
int j = this.items[i].getData();
|
2013-03-13 23:33:27 +01:00
|
|
|
int k = this.c(j, itemstack);
|
2012-01-17 17:08:54 +01:00
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
if (!ItemPotion.f(j) && ItemPotion.f(k)) {
|
2012-01-17 17:08:54 +01:00
|
|
|
flag = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
List list = Item.POTION.c(j);
|
|
|
|
List list1 = Item.POTION.c(k);
|
2012-01-17 17:08:54 +01:00
|
|
|
|
|
|
|
if ((j <= 0 || list != list1) && (list == null || !list.equals(list1) && list1 != null) && j != k) {
|
|
|
|
flag = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return flag;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-06 13:05:28 +01:00
|
|
|
private void u() {
|
2013-03-13 23:33:27 +01:00
|
|
|
if (this.l()) {
|
2012-02-29 22:31:04 +01:00
|
|
|
ItemStack itemstack = this.items[3];
|
2012-01-17 17:08:54 +01:00
|
|
|
|
2013-03-25 05:22:32 +01:00
|
|
|
// CraftBukkit start
|
2012-04-25 23:37:17 +02:00
|
|
|
if (getOwner() != null) {
|
2012-07-22 08:18:00 +02:00
|
|
|
BrewEvent event = new BrewEvent(world.getWorld().getBlockAt(x, y, z), (org.bukkit.inventory.BrewerInventory) this.getOwner().getInventory());
|
|
|
|
org.bukkit.Bukkit.getPluginManager().callEvent(event);
|
2013-03-25 05:22:32 +01:00
|
|
|
if (event.isCancelled()) {
|
2012-04-25 23:37:17 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-02-29 19:56:35 +01:00
|
|
|
// CraftBukkit end
|
|
|
|
|
2012-01-17 17:08:54 +01:00
|
|
|
for (int i = 0; i < 3; ++i) {
|
2012-02-29 22:31:04 +01:00
|
|
|
if (this.items[i] != null && this.items[i].id == Item.POTION.id) {
|
|
|
|
int j = this.items[i].getData();
|
2013-03-13 23:33:27 +01:00
|
|
|
int k = this.c(j, itemstack);
|
|
|
|
List list = Item.POTION.c(j);
|
|
|
|
List list1 = Item.POTION.c(k);
|
2012-01-17 17:08:54 +01:00
|
|
|
|
|
|
|
if ((j <= 0 || list != list1) && (list == null || !list.equals(list1) && list1 != null)) {
|
|
|
|
if (j != k) {
|
2012-02-29 22:31:04 +01:00
|
|
|
this.items[i].setData(k);
|
2012-01-17 17:08:54 +01:00
|
|
|
}
|
2013-03-13 23:33:27 +01:00
|
|
|
} else if (!ItemPotion.f(j) && ItemPotion.f(k)) {
|
2012-02-29 22:31:04 +01:00
|
|
|
this.items[i].setData(k);
|
2012-01-17 17:08:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
if (Item.byId[itemstack.id].t()) {
|
|
|
|
this.items[3] = new ItemStack(Item.byId[itemstack.id].s());
|
2012-01-17 17:08:54 +01:00
|
|
|
} else {
|
2012-02-29 22:31:04 +01:00
|
|
|
--this.items[3].count;
|
|
|
|
if (this.items[3].count <= 0) {
|
|
|
|
this.items[3] = null;
|
2012-01-17 17:08:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
private int c(int i, ItemStack itemstack) {
|
|
|
|
return itemstack == null ? i : (Item.byId[itemstack.id].w() ? PotionBrewer.a(i, Item.byId[itemstack.id].v()) : i);
|
2012-01-17 17:08:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void a(NBTTagCompound nbttagcompound) {
|
|
|
|
super.a(nbttagcompound);
|
|
|
|
NBTTagList nbttaglist = nbttagcompound.getList("Items");
|
|
|
|
|
2012-02-29 22:31:04 +01:00
|
|
|
this.items = new ItemStack[this.getSize()];
|
2012-01-17 17:08:54 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < nbttaglist.size(); ++i) {
|
|
|
|
NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.get(i);
|
|
|
|
byte b0 = nbttagcompound1.getByte("Slot");
|
|
|
|
|
2012-02-29 22:31:04 +01:00
|
|
|
if (b0 >= 0 && b0 < this.items.length) {
|
2013-01-17 10:28:44 +01:00
|
|
|
this.items[b0] = ItemStack.createStack(nbttagcompound1);
|
2012-01-17 17:08:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-29 22:31:04 +01:00
|
|
|
this.brewTime = nbttagcompound.getShort("BrewTime");
|
2013-03-13 23:33:27 +01:00
|
|
|
if (nbttagcompound.hasKey("CustomName")) {
|
2013-03-20 21:09:23 +01:00
|
|
|
this.g = nbttagcompound.getString("CustomName");
|
2013-03-13 23:33:27 +01:00
|
|
|
}
|
2012-01-17 17:08:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void b(NBTTagCompound nbttagcompound) {
|
|
|
|
super.b(nbttagcompound);
|
2012-02-29 22:31:04 +01:00
|
|
|
nbttagcompound.setShort("BrewTime", (short) this.brewTime);
|
2012-01-17 17:08:54 +01:00
|
|
|
NBTTagList nbttaglist = new NBTTagList();
|
|
|
|
|
2012-02-29 22:31:04 +01:00
|
|
|
for (int i = 0; i < this.items.length; ++i) {
|
|
|
|
if (this.items[i] != null) {
|
2012-01-17 17:08:54 +01:00
|
|
|
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
|
|
|
|
|
|
|
|
nbttagcompound1.setByte("Slot", (byte) i);
|
2012-02-29 22:31:04 +01:00
|
|
|
this.items[i].save(nbttagcompound1);
|
2012-01-17 17:08:54 +01:00
|
|
|
nbttaglist.add(nbttagcompound1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nbttagcompound.set("Items", nbttaglist);
|
2013-03-13 23:33:27 +01:00
|
|
|
if (this.c()) {
|
2013-03-20 21:09:23 +01:00
|
|
|
nbttagcompound.setString("CustomName", this.g);
|
2013-03-13 23:33:27 +01:00
|
|
|
}
|
2012-01-17 17:08:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public ItemStack getItem(int i) {
|
2012-02-29 22:31:04 +01:00
|
|
|
return i >= 0 && i < this.items.length ? this.items[i] : null;
|
2012-01-17 17:08:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public ItemStack splitStack(int i, int j) {
|
2012-02-29 22:31:04 +01:00
|
|
|
if (i >= 0 && i < this.items.length) {
|
|
|
|
ItemStack itemstack = this.items[i];
|
2012-01-17 17:08:54 +01:00
|
|
|
|
2012-02-29 22:31:04 +01:00
|
|
|
this.items[i] = null;
|
2012-01-17 17:08:54 +01:00
|
|
|
return itemstack;
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-01 11:49:23 +01:00
|
|
|
public ItemStack splitWithoutUpdate(int i) {
|
|
|
|
if (i >= 0 && i < this.items.length) {
|
|
|
|
ItemStack itemstack = this.items[i];
|
|
|
|
|
|
|
|
this.items[i] = null;
|
|
|
|
return itemstack;
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-17 17:08:54 +01:00
|
|
|
public void setItem(int i, ItemStack itemstack) {
|
2012-02-29 22:31:04 +01:00
|
|
|
if (i >= 0 && i < this.items.length) {
|
|
|
|
this.items[i] = itemstack;
|
2012-01-17 17:08:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getMaxStackSize() {
|
2012-07-29 09:33:13 +02:00
|
|
|
return this.maxStack; // CraftBukkit
|
2012-01-17 17:08:54 +01:00
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
public boolean a(EntityHuman entityhuman) {
|
2012-01-17 17:08:54 +01: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;
|
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
public void startOpen() {}
|
2012-01-17 17:08:54 +01:00
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
public void g() {}
|
2012-01-17 17:08:54 +01:00
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
public boolean b(int i, ItemStack itemstack) {
|
|
|
|
return i == 3 ? Item.byId[itemstack.id].w() : itemstack.id == Item.POTION.id || itemstack.id == Item.GLASS_BOTTLE.id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int j() {
|
2012-01-17 17:08:54 +01:00
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
for (int j = 0; j < 3; ++j) {
|
2012-02-29 22:31:04 +01:00
|
|
|
if (this.items[j] != null) {
|
2012-01-17 17:08:54 +01:00
|
|
|
i |= 1 << j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
2013-03-13 23:33:27 +01:00
|
|
|
|
2013-03-20 21:09:23 +01:00
|
|
|
public int[] getSlotsForFace(int i) {
|
|
|
|
return i == 1 ? a : b;
|
2013-03-13 23:33:27 +01:00
|
|
|
}
|
|
|
|
|
2013-03-20 21:09:23 +01:00
|
|
|
public boolean canPlaceItemThroughFace(int i, ItemStack itemstack, int j) {
|
|
|
|
return this.b(i, itemstack);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canTakeItemThroughFace(int i, ItemStack itemstack, int j) {
|
|
|
|
return true;
|
2013-03-13 23:33:27 +01:00
|
|
|
}
|
2012-01-17 17:08:54 +01:00
|
|
|
}
|