3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-18 20:40:08 +01:00

Use wall time instead of ticks for several things. Fixes BUKKIT-4059

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.
Dieser Commit ist enthalten in:
Travis Watkins 2013-04-11 18:28:15 -05:00 committet von Wesley Wolfe
Ursprung 94f43d8c36
Commit 1c18834b7d
7 geänderte Dateien mit 37 neuen und 17 gelöschten Zeilen

Datei anzeigen

@ -10,7 +10,7 @@ public class EntityItem extends Entity {
public int pickupDelay; public int pickupDelay;
private int d; private int d;
public float c; public float c;
private int lastTick = (int) (System.currentTimeMillis() / 50); // CraftBukkit private int lastTick = MinecraftServer.currentTick; // CraftBukkit
public EntityItem(World world, double d0, double d1, double d2) { public EntityItem(World world, double d0, double d1, double d2) {
super(world); super(world);
@ -55,10 +55,11 @@ public class EntityItem extends Entity {
public void l_() { public void l_() {
super.l_(); super.l_();
// CraftBukkit start // CraftBukkit start - Use wall time for pickup and despawn timers
int currentTick = (int) (System.currentTimeMillis() / 50); int elapsedTicks = Math.max(1, MinecraftServer.currentTick - this.lastTick);
this.pickupDelay -= (currentTick - this.lastTick); this.pickupDelay -= elapsedTicks;
this.lastTick = currentTick; this.age += elapsedTicks;
this.lastTick = MinecraftServer.currentTick;
// CraftBukkit end // CraftBukkit end
this.lastX = this.locX; this.lastX = this.locX;
@ -100,7 +101,7 @@ public class EntityItem extends Entity {
this.motY *= -0.5D; this.motY *= -0.5D;
} }
++this.age; // ++this.age; // CraftBukkit - Moved up
if (!this.world.isStatic && this.age >= 6000) { if (!this.world.isStatic && this.age >= 6000) {
// CraftBukkit start // CraftBukkit start
if (org.bukkit.craftbukkit.event.CraftEventFactory.callItemDespawnEvent(this).isCancelled()) { if (org.bukkit.craftbukkit.event.CraftEventFactory.callItemDespawnEvent(this).isCancelled()) {

Datei anzeigen

@ -10,6 +10,7 @@ import org.bukkit.event.entity.EntityCombustEvent;
public class EntityZombie extends EntityMonster { public class EntityZombie extends EntityMonster {
private int d = 0; private int d = 0;
private int lastTick = MinecraftServer.currentTick; // CraftBukkit
public EntityZombie(World world) { public EntityZombie(World world) {
super(world); super(world);
@ -119,6 +120,12 @@ public class EntityZombie extends EntityMonster {
if (!this.world.isStatic && this.o()) { if (!this.world.isStatic && this.o()) {
int i = this.q(); int i = this.q();
// CraftBukkit start - Use wall time instead of ticks for villager conversion
int elapsedTicks = Math.max(1, MinecraftServer.currentTick - this.lastTick);
this.lastTick = MinecraftServer.currentTick;
i *= elapsedTicks;
// CraftBukkit end
this.d -= i; this.d -= i;
if (this.d <= 0) { if (this.d <= 0) {
this.p(); this.p();

Datei anzeigen

@ -78,7 +78,7 @@ public abstract class MinecraftServer implements ICommandListener, Runnable, IMo
public org.bukkit.command.ConsoleCommandSender console; public org.bukkit.command.ConsoleCommandSender console;
public org.bukkit.command.RemoteConsoleCommandSender remoteConsole; public org.bukkit.command.RemoteConsoleCommandSender remoteConsole;
public ConsoleReader reader; public ConsoleReader reader;
public static int currentTick; public static int currentTick = (int) (System.currentTimeMillis() / 50);
public final Thread primaryThread; public final Thread primaryThread;
public java.util.Queue<Runnable> processQueue = new java.util.concurrent.ConcurrentLinkedQueue<Runnable>(); public java.util.Queue<Runnable> processQueue = new java.util.concurrent.ConcurrentLinkedQueue<Runnable>();
public int autosavePeriod; public int autosavePeriod;

Datei anzeigen

@ -7,6 +7,7 @@ public class MobEffect {
private int amplification; private int amplification;
private boolean splash; private boolean splash;
private boolean ambient; private boolean ambient;
private int lastTick = MinecraftServer.currentTick; // CraftBukkit
public MobEffect(int i, int j) { public MobEffect(int i, int j) {
this(i, j, 0); this(i, j, 0);
@ -81,7 +82,13 @@ public class MobEffect {
} }
private int h() { private int h() {
return --this.duration; // CraftBukkit start - Use wall time instead of ticks for potion effects
int elapsedTicks = Math.max(1, MinecraftServer.currentTick - this.lastTick);
this.lastTick = MinecraftServer.currentTick;
this.duration -= elapsedTicks;
return this.duration;
// CraftBukkit end
} }
public void b(EntityLiving entityliving) { public void b(EntityLiving entityliving) {

Datei anzeigen

@ -55,7 +55,7 @@ public class PlayerInteractManager {
} }
public void a() { public void a() {
this.currentTick = (int) (System.currentTimeMillis() / 50); // CraftBukkit this.currentTick = MinecraftServer.currentTick; // CraftBukkit
int i; int i;
float f; float f;
int j; int j;
@ -189,7 +189,7 @@ public class PlayerInteractManager {
public void a(int i, int j, int k) { public void a(int i, int j, int k) {
if (i == this.f && j == this.g && k == this.h) { if (i == this.f && j == this.g && k == this.h) {
this.currentTick = (int) (System.currentTimeMillis() / 50); // CraftBukkit this.currentTick = MinecraftServer.currentTick; // CraftBukkit
int l = this.currentTick - this.lastDigTick; int l = this.currentTick - this.lastDigTick;
int i1 = this.world.getTypeId(i, j, k); int i1 = this.world.getTypeId(i, j, k);

Datei anzeigen

@ -17,6 +17,7 @@ public class TileEntityBrewingStand extends TileEntity implements IWorldInventor
private int e; private int e;
private int f; private int f;
private String g; private String g;
private int lastTick = MinecraftServer.currentTick; // CraftBukkit
public TileEntityBrewingStand() {} public TileEntityBrewingStand() {}
@ -62,9 +63,14 @@ public class TileEntityBrewingStand extends TileEntity implements IWorldInventor
} }
public void h() { 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) { if (this.brewTime > 0) {
--this.brewTime; this.brewTime -= elapsedTicks;
if (this.brewTime == 0) { if (this.brewTime <= 0) { // == -> <=
// CraftBukkit end
this.u(); this.u();
this.update(); this.update();
} else if (!this.l()) { } else if (!this.l()) {

Datei anzeigen

@ -22,7 +22,7 @@ public class TileEntityFurnace extends TileEntity implements IWorldInventory {
private String h; private String h;
// CraftBukkit start // CraftBukkit start
private int lastTick = (int) (System.currentTimeMillis() / 50); private int lastTick = MinecraftServer.currentTick;
private int maxStack = MAX_STACK; private int maxStack = MAX_STACK;
public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>(); public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
@ -165,10 +165,9 @@ public class TileEntityFurnace extends TileEntity implements IWorldInventory {
boolean flag = this.burnTime > 0; boolean flag = this.burnTime > 0;
boolean flag1 = false; boolean flag1 = false;
// CraftBukkit start // CraftBukkit start - Use wall time instead of ticks for cooking
int currentTick = (int) (System.currentTimeMillis() / 50); // CraftBukkit int elapsedTicks = Math.max(1, MinecraftServer.currentTick - this.lastTick);
int elapsedTicks = currentTick - this.lastTick; this.lastTick = MinecraftServer.currentTick;
this.lastTick = currentTick;
// CraftBukkit - moved from below // CraftBukkit - moved from below
if (this.isBurning() && this.canBurn()) { if (this.isBurning() && this.canBurn()) {