mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-19 15:09:25 +00:00
* Unify comment format * More configurable * Remove one extra execute mid-tick task call in level tick when PWT is disabled This may cause extremely rare, weird, strange, magic, mysterious issues with plugins, or potentially more. One example is that it may cause boss mob duplication issue when `ONE MOB ONLY` was enabled in plugin SupremeBosses
565 lines
36 KiB
Diff
565 lines
36 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
|
|
Date: Thu, 24 Apr 2025 16:36:16 -0400
|
|
Subject: [PATCH] Paw optimization
|
|
|
|
Some random optimizations
|
|
|
|
- Remove Paper's dead code
|
|
- Only set shuffle random seed if is really used
|
|
- Cache direction values to skip copy
|
|
- Secret patches (WIP)
|
|
|
|
diff --git a/net/minecraft/Util.java b/net/minecraft/Util.java
|
|
index 9f7288223bc1f13e3664d82d2e883336f527e5e2..ed51fd7c4c9f26dbcc348e6aefcafd367b1dd7bc 100644
|
|
--- a/net/minecraft/Util.java
|
|
+++ b/net/minecraft/Util.java
|
|
@@ -96,7 +96,7 @@ public class Util {
|
|
private static final TracingExecutor BACKGROUND_EXECUTOR = makeExecutor("Main", -1); // Paper - Perf: add priority
|
|
private static final TracingExecutor IO_POOL = makeIoExecutor("IO-Worker-", false);
|
|
public static final TracingExecutor DIMENSION_DATA_IO_POOL = makeExtraIoExecutor("Dimension-Data-IO-Worker-"); // Paper - Separate dimension data IO pool
|
|
- private static final TracingExecutor DOWNLOAD_POOL = makeIoExecutor("Download-", true);
|
|
+ //private static final TracingExecutor DOWNLOAD_POOL = makeIoExecutor("Download-", true); // Leaf - paw optimization - Remove client-only code
|
|
// Paper start - don't submit BLOCKING PROFILE LOOKUPS to the world gen thread
|
|
// Leaf start - More virtual threads
|
|
public static final ExecutorService PROFILE_EXECUTOR = createProfileExecutor(); /* new Executors.newFixedThreadPool(2, new java.util.concurrent.ThreadFactory() {
|
|
@@ -270,7 +270,7 @@ public class Util {
|
|
}
|
|
|
|
public static TracingExecutor nonCriticalIoPool() {
|
|
- return DOWNLOAD_POOL;
|
|
+ return null; // Leaf - paw optimization - Remove client-only code
|
|
}
|
|
|
|
public static void shutdownExecutors() {
|
|
diff --git a/net/minecraft/network/Connection.java b/net/minecraft/network/Connection.java
|
|
index d04531c7316fc13207a6b7312a82697eb51b96f7..c64ce409b13a4f95e73cef7cc48db49eabffcc8a 100644
|
|
--- a/net/minecraft/network/Connection.java
|
|
+++ b/net/minecraft/network/Connection.java
|
|
@@ -646,13 +646,7 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
|
|
if (!(this.packetListener instanceof net.minecraft.server.network.ServerLoginPacketListenerImpl loginPacketListener)
|
|
|| loginPacketListener.state != net.minecraft.server.network.ServerLoginPacketListenerImpl.State.VERIFYING
|
|
|| Connection.joinAttemptsThisTick++ < MAX_PER_TICK) {
|
|
- // Paper start - detailed watchdog information
|
|
- net.minecraft.network.protocol.PacketUtils.packetProcessing.push(this.packetListener);
|
|
- try {
|
|
tickablePacketListener.tick();
|
|
- } finally {
|
|
- net.minecraft.network.protocol.PacketUtils.packetProcessing.pop();
|
|
- } // Paper end - detailed watchdog information
|
|
} // Paper end - Buffer joins to world
|
|
}
|
|
|
|
diff --git a/net/minecraft/network/protocol/PacketUtils.java b/net/minecraft/network/protocol/PacketUtils.java
|
|
index 4535858701b2bb232b9d2feb2af6551526232ddc..e65c62dbe4c1560ae153e4c4344e9194c783a2f4 100644
|
|
--- a/net/minecraft/network/protocol/PacketUtils.java
|
|
+++ b/net/minecraft/network/protocol/PacketUtils.java
|
|
@@ -21,8 +21,6 @@ public class PacketUtils {
|
|
public static <T extends PacketListener> void ensureRunningOnSameThread(Packet<T> packet, T processor, BlockableEventLoop<?> executor) throws RunningOnDifferentThreadException {
|
|
if (!executor.isSameThread()) {
|
|
executor.executeIfPossible(() -> {
|
|
- packetProcessing.push(processor); // Paper - detailed watchdog information
|
|
- try { // Paper - detailed watchdog information
|
|
if (processor instanceof net.minecraft.server.network.ServerCommonPacketListenerImpl serverCommonPacketListener && serverCommonPacketListener.processedDisconnect) return; // Paper - Don't handle sync packets for kicked players
|
|
if (processor.shouldHandleMessage(packet)) {
|
|
try {
|
|
@@ -37,12 +35,6 @@ public class PacketUtils {
|
|
} else {
|
|
LOGGER.debug("Ignoring packet due to disconnection: {}", packet);
|
|
}
|
|
- // Paper start - detailed watchdog information
|
|
- } finally {
|
|
- totalMainThreadPacketsProcessed.getAndIncrement();
|
|
- packetProcessing.pop();
|
|
- }
|
|
- // Paper end - detailed watchdog information
|
|
});
|
|
throw RunningOnDifferentThreadException.RUNNING_ON_DIFFERENT_THREAD;
|
|
}
|
|
@@ -69,22 +61,4 @@ public class PacketUtils {
|
|
|
|
packetListener.fillCrashReport(crashReport);
|
|
}
|
|
-
|
|
- // Paper start - detailed watchdog information
|
|
- public static final java.util.concurrent.ConcurrentLinkedDeque<PacketListener> packetProcessing = new java.util.concurrent.ConcurrentLinkedDeque<>();
|
|
- static final java.util.concurrent.atomic.AtomicLong totalMainThreadPacketsProcessed = new java.util.concurrent.atomic.AtomicLong();
|
|
-
|
|
- public static long getTotalProcessedPackets() {
|
|
- return totalMainThreadPacketsProcessed.get();
|
|
- }
|
|
-
|
|
- public static java.util.List<PacketListener> getCurrentPacketProcessors() {
|
|
- java.util.List<PacketListener> listeners = new java.util.ArrayList<>(4);
|
|
- for (PacketListener listener : packetProcessing) {
|
|
- listeners.add(listener);
|
|
- }
|
|
-
|
|
- return listeners;
|
|
- }
|
|
- // Paper end - detailed watchdog information
|
|
}
|
|
diff --git a/net/minecraft/server/level/ServerChunkCache.java b/net/minecraft/server/level/ServerChunkCache.java
|
|
index 2847aa24cca82b1c66b69600ddcb5dbdadec5b9d..bd4c98e9ec41a2bd608e2e2245c503be3171ceee 100644
|
|
--- a/net/minecraft/server/level/ServerChunkCache.java
|
|
+++ b/net/minecraft/server/level/ServerChunkCache.java
|
|
@@ -638,8 +638,10 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
|
|
this.level.natureSpawnChunkMap.build();
|
|
this.level.natureSpawnChunkMap.collectSpawningChunks(this.level.moonrise$getPlayerTickingChunks(), list);
|
|
// Paper start - chunk tick iteration optimisation
|
|
- this.shuffleRandom.setSeed(this.level.random.nextLong());
|
|
- if (!this.level.paperConfig().entities.spawning.perPlayerMobSpawns) Util.shuffle(list, this.shuffleRandom); // Paper - Optional per player mob spawns; do not need this when per-player is enabled
|
|
+ if (!this.level.paperConfig().entities.spawning.perPlayerMobSpawns) {
|
|
+ this.shuffleRandom.setSeed(this.level.random.nextLong()); // Leaf - paw optimization - Only set seed if is really used
|
|
+ Util.shuffle(list, this.shuffleRandom); // Paper - Optional per player mob spawns; do not need this when per-player is enabled
|
|
+ }
|
|
// Paper end - chunk tick iteration optimisation
|
|
|
|
if (!org.dreeam.leaf.config.modules.async.AsyncMobSpawning.enabled || _pufferfish_spawnCountsReady.get()) {
|
|
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
|
|
index edec4bf5f8818e242bda0cf19bedadb6532edb9f..78b252fcdd0079508d3811ba299b1faedd661c51 100644
|
|
--- a/net/minecraft/server/level/ServerLevel.java
|
|
+++ b/net/minecraft/server/level/ServerLevel.java
|
|
@@ -1506,13 +1506,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
|
// Paper end - log detailed entity tick information
|
|
|
|
public void tickNonPassenger(Entity entity) {
|
|
- // Paper start - log detailed entity tick information
|
|
ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread("Cannot tick an entity off-main");
|
|
- try {
|
|
- if (currentlyTickingEntity.get() == null) {
|
|
- currentlyTickingEntity.lazySet(entity);
|
|
- }
|
|
- // Paper end - log detailed entity tick information
|
|
entity.setOldPosAndRot();
|
|
entity.tickCount++;
|
|
entity.totalEntityAge++; // Paper - age-like counter for all entities
|
|
@@ -1525,13 +1519,6 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
|
for (Entity entity1 : entity.getPassengers()) {
|
|
this.tickPassenger(entity, entity1, isActive); // Paper - EAR 2
|
|
}
|
|
- // Paper start - log detailed entity tick information
|
|
- } finally {
|
|
- if (currentlyTickingEntity.get() == entity) {
|
|
- currentlyTickingEntity.lazySet(null);
|
|
- }
|
|
- }
|
|
- // Paper end - log detailed entity tick information
|
|
}
|
|
|
|
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 984e1ba6adc13da1a9d8e901f008ded9b04e1224..d2a6f2bfa4370fee99b3f535724fc3ee18ce496f 100644
|
|
--- a/net/minecraft/world/entity/Entity.java
|
|
+++ b/net/minecraft/world/entity/Entity.java
|
|
@@ -1136,16 +1136,6 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
return this.onGround;
|
|
}
|
|
|
|
- // Paper start - detailed watchdog information
|
|
- public final Object posLock = new Object(); // Paper - log detailed entity tick information
|
|
-
|
|
- @Nullable
|
|
- private Vec3 moveVector;
|
|
- private double moveStartX;
|
|
- private double moveStartY;
|
|
- private double moveStartZ;
|
|
- // Paper end - detailed watchdog information
|
|
-
|
|
public void move(MoverType type, Vec3 movement) {
|
|
// Gale start - VMP - skip entity move if movement is zero
|
|
if (!this.boundingBoxChanged && movement.equals(Vec3.ZERO)) {
|
|
@@ -1154,16 +1144,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
boundingBoxChanged = false;
|
|
// Gale end - VMP - skip entity move if movement is zero
|
|
final Vec3 originalMovement = movement; // Paper - Expose pre-collision velocity
|
|
- // Paper start - detailed watchdog information
|
|
ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread("Cannot move an entity off-main");
|
|
- synchronized (this.posLock) {
|
|
- this.moveStartX = this.getX();
|
|
- this.moveStartY = this.getY();
|
|
- this.moveStartZ = this.getZ();
|
|
- this.moveVector = movement;
|
|
- }
|
|
- try {
|
|
- // Paper end - detailed watchdog information
|
|
if (this.noPhysics) {
|
|
this.setPos(this.getX() + movement.x, this.getY() + movement.y, this.getZ() + movement.z);
|
|
} else {
|
|
@@ -1287,13 +1268,6 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
// Gale end - skip negligible planar movement multiplication
|
|
}
|
|
}
|
|
- // Paper start - detailed watchdog information
|
|
- } finally {
|
|
- synchronized (this.posLock) { // Paper
|
|
- this.moveVector = null;
|
|
- } // Paper
|
|
- }
|
|
- // Paper end - detailed watchdog information
|
|
}
|
|
|
|
private void applyMovementEmissionAndPlaySound(Entity.MovementEmission movementEmission, Vec3 movement, BlockPos pos, BlockState state) {
|
|
@@ -5027,9 +5001,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
}
|
|
|
|
public void setDeltaMovement(Vec3 deltaMovement) {
|
|
- synchronized (this.posLock) { // Paper - detailed watchdog information
|
|
this.deltaMovement = deltaMovement;
|
|
- } // Paper - detailed watchdog information
|
|
}
|
|
|
|
public void addDeltaMovement(Vec3 addend) {
|
|
@@ -5127,9 +5099,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
}
|
|
// Paper end - Block invalid positions and bounding box
|
|
if (this.position.x != x || this.position.y != y || this.position.z != z) {
|
|
- synchronized (this.posLock) { // Paper - detailed watchdog information
|
|
this.position = new Vec3(x, y, z);
|
|
- } // Paper - detailed watchdog information
|
|
int floor = Mth.floor(x);
|
|
int floor1 = Mth.floor(y);
|
|
int floor2 = Mth.floor(z);
|
|
diff --git a/net/minecraft/world/level/block/BaseCoralPlantTypeBlock.java b/net/minecraft/world/level/block/BaseCoralPlantTypeBlock.java
|
|
index 2653ae5bf66f2b117f86e4df04d9cc307ba09011..0278e54171609b9baa8999d321f47849a6e62155 100644
|
|
--- a/net/minecraft/world/level/block/BaseCoralPlantTypeBlock.java
|
|
+++ b/net/minecraft/world/level/block/BaseCoralPlantTypeBlock.java
|
|
@@ -43,7 +43,7 @@ public abstract class BaseCoralPlantTypeBlock extends Block implements SimpleWat
|
|
if (state.getValue(WATERLOGGED)) {
|
|
return true;
|
|
} else {
|
|
- for (Direction direction : Direction.values()) {
|
|
+ for (Direction direction : Direction.VALUES) { // Leaf - paw optimization - cache direction values
|
|
if (level.getFluidState(pos.relative(direction)).is(FluidTags.WATER)) {
|
|
return true;
|
|
}
|
|
diff --git a/net/minecraft/world/level/block/BaseFireBlock.java b/net/minecraft/world/level/block/BaseFireBlock.java
|
|
index 111eb3a1c584ae42e1afb784cfbaa50dc252e91f..be0e229a0b0b531d956cbfcb8184df644f470fde 100644
|
|
--- a/net/minecraft/world/level/block/BaseFireBlock.java
|
|
+++ b/net/minecraft/world/level/block/BaseFireBlock.java
|
|
@@ -206,7 +206,7 @@ public abstract class BaseFireBlock extends Block {
|
|
BlockPos.MutableBlockPos mutableBlockPos = pos.mutable();
|
|
boolean flag = false;
|
|
|
|
- for (Direction direction1 : Direction.values()) {
|
|
+ for (Direction direction1 : Direction.VALUES) { // Leaf - paw optimization - cache direction values
|
|
if (level.getBlockState(mutableBlockPos.set(pos).move(direction1)).is(Blocks.OBSIDIAN)) {
|
|
flag = true;
|
|
break;
|
|
diff --git a/net/minecraft/world/level/block/FireBlock.java b/net/minecraft/world/level/block/FireBlock.java
|
|
index 73ce9594ab12fd54b9be265c2c4adf9f28fb1b21..51dc0aabc60a317b0340ec7770d057d5ac68429f 100644
|
|
--- a/net/minecraft/world/level/block/FireBlock.java
|
|
+++ b/net/minecraft/world/level/block/FireBlock.java
|
|
@@ -138,7 +138,7 @@ public class FireBlock extends BaseFireBlock {
|
|
if (!this.canBurn(blockState) && !blockState.isFaceSturdy(level, blockPos, Direction.UP)) {
|
|
BlockState blockState1 = this.defaultBlockState();
|
|
|
|
- for (Direction direction : Direction.values()) {
|
|
+ for (Direction direction : Direction.VALUES) { // Leaf - paw optimization - cache direction values
|
|
BooleanProperty booleanProperty = PROPERTY_BY_DIRECTION.get(direction);
|
|
if (booleanProperty != null) {
|
|
blockState1 = blockState1.setValue(booleanProperty, this.canBurn(level.getBlockState(pos.relative(direction))));
|
|
@@ -310,7 +310,7 @@ public class FireBlock extends BaseFireBlock {
|
|
}
|
|
|
|
private boolean isValidFireLocation(BlockGetter level, BlockPos pos) {
|
|
- for (Direction direction : Direction.values()) {
|
|
+ for (Direction direction : Direction.VALUES) { // Leaf - paw optimization - cache direction values
|
|
if (this.canBurn(level.getBlockState(pos.relative(direction)))) {
|
|
return true;
|
|
}
|
|
@@ -325,7 +325,7 @@ public class FireBlock extends BaseFireBlock {
|
|
} else {
|
|
int i = 0;
|
|
|
|
- for (Direction direction : Direction.values()) {
|
|
+ for (Direction direction : Direction.VALUES) { // Leaf - paw optimization - cache direction values
|
|
BlockState blockState = level.getBlockState(pos.relative(direction));
|
|
i = Math.max(this.getIgniteOdds(blockState), i);
|
|
}
|
|
diff --git a/net/minecraft/world/level/block/FrostedIceBlock.java b/net/minecraft/world/level/block/FrostedIceBlock.java
|
|
index 7001d7d488a5f2e8a39e30866b1b93a38807ddee..ff602b8f03884b3fa1b9aa7aecf5709356abbf41 100644
|
|
--- a/net/minecraft/world/level/block/FrostedIceBlock.java
|
|
+++ b/net/minecraft/world/level/block/FrostedIceBlock.java
|
|
@@ -48,7 +48,7 @@ public class FrostedIceBlock extends IceBlock {
|
|
&& this.slightlyMelt(state, level, pos)) {
|
|
BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos();
|
|
|
|
- for (Direction direction : Direction.values()) {
|
|
+ for (Direction direction : Direction.VALUES) { // Leaf - paw optimization - cache direction values
|
|
mutableBlockPos.setWithOffset(pos, direction);
|
|
BlockState blockState = level.getBlockState(mutableBlockPos);
|
|
if (blockState.is(this) && !this.slightlyMelt(blockState, level, mutableBlockPos)) {
|
|
@@ -84,7 +84,7 @@ public class FrostedIceBlock extends IceBlock {
|
|
int i = 0;
|
|
BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos();
|
|
|
|
- for (Direction direction : Direction.values()) {
|
|
+ for (Direction direction : Direction.VALUES) { // Leaf - paw optimization - cache direction values
|
|
mutableBlockPos.setWithOffset(pos, direction);
|
|
if (level.getBlockState(mutableBlockPos).is(this)) {
|
|
if (++i >= neighborsRequired) {
|
|
diff --git a/net/minecraft/world/level/block/LeavesBlock.java b/net/minecraft/world/level/block/LeavesBlock.java
|
|
index 010e9814490ffaa153df5b7865da17e2a84c7e82..d6750aec0f4695a99557beb92fda7a892fecc58d 100644
|
|
--- a/net/minecraft/world/level/block/LeavesBlock.java
|
|
+++ b/net/minecraft/world/level/block/LeavesBlock.java
|
|
@@ -110,7 +110,7 @@ public abstract class LeavesBlock extends Block implements SimpleWaterloggedBloc
|
|
int i = 7;
|
|
BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos();
|
|
|
|
- for (Direction direction : Direction.values()) {
|
|
+ for (Direction direction : Direction.VALUES) { // Leaf - paw optimization - cache direction values
|
|
mutableBlockPos.setWithOffset(pos, direction);
|
|
i = Math.min(i, getDistanceAt(level.getBlockState(mutableBlockPos)) + 1);
|
|
if (i == 1) {
|
|
diff --git a/net/minecraft/world/level/block/RedStoneWireBlock.java b/net/minecraft/world/level/block/RedStoneWireBlock.java
|
|
index 5b248fe2dc06f46c519b388a054776d4a0df7421..60d4399368752f9d3cfc8091ed08ca8ec1a31bcf 100644
|
|
--- a/net/minecraft/world/level/block/RedStoneWireBlock.java
|
|
+++ b/net/minecraft/world/level/block/RedStoneWireBlock.java
|
|
@@ -360,7 +360,7 @@ public class RedStoneWireBlock extends Block {
|
|
if (level.getBlockState(pos).is(this)) {
|
|
level.updateNeighborsAt(pos, this);
|
|
|
|
- for (Direction direction : Direction.values()) {
|
|
+ for (Direction direction : Direction.VALUES) { // Leaf - paw optimization - cache direction values
|
|
level.updateNeighborsAt(pos.relative(direction), this);
|
|
}
|
|
}
|
|
@@ -388,7 +388,7 @@ public class RedStoneWireBlock extends Block {
|
|
@Override
|
|
protected void affectNeighborsAfterRemoval(BlockState state, ServerLevel level, BlockPos pos, boolean movedByPiston) {
|
|
if (!movedByPiston) {
|
|
- for (Direction direction : Direction.values()) {
|
|
+ for (Direction direction : Direction.VALUES) { // Leaf - paw optimization - cache direction values
|
|
level.updateNeighborsAt(pos.relative(direction), this);
|
|
}
|
|
|
|
diff --git a/net/minecraft/world/level/block/piston/PistonBaseBlock.java b/net/minecraft/world/level/block/piston/PistonBaseBlock.java
|
|
index 10484ee85482e86be5e0a09d8202df600a32092e..5b530b582d865ec407639c2262823bb7057b92a9 100644
|
|
--- a/net/minecraft/world/level/block/piston/PistonBaseBlock.java
|
|
+++ b/net/minecraft/world/level/block/piston/PistonBaseBlock.java
|
|
@@ -127,7 +127,7 @@ public class PistonBaseBlock extends DirectionalBlock {
|
|
}
|
|
|
|
private boolean getNeighborSignal(SignalGetter signalGetter, BlockPos pos, Direction direction) {
|
|
- for (Direction direction1 : Direction.values()) {
|
|
+ for (Direction direction1 : Direction.VALUES) { // Leaf - paw optimization - cache direction values
|
|
if (direction1 != direction && signalGetter.hasSignal(pos.relative(direction1), direction1)) {
|
|
return true;
|
|
}
|
|
@@ -138,7 +138,7 @@ public class PistonBaseBlock extends DirectionalBlock {
|
|
} else {
|
|
BlockPos blockPos = pos.above();
|
|
|
|
- for (Direction direction2 : Direction.values()) {
|
|
+ for (Direction direction2 : Direction.VALUES) { // Leaf - paw optimization - cache direction values
|
|
if (direction2 != Direction.DOWN && signalGetter.hasSignal(blockPos.relative(direction2), direction2)) {
|
|
return true;
|
|
}
|
|
diff --git a/net/minecraft/world/level/block/state/pattern/BlockPattern.java b/net/minecraft/world/level/block/state/pattern/BlockPattern.java
|
|
index f7bb979f08634a7e1b77c59040f59fb5e11aafa5..9b60bbebd32f045bd0f5b91cd30264396e673d30 100644
|
|
--- a/net/minecraft/world/level/block/state/pattern/BlockPattern.java
|
|
+++ b/net/minecraft/world/level/block/state/pattern/BlockPattern.java
|
|
@@ -79,8 +79,8 @@ public class BlockPattern {
|
|
int max = Math.max(Math.max(this.width, this.height), this.depth);
|
|
|
|
for (BlockPos blockPos : BlockPos.betweenClosed(pos, pos.offset(max - 1, max - 1, max - 1))) {
|
|
- for (Direction direction : Direction.values()) {
|
|
- for (Direction direction1 : Direction.values()) {
|
|
+ for (Direction direction : Direction.VALUES) { // Leaf - paw optimization - cache direction values
|
|
+ for (Direction direction1 : Direction.VALUES) { // Leaf - paw optimization - cache direction values
|
|
if (direction1 != direction && direction1 != direction.getOpposite()) {
|
|
BlockPattern.BlockPatternMatch blockPatternMatch = this.matches(blockPos, direction, direction1, loadingCache);
|
|
if (blockPatternMatch != null) {
|
|
diff --git a/net/minecraft/world/level/gameevent/vibrations/VibrationSystem.java b/net/minecraft/world/level/gameevent/vibrations/VibrationSystem.java
|
|
index c0940bea065d109a29dd4218881c117d517dcf67..9bf0a66115c1c64b036d1504d9842b49efeb5879 100644
|
|
--- a/net/minecraft/world/level/gameevent/vibrations/VibrationSystem.java
|
|
+++ b/net/minecraft/world/level/gameevent/vibrations/VibrationSystem.java
|
|
@@ -256,7 +256,7 @@ public interface VibrationSystem {
|
|
Vec3 vec3 = new Vec3(Mth.floor(eventPos.x) + 0.5, Mth.floor(eventPos.y) + 0.5, Mth.floor(eventPos.z) + 0.5);
|
|
Vec3 vec31 = new Vec3(Mth.floor(vibrationUserPos.x) + 0.5, Mth.floor(vibrationUserPos.y) + 0.5, Mth.floor(vibrationUserPos.z) + 0.5);
|
|
|
|
- for (Direction direction : Direction.values()) {
|
|
+ for (Direction direction : Direction.VALUES) { // Leaf - paw optimization - cache direction values
|
|
Vec3 vec32 = vec3.relative(direction, 1.0E-5F);
|
|
if (level.isBlockInLine(new ClipBlockStateContext(vec32, vec31, state -> state.is(BlockTags.OCCLUDES_VIBRATION_SIGNALS))).getType()
|
|
!= HitResult.Type.BLOCK) {
|
|
diff --git a/net/minecraft/world/level/levelgen/feature/BlueIceFeature.java b/net/minecraft/world/level/levelgen/feature/BlueIceFeature.java
|
|
index 5bbc9cacd8675c96d99f8b46399742753888d2f7..0c818d43c3d58e1f61e30d63556ba82356d53290 100644
|
|
--- a/net/minecraft/world/level/levelgen/feature/BlueIceFeature.java
|
|
+++ b/net/minecraft/world/level/levelgen/feature/BlueIceFeature.java
|
|
@@ -26,7 +26,7 @@ public class BlueIceFeature extends Feature<NoneFeatureConfiguration> {
|
|
} else {
|
|
boolean flag = false;
|
|
|
|
- for (Direction direction : Direction.values()) {
|
|
+ for (Direction direction : Direction.VALUES) { // Leaf - paw optimization - cache direction values
|
|
if (direction != Direction.DOWN && worldGenLevel.getBlockState(blockPos.relative(direction)).is(Blocks.PACKED_ICE)) {
|
|
flag = true;
|
|
break;
|
|
@@ -51,7 +51,7 @@ public class BlueIceFeature extends Feature<NoneFeatureConfiguration> {
|
|
);
|
|
BlockState blockState = worldGenLevel.getBlockState(blockPos1);
|
|
if (blockState.isAir() || blockState.is(Blocks.WATER) || blockState.is(Blocks.PACKED_ICE) || blockState.is(Blocks.ICE)) {
|
|
- for (Direction direction1 : Direction.values()) {
|
|
+ for (Direction direction1 : Direction.VALUES) { // Leaf - paw optimization - cache direction values
|
|
BlockState blockState1 = worldGenLevel.getBlockState(blockPos1.relative(direction1));
|
|
if (blockState1.is(Blocks.BLUE_ICE)) {
|
|
worldGenLevel.setBlock(blockPos1, Blocks.BLUE_ICE.defaultBlockState(), 2);
|
|
diff --git a/net/minecraft/world/level/levelgen/feature/Feature.java b/net/minecraft/world/level/levelgen/feature/Feature.java
|
|
index d4b7275351e5b6dec6fb724c3dd455447dd1ed23..c3c021f5d1a20dab9fa14146ca6ffdb45a14421d 100644
|
|
--- a/net/minecraft/world/level/levelgen/feature/Feature.java
|
|
+++ b/net/minecraft/world/level/levelgen/feature/Feature.java
|
|
@@ -207,7 +207,7 @@ public abstract class Feature<FC extends FeatureConfiguration> {
|
|
public static boolean checkNeighbors(Function<BlockPos, BlockState> adjacentStateAccessor, BlockPos pos, Predicate<BlockState> filter) {
|
|
BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos();
|
|
|
|
- for (Direction direction : Direction.values()) {
|
|
+ for (Direction direction : Direction.VALUES) { // Leaf - paw optimization - cache direction values
|
|
mutableBlockPos.setWithOffset(pos, direction);
|
|
if (filter.test(adjacentStateAccessor.apply(mutableBlockPos))) {
|
|
return true;
|
|
diff --git a/net/minecraft/world/level/levelgen/feature/GlowstoneFeature.java b/net/minecraft/world/level/levelgen/feature/GlowstoneFeature.java
|
|
index 0062e6ba05ff73ed80c5bc5d3765c8872ef081e0..e002a1ad27bc18a7fc5ac9d1ecae523a9e66886f 100644
|
|
--- a/net/minecraft/world/level/levelgen/feature/GlowstoneFeature.java
|
|
+++ b/net/minecraft/world/level/levelgen/feature/GlowstoneFeature.java
|
|
@@ -35,7 +35,7 @@ public class GlowstoneFeature extends Feature<NoneFeatureConfiguration> {
|
|
if (worldGenLevel.getBlockState(blockPos1).isAir()) {
|
|
int i1 = 0;
|
|
|
|
- for (Direction direction : Direction.values()) {
|
|
+ for (Direction direction : Direction.VALUES) { // Leaf - paw optimization - cache direction values
|
|
if (worldGenLevel.getBlockState(blockPos1.relative(direction)).is(Blocks.GLOWSTONE)) {
|
|
i1++;
|
|
}
|
|
diff --git a/net/minecraft/world/level/levelgen/feature/TreeFeature.java b/net/minecraft/world/level/levelgen/feature/TreeFeature.java
|
|
index ef444a4975cb7b24b6dc3b0e6b8d727265bf6011..6a191796e21b1ed2304fd89ecf79d3773878006b 100644
|
|
--- a/net/minecraft/world/level/levelgen/feature/TreeFeature.java
|
|
+++ b/net/minecraft/world/level/levelgen/feature/TreeFeature.java
|
|
@@ -203,7 +203,7 @@ public class TreeFeature extends Feature<TreeConfiguration> {
|
|
|
|
discreteVoxelShape.fill(blockPos1.getX() - box.minX(), blockPos1.getY() - box.minY(), blockPos1.getZ() - box.minZ());
|
|
|
|
- for (Direction direction : Direction.values()) {
|
|
+ for (Direction direction : Direction.VALUES) { // Leaf - paw optimization - cache direction values
|
|
mutableBlockPos.setWithOffset(blockPos1, direction);
|
|
if (box.isInside(mutableBlockPos)) {
|
|
int i3 = mutableBlockPos.getX() - box.minX();
|
|
diff --git a/net/minecraft/world/level/levelgen/feature/VinesFeature.java b/net/minecraft/world/level/levelgen/feature/VinesFeature.java
|
|
index 231f91a96cb2ab2e9d246bb57704d6364979e2aa..3da252ab857f7c1e5d6cc3d979a53e660a3b98cd 100644
|
|
--- a/net/minecraft/world/level/levelgen/feature/VinesFeature.java
|
|
+++ b/net/minecraft/world/level/levelgen/feature/VinesFeature.java
|
|
@@ -21,7 +21,7 @@ public class VinesFeature extends Feature<NoneFeatureConfiguration> {
|
|
if (!worldGenLevel.isEmptyBlock(blockPos)) {
|
|
return false;
|
|
} else {
|
|
- for (Direction direction : Direction.values()) {
|
|
+ for (Direction direction : Direction.VALUES) { // Leaf - paw optimization - cache direction values
|
|
if (direction != Direction.DOWN && VineBlock.isAcceptableNeighbour(worldGenLevel, blockPos.relative(direction), direction)) {
|
|
worldGenLevel.setBlock(blockPos, Blocks.VINE.defaultBlockState().setValue(VineBlock.getPropertyForFace(direction), true), 2);
|
|
return true;
|
|
diff --git a/net/minecraft/world/level/levelgen/feature/treedecorators/CreakingHeartDecorator.java b/net/minecraft/world/level/levelgen/feature/treedecorators/CreakingHeartDecorator.java
|
|
index ffdcdc6ecdb2273ae5ca6db1f3dbd563fe241db3..25f4f7741832faca6a29c099056867d43cb0dcc4 100644
|
|
--- a/net/minecraft/world/level/levelgen/feature/treedecorators/CreakingHeartDecorator.java
|
|
+++ b/net/minecraft/world/level/levelgen/feature/treedecorators/CreakingHeartDecorator.java
|
|
@@ -38,7 +38,7 @@ public class CreakingHeartDecorator extends TreeDecorator {
|
|
List<BlockPos> list1 = new ArrayList<>(list);
|
|
Util.shuffle(list1, randomSource);
|
|
Optional<BlockPos> optional = list1.stream().filter(pos -> {
|
|
- for (Direction direction : Direction.values()) {
|
|
+ for (Direction direction : Direction.VALUES) { // Leaf - paw optimization - cache direction values
|
|
if (!context.checkBlock(pos.relative(direction), blockState -> blockState.is(BlockTags.LOGS))) {
|
|
return false;
|
|
}
|
|
diff --git a/net/minecraft/world/level/levelgen/structure/structures/BuriedTreasurePieces.java b/net/minecraft/world/level/levelgen/structure/structures/BuriedTreasurePieces.java
|
|
index f515f7c881d597072db226f60cfae2d7ebe89ea4..ed4d719c7dfbce695a8fdc59ded6aae75c273714 100644
|
|
--- a/net/minecraft/world/level/levelgen/structure/structures/BuriedTreasurePieces.java
|
|
+++ b/net/minecraft/world/level/levelgen/structure/structures/BuriedTreasurePieces.java
|
|
@@ -54,7 +54,7 @@ public class BuriedTreasurePieces {
|
|
|| blockState1 == Blocks.DIORITE.defaultBlockState()) {
|
|
BlockState blockState2 = !blockState.isAir() && !this.isLiquid(blockState) ? blockState : Blocks.SAND.defaultBlockState();
|
|
|
|
- for (Direction direction : Direction.values()) {
|
|
+ for (Direction direction : Direction.VALUES) { // Leaf - paw optimization - cache direction values
|
|
BlockPos blockPos = mutableBlockPos.relative(direction);
|
|
BlockState blockState3 = level.getBlockState(blockPos);
|
|
if (blockState3.isAir() || this.isLiquid(blockState3)) {
|
|
diff --git a/net/minecraft/world/level/levelgen/structure/structures/DesertPyramidStructure.java b/net/minecraft/world/level/levelgen/structure/structures/DesertPyramidStructure.java
|
|
index ef9c2c0a665a1acf490affd9cd4496ae9d677410..27e7c1bb585f30165bd501bb8f8aab0dd147ca5b 100644
|
|
--- a/net/minecraft/world/level/levelgen/structure/structures/DesertPyramidStructure.java
|
|
+++ b/net/minecraft/world/level/levelgen/structure/structures/DesertPyramidStructure.java
|
|
@@ -48,7 +48,7 @@ public class DesertPyramidStructure extends SinglePieceStructure {
|
|
}
|
|
}
|
|
|
|
- ObjectArrayList<BlockPos> list = new ObjectArrayList<>(set.stream().toList());
|
|
+ ObjectArrayList<BlockPos> list = new ObjectArrayList<>(set); // Leaf - paw optimization - TODO: use array
|
|
RandomSource randomSource = RandomSource.create(level.getSeed()).forkPositional().at(pieces.calculateBoundingBox().getCenter());
|
|
Util.shuffle(list, randomSource);
|
|
int min = Math.min(set.size(), randomSource.nextInt(5, 8));
|
|
diff --git a/net/minecraft/world/level/levelgen/structure/structures/MineshaftPieces.java b/net/minecraft/world/level/levelgen/structure/structures/MineshaftPieces.java
|
|
index 53d3bf1d2a1debe46e276b1db25b420be4ad9958..090e661107195589bf72d40ed86726ad2d878869 100644
|
|
--- a/net/minecraft/world/level/levelgen/structure/structures/MineshaftPieces.java
|
|
+++ b/net/minecraft/world/level/levelgen/structure/structures/MineshaftPieces.java
|
|
@@ -561,7 +561,7 @@ public class MineshaftPieces {
|
|
BlockPos.MutableBlockPos worldPos = this.getWorldPos(x, y, z);
|
|
int i = 0;
|
|
|
|
- for (Direction direction : Direction.values()) {
|
|
+ for (Direction direction : Direction.VALUES) { // Leaf - paw optimization - cache direction values
|
|
worldPos.move(direction);
|
|
if (box.isInside(worldPos) && level.getBlockState(worldPos).isFaceSturdy(level, worldPos, direction.getOpposite())) {
|
|
if (++i >= required) {
|
|
diff --git a/net/minecraft/world/level/levelgen/structure/structures/OceanMonumentPieces.java b/net/minecraft/world/level/levelgen/structure/structures/OceanMonumentPieces.java
|
|
index 999ac28a9e371f685554cdec2e645ebe11ddfc92..5a946ad8bec11413d4538b813f0cead40ccf6630 100644
|
|
--- a/net/minecraft/world/level/levelgen/structure/structures/OceanMonumentPieces.java
|
|
+++ b/net/minecraft/world/level/levelgen/structure/structures/OceanMonumentPieces.java
|
|
@@ -244,7 +244,7 @@ public class OceanMonumentPieces {
|
|
for (int i2 = 0; i2 < 3; i2++) {
|
|
int roomIndex = getRoomIndex(i, i2, i1);
|
|
if (roomDefinitions[roomIndex] != null) {
|
|
- for (Direction direction : Direction.values()) {
|
|
+ for (Direction direction : Direction.VALUES) { // Leaf - paw optimization - cache direction values
|
|
int i3 = i + direction.getStepX();
|
|
int i4 = i2 + direction.getStepY();
|
|
int i5 = i1 + direction.getStepZ();
|
|
diff --git a/net/minecraft/world/level/material/LavaFluid.java b/net/minecraft/world/level/material/LavaFluid.java
|
|
index 5984ea9f6236a80b666fe6c33a99245389b54e8f..e681e8ccc91f8970a03a0a126a1cda61fceb9363 100644
|
|
--- a/net/minecraft/world/level/material/LavaFluid.java
|
|
+++ b/net/minecraft/world/level/material/LavaFluid.java
|
|
@@ -138,7 +138,7 @@ public abstract class LavaFluid extends FlowingFluid {
|
|
}
|
|
|
|
private boolean hasFlammableNeighbours(LevelReader level, BlockPos pos) {
|
|
- for (Direction direction : Direction.values()) {
|
|
+ for (Direction direction : Direction.VALUES) { // Leaf - paw optimization - cache direction values
|
|
if (this.isFlammable(level, pos.relative(direction))) {
|
|
return true;
|
|
}
|
|
diff --git a/net/minecraft/world/level/pathfinder/AmphibiousNodeEvaluator.java b/net/minecraft/world/level/pathfinder/AmphibiousNodeEvaluator.java
|
|
index 33047e446adf252a179cb0220c20a7d83f361482..9c58425f2afdbe5701910d8473fd5b344ffe31dd 100644
|
|
--- a/net/minecraft/world/level/pathfinder/AmphibiousNodeEvaluator.java
|
|
+++ b/net/minecraft/world/level/pathfinder/AmphibiousNodeEvaluator.java
|
|
@@ -97,7 +97,7 @@ public class AmphibiousNodeEvaluator extends WalkNodeEvaluator {
|
|
if (pathTypeFromState == PathType.WATER) {
|
|
BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos();
|
|
|
|
- for (Direction direction : Direction.values()) {
|
|
+ for (Direction direction : Direction.VALUES) { // Leaf - paw optimization - cache direction values
|
|
mutableBlockPos.set(x, y, z).move(direction);
|
|
PathType pathTypeFromState1 = context.getPathTypeFromState(mutableBlockPos.getX(), mutableBlockPos.getY(), mutableBlockPos.getZ());
|
|
if (pathTypeFromState1 == PathType.BLOCKED) {
|
|
diff --git a/net/minecraft/world/level/pathfinder/SwimNodeEvaluator.java b/net/minecraft/world/level/pathfinder/SwimNodeEvaluator.java
|
|
index b25d3bf3d5c575cd5c9a97a6d5ee7191467fe839..c598d91cd9fb711bc9aaa068fbb806619c0d4fe2 100644
|
|
--- a/net/minecraft/world/level/pathfinder/SwimNodeEvaluator.java
|
|
+++ b/net/minecraft/world/level/pathfinder/SwimNodeEvaluator.java
|
|
@@ -51,7 +51,7 @@ public class SwimNodeEvaluator extends NodeEvaluator {
|
|
int i = 0;
|
|
Map<Direction, Node> map = Maps.newEnumMap(Direction.class);
|
|
|
|
- for (Direction direction : Direction.values()) {
|
|
+ for (Direction direction : Direction.VALUES) { // Leaf - paw optimization - cache direction values
|
|
Node node1 = this.findAcceptedNode(node.x + direction.getStepX(), node.y + direction.getStepY(), node.z + direction.getStepZ());
|
|
map.put(direction, node1);
|
|
if (this.isNodeValid(node1)) {
|