9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2026-01-06 15:51:31 +00:00

Re-add Sakura: Optimise check inside blocks and traverse blocks

This commit is contained in:
Dreeam
2025-08-14 22:37:10 +08:00
parent a74b57b875
commit a1b39f41d6
51 changed files with 80 additions and 80 deletions

View File

@@ -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;
}

View File

@@ -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 {

View File

@@ -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;