mirror of
https://github.com/Samsuik/Sakura.git
synced 2025-12-19 14:59:30 +00:00
139 lines
8.9 KiB
Diff
139 lines
8.9 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Samsuik <kfian294ma4@gmail.com>
|
|
Date: Sun, 18 May 2025 20:42:03 +0100
|
|
Subject: [PATCH] Optimise block counting for cannon entities
|
|
|
|
|
|
diff --git a/ca/spottedleaf/moonrise/patches/collisions/CollisionUtil.java b/ca/spottedleaf/moonrise/patches/collisions/CollisionUtil.java
|
|
index c09658eb8c2824ac0c887f94771d9b467ecab8b1..992354bfc3f279946635d3a8f2bc109d4f1c8603 100644
|
|
--- a/ca/spottedleaf/moonrise/patches/collisions/CollisionUtil.java
|
|
+++ b/ca/spottedleaf/moonrise/patches/collisions/CollisionUtil.java
|
|
@@ -1943,6 +1943,7 @@ public final class CollisionUtil {
|
|
final BlockPos.MutableBlockPos mutablePos = new BlockPos.MutableBlockPos();
|
|
final CollisionContext collisionShape = new LazyEntityCollisionContext(entity);
|
|
final boolean useEntityCollisionShape = LazyEntityCollisionContext.useEntityCollisionShape(world, entity);
|
|
+ final boolean cannonEntity = entity.isFallingBlock || entity.isPrimedTNT; // Sakura - optimise block counting for cannon entities
|
|
|
|
// special cases:
|
|
if (minBlockY > maxBlockY) {
|
|
@@ -2003,15 +2004,19 @@ public final class CollisionUtil {
|
|
|
|
final boolean hasSpecial = !fullBlocks && ((BlockCountingChunkSection)section).moonrise$hasSpecialCollidingBlocks(); // Sakura - collide with non-solid blocks
|
|
final int sectionAdjust = !hasSpecial ? 1 : 0;
|
|
+ // Sakura start - optimise block counting for cannon entities
|
|
+ final boolean hasMovingBlocks = section.hasMovingPistonBlocks();
|
|
+ final int sectionAdjustCE = cannonEntity && !hasMovingBlocks || !cannonEntity && !hasSpecial ? 1 : 0;
|
|
|
|
final PalettedContainer<BlockState> blocks = section.states;
|
|
|
|
- final int minXIterate = currChunkX == minChunkX ? (minBlockX & 15) + sectionAdjust : 0;
|
|
- final int maxXIterate = currChunkX == maxChunkX ? (maxBlockX & 15) - sectionAdjust : 15;
|
|
- final int minZIterate = currChunkZ == minChunkZ ? (minBlockZ & 15) + sectionAdjust : 0;
|
|
- final int maxZIterate = currChunkZ == maxChunkZ ? (maxBlockZ & 15) - sectionAdjust : 15;
|
|
+ final int minXIterate = currChunkX == minChunkX ? (minBlockX & 15) + sectionAdjustCE : 0;
|
|
+ final int maxXIterate = currChunkX == maxChunkX ? (maxBlockX & 15) - sectionAdjustCE : 15;
|
|
+ final int minZIterate = currChunkZ == minChunkZ ? (minBlockZ & 15) + sectionAdjustCE : 0;
|
|
+ final int maxZIterate = currChunkZ == maxChunkZ ? (maxBlockZ & 15) - sectionAdjustCE : 15;
|
|
final int minYIterate = currChunkY == minChunkY ? (minBlockY & 15) + sectionAdjust : 0;
|
|
- final int maxYIterate = currChunkY == maxChunkY ? (maxBlockY & 15) - sectionAdjust : 15;
|
|
+ final int maxYIterate = currChunkY == maxChunkY ? (maxBlockY & 15) - sectionAdjustCE : 15;
|
|
+ // Sakura end - optimise block counting for cannon entities
|
|
|
|
for (int currY = minYIterate; currY <= maxYIterate; ++currY) {
|
|
final int blockY = currY | (currChunkY << 4);
|
|
diff --git a/net/minecraft/world/level/Level.java b/net/minecraft/world/level/Level.java
|
|
index 8156e920d76a92fd74b90de816aaff0ced480b5f..32171561b4cd98f1f260bf14e1ac16b0684f325f 100644
|
|
--- a/net/minecraft/world/level/Level.java
|
|
+++ b/net/minecraft/world/level/Level.java
|
|
@@ -616,6 +616,7 @@ public abstract class Level implements LevelAccessor, UUIDLookup<Entity>, AutoCl
|
|
BlockPos selected = null;
|
|
double selectedDistance = Double.MAX_VALUE;
|
|
final Vec3 entityPos = entity.position();
|
|
+ final boolean cannonEntity = entity.isFallingBlock || entity.isPrimedTNT; // Sakura - optimise block counting for cannon entities
|
|
|
|
// special cases:
|
|
if (minBlockY > maxBlockY) {
|
|
@@ -658,15 +659,19 @@ public abstract class Level implements LevelAccessor, UUIDLookup<Entity>, AutoCl
|
|
|
|
final boolean hasSpecial = ((ca.spottedleaf.moonrise.patches.block_counting.BlockCountingChunkSection)section).moonrise$hasSpecialCollidingBlocks();
|
|
final int sectionAdjust = !hasSpecial ? 1 : 0;
|
|
+ // Sakura start - optimise block counting for cannon entities
|
|
+ final boolean hasMovingBlocks = section.hasMovingPistonBlocks();
|
|
+ final int sectionAdjustCE = cannonEntity && !hasMovingBlocks || !cannonEntity && !hasSpecial ? 1 : 0;
|
|
|
|
final net.minecraft.world.level.chunk.PalettedContainer<net.minecraft.world.level.block.state.BlockState> blocks = section.states;
|
|
|
|
- final int minXIterate = currChunkX == minChunkX ? (minBlockX & 15) + sectionAdjust : 0;
|
|
- final int maxXIterate = currChunkX == maxChunkX ? (maxBlockX & 15) - sectionAdjust : 15;
|
|
- final int minZIterate = currChunkZ == minChunkZ ? (minBlockZ & 15) + sectionAdjust : 0;
|
|
- final int maxZIterate = currChunkZ == maxChunkZ ? (maxBlockZ & 15) - sectionAdjust : 15;
|
|
+ final int minXIterate = currChunkX == minChunkX ? (minBlockX & 15) + sectionAdjustCE : 0;
|
|
+ final int maxXIterate = currChunkX == maxChunkX ? (maxBlockX & 15) - sectionAdjustCE : 15;
|
|
+ final int minZIterate = currChunkZ == minChunkZ ? (minBlockZ & 15) + sectionAdjustCE : 0;
|
|
+ final int maxZIterate = currChunkZ == maxChunkZ ? (maxBlockZ & 15) - sectionAdjustCE : 15;
|
|
final int minYIterate = currChunkY == minChunkY ? (minBlockY & 15) + sectionAdjust : 0;
|
|
- final int maxYIterate = currChunkY == maxChunkY ? (maxBlockY & 15) - sectionAdjust : 15;
|
|
+ final int maxYIterate = currChunkY == maxChunkY ? (maxBlockY & 15) - sectionAdjustCE : 15;
|
|
+ // Sakura end - optimise block counting for cannon entities
|
|
|
|
for (int currY = minYIterate; currY <= maxYIterate; ++currY) {
|
|
final int blockY = currY | (currChunkY << 4);
|
|
diff --git a/net/minecraft/world/level/chunk/LevelChunkSection.java b/net/minecraft/world/level/chunk/LevelChunkSection.java
|
|
index 598e22c085e55be7a35ca6d73b8bc9f465bb6e33..ea193b58a9e49a1c33f0191285a58086be9e0dfa 100644
|
|
--- a/net/minecraft/world/level/chunk/LevelChunkSection.java
|
|
+++ b/net/minecraft/world/level/chunk/LevelChunkSection.java
|
|
@@ -47,6 +47,13 @@ public class LevelChunkSection implements ca.spottedleaf.moonrise.patches.block_
|
|
return this.tickingBlocks;
|
|
}
|
|
// Paper end - block counting
|
|
+ // Sakura start - optimise block counting for cannon entities
|
|
+ private short movingPistonBlocks;
|
|
+
|
|
+ public final boolean hasMovingPistonBlocks() {
|
|
+ return this.movingPistonBlocks != 0;
|
|
+ }
|
|
+ // Sakura end - optimise block counting for cannon entities
|
|
|
|
private LevelChunkSection(LevelChunkSection section) {
|
|
this.nonEmptyBlockCount = section.nonEmptyBlockCount;
|
|
@@ -117,6 +124,18 @@ public class LevelChunkSection implements ca.spottedleaf.moonrise.patches.block_
|
|
}
|
|
}
|
|
|
|
+ // Sakura start - optimise block counting for cannon entities
|
|
+ final boolean isMovingPistonOld = oldState.is(Blocks.MOVING_PISTON);
|
|
+ final boolean isMovingPistonNew = newState.is(Blocks.MOVING_PISTON);
|
|
+ if (isMovingPistonOld != isMovingPistonNew) {
|
|
+ if (isMovingPistonOld) {
|
|
+ --this.movingPistonBlocks;
|
|
+ } else {
|
|
+ ++this.movingPistonBlocks;
|
|
+ }
|
|
+ }
|
|
+ // Sakura end - optimise block counting for cannon entities
|
|
+
|
|
final boolean oldTicking = oldState.isRandomlyTicking();
|
|
final boolean newTicking = newState.isRandomlyTicking();
|
|
if (oldTicking != newTicking) {
|
|
@@ -192,6 +211,7 @@ public class LevelChunkSection implements ca.spottedleaf.moonrise.patches.block_
|
|
this.tickingBlockCount = (short)0;
|
|
this.tickingFluidCount = (short)0;
|
|
this.specialCollidingBlocks = (short)0;
|
|
+ this.movingPistonBlocks = (short) 0; // Sakura - optimise block counting for cannon entities
|
|
this.tickingBlocks.clear();
|
|
|
|
if (this.maybeHas((final BlockState state) -> !state.isAir())) {
|
|
@@ -220,6 +240,12 @@ public class LevelChunkSection implements ca.spottedleaf.moonrise.patches.block_
|
|
continue;
|
|
}
|
|
|
|
+ // Sakura start - optimise block counting for cannon entities
|
|
+ if (state.is(Blocks.MOVING_PISTON)) {
|
|
+ this.movingPistonBlocks += (short) paletteCount;
|
|
+ }
|
|
+ // Sakura end - optimise block counting for cannon entities
|
|
+
|
|
if (ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.isSpecialCollidingBlock(state)) {
|
|
this.specialCollidingBlocks += (short)paletteCount;
|
|
}
|