9
0
mirror of https://github.com/Samsuik/Sakura.git synced 2025-12-19 14:59:30 +00:00
Files
SakuraMC/sakura-server/minecraft-patches/features/0027-Optimise-check-inside-blocks-and-traverse-blocks.patch
Samsuik dc3793b1c6 Updated Upstream (Paper)
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
2025-06-23 10:47:22 +01:00

78 lines
4.7 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samsuik <kfian294ma4@gmail.com>
Date: Fri, 8 Nov 2024 19:35:49 +0000
Subject: [PATCH] Optimise check inside blocks and traverse blocks
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
index 6eaef984b71881bc04f835d4773f18b754e2fcd4..f5e3f2e066e257bc791254e3bf7ff6659c077d09 100644
--- a/net/minecraft/world/entity/Entity.java
+++ b/net/minecraft/world/entity/Entity.java
@@ -1880,6 +1880,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
private void checkInsideBlocks(List<Entity.Movement> movements, InsideBlockEffectApplier.StepBasedCollector stepBasedCollector) {
if (this.isAffectedByBlocks()) {
LongSet set = this.visitedBlocks;
+ final net.minecraft.world.level.chunk.ChunkAccess[] chunkCache = new net.minecraft.world.level.chunk.ChunkAccess[4]; // Sakura - optimise check inside blocks
for (Entity.Movement movement : movements) {
Vec3 vec3 = movement.from();
@@ -1895,7 +1896,20 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
this.physics, // Sakura - configure cannon physics
(pos, step) -> {
if (this.isAlive()) {
- BlockState blockState = this.level().getBlockState(pos);
+ // Sakura start - optimise check inside blocks
+ final int chunkX = pos.getX() >> 4;
+ final int chunkZ = pos.getZ() >> 4;
+ final int chunkKey = ((chunkX << 2) | chunkZ) & 3;
+ net.minecraft.world.level.chunk.ChunkAccess chunk = chunkCache[chunkKey];
+ if (chunk == null || chunk.locX != chunkX || chunk.locZ != chunkZ) {
+ chunk = this.level().getChunkIfLoadedImmediately(chunkX, chunkZ);
+ if (chunk == null) {
+ return;
+ }
+ chunkCache[chunkKey] = chunk;
+ }
+ final BlockState blockState = chunk.getBlockState(pos);
+ // Sakura end - optimise check inside blocks
if (!blockState.isAir()) {
if (set.add(pos.asLong())) {
VoxelShape entityInsideCollisionShape = blockState.getEntityInsideCollisionShape(this.level(), pos, this);
diff --git a/net/minecraft/world/level/BlockGetter.java b/net/minecraft/world/level/BlockGetter.java
index 673e07e24c0cc0bc8301a15ca028c0bd72a3439c..11f9181e5c829cff7adf4feef9a6e6942b021850 100644
--- a/net/minecraft/world/level/BlockGetter.java
+++ b/net/minecraft/world/level/BlockGetter.java
@@ -221,18 +221,30 @@ public interface BlockGetter extends LevelHeightAccessor {
Vec3 vec3 = to.subtract(from);
if ((physics == null || physics.afterOrEqual(1_21_2)) && !(vec3.lengthSqr() < Mth.square(0.99999F))) {
// Sakura end - configure cannon physics
+ // Sakura start - optimise check inside blocks
+ final boolean xZero = vec3.x() == 0.0;
+ final boolean yZero = vec3.y() == 0.0;
+ final boolean zZero = vec3.z() == 0.0;
+ if (xZero && yZero || yZero && zZero || xZero && zZero) {
+ int blockIndex = 0;
+ for (BlockPos blockPos : me.samsuik.sakura.utils.BlockPosIterator.traverseArea(vec3, boundingBox)) {
+ stepVisitor.visit(blockPos, blockIndex++);
+ }
+ return;
+ }
+ // Sakura end - optimise check inside blocks
LongSet set = new LongOpenHashSet();
Vec3 minPosition = boundingBox.getMinPosition();
Vec3 vec31 = minPosition.subtract(vec3);
int i = addCollisionsAlongTravel(set, vec31, minPosition, boundingBox, stepVisitor);
- for (BlockPos blockPos1 : BlockPos.betweenClosed(boundingBox)) {
+ for (BlockPos blockPos1 : me.samsuik.sakura.utils.BlockPosIterator.iterable(boundingBox)) { // Sakura - optimise check inside blocks
if (!set.contains(blockPos1.asLong())) {
stepVisitor.visit(blockPos1, i + 1);
}
}
} else {
- for (BlockPos blockPos : BlockPos.betweenClosed(boundingBox)) {
+ for (BlockPos blockPos : me.samsuik.sakura.utils.BlockPosIterator.iterable(boundingBox)) { // Sakura - optimise check inside blocks
stepVisitor.visit(blockPos, 0);
}
}