mirror of
https://github.com/Samsuik/Sakura.git
synced 2025-12-28 19:29:07 +00:00
Upstream has released updates that appear to apply and compile correctly Paper Changes: PaperMC/Paper@056268e [ci skip] Correct javadoc for Weapon Component (#13096) PaperMC/Paper@a0ea729 Fix minimum tick time reporting and off thread reading PaperMC/Paper@ba2fb8c Update spark-paper dependency version (#13171) PaperMC/Paper@ce983d7 Misc fixes to tick reporting (#13174) PaperMC/Paper@9d95cd5 Use BUILD_STARTED_AT instead of Instant.now() for build timestamp (#13175) PaperMC/Paper@610f1d2 Update fill-gradle to v1.0.9 PaperMC/Paper@ffcb7b2 Update Parchment (#13177) PaperMC/Paper@c33a9ce Fix incorrect variable use in Entity#startRiding PaperMC/Paper@c710b66 Add MapPalette.getNearestColor (#13104) PaperMC/Paper@b57d641 Expose isReplaceable on BlockData (#13180) PaperMC/Paper@af1823d Reduce impact of tick time calculations (#13188) PaperMC/Paper@89ca94a [ci skip] Rebuild patches PaperMC/Paper@e5cc256 [ci skip] Update CONTRIBUTING.md for Gradle and Windows Docs (#13190) PaperMC/Paper@ab99393 Fix charged creeper explosions not dropping mob skulls (#13167)
187 lines
9.6 KiB
Diff
187 lines
9.6 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 24649fb3328a67d654795824ff7f68e93425c448..31fa5bb8a9d0076ea8072177f298f55ae3e2ee59 100644
|
|
--- a/net/minecraft/world/entity/Entity.java
|
|
+++ b/net/minecraft/world/entity/Entity.java
|
|
@@ -1203,7 +1203,7 @@ public abstract class Entity implements SyncedDataHolder, DebugValueSource, Name
|
|
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
|
|
double min = Math.min(vec3.length(), 8.0);
|
|
Vec3 vec31 = this.position().add(vec3.normalize().scale(min));
|
|
BlockHitResult blockHitResult = this.level()
|
|
@@ -1558,6 +1558,132 @@ public abstract class Entity implements SyncedDataHolder, DebugValueSource, Name
|
|
return list.isEmpty() ? distance : -Shapes.collide(Direction.Axis.Y, boundingBox, list, -distance);
|
|
}
|
|
|
|
+ // Sakura start - optimise cannon entity movement
|
|
+ protected final Vec3 sakura$collide(final Vec3 movement) {
|
|
+ if (movement.x == 0.0 && movement.y == 0.0 && movement.z == 0.0) {
|
|
+ return movement;
|
|
+ }
|
|
+
|
|
+ final List<VoxelShape> potentialCollisionsVoxel = new it.unimi.dsi.fastutil.objects.ObjectArrayList<>(0);
|
|
+ final List<AABB> potentialCollisionsBB = new it.unimi.dsi.fastutil.objects.ObjectArrayList<>(4);
|
|
+ final 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(final Vec3 movement, final AABB currBoundingBox, final List<VoxelShape> voxelList, final 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(final Vec3 movement, AABB currBoundingBox, final List<VoxelShape> voxelList, final 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 = 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(final AABB collisionBox, final List<VoxelShape> voxelList, final List<AABB> bbList, final 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(final AABB currBoundingBox, double x, final List<VoxelShape> voxelList, final List<AABB> bbList) {
|
|
+ final 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(final AABB currBoundingBox, double y, final List<VoxelShape> voxelList, final List<AABB> bbList) {
|
|
+ final 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(final AABB currBoundingBox, double z, final List<VoxelShape> voxelList, final List<AABB> bbList) {
|
|
+ final 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(final AABB bb, final 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(final AABB bb, final 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(final AABB bb, final 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 cdce0160bc4eeacfd5e7751a0d6d4192d4832c53..00d0cabd7d190e6258b595c372440b0fd06311a4 100644
|
|
--- a/net/minecraft/world/entity/item/FallingBlockEntity.java
|
|
+++ b/net/minecraft/world/entity/item/FallingBlockEntity.java
|
|
@@ -124,6 +124,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(final Vec3 movement) {
|
|
+ return this.sakura$collide(movement);
|
|
+ }
|
|
+ // Sakura end - optimise cannon entity movement
|
|
|
|
public FallingBlockEntity(EntityType<? extends FallingBlockEntity> type, Level level) {
|
|
super(type, level);
|
|
diff --git a/net/minecraft/world/entity/item/PrimedTnt.java b/net/minecraft/world/entity/item/PrimedTnt.java
|
|
index 8554e1e95d921eac7b0a6aa7afaa2b3b6e09f423..dee0b2f7ace916d9d3206b2dac166d14d62c8fde 100644
|
|
--- a/net/minecraft/world/entity/item/PrimedTnt.java
|
|
+++ b/net/minecraft/world/entity/item/PrimedTnt.java
|
|
@@ -82,6 +82,12 @@ public class PrimedTnt extends Entity implements TraceableEntity, me.samsuik.sak
|
|
this.mergeData.count = count; // Sakura - specialised explosions
|
|
}
|
|
// Sakura end - merge cannon entities
|
|
+ // Sakura start - optimise cannon entity movement
|
|
+ @Override
|
|
+ protected final net.minecraft.world.phys.Vec3 collide(final net.minecraft.world.phys.Vec3 movement) {
|
|
+ return this.sakura$collide(movement);
|
|
+ }
|
|
+ // Sakura end - optimise cannon entity movement
|
|
|
|
public PrimedTnt(EntityType<? extends PrimedTnt> type, Level level) {
|
|
super(type, level);
|