9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-19 15:09:25 +00:00
Files
Leaf/leaf-archived-patches/unapplied/mcserver/0225-Sakura-Optimise-check-inside-blocks-and-traverse-blo.patch
Dreeam 8bffdef317 More patches
Shallou - Habitat
Genre: Progressive House (maybe)
2025-09-29 14:23:25 -04:00

79 lines
4.8 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
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;
}