mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-19 15:09:25 +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: Fri, 8 Nov 2024 19:35:49 +0000
|
|
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 df4b26a6304df92f4eda27ac986ca78d5217ce6c..a4de10a32f49b7b361fc9dd1d142caeef8d7d148 100644
|
|
--- a/net/minecraft/world/entity/Entity.java
|
|
+++ b/net/minecraft/world/entity/Entity.java
|
|
@@ -1710,6 +1710,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();
|
|
@@ -1721,7 +1726,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);
|