9
0
mirror of https://github.com/Samsuik/Sakura.git synced 2025-12-22 08:19:26 +00:00
Files
SakuraMC/patches/server/0021-Optimise-Fast-Movement.patch
Samsuik 7de1cfbc8f Updated Upstream (Paper)
Upstream has released updates that appear to apply and compile correctly

Paper Changes:
PaperMC/Paper@a80d31b Log command execution exceptions if debug=true (#10130)
PaperMC/Paper@ec19620 Use a ConcurrentHashMap for enum mappings for BlockData (#10161)
PaperMC/Paper@f28caff Limit ResourceLocation length to nbt string tag length
PaperMC/Paper@a0ffb57 [ci skip] Small cleanup to mc utils patch
PaperMC/Paper@8c8862f Also check for the actual character length in ResourceLocation validation
PaperMC/Paper@e84621a [ci skip] Add more patch identifying comments
PaperMC/Paper@c0e4697 [ci skip] Add more patch identifying comments
PaperMC/Paper@17275ff [ci skip] add more comments & move 1 hunk to correct patch
PaperMC/Paper@78fcb8e [ci skip] Update contributing guidelines to include identifying commit titles in comments (#10162)
PaperMC/Paper@8657cd9 Updated Upstream (Bukkit/CraftBukkit/Spigot) (#10164)
PaperMC/Paper@c151c95 Fixup AsyncPreLoginEvent patches
PaperMC/Paper@93a848c Readd missed line
PaperMC/Paper@f9fdedf [ci skip] Add more patch identifying comments, merge related patches
PaperMC/Paper@0ef5984 [ci skip] Add more patch identifying comments, merge related patches
PaperMC/Paper@848a396 Add mob goal generator (#9980)
PaperMC/Paper@ebf97bd [ci skip] Add more patch identifying comments
PaperMC/Paper@94807a1 [ci skip] Minor cleanup and patch merges
PaperMC/Paper@5e73c55 [ci skip] Add more identifying patch comments
PaperMC/Paper@3e20d3a [ci skip] Add more identifying patch comments
PaperMC/Paper@f61ebdc Fix issue with kick event causes being passed improperly
PaperMC/Paper@106c67a [ci skip] Add more identifying patch comments
PaperMC/Paper@cc693ce [ci skip] Add more identifying patch comments, merge related patches
PaperMC/Paper@eeb6afc [ci skip] Add more identifying patch comments, merge related patches
PaperMC/Paper@1c956ab [ci skip] Add more identifying patch comments, merge related patches
PaperMC/Paper@42e88a8 [ci skip] Add more identifying patch comments
PaperMC/Paper@8e41ef4 Add visual blockdata api for primed tnt (#10146)
PaperMC/Paper@68c3297 [ci skip] Add more identifying patch comments
PaperMC/Paper@4a98986 Add back Reduce allocation of Vec3D by entity tracker patch (#10179)
PaperMC/Paper@b48d737 Async world data IO saving (#10171)
PaperMC/Paper@8d94596 [ci skip] Add more identifying patch comments
PaperMC/Paper@f7dd304 [ci skip] Add more identifying patch comments
PaperMC/Paper@98e6d20 [ci skip] Add more identifying patch comments
PaperMC/Paper@e9e0bc1 [ci skip] Add more identifying patch comments
PaperMC/Paper@d9df6bc [ci skip] Add more patch identifying comments, cleanup
PaperMC/Paper@27cabc1 [ci skip] Add more patch identifying comments
PaperMC/Paper@684319f [ci skip] Add more patch identifying comments
PaperMC/Paper@9eb0b38 [ci skip] Add more patch identifying comments
PaperMC/Paper@25013d9 [ci skip] Move some disruptive patches back
PaperMC/Paper@484d6bf [ci skip] Move some disruptive patches back
PaperMC/Paper@52619e7 [ci skip] Add more patch identifying comments
PaperMC/Paper@e660379 [ci skip] Move some disruptive patches back
PaperMC/Paper@c57d1aa Move diffs around to compile without later ones applied
PaperMC/Paper@581b101 Add world to Entity AddTo/RemoveFrom Events (#10183)
PaperMC/Paper@24dc2bf Add BlockStateMeta#clearBlockState (#10160)
PaperMC/Paper@76da4bc Expose LootTable of DecoratedPot (#10023)
PaperMC/Paper@11645e3 [ci skip] (Mostly) finish adding identifying patch comments
PaperMC/Paper@51bef80 [ci skip] Remove removed patches
PaperMC/Paper@ad2cf68 [ci skip] Move chunk system patch back a bit
PaperMC/Paper@d405ff1 [ci skip] Fixup last commit
PaperMC/Paper@a4a08b7 [ci skip] Move chunk system patch a bit back
PaperMC/Paper@b700460 Convert average tick value in the GUI to the correct granularity
PaperMC/Paper@1831240 [ci skip] Move chunk system patch back
PaperMC/Paper@b03f255 Finish moving patches back and improving compilable state
PaperMC/Paper@bd2fd61 [ci skip] Fixup a few bad comments
PaperMC/Paper@fe53b0e Updated Upstream (Bukkit/CraftBukkit/Spigot)
PaperMC/Paper@1ed50da Fix javadoc errors, remove unused classes
PaperMC/Paper@7f7d05a [ci skip] Remove IRC link from the README (#10194)
PaperMC/Paper@ed130f1 [ci skip] clarify javadocs for Block#getDrops (#10153)
PaperMC/Paper@4643b0d Shulker duplicate event (#10135)
PaperMC/Paper@b333831 Make spawn egg colours visible (#10158)
PaperMC/Paper@0cc3a7e Disable memory reserve allocating (#10180)
PaperMC/Paper@3841722 Properly check if a loot table exists (#10190)
PaperMC/Paper@b3c8108 [ci skip] Fix incorrect documentation for BlockDropItemEvent (#10175)
PaperMC/Paper@294347b [ci skip] Cleanup events (#10202)
PaperMC/Paper@87ce7c7 Small refactor of Paper plugin context preparation
PaperMC/Paper@7f856a1 Fix sleeping pos desync
PaperMC/Paper@8bc5be8 Add missing catch
PaperMC/Paper@c5d168c More provider source fixup
PaperMC/Paper@9e171ef Improve tag parser handling, move hunks out of chunk system patch
PaperMC/Paper@934cd77 Lifecycle Event System (#9629)
PaperMC/Paper@534659e Fix NotNull locales (#10216)
PaperMC/Paper@9c04729 Add Arrow/Stinger Removal Time API (#10193)
PaperMC/Paper@69b52b4 Check for server JARs in plugin directory (#10228)
PaperMC/Paper@cbe62d9 Add Conduit API (#10195)
PaperMC/Paper@97c0120 Fix fox drops on death (#8862)
PaperMC/Paper@581fb30 itemstack expose tooltip lines (#10185)
PaperMC/Paper@99bae59 Propagate failed to bind to port error (#10235)
PaperMC/Paper@bf6e803 Fix WaterBottleSplashEvent not forwarding hit result (#10203)
PaperMC/Paper@2fa2d32 Fix possible StackOverflowError for some dispenser iteractions (#8524)
PaperMC/Paper@e6a5215 Properly track the changed item from dispense events (#8658)
PaperMC/Paper@4b58a85 Fire BlockPreDispenseEvent for droppers (#10226)
PaperMC/Paper@cde5587 Add getChunkSnapshot includeLightData parameter (#10234)
PaperMC/Paper@31699ae Updated Upstream (Bukkit/CraftBukkit) (#10242)
PaperMC/Paper@37df121 Fix BlockState being set to null for damage events (#10252)
PaperMC/Paper@7f85940 Updated Upstream (Bukkit) (#10255)
PaperMC/Paper@7ccefdc Fire entity knockback event for ownerless tnt (#7171)
PaperMC/Paper@a07d526 [ci skip] Fix JavaDoc mistake in BlockPistonRetractEvent (#10250)
PaperMC/Paper@9a66f2b [ci skip] Fix javadoc mistake in PluginMeta (#10258)
PaperMC/Paper@1964b22 Scoreboard objective number format api (#10036)
PaperMC/Paper@d95341e FluidState API (#9951)
PaperMC/Paper@351923d Run round-trip adventure codec tests with JSON, NBT, and Java ops. Use JavaOps for conversions. (#10031)
PaperMC/Paper@4939f87 Add more ResourceLocation checks, some cleanup
2024-02-20 15:26:46 +00:00

229 lines
11 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samsuik <40902469+Samsuik@users.noreply.github.com>
Date: Fri, 13 Oct 2023 14:36:19 +0100
Subject: [PATCH] Optimise Fast Movement
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 2320cbd0714294c078ec6e16c687713d28b0c174..472a411b18b27f498e3a446d2d335ff25d8da859 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -1223,6 +1223,95 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
}
// Paper end - detailed watchdog information
+ // Sakura start - stripped back movement method for basic entities
+ public void moveBasic(MoverType movementType, Vec3 movement) {
+ io.papermc.paper.util.TickThread.ensureTickThread("Cannot move an entity off-main");
+
+ if (this.noPhysics) {
+ this.setPos(this.getX() + movement.x, this.getY() + movement.y, this.getZ() + movement.z);
+ } else {
+ if (movementType == MoverType.PISTON) { // Paper
+ movement = this.limitPistonMovement(movement);
+ if (movement.equals(Vec3.ZERO)) {
+ return;
+ }
+ }
+
+ this.level().getProfiler().push("move");
+ if (this.stuckSpeedMultiplier.lengthSqr() > 1.0E-7D) {
+ movement = movement.multiply(this.stuckSpeedMultiplier);
+ this.stuckSpeedMultiplier = Vec3.ZERO;
+ this.setDeltaMovement(Vec3.ZERO);
+ }
+
+ // collideScan for optimised large movements
+ Vec3 vec3d1 = this.collideScan(movement);
+ double d0 = vec3d1.lengthSqr();
+
+ if (d0 > 1.0E-7D) {
+ // NOTE: if there are any blocks in the future that rely on fall distance make sure this is correct.
+ // The only block I am aware of is powdered snow that has a special case for falling blocks.
+ if (this.fallDistance != 0.0F && d0 >= 1.0D && !isFallingBlock) {
+ BlockHitResult movingobjectpositionblock = this.level().clip(new ClipContext(this.position(), this.position().add(vec3d1), ClipContext.Block.FALLDAMAGE_RESETTING, ClipContext.Fluid.WATER, this));
+
+ if (movingobjectpositionblock.getType() != HitResult.Type.MISS) {
+ this.resetFallDistance();
+ }
+ }
+
+ this.setPos(this.getX() + vec3d1.x, this.getY() + vec3d1.y, this.getZ() + vec3d1.z);
+ }
+
+ this.level().getProfiler().pop();
+ this.level().getProfiler().push("rest");
+ boolean flag = !Mth.equal(movement.x, vec3d1.x);
+ boolean flag1 = !Mth.equal(movement.z, vec3d1.z);
+
+ this.horizontalCollision = flag || flag1;
+ this.verticalCollision = movement.y != vec3d1.y;
+ this.verticalCollisionBelow = this.verticalCollision && movement.y < 0.0D;
+ if (this.horizontalCollision) {
+ this.minorHorizontalCollision = this.isHorizontalCollisionMinor(vec3d1);
+ } else {
+ this.minorHorizontalCollision = false;
+ }
+
+ this.setOnGroundWithKnownMovement(this.verticalCollisionBelow, vec3d1);
+ BlockPos blockposition = this.getOnPosLegacy();
+ BlockState iblockdata = this.level().getBlockState(blockposition);
+
+ this.checkFallDamage(vec3d1.y, this.onGround(), iblockdata, blockposition);
+ if (this.isRemoved()) {
+ this.level().getProfiler().pop();
+ } else {
+ if (this.horizontalCollision) {
+ Vec3 vec3d2 = this.getDeltaMovement();
+
+ this.setDeltaMovement(flag ? 0.0D : vec3d2.x, vec3d2.y, flag1 ? 0.0D : vec3d2.z);
+ }
+
+ Block block = iblockdata.getBlock();
+
+ if (movement.y != vec3d1.y) {
+ block.updateEntityAfterFallOn(this.level(), this);
+ }
+
+ if (this.onGround()) {
+ // used for slowing down entities on top of slime
+ block.stepOn(this.level(), blockposition, iblockdata, this);
+ }
+
+ this.tryCheckInsideBlocks();
+
+ float f = this.getBlockSpeedFactor();
+
+ this.multiplyDeltaMovement((double) f, 1.0D, (double) f); // Sakura - reduce movement allocations
+ this.level().getProfiler().pop();
+ }
+ }
+ }
+ // Sakura end
+
public void move(MoverType movementType, Vec3 movement) {
final Vec3 originalMovement = movement; // Paper - Expose pre-collision velocity
// Paper start - detailed watchdog information
@@ -1601,6 +1690,95 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
return offsetFactor;
}
+ // Sakura start
+ private Vec3 collideScan(Vec3 movement) {
+ if (movement.x == 0.0 && movement.y == 0.0 && movement.z == 0.0) {
+ return movement;
+ }
+
+ final boolean scan = movement.lengthSqr() >= 12.0;
+ final List<AABB> potentialCollisionsBB = new it.unimi.dsi.fastutil.objects.ObjectArrayList<>(4);
+ final List<VoxelShape> potentialCollisionsVoxel = new it.unimi.dsi.fastutil.objects.ObjectArrayList<>(1);
+ final AABB currBoundingBox = getBoundingBox();
+
+ if (scan) {
+ return scanAndCollide(movement, currBoundingBox, potentialCollisionsVoxel, potentialCollisionsBB);
+ } else {
+ final AABB bb = currBoundingBox.expandTowards(movement.x, movement.y, movement.z);
+ collectCollisions(bb, potentialCollisionsVoxel, potentialCollisionsBB);
+ return io.papermc.paper.util.CollisionUtil.performCollisions(movement, currBoundingBox, potentialCollisionsVoxel, potentialCollisionsBB);
+ }
+ }
+
+ private Vec3 scanAndCollide(Vec3 movement, AABB currBoundingBox, List<VoxelShape> voxelList, List<AABB> bbList) {
+ double x = movement.x;
+ double y = movement.y;
+ double z = movement.z;
+
+ final boolean xSmaller = Math.abs(x) < Math.abs(z);
+
+ if (y != 0.0) {
+ y = scanY(currBoundingBox, y, voxelList, bbList);
+
+ if (y != 0.0) {
+ currBoundingBox = io.papermc.paper.util.CollisionUtil.offsetY(currBoundingBox, y);
+ }
+ }
+
+ if (xSmaller && z != 0.0) {
+ z = scanZ(currBoundingBox, z, voxelList, bbList);
+
+ if (z != 0.0) {
+ currBoundingBox = io.papermc.paper.util.CollisionUtil.offsetZ(currBoundingBox, z);
+ }
+ }
+
+ if (x != 0.0) {
+ x = scanX(currBoundingBox, x, voxelList, bbList);
+
+ if (x != 0.0) {
+ currBoundingBox = io.papermc.paper.util.CollisionUtil.offsetX(currBoundingBox, x);
+ }
+ }
+
+ if (!xSmaller && z != 0.0) {
+ z = scanZ(currBoundingBox, z, voxelList, bbList);
+ }
+
+ return new Vec3(x, y, z);
+ }
+
+ private void collectCollisions(AABB collisionBox, List<VoxelShape> voxelList, List<AABB> bbList) {
+ // Copied from the collide method below
+ io.papermc.paper.util.CollisionUtil.getCollisions(
+ level, this, collisionBox, voxelList, bbList,
+ io.papermc.paper.util.CollisionUtil.COLLISION_FLAG_CHECK_BORDER | this.getExtraCollisionFlags(), // Sakura
+ null, null
+ );
+ }
+
+ private double scanX(AABB currBoundingBox, double x, List<VoxelShape> voxelList, List<AABB> bbList) {
+ AABB scanBox = currBoundingBox.expandTowards(x, 0.0, 0.0);
+ collectCollisions(scanBox, voxelList, bbList);
+ x = io.papermc.paper.util.CollisionUtil.performAABBCollisionsX(currBoundingBox, x, bbList);
+ return io.papermc.paper.util.CollisionUtil.performVoxelCollisionsX(currBoundingBox, x, voxelList);
+ }
+
+ private double scanY(AABB currBoundingBox, double y, List<VoxelShape> voxelList, List<AABB> bbList) {
+ AABB scanBox = currBoundingBox.expandTowards(0.0, y, 0.0);
+ collectCollisions(scanBox, voxelList, bbList);
+ y = io.papermc.paper.util.CollisionUtil.performAABBCollisionsY(currBoundingBox, y, bbList);
+ return io.papermc.paper.util.CollisionUtil.performVoxelCollisionsY(currBoundingBox, y, voxelList);
+ }
+
+ private double scanZ(AABB currBoundingBox, double z, List<VoxelShape> voxelList, List<AABB> bbList) {
+ AABB scanBox = currBoundingBox.expandTowards(0.0, 0.0, z);
+ collectCollisions(scanBox, voxelList, bbList);
+ z = io.papermc.paper.util.CollisionUtil.performAABBCollisionsZ(currBoundingBox, z, bbList);
+ return io.papermc.paper.util.CollisionUtil.performVoxelCollisionsZ(currBoundingBox, z, voxelList);
+ }
+ // Sakura end
+
private Vec3 collide(Vec3 movement) {
// Paper start - optimise collisions
final boolean xZero = movement.x == 0.0;
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 ff6d82fe45dd9613faebed71f7936451100848df..6a18f855d26e5a32f9bc40af5e238754a0697440 100644
--- a/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
+++ b/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
@@ -202,7 +202,7 @@ public class FallingBlockEntity extends Entity {
this.addDeltaMovement(0.0D, -0.04D, 0.0D); // Sakura - reduce movement allocations
}
- this.move(MoverType.SELF, this.getDeltaMovement());
+ this.moveBasic(MoverType.SELF, this.getDeltaMovement()); // Sakura - optimise simple entity movement
// Paper start - fix sand duping
if (this.isRemoved()) {
return;
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 a7f6100520cbcdb4851954bc1b919e232a91a464..a7ecf63d18891c61ddbdc55e74aa10da884838e8 100644
--- a/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
+++ b/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
@@ -118,7 +118,7 @@ public class PrimedTnt extends Entity implements TraceableEntity {
this.addDeltaMovement(0.0D, -0.04D, 0.0D); // Sakura - reduce movement allocations
}
- this.move(MoverType.SELF, this.getDeltaMovement());
+ this.moveBasic(MoverType.SELF, this.getDeltaMovement()); // Sakura - optimise simple entity movement
// Paper start - Configurable TNT height nerf
if (this.level().paperConfig().fixes.tntEntityHeightNerf.test(v -> this.getY() > v)) {
this.discard();