mirror of
https://github.com/PaperMC/Paper.git
synced 2026-11-25 10:29:41 -05:00
Currently furnace smelting and the item pickup delay timer use wall time (aka actual time passed) to emulate a constant tick rate so run at the same speed regardless of the server's actual tick rate. There are several other places this makes sense so this commit converts them. The item despawn timer is converted so now always takes 5 minutes. Users know this 5 minute number well so keeping this constant helps to avoid confusion. This also helps alleviate lag because if a large number of item drops is the reason your server is running slowly having them stay around longer just means your server is slow longer. Potion brewing and the zombie villager conversion timer are now constant. These match the furnace criteria of being useful for hiding lag and not having a detrimental effect on gameplay. Potion effects are now also using wall time. The client is told about effect times in ticks and displays this information to the user as minutes and seconds assuming a solid 20 ticks per second. The server does have code for updating the client with the current time remaining to help avoid skew due to differing tick rates but making this a constant makes sense due to this display.
298 lines
8.7 KiB
Java
298 lines
8.7 KiB
Java
package net.minecraft.server;
|
|
|
|
import java.util.List;
|
|
|
|
// CraftBukkit start
|
|
import org.bukkit.craftbukkit.entity.CraftHumanEntity;
|
|
import org.bukkit.entity.HumanEntity;
|
|
import org.bukkit.event.inventory.BrewEvent;
|
|
// CraftBukkit end
|
|
|
|
public class TileEntityBrewingStand extends TileEntity implements IWorldInventory {
|
|
|
|
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;
|
|
private int lastTick = MinecraftServer.currentTick; // CraftBukkit
|
|
|
|
public TileEntityBrewingStand() {}
|
|
|
|
// CraftBukkit start
|
|
public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
|
|
private int maxStack = 64;
|
|
|
|
public void onOpen(CraftHumanEntity who) {
|
|
transaction.add(who);
|
|
}
|
|
|
|
public void onClose(CraftHumanEntity who) {
|
|
transaction.remove(who);
|
|
}
|
|
|
|
public List<HumanEntity> getViewers() {
|
|
return transaction;
|
|
}
|
|
|
|
public ItemStack[] getContents() {
|
|
return this.items;
|
|
}
|
|
|
|
public void setMaxStackSize(int size) {
|
|
maxStack = size;
|
|
}
|
|
// CraftBukkit end
|
|
|
|
public String getName() {
|
|
return this.c() ? this.g : "container.brewing";
|
|
}
|
|
|
|
public boolean c() {
|
|
return this.g != null && this.g.length() > 0;
|
|
}
|
|
|
|
public void a(String s) {
|
|
this.g = s;
|
|
}
|
|
|
|
public int getSize() {
|
|
return this.items.length;
|
|
}
|
|
|
|
public void h() {
|
|
// CraftBukkit start - Use wall time instead of ticks for brewing
|
|
int elapsedTicks = Math.max(1, MinecraftServer.currentTick - this.lastTick);
|
|
this.lastTick = MinecraftServer.currentTick;
|
|
|
|
if (this.brewTime > 0) {
|
|
this.brewTime -= elapsedTicks;
|
|
if (this.brewTime <= 0) { // == -> <=
|
|
// CraftBukkit end
|
|
this.u();
|
|
this.update();
|
|
} else if (!this.l()) {
|
|
this.brewTime = 0;
|
|
this.update();
|
|
} else if (this.f != this.items[3].id) {
|
|
this.brewTime = 0;
|
|
this.update();
|
|
}
|
|
} else if (this.l()) {
|
|
this.brewTime = 400;
|
|
this.f = this.items[3].id;
|
|
}
|
|
|
|
int i = this.j();
|
|
|
|
if (i != this.e) {
|
|
this.e = i;
|
|
this.world.setData(this.x, this.y, this.z, i, 2);
|
|
}
|
|
|
|
super.h();
|
|
}
|
|
|
|
public int x_() {
|
|
return this.brewTime;
|
|
}
|
|
|
|
private boolean l() {
|
|
if (this.items[3] != null && this.items[3].count > 0) {
|
|
ItemStack itemstack = this.items[3];
|
|
|
|
if (!Item.byId[itemstack.id].w()) {
|
|
return false;
|
|
} else {
|
|
boolean flag = false;
|
|
|
|
for (int i = 0; i < 3; ++i) {
|
|
if (this.items[i] != null && this.items[i].id == Item.POTION.id) {
|
|
int j = this.items[i].getData();
|
|
int k = this.c(j, itemstack);
|
|
|
|
if (!ItemPotion.f(j) && ItemPotion.f(k)) {
|
|
flag = true;
|
|
break;
|
|
}
|
|
|
|
List list = Item.POTION.c(j);
|
|
List list1 = Item.POTION.c(k);
|
|
|
|
if ((j <= 0 || list != list1) && (list == null || !list.equals(list1) && list1 != null) && j != k) {
|
|
flag = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
return flag;
|
|
}
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
private void u() {
|
|
if (this.l()) {
|
|
ItemStack itemstack = this.items[3];
|
|
|
|
// CraftBukkit start
|
|
if (getOwner() != null) {
|
|
BrewEvent event = new BrewEvent(world.getWorld().getBlockAt(x, y, z), (org.bukkit.inventory.BrewerInventory) this.getOwner().getInventory());
|
|
org.bukkit.Bukkit.getPluginManager().callEvent(event);
|
|
if (event.isCancelled()) {
|
|
return;
|
|
}
|
|
}
|
|
// CraftBukkit end
|
|
|
|
for (int i = 0; i < 3; ++i) {
|
|
if (this.items[i] != null && this.items[i].id == Item.POTION.id) {
|
|
int j = this.items[i].getData();
|
|
int k = this.c(j, itemstack);
|
|
List list = Item.POTION.c(j);
|
|
List list1 = Item.POTION.c(k);
|
|
|
|
if ((j <= 0 || list != list1) && (list == null || !list.equals(list1) && list1 != null)) {
|
|
if (j != k) {
|
|
this.items[i].setData(k);
|
|
}
|
|
} else if (!ItemPotion.f(j) && ItemPotion.f(k)) {
|
|
this.items[i].setData(k);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (Item.byId[itemstack.id].t()) {
|
|
this.items[3] = new ItemStack(Item.byId[itemstack.id].s());
|
|
} else {
|
|
--this.items[3].count;
|
|
if (this.items[3].count <= 0) {
|
|
this.items[3] = null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
public void a(NBTTagCompound nbttagcompound) {
|
|
super.a(nbttagcompound);
|
|
NBTTagList nbttaglist = nbttagcompound.getList("Items");
|
|
|
|
this.items = new ItemStack[this.getSize()];
|
|
|
|
for (int i = 0; i < nbttaglist.size(); ++i) {
|
|
NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.get(i);
|
|
byte b0 = nbttagcompound1.getByte("Slot");
|
|
|
|
if (b0 >= 0 && b0 < this.items.length) {
|
|
this.items[b0] = ItemStack.createStack(nbttagcompound1);
|
|
}
|
|
}
|
|
|
|
this.brewTime = nbttagcompound.getShort("BrewTime");
|
|
if (nbttagcompound.hasKey("CustomName")) {
|
|
this.g = nbttagcompound.getString("CustomName");
|
|
}
|
|
}
|
|
|
|
public void b(NBTTagCompound nbttagcompound) {
|
|
super.b(nbttagcompound);
|
|
nbttagcompound.setShort("BrewTime", (short) this.brewTime);
|
|
NBTTagList nbttaglist = new NBTTagList();
|
|
|
|
for (int i = 0; i < this.items.length; ++i) {
|
|
if (this.items[i] != null) {
|
|
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
|
|
|
|
nbttagcompound1.setByte("Slot", (byte) i);
|
|
this.items[i].save(nbttagcompound1);
|
|
nbttaglist.add(nbttagcompound1);
|
|
}
|
|
}
|
|
|
|
nbttagcompound.set("Items", nbttaglist);
|
|
if (this.c()) {
|
|
nbttagcompound.setString("CustomName", this.g);
|
|
}
|
|
}
|
|
|
|
public ItemStack getItem(int i) {
|
|
return i >= 0 && i < this.items.length ? this.items[i] : null;
|
|
}
|
|
|
|
public ItemStack splitStack(int i, int j) {
|
|
if (i >= 0 && i < this.items.length) {
|
|
ItemStack itemstack = this.items[i];
|
|
|
|
this.items[i] = null;
|
|
return itemstack;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
public void setItem(int i, ItemStack itemstack) {
|
|
if (i >= 0 && i < this.items.length) {
|
|
this.items[i] = itemstack;
|
|
}
|
|
}
|
|
|
|
public int getMaxStackSize() {
|
|
return this.maxStack; // CraftBukkit
|
|
}
|
|
|
|
public boolean a(EntityHuman entityhuman) {
|
|
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;
|
|
}
|
|
|
|
public void startOpen() {}
|
|
|
|
public void g() {}
|
|
|
|
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() {
|
|
int i = 0;
|
|
|
|
for (int j = 0; j < 3; ++j) {
|
|
if (this.items[j] != null) {
|
|
i |= 1 << j;
|
|
}
|
|
}
|
|
|
|
return i;
|
|
}
|
|
|
|
public int[] getSlotsForFace(int i) {
|
|
return i == 1 ? a : b;
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|