9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-25 09:59:15 +00:00

[ci skip] cleanup

This commit is contained in:
Dreeam
2025-03-27 17:12:32 -04:00
parent c36c34cf85
commit e56ef42b4e
11 changed files with 63 additions and 88 deletions

View File

@@ -5,20 +5,22 @@ Subject: [PATCH] Optimize addOrUpdateTransientModifier
diff --git a/net/minecraft/world/entity/ai/attributes/AttributeInstance.java b/net/minecraft/world/entity/ai/attributes/AttributeInstance.java
index ceff383d565267edd13a6d9006030b8e1f8053e3..71fb9a61e8d3ac7094d0630aebdc46dbe74dd0ae 100644
index ceff383d565267edd13a6d9006030b8e1f8053e3..7dae9cc18cd6eede8f1b2196b55103428f35382e 100644
--- a/net/minecraft/world/entity/ai/attributes/AttributeInstance.java
+++ b/net/minecraft/world/entity/ai/attributes/AttributeInstance.java
@@ -88,8 +88,11 @@ public class AttributeInstance {
@@ -88,8 +88,13 @@ public class AttributeInstance {
}
public void addOrUpdateTransientModifier(AttributeModifier modifier) {
- AttributeModifier attributeModifier = this.modifierById.put(modifier.id(), modifier);
- if (modifier != attributeModifier) {
+ // Leaf start - Optimize addOrUpdateTransientModifier
+ // First check if we already have the same modifier instance to avoid unnecessary put operations
+ AttributeModifier existingModifier = this.modifierById.get(modifier.id());
+ // Only perform updates if the modifier is new or different
+ if (existingModifier != modifier) {
+ this.modifierById.put(modifier.id(), modifier);
+ // Leaf end - Optimize addOrUpdateTransientModifier
this.getModifiers(modifier.operation()).put(modifier.id(), modifier);
this.setDirty();
}

View File

@@ -5,23 +5,10 @@ Subject: [PATCH] Optimize ContextMap.create
diff --git a/net/minecraft/util/context/ContextMap.java b/net/minecraft/util/context/ContextMap.java
index cc8d67df5e074beb8c41bb6ce4f519f963e59d0d..9b1152db265afd87f17f0b7d4b2d09f4913b2f9c 100644
index cc8d67df5e074beb8c41bb6ce4f519f963e59d0d..64a48913868d9b8c0a4bb3f97458a64c95e99034 100644
--- a/net/minecraft/util/context/ContextMap.java
+++ b/net/minecraft/util/context/ContextMap.java
@@ -1,10 +1,8 @@
package net.minecraft.util.context;
import com.google.common.collect.Sets;
-import java.util.IdentityHashMap;
-import java.util.Map;
-import java.util.NoSuchElementException;
-import java.util.Set;
+
+import java.util.*;
import javax.annotation.Nullable;
import org.jetbrains.annotations.Contract;
@@ -72,17 +70,39 @@ public class ContextMap {
@@ -72,17 +72,41 @@ public class ContextMap {
}
public ContextMap create(ContextKeySet contextKeySet) {
@@ -34,6 +21,7 @@ index cc8d67df5e074beb8c41bb6ce4f519f963e59d0d..9b1152db265afd87f17f0b7d4b2d09f4
- throw new IllegalArgumentException("Missing required parameters: " + set1);
- } else {
- return new ContextMap(this.params);
+ // Leaf start - Optimize ContextMap.create
+ Set<ContextKey<?>> allowed = contextKeySet.allowed();
+ Set<ContextKey<?>> invalid = null;
+
@@ -41,11 +29,11 @@ index cc8d67df5e074beb8c41bb6ce4f519f963e59d0d..9b1152db265afd87f17f0b7d4b2d09f4
+ for (ContextKey<?> key : this.params.keySet()) {
+ if (!allowed.contains(key)) {
+ if (invalid == null) {
+ invalid = new HashSet<>();
+ invalid = new java.util.HashSet<>();
+ }
+ invalid.add(key);
+ }
+ }
}
}
+ if (invalid != null) {
+ throw new IllegalArgumentException("Parameters not allowed in this parameter set: " + invalid);
+ }
@@ -57,16 +45,17 @@ index cc8d67df5e074beb8c41bb6ce4f519f963e59d0d..9b1152db265afd87f17f0b7d4b2d09f4
+ for (ContextKey<?> reqKey : required) {
+ if (!this.params.containsKey(reqKey)) {
+ if (missing == null) {
+ missing = new HashSet<>();
+ missing = new java.util.HashSet<>();
+ }
+ missing.add(reqKey);
}
}
+ }
+ }
+ if (missing != null) {
+ throw new IllegalArgumentException("Missing required parameters: " + missing);
+ }
+
+ return new ContextMap(this.params);
+ // Leaf end - Optimize ContextMap.create
}
}
}

