Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
at develop 253 lines 8.6 kB view raw
1package net.minecraft.server; 2 3// CraftBukkit start 4 5import org.bukkit.craftbukkit.inventory.CraftItemStack; 6import org.bukkit.event.inventory.FurnaceBurnEvent; 7import org.bukkit.event.inventory.FurnaceSmeltEvent; 8// CraftBukkit end 9 10import uk.betacraft.uberbukkit.Uberbukkit; 11 12public class TileEntityFurnace extends TileEntity implements IInventory { 13 14 private ItemStack[] items = new ItemStack[3]; 15 public int burnTime = 0; 16 public int ticksForCurrentFuel = 0; 17 public int cookTime = 0; 18 19 // CraftBukkit start 20 private int lastTick = (int) (System.currentTimeMillis() / 50); 21 22 public ItemStack[] getContents() { 23 return this.items; 24 } 25 // CraftBukkit end 26 27 public TileEntityFurnace() { 28 } 29 30 public int getSize() { 31 return this.items.length; 32 } 33 34 public ItemStack getItem(int i) { 35 return this.items[i]; 36 } 37 38 public ItemStack splitStack(int i, int j) { 39 if (this.items[i] != null) { 40 ItemStack itemstack; 41 42 if (this.items[i].count <= j) { 43 itemstack = this.items[i]; 44 this.items[i] = null; 45 return itemstack; 46 } else { 47 itemstack = this.items[i].a(j); 48 if (this.items[i].count == 0) { 49 this.items[i] = null; 50 } 51 52 return itemstack; 53 } 54 } else { 55 return null; 56 } 57 } 58 59 public void setItem(int i, ItemStack itemstack) { 60 this.items[i] = itemstack; 61 if (itemstack != null && itemstack.count > this.getMaxStackSize()) { 62 itemstack.count = this.getMaxStackSize(); 63 } 64 } 65 66 public String getName() { 67 return "Furnace"; 68 } 69 70 public void a(NBTTagCompound nbttagcompound) { 71 super.a(nbttagcompound); 72 NBTTagList nbttaglist = nbttagcompound.l("Items"); 73 74 this.items = new ItemStack[this.getSize()]; 75 76 for (int i = 0; i < nbttaglist.c(); ++i) { 77 NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.a(i); 78 byte b0 = nbttagcompound1.c("Slot"); 79 80 if (b0 >= 0 && b0 < this.items.length) { 81 this.items[b0] = new ItemStack(nbttagcompound1); 82 } 83 } 84 85 this.burnTime = nbttagcompound.d("BurnTime"); 86 this.cookTime = nbttagcompound.d("CookTime"); 87 this.ticksForCurrentFuel = this.fuelTime(this.items[1]); 88 } 89 90 public void b(NBTTagCompound nbttagcompound) { 91 super.b(nbttagcompound); 92 nbttagcompound.a("BurnTime", (short) this.burnTime); 93 nbttagcompound.a("CookTime", (short) this.cookTime); 94 NBTTagList nbttaglist = new NBTTagList(); 95 96 for (int i = 0; i < this.items.length; ++i) { 97 if (this.items[i] != null) { 98 NBTTagCompound nbttagcompound1 = new NBTTagCompound(); 99 100 nbttagcompound1.a("Slot", (byte) i); 101 this.items[i].a(nbttagcompound1); 102 nbttaglist.a((NBTBase) nbttagcompound1); 103 } 104 } 105 106 nbttagcompound.a("Items", (NBTBase) nbttaglist); 107 } 108 109 public int getMaxStackSize() { 110 return 64; 111 } 112 113 public boolean isBurning() { 114 return this.burnTime > 0; 115 } 116 117 public void g_() { 118 boolean flag = this.burnTime > 0; 119 boolean flag1 = false; 120 121 // CraftBukkit start 122 int currentTick = (int) (System.currentTimeMillis() / 50); // CraftBukkit 123 int elapsedTicks = currentTick - this.lastTick; 124 this.lastTick = currentTick; 125 126 // CraftBukkit - moved from below 127 if (this.isBurning() && this.canBurn()) { 128 this.cookTime += elapsedTicks; 129 if (this.cookTime >= 200) { 130 this.cookTime %= 200; 131 this.burn(); 132 flag1 = true; 133 } 134 } else { 135 this.cookTime = 0; 136 } 137 // CraftBukkit end 138 139 if (this.burnTime > 0) { 140 this.burnTime -= elapsedTicks; // CraftBukkit 141 } 142 143 if (!this.world.isStatic) { 144 // CraftBukkit start - handle multiple elapsed ticks 145 if (this.burnTime <= 0 && this.canBurn() && this.items[1] != null) { // CraftBukkit - == to <= 146 CraftItemStack fuel = new CraftItemStack(this.items[1]); 147 148 FurnaceBurnEvent furnaceBurnEvent = new FurnaceBurnEvent(this.world.getWorld().getBlockAt(this.x, this.y, this.z), fuel, this.fuelTime(this.items[1])); 149 this.world.getServer().getPluginManager().callEvent(furnaceBurnEvent); 150 151 if (furnaceBurnEvent.isCancelled()) { 152 return; 153 } 154 155 this.ticksForCurrentFuel = furnaceBurnEvent.getBurnTime(); 156 this.burnTime += this.ticksForCurrentFuel; 157 if (this.burnTime > 0 && furnaceBurnEvent.isBurning()) { 158 // CraftBukkit end 159 flag1 = true; 160 if (this.items[1] != null) { 161 --this.items[1].count; 162 if (this.items[1].count == 0) { 163 this.items[1] = null; 164 } 165 } 166 } 167 } 168 169 /* CraftBukkit start - moved up 170 if (this.f() && this.process()) { 171 ++this.cookTime; 172 if (this.cookTime == 200) { 173 this.cookTime = 0; 174 this.burn(); 175 flag1 = true; 176 } 177 } else { 178 this.cookTime = 0; 179 } 180 // CraftBukkit end */ 181 182 if (flag != this.burnTime > 0) { 183 flag1 = true; 184 BlockFurnace.a(this.burnTime > 0, this.world, this.x, this.y, this.z); 185 } 186 } 187 188 if (flag1) { 189 this.update(); 190 } 191 } 192 193 private boolean canBurn() { 194 if (this.items[0] == null) { 195 return false; 196 } else { 197 ItemStack itemstack = FurnaceRecipes.getInstance().a(this.items[0].getItem().id); 198 199 // CraftBukkit - consider resultant count instead of current count 200 return itemstack == null ? false : (this.items[2] == null ? true : (!this.items[2].doMaterialsMatch(itemstack) ? false : (this.items[2].count + itemstack.count <= this.getMaxStackSize() && this.items[2].count < this.items[2].getMaxStackSize() ? true : this.items[2].count + itemstack.count <= itemstack.getMaxStackSize()))); 201 } 202 } 203 204 public void burn() { 205 if (this.canBurn()) { 206 ItemStack itemstack = FurnaceRecipes.getInstance().a(this.items[0].getItem().id); 207 208 // CraftBukkit start 209 CraftItemStack source = new CraftItemStack(this.items[0]); 210 CraftItemStack result = new CraftItemStack(itemstack.cloneItemStack()); 211 212 FurnaceSmeltEvent furnaceSmeltEvent = new FurnaceSmeltEvent(this.world.getWorld().getBlockAt(this.x, this.y, this.z), source, result); 213 this.world.getServer().getPluginManager().callEvent(furnaceSmeltEvent); 214 215 if (furnaceSmeltEvent.isCancelled()) { 216 return; 217 } 218 219 org.bukkit.inventory.ItemStack oldResult = furnaceSmeltEvent.getResult(); 220 ItemStack newResult = new ItemStack(oldResult.getTypeId(), oldResult.getAmount(), oldResult.getDurability()); 221 itemstack = newResult; 222 223 if (this.items[2] == null) { 224 this.items[2] = itemstack.cloneItemStack(); 225 } else if (this.items[2].id == itemstack.id) { 226 // CraftBukkit - compare damage too 227 if (this.items[2].damage == itemstack.damage) { 228 this.items[2].count += itemstack.count; 229 } 230 // CraftBukkit end 231 } 232 233 --this.items[0].count; 234 if (this.items[0].count <= 0) { 235 this.items[0] = null; 236 } 237 } 238 } 239 240 private int fuelTime(ItemStack itemstack) { 241 if (itemstack == null) { 242 return 0; 243 } else { 244 int i = itemstack.getItem().id; 245 246 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 : (Uberbukkit.getTargetPVN() >= 11 ? (i == Block.SAPLING.id ? 100 : 0) : 0)))); 247 } 248 } 249 250 public boolean a_(EntityHuman entityhuman) { 251 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; 252 } 253}