mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-30 20:39:21 +00:00
70 lines
3.9 KiB
Diff
70 lines
3.9 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Samsuik <kfian294ma4@gmail.com>
|
|
Date: Thu, 1 May 2025 22:38:48 +0200
|
|
Subject: [PATCH] Sakura: Optimise-check-inside-blocks-and-traverse-blocks
|
|
|
|
Dreeam TODO: refactor checkinsideblcoks
|
|
|
|
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
|
|
index 4221e5322fa3a3ff6ab53946aa71d54144d2c4b2..4474639b0411236e208c542973084864365c544c 100644
|
|
--- a/net/minecraft/world/entity/Entity.java
|
|
+++ b/net/minecraft/world/entity/Entity.java
|
|
@@ -1670,6 +1670,11 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
private void checkInsideBlocks(List<Entity.Movement> movements, Set<BlockState> blocksInside) {
|
|
if (this.isAffectedByBlocks()) {
|
|
LongSet set = this.visitedBlocks;
|
|
+ // Sakura start - optimise check inside blocks
|
|
+ int lastChunkX = Integer.MIN_VALUE;
|
|
+ int lastChunkZ = Integer.MIN_VALUE;
|
|
+ net.minecraft.world.level.chunk.ChunkAccess chunk = null;
|
|
+ // Sakura end - optimise check inside blocks
|
|
|
|
for (Entity.Movement movement : movements) {
|
|
Vec3 vec3 = movement.from();
|
|
@@ -1681,7 +1686,19 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
return;
|
|
}
|
|
|
|
- BlockState blockState = this.level().getBlockState(blockPos);
|
|
+ // Sakura start - optimise check inside blocks
|
|
+ final int chunkX = blockPos.getX() >> 4;
|
|
+ final int chunkZ = blockPos.getZ() >> 4;
|
|
+ if (chunk == null || chunkX != lastChunkX || chunkZ != lastChunkZ) {
|
|
+ chunk = this.level.getChunkIfLoadedImmediately(chunkX, chunkZ);
|
|
+ if (chunk == null) {
|
|
+ continue;
|
|
+ }
|
|
+ lastChunkX = chunkX;
|
|
+ lastChunkZ = chunkZ;
|
|
+ }
|
|
+ final BlockState blockState = chunk.getBlockState(blockPos);
|
|
+ // Sakura end - optimise check inside blocks
|
|
if (!blockState.isAir() && set.add(blockPos.asLong())) {
|
|
try {
|
|
VoxelShape entityInsideCollisionShape = blockState.getEntityInsideCollisionShape(this.level(), blockPos);
|
|
diff --git a/net/minecraft/world/level/BlockGetter.java b/net/minecraft/world/level/BlockGetter.java
|
|
index 91865d7e78e15cc643a65de03045b90a52d6ec2a..03f82e60528738e89f195cfc59094f53156f5370 100644
|
|
--- a/net/minecraft/world/level/BlockGetter.java
|
|
+++ b/net/minecraft/world/level/BlockGetter.java
|
|
@@ -214,10 +214,18 @@ public interface BlockGetter extends LevelHeightAccessor {
|
|
|
|
static Iterable<BlockPos> boxTraverseBlocks(Vec3 oldPosition, Vec3 position, AABB boundingBox) {
|
|
Vec3 vec3 = position.subtract(oldPosition);
|
|
- Iterable<BlockPos> iterable = BlockPos.betweenClosed(boundingBox);
|
|
+ // Sakura start - optimise check inside blocks
|
|
if (vec3.lengthSqr() < Mth.square(0.99999F)) {
|
|
- return iterable;
|
|
+ return org.dreeam.leaf.util.map.BlockPosIterator.iterable(boundingBox);
|
|
} else {
|
|
+ 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) {
|
|
+ return org.dreeam.leaf.util.map.BlockPosIterator.traverseArea(vec3, boundingBox);
|
|
+ }
|
|
+ Iterable<BlockPos> iterable = BlockPos.betweenClosed(boundingBox);
|
|
+ // Sakura end - optimise check inside blocks
|
|
Set<BlockPos> set = new ObjectLinkedOpenHashSet<>();
|
|
Vec3 minPosition = boundingBox.getMinPosition();
|
|
Vec3 vec31 = minPosition.subtract(vec3);
|