mirror of
https://github.com/Samsuik/Sakura.git
synced 2025-12-21 15:59:26 +00:00
Upstream has released updates that appear to apply and compile correctly Paper Changes: PaperMC/Paper@b4f04ff Add Plugin#getDataPath (#11080) PaperMC/Paper@05e5865 Add ItemType#getItemRarity (#11049) PaperMC/Paper@aa929d6 Call PlayerLaunchProjectileEvent for wind charge (#10911) PaperMC/Paper@8b23018 Avoid collision shapes outside world border in findFreePosition PaperMC/Paper@3b45454 Port random ticking optimisation from Moonrise PaperMC/Paper@77fcb29 Apply incremental player/level saving patch PaperMC/Paper@9fd7710 Apply automatic regionfile header recalculation patch PaperMC/Paper@b57b24d Do not try to stop main thread during watchdog shutdown PaperMC/Paper@2cd8c46 Add OMINOUS_ITEM_SPAWNER SpawnReason (#10897) PaperMC/Paper@ef96a69 Fire EntityChangeBlockEvent for weaving potion effect (#11087) PaperMC/Paper@a6ceda1 distinguish between null and empty map in API (#10829) PaperMC/Paper@506f165 Don't store removed components in multiple places (#11091) PaperMC/Paper@ceeb8c1 Disable timings by default (#11095) PaperMC/Paper@05ed6a6 Fix priority scheduling logic PaperMC/Paper@967f98a Optimise chunk tick checking during chunk tick PaperMC/Paper@00b949f Remove Moonrise utils to MCUtils, remove duplicated/unused utils PaperMC/Paper@4efd24b Remove unused chunk system hooks in MCUtils PaperMC/Paper@b653276 Finish chunk tick iteration optimisation port from Moonrise PaperMC/Paper@2df5bba Log throwable when failing to save chunk/poi/entity data PaperMC/Paper@44c3dd0 fix exact choice shapeless recipes (#10973) PaperMC/Paper@dd11ef8 Updated Upstream (Bukkit/CraftBukkit/Spigot) (#11102) PaperMC/Paper@3c8a7fe Re-add missing chunk event calls (#11104) PaperMC/Paper@a8db527 Even more cleanup of mcutil patch PaperMC/Paper@d08e8d1 Add total time to done message (#11109) PaperMC/Paper@2a39276 Add CrafterCraftEvent (#11082) PaperMC/Paper@75af62b Split rewriting flag into `paper.disableOldApiSupport` and `paper.disablePluginRemapping` (#11108) PaperMC/Paper@7ea4039 Fixup startup time log message PaperMC/Paper@e71c1df Call PlayerChunkUnloadEvent PaperMC/Paper@968bdeb Make CraftComplexRecipe extend CraftingRecipe (#11114) PaperMC/Paper@f1f01a1 Adjust done message again (#11118)
227 lines
12 KiB
Diff
227 lines
12 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 cannon entity movement
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
index 023500526ab0a42bf7cbf21e1773cf5369aa2323..00fcff6e934ec7bc7a7ba853cab4c6e69c42af99 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
@@ -1164,6 +1164,93 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
return this.moveStartZ;
|
|
}
|
|
// Paper end - detailed watchdog information
|
|
+ // Sakura start - optimise cannon entity movement; stripped back movement method
|
|
+ public final void moveStripped(MoverType movementType, Vec3 movement) {
|
|
+ ca.spottedleaf.moonrise.common.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: Every minecraft update check if there are any new blocks that make sure of fallDistance.
|
|
+ // As of 1.21 the only block is powdered snow which returns a solid collision for falling blocks.
|
|
+ if (this.fallDistance != 0.0F && d0 >= 1.0D && !this.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.setOnGroundWithMovement(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.setDeltaMovement(this.getDeltaMovement().multiply((double) f, 1.0D, (double) f));
|
|
+ this.level().getProfiler().pop();
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ // Sakura end - optimise cannon entity movement; stripped back movement method
|
|
|
|
public void move(MoverType movementType, Vec3 movement) {
|
|
final Vec3 originalMovement = movement; // Paper - Expose pre-collision velocity
|
|
@@ -1508,6 +1595,95 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
return offsetFactor;
|
|
}
|
|
|
|
+ // Sakura start - optimise cannon entity movement
|
|
+ private Vec3 collideScan(Vec3 movement) {
|
|
+ if (movement.x == 0.0 && movement.y == 0.0 && movement.z == 0.0) {
|
|
+ return movement;
|
|
+ }
|
|
+
|
|
+ boolean scan = movement.lengthSqr() >= 12.0;
|
|
+ List<AABB> potentialCollisionsBB = new it.unimi.dsi.fastutil.objects.ObjectArrayList<>(4);
|
|
+ List<VoxelShape> potentialCollisionsVoxel = new it.unimi.dsi.fastutil.objects.ObjectArrayList<>(1);
|
|
+ AABB currBoundingBox = getBoundingBox();
|
|
+
|
|
+ if (scan) {
|
|
+ return this.scanAndCollide(movement, currBoundingBox, potentialCollisionsVoxel, potentialCollisionsBB);
|
|
+ } else {
|
|
+ AABB bb = currBoundingBox.expandTowards(movement.x, movement.y, movement.z);
|
|
+ this.collectCollisions(bb, potentialCollisionsVoxel, potentialCollisionsBB);
|
|
+ return ca.spottedleaf.moonrise.patches.collisions.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;
|
|
+
|
|
+ boolean xSmaller = Math.abs(x) < Math.abs(z);
|
|
+
|
|
+ if (y != 0.0) {
|
|
+ y = this.scanY(currBoundingBox, y, voxelList, bbList);
|
|
+
|
|
+ if (y != 0.0) {
|
|
+ currBoundingBox = ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.offsetY(currBoundingBox, y);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ if (xSmaller && z != 0.0) {
|
|
+ z = this.scanZ(currBoundingBox, z, voxelList, bbList);
|
|
+
|
|
+ if (z != 0.0) {
|
|
+ currBoundingBox = ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.offsetZ(currBoundingBox, z);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ if (x != 0.0) {
|
|
+ x = this.scanX(currBoundingBox, x, voxelList, bbList);
|
|
+
|
|
+ if (x != 0.0) {
|
|
+ currBoundingBox = ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.offsetX(currBoundingBox, x);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ if (!xSmaller && z != 0.0) {
|
|
+ z = this.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
|
|
+ ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.getCollisions(
|
|
+ this.level, this, collisionBox, voxelList, bbList,
|
|
+ ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.COLLISION_FLAG_CHECK_BORDER | this.getExtraCollisionFlags(), // Sakura - load chunks on movement
|
|
+ null, null
|
|
+ );
|
|
+ }
|
|
+
|
|
+ private double scanX(AABB currBoundingBox, double x, List<VoxelShape> voxelList, List<AABB> bbList) {
|
|
+ AABB scanBox = currBoundingBox.expandTowards(x, 0.0, 0.0);
|
|
+ this.collectCollisions(scanBox, voxelList, bbList);
|
|
+ x = ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.performAABBCollisionsX(currBoundingBox, x, bbList);
|
|
+ return ca.spottedleaf.moonrise.patches.collisions.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);
|
|
+ this.collectCollisions(scanBox, voxelList, bbList);
|
|
+ y = ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.performAABBCollisionsY(currBoundingBox, y, bbList);
|
|
+ return ca.spottedleaf.moonrise.patches.collisions.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);
|
|
+ this.collectCollisions(scanBox, voxelList, bbList);
|
|
+ z = ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.performAABBCollisionsZ(currBoundingBox, z, bbList);
|
|
+ return ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.performVoxelCollisionsZ(currBoundingBox, z, voxelList);
|
|
+ }
|
|
+ // Sakura end - optimise cannon entity movement
|
|
+
|
|
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 19eed968884f79a7982d96ae8c3c378f00afbdf9..cc5ef63a99a18f093f600612bf972cf50722e3a5 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
|
|
@@ -204,7 +204,7 @@ public class FallingBlockEntity extends Entity implements me.samsuik.sakura.enti
|
|
|
|
++this.time;
|
|
this.applyGravity();
|
|
- this.move(MoverType.SELF, this.getDeltaMovement());
|
|
+ this.moveStripped(MoverType.SELF, this.getDeltaMovement()); // Sakura - optimise cannon 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 e048542cdd1fe9c807ce21e57af9cf59b4adb33f..fdbc990af4190f93f207c3309cf9f89613092c0a 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
|
|
@@ -124,7 +124,7 @@ public class PrimedTnt extends Entity implements TraceableEntity, me.samsuik.sak
|
|
if (this.level().spigotConfig.maxTntTicksPerTick > 0 && ++this.level().spigotConfig.currentPrimedTnt > this.level().spigotConfig.maxTntTicksPerTick) { return; } // Spigot
|
|
this.handlePortal();
|
|
this.applyGravity();
|
|
- this.move(MoverType.SELF, this.getDeltaMovement());
|
|
+ this.moveStripped(MoverType.SELF, this.getDeltaMovement()); // Sakura - optimise cannon 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);
|