mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2026-01-04 15:41:40 +00:00
Apply some
This commit is contained in:
@@ -3,6 +3,8 @@ From: Martijn Muijsers <martijnmuijsers@live.nl>
|
||||
Date: Sun, 25 Dec 2022 20:29:03 +0100
|
||||
Subject: [PATCH] Skip unnecessary mob spawning computations
|
||||
|
||||
Removed since Leaf 1.21.5, can be replaced by other optimizations
|
||||
|
||||
License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
|
||||
Gale - https://galemc.org
|
||||
|
||||
@@ -3,6 +3,7 @@ From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
|
||||
Date: Tue, 27 Aug 2024 22:53:08 -0400
|
||||
Subject: [PATCH] Don't spawn if lastSpawnState is null
|
||||
|
||||
Removed since Leaf 1.21.5, uesless
|
||||
|
||||
diff --git a/net/minecraft/server/level/ServerChunkCache.java b/net/minecraft/server/level/ServerChunkCache.java
|
||||
index 6c031f6b1d9c762c8ce7c39a002f9f151347d3a1..6735f9e23c8972b7cf1438a2f3b49d780c1ff78c 100644
|
||||
@@ -1,56 +0,0 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Taiyou06 <kaandindar21@gmail.com>
|
||||
Date: Fri, 21 Feb 2025 15:06:55 +0100
|
||||
Subject: [PATCH] Bulk writes to writeLongArray during chunk loading
|
||||
|
||||
|
||||
diff --git a/net/minecraft/network/FriendlyByteBuf.java b/net/minecraft/network/FriendlyByteBuf.java
|
||||
index abb0141426fd716e79a947b9498a8351daa342fc..6971f93c3f6008f2c2f99fc52e2a3058fd8b7659 100644
|
||||
--- a/net/minecraft/network/FriendlyByteBuf.java
|
||||
+++ b/net/minecraft/network/FriendlyByteBuf.java
|
||||
@@ -341,10 +341,43 @@ public class FriendlyByteBuf extends ByteBuf {
|
||||
|
||||
public FriendlyByteBuf writeLongArray(long[] array) {
|
||||
this.writeVarInt(array.length);
|
||||
+ // Leaf start - Bulk writes to writeLongArray during chunk loading
|
||||
+ if (array.length == 0) {
|
||||
+ return this;
|
||||
+ }
|
||||
+ int neededBytes = array.length * Long.BYTES;
|
||||
+ int maxWritableBytes = this.source.maxWritableBytes();
|
||||
+
|
||||
+ if (maxWritableBytes >= neededBytes) {
|
||||
+ this.source.ensureWritable(neededBytes);
|
||||
+ int writerIndex = this.source.writerIndex();
|
||||
+
|
||||
+ if (this.source.hasArray()) {
|
||||
+ byte[] dest = this.source.array();
|
||||
+ int offset = this.source.arrayOffset() + writerIndex;
|
||||
+
|
||||
+ ByteBuffer buf = ByteBuffer.wrap(dest, offset, neededBytes).order(this.source.order());
|
||||
+ buf.asLongBuffer().put(array);
|
||||
|
||||
- for (long l : array) {
|
||||
- this.writeLong(l);
|
||||
+ this.source.writerIndex(writerIndex + neededBytes);
|
||||
+ } else if (this.source.nioBufferCount() > 0) {
|
||||
+ ByteBuffer nioBuf = this.source.nioBuffer(writerIndex, neededBytes);
|
||||
+ nioBuf.asLongBuffer().put(array);
|
||||
+ this.source.writerIndex(writerIndex + neededBytes);
|
||||
+ } else {
|
||||
+ ByteBuffer temp = ByteBuffer.allocate(neededBytes).order(this.source.order());
|
||||
+ temp.asLongBuffer().put(array);
|
||||
+ temp.rewind();
|
||||
+ this.source.writeBytes(temp);
|
||||
+ }
|
||||
+ } else {
|
||||
+ // Not enough space even at max capacity, use traditional approach
|
||||
+ // which will write each element individually (and handle growing the buffer as needed)
|
||||
+ for (long l : array) {
|
||||
+ this.writeLong(l);
|
||||
+ }
|
||||
}
|
||||
+ // Leaf end - Bulk writes to writeLongArray during chunk loading
|
||||
|
||||
return this;
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
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);
|
||||
@@ -1,83 +0,0 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Yive <6853318+Yive@users.noreply.github.com>
|
||||
Date: Tue, 11 Jul 2023 13:27:01 -0700
|
||||
Subject: [PATCH] Pluto: Check if the cactus can even survive being placed
|
||||
|
||||
Original license: GPLv3
|
||||
Original project: https://github.com/Yive/Pluto
|
||||
|
||||
Results at 3,000 randomTickSpeed and 24,448 cacti:
|
||||
|
||||
check-survival-before-growth - false & doTileDrop - true: 48mspt
|
||||
check-survival-before-growth - true & doTileDrop - true: 25mspt
|
||||
check-survival-before-growth - false & doTileDrop - false: 18mspt
|
||||
check-survival-before-growth - true & doTileDrop - false: 6mspt
|
||||
|
||||
Setting the gamerule "doTileDrop" to false was to simulate a server that has chunk collectors.
|
||||
|
||||
Note: This might increase the item output of a cacti farm, though in theory it should act the same as vanilla.
|
||||
|
||||
diff --git a/net/minecraft/world/level/block/CactusBlock.java b/net/minecraft/world/level/block/CactusBlock.java
|
||||
index 079b4c95cf81119ca99daeb159aefca389afed74..8fe29455d7ae44f43c663718d38ea2d8cf639797 100644
|
||||
--- a/net/minecraft/world/level/block/CactusBlock.java
|
||||
+++ b/net/minecraft/world/level/block/CactusBlock.java
|
||||
@@ -49,10 +49,15 @@ public class CactusBlock extends Block implements BonemealableBlock { // Purpur
|
||||
@Override
|
||||
protected void randomTick(BlockState state, ServerLevel level, BlockPos pos, RandomSource random) {
|
||||
BlockPos blockPos = pos.above();
|
||||
- if (level.isEmptyBlock(blockPos)) {
|
||||
+ // Pluto start - Decrease chunk/block lookups
|
||||
+ net.minecraft.world.level.chunk.LevelChunk chunk = level.getChunkIfLoaded(blockPos);
|
||||
+ if (chunk == null) return;
|
||||
+
|
||||
+ if (chunk.getBlockState(blockPos).isAir()) {
|
||||
+ // Pluto end - Decrease chunk/block lookups
|
||||
int i = 1;
|
||||
|
||||
- while (level.getBlockState(pos.below(i)).is(this)) {
|
||||
+ while (chunk.getBlockState(pos.below(i)).is(this)) { // Pluto - Decrease chunk/block lookups
|
||||
i++;
|
||||
}
|
||||
|
||||
@@ -61,11 +66,28 @@ public class CactusBlock extends Block implements BonemealableBlock { // Purpur
|
||||
|
||||
int modifier = level.spigotConfig.cactusModifier; // Spigot - SPIGOT-7159: Better modifier resolution
|
||||
if (ageValue >= 15 || (modifier != 100 && random.nextFloat() < (modifier / (100.0f * 16)))) { // Spigot - SPIGOT-7159: Better modifier
|
||||
+ // Pluto start - Check if the cactus can even survive being placed
|
||||
+ if (org.dreeam.leaf.config.modules.opt.CheckSurvivalBeforeGrowth.cactusCheckSurvivalBeforeGrowth && !canSurvive(level, blockPos)) {
|
||||
+ level.levelEvent(LevelEvent.PARTICLES_DESTROY_BLOCK, blockPos, Block.getId(state));
|
||||
+ // We're going to fake the block breaking to match vanilla standards.
|
||||
+ for (net.minecraft.world.item.ItemStack drop : Block.getDrops(state, level, pos, null)) { // Use base cactus since we don't place a block
|
||||
+ Block.popResource(level, blockPos, drop);
|
||||
+ }
|
||||
+ level.setBlock(pos, state.setValue(CactusBlock.AGE, 0), Block.UPDATE_CLIENTS | Block.UPDATE_KNOWN_SHAPE);
|
||||
+ return;
|
||||
+ }
|
||||
+ // Pluto end - Check if the cactus can even survive being placed
|
||||
org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockGrowEvent(level, blockPos, this.defaultBlockState()); // CraftBukkit
|
||||
BlockState blockState = state.setValue(AGE, Integer.valueOf(0));
|
||||
level.setBlock(pos, blockState, 4);
|
||||
level.neighborChanged(blockState, blockPos, this, null, false);
|
||||
} else if (modifier == 100 || random.nextFloat() < (modifier / (100.0f * 16))) { // Spigot - SPIGOT-7159: Better modifier resolution
|
||||
+ // Pluto start - Check if the cactus can even survive being placed
|
||||
+ if (org.dreeam.leaf.config.modules.opt.CheckSurvivalBeforeGrowth.cactusCheckSurvivalBeforeGrowth) {
|
||||
+ level.setBlock(pos, state.setValue(CactusBlock.AGE, ageValue + 1), Block.UPDATE_CLIENTS | Block.UPDATE_KNOWN_SHAPE);
|
||||
+ return;
|
||||
+ }
|
||||
+ // Pluto end - Check if the cactus can even survive being placed
|
||||
level.setBlock(pos, state.setValue(AGE, Integer.valueOf(ageValue + 1)), 4);
|
||||
}
|
||||
}
|
||||
@@ -102,6 +124,12 @@ public class CactusBlock extends Block implements BonemealableBlock { // Purpur
|
||||
|
||||
@Override
|
||||
protected boolean canSurvive(BlockState state, LevelReader level, BlockPos pos) {
|
||||
+ // Pluto start - Check if the cactus can even survive being placed
|
||||
+ return canSurvive(level, pos);
|
||||
+ }
|
||||
+
|
||||
+ protected boolean canSurvive(LevelReader level, BlockPos pos) {
|
||||
+ // Pluto end - Check if the cactus can even survive being placed
|
||||
for (Direction direction : Direction.Plane.HORIZONTAL) {
|
||||
BlockState blockState = level.getBlockState(pos.relative(direction));
|
||||
if ((level.getWorldBorder().world.purpurConfig.cactusBreaksFromSolidNeighbors && blockState.isSolid()) || level.getFluidState(pos.relative(direction)).is(FluidTags.LAVA)) { // Purpur - Cactus breaks from solid neighbors config
|
||||
@@ -11,7 +11,7 @@ The "distanceToSqr" call is a bit expensive, so avoiding it is pretty nice, arou
|
||||
We could also check if the x,y,z coordinates are equal, but for now, let's just keep the identity check, which also helps us since Minecraft's code does reuse the original delta movement Vec3 object
|
||||
|
||||
diff --git a/net/minecraft/server/level/ServerEntity.java b/net/minecraft/server/level/ServerEntity.java
|
||||
index 0db57c334bef3b6473ae1b734f953e150862eab5..27e8c6a61cfa30b4e5bcc8ac30b0023940d9f310 100644
|
||||
index 7fe21b10eefce56dde19baebf9cb6d2d0a8d73ec..b3fe9ea70148cdbefbdb617abaf81fe48ee26685 100644
|
||||
--- a/net/minecraft/server/level/ServerEntity.java
|
||||
+++ b/net/minecraft/server/level/ServerEntity.java
|
||||
@@ -211,6 +211,7 @@ public class ServerEntity {
|
||||
@@ -0,0 +1,61 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Taiyou06 <kaandindar21@gmail.com>
|
||||
Date: Fri, 21 Feb 2025 15:06:55 +0100
|
||||
Subject: [PATCH] Bulk writes to writeLongArray during chunk loading
|
||||
|
||||
|
||||
diff --git a/net/minecraft/network/FriendlyByteBuf.java b/net/minecraft/network/FriendlyByteBuf.java
|
||||
index 76576f2fd8b267d96186ab337bf4e41520e3cd18..8cfe865c0e1ef097846113342660fe26ecc20783 100644
|
||||
--- a/net/minecraft/network/FriendlyByteBuf.java
|
||||
+++ b/net/minecraft/network/FriendlyByteBuf.java
|
||||
@@ -360,6 +360,50 @@ public class FriendlyByteBuf extends ByteBuf {
|
||||
}
|
||||
}
|
||||
|
||||
+ // Leaf start - Bulk writes to writeLongArray during chunk loading
|
||||
+ public static void writeLongArray(FriendlyByteBuf buffer, long[] array) {
|
||||
+ VarInt.write(buffer, array.length);
|
||||
+ writeFixedSizeLongArray(buffer, array);
|
||||
+ }
|
||||
+
|
||||
+ public static void writeFixedSizeLongArray(FriendlyByteBuf buffer, long[] array) {
|
||||
+ if (array.length == 0) {
|
||||
+ return;
|
||||
+ }
|
||||
+ int neededBytes = array.length * Long.BYTES;
|
||||
+ int maxWritableBytes = buffer.source.maxWritableBytes();
|
||||
+
|
||||
+ if (maxWritableBytes >= neededBytes) {
|
||||
+ buffer.source.ensureWritable(neededBytes);
|
||||
+ int writerIndex = buffer.source.writerIndex();
|
||||
+
|
||||
+ if (buffer.source.hasArray()) {
|
||||
+ byte[] dest = buffer.source.array();
|
||||
+ int offset = buffer.source.arrayOffset() + writerIndex;
|
||||
+
|
||||
+ ByteBuffer buf = ByteBuffer.wrap(dest, offset, neededBytes).order(buffer.source.order());
|
||||
+ buf.asLongBuffer().put(array);
|
||||
+ buffer.source.writerIndex(writerIndex + neededBytes);
|
||||
+ } else if (buffer.source.nioBufferCount() > 0) {
|
||||
+ ByteBuffer nioBuf = buffer.source.nioBuffer(writerIndex, neededBytes);
|
||||
+ nioBuf.asLongBuffer().put(array);
|
||||
+ buffer.source.writerIndex(writerIndex + neededBytes);
|
||||
+ } else {
|
||||
+ ByteBuffer temp = ByteBuffer.allocate(neededBytes).order(buffer.source.order());
|
||||
+ temp.asLongBuffer().put(array);
|
||||
+ temp.rewind();
|
||||
+ buffer.source.writeBytes(temp);
|
||||
+ }
|
||||
+ } else {
|
||||
+ // Not enough space even at max capacity, use traditional approach
|
||||
+ // which will write each element individually (and handle growing the buffer as needed)
|
||||
+ for (long l : array) {
|
||||
+ buffer.writeLong(l);
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ // Leaf end - Bulk writes to writeLongArray during chunk loading
|
||||
+
|
||||
public long[] readLongArray() {
|
||||
return readLongArray(this);
|
||||
}
|
||||
@@ -230,7 +230,7 @@ index fb5077450aa9f7b7a03dd20c27a68dfdaab5ef06..f37fd3b9ab725e5b8eb7fccf9b35bbc0
|
||||
player.getInventory().removeItem(ammo);
|
||||
}
|
||||
diff --git a/net/minecraft/world/level/Level.java b/net/minecraft/world/level/Level.java
|
||||
index 817cc2e4f311a626681d94b748a01ae2e3048445..e47e4d11e7dcd8cb4ab6ef965d8b16e6396d2856 100644
|
||||
index 22da84734462d09a55bc599db4374e1e4f4d6bd2..2f679f03360a2847ba3d98a6698b7c0210a0b67e 100644
|
||||
--- a/net/minecraft/world/level/Level.java
|
||||
+++ b/net/minecraft/world/level/Level.java
|
||||
@@ -170,6 +170,7 @@ public abstract class Level implements LevelAccessor, UUIDLookup<Entity>, AutoCl
|
||||
@@ -8,7 +8,7 @@ Integrated with Imanity Software's Raytrace AntiXray for better performance
|
||||
Original project: https://github.com/Imanity-Software/raytrace-antixray-spigot-sdk
|
||||
|
||||
diff --git a/net/minecraft/server/level/ServerPlayerGameMode.java b/net/minecraft/server/level/ServerPlayerGameMode.java
|
||||
index d1f74d10e5e3d65895d7e87dd77f298cd9689b33..8fdc5ab8bfba0e40cedfac64d6bc5e24d1cca969 100644
|
||||
index 3a596650feb96123c5684bb5065e20c5b005c0b9..f7a05fd098ef7b303254cd410414d50d68225395 100644
|
||||
--- a/net/minecraft/server/level/ServerPlayerGameMode.java
|
||||
+++ b/net/minecraft/server/level/ServerPlayerGameMode.java
|
||||
@@ -296,6 +296,12 @@ public class ServerPlayerGameMode {
|
||||
@@ -25,7 +25,7 @@ index d1f74d10e5e3d65895d7e87dd77f298cd9689b33..8fdc5ab8bfba0e40cedfac64d6bc5e24
|
||||
}
|
||||
|
||||
diff --git a/net/minecraft/world/level/Level.java b/net/minecraft/world/level/Level.java
|
||||
index e47e4d11e7dcd8cb4ab6ef965d8b16e6396d2856..20be5c4200bfee01d62fa1103a3663b91107d5d8 100644
|
||||
index 2f679f03360a2847ba3d98a6698b7c0210a0b67e..309dbb3b7a485ef5e13f893e53bbdbec1401422e 100644
|
||||
--- a/net/minecraft/world/level/Level.java
|
||||
+++ b/net/minecraft/world/level/Level.java
|
||||
@@ -1174,6 +1174,12 @@ public abstract class Level implements LevelAccessor, UUIDLookup<Entity>, AutoCl
|
||||
@@ -5,7 +5,7 @@ Subject: [PATCH] Micro optimizations for random tick
|
||||
|
||||
|
||||
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
|
||||
index 7ca4fd418599cdb1bb1de44f4c3c57f1770a4038..461b620b703c9fca2691f724a9b865ad54aa90a4 100644
|
||||
index c6eb136e8db0aa232681ac9bd28c4b70fbbacb40..1346cff0018e6d17cb892892c3aeebfb86453b60 100644
|
||||
--- a/net/minecraft/server/level/ServerLevel.java
|
||||
+++ b/net/minecraft/server/level/ServerLevel.java
|
||||
@@ -903,7 +903,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
||||
@@ -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
|
||||
|
||||
Dreeam TODO: refactor checkinsideblcoks
|
||||
|
||||
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
|
||||
index 1db32873588673900a8afa9767c3af12c7b6742a..5d1027cb511be78b1e29d0e3bdc49cc9d6add346 100644
|
||||
--- a/net/minecraft/world/entity/Entity.java
|
||||
+++ b/net/minecraft/world/entity/Entity.java
|
||||
@@ -1697,6 +1697,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();
|
||||
@@ -1708,7 +1709,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);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Samsuik <kfian294ma4@gmail.com>
|
||||
Date: Thu, 1 May 2025 22:28:50 +0200
|
||||
Subject: [PATCH] Sakura: copy-EntityList-implementation-to-BasicEntityList
|
||||
Date: Sun, 2 Feb 2025 17:05:05 +0000
|
||||
Subject: [PATCH] Sakura: copy EntityList implementation to BasicEntityList
|
||||
|
||||
|
||||
diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java b/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java
|
||||
@@ -5,7 +5,7 @@ Subject: [PATCH] Reduce PlayerChunk Updates
|
||||
|
||||
|
||||
diff --git a/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||||
index a3069b29a1b78012314747d705e27c167acd10b3..3b322c7d65a7f71b94cff660d8702abf646f52e6 100644
|
||||
index 6992a53abdcff6299bedf33ba0b1bc6386a1ea74..b89b6c5affd0a84f56756d9c5e92fe176c41061b 100644
|
||||
--- a/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||||
+++ b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||||
@@ -1418,6 +1418,8 @@ public class ServerGamePacketListenerImpl
|
||||
@@ -0,0 +1,87 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Yive <6853318+Yive@users.noreply.github.com>
|
||||
Date: Tue, 11 Jul 2023 13:27:01 -0700
|
||||
Subject: [PATCH] Pluto: Check if the cactus can even survive being placed
|
||||
|
||||
Original license: GPLv3
|
||||
Original project: https://github.com/Yive/Pluto
|
||||
|
||||
Results at 3,000 randomTickSpeed and 24,448 cacti:
|
||||
|
||||
check-survival-before-growth - false & doTileDrop - true: 48mspt
|
||||
check-survival-before-growth - true & doTileDrop - true: 25mspt
|
||||
check-survival-before-growth - false & doTileDrop - false: 18mspt
|
||||
check-survival-before-growth - true & doTileDrop - false: 6mspt
|
||||
|
||||
Setting the gamerule "doTileDrop" to false was to simulate a server that has chunk collectors.
|
||||
|
||||
Note: This might increase the item output of a cacti farm, though in theory it should act the same as vanilla.
|
||||
|
||||
diff --git a/net/minecraft/world/level/block/CactusBlock.java b/net/minecraft/world/level/block/CactusBlock.java
|
||||
index 0f8cfa5423cd1813c655237aa544dad2dc56ba4d..246193cc914f88cba2eb5959bd3fd8e56e7ebc61 100644
|
||||
--- a/net/minecraft/world/level/block/CactusBlock.java
|
||||
+++ b/net/minecraft/world/level/block/CactusBlock.java
|
||||
@@ -52,25 +52,46 @@ public class CactusBlock extends Block implements BonemealableBlock { // Purpur
|
||||
|
||||
@Override
|
||||
protected void randomTick(BlockState state, ServerLevel level, BlockPos pos, RandomSource random) {
|
||||
- BlockPos blockPos = pos.above();
|
||||
- if (level.isEmptyBlock(blockPos)) {
|
||||
+ // Pluto start - Decrease chunk/block lookups
|
||||
+ final int x = pos.getX();
|
||||
+ final int z = pos.getZ();
|
||||
+ net.minecraft.world.level.chunk.LevelChunk chunk = level.getChunkIfLoaded(x >> 4, z >> 4);
|
||||
+ if (chunk == null) return;
|
||||
+
|
||||
+ final int y = pos.getY();
|
||||
+ if (chunk.getBlockState(x, y + 1, z).isAir()) {
|
||||
+ // Pluto end - Decrease chunk/block lookups
|
||||
int i = 1;
|
||||
int ageValue = state.getValue(AGE);
|
||||
|
||||
- while (level.getBlockState(pos.below(i)).is(this)) {
|
||||
+ while (chunk.getBlockState(pos.below(i)).is(this)) { // Pluto - Decrease chunk/block lookups
|
||||
if (++i == level.paperConfig().maxGrowthHeight.cactus && ageValue == 15) { // Paper - Configurable cactus/bamboo/reed growth height
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
- if (ageValue == 8 && this.canSurvive(this.defaultBlockState(), level, pos.above())) {
|
||||
+ // Pluto start - Decrease chunk/block lookups
|
||||
+ BlockPos blockPos = null;
|
||||
+ if (ageValue == 8 && this.canSurvive(this.defaultBlockState(), level, blockPos = pos.above())) {
|
||||
+ // Pluto end - Decrease chunk/block lookups
|
||||
double d = i >= level.paperConfig().maxGrowthHeight.cactus ? 0.25 : 0.1; // Paper - Configurable cactus/bamboo/reed growth height
|
||||
if (random.nextDouble() <= d) {
|
||||
org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockGrowEvent(level, blockPos, Blocks.CACTUS_FLOWER.defaultBlockState(), 3);
|
||||
}
|
||||
} else if (ageValue == 15 && i < level.paperConfig().maxGrowthHeight.cactus) { // Paper - Configurable cactus/bamboo/reed growth height
|
||||
+ // Pluto start - Check if the cactus can even survive being placed
|
||||
+ if (org.dreeam.leaf.config.modules.opt.CheckSurvivalBeforeGrowth.cactusCheckSurvivalBeforeGrowth && !canSurvive(level, blockPos = pos.above())) { // Pluto - Decrease chunk/block lookups
|
||||
+ level.levelEvent(LevelEvent.PARTICLES_DESTROY_BLOCK, blockPos, Block.getId(state));
|
||||
+ // We're going to fake the block breaking to match vanilla standards.
|
||||
+ for (net.minecraft.world.item.ItemStack drop : Block.getDrops(state, level, pos, null)) { // Use base cactus since we don't place a block
|
||||
+ Block.popResource(level, blockPos, drop);
|
||||
+ }
|
||||
+ level.setBlock(pos, state.setValue(CactusBlock.AGE, 0), Block.UPDATE_NONE);
|
||||
+ return;
|
||||
+ }
|
||||
+ // Pluto end - Check if the cactus can even survive being placed
|
||||
// Paper start
|
||||
- if (!org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockGrowEvent(level, blockPos, this.defaultBlockState(), 3)) {
|
||||
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockGrowEvent(level, blockPos == null ? blockPos = pos.above() : blockPos, this.defaultBlockState(), 3)) { // Pluto - Decrease chunk/block lookups
|
||||
return;
|
||||
}
|
||||
// Paper end
|
||||
@@ -115,6 +136,11 @@ public class CactusBlock extends Block implements BonemealableBlock { // Purpur
|
||||
|
||||
@Override
|
||||
protected boolean canSurvive(BlockState state, LevelReader level, BlockPos pos) {
|
||||
+ // Pluto start - Check if the cactus can even survive being placed
|
||||
+ return canSurvive(level, pos);
|
||||
+ }
|
||||
+ protected boolean canSurvive(LevelReader level, BlockPos pos) {
|
||||
+ // Pluto end - Check if the cactus can even survive being placed
|
||||
for (Direction direction : Direction.Plane.HORIZONTAL) {
|
||||
BlockState blockState = level.getBlockState(pos.relative(direction));
|
||||
if ((level.getWorldBorder().world.purpurConfig.cactusBreaksFromSolidNeighbors && blockState.isSolid()) || level.getFluidState(pos.relative(direction)).is(FluidTags.LAVA)) { // Purpur - Cactus breaks from solid neighbors config
|
||||
@@ -5,7 +5,7 @@ Subject: [PATCH] Optimise player movement checks
|
||||
|
||||
|
||||
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
|
||||
index 658b8af9b1db252d5664956907a5c0db538018b0..6f3fd83c9f0bafe613c780ba56430084e91fdd2a 100644
|
||||
index 5d1027cb511be78b1e29d0e3bdc49cc9d6add346..1b4aae603e965ae15d9b7e204a2ac5d31d045db0 100644
|
||||
--- a/net/minecraft/world/entity/Entity.java
|
||||
+++ b/net/minecraft/world/entity/Entity.java
|
||||
@@ -1190,7 +1190,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
||||
@@ -5,7 +5,7 @@ Subject: [PATCH] Optimize isEyeInFluid
|
||||
|
||||
|
||||
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
|
||||
index 6f3fd83c9f0bafe613c780ba56430084e91fdd2a..fbdc7e54df6cf28264b1dc0d395b9f91206cd50e 100644
|
||||
index 1b4aae603e965ae15d9b7e204a2ac5d31d045db0..ffb23578d5d7a2a821427dae9bab343ec3c45036 100644
|
||||
--- a/net/minecraft/world/entity/Entity.java
|
||||
+++ b/net/minecraft/world/entity/Entity.java
|
||||
@@ -269,6 +269,9 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
||||
@@ -18,7 +18,7 @@ index 6f3fd83c9f0bafe613c780ba56430084e91fdd2a..fbdc7e54df6cf28264b1dc0d395b9f91
|
||||
public int invulnerableTime;
|
||||
protected boolean firstTick = true;
|
||||
protected final SynchedEntityData entityData;
|
||||
@@ -1997,7 +2000,8 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
||||
@@ -2011,7 +2014,8 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
||||
|
||||
private void updateFluidOnEyes() {
|
||||
this.wasEyeInWater = this.isEyeInFluid(FluidTags.WATER);
|
||||
@@ -28,7 +28,7 @@ index 6f3fd83c9f0bafe613c780ba56430084e91fdd2a..fbdc7e54df6cf28264b1dc0d395b9f91
|
||||
double eyeY = this.getEyeY();
|
||||
if (!(
|
||||
this.getVehicle() instanceof AbstractBoat abstractBoat
|
||||
@@ -2009,7 +2013,18 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
||||
@@ -2023,7 +2027,18 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
||||
FluidState fluidState = this.level().getFluidState(blockPos);
|
||||
double d = blockPos.getY() + fluidState.getHeight(this.level(), blockPos);
|
||||
if (d > eyeY) {
|
||||
@@ -48,7 +48,7 @@ index 6f3fd83c9f0bafe613c780ba56430084e91fdd2a..fbdc7e54df6cf28264b1dc0d395b9f91
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2089,9 +2104,25 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
||||
@@ -2103,9 +2118,25 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ index a753481afe02a2367c378c7f39206fde23eda00d..753b4255d9e9b9628bc5825a6b4f0f25
|
||||
|
||||
private void tickPassenger(Entity ridingEntity, Entity passengerEntity, final boolean isActive) { // Paper - EAR 2
|
||||
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
|
||||
index f3a6c98fb803f2141be0ef8315ed9294515f1b73..6d8c7d90b0a64e99a2e811ccdb84a03be95e27b3 100644
|
||||
index ffb23578d5d7a2a821427dae9bab343ec3c45036..95a15fa08a5bd2bb799a125e03844259038ef290 100644
|
||||
--- a/net/minecraft/world/entity/Entity.java
|
||||
+++ b/net/minecraft/world/entity/Entity.java
|
||||
@@ -1140,16 +1140,6 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
||||
@@ -177,7 +177,7 @@ index f3a6c98fb803f2141be0ef8315ed9294515f1b73..6d8c7d90b0a64e99a2e811ccdb84a03b
|
||||
}
|
||||
|
||||
private void applyMovementEmissionAndPlaySound(Entity.MovementEmission movementEmission, Vec3 movement, BlockPos pos, BlockState state) {
|
||||
@@ -4817,9 +4791,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
||||
@@ -4831,9 +4805,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
||||
}
|
||||
|
||||
public void setDeltaMovement(Vec3 deltaMovement) {
|
||||
@@ -187,7 +187,7 @@ index f3a6c98fb803f2141be0ef8315ed9294515f1b73..6d8c7d90b0a64e99a2e811ccdb84a03b
|
||||
}
|
||||
|
||||
public void addDeltaMovement(Vec3 addend) {
|
||||
@@ -4927,9 +4899,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
||||
@@ -4941,9 +4913,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
||||
}
|
||||
// Paper end - Fix MC-4
|
||||
if (this.position.x != x || this.position.y != y || this.position.z != z) {
|
||||
@@ -42,7 +42,7 @@ index 2d24d03bbdb5ee0d862cbfff2219f58afffafe12..11f4f2f3bc4c9f9f6a1f83b90f3de34c
|
||||
|
||||
protected boolean addEntity(final Entity entity, final boolean fromDisk, final boolean event) {
|
||||
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
|
||||
index 6d8c7d90b0a64e99a2e811ccdb84a03be95e27b3..f00a981ef03886f17852f38ba5e83baf856fd1c1 100644
|
||||
index 95a15fa08a5bd2bb799a125e03844259038ef290..905ffdc8d9188c40dc86216c651e22dcbd14dc95 100644
|
||||
--- a/net/minecraft/world/entity/Entity.java
|
||||
+++ b/net/minecraft/world/entity/Entity.java
|
||||
@@ -370,6 +370,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
||||
@@ -29,7 +29,7 @@ public final class BlockPosIterator extends AbstractIterator<BlockPos> {
|
||||
Vec3 movement = vec.scale(toTravel);
|
||||
AABB fromBB = boundingBox.move(-vec.x, -vec.y, -vec.z);
|
||||
AABB searchArea = fromBB.expandTowards(movement);
|
||||
return BlockPosIterator.iterable(searchArea);
|
||||
return iterable(searchArea);
|
||||
}
|
||||
|
||||
public BlockPosIterator(AABB bb) {
|
||||
|
||||
Reference in New Issue
Block a user