mirror of
https://github.com/Samsuik/Sakura.git
synced 2025-12-19 14:59:30 +00:00
Upstream has released updates that appear to apply and compile correctly Paper Changes: PaperMC/Paper@4eda045 Backport fix for MC-296337 (Fixes #12617) (#12619) PaperMC/Paper@7ebc94c Add Registry#getTagValues (#12603) PaperMC/Paper@e87320d Fix UOE when using generateTree with pale oak (#12616) PaperMC/Paper@94f2903 Do not blow up accessing unregistered memories from API (Fixes #12618) (#12639) PaperMC/Paper@03efecf Do not fire PlayerDropItemEvent for /give command PaperMC/Paper@3527ccd feat: expose updateDemand and restock on Villager (#12608) PaperMC/Paper@320f25c fix sponge-absorb deleting chest content (#12647) PaperMC/Paper@95565e0 Add missing attribute serialization updater PaperMC/Paper@519e422 Fix infinite loop in RegionFile IO PaperMC/Paper@ba7fb23 Finish moving over to Holderable (#12646) PaperMC/Paper@39203a6 [ci skip] Publish PR API and dev bundles (#12672) PaperMC/Paper@a1b3058 Provide env environment variable and copy spigots sys prop for overriding default repository
186 lines
9.3 KiB
Diff
186 lines
9.3 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Samsuik <kfian294ma4@gmail.com>
|
|
Date: Fri, 13 Oct 2023 14:36:19 +0100
|
|
Subject: [PATCH] Optimise cannon entity movement
|
|
|
|
|
|
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
|
|
index 68e2b26835a2588a047e9ea175eb8e4912041976..98107921d7251e1b7fc621103a31afdfd3bb5af7 100644
|
|
--- a/net/minecraft/world/entity/Entity.java
|
|
+++ b/net/minecraft/world/entity/Entity.java
|
|
@@ -1169,7 +1169,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
Vec3 vec3 = this.collide(movement);
|
|
double d = vec3.lengthSqr();
|
|
if (d > 1.0E-7 || movement.lengthSqr() - d < 1.0E-7) {
|
|
- if (this.fallDistance != 0.0 && d >= 1.0) {
|
|
+ if (this.fallDistance != 0.0 && d >= 1.0 && !this.isFallingBlock) { // Sakura - optimise cannon entity movement
|
|
BlockHitResult blockHitResult = this.level()
|
|
.clip(
|
|
new ClipContext(this.position(), this.position().add(vec3), ClipContext.Block.FALLDAMAGE_RESETTING, ClipContext.Fluid.WATER, this)
|
|
@@ -1510,6 +1510,131 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
return distance;
|
|
}
|
|
|
|
+ // Sakura start - optimise cannon entity movement
|
|
+ protected final Vec3 sakura_collide(Vec3 movement) {
|
|
+ if (movement.x == 0.0 && movement.y == 0.0 && movement.z == 0.0) {
|
|
+ return movement;
|
|
+ }
|
|
+
|
|
+ List<VoxelShape> potentialCollisionsVoxel = new it.unimi.dsi.fastutil.objects.ObjectArrayList<>(0);
|
|
+ List<AABB> potentialCollisionsBB = new it.unimi.dsi.fastutil.objects.ObjectArrayList<>(4);
|
|
+ AABB currBoundingBox = this.getBoundingBox();
|
|
+
|
|
+ if (movement.lengthSqr() >= 12.0) { // axis scan on large movement
|
|
+ return this.collideAxisScan(movement, currBoundingBox, potentialCollisionsVoxel, potentialCollisionsBB);
|
|
+ } else {
|
|
+ return this.collideCube(movement, currBoundingBox, potentialCollisionsVoxel, potentialCollisionsBB);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ private Vec3 collideCube(Vec3 movement, AABB currBoundingBox, List<VoxelShape> voxelList, List<AABB> bbList) {
|
|
+ final AABB bb;
|
|
+ if (movement.x() == 0.0 && movement.z() == 0.0) {
|
|
+ if (movement.y > 0.0) {
|
|
+ bb = ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.cutUpwards(currBoundingBox, movement.y);
|
|
+ } else {
|
|
+ bb = ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.cutDownwards(currBoundingBox, movement.y);
|
|
+ }
|
|
+ } else {
|
|
+ bb = currBoundingBox.expandTowards(movement.x, movement.y, movement.z);
|
|
+ }
|
|
+ this.collectCollisions(bb, voxelList, bbList, ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.COLLISION_FLAG_CHECK_BORDER);
|
|
+ return ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.performCollisions(movement, currBoundingBox, voxelList, bbList);
|
|
+ }
|
|
+
|
|
+ private Vec3 collideAxisScan(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, int flags) {
|
|
+ // Copied from the collide method below
|
|
+ ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.getCollisionsForBlocksOrWorldBorder(
|
|
+ this.level, this, collisionBox, voxelList, bbList,
|
|
+ flags | this.getExtraCollisionFlags(), null // Sakura - load chunks on movement
|
|
+ );
|
|
+
|
|
+ ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.getEntityHardCollisions(
|
|
+ this.level, this, collisionBox, bbList, 0, null
|
|
+ );
|
|
+ }
|
|
+
|
|
+ private double scanX(AABB currBoundingBox, double x, List<VoxelShape> voxelList, List<AABB> bbList) {
|
|
+ AABB scanBox = cutBoundingBoxX(currBoundingBox, x);
|
|
+ this.collectCollisions(scanBox, voxelList, bbList, ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.COLLISION_FLAG_CHECK_BORDER);
|
|
+ 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 = cutBoundingBoxY(currBoundingBox, y);
|
|
+ this.collectCollisions(scanBox, voxelList, bbList, 0);
|
|
+ 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 = cutBoundingBoxZ(currBoundingBox, z);
|
|
+ this.collectCollisions(scanBox, voxelList, bbList, ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.COLLISION_FLAG_CHECK_BORDER);
|
|
+ z = ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.performAABBCollisionsZ(currBoundingBox, z, bbList);
|
|
+ return ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.performVoxelCollisionsZ(currBoundingBox, z, voxelList);
|
|
+ }
|
|
+
|
|
+ private static AABB cutBoundingBoxX(AABB bb, double x) {
|
|
+ if (x > 0.0) {
|
|
+ return ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.cutRight(bb, x);
|
|
+ } else {
|
|
+ return ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.cutLeft(bb, x);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ private static AABB cutBoundingBoxY(AABB bb, double y) {
|
|
+ if (y > 0.0) {
|
|
+ return ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.cutUpwards(bb, y);
|
|
+ } else {
|
|
+ return ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.cutDownwards(bb, y);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ private static AABB cutBoundingBoxZ(AABB bb, double z) {
|
|
+ if (z > 0.0) {
|
|
+ return ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.cutForwards(bb, z);
|
|
+ } else {
|
|
+ return ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.cutBackwards(bb, z);
|
|
+ }
|
|
+ }
|
|
+ // Sakura end - optimise cannon entity movement
|
|
+
|
|
// Paper start - optimise collisions
|
|
protected Vec3 collide(Vec3 movement) {
|
|
final boolean xZero = movement.x == 0.0;
|
|
diff --git a/net/minecraft/world/entity/item/FallingBlockEntity.java b/net/minecraft/world/entity/item/FallingBlockEntity.java
|
|
index 6f0b77e77186dd394b5949977e3e1a66610bc354..0dc8c7a74df21e10d3eec66682d5efc61b335e61 100644
|
|
--- a/net/minecraft/world/entity/item/FallingBlockEntity.java
|
|
+++ b/net/minecraft/world/entity/item/FallingBlockEntity.java
|
|
@@ -121,6 +121,12 @@ public class FallingBlockEntity extends Entity implements me.samsuik.sakura.enti
|
|
return itemEntity;
|
|
}
|
|
// Sakura end - merge cannon entities
|
|
+ // Sakura start - optimise cannon entity movement
|
|
+ @Override
|
|
+ protected final Vec3 collide(Vec3 movement) {
|
|
+ return this.sakura_collide(movement);
|
|
+ }
|
|
+ // Sakura end - optimise cannon entity movement
|
|
|
|
public FallingBlockEntity(EntityType<? extends FallingBlockEntity> entityType, Level level) {
|
|
super(entityType, level);
|
|
diff --git a/net/minecraft/world/entity/item/PrimedTnt.java b/net/minecraft/world/entity/item/PrimedTnt.java
|
|
index 57cfc90b3193fe8603cf10c444ae9be6dce8e584..a5fdbd843ad49a862508574c1b07a2503c019f96 100644
|
|
--- a/net/minecraft/world/entity/item/PrimedTnt.java
|
|
+++ b/net/minecraft/world/entity/item/PrimedTnt.java
|
|
@@ -83,6 +83,12 @@ public class PrimedTnt extends Entity implements TraceableEntity, me.samsuik.sak
|
|
this.mergeData.setCount(count); // Sakura - specialised explosions
|
|
}
|
|
// Sakura end - merge cannon entities
|
|
+ // Sakura start - optimise cannon entity movement
|
|
+ @Override
|
|
+ protected final net.minecraft.world.phys.Vec3 collide(net.minecraft.world.phys.Vec3 movement) {
|
|
+ return this.sakura_collide(movement);
|
|
+ }
|
|
+ // Sakura end - optimise cannon entity movement
|
|
|
|
public PrimedTnt(EntityType<? extends PrimedTnt> entityType, Level level) {
|
|
super(entityType, level);
|