mirror of
https://github.com/Samsuik/Sakura.git
synced 2025-12-22 16:29:16 +00:00
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)
229 lines
11 KiB
Diff
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 c518dc036459b925e384fed8cdf81d89b081a19e..11b137cad5455a46064fafe73fd0ab60ffb537a3 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
@@ -1236,6 +1236,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
|
|
@@ -1614,6 +1703,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 7a1cc86185b9f4b6aa82cb2dd92500063b9f0736..0e60e3f694dd4d52ce92290148ff043e834d7c4c 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
|
|
@@ -198,7 +198,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 - Configurable falling blocks height nerf
|
|
if (this.level().paperConfig().fixes.fallingBlockHeightNerf.test(v -> this.getY() > v)) {
|
|
if (this.dropItem && this.level().getGameRules().getBoolean(GameRules.RULE_DOENTITYDROPS)) {
|
|
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 2800af98260ebdab107466c596d2ec8cba6088fe..7ff11a09234606508dac8347af281885b0a1f7e1 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
|
|
@@ -119,7 +119,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(EntityRemoveEvent.Cause.OUT_OF_WORLD);
|