View File

@@ -1,11 +1,11 @@
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
Subject: [PATCH] Micro optimizations for random tick
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
index b5a61261083ddab70582c1a1d5cac0b9ced9b652..ab8cc4e2c74d4b214fd24f5ea415a8dc8f24bb57 100644
index b5a61261083ddab70582c1a1d5cac0b9ced9b652..ab84d6a07c094b9fb23cd63504d7652342fd6974 100644
--- a/net/minecraft/server/level/ServerLevel.java
+++ b/net/minecraft/server/level/ServerLevel.java
@@ -924,7 +924,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
@@ -13,7 +13,7 @@ index b5a61261083ddab70582c1a1d5cac0b9ced9b652..ab8cc4e2c74d4b214fd24f5ea415a8dc
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 - no redundant cast
+ 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();
@@ -22,7 +22,7 @@ index b5a61261083ddab70582c1a1d5cac0b9ced9b652..ab8cc4e2c74d4b214fd24f5ea415a8dc
for (int sectionIndex = 0, sectionsLen = sections.length; sectionIndex < sectionsLen; sectionIndex++) {
- final int offsetY = (sectionIndex + minSection) << 4;
+ // Leaf start - continue early
+ // 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()) {
@@ -30,43 +30,43 @@ index b5a61261083ddab70582c1a1d5cac0b9ced9b652..ab8cc4e2c74d4b214fd24f5ea415a8dc
}
+ 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
+ // 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 - no redundant cast
+ 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 - inline one-time value
+ 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 - no unnecessary operations
+ 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 - no redundant mask
+ 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 - no redundant cast
+ 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 - no redundant cast
+ fluidState.randomTick(this, pos, simpleRandom); // Leaf - Micro optimizations for random tick - no redundant cast
}
}
}
}
-
- return;
+ // Leaf - no redundant return
+ // Leaf - Micro optimizations for random tick - no redundant return
}
// Paper end - optimise random ticking

View File

