From 3bbfb41798e926e9a186f5c408320e3671ad13b4 Mon Sep 17 00:00:00 2001 From: Travis Watkins Date: Sat, 27 Apr 2013 04:50:37 -0500 Subject: [PATCH] Fix things using wall time running too fast. Fixes BUKKIT-4155 When converting things in Minecraft to use wall time instead of ticks I realized we'd run into integer division rounding issues and could have updates that end up counting as zero ticks. To compensate for this the code ensures we always process at least one tick. However, every time we end up with zero ticks the next time we have an extra tick due to rounding the other way with the leftovers. This means we are going far too fast and should not have this at least one tick logic at all. On top of this some potions rely on the number of ticks they run and not just the amount of time they last and so potions were put back to running with ticks entirely. --- .../java/net/minecraft/server/EntityItem.java | 2 +- .../net/minecraft/server/EntityZombie.java | 2 +- .../java/net/minecraft/server/MobEffect.java | 150 ------------------ .../server/TileEntityBrewingStand.java | 2 +- .../minecraft/server/TileEntityFurnace.java | 2 +- 5 files changed, 4 insertions(+), 154 deletions(-) delete mode 100644 src/main/java/net/minecraft/server/MobEffect.java diff --git a/src/main/java/net/minecraft/server/EntityItem.java b/src/main/java/net/minecraft/server/EntityItem.java index a28d233d49..0225f53504 100644 --- a/src/main/java/net/minecraft/server/EntityItem.java +++ b/src/main/java/net/minecraft/server/EntityItem.java @@ -56,7 +56,7 @@ public class EntityItem extends Entity { public void l_() { super.l_(); // CraftBukkit start - Use wall time for pickup and despawn timers - int elapsedTicks = Math.max(1, MinecraftServer.currentTick - this.lastTick); + int elapsedTicks = MinecraftServer.currentTick - this.lastTick; this.pickupDelay -= elapsedTicks; this.age += elapsedTicks; this.lastTick = MinecraftServer.currentTick; diff --git a/src/main/java/net/minecraft/server/EntityZombie.java b/src/main/java/net/minecraft/server/EntityZombie.java index 7c717a608a..8aa910380a 100644 --- a/src/main/java/net/minecraft/server/EntityZombie.java +++ b/src/main/java/net/minecraft/server/EntityZombie.java @@ -121,7 +121,7 @@ public class EntityZombie extends EntityMonster { int i = this.q(); // CraftBukkit start - Use wall time instead of ticks for villager conversion - int elapsedTicks = Math.max(1, MinecraftServer.currentTick - this.lastTick); + int elapsedTicks = MinecraftServer.currentTick - this.lastTick; this.lastTick = MinecraftServer.currentTick; i *= elapsedTicks; // CraftBukkit end diff --git a/src/main/java/net/minecraft/server/MobEffect.java b/src/main/java/net/minecraft/server/MobEffect.java deleted file mode 100644 index 2ba51cfebe..0000000000 --- a/src/main/java/net/minecraft/server/MobEffect.java +++ /dev/null @@ -1,150 +0,0 @@ -package net.minecraft.server; - -public class MobEffect { - - private int effectId; - private int duration; - private int amplification; - private boolean splash; - private boolean ambient; - private int lastTick = MinecraftServer.currentTick; // CraftBukkit - - public MobEffect(int i, int j) { - this(i, j, 0); - } - - public MobEffect(int i, int j, int k) { - this(i, j, k, false); - } - - public MobEffect(int i, int j, int k, boolean flag) { - this.effectId = i; - this.duration = j; - this.amplification = k; - this.ambient = flag; - } - - public MobEffect(MobEffect mobeffect) { - this.effectId = mobeffect.effectId; - this.duration = mobeffect.duration; - this.amplification = mobeffect.amplification; - } - - public void a(MobEffect mobeffect) { - if (this.effectId != mobeffect.effectId) { - System.err.println("This method should only be called for matching effects!"); - } - - if (mobeffect.amplification > this.amplification) { - this.amplification = mobeffect.amplification; - this.duration = mobeffect.duration; - } else if (mobeffect.amplification == this.amplification && this.duration < mobeffect.duration) { - this.duration = mobeffect.duration; - } else if (!mobeffect.ambient && this.ambient) { - this.ambient = mobeffect.ambient; - } - } - - public int getEffectId() { - return this.effectId; - } - - public int getDuration() { - return this.duration; - } - - public int getAmplifier() { - return this.amplification; - } - - public boolean isSplash() { - return this.splash; - } - - public void setSplash(boolean flag) { - this.splash = flag; - } - - public boolean isAmbient() { - return this.ambient; - } - - public boolean tick(EntityLiving entityliving) { - if (this.duration > 0) { - if (MobEffectList.byId[this.effectId].a(this.duration, this.amplification)) { - this.b(entityliving); - } - - this.h(); - } - - return this.duration > 0; - } - - private int h() { - // 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) { - if (this.duration > 0) { - MobEffectList.byId[this.effectId].tick(entityliving, this.amplification); - } - } - - public String f() { - return MobEffectList.byId[this.effectId].a(); - } - - public int hashCode() { - return this.effectId; - } - - public String toString() { - String s = ""; - - if (this.getAmplifier() > 0) { - s = this.f() + " x " + (this.getAmplifier() + 1) + ", Duration: " + this.getDuration(); - } else { - s = this.f() + ", Duration: " + this.getDuration(); - } - - if (this.splash) { - s = s + ", Splash: true"; - } - - return MobEffectList.byId[this.effectId].i() ? "(" + s + ")" : s; - } - - public boolean equals(Object object) { - if (!(object instanceof MobEffect)) { - return false; - } else { - MobEffect mobeffect = (MobEffect) object; - - return this.effectId == mobeffect.effectId && this.amplification == mobeffect.amplification && this.duration == mobeffect.duration && this.splash == mobeffect.splash && this.ambient == mobeffect.ambient; - } - } - - public NBTTagCompound a(NBTTagCompound nbttagcompound) { - nbttagcompound.setByte("Id", (byte) this.getEffectId()); - nbttagcompound.setByte("Amplifier", (byte) this.getAmplifier()); - nbttagcompound.setInt("Duration", this.getDuration()); - nbttagcompound.setBoolean("Ambient", this.isAmbient()); - return nbttagcompound; - } - - public static MobEffect b(NBTTagCompound nbttagcompound) { - byte b0 = nbttagcompound.getByte("Id"); - byte b1 = nbttagcompound.getByte("Amplifier"); - int i = nbttagcompound.getInt("Duration"); - boolean flag = nbttagcompound.getBoolean("Ambient"); - - return new MobEffect(b0, i, b1, flag); - } -} diff --git a/src/main/java/net/minecraft/server/TileEntityBrewingStand.java b/src/main/java/net/minecraft/server/TileEntityBrewingStand.java index e362c26d01..2d943bef5c 100644 --- a/src/main/java/net/minecraft/server/TileEntityBrewingStand.java +++ b/src/main/java/net/minecraft/server/TileEntityBrewingStand.java @@ -64,7 +64,7 @@ public class TileEntityBrewingStand extends TileEntity implements IWorldInventor public void h() { // CraftBukkit start - Use wall time instead of ticks for brewing - int elapsedTicks = Math.max(1, MinecraftServer.currentTick - this.lastTick); + int elapsedTicks = MinecraftServer.currentTick - this.lastTick; this.lastTick = MinecraftServer.currentTick; if (this.brewTime > 0) { diff --git a/src/main/java/net/minecraft/server/TileEntityFurnace.java b/src/main/java/net/minecraft/server/TileEntityFurnace.java index 05a07b93d4..e0f6cda3b2 100644 --- a/src/main/java/net/minecraft/server/TileEntityFurnace.java +++ b/src/main/java/net/minecraft/server/TileEntityFurnace.java @@ -166,7 +166,7 @@ public class TileEntityFurnace extends TileEntity implements IWorldInventory { boolean flag1 = false; // CraftBukkit start - Use wall time instead of ticks for cooking - int elapsedTicks = Math.max(1, MinecraftServer.currentTick - this.lastTick); + int elapsedTicks = MinecraftServer.currentTick - this.lastTick; this.lastTick = MinecraftServer.currentTick; // CraftBukkit - moved from below