9
0
mirror of https://github.com/Samsuik/Sakura.git synced 2026-01-04 15:31:43 +00:00
Files
SakuraMC/patches/server/0007-Reduce-deltaMovement-Allocations.patch
Samsuik f948e10cd7 Updated Upstream (Paper)
Upstream has released updates that appear to apply and compile correctly

Paper Changes:
PaperMC/Paper@0052e2d build: Update tiny-remapper to 0.10.1 & remove unused repo from dev bundle config (#10303)
PaperMC/Paper@a0931f4 Updated Upstream (Bukkit/CraftBukkit) (#10301)
PaperMC/Paper@80e1a45 Add param to overrides to the correct method is called (#10308)
PaperMC/Paper@62b220a Allow passenger retaining teleport via end gateway (#10283)
PaperMC/Paper@ab1afb0 Fix missing profiler.pop() in PathFinder::findPath (#10320)
PaperMC/Paper@cd110a8 [ci skip] Update CONTRIBUTING.md (#10318)
PaperMC/Paper@e603486 Add onboarding message for initial server start (#10312)
PaperMC/Paper@d361a7f Fix DamageSource API (#10307)
PaperMC/Paper@99a6416 Expand Hopper BlockState API (#10328)
PaperMC/Paper@09d6dfb [ci skip] Upstream dependencies in workflow scripts. (#10338)
PaperMC/Paper@55ffcb1 Fix tripwire disarming not working as intended
PaperMC/Paper@05fe15e Fire EntityChangeBlockEvent on beehive nectar deposit (#10306)
PaperMC/Paper@de620b8 Clone mutable types in events when changes are discarded (#10333)
PaperMC/Paper@41ffa0c Expose power on fireballs (#10302)
PaperMC/Paper@88419b2 Do not copy profile data if profiles are the same (#10259)
PaperMC/Paper@9ec7dfc Move invisible setting up to entities (#10346)
PaperMC/Paper@b600140 Add methods to change entity physics (#10334)
PaperMC/Paper@00fd87a Return dummy string instead of empty optional
PaperMC/Paper@710dced [ci skip] move custom brig exception to paper package
PaperMC/Paper@45d1486 build: Update paperweight to 1.5.12 and Gradle Wrapper to 8.7 (#10361)
PaperMC/Paper@e709245 Add config option for tripwire disarming fix
PaperMC/Paper@a203544 build: Compile against and shade the filtered jar (#9747)
PaperMC/Paper@bd38e03 Updated Upstream (Bukkit/CraftBukkit) (#10379)
PaperMC/Paper@a774fba feat: Entity#teleportAsync method with TeleportFlags (#10371)
PaperMC/Paper@06361fa Fix invalid block entities created during world gen (#10375)
PaperMC/Paper@bbee11f Deprecate Bukkit#getLogger (#10388)
PaperMC/Paper@d8456ee Don't throw NPE for unplaced blockstate on #getDrops (#10366)
PaperMC/Paper@182e79b Add more item use API (#10304)
PaperMC/Paper@acf838f Backport some stuff from the generators branch (#10365)
PaperMC/Paper@3d31e45 Add BlockBreakProgressUpdateEvent (#10300)
PaperMC/Paper@8e75001 Disable vertical air friction when item entities have friction disabled (#10369)
PaperMC/Paper@241d8e2 Ignore minecart in activation range (#10359)
PaperMC/Paper@1207162 Allow player-list API to self un/list (#10358)
PaperMC/Paper@5436d44 Deprecate several Keyed#getKey methods (#10357)
PaperMC/Paper@a7f1dc6 Change online mode default for Velocity configuration (#10413)
PaperMC/Paper@37db2d7 [ci skip] Update book page/char limit for book meta doc (#10415)
PaperMC/Paper@526795b Update patches to handle vineflower decompiler (#10406)
PaperMC/Paper@8fe90de [ci skip] Referenced InventoryDragEvent in documentation of InventoryClickEvent (#10395)
PaperMC/Paper@46d462b Fix StackOverflowException thrown on shutdown (Fixes #10404) (#10408)
PaperMC/Paper@f061e76 Fix hit criteria advancement triggered before changing state (#10409)
PaperMC/Paper@3263470 Add color transition and clone functions to ParticleBuilder (#10342)
PaperMC/Paper@4445d23 Deprecate ItemStack#setType & add ItemStack#withType (#10290)
PaperMC/Paper@862299b "Downgrade" Vineflower to 1.10.1 release (#10423)
PaperMC/Paper@9e886c4 Remove dead code (LegacyResult) (#10411)
PaperMC/Paper@3b078f8 Add API for ticking fluids (#10435)
PaperMC/Paper@908b814 Fix inventory desync with PlayerLeashEntityEvent (#10436)
PaperMC/Paper@3af1346 Allow setting player list name early
PaperMC/Paper@a033033 Added chunk view API (#10398)
PaperMC/Paper@c5f68ff Add CartographyItemEvent and get/setResult for CartographyInventory (#10396)
PaperMC/Paper@fc53ff5 Add Configuration for finding Structures outside World Border (#10437)
PaperMC/Paper@a6b6ecd More Raid API (#7537)
PaperMC/Paper@f4c7d37 [ci skip] Fix javadoc typo (#10445)
2024-04-25 17:31:11 +01:00

261 lines
12 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 7e4ed21080c56961713f35e219dd592f5f717d63..5fbcdbaf4c0344dc3e8fff7bf31c2b021a0ae6cf 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -1253,7 +1253,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);
@@ -2069,6 +2069,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
public void moveTo(double x, double y, double z, float yaw, float pitch) {
// Paper start - Fix Entity Teleportation and cancel velocity if teleported
if (!preserveMotion) {
+ this.movementDirty = false; // Sakura
this.deltaMovement = Vec3.ZERO;
} else {
this.preserveMotion = false;
@@ -3473,29 +3474,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();
}
@@ -4484,16 +4489,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);
@@ -4564,11 +4572,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
@@ -4579,7 +4629,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 4f072853272bedd79bdf53d2a8373d8e0f6fdd29..91aa2714bae3f8f5d0fb76426b2b8cfc61941f54 100644
--- a/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
+++ b/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
@@ -141,7 +141,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());
@@ -181,7 +181,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)));
@@ -248,7 +248,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 2e6691b86e161616bb2dcf5ce0391ad57a3ef422..7890f84d7a69e2e6820ef0daa35f898534f7372f 100644
--- a/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
+++ b/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
@@ -75,7 +75,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());
@@ -85,9 +85,9 @@ public class PrimedTnt extends Entity implements TraceableEntity {
return;
}
// Paper end - Configurable TNT height nerf
- 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 0e20d82c11702396306c0529f92496073d986380..89942b02225a116ec883ff8a3872d4d2ca348d17 100644
--- a/src/main/java/net/minecraft/world/level/Explosion.java
+++ b/src/main/java/net/minecraft/world/level/Explosion.java
@@ -617,10 +617,11 @@ public class Explosion {
d8 *= d13;
d9 *= d13;
d10 *= d13;
- Vec3 vec3d1 = new Vec3(d8, d9, d10);
+ Vec3 vec3d1 = null; // Sakura - move allocation below living entity condition
// CraftBukkit start - Call EntityKnockbackEvent
if (entity instanceof LivingEntity) {
+ vec3d1 = new Vec3(d8, d9, d10); // Sakura
Vec3 result = entity.getDeltaMovement().add(vec3d1);
org.bukkit.event.entity.EntityKnockbackEvent event = CraftEventFactory.callEntityKnockbackEvent((org.bukkit.craftbukkit.entity.CraftLivingEntity) entity.getBukkitEntity(), this.source, org.bukkit.event.entity.EntityKnockbackEvent.KnockbackCause.EXPLOSION, d13, vec3d1, result.x, result.y, result.z);
@@ -635,9 +636,13 @@ public class Explosion {
vec3d1 = org.bukkit.craftbukkit.util.CraftVector.toNMS(paperEvent.getAcceleration());
}
// Paper end - call EntityKnockbackByEntityEvent for explosions
+ // Sakura start - reduce deltamovement allocations
+ entity.setDeltaMovement(entity.getDeltaMovement().add(vec3d1));
+ } else {
+ entity.addDeltaMovement(d8, d9, d10);
+ // Sakura end - reduce deltamovement allocations
}
// CraftBukkit end
- entity.setDeltaMovement(entity.getDeltaMovement().add(vec3d1));
if (entity instanceof Player) {
Player entityhuman = (Player) entity;
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 22036ed3ea0629bc12981a8d91a03e55cc2117d6..73a453ef678ed90ebc1de4d1efc258ad81cf36b8 100644
--- a/src/main/java/net/minecraft/world/level/block/Block.java
+++ b/src/main/java/net/minecraft/world/level/block/Block.java
@@ -469,7 +469,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) {