@@ -5,19 +5,10 @@ Subject: [PATCH] Remove streams on updateConnectedPlayersWithinRange
diff --git a/net/minecraft/world/level/block/entity/vault/VaultSharedData.java b/net/minecraft/world/level/block/entity/vault/VaultSharedData.java
index 50d6ff126a35ce8613175b550dac50cd82c43f9d..8fc21228a77206387d341734e6fd9df1f641958d 100644
index 50d6ff126a35ce8613175b550dac50cd82c43f9d..ea76c2084a5591ec2373172a6f31b10d12f13849 100644
--- a/net/minecraft/world/level/block/entity/vault/VaultSharedData.java
+++ b/net/minecraft/world/level/block/entity/vault/VaultSharedData.java
@@ -3,6 +3,8 @@ package net.minecraft.world.level.block.entity.vault;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import it.unimi.dsi.fastutil.objects.ObjectLinkedOpenHashSet;
+
+import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
@@ -65,11 +67,15 @@ public class VaultSharedData {
@@ -65,11 +65,17 @@ public class VaultSharedData {
}
void updateConnectedPlayersWithinRange(ServerLevel level, BlockPos pos, VaultServerData serverData, VaultConfig config, double deactivationRange) {
@@ -26,7 +17,8 @@ index 50d6ff126a35ce8613175b550dac50cd82c43f9d..8fc21228a77206387d341734e6fd9df1
- .stream()
- .filter(uuid -> !serverData.getRewardedPlayers().contains(uuid))
- .collect(Collectors.toSet());
+ List<UUID> detectedPlayers = config.playerDetector().detect(level, config.entitySelector(), pos, deactivationRange, false);
+ // Leaf start - Remove streams on updateConnectedPlayersWithinRange
+ java.util.List<UUID> detectedPlayers = config.playerDetector().detect(level, config.entitySelector(), pos, deactivationRange, false);
+ Set<UUID> set = new ObjectLinkedOpenHashSet<>();
+
+ for (UUID uuid : detectedPlayers) {
@@ -34,6 +26,7 @@ index 50d6ff126a35ce8613175b550dac50cd82c43f9d..8fc21228a77206387d341734e6fd9df1
+ set.add(uuid);
+ }
+ }
+ // Leaf end - Remove streams on updateConnectedPlayersWithinRange
+
if (!this.connectedPlayers.equals(set)) {
this.connectedPlayers = set;

View File

@@ -5,17 +5,10 @@ Subject: [PATCH] Remove streams on PlayerDetector
diff --git a/net/minecraft/world/level/block/entity/trialspawner/PlayerDetector.java b/net/minecraft/world/level/block/entity/trialspawner/PlayerDetector.java
index 774d4028f0be7c388abb47f8eb97011341f50f59..80e69b296594e589fa680d0fa08e42f1c07d82a9 100644
index 774d4028f0be7c388abb47f8eb97011341f50f59..1597af2092e993efb1c02f92ed14d8c5a500403a 100644
--- a/net/minecraft/world/level/block/entity/trialspawner/PlayerDetector.java
+++ b/net/minecraft/world/level/block/entity/trialspawner/PlayerDetector.java
@@ -1,5 +1,6 @@
package net.minecraft.world.level.block.entity.trialspawner;
+import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
@@ -21,27 +22,42 @@ import net.minecraft.world.phys.Vec3;
@@ -21,27 +21,42 @@ import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.CollisionContext;
public interface PlayerDetector {
@@ -30,7 +23,7 @@ index 774d4028f0be7c388abb47f8eb97011341f50f59..80e69b296594e589fa680d0fa08e42f1
- .toList();
- PlayerDetector INCLUDING_CREATIVE_PLAYERS = (level, entitySelector, pos, maxDistance, requireLineOfSight) -> entitySelector.getPlayers(
+ );
+ List<UUID> result = new ArrayList<>();
+ List<UUID> result = new java.util.ArrayList<>();
+ for (Player player : players) {
+ if (!requireLineOfSight || inLineOfSight(level, pos.getCenter(), player.getEyePosition())) {
+ result.add(player.getUUID());
@@ -48,7 +41,7 @@ index 774d4028f0be7c388abb47f8eb97011341f50f59..80e69b296594e589fa680d0fa08e42f1
- .map(Entity::getUUID)
- .toList();
+ );
+ List<UUID> result = new ArrayList<>();
+ List<UUID> result = new java.util.ArrayList<>();
+ for (Player player : players) {
+ if (!requireLineOfSight || inLineOfSight(level, pos.getCenter(), player.getEyePosition())) {
+ result.add(player.getUUID());
@@ -65,7 +58,7 @@ index 774d4028f0be7c388abb47f8eb97011341f50f59..80e69b296594e589fa680d0fa08e42f1
- .map(Entity::getUUID)
- .toList();
+ List<? extends Entity> sheep = entitySelector.getEntities(level, EntityType.SHEEP, aabb, LivingEntity::isAlive);
+ List<UUID> result = new ArrayList<>();
+ List<UUID> result = new java.util.ArrayList<>();
+ for (Entity entity : sheep) {
+ if (!requireLineOfSight || inLineOfSight(level, pos.getCenter(), entity.getEyePosition())) {
+ result.add(entity.getUUID());
@@ -75,12 +68,12 @@ index 774d4028f0be7c388abb47f8eb97011341f50f59..80e69b296594e589fa680d0fa08e42f1
};
List<UUID> detect(ServerLevel level, PlayerDetector.EntitySelector entitySelector, BlockPos pos, double maxDistance, boolean flag);
@@ -78,14 +94,27 @@ public interface PlayerDetector {
@@ -78,14 +93,27 @@ public interface PlayerDetector {
return new PlayerDetector.EntitySelector() {
@Override
public List<Player> getPlayers(ServerLevel level, Predicate<? super Player> predicate) {
- return players.stream().filter(predicate).toList();
+ List<Player> result = new ArrayList<>();
+ List<Player> result = new java.util.ArrayList<>();
+ for (Player player : players) {
+ if (predicate.test(player)) {
+ result.add(player);
@@ -94,7 +87,7 @@ index 774d4028f0be7c388abb47f8eb97011341f50f59..80e69b296594e589fa680d0fa08e42f1
ServerLevel level, EntityTypeTest<Entity, T> typeTest, AABB boundingBox, Predicate<? super T> predicate
) {
- return players.stream().map(typeTest::tryCast).filter(Objects::nonNull).filter(predicate).toList();
+ List<T> result = new ArrayList<>();
+ List<T> result = new java.util.ArrayList<>();
+ for (Player player : players) {
+ T entity = typeTest.tryCast(player);
+ if (entity != null && predicate.test(entity)) {

View File

@@ -1,7 +1,7 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Taiyou06 <kaandindar21@gmail.com>
Date: Sun, 23 Mar 2025 11:51:44 +0100
Subject: [PATCH] AsyncBlockFinding
Subject: [PATCH] Async Block Finding
diff --git a/net/minecraft/world/entity/ai/goal/MoveToBlockGoal.java b/net/minecraft/world/entity/ai/goal/MoveToBlockGoal.java

View File

@@ -1,7 +1,7 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Taiyou06 <kaandindar21@gmail.com>
Date: Sun, 23 Mar 2025 20:48:16 +0100
Subject: [PATCH] Direct iteration on Sensing.tick
Subject: [PATCH] Use direct iteration on Sensing.tick
diff --git a/net/minecraft/world/entity/ai/sensing/Sensing.java b/net/minecraft/world/entity/ai/sensing/Sensing.java

View File

@@ -27,7 +27,6 @@ public class SparklyPaperParallelWorldTicking extends ConfigModules {
**实验性功能**
启用并行世界处理以提高多核系统的性能.""");
enabled = config.getBoolean(getBasePath() + ".enabled", enabled);
threads = config.getInt(getBasePath() + ".threads", threads);
threads = enabled ? threads : 0;

View File

@@ -19,7 +19,9 @@ public class FastRNG extends ConfigModules {
public static boolean useLegacyForSlimeChunk = false;
public static boolean useDirectImpl = false;
public static boolean worldgenEnabled() {return enabled && enableForWorldgen;} // Helper function
public static boolean worldgenEnabled() {
return enabled && enableForWorldgen;
} // Helper function
@Override
public void onLoaded() {

View File

@@ -3,8 +3,8 @@ package org.dreeam.leaf.util.map;
import it.unimi.dsi.fastutil.longs.*;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantLock;
@@ -41,8 +41,8 @@ public final class ConcurrentLongHashSet extends LongOpenHashSet implements Long
/**
* Creates a new concurrent long set with the specified parameters.
*
* @param initialCapacity the initial capacity
* @param loadFactor the load factor
* @param initialCapacity the initial capacity
* @param loadFactor the load factor
* @param concurrencyLevel the concurrency level
*/
public ConcurrentLongHashSet(int initialCapacity, float loadFactor, int concurrencyLevel) {
@@ -465,9 +465,7 @@ public final class ConcurrentLongHashSet extends LongOpenHashSet implements Long
void clear() {
lock.lock();
try {
for (int i = 0; i < used.length; i++) {
used[i] = false;
}
Arrays.fill(used, false);
size = 0;
} finally {
lock.unlock();

View File

@@ -11,7 +11,6 @@ import java.util.concurrent.ThreadLocalRandom;
import java.util.random.RandomGenerator;
import java.util.random.RandomGeneratorFactory;
public class FasterRandomSource implements BitRandomSource {
private static final int INT_BITS = 48;
@@ -42,6 +41,7 @@ public class FasterRandomSource implements BitRandomSource {
if (isSplittableGenerator) {
return new FasterRandomSource(seed, ((RandomGenerator.SplittableGenerator) this.randomGenerator).split());
}
return new FasterRandomSource(this.nextLong());
}
@@ -61,10 +61,9 @@ public class FasterRandomSource implements BitRandomSource {
if (useDirectImpl) {
// Direct
return (int) ((seed = seed * MULTIPLIER + INCREMENT & SEED_MASK) >>> (INT_BITS - bits));
} else {
// old
return (int) ((seed * MULTIPLIER + INCREMENT & SEED_MASK) >>> (INT_BITS - bits));
}
return (int) ((seed * MULTIPLIER + INCREMENT & SEED_MASK) >>> (INT_BITS - bits));
}
public static class FasterRandomSourcePositionalRandomFactory implements PositionalRandomFactory {
@@ -104,9 +103,9 @@ public class FasterRandomSource implements BitRandomSource {
if (useDirectImpl) {
return (int) (((seed = seed * MULTIPLIER + INCREMENT & SEED_MASK) >>> 16) ^
((seed = seed * MULTIPLIER + INCREMENT & SEED_MASK) >>> 32));
} else {
return randomGenerator.nextInt();
}
return randomGenerator.nextInt();
}
@Override
@@ -121,45 +120,45 @@ public class FasterRandomSource implements BitRandomSource {
val = bits % bound;
} while (bits - val + (bound - 1) < 0);
return val;
} else {
return randomGenerator.nextInt(bound);
}
return randomGenerator.nextInt(bound);
}
@Override
public final long nextLong() {
if (useDirectImpl) {
return ((long) next(32) << 32) + next(32);
} else {
return randomGenerator.nextLong();
}
return randomGenerator.nextLong();
}
@Override
public final boolean nextBoolean() {
if (useDirectImpl) {
return next(1) != 0;
} else {
return randomGenerator.nextBoolean();
}
return randomGenerator.nextBoolean();
}
@Override
public final float nextFloat() {
if (useDirectImpl) {
return next(24) / ((float) (1 << 24));
} else {
return randomGenerator.nextFloat();
}
return randomGenerator.nextFloat();
}
@Override
public final double nextDouble() {
if (useDirectImpl) {
return (((long) next(26) << 27) + next(27)) / (double) (1L << 53);
} else {
return randomGenerator.nextDouble();
}
return randomGenerator.nextDouble();
}
@Override