3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-18 14:00:05 +01:00
Paper/src/main/java/net/minecraft/server/TileEntityFurnace.java

190 Zeilen
5.1 KiB
Java

package net.minecraft.server;
public class TileEntityFurnace extends TileEntity implements IInventory {
2011-01-29 22:50:29 +01:00
private ItemStack[] h = new ItemStack[3];
2011-02-23 03:37:56 +01:00
public int a = 0;
public int b = 0;
public int c = 0;
// CraftBukkit start
public ItemStack[] getContents() {
return h;
}
// CraftBukkit end
2011-01-29 22:50:29 +01:00
public TileEntityFurnace() {}
2011-02-23 03:37:56 +01:00
public int m_() {
2011-01-29 22:50:29 +01:00
return this.h.length;
}
2011-02-23 03:37:56 +01:00
public ItemStack c_(int i) {
2011-01-29 22:50:29 +01:00
return this.h[i];
}
2011-02-23 03:37:56 +01:00
public ItemStack a(int i, int j) {
2011-01-29 22:50:29 +01:00
if (this.h[i] != null) {
ItemStack itemstack;
2011-01-29 22:50:29 +01:00
if (this.h[i].count <= j) {
itemstack = this.h[i];
this.h[i] = null;
return itemstack;
2011-01-29 22:50:29 +01:00
} else {
itemstack = this.h[i].a(j);
if (this.h[i].count == 0) {
this.h[i] = null;
}
2011-01-29 22:50:29 +01:00
return itemstack;
}
} else {
return null;
}
}
2011-01-29 22:50:29 +01:00
public void a(int i, ItemStack itemstack) {
this.h[i] = itemstack;
2011-02-23 03:37:56 +01:00
if (itemstack != null && itemstack.count > this.n_()) {
itemstack.count = this.n_();
}
}
2011-02-23 03:37:56 +01:00
public String c() {
return "Furnace";
}
public void a(NBTTagCompound nbttagcompound) {
super.a(nbttagcompound);
2011-02-23 03:37:56 +01:00
NBTTagList nbttaglist = nbttagcompound.l("Items");
2011-02-23 03:37:56 +01:00
this.h = new ItemStack[this.m_()];
2011-01-29 22:50:29 +01:00
2011-02-23 03:37:56 +01:00
for (int i = 0; i < nbttaglist.c(); ++i) {
2011-01-29 22:50:29 +01:00
NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.a(i);
2011-02-23 03:37:56 +01:00
byte b0 = nbttagcompound1.c("Slot");
2011-01-29 22:50:29 +01:00
if (b0 >= 0 && b0 < this.h.length) {
this.h[b0] = new ItemStack(nbttagcompound1);
}
}
2011-02-23 03:37:56 +01:00
this.a = nbttagcompound.d("BurnTime");
this.c = nbttagcompound.d("CookTime");
this.b = this.a(this.h[1]);
}
public void b(NBTTagCompound nbttagcompound) {
super.b(nbttagcompound);
2011-02-23 03:37:56 +01:00
nbttagcompound.a("BurnTime", (short) this.a);
nbttagcompound.a("CookTime", (short) this.c);
NBTTagList nbttaglist = new NBTTagList();
2011-01-29 22:50:29 +01:00
for (int i = 0; i < this.h.length; ++i) {
if (this.h[i] != null) {
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
2011-01-29 22:50:29 +01:00
nbttagcompound1.a("Slot", (byte) i);
this.h[i].a(nbttagcompound1);
nbttaglist.a((NBTBase) nbttagcompound1);
}
}
2011-01-29 22:50:29 +01:00
nbttagcompound.a("Items", (NBTBase) nbttaglist);
}
2011-02-23 03:37:56 +01:00
public int n_() {
return 64;
}
2011-02-23 03:37:56 +01:00
public boolean f() {
return this.a > 0;
}
2011-02-23 03:37:56 +01:00
public void i_() {
boolean flag = this.a > 0;
boolean flag1 = false;
2011-02-23 03:37:56 +01:00
if (this.a > 0) {
--this.a;
}
2011-01-29 22:50:29 +01:00
2011-02-23 03:37:56 +01:00
if (!this.d.isStatic) {
if (this.a == 0 && this.i()) {
this.b = this.a = this.a(this.h[1]);
if (this.a > 0) {
flag1 = true;
2011-01-29 22:50:29 +01:00
if (this.h[1] != null) {
--this.h[1].count;
if (this.h[1].count == 0) {
this.h[1] = null;
}
}
}
}
2011-01-29 22:50:29 +01:00
2011-02-23 03:37:56 +01:00
if (this.f() && this.i()) {
++this.c;
if (this.c == 200) {
this.c = 0;
this.g();
flag1 = true;
}
} else {
2011-02-23 03:37:56 +01:00
this.c = 0;
}
2011-01-29 22:50:29 +01:00
2011-02-23 03:37:56 +01:00
if (flag != this.a > 0) {
flag1 = true;
2011-02-23 03:37:56 +01:00
BlockFurnace.a(this.a > 0, this.d, this.e, this.f, this.g);
}
}
2011-01-29 22:50:29 +01:00
if (flag1) {
2011-02-23 03:37:56 +01:00
this.h();
}
}
private boolean i() {
2011-01-29 22:50:29 +01:00
if (this.h[0] == null) {
return false;
2011-01-29 22:50:29 +01:00
} else {
ItemStack itemstack = FurnaceRecipes.a().a(this.h[0].a().id);
2011-02-23 03:37:56 +01:00
return itemstack == null ? false : (this.h[2] == null ? true : (!this.h[2].a(itemstack) ? false : (this.h[2].count < this.n_() && this.h[2].count < this.h[2].b() ? true : this.h[2].count < itemstack.b())));
}
}
2011-02-23 03:37:56 +01:00
public void g() {
2011-01-29 22:50:29 +01:00
if (this.i()) {
ItemStack itemstack = FurnaceRecipes.a().a(this.h[0].a().id);
2011-01-29 22:50:29 +01:00
if (this.h[2] == null) {
this.h[2] = itemstack.j();
} else if (this.h[2].id == itemstack.id) {
++this.h[2].count;
}
--this.h[0].count;
if (this.h[0].count <= 0) {
this.h[0] = null;
}
}
}
private int a(ItemStack itemstack) {
if (itemstack == null) {
return 0;
2011-01-29 22:50:29 +01:00
} else {
int i = itemstack.a().id;
2011-01-29 22:50:29 +01:00
return i < 256 && Block.byId[i].material == Material.WOOD ? 300 : (i == Item.STICK.id ? 100 : (i == Item.COAL.id ? 1600 : (i == Item.LAVA_BUCKET.id ? 20000 : 0)));
}
}
2011-01-29 22:50:29 +01:00
public boolean a_(EntityHuman entityhuman) {
2011-02-23 03:37:56 +01:00
return this.d.getTileEntity(this.e, this.f, this.g) != this ? false : entityhuman.d((double) this.e + 0.5D, (double) this.f + 0.5D, (double) this.g + 0.5D) <= 64.0D;
}
2011-01-29 22:50:29 +01:00
}