mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-22 16:39:22 +00:00
Re-add Sakura: Optimise check inside blocks and traverse blocks
This commit is contained in:
@@ -1,78 +0,0 @@
|
||||
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 e0db9281f023a09d69479f28a7c8f681641f642f..cc6b6b442d72b4a974cedd8ceef710304e52ab18 100644
|
||||
--- a/net/minecraft/world/entity/Entity.java
|
||||
+++ b/net/minecraft/world/entity/Entity.java
|
||||
@@ -1701,6 +1701,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();
|
||||
@@ -1712,7 +1713,20 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
||||
aabb,
|
||||
(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 dd7e32b8b176c0f4c13e50aeed33c2c9ccba4b53..ee514d457b5c2df912daeebb5fb8b824b5496b0e 100644
|
||||
--- a/net/minecraft/world/level/BlockGetter.java
|
||||
+++ b/net/minecraft/world/level/BlockGetter.java
|
||||
@@ -215,18 +215,30 @@ public interface BlockGetter extends LevelHeightAccessor {
|
||||
static void forEachBlockIntersectedBetween(Vec3 from, Vec3 to, AABB boundingBox, BlockGetter.BlockStepVisitor stepVisitor) {
|
||||
Vec3 vec3 = to.subtract(from);
|
||||
if (!(vec3.lengthSqr() < Mth.square(0.99999F))) {
|
||||
+ // 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 : org.dreeam.leaf.util.map.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 : org.dreeam.leaf.util.map.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 : org.dreeam.leaf.util.map.BlockPosIterator.iterable(boundingBox)) { // Sakura - optimise check inside blocks
|
||||
stepVisitor.visit(blockPos, 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
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
|
||||
|
||||
Chunk cache is already removed from this patch, since we already have it in Leaf
|
||||
|
||||
The JMH benchmark of this patch can be found in SunBox's `BetterBlocksTraverse`
|
||||
|
||||
diff --git a/net/minecraft/world/entity/monster/Ghast.java b/net/minecraft/world/entity/monster/Ghast.java
|
||||
index 6f312f0b8ab60c839129ea671f2d9c128fa58e58..6ec83870c67810c7d0239ff7075549a93dc232eb 100644
|
||||
--- a/net/minecraft/world/entity/monster/Ghast.java
|
||||
+++ b/net/minecraft/world/entity/monster/Ghast.java
|
||||
@@ -331,7 +331,7 @@ public class Ghast extends Mob implements Enemy {
|
||||
AABB boundingBox = this.ghast.getBoundingBox();
|
||||
AABB aabb = boundingBox.move(delta);
|
||||
if (this.careful) {
|
||||
- for (BlockPos blockPos : BlockPos.betweenClosed(aabb.inflate(1.0))) {
|
||||
+ for (BlockPos blockPos : org.dreeam.leaf.util.list.BlockPosIterator.iterable(aabb.inflate(1.0))) { // Leaf - Sakura - optimise check inside blocks
|
||||
if (!this.blockTraversalPossible(this.ghast.level(), null, null, blockPos, false, false)) {
|
||||
return false;
|
||||
}
|
||||
diff --git a/net/minecraft/world/entity/projectile/ThrowableProjectile.java b/net/minecraft/world/entity/projectile/ThrowableProjectile.java
|
||||
index 5104636be1de4bf1dc491673cad55854a106da53..4c61f4552dc64b1347c7b8dfe9502aac11c75888 100644
|
||||
--- a/net/minecraft/world/entity/projectile/ThrowableProjectile.java
|
||||
+++ b/net/minecraft/world/entity/projectile/ThrowableProjectile.java
|
||||
@@ -93,7 +93,7 @@ public abstract class ThrowableProjectile extends Projectile {
|
||||
|
||||
private void handleFirstTickBubbleColumn() {
|
||||
if (this.firstTick) {
|
||||
- for (BlockPos blockPos : BlockPos.betweenClosed(this.getBoundingBox())) {
|
||||
+ for (BlockPos blockPos : org.dreeam.leaf.util.list.BlockPosIterator.iterable(this.getBoundingBox())) { // Leaf - Sakura - optimise check inside blocks
|
||||
BlockState blockState = this.level().getBlockState(blockPos);
|
||||
if (blockState.is(Blocks.BUBBLE_COLUMN)) {
|
||||
blockState.entityInside(this.level(), blockPos, this, InsideBlockEffectApplier.NOOP);
|
||||
diff --git a/net/minecraft/world/level/BlockGetter.java b/net/minecraft/world/level/BlockGetter.java
|
||||
index 2146efa860d8323a88f3ad365c0cdb66de42154a..eeddffbe6a47dc1a42c07f286bfec0cbde33fc17 100644
|
||||
--- a/net/minecraft/world/level/BlockGetter.java
|
||||
+++ b/net/minecraft/world/level/BlockGetter.java
|
||||
@@ -215,7 +215,7 @@ public interface BlockGetter extends LevelHeightAccessor {
|
||||
static boolean forEachBlockIntersectedBetween(Vec3 from, Vec3 to, AABB boundingBox, BlockGetter.BlockStepVisitor visitor) {
|
||||
Vec3 vec3 = to.subtract(from);
|
||||
if (vec3.lengthSqr() < Mth.square(0.99999F)) {
|
||||
- for (BlockPos blockPos : BlockPos.betweenClosed(boundingBox)) {
|
||||
+ for (BlockPos blockPos : org.dreeam.leaf.util.list.BlockPosIterator.iterable(boundingBox)) { // Leaf - Sakura - optimise check inside blocks
|
||||
if (!visitor.visit(blockPos, 0)) {
|
||||
return false;
|
||||
}
|
||||
@@ -223,6 +223,20 @@ public interface BlockGetter extends LevelHeightAccessor {
|
||||
|
||||
return true;
|
||||
} else {
|
||||
+ // Leaf start - Sakura - 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 (final BlockPos blockPos : org.dreeam.leaf.util.list.BlockPosIterator.traverseArea(vec3, boundingBox)) {
|
||||
+ if (!visitor.visit(blockPos, blockIndex++)) {
|
||||
+ return false;
|
||||
+ }
|
||||
+ }
|
||||
+ return true;
|
||||
+ }
|
||||
+ // Leaf end - Sakura - optimise check inside blocks
|
||||
LongSet set = new LongOpenHashSet();
|
||||
Vec3 minPosition = boundingBox.getMinPosition();
|
||||
Vec3 vec31 = minPosition.subtract(vec3);
|
||||
@@ -230,7 +244,7 @@ public interface BlockGetter extends LevelHeightAccessor {
|
||||
if (i < 0) {
|
||||
return false;
|
||||
} else {
|
||||
- for (BlockPos blockPos1 : BlockPos.betweenClosed(boundingBox)) {
|
||||
+ for (BlockPos blockPos1 : org.dreeam.leaf.util.list.BlockPosIterator.iterable(boundingBox)) { // Leaf - Sakura - optimise check inside blocks
|
||||
if (!set.contains(blockPos1.asLong()) && !visitor.visit(blockPos1, i + 1)) {
|
||||
return false;
|
||||
}
|
||||
@@ -703,7 +703,7 @@ index 5c1992a7fd5d7c5fe23ebfad35a828263d0ff93c..1b2c471c0509d8e77454169df8a5dc24
|
||||
// Purpur end - Configurable entity base attributes
|
||||
|
||||
diff --git a/net/minecraft/world/entity/monster/Ghast.java b/net/minecraft/world/entity/monster/Ghast.java
|
||||
index 6f312f0b8ab60c839129ea671f2d9c128fa58e58..03805ec5e766052a85446a23a5efbac3e6759f44 100644
|
||||
index 6ec83870c67810c7d0239ff7075549a93dc232eb..c249946248a5465fd9b08eac07a306ad2aee2ae6 100644
|
||||
--- a/net/minecraft/world/entity/monster/Ghast.java
|
||||
+++ b/net/minecraft/world/entity/monster/Ghast.java
|
||||
@@ -77,8 +77,8 @@ public class Ghast extends Mob implements Enemy {
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.dreeam.leaf.util.map;
|
||||
package org.dreeam.leaf.util.list;
|
||||
|
||||
import com.google.common.collect.AbstractIterator;
|
||||
import net.minecraft.core.BlockPos;
|
||||
Reference in New Issue
Block a user