mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-19 15:09:25 +00:00
* rebase * optimize LivingEntity#travel * cleanup * Replace fluid height map * reuse array list in Entity#collide * cleanup * fix fire and liquid collision shape * fix checkInside * inline betweenClosed * cleanup * optimize getOnPos * optimize equals in getOnPos * update mainSupportingBlockPos on dirty * cleanup * rename * merge same patch * rebase and remove properly * [ci skip] cleanup * rebase and rebuild * fix async locator * remove async locator * cleanup * rebase --------- Co-authored-by: Taiyou06 <kaandindar21@gmail.com>
73 lines
4.7 KiB
Diff
73 lines
4.7 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Taiyou06 <kaandindar21@gmail.com>
|
|
Date: Sat, 22 Mar 2025 03:02:52 +0100
|
|
Subject: [PATCH] Micro optimizations for random tick
|
|
|
|
|
|
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
|
|
index dfeff3886bfeb3aa92e5961237ac0af89c78cb4e..33e18114fdcc36df56156932d99f732b417887c0 100644
|
|
--- a/net/minecraft/server/level/ServerLevel.java
|
|
+++ b/net/minecraft/server/level/ServerLevel.java
|
|
@@ -1042,7 +1042,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
|
// Paper start - optimise random ticking
|
|
private void optimiseRandomTick(final LevelChunk chunk, final int tickSpeed) {
|
|
final LevelChunkSection[] sections = chunk.getSections();
|
|
- final int minSection = ca.spottedleaf.moonrise.common.util.WorldUtil.getMinSection((ServerLevel)(Object)this);
|
|
+ final int minSection = ca.spottedleaf.moonrise.common.util.WorldUtil.getMinSection(this); // Leaf - Micro optimizations for random tick - no redundant cast
|
|
final net.minecraft.world.level.levelgen.BitRandomSource simpleRandom = this.simpleRandom; // Leaf - Faster random generator - upcasting
|
|
final boolean doubleTickFluids = !ca.spottedleaf.moonrise.common.PlatformHooks.get().configFixMC224294();
|
|
|
|
@@ -1051,41 +1051,41 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
|
final int offsetZ = cpos.z << 4;
|
|
|
|
for (int sectionIndex = 0, sectionsLen = sections.length; sectionIndex < sectionsLen; sectionIndex++) {
|
|
- final int offsetY = (sectionIndex + minSection) << 4;
|
|
+ // Leaf start - Micro optimizations for random tick
|
|
final LevelChunkSection section = sections[sectionIndex];
|
|
- final net.minecraft.world.level.chunk.PalettedContainer<net.minecraft.world.level.block.state.BlockState> states = section.states;
|
|
if (!section.isRandomlyTickingBlocks()) {
|
|
continue;
|
|
}
|
|
+ final int offsetY = (sectionIndex + minSection) << 4;
|
|
+ final net.minecraft.world.level.chunk.PalettedContainer<net.minecraft.world.level.block.state.BlockState> states = section.states;
|
|
+ // Leaf end - Micro optimizations for random tick
|
|
|
|
- final ca.spottedleaf.moonrise.common.list.ShortList tickList = ((ca.spottedleaf.moonrise.patches.block_counting.BlockCountingChunkSection)section).moonrise$getTickingBlockList();
|
|
+ final ca.spottedleaf.moonrise.common.list.ShortList tickList = section.moonrise$getTickingBlockList(); // Leaf - Micro optimizations for random tick - no redundant cast
|
|
|
|
for (int i = 0; i < tickSpeed; ++i) {
|
|
- final int tickingBlocks = tickList.size();
|
|
final int index = simpleRandom.nextInt() & ((16 * 16 * 16) - 1);
|
|
|
|
- if (index >= tickingBlocks) {
|
|
+ if (index >= tickList.size()) { // Leaf - Micro optimizations for random tick - inline one-time value
|
|
// most of the time we fall here
|
|
continue;
|
|
}
|
|
|
|
- final int location = (int)tickList.getRaw(index) & 0xFFFF;
|
|
+ final int location = tickList.getRaw(index); // Leaf - Micro optimizations for random tick - no unnecessary operations
|
|
final BlockState state = states.get(location);
|
|
|
|
// do not use a mutable pos, as some random tick implementations store the input without calling immutable()!
|
|
- final BlockPos pos = new BlockPos((location & 15) | offsetX, ((location >>> (4 + 4)) & 15) | offsetY, ((location >>> 4) & 15) | offsetZ);
|
|
+ final BlockPos pos = new BlockPos((location & 15) | offsetX, (location >>> (4 + 4)) | offsetY, ((location >>> 4) & 15) | offsetZ); // Leaf - Micro optimizations for random tick - no redundant mask
|
|
|
|
- state.randomTick((ServerLevel)(Object)this, pos, simpleRandom);
|
|
+ state.randomTick(this, pos, simpleRandom); // Leaf - Micro optimizations for random tick - no redundant cast
|
|
if (doubleTickFluids) {
|
|
final FluidState fluidState = state.getFluidState();
|
|
if (fluidState.isRandomlyTicking()) {
|
|
- fluidState.randomTick((ServerLevel)(Object)this, pos, simpleRandom);
|
|
+ fluidState.randomTick(this, pos, simpleRandom); // Leaf - Micro optimizations for random tick - no redundant cast
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
- return;
|
|
+ // Leaf - Micro optimizations for random tick - no redundant return
|
|
}
|
|
// Paper end - optimise random ticking
|
|
|