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 fb091042cc Updated Upstream (Paper)
Upstream has released updates that appear to apply and compile correctly

Paper Changes:
PaperMC/Paper@1e7dd72 Remove 'fix Vanilla Minecart speed' patch (#10068)
PaperMC/Paper@e7e1c8a Fix and add new scoreboard API (#10037)
PaperMC/Paper@49f9f6f Add Registry#getKey (#10066)
PaperMC/Paper@4adca3d Update to adventure 4.15 (#10045)
PaperMC/Paper@ff7b9b0 Increase default custom payload channel size limit (#10006)
PaperMC/Paper@1cda66e Hotfix Entity isInRain reobf issue
PaperMC/Paper@61768e0 [ci skip] Remove no longer needed mappings change
PaperMC/Paper@e035fd7 Updated Upstream (Bukkit/CraftBukkit/Spigot)
PaperMC/Paper@c215ce1 [ci skip] cleanup patch diff from last commit
PaperMC/Paper@4fdda9e Keep newlines in outdated client/server message (#10042)
PaperMC/Paper@f483b38 fix NPE on EntityTeleportEvent getTo (#10016)
PaperMC/Paper@dc62150 Catch async usage of playsound (#10021)
PaperMC/Paper@0d6a0c3 Fix command block async message (again) (#10082)
PaperMC/Paper@d1f507f Don't fire 2 game events for certain cauldron interactions (#8904)
PaperMC/Paper@a401585 Fix campfire recipes not always outputting full result (#8754)
PaperMC/Paper@88d28d6 Fix long loading screen when refreshing skins (#10026)
PaperMC/Paper@c081104 Add experience points api (#9688)
PaperMC/Paper@8221b08 Fix global sound event gamerule not being respected (#8727)
PaperMC/Paper@3c0d6aa Updated Upstream (Bukkit/CraftBukkit/Spigot) (#10085)
PaperMC/Paper@2c3ccb8 Add drops to shear events (#5678)
PaperMC/Paper@b2ffb1b Add PlayerShieldDisableEvent (#9177)
PaperMC/Paper@2951732 Add HiddenPotionEffect API (#9910)
PaperMC/Paper@e4ab50d Properly disallow async Player#chat (#8123)
PaperMC/Paper@5e978d3 Fix Folia scheduler tasks not canceling when plugin disable (#10091)
PaperMC/Paper@e56e53f Fix some component bugs in login disconnect packet (#10090)
PaperMC/Paper@3484ae9 Call entity_die game event after event cancel check (#10096)
PaperMC/Paper@0ae58c0 cleanup player death event adventure logic (#10095)
PaperMC/Paper@1281f4f Make region/lock shift accessors per world
PaperMC/Paper@983377b Correctly check if bucket dispenses will succeed for event (#10109)
PaperMC/Paper@58e120b [ci skip] Remove extraneous diff added in 1.20.3 update (#10101)
PaperMC/Paper@816bacc Call EntityChangeBlockEvent for cake eating (#10105)
PaperMC/Paper@692db0c fix CustomModelData being removed (#10113)
PaperMC/Paper@509876d Keep fully frozen entities fully activated (#10103)
PaperMC/Paper@1fa48d1 include relative flags in PlayerTeleportEvent (#8190)
PaperMC/Paper@ae001ae Fix untrack event not being called for all 'untracks' (#10110)
PaperMC/Paper@259bc76 Pass system properties to maven repo session (#10117)
PaperMC/Paper@b2a6d57 Validate ResourceLocation in NBT reading
PaperMC/Paper@7eaff48 [ci skip] Replace some magic values with constant references
PaperMC/Paper@19a6202 Fix experience & improvements to block events (#8067)
PaperMC/Paper@8379027 Fix cmd permission levels for command blocks (#7404)
PaperMC/Paper@a93acc4 Fix EntityChangePoseEvent being called during worldgen (#10120)
PaperMC/Paper@25a99b1 Fix BlockDestroyEvents effectBlock not being set (#10131)
PaperMC/Paper@a58e29d Fix a borked update of 'Properly handle BlockBreakEvent#isDropItems' (#10134)
PaperMC/Paper@570cfb4 Validate missed resource location parsing
PaperMC/Paper@e46276e Fixup NamespacedKey parsing
PaperMC/Paper@f1c5f01 [ci skip] Fix typo
PaperMC/Paper@07b956e Fix tests by disabling them
2024-01-08 15:03:35 +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 8562e2794fc2cc29e55d34186480e820bffe1237..b25ee7bf3ff5d8d533055f737c17e0e21b4f641a 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -1220,6 +1220,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) {
// Paper start - detailed watchdog information
io.papermc.paper.util.TickThread.ensureTickThread("Cannot move an entity off-main");
@@ -1597,6 +1686,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 java.util.ArrayList<>(8);
+ final List<VoxelShape> potentialCollisionsVoxel = new java.util.ArrayList<>(2);
+ 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 3a0d82cd7a0d7ec20138effd6d84eee60ffab788..b7f9c8a6de4c07f230f99b6bfa1332166e696b49 100644
--- a/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
+++ b/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
@@ -201,7 +201,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
// Paper start - fix sand duping
if (this.isRemoved()) {
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 1b8d43cf54999c9a005459bc59d7b5a50bb9c1ee..ebfd24f9fb90071288f0c872c0e3fbd58bb3f2b9 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
// Paper start - Configurable TNT entity height nerf
if (this.level().paperConfig().fixes.tntEntityHeightNerf.test(v -> this.getY() > v)) {
this.discard();