mirror of
https://github.com/Samsuik/Sakura.git
synced 2025-12-22 08:19:26 +00:00
Upstream has released updates that appear to apply and compile correctly Paper Changes: PaperMC/Paper@dc3ef2a Fix vanilla components not being translated (#9893) PaperMC/Paper@7e15d97 Remove no longer needed diff from adventure patch PaperMC/Paper@f1820dc Fix incorrect border collision detection PaperMC/Paper@de04cbc Updated Upstream (Bukkit/CraftBukkit) (#10034) PaperMC/Paper@ff26d54 send sound and particle packets immediately even if off main (#10033) PaperMC/Paper@e3140fb hotfix spawning item/xp in wrong spot PaperMC/Paper@0b95298 Make worldborder collisions consistent with Vanilla PaperMC/Paper@47b2c18 Don't fire the drop event on player deaths (#10046) PaperMC/Paper@8c007d9 properly read and store sus effect duration (#10050) PaperMC/Paper@5385b21 [ci skip] Make test results viewable in-browser and downloadable (#10055) PaperMC/Paper@086ca61 Fix world border edge collision (#10053) PaperMC/Paper@45e01a2 Use correct max stack size in crafter (#10057) PaperMC/Paper@d11a588 Remove duplicate code in chunk tick iteration (#10056) PaperMC/Paper@b4c9e7e add missing Experimental annotations (#10012)
247 lines
11 KiB
Diff
247 lines
11 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Samsuik <kfian294ma4@gmail.com>
|
|
Date: Fri, 24 Mar 2023 16:29:21 +0000
|
|
Subject: [PATCH] Reduce deltaMovement Allocations
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
index b2d2b6d588572682730a228888b6dcdae2dc5020..4ffa96f7eeefd6a2a07458f68458cdbf4369340f 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
@@ -1233,7 +1233,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
|
|
this.tryCheckInsideBlocks();
|
|
float f = this.getBlockSpeedFactor();
|
|
|
|
- this.setDeltaMovement(this.getDeltaMovement().multiply((double) f, 1.0D, (double) f));
|
|
+ this.multiplyDeltaMovement((double) f, 1.0D, (double) f); // Sakura - reduce movement allocations
|
|
// Paper start - remove expensive streams from here
|
|
boolean noneMatch = true;
|
|
AABB fireSearchBox = this.getBoundingBox().deflate(1.0E-6D);
|
|
@@ -2049,6 +2049,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
|
|
public void moveTo(double x, double y, double z, float yaw, float pitch) {
|
|
// Paper - cancel entity velocity if teleported
|
|
if (!preserveMotion) {
|
|
+ this.movementDirty = false; // Sakura
|
|
this.deltaMovement = Vec3.ZERO;
|
|
} else {
|
|
this.preserveMotion = false;
|
|
@@ -3451,29 +3452,33 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
|
|
}
|
|
|
|
public void onAboveBubbleCol(boolean drag) {
|
|
- Vec3 vec3d = this.getDeltaMovement();
|
|
+ // Sakura start - reduce movement allocations
|
|
+ // Vec3 vec3d = this.getDeltaMovement();
|
|
+ this.syncDeltaMovement();
|
|
double d0;
|
|
|
|
if (drag) {
|
|
- d0 = Math.max(-0.9D, vec3d.y - 0.03D);
|
|
+ d0 = Math.max(-0.9D, movementY - 0.03D);
|
|
} else {
|
|
- d0 = Math.min(1.8D, vec3d.y + 0.1D);
|
|
+ d0 = Math.min(1.8D, movementY + 0.1D);
|
|
}
|
|
|
|
- this.setDeltaMovement(vec3d.x, d0, vec3d.z);
|
|
+ this.setDeltaMovement(movementX, d0, movementZ);
|
|
}
|
|
|
|
public void onInsideBubbleColumn(boolean drag) {
|
|
- Vec3 vec3d = this.getDeltaMovement();
|
|
+ // Vec3 vec3d = this.getDeltaMovement();
|
|
+ this.syncDeltaMovement();
|
|
double d0;
|
|
|
|
if (drag) {
|
|
- d0 = Math.max(-0.3D, vec3d.y - 0.03D);
|
|
+ d0 = Math.max(-0.3D, movementY - 0.03D);
|
|
} else {
|
|
- d0 = Math.min(0.7D, vec3d.y + 0.06D);
|
|
+ d0 = Math.min(0.7D, movementY + 0.06D);
|
|
}
|
|
|
|
- this.setDeltaMovement(vec3d.x, d0, vec3d.z);
|
|
+ this.setDeltaMovement(movementX, d0, movementZ);
|
|
+ // Sakura end
|
|
this.resetFallDistance();
|
|
}
|
|
|
|
@@ -4460,16 +4465,19 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
|
|
vec3d = vec3d.normalize();
|
|
}
|
|
|
|
- Vec3 vec3d2 = this.getDeltaMovement();
|
|
+ // Sakura start - reduce movement allocations
|
|
+ // Vec3 vec3d2 = this.getDeltaMovement();
|
|
+ this.syncDeltaMovement();
|
|
|
|
vec3d = vec3d.scale(speed * 1.0D);
|
|
double d3 = 0.003D;
|
|
|
|
- if (Math.abs(vec3d2.x) < 0.003D && Math.abs(vec3d2.z) < 0.003D && vec3d.length() < 0.0045000000000000005D) {
|
|
+ if (Math.abs(movementX) < 0.003D && Math.abs(movementZ) < 0.003D && vec3d.length() < 0.0045000000000000005D) {
|
|
vec3d = vec3d.normalize().scale(0.0045000000000000005D);
|
|
}
|
|
|
|
- this.setDeltaMovement(this.getDeltaMovement().add(vec3d));
|
|
+ this.addDeltaMovement(vec3d.x, vec3d.y, vec3d.z);
|
|
+ // Sakura end
|
|
}
|
|
|
|
this.fluidHeight.put(tag, d1);
|
|
@@ -4540,11 +4548,53 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
|
|
return this.chunkPosition;
|
|
}
|
|
|
|
+ // Sakura start - reduce movement allocations
|
|
+ private double movementX;
|
|
+ private double movementY;
|
|
+ private double movementZ;
|
|
+ private boolean movementDirty;
|
|
+
|
|
+ public void addDeltaMovement(double x, double y, double z) {
|
|
+ syncDeltaMovement();
|
|
+ movementX += x;
|
|
+ movementY += y;
|
|
+ movementZ += z;
|
|
+ }
|
|
+
|
|
+ public void scaleDeltaMovement(double n) {
|
|
+ syncDeltaMovement();
|
|
+ movementX *= n;
|
|
+ movementY *= n;
|
|
+ movementZ *= n;
|
|
+ }
|
|
+
|
|
+ public void multiplyDeltaMovement(double x, double y, double z) {
|
|
+ syncDeltaMovement();
|
|
+ movementX *= x;
|
|
+ movementY *= y;
|
|
+ movementZ *= z;
|
|
+ }
|
|
+
|
|
+ private void updateDeltaMovement() {
|
|
+ if (movementDirty) {
|
|
+ deltaMovement = new Vec3(movementX, movementY, movementZ);
|
|
+ movementDirty = false;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ private void syncDeltaMovement() {
|
|
+ if (!movementDirty) {
|
|
+ setDeltaMovement(deltaMovement.x, deltaMovement.y, deltaMovement.z);
|
|
+ }
|
|
+ }
|
|
+
|
|
public Vec3 getDeltaMovement() {
|
|
+ updateDeltaMovement();
|
|
return this.deltaMovement;
|
|
}
|
|
|
|
public void setDeltaMovement(Vec3 velocity) {
|
|
+ movementDirty = false;
|
|
synchronized (this.posLock) { // Paper
|
|
this.deltaMovement = velocity;
|
|
} // Paper
|
|
@@ -4555,7 +4605,11 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
|
|
}
|
|
|
|
public void setDeltaMovement(double x, double y, double z) {
|
|
- this.setDeltaMovement(new Vec3(x, y, z));
|
|
+ movementX = x;
|
|
+ movementY = y;
|
|
+ movementZ = z;
|
|
+ movementDirty = true;
|
|
+ // Sakura end
|
|
}
|
|
|
|
public final int getBlockX() {
|
|
diff --git a/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java b/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
|
|
index 3ec931c9aa9e2857e0c24eeb47c1048ace05f6fe..ec8488a2ab16950052a3bff04be6e3ecc3b44891 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
|
|
@@ -145,7 +145,7 @@ public class FallingBlockEntity extends Entity {
|
|
|
|
++this.time;
|
|
if (!this.isNoGravity()) {
|
|
- this.setDeltaMovement(this.getDeltaMovement().add(0.0D, -0.04D, 0.0D));
|
|
+ this.addDeltaMovement(0.0D, -0.04D, 0.0D); // Sakura - reduce movement allocations
|
|
}
|
|
|
|
this.move(MoverType.SELF, this.getDeltaMovement());
|
|
@@ -192,7 +192,7 @@ public class FallingBlockEntity extends Entity {
|
|
} else {
|
|
BlockState iblockdata = this.level().getBlockState(blockposition);
|
|
|
|
- this.setDeltaMovement(this.getDeltaMovement().multiply(0.7D, -0.5D, 0.7D));
|
|
+ this.multiplyDeltaMovement(0.7D, -0.5D, 0.7D); // Sakura - reduce movement allocations
|
|
if (!iblockdata.is(Blocks.MOVING_PISTON)) {
|
|
if (!this.cancelDrop) {
|
|
boolean flag2 = iblockdata.canBeReplaced((BlockPlaceContext) (new DirectionalPlaceContext(this.level(), blockposition, Direction.DOWN, ItemStack.EMPTY, Direction.UP)));
|
|
@@ -259,7 +259,7 @@ public class FallingBlockEntity extends Entity {
|
|
}
|
|
}
|
|
|
|
- this.setDeltaMovement(this.getDeltaMovement().scale(0.98D));
|
|
+ this.scaleDeltaMovement(0.98D); // Sakura - reduce movement allocations
|
|
}
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java b/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
|
|
index 62a3cd512d473d5ed673386d5c15091a09426945..12067c0372ad2803ffa2501a8296496a9ce7b292 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
|
|
@@ -74,7 +74,7 @@ public class PrimedTnt extends Entity implements TraceableEntity {
|
|
public void tick() {
|
|
if (this.level().spigotConfig.maxTntTicksPerTick > 0 && ++this.level().spigotConfig.currentPrimedTnt > this.level().spigotConfig.maxTntTicksPerTick) { return; } // Spigot
|
|
if (!this.isNoGravity()) {
|
|
- this.setDeltaMovement(this.getDeltaMovement().add(0.0D, -0.04D, 0.0D));
|
|
+ this.addDeltaMovement(0.0D, -0.04D, 0.0D); // Sakura - reduce movement allocations
|
|
}
|
|
|
|
this.move(MoverType.SELF, this.getDeltaMovement());
|
|
@@ -84,9 +84,9 @@ public class PrimedTnt extends Entity implements TraceableEntity {
|
|
return;
|
|
}
|
|
// Paper end
|
|
- this.setDeltaMovement(this.getDeltaMovement().scale(0.98D));
|
|
+ this.scaleDeltaMovement(0.98D); // Sakura - reduce movement allocations
|
|
if (this.onGround()) {
|
|
- this.setDeltaMovement(this.getDeltaMovement().multiply(0.7D, -0.5D, 0.7D));
|
|
+ this.multiplyDeltaMovement(0.7D, -0.5D, 0.7D); // Sakura - reduce movement allocations
|
|
}
|
|
|
|
int i = this.getFuse() - 1;
|
|
diff --git a/src/main/java/net/minecraft/world/level/Explosion.java b/src/main/java/net/minecraft/world/level/Explosion.java
|
|
index 9cd244090c294927a7a92c920854d2282ea3f021..3d4a75302d72bdbe47d0efbe08c89401dbe22a87 100644
|
|
--- a/src/main/java/net/minecraft/world/level/Explosion.java
|
|
+++ b/src/main/java/net/minecraft/world/level/Explosion.java
|
|
@@ -619,10 +619,11 @@ public class Explosion {
|
|
d8 *= d13;
|
|
d9 *= d13;
|
|
d10 *= d13;
|
|
- Vec3 vec3d1 = new Vec3(d8, d9, d10);
|
|
+ // Sakura - moved down
|
|
|
|
- entity.setDeltaMovement(entity.getDeltaMovement().add(vec3d1));
|
|
+ entity.addDeltaMovement(d8, d9, d10); // Sakura reduce deltamovement allocations
|
|
if (entity instanceof Player) {
|
|
+ Vec3 vec3d1 = new Vec3(d8, d9, d10); // Sakura
|
|
Player entityhuman = (Player) entity;
|
|
|
|
if (!entityhuman.isSpectator() && (!entityhuman.isCreative() || !entityhuman.getAbilities().flying) && !level.paperConfig().environment.disableExplosionKnockback) { // Paper - Disable explosion knockback
|
|
diff --git a/src/main/java/net/minecraft/world/level/block/Block.java b/src/main/java/net/minecraft/world/level/block/Block.java
|
|
index 4d50dd92a7f3187ee1d8edb926e7c273c8156549..ec24eadbe7dd7e60c023303dc8050e3e784516a1 100644
|
|
--- a/src/main/java/net/minecraft/world/level/block/Block.java
|
|
+++ b/src/main/java/net/minecraft/world/level/block/Block.java
|
|
@@ -460,7 +460,7 @@ public class Block extends BlockBehaviour implements ItemLike {
|
|
}
|
|
|
|
public void updateEntityAfterFallOn(BlockGetter world, Entity entity) {
|
|
- entity.setDeltaMovement(entity.getDeltaMovement().multiply(1.0D, 0.0D, 1.0D));
|
|
+ entity.multiplyDeltaMovement(1.0D, 0.0D, 1.0D); // Sakura
|
|
}
|
|
|
|
public ItemStack getCloneItemStack(LevelReader world, BlockPos pos, BlockState state) {
|