Skip to content

Instantly share code, notes, and snippets.

@aikar
Created October 25, 2018 04:59
Show Gist options
  • Save aikar/b2c45c2982cfbc9fc808df2b5bf593f7 to your computer and use it in GitHub Desktop.
Save aikar/b2c45c2982cfbc9fc808df2b5bf593f7 to your computer and use it in GitHub Desktop.
diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
index b766e00d0b..2042b9bd71 100644
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
@@ -569,4 +569,10 @@ public class PaperWorldConfig {
private void preventMovingIntoUnloadedChunks() {
preventMovingIntoUnloadedChunks = getBoolean("settings.prevent-moving-into-unloaded-chunks", false);
}
+
+ public double optimizeEntityMovement = 0.5D;
+ private void optimizeEntityMovement() {
+ optimizeEntityMovement = getDouble("optimize-entity-movement", optimizeEntityMovement);
+ }
+
}
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
index e8c811dd94..bee324f717 100644
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
@@ -558,6 +558,12 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
}
+ // Paper start
+ double pendingX = 0D;
+ double pendingY = 0D;
+ double pendingZ = 0D;
+ // Paper end
+
public void extinguish() {
this.fireTicks = 0;
}
@@ -580,6 +586,23 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
this.a(this.getBoundingBox().d(d0, d1, d2));
this.recalcPosition();
} else {
+ // Paper start
+ final double optimizeMin = this.world.paperConfig.optimizeEntityMovement;
+ if (optimizeMin > 0 && enummovetype == EnumMoveType.SELF) {
+ if (pendingX != 0D) {
+ d0 += pendingX;
+ pendingX = 0D;
+ }
+ if (pendingY != 0D) {
+ d1 += pendingY;
+ pendingY = 0D;
+ }
+ if (pendingZ != 0D) {
+ d2 += pendingZ;
+ pendingZ = 0D;
+ }
+ }
+ // Paper end
if (enummovetype == EnumMoveType.PISTON) {
this.activatedTick = MinecraftServer.currentTick + 20; // Paper
long i = this.world.getTime();
@@ -683,6 +706,17 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
}
}
+ // Paper start
+ if (optimizeMin > 0 && enummovetype == EnumMoveType.SELF && d0 * d0 < optimizeMin && d1 * d1 < optimizeMin && d2 * d2 < optimizeMin) {
+ pendingX = d0;
+ pendingY = d1;
+ pendingZ = d2;
+ d0 = d7 = 0;
+ d1 = d8 = 0;
+ d2 = d9 = 0;
+ }
+ // Paper end
+
AxisAlignedBB axisalignedbb = this.getBoundingBox();
if (d0 != 0.0D || d1 != 0.0D || d2 != 0.0D) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment