mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-30 20:39:21 +00:00
Some work
This commit is contained in:
@@ -0,0 +1,184 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Kevin Raneri <kevin.raneri@gmail.com>
|
||||
Date: Wed, 10 Nov 2021 00:37:03 -0500
|
||||
Subject: [PATCH] Pufferfish: Optimize mob spawning
|
||||
|
||||
Original license: GPL v3
|
||||
Original project: https://github.com/pufferfish-gg/Pufferfish
|
||||
|
||||
Co-authored-by: booky10 <boooky10@gmail.com>
|
||||
|
||||
This patch aims to reduce the main-thread impact of mob spawning by
|
||||
offloading as much work as possible to other threads. It is possible for
|
||||
inconsistencies to come up, but when they happen they never interfere
|
||||
with the server's operation (they don't produce errors), and side
|
||||
effects are limited to more or less mobs being spawned in any particular
|
||||
tick.
|
||||
|
||||
It is possible to disable this optimization if it is not required or if
|
||||
it interferes with any plugins. On servers with thousands of entities,
|
||||
this can result in performance gains of up to 15%, which is significant
|
||||
and, in my opinion, worth the low risk of minor mob-spawning-related
|
||||
inconsistencies.
|
||||
|
||||
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
|
||||
index 99e9fe7562520e37f8b0fa938b53a973b23c65c3..ff1f5943cb99353df6069060c67da86516c9c956 100644
|
||||
--- a/net/minecraft/server/MinecraftServer.java
|
||||
+++ b/net/minecraft/server/MinecraftServer.java
|
||||
@@ -285,6 +285,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||||
public boolean isIteratingOverLevels = false; // Paper - Throw exception on world create while being ticked
|
||||
private final Set<String> pluginsBlockingSleep = new java.util.HashSet<>(); // Paper - API to allow/disallow tick sleeping
|
||||
public static final long SERVER_INIT = System.nanoTime(); // Paper - Lag compensation
|
||||
+ public gg.pufferfish.pufferfish.util.AsyncExecutor mobSpawnExecutor = new gg.pufferfish.pufferfish.util.AsyncExecutor("MobSpawning"); // Pufferfish - optimize mob spawning
|
||||
|
||||
public static <S extends MinecraftServer> S spin(Function<Thread, S> threadFunction) {
|
||||
AtomicReference<S> atomicReference = new AtomicReference<>();
|
||||
diff --git a/net/minecraft/server/dedicated/DedicatedServer.java b/net/minecraft/server/dedicated/DedicatedServer.java
|
||||
index cd266af35c7b8455af19adc9b0874cdd7572217f..349eafa321c955c6bda7a5aa6931311d85867565 100644
|
||||
--- a/net/minecraft/server/dedicated/DedicatedServer.java
|
||||
+++ b/net/minecraft/server/dedicated/DedicatedServer.java
|
||||
@@ -320,6 +320,8 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
|
||||
LOGGER.info("JMX monitoring enabled");
|
||||
}
|
||||
|
||||
+ if (org.dreeam.leaf.config.modules.async.AsyncMobSpawning.enabled) mobSpawnExecutor.start(); // Pufferfish
|
||||
+
|
||||
return true;
|
||||
}
|
||||
}
|
||||
diff --git a/net/minecraft/server/level/ServerChunkCache.java b/net/minecraft/server/level/ServerChunkCache.java
|
||||
index 52cef9fed4a68d16d89eabacbad073ead0685972..229e115447b06db3e3b440ee8ea0505979656846 100644
|
||||
--- a/net/minecraft/server/level/ServerChunkCache.java
|
||||
+++ b/net/minecraft/server/level/ServerChunkCache.java
|
||||
@@ -182,6 +182,8 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
|
||||
}
|
||||
// Paper end - chunk tick iteration optimisations
|
||||
|
||||
+ public boolean firstRunSpawnCounts = true; // Pufferfish
|
||||
+ public final java.util.concurrent.atomic.AtomicBoolean _pufferfish_spawnCountsReady = new java.util.concurrent.atomic.AtomicBoolean(false); // Pufferfish - optimize countmobs
|
||||
|
||||
public ServerChunkCache(
|
||||
ServerLevel level,
|
||||
@@ -506,6 +508,54 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
|
||||
|
||||
this.broadcastChangedChunks(); // Gale - Purpur - remove vanilla profiler
|
||||
}
|
||||
+
|
||||
+ // Pufferfish start - optimize mob spawning
|
||||
+ if (org.dreeam.leaf.config.modules.async.AsyncMobSpawning.enabled) {
|
||||
+ for (ServerPlayer player : this.level.players) {
|
||||
+ // Paper start - per player mob spawning backoff
|
||||
+ for (int ii = 0; ii < ServerPlayer.MOBCATEGORY_TOTAL_ENUMS; ii++) {
|
||||
+ player.mobCounts[ii] = 0;
|
||||
+
|
||||
+ int newBackoff = player.mobBackoffCounts[ii] - 1; // TODO make configurable bleed // TODO use nonlinear algorithm?
|
||||
+ if (newBackoff < 0) {
|
||||
+ newBackoff = 0;
|
||||
+ }
|
||||
+ player.mobBackoffCounts[ii] = newBackoff;
|
||||
+ }
|
||||
+ // Paper end - per player mob spawning backoff
|
||||
+ }
|
||||
+ if (firstRunSpawnCounts) {
|
||||
+ firstRunSpawnCounts = false;
|
||||
+ _pufferfish_spawnCountsReady.set(true);
|
||||
+ }
|
||||
+ if (_pufferfish_spawnCountsReady.getAndSet(false)) {
|
||||
+ net.minecraft.server.MinecraftServer.getServer().mobSpawnExecutor.submit(() -> {
|
||||
+ int mapped = distanceManager.getNaturalSpawnChunkCount();
|
||||
+ ca.spottedleaf.moonrise.common.list.IteratorSafeOrderedReferenceSet.Iterator<Entity> objectiterator =
|
||||
+ level.entityTickList.entities.iterator(ca.spottedleaf.moonrise.common.list.IteratorSafeOrderedReferenceSet.ITERATOR_FLAG_SEE_ADDITIONS);
|
||||
+ try {
|
||||
+ gg.pufferfish.pufferfish.util.IterableWrapper<Entity> wrappedIterator =
|
||||
+ new gg.pufferfish.pufferfish.util.IterableWrapper<>(objectiterator);
|
||||
+ // Fix: Use proper mob cap calculator based on configuration
|
||||
+ LocalMobCapCalculator mobCapCalculator = !level.paperConfig().entities.spawning.perPlayerMobSpawns ?
|
||||
+ new LocalMobCapCalculator(chunkMap) : null;
|
||||
+
|
||||
+ // This ensures the caps are properly enforced by using the correct calculator
|
||||
+ lastSpawnState = NaturalSpawner.createState(
|
||||
+ mapped,
|
||||
+ wrappedIterator,
|
||||
+ ServerChunkCache.this::getFullChunk,
|
||||
+ mobCapCalculator, // This is the key fix - was previously null
|
||||
+ level.paperConfig().entities.spawning.perPlayerMobSpawns
|
||||
+ );
|
||||
+ } finally {
|
||||
+ objectiterator.finishedIterating();
|
||||
+ }
|
||||
+ _pufferfish_spawnCountsReady.set(true);
|
||||
+ });
|
||||
+ }
|
||||
+ }
|
||||
+ // Pufferfish end
|
||||
}
|
||||
|
||||
private void broadcastChangedChunks() { // Gale - Purpur - remove vanilla profiler
|
||||
@@ -524,6 +574,7 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
|
||||
// Paper start - Optional per player mob spawns
|
||||
NaturalSpawner.SpawnState spawnState;
|
||||
if ((this.spawnFriendlies || this.spawnEnemies) && this.level.paperConfig().entities.spawning.perPlayerMobSpawns) { // don't count mobs when animals and monsters are disabled
|
||||
+ if (!org.dreeam.leaf.config.modules.async.AsyncMobSpawning.enabled) { // Pufferfish - moved down when async processing
|
||||
// re-set mob counts
|
||||
for (ServerPlayer player : this.level.players) {
|
||||
// Paper start - per player mob spawning backoff
|
||||
@@ -538,12 +589,16 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
|
||||
}
|
||||
// Paper end - per player mob spawning backoff
|
||||
}
|
||||
- spawnState = NaturalSpawner.createState(naturalSpawnChunkCount, this.level.getAllEntities(), this::getFullChunk, null, true);
|
||||
+ lastSpawnState = NaturalSpawner.createState(naturalSpawnChunkCount, this.level.getAllEntities(), this::getFullChunk, null, true); // Pufferfish - async mob spawning
|
||||
+ } // Pufferfish - (endif) moved down when async processing
|
||||
} else {
|
||||
- spawnState = NaturalSpawner.createState(naturalSpawnChunkCount, this.level.getAllEntities(), this::getFullChunk, !this.level.paperConfig().entities.spawning.perPlayerMobSpawns ? new LocalMobCapCalculator(this.chunkMap) : null, false);
|
||||
+ // Pufferfish start - async mob spawning
|
||||
+ lastSpawnState = NaturalSpawner.createState(naturalSpawnChunkCount, this.level.getAllEntities(), this::getFullChunk, !this.level.paperConfig().entities.spawning.perPlayerMobSpawns ? new LocalMobCapCalculator(this.chunkMap) : null, false);
|
||||
+ _pufferfish_spawnCountsReady.set(true);
|
||||
+ // Pufferfish end
|
||||
}
|
||||
// Paper end - Optional per player mob spawns
|
||||
- this.lastSpawnState = spawnState;
|
||||
+ //this.lastSpawnState = spawnState; // Pufferfish - this is managed asynchronously
|
||||
boolean _boolean = this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBSPAWNING) && !this.level.players().isEmpty(); // CraftBukkit
|
||||
int _int = this.level.getGameRules().getInt(GameRules.RULE_RANDOMTICKING);
|
||||
List<MobCategory> filteredSpawningCategories;
|
||||
@@ -557,7 +612,7 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
|
||||
}
|
||||
// Paper end - PlayerNaturallySpawnCreaturesEvent
|
||||
boolean flag = this.level.ticksPerSpawnCategory.getLong(org.bukkit.entity.SpawnCategory.ANIMAL) != 0L && this.level.getLevelData().getGameTime() % this.level.ticksPerSpawnCategory.getLong(org.bukkit.entity.SpawnCategory.ANIMAL) == 0L; // CraftBukkit
|
||||
- filteredSpawningCategories = NaturalSpawner.getFilteredSpawningCategories(spawnState, this.spawnFriendlies, this.spawnEnemies, flag, this.level); // CraftBukkit
|
||||
+ filteredSpawningCategories = NaturalSpawner.getFilteredSpawningCategories(lastSpawnState, this.spawnFriendlies, this.spawnEnemies, flag, this.level); // CraftBukkit // Pufferfish
|
||||
} else {
|
||||
filteredSpawningCategories = List.of();
|
||||
}
|
||||
@@ -572,7 +627,7 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
|
||||
// Paper end - chunk tick iteration optimisation
|
||||
|
||||
for (LevelChunk levelChunk : list) {
|
||||
- this.tickSpawningChunk(levelChunk, timeInhabited, filteredSpawningCategories, spawnState);
|
||||
+ this.tickSpawningChunk(levelChunk, timeInhabited, filteredSpawningCategories, lastSpawnState); // Pufferfish
|
||||
}
|
||||
} finally {
|
||||
list.clear();
|
||||
@@ -592,7 +647,7 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
|
||||
}
|
||||
|
||||
if (!spawnCategories.isEmpty()) {
|
||||
- if (this.level.getWorldBorder().isWithinBounds(pos)) { // Paper - rewrite chunk system
|
||||
+ if (this.level.getWorldBorder().isWithinBounds(pos) && (!org.dreeam.leaf.config.modules.async.AsyncMobSpawning.enabled || _pufferfish_spawnCountsReady.get())) { // Paper - rewrite chunk system // Pufferfish
|
||||
NaturalSpawner.spawnForChunk(this.level, chunk, spawnState, spawnCategories);
|
||||
}
|
||||
}
|
||||
diff --git a/net/minecraft/world/level/entity/EntityTickList.java b/net/minecraft/world/level/entity/EntityTickList.java
|
||||
index 423779a2b690f387a4f0bd07b97b50e0baefda76..dec51066fc3f57b7bdc56195313c219f45a7fbee 100644
|
||||
--- a/net/minecraft/world/level/entity/EntityTickList.java
|
||||
+++ b/net/minecraft/world/level/entity/EntityTickList.java
|
||||
@@ -9,7 +9,7 @@ import javax.annotation.Nullable;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
|
||||
public class EntityTickList {
|
||||
- private final ca.spottedleaf.moonrise.common.list.IteratorSafeOrderedReferenceSet<net.minecraft.world.entity.Entity> entities = new ca.spottedleaf.moonrise.common.list.IteratorSafeOrderedReferenceSet<>(); // Paper - rewrite chunk system
|
||||
+ public final ca.spottedleaf.moonrise.common.list.IteratorSafeOrderedReferenceSet<net.minecraft.world.entity.Entity> entities = new ca.spottedleaf.moonrise.common.list.IteratorSafeOrderedReferenceSet<>(); // Paper - rewrite chunk system // Pufferfish - private->public
|
||||
|
||||
private void ensureActiveIsNotIterated() {
|
||||
// Paper - rewrite chunk system
|
||||
@@ -7,10 +7,10 @@ Original license: MIT
|
||||
Original project: https://github.com/PurpurMC/Purpur
|
||||
|
||||
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
|
||||
index 99e9fe7562520e37f8b0fa938b53a973b23c65c3..c84f187395d6b2d4c2e891aa545324f213902457 100644
|
||||
index ff1f5943cb99353df6069060c67da86516c9c956..0c4c76eb3fe04a67784997a19678f081eb86d00e 100644
|
||||
--- a/net/minecraft/server/MinecraftServer.java
|
||||
+++ b/net/minecraft/server/MinecraftServer.java
|
||||
@@ -1804,7 +1804,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||||
@@ -1805,7 +1805,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||||
|
||||
@DontObfuscate
|
||||
public String getServerModName() {
|
||||
@@ -0,0 +1,40 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Blast-MC <cjblanton2@gmail.com>
|
||||
Date: Thu, 25 Aug 2022 20:32:01 -0400
|
||||
Subject: [PATCH] Parchment: Make FixLight use action bar
|
||||
|
||||
Original license: GPLv3
|
||||
Original project: https://github.com/ProjectEdenGG/Parchment
|
||||
|
||||
diff --git a/io/papermc/paper/command/subcommands/FixLightCommand.java b/io/papermc/paper/command/subcommands/FixLightCommand.java
|
||||
index 85950a1aa732ab8c01ad28bec9e0de140e1a172e..8e8d1a38290c2dc3f88deda64d050e89273a5b89 100644
|
||||
--- a/io/papermc/paper/command/subcommands/FixLightCommand.java
|
||||
+++ b/io/papermc/paper/command/subcommands/FixLightCommand.java
|
||||
@@ -95,17 +95,20 @@ public final class FixLightCommand implements PaperSubcommand {
|
||||
((StarLightLightingProvider)lightengine).starlight$serverRelightChunks(chunks,
|
||||
(final ChunkPos chunkPos) -> {
|
||||
++relitChunks[0];
|
||||
- sender.getBukkitEntity().sendMessage(text().color(DARK_AQUA).append(
|
||||
- text("Relit chunk ", BLUE), text(chunkPos.toString()),
|
||||
- text(", progress: ", BLUE), text(ONE_DECIMAL_PLACES.get().format(100.0 * (double) (relitChunks[0]) / (double) pending[0]) + "%")
|
||||
- ));
|
||||
+ sender.getBukkitEntity().sendActionBar(text().color(DARK_AQUA).append(
|
||||
+ text("Relighting Chunks: ", DARK_AQUA), text(chunkPos.toString()),
|
||||
+ text(" " + relitChunks[0], net.kyori.adventure.text.format.NamedTextColor.YELLOW),
|
||||
+ text("/", DARK_AQUA),
|
||||
+ text(pending[0] + " ", net.kyori.adventure.text.format.NamedTextColor.YELLOW),
|
||||
+ text("(" + ONE_DECIMAL_PLACES.get().format(100.0 * (double) (relitChunks[0]) / (double) pending[0]) + "%)", net.kyori.adventure.text.format.NamedTextColor.YELLOW)
|
||||
+ )); // Leaf - Parchment - Make FixLight use action bar
|
||||
},
|
||||
(final int totalRelit) -> {
|
||||
final long end = System.nanoTime();
|
||||
sender.getBukkitEntity().sendMessage(text().color(DARK_AQUA).append(
|
||||
- text("Relit ", BLUE), text(totalRelit),
|
||||
- text(" chunks. Took ", BLUE), text(ONE_DECIMAL_PLACES.get().format(1.0e-6 * (end - start)) + "ms")
|
||||
- ));
|
||||
+ text("Relit ", DARK_AQUA), text(totalRelit, net.kyori.adventure.text.format.NamedTextColor.YELLOW),
|
||||
+ text(" chunks. Took ", DARK_AQUA), text(ONE_DECIMAL_PLACES.get().format(1.0e-6 * (end - start)) + "ms", net.kyori.adventure.text.format.NamedTextColor.YELLOW)
|
||||
+ )); // Leaf - Parchment - Make FixLight use action bar
|
||||
if (done != null) {
|
||||
done.run();
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
|
||||
Date: Tue, 2 Jan 2024 21:13:53 -0500
|
||||
Subject: [PATCH] Faster sequencing of futures for chunk structure gen
|
||||
|
||||
Replace `thenApply` with `thenCompose`. Once one task is completed then the next task starts immediately,
|
||||
to prevent blocking threads while waiting to complete all tasks. But may cause the sequence of future compose disorder.
|
||||
|
||||
diff --git a/net/minecraft/Util.java b/net/minecraft/Util.java
|
||||
index d1fcc73f579d1c4ac79213ad039c8d803ff51b1a..9918572306e983281d05c6d28c8a5d843348ad2d 100644
|
||||
--- a/net/minecraft/Util.java
|
||||
+++ b/net/minecraft/Util.java
|
||||
@@ -620,17 +620,39 @@ public class Util {
|
||||
return Maps.transformValues(map, mapper);
|
||||
}
|
||||
|
||||
+ // Leaf start - Faster sequencing of futures for chunk structure gen
|
||||
public static <V> CompletableFuture<List<V>> sequence(List<? extends CompletableFuture<V>> futures) {
|
||||
+ return sequence(futures, false);
|
||||
+ }
|
||||
+ public static <V> CompletableFuture<List<V>> sequence(List<? extends CompletableFuture<V>> futures, boolean useFaster) {
|
||||
+ // Leaf end - Faster sequencing of futures for chunk structure gen
|
||||
if (futures.isEmpty()) {
|
||||
return CompletableFuture.completedFuture(List.of());
|
||||
} else if (futures.size() == 1) {
|
||||
return futures.get(0).thenApply(List::of);
|
||||
} else {
|
||||
CompletableFuture<Void> completableFuture = CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]));
|
||||
+ if (useFaster) return sequenceFaster(futures, completableFuture); // Leaf - Faster sequencing of futures for chunk structure gen
|
||||
return completableFuture.thenApply(_void -> futures.stream().map(CompletableFuture::join).toList());
|
||||
}
|
||||
}
|
||||
|
||||
+ // Leaf start - Faster sequencing of futures for chunk structure gen
|
||||
+ private static <V> CompletableFuture<List<V>> sequenceFaster(List<? extends CompletableFuture<V>> futures, CompletableFuture<Void> completableFuture) {
|
||||
+ return completableFuture.thenCompose($ ->
|
||||
+ CompletableFuture.supplyAsync(() -> {
|
||||
+ List<V> list = new java.util.ArrayList<>();
|
||||
+
|
||||
+ for (CompletableFuture<V> future : futures) {
|
||||
+ list.add(future.join());
|
||||
+ }
|
||||
+
|
||||
+ return list;
|
||||
+ }
|
||||
+ ));
|
||||
+ }
|
||||
+ // Leaf end - Faster sequencing of futures for chunk structure gen
|
||||
+
|
||||
public static <V> CompletableFuture<List<V>> sequenceFailFast(List<? extends CompletableFuture<? extends V>> completableFutures) {
|
||||
CompletableFuture<List<V>> completableFuture = new CompletableFuture<>();
|
||||
return fallibleSequence(completableFutures, completableFuture::completeExceptionally).applyToEither(completableFuture, Function.identity());
|
||||
diff --git a/net/minecraft/server/ReloadableServerRegistries.java b/net/minecraft/server/ReloadableServerRegistries.java
|
||||
index d8c472b8c6aadcaadef14abd8ab43f466e94417e..bc079b6c3d751f2a63d089bf209cf7d8e0da76e8 100644
|
||||
--- a/net/minecraft/server/ReloadableServerRegistries.java
|
||||
+++ b/net/minecraft/server/ReloadableServerRegistries.java
|
||||
@@ -52,7 +52,7 @@ public class ReloadableServerRegistries {
|
||||
List<CompletableFuture<WritableRegistry<?>>> list1 = LootDataType.values()
|
||||
.map(lootDataType -> scheduleRegistryLoad((LootDataType<?>)lootDataType, registryOps, resourceManager, backgroundExecutor, conversions)) // Paper
|
||||
.toList();
|
||||
- CompletableFuture<List<WritableRegistry<?>>> completableFuture = Util.sequence(list1);
|
||||
+ CompletableFuture<List<WritableRegistry<?>>> completableFuture = Util.sequence(list1, false); // Leaf - Faster sequencing of futures for chunk structure gen
|
||||
return completableFuture.thenApplyAsync(
|
||||
list2 -> createAndValidateFullContext(registryAccess, provider, (List<WritableRegistry<?>>)list2), backgroundExecutor
|
||||
);
|
||||
diff --git a/net/minecraft/world/level/chunk/ChunkGeneratorStructureState.java b/net/minecraft/world/level/chunk/ChunkGeneratorStructureState.java
|
||||
index 619b98e42e254c0c260c171a26a2472ddf59b885..f07a5416e5dc7e9a798a78ce9573a0c42bc59d04 100644
|
||||
--- a/net/minecraft/world/level/chunk/ChunkGeneratorStructureState.java
|
||||
+++ b/net/minecraft/world/level/chunk/ChunkGeneratorStructureState.java
|
||||
@@ -255,7 +255,7 @@ public class ChunkGeneratorStructureState {
|
||||
}
|
||||
}
|
||||
|
||||
- return Util.sequence(list).thenApply(completed -> {
|
||||
+ return Util.sequence(list, org.dreeam.leaf.config.modules.opt.FasterStructureGenFutureSequencing.enabled).thenApply(completed -> { // Leaf - Faster sequencing of futures for chunk structure gen
|
||||
double d2 = stopwatch.stop().elapsed(TimeUnit.MILLISECONDS) / 1000.0;
|
||||
LOGGER.debug("Calculation for {} took {}s", structureSet, d2);
|
||||
return completed;
|
||||
@@ -0,0 +1,27 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
|
||||
Date: Mon, 15 Jan 2024 10:53:10 -0500
|
||||
Subject: [PATCH] Reduce active items finding hopper nearby check
|
||||
|
||||
This patch add a toggle for active items checking MinecraftHopper nearby,
|
||||
|
||||
But still recommend to turn-off `checkForMinecartNearItemWhileActive`
|
||||
Since `Reduce-hopper-item-checks.patch` will cause lag under massive dropped items
|
||||
|
||||
diff --git a/net/minecraft/world/entity/item/ItemEntity.java b/net/minecraft/world/entity/item/ItemEntity.java
|
||||
index 6d01f8f8d95573cc545a0c1058cea87f40a39f05..8773952bb271158ca5387a2e8813c16116d8ee64 100644
|
||||
--- a/net/minecraft/world/entity/item/ItemEntity.java
|
||||
+++ b/net/minecraft/world/entity/item/ItemEntity.java
|
||||
@@ -242,7 +242,11 @@ public class ItemEntity extends Entity implements TraceableEntity {
|
||||
this.discard(org.bukkit.event.entity.EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
|
||||
return; // Gale - EMC - reduce hopper item checks
|
||||
}
|
||||
- this.markNearbyHopperCartsAsImmune(); // Gale - EMC - reduce hopper item checks
|
||||
+ // Leaf start - Reduce active items finding hopper nearby check
|
||||
+ if (level().galeConfig().smallOptimizations.reducedIntervals.checkNearbyItem.hopper.minecart.temporaryImmunity.checkForMinecartNearItemWhileActive) {
|
||||
+ this.markNearbyHopperCartsAsImmune(); // Gale - EMC - reduce hopper item checks
|
||||
+ }
|
||||
+ // Leaf end - Reduce active items finding hopper nearby check
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: MrPowerGamerBR <git@mrpowergamerbr.com>
|
||||
Date: Wed, 15 Nov 2023 23:39:36 -0300
|
||||
Subject: [PATCH] SparklyPaper: Skip "distanceToSqr" call in
|
||||
"ServerEntity#sendChanges" if the delta movement hasn't changed
|
||||
|
||||
Original project: https://github.com/SparklyPower/SparklyPaper
|
||||
|
||||
The "distanceToSqr" call is a bit expensive, so avoiding it is pretty nice, around ~15% calls are skipped with this check
|
||||
|
||||
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 bcbc25c6dc5a2063b1ad410194a25b0d5ff7c8d8..936429fd17d8649329e6258a4e10c9e6bf62f6de 100644
|
||||
--- a/net/minecraft/server/level/ServerEntity.java
|
||||
+++ b/net/minecraft/server/level/ServerEntity.java
|
||||
@@ -206,6 +206,7 @@ public class ServerEntity {
|
||||
|
||||
if (this.entity.hasImpulse || this.trackDelta || this.entity instanceof LivingEntity && ((LivingEntity)this.entity).isFallFlying()) {
|
||||
Vec3 deltaMovement = this.entity.getDeltaMovement();
|
||||
+ if (deltaMovement != this.lastSentMovement) { // SparklyPaper start - skip distanceToSqr call in ServerEntity#sendChanges if the delta movement hasn't changed
|
||||
double d = deltaMovement.distanceToSqr(this.lastSentMovement);
|
||||
if (d > 1.0E-7 || d > 0.0 && deltaMovement.lengthSqr() == 0.0) {
|
||||
this.lastSentMovement = deltaMovement;
|
||||
@@ -223,6 +224,7 @@ public class ServerEntity {
|
||||
this.broadcast.accept(new ClientboundSetEntityMotionPacket(this.entity.getId(), this.lastSentMovement));
|
||||
}
|
||||
}
|
||||
+ } // SparklyPaper end
|
||||
}
|
||||
|
||||
if (packet != null) {
|
||||
@@ -0,0 +1,25 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: MrPowerGamerBR <git@mrpowergamerbr.com>
|
||||
Date: Fri, 17 Nov 2023 14:22:41 -0300
|
||||
Subject: [PATCH] SparklyPaper: Skip "MapItem#update()" if the map does not
|
||||
have the CraftMapRenderer present
|
||||
|
||||
Original project: https://github.com/SparklyPower/SparklyPaper
|
||||
|
||||
Optimizes "image in map" maps, without requiring the map to be locked, which some old map plugins may not do
|
||||
|
||||
This has the disadvantage that the vanilla map data will never be updated while the CraftMapRenderer is not present, but that's not a huuuge problem for u
|
||||
|
||||
diff --git a/net/minecraft/world/item/MapItem.java b/net/minecraft/world/item/MapItem.java
|
||||
index ba0b254d43651bca1f29b5272af05d068fc37ba8..2c6349285f598a4fbbc891eca1fb05efab109458 100644
|
||||
--- a/net/minecraft/world/item/MapItem.java
|
||||
+++ b/net/minecraft/world/item/MapItem.java
|
||||
@@ -274,7 +274,7 @@ public class MapItem extends Item {
|
||||
savedData.tickCarriedBy(player, stack);
|
||||
}
|
||||
|
||||
- if (!savedData.locked && slot != null && slot.getType() == EquipmentSlot.Type.HAND) {
|
||||
+ if (!savedData.locked && slot != null && slot.getType() == EquipmentSlot.Type.HAND && (!org.dreeam.leaf.config.modules.opt.SkipMapItemDataUpdates.enabled || savedData.mapView.getRenderers().stream().anyMatch(mapRenderer -> mapRenderer.getClass() == org.bukkit.craftbukkit.map.CraftMapRenderer.class))) { // SparklyPaper - don't update maps if they don't have the CraftMapRenderer in the render list
|
||||
this.update(level, entity, savedData);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: MrPowerGamerBR <git@mrpowergamerbr.com>
|
||||
Date: Sun, 19 Nov 2023 12:35:16 -0300
|
||||
Subject: [PATCH] SparklyPaper: Skip EntityScheduler's executeTick checks if
|
||||
there isn't any tasks to be run
|
||||
|
||||
Original project: https://github.com/SparklyPower/SparklyPaper
|
||||
|
||||
On each tick, Paper runs EntityScheduler's executeTick of each entity. This is a bit expensive, due to ArrayDeque's size() call because it ain't a simple "get the current queue size" function, due to the thread checks, and because it needs to iterate all entities in all worlds.
|
||||
|
||||
To avoid the hefty ArrayDeque's size() call, we check if we *really* need to execute the executeTick, by adding all entities with scheduled tasks to a global set.
|
||||
|
||||
Most entities won't have any scheduled tasks, so this is a nice performance bonus. These optimizations, however, wouldn't work in a Folia environment, but because in SparklyPaper executeTick is always executed on the main thread, it ain't an issue for us (yay).
|
||||
|
||||
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
|
||||
index 0c4c76eb3fe04a67784997a19678f081eb86d00e..6685763f33a86c7faf7d26d58685e8402d399980 100644
|
||||
--- a/net/minecraft/server/MinecraftServer.java
|
||||
+++ b/net/minecraft/server/MinecraftServer.java
|
||||
@@ -286,6 +286,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||||
private final Set<String> pluginsBlockingSleep = new java.util.HashSet<>(); // Paper - API to allow/disallow tick sleeping
|
||||
public static final long SERVER_INIT = System.nanoTime(); // Paper - Lag compensation
|
||||
public gg.pufferfish.pufferfish.util.AsyncExecutor mobSpawnExecutor = new gg.pufferfish.pufferfish.util.AsyncExecutor("MobSpawning"); // Pufferfish - optimize mob spawning
|
||||
+ public final Set<net.minecraft.world.entity.Entity> entitiesWithScheduledTasks = java.util.concurrent.ConcurrentHashMap.newKeySet(); // SparklyPaper - skip EntityScheduler's executeTick checks if there isn't any tasks to be run (concurrent because plugins may schedule tasks async)
|
||||
|
||||
public static <S extends MinecraftServer> S spin(Function<Thread, S> threadFunction) {
|
||||
AtomicReference<S> atomicReference = new AtomicReference<>();
|
||||
@@ -1629,6 +1630,22 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||||
this.server.getScheduler().mainThreadHeartbeat(); // CraftBukkit
|
||||
// Paper start - Folia scheduler API
|
||||
((io.papermc.paper.threadedregions.scheduler.FoliaGlobalRegionScheduler) org.bukkit.Bukkit.getGlobalRegionScheduler()).tick();
|
||||
+ // SparklyPaper - skip EntityScheduler's executeTick checks if there isn't any tasks to be run
|
||||
+ for (final net.minecraft.world.entity.Entity entity : entitiesWithScheduledTasks) {
|
||||
+ if (entity.isRemoved()) {
|
||||
+ continue;
|
||||
+ }
|
||||
+
|
||||
+ final org.bukkit.craftbukkit.entity.CraftEntity bukkit = entity.getBukkitEntityRaw();
|
||||
+ if (bukkit != null) {
|
||||
+ io.papermc.paper.threadedregions.EntityScheduler scheduler = bukkit.taskScheduler;
|
||||
+ scheduler.executeTick();
|
||||
+ if (!scheduler.hasTasks()) {
|
||||
+ this.entitiesWithScheduledTasks.remove(entity);
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ /*
|
||||
getAllLevels().forEach(level -> {
|
||||
for (final net.minecraft.world.entity.Entity entity : level.getEntities().getAll()) {
|
||||
if (entity.isRemoved()) {
|
||||
@@ -1640,6 +1657,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||||
}
|
||||
}
|
||||
});
|
||||
+ */
|
||||
+ // SparklyPaper end
|
||||
// Paper end - Folia scheduler API
|
||||
io.papermc.paper.adventure.providers.ClickCallbackProviderImpl.CALLBACK_MANAGER.handleQueue(this.tickCount); // Paper
|
||||
this.getFunctions().tick();
|
||||
@@ -0,0 +1,30 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: MrPowerGamerBR <git@mrpowergamerbr.com>
|
||||
Date: Thu, 23 Nov 2023 14:36:47 -0300
|
||||
Subject: [PATCH] SparklyPaper: Optimize "canSee" checks
|
||||
|
||||
Original project: https://github.com/SparklyPower/SparklyPaper
|
||||
|
||||
The "canSee" checks is in a hot path, invoked by each entity for each player on the server if they are in tracking range, so optimizing it is pretty nice
|
||||
|
||||
First, we change the original "HashMap" to fastutil's "Object2ObjectOpenHashMap", because the containsKey throughput is better
|
||||
|
||||
Then, we add a "isEmpty()" check before attempting to check if the map contains something
|
||||
|
||||
This seems stupid, but it does seem that it improves the performance a bit, and it makes sense, "containsKey(...)" does not attempt to check the map size before attempting to check if the map contains the key
|
||||
|
||||
We also create a "canSee" method tailored for "ChunkMap#updatePlayer()", a method without the equals check (the "updatePlayer()" already checks if the entity is the same entity) because the CraftPlayer's `equals()` check is a *bit* expensive compared to only checking the object's identity, and because the identity has already been check, we don't need to check it twice.
|
||||
|
||||
diff --git a/net/minecraft/server/level/ChunkMap.java b/net/minecraft/server/level/ChunkMap.java
|
||||
index a95feb65b392a971ac570dd3fd771b6ff89a2684..c60b9e4076450de2157c1a3cf4f98cc2c19e4e6a 100644
|
||||
--- a/net/minecraft/server/level/ChunkMap.java
|
||||
+++ b/net/minecraft/server/level/ChunkMap.java
|
||||
@@ -1295,7 +1295,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
||||
flag = flag && this.entity.broadcastToPlayer(player) && ChunkMap.this.isChunkTracked(player, this.entity.chunkPosition().x, this.entity.chunkPosition().z);
|
||||
// Paper end - Configurable entity tracking range by Y
|
||||
// CraftBukkit start - respect vanish API
|
||||
- if (flag && !player.getBukkitEntity().canSee(this.entity.getBukkitEntity())) { // Paper - only consider hits
|
||||
+ if (flag && !player.getBukkitEntity().canSeeChunkMapUpdatePlayer(this.entity.getBukkitEntity())) { // Paper - only consider hits // SparklyPaper - optimize canSee checks
|
||||
flag = false;
|
||||
}
|
||||
// CraftBukkit end
|
||||
@@ -0,0 +1,24 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: MrPowerGamerBR <git@mrpowergamerbr.com>
|
||||
Date: Fri, 23 Aug 2024 16:20:45 -0300
|
||||
Subject: [PATCH] SparklyPaper: Allow throttling hopper checks if the target
|
||||
container is full
|
||||
|
||||
Original project: https://github.com/SparklyPower/SparklyPaper
|
||||
|
||||
diff --git a/net/minecraft/world/level/block/entity/HopperBlockEntity.java b/net/minecraft/world/level/block/entity/HopperBlockEntity.java
|
||||
index c2c7832fbb207ecfd23c7a086ef72db9648f48f9..0ea3fef7cccbbeac608e87313e809fbc045a1bdf 100644
|
||||
--- a/net/minecraft/world/level/block/entity/HopperBlockEntity.java
|
||||
+++ b/net/minecraft/world/level/block/entity/HopperBlockEntity.java
|
||||
@@ -423,6 +423,11 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
|
||||
} else {
|
||||
Direction opposite = blockEntity.facing.getOpposite();
|
||||
if (isFullContainer(attachedContainer, opposite)) {
|
||||
+ // Leaf start - SparklyPaper - Throttle hopper when full
|
||||
+ if (org.dreeam.leaf.config.modules.opt.ThrottleHopperWhenFull.enabled && org.dreeam.leaf.config.modules.opt.ThrottleHopperWhenFull.skipTicks > 0) {
|
||||
+ blockEntity.setCooldown(org.dreeam.leaf.config.modules.opt.ThrottleHopperWhenFull.skipTicks);
|
||||
+ }
|
||||
+ // Leaf end - SparklyPaper - Throttle hopper when full
|
||||
return false;
|
||||
} else {
|
||||
// Paper start - Perf: Optimize Hoppers
|
||||
@@ -0,0 +1,43 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: lilingfengdev <145678359+lilingfengdev@users.noreply.github.com>
|
||||
Date: Thu, 18 Jan 2024 13:30:02 +0800
|
||||
Subject: [PATCH] Polpot: Make egg and snowball can knockback player
|
||||
|
||||
Original project: https://github.com/HaHaWTH/Polpot
|
||||
|
||||
diff --git a/net/minecraft/world/entity/projectile/Snowball.java b/net/minecraft/world/entity/projectile/Snowball.java
|
||||
index 677b4b681f9c2c09a8ae3cfdec72102265547a7b..b5ee9ff679a8e9ec441154b698ed0196d525ae67 100644
|
||||
--- a/net/minecraft/world/entity/projectile/Snowball.java
|
||||
+++ b/net/minecraft/world/entity/projectile/Snowball.java
|
||||
@@ -54,6 +54,12 @@ public class Snowball extends ThrowableItemProjectile {
|
||||
Entity entity = result.getEntity();
|
||||
int i = entity instanceof Blaze ? 3 : 0;
|
||||
entity.hurt(this.damageSources().thrown(this, this.getOwner()), i);
|
||||
+ // Leaf start - Polpot - Make snowball can knockback player
|
||||
+ if (org.dreeam.leaf.config.modules.gameplay.Knockback.snowballCanKnockback && entity instanceof net.minecraft.server.level.ServerPlayer serverPlayer) {
|
||||
+ entity.hurt(this.damageSources().thrown(this, this.getOwner()), 0.0000001F);
|
||||
+ serverPlayer.knockback(0.4000000059604645D, this.getX() - entity.getX(), this.getZ() - entity.getZ());
|
||||
+ }
|
||||
+ // Leaf end - Polpot - Make snowball can knockback player
|
||||
}
|
||||
|
||||
@Override
|
||||
diff --git a/net/minecraft/world/entity/projectile/ThrownEgg.java b/net/minecraft/world/entity/projectile/ThrownEgg.java
|
||||
index 73ec34b43f3fb2aa3edc3f1cb48a923d1fa32036..0e4cba55c15d17af2dff7d9e10cecaf821853475 100644
|
||||
--- a/net/minecraft/world/entity/projectile/ThrownEgg.java
|
||||
+++ b/net/minecraft/world/entity/projectile/ThrownEgg.java
|
||||
@@ -54,7 +54,14 @@ public class ThrownEgg extends ThrowableItemProjectile {
|
||||
@Override
|
||||
protected void onHitEntity(EntityHitResult result) {
|
||||
super.onHitEntity(result);
|
||||
+ net.minecraft.world.entity.Entity entity = result.getEntity(); // Polpot - make egg can knockback player
|
||||
result.getEntity().hurt(this.damageSources().thrown(this, this.getOwner()), 0.0F);
|
||||
+ // Leaf start - Polpot - Make egg can knockback player
|
||||
+ if (org.dreeam.leaf.config.modules.gameplay.Knockback.eggCanKnockback && entity instanceof net.minecraft.server.level.ServerPlayer serverPlayer) {
|
||||
+ entity.hurt(this.damageSources().thrown(this, this.getOwner()), 0.0000001F);
|
||||
+ serverPlayer.knockback(0.4000000059604645D, this.getX() - entity.getX(), this.getZ() - entity.getZ());
|
||||
+ }
|
||||
+ // Leaf end - Polpot - Make egg can knockback player
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -0,0 +1,23 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
|
||||
Date: Mon, 19 Feb 2024 13:10:16 -0500
|
||||
Subject: [PATCH] Redirect vanilla getProfiler to inactive in
|
||||
PathNavigationRegion
|
||||
|
||||
To fix compatibility with some plugins, e.g. Citizens, ModelEngine, etc.
|
||||
|
||||
diff --git a/net/minecraft/world/level/PathNavigationRegion.java b/net/minecraft/world/level/PathNavigationRegion.java
|
||||
index 21dee87c792dcba52d9dff637e4729a2ec377ac0..89571b56618ad83b8fd1c218f0f2bb0a72ea3d49 100644
|
||||
--- a/net/minecraft/world/level/PathNavigationRegion.java
|
||||
+++ b/net/minecraft/world/level/PathNavigationRegion.java
|
||||
@@ -153,4 +153,10 @@ public class PathNavigationRegion implements CollisionGetter {
|
||||
public int getHeight() {
|
||||
return this.level.getHeight();
|
||||
}
|
||||
+
|
||||
+ // Leaf start - Redirect vanilla getProfiler to inactive in PathNavigationRegion
|
||||
+ public net.minecraft.util.profiling.ProfilerFiller getProfiler() {
|
||||
+ return net.minecraft.util.profiling.InactiveProfiler.INSTANCE; // Gale - Purpur - remove vanilla profiler
|
||||
+ }
|
||||
+ // Leaf end - Redirect vanilla getProfiler to inactive in PathNavigationRegion
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
|
||||
Date: Tue, 27 Feb 2024 03:17:10 -0500
|
||||
Subject: [PATCH] Remove useless creating stats json bases on player name logic
|
||||
|
||||
|
||||
diff --git a/net/minecraft/server/players/PlayerList.java b/net/minecraft/server/players/PlayerList.java
|
||||
index 8bbf8d660a68c8c74204e101ec3ec0b775883090..68d8bb239c2e48e5b3e280676274067e1f597620 100644
|
||||
--- a/net/minecraft/server/players/PlayerList.java
|
||||
+++ b/net/minecraft/server/players/PlayerList.java
|
||||
@@ -1377,6 +1377,8 @@ public abstract class PlayerList {
|
||||
if (serverStatsCounter == null) {
|
||||
File file = this.server.getWorldPath(LevelResource.PLAYER_STATS_DIR).toFile();
|
||||
File file1 = new File(file, uuid + ".json");
|
||||
+ // Leaf start - Remove useless creating stats json bases on player name logic
|
||||
+ /*
|
||||
if (!file1.exists()) {
|
||||
File file2 = new File(file, displayName + ".json"); // CraftBukkit
|
||||
Path path = file2.toPath();
|
||||
@@ -1384,6 +1386,8 @@ public abstract class PlayerList {
|
||||
file2.renameTo(file1);
|
||||
}
|
||||
}
|
||||
+ */
|
||||
+ // Leaf end - Remove useless creating stats json bases on player name logic
|
||||
|
||||
serverStatsCounter = new ServerStatsCounter(this.server, file1);
|
||||
// this.stats.put(uuid, serverStatsCounter); // CraftBukkit
|
||||
@@ -0,0 +1,19 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com>
|
||||
Date: Fri, 25 Oct 2024 02:27:21 +0800
|
||||
Subject: [PATCH] Virtual thread for chat executor
|
||||
|
||||
|
||||
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
|
||||
index 6685763f33a86c7faf7d26d58685e8402d399980..8d8e6cc29a783810a27483ad213f020979ede359 100644
|
||||
--- a/net/minecraft/server/MinecraftServer.java
|
||||
+++ b/net/minecraft/server/MinecraftServer.java
|
||||
@@ -2628,7 +2628,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||||
}
|
||||
|
||||
public final java.util.concurrent.ExecutorService chatExecutor = java.util.concurrent.Executors.newCachedThreadPool(
|
||||
- new com.google.common.util.concurrent.ThreadFactoryBuilder().setDaemon(true).setNameFormat("Async Chat Thread - #%d").setUncaughtExceptionHandler(new net.minecraft.DefaultUncaughtExceptionHandlerWithName(net.minecraft.server.MinecraftServer.LOGGER)).build()); // Paper
|
||||
+ new com.google.common.util.concurrent.ThreadFactoryBuilder().setDaemon(true).setNameFormat("Async Chat Thread - #%d").setThreadFactory(org.dreeam.leaf.config.modules.opt.VT4ChatExecutor.enabled ? Thread.ofVirtual().factory() : java.util.concurrent.Executors.defaultThreadFactory()).setUncaughtExceptionHandler(new net.minecraft.DefaultUncaughtExceptionHandlerWithName(net.minecraft.server.MinecraftServer.LOGGER)).build()); // Paper // Leaf - Virtual thread for chat executor
|
||||
public final ChatDecorator improvedChatDecorator = new io.papermc.paper.adventure.ImprovedChatDecorator(this); // Paper - adventure
|
||||
|
||||
public ChatDecorator getChatDecorator() {
|
||||
@@ -0,0 +1,19 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com>
|
||||
Date: Tue, 31 Dec 2024 00:00:00 -0800
|
||||
Subject: [PATCH] Virtual thread for user authenticator
|
||||
|
||||
|
||||
diff --git a/net/minecraft/server/network/ServerLoginPacketListenerImpl.java b/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
||||
index 0dc83987ac145a5ad0452eb588365a20498f9e87..451a8b9f4deda749b0cb08adb4b5408c2e3ffd93 100644
|
||||
--- a/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
||||
+++ b/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
||||
@@ -54,7 +54,7 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
|
||||
// CraftBukkit end
|
||||
private static final AtomicInteger UNIQUE_THREAD_ID = new AtomicInteger(0);
|
||||
static final Logger LOGGER = LogUtils.getLogger();
|
||||
- private static final java.util.concurrent.ExecutorService authenticatorPool = java.util.concurrent.Executors.newCachedThreadPool(new com.google.common.util.concurrent.ThreadFactoryBuilder().setNameFormat("User Authenticator #%d").setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(LOGGER)).build()); // Paper - Cache authenticator threads
|
||||
+ private static final java.util.concurrent.ExecutorService authenticatorPool = java.util.concurrent.Executors.newCachedThreadPool(new com.google.common.util.concurrent.ThreadFactoryBuilder().setNameFormat("User Authenticator #%d").setThreadFactory(org.dreeam.leaf.config.modules.opt.VT4UserAuthenticator.enabled ? Thread.ofVirtual().factory() : java.util.concurrent.Executors.defaultThreadFactory()).setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(LOGGER)).build()); // Paper - Cache authenticator threads // Leaf - Virtual thread for user authenticator
|
||||
private static final int MAX_TICKS_BEFORE_LOGIN = 600;
|
||||
private final byte[] challenge;
|
||||
final MinecraftServer server;
|
||||
@@ -0,0 +1,160 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: etil2jz <81570777+etil2jz@users.noreply.github.com>
|
||||
Date: Tue, 2 Aug 2022 14:48:12 +0200
|
||||
Subject: [PATCH] Mirai: Configurable chat message signatures
|
||||
|
||||
Fixed & Updated by Dreeam-qwq
|
||||
Original license: GPLv3
|
||||
Original project: https://github.com/Dreeam-qwq/Mirai
|
||||
|
||||
Original license: GPLv3
|
||||
Original project: https://github.com/etil2jz/Mirai
|
||||
|
||||
diff --git a/net/minecraft/network/FriendlyByteBuf.java b/net/minecraft/network/FriendlyByteBuf.java
|
||||
index 7da7d645f83f351e8c964da01734f3074a877ca1..76576f2fd8b267d96186ab337bf4e41520e3cd18 100644
|
||||
--- a/net/minecraft/network/FriendlyByteBuf.java
|
||||
+++ b/net/minecraft/network/FriendlyByteBuf.java
|
||||
@@ -118,6 +118,17 @@ public class FriendlyByteBuf extends ByteBuf {
|
||||
public <T> void writeJsonWithCodec(Codec<T> codec, T value, int maxLength) {
|
||||
// Paper end - Adventure; add max length parameter
|
||||
DataResult<JsonElement> dataResult = codec.encodeStart(JsonOps.INSTANCE, value);
|
||||
+ // Leaf start - Configurable chat message signatures
|
||||
+ if (!org.dreeam.leaf.config.modules.network.ChatMessageSignature.enabled && codec == net.minecraft.network.protocol.status.ServerStatus.CODEC) {
|
||||
+ JsonElement element = dataResult.getOrThrow(string -> new EncoderException("Failed to encode: " + string + " " + value));
|
||||
+
|
||||
+ element.getAsJsonObject().addProperty("preventsChatReports", true);
|
||||
+ this.writeUtf(GSON.toJson(element));
|
||||
+
|
||||
+ return;
|
||||
+ }
|
||||
+ // Leaf end - Configurable chat message signatures
|
||||
+
|
||||
this.writeUtf(GSON.toJson(dataResult.getOrThrow(exception -> new EncoderException("Failed to encode: " + exception + " " + value))), maxLength); // Paper - Adventure; add max length parameter
|
||||
}
|
||||
|
||||
diff --git a/net/minecraft/network/protocol/game/ClientboundLoginPacket.java b/net/minecraft/network/protocol/game/ClientboundLoginPacket.java
|
||||
index 89f06581e2b1f9f0240e7841db2f57dedc5d81b7..ba4ec05a9c9dfa958fdfa4a68ee85bcd9c379883 100644
|
||||
--- a/net/minecraft/network/protocol/game/ClientboundLoginPacket.java
|
||||
+++ b/net/minecraft/network/protocol/game/ClientboundLoginPacket.java
|
||||
@@ -55,7 +55,7 @@ public record ClientboundLoginPacket(
|
||||
buffer.writeBoolean(this.showDeathScreen);
|
||||
buffer.writeBoolean(this.doLimitedCrafting);
|
||||
this.commonPlayerSpawnInfo.write(buffer);
|
||||
- buffer.writeBoolean(this.enforcesSecureChat);
|
||||
+ buffer.writeBoolean(!org.dreeam.leaf.config.modules.network.ChatMessageSignature.enabled || this.enforcesSecureChat); // Leaf - Mirai - Configurable chat message signatures
|
||||
}
|
||||
|
||||
@Override
|
||||
diff --git a/net/minecraft/network/protocol/game/ServerboundChatPacket.java b/net/minecraft/network/protocol/game/ServerboundChatPacket.java
|
||||
index b5afc05924ae899e020c303c8b86398e1d4ab8a0..73c2ed488c34cddbafdcbb6f2636264ebcc7286b 100644
|
||||
--- a/net/minecraft/network/protocol/game/ServerboundChatPacket.java
|
||||
+++ b/net/minecraft/network/protocol/game/ServerboundChatPacket.java
|
||||
@@ -23,7 +23,7 @@ public record ServerboundChatPacket(String message, Instant timeStamp, long salt
|
||||
buffer.writeUtf(this.message, 256);
|
||||
buffer.writeInstant(this.timeStamp);
|
||||
buffer.writeLong(this.salt);
|
||||
- buffer.writeNullable(this.signature, MessageSignature::write);
|
||||
+ if (org.dreeam.leaf.config.modules.network.ChatMessageSignature.enabled) buffer.writeNullable(this.signature, MessageSignature::write); // Leaf - Mirai - Configurable chat message signatures
|
||||
this.lastSeenMessages.write(buffer);
|
||||
}
|
||||
|
||||
diff --git a/net/minecraft/network/protocol/status/ServerStatus.java b/net/minecraft/network/protocol/status/ServerStatus.java
|
||||
index 094d1821d298fc228270b2d6cf0445949434f3e2..21334ae4764740e5cf1382726d5f5231fa220d5d 100644
|
||||
--- a/net/minecraft/network/protocol/status/ServerStatus.java
|
||||
+++ b/net/minecraft/network/protocol/status/ServerStatus.java
|
||||
@@ -23,7 +23,10 @@ public record ServerStatus(
|
||||
boolean enforcesSecureChat
|
||||
) {
|
||||
public static final Codec<ServerStatus> CODEC = RecordCodecBuilder.create(
|
||||
- instance -> instance.group(
|
||||
+ // Leaf start - Mirai - Configurable chat message signatures
|
||||
+ instance ->
|
||||
+ org.dreeam.leaf.config.modules.network.ChatMessageSignature.enabled
|
||||
+ ? instance.group(
|
||||
ComponentSerialization.CODEC.lenientOptionalFieldOf("description", CommonComponents.EMPTY).forGetter(ServerStatus::description),
|
||||
ServerStatus.Players.CODEC.lenientOptionalFieldOf("players").forGetter(ServerStatus::players),
|
||||
ServerStatus.Version.CODEC.lenientOptionalFieldOf("version").forGetter(ServerStatus::version),
|
||||
@@ -31,6 +34,15 @@ public record ServerStatus(
|
||||
Codec.BOOL.lenientOptionalFieldOf("enforcesSecureChat", false).forGetter(ServerStatus::enforcesSecureChat)
|
||||
)
|
||||
.apply(instance, ServerStatus::new)
|
||||
+ : instance.group(
|
||||
+ ComponentSerialization.CODEC.lenientOptionalFieldOf("description", CommonComponents.EMPTY).forGetter(ServerStatus::description),
|
||||
+ ServerStatus.Players.CODEC.lenientOptionalFieldOf("players").forGetter(ServerStatus::players),
|
||||
+ ServerStatus.Version.CODEC.lenientOptionalFieldOf("version").forGetter(ServerStatus::version),
|
||||
+ ServerStatus.Favicon.CODEC.lenientOptionalFieldOf("favicon").forGetter(ServerStatus::favicon),
|
||||
+ Codec.BOOL.lenientOptionalFieldOf("enforcesSecureChat", false).forGetter(x -> true)
|
||||
+ )
|
||||
+ .apply(instance, ServerStatus::new)
|
||||
+ // Leaf end- Mirai - Configurable chat message signatures
|
||||
);
|
||||
|
||||
public record Favicon(byte[] iconBytes) {
|
||||
diff --git a/net/minecraft/server/dedicated/DedicatedServer.java b/net/minecraft/server/dedicated/DedicatedServer.java
|
||||
index 349eafa321c955c6bda7a5aa6931311d85867565..f1bd860f9ab3ac2e2a09be9232550e627f3c1040 100644
|
||||
--- a/net/minecraft/server/dedicated/DedicatedServer.java
|
||||
+++ b/net/minecraft/server/dedicated/DedicatedServer.java
|
||||
@@ -580,6 +580,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
|
||||
|
||||
@Override
|
||||
public boolean enforceSecureProfile() {
|
||||
+ if (!org.dreeam.leaf.config.modules.network.ChatMessageSignature.enabled) return false; // Leaf - Mirai - Configurable chat message signatures
|
||||
DedicatedServerProperties properties = this.getProperties();
|
||||
// Paper start - Add setting for proxy online mode status
|
||||
return properties.enforceSecureProfile
|
||||
diff --git a/net/minecraft/server/network/ServerCommonPacketListenerImpl.java b/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
|
||||
index 8c3255661221f8afbccb661bec3afb47e4059403..0450c85bf7c7af1c863514f7c13b5fe15233dac6 100644
|
||||
--- a/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
|
||||
+++ b/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
|
||||
@@ -308,10 +308,30 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
|
||||
}
|
||||
|
||||
public void send(Packet<?> packet) {
|
||||
+ // Leaf start - Mirai - Configurable chat message signatures
|
||||
+ if (!org.dreeam.leaf.config.modules.network.ChatMessageSignature.enabled) {
|
||||
+ if (packet instanceof net.minecraft.network.protocol.game.ClientboundPlayerChatPacket chat) {
|
||||
+ packet = new net.minecraft.network.protocol.game.ClientboundSystemChatPacket(
|
||||
+ chat.chatType().decorate(chat.unsignedContent() != null ? chat.unsignedContent() : Component.literal(chat.body().content())),
|
||||
+ false
|
||||
+ );
|
||||
+ this.send(packet);
|
||||
+ return;
|
||||
+ }
|
||||
+ }
|
||||
+ // Leaf end - Mirai - Configurable chat message signatures
|
||||
this.send(packet, null);
|
||||
}
|
||||
|
||||
public void send(Packet<?> packet, @Nullable PacketSendListener listener) {
|
||||
+ // Leaf start - Mirai - Configurable chat message signatures
|
||||
+ if (!org.dreeam.leaf.config.modules.network.ChatMessageSignature.enabled) {
|
||||
+ if (packet instanceof net.minecraft.network.protocol.game.ClientboundPlayerChatPacket chat && listener != null) {
|
||||
+ this.send(chat);
|
||||
+ return;
|
||||
+ }
|
||||
+ }
|
||||
+ // Leaf end - Mirai - Configurable chat message signatures
|
||||
// CraftBukkit start
|
||||
if (packet == null || this.processedDisconnect) { // Spigot
|
||||
return;
|
||||
diff --git a/net/minecraft/server/players/PlayerList.java b/net/minecraft/server/players/PlayerList.java
|
||||
index 68d8bb239c2e48e5b3e280676274067e1f597620..a6340714eab6d7eafae639c6aeb2aeb75a0e6c07 100644
|
||||
--- a/net/minecraft/server/players/PlayerList.java
|
||||
+++ b/net/minecraft/server/players/PlayerList.java
|
||||
@@ -1336,7 +1336,7 @@ public abstract class PlayerList {
|
||||
public void broadcastChatMessage(PlayerChatMessage message, Predicate<ServerPlayer> shouldFilterMessageTo, @Nullable ServerPlayer sender, ChatType.Bound boundChatType, @Nullable Function<net.kyori.adventure.audience.Audience, Component> unsignedFunction) {
|
||||
// Paper end
|
||||
boolean flag = this.verifyChatTrusted(message);
|
||||
- this.server.logChatMessage((unsignedFunction == null ? message.decoratedContent() : unsignedFunction.apply(this.server.console)), boundChatType, flag || !org.galemc.gale.configuration.GaleGlobalConfiguration.get().logToConsole.chat.notSecureMarker ? null : "Not Secure"); // Paper // Gale - do not log Not Secure marker
|
||||
+ this.server.logChatMessage((unsignedFunction == null ? message.decoratedContent() : unsignedFunction.apply(this.server.console)), boundChatType, !org.dreeam.leaf.config.modules.network.ChatMessageSignature.enabled || flag || !org.galemc.gale.configuration.GaleGlobalConfiguration.get().logToConsole.chat.notSecureMarker ? null : "Not Secure"); // Paper // Gale - do not log Not Secure marker // Leaf - Mirai - Configurable chat message signatures
|
||||
OutgoingChatMessage outgoingChatMessage = OutgoingChatMessage.create(message);
|
||||
boolean flag1 = false;
|
||||
|
||||
@@ -1361,6 +1361,7 @@ public abstract class PlayerList {
|
||||
}
|
||||
|
||||
public boolean verifyChatTrusted(PlayerChatMessage message) {
|
||||
+ if (!org.dreeam.leaf.config.modules.network.ChatMessageSignature.enabled) return true; // Leaf - Mirai - Configurable chat message signatures
|
||||
return message.hasSignature() && !message.hasExpiredServer(Instant.now());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
|
||||
Date: Thu, 28 Mar 2024 13:36:09 -0400
|
||||
Subject: [PATCH] Cache player profileResult
|
||||
|
||||
|
||||
diff --git a/net/minecraft/server/network/ServerLoginPacketListenerImpl.java b/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
||||
index 451a8b9f4deda749b0cb08adb4b5408c2e3ffd93..0aa72ed879e9f7199b75defca884bf8242caae99 100644
|
||||
--- a/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
||||
+++ b/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
||||
@@ -70,6 +70,11 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
|
||||
private net.minecraft.server.level.ServerPlayer player; // CraftBukkit
|
||||
public boolean iKnowThisMayNotBeTheBestIdeaButPleaseDisableUsernameValidation = false; // Paper - username validation overriding
|
||||
private int velocityLoginMessageId = -1; // Paper - Add Velocity IP Forwarding Support
|
||||
+ // Leaf start - Cache player profileResult
|
||||
+ private static final com.github.benmanes.caffeine.cache.Cache<String, ProfileResult> playerProfileResultCache = com.github.benmanes.caffeine.cache.Caffeine.newBuilder()
|
||||
+ .expireAfterWrite(org.dreeam.leaf.config.modules.misc.Cache.cachePlayerProfileResultTimeout, java.util.concurrent.TimeUnit.MINUTES)
|
||||
+ .build();
|
||||
+ // Leaf end - Cache player profileResult
|
||||
|
||||
public ServerLoginPacketListenerImpl(MinecraftServer server, Connection connection, boolean transferred) {
|
||||
this.server = server;
|
||||
@@ -303,9 +308,23 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
|
||||
String string1 = Objects.requireNonNull(ServerLoginPacketListenerImpl.this.requestedUsername, "Player name not initialized");
|
||||
|
||||
try {
|
||||
- ProfileResult profileResult = ServerLoginPacketListenerImpl.this.server
|
||||
- .getSessionService()
|
||||
- .hasJoinedServer(string1, string, this.getAddress());
|
||||
+ // Leaf start - Cache player profileResult
|
||||
+ ProfileResult profileResult;
|
||||
+ if (org.dreeam.leaf.config.modules.misc.Cache.cachePlayerProfileResult) {
|
||||
+ profileResult = playerProfileResultCache.getIfPresent(string1);
|
||||
+
|
||||
+ if (profileResult == null) {
|
||||
+ profileResult = ServerLoginPacketListenerImpl.this.server
|
||||
+ .getSessionService()
|
||||
+ .hasJoinedServer(string1, string, this.getAddress());
|
||||
+ playerProfileResultCache.put(string1, profileResult);
|
||||
+ }
|
||||
+ } else {
|
||||
+ profileResult = ServerLoginPacketListenerImpl.this.server
|
||||
+ .getSessionService()
|
||||
+ .hasJoinedServer(string1, string, this.getAddress());
|
||||
+ }
|
||||
+ // Leaf end - Cache player profileResult
|
||||
if (profileResult != null) {
|
||||
GameProfile gameProfile = profileResult.profile();
|
||||
// CraftBukkit start - fire PlayerPreLoginEvent
|
||||
@@ -0,0 +1,428 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Apehum <apehumchik@gmail.com>
|
||||
Date: Thu, 9 Dec 2021 02:18:17 +0800
|
||||
Subject: [PATCH] Matter: Secure Seed
|
||||
|
||||
TODO - Dreeam:
|
||||
Update to BLAKE3
|
||||
|
||||
Original license: GPLv3
|
||||
Original project: https://github.com/plasmoapp/matter
|
||||
|
||||
Co-authored-by: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
|
||||
Co-authored-by: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com>
|
||||
|
||||
diff --git a/net/minecraft/server/dedicated/DedicatedServerProperties.java b/net/minecraft/server/dedicated/DedicatedServerProperties.java
|
||||
index f6518e29f805018c72222f5aaa7b662071665b65..1bf57875cb363e08734222ed59f3b77a2d0dfba5 100644
|
||||
--- a/net/minecraft/server/dedicated/DedicatedServerProperties.java
|
||||
+++ b/net/minecraft/server/dedicated/DedicatedServerProperties.java
|
||||
@@ -113,7 +113,17 @@ public class DedicatedServerProperties extends Settings<DedicatedServerPropertie
|
||||
String string = this.get("level-seed", "");
|
||||
boolean flag = this.get("generate-structures", true);
|
||||
long l = WorldOptions.parseSeed(string).orElse(WorldOptions.randomSeed());
|
||||
- this.worldOptions = new WorldOptions(l, flag, false);
|
||||
+ // Leaf start - Matter - Secure Seed
|
||||
+ if (org.dreeam.leaf.config.modules.misc.SecureSeed.enabled) {
|
||||
+ String featureSeedStr = this.get("feature-level-seed", "");
|
||||
+ long[] featureSeed = su.plo.matter.Globals.parseSeed(featureSeedStr)
|
||||
+ .orElse(su.plo.matter.Globals.createRandomWorldSeed());
|
||||
+
|
||||
+ this.worldOptions = new WorldOptions(l, featureSeed, flag, false);
|
||||
+ } else {
|
||||
+ this.worldOptions = new WorldOptions(l, flag, false);
|
||||
+ }
|
||||
+ // Leaf end - Matter - Secure Seed
|
||||
this.worldDimensionData = new DedicatedServerProperties.WorldDimensionData(
|
||||
this.get("generator-settings", property -> GsonHelper.parse(!property.isEmpty() ? property : "{}"), new JsonObject()),
|
||||
this.get("level-type", property -> property.toLowerCase(Locale.ROOT), WorldPresets.NORMAL.location().toString())
|
||||
diff --git a/net/minecraft/server/level/ServerChunkCache.java b/net/minecraft/server/level/ServerChunkCache.java
|
||||
index 229e115447b06db3e3b440ee8ea0505979656846..a9acfc3ba6c3447b4632d32fe24e9a09d55ba1e2 100644
|
||||
--- a/net/minecraft/server/level/ServerChunkCache.java
|
||||
+++ b/net/minecraft/server/level/ServerChunkCache.java
|
||||
@@ -674,6 +674,7 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
|
||||
}
|
||||
|
||||
public ChunkGenerator getGenerator() {
|
||||
+ su.plo.matter.Globals.setupGlobals(level); // Leaf - Matter - Secure Seed
|
||||
return this.chunkMap.generator();
|
||||
}
|
||||
|
||||
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
|
||||
index cce8c151e46873c2de9be77d832bf695ee44ee24..27b9669330e43c9a5679a44cc105e8de0b36d184 100644
|
||||
--- a/net/minecraft/server/level/ServerLevel.java
|
||||
+++ b/net/minecraft/server/level/ServerLevel.java
|
||||
@@ -604,6 +604,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
||||
chunkGenerator = new org.bukkit.craftbukkit.generator.CustomChunkGenerator(this, chunkGenerator, gen);
|
||||
}
|
||||
// CraftBukkit end
|
||||
+ su.plo.matter.Globals.setupGlobals(this); // Leaf - Matter - Secure Seed
|
||||
boolean flag = server.forceSynchronousWrites();
|
||||
DataFixer fixerUpper = server.getFixerUpper();
|
||||
// Paper - rewrite chunk system
|
||||
diff --git a/net/minecraft/world/entity/monster/Slime.java b/net/minecraft/world/entity/monster/Slime.java
|
||||
index 6a8a5a76400beeaf69a17d53105a7a522ec5791e..cd6b9c40658b5caf804ebfe5419581894b067d59 100644
|
||||
--- a/net/minecraft/world/entity/monster/Slime.java
|
||||
+++ b/net/minecraft/world/entity/monster/Slime.java
|
||||
@@ -328,7 +328,11 @@ public class Slime extends Mob implements Enemy {
|
||||
}
|
||||
|
||||
ChunkPos chunkPos = new ChunkPos(pos);
|
||||
- boolean flag = level.getMinecraftWorld().paperConfig().entities.spawning.allChunksAreSlimeChunks || WorldgenRandom.seedSlimeChunk(chunkPos.x, chunkPos.z, ((WorldGenLevel) level).getSeed(), level.getMinecraftWorld().spigotConfig.slimeSeed).nextInt(10) == 0; // Paper
|
||||
+ // Leaf start - Matter - Secure Seed
|
||||
+ boolean flag = level.getMinecraftWorld().paperConfig().entities.spawning.allChunksAreSlimeChunks || org.dreeam.leaf.config.modules.misc.SecureSeed.enabled
|
||||
+ ? level.getChunk(chunkPos.x, chunkPos.z).isSlimeChunk()
|
||||
+ : WorldgenRandom.seedSlimeChunk(chunkPos.x, chunkPos.z, ((WorldGenLevel) level).getSeed(), level.getMinecraftWorld().spigotConfig.slimeSeed).nextInt(10) == 0; // Paper
|
||||
+ // Leaf end - Matter - Secure Seed
|
||||
// Paper start - Replace rules for Height in Slime Chunks
|
||||
final double maxHeightSlimeChunk = level.getMinecraftWorld().paperConfig().entities.spawning.slimeSpawnHeight.slimeChunk.maximum;
|
||||
if (random.nextInt(10) == 0 && flag && pos.getY() < maxHeightSlimeChunk) {
|
||||
diff --git a/net/minecraft/world/level/chunk/ChunkAccess.java b/net/minecraft/world/level/chunk/ChunkAccess.java
|
||||
index 3b7f0d5fe40bdda65ab859a0c22bf0d369dc0f01..6683df8d0f5a61ab094393f761a3d3a22d6e0455 100644
|
||||
--- a/net/minecraft/world/level/chunk/ChunkAccess.java
|
||||
+++ b/net/minecraft/world/level/chunk/ChunkAccess.java
|
||||
@@ -87,6 +87,10 @@ public abstract class ChunkAccess implements BiomeManager.NoiseBiomeSource, Ligh
|
||||
public org.bukkit.craftbukkit.persistence.DirtyCraftPersistentDataContainer persistentDataContainer = new org.bukkit.craftbukkit.persistence.DirtyCraftPersistentDataContainer(ChunkAccess.DATA_TYPE_REGISTRY);
|
||||
// CraftBukkit end
|
||||
public final Registry<Biome> biomeRegistry; // CraftBukkit
|
||||
+ // Leaf start - Matter - Secure Seed
|
||||
+ private boolean slimeChunk;
|
||||
+ private boolean hasComputedSlimeChunk;
|
||||
+ // Leaf end - Matter - Secure Seed
|
||||
|
||||
// Paper start - rewrite chunk system
|
||||
private volatile ca.spottedleaf.moonrise.patches.starlight.light.SWMRNibbleArray[] blockNibbles;
|
||||
@@ -191,6 +195,17 @@ public abstract class ChunkAccess implements BiomeManager.NoiseBiomeSource, Ligh
|
||||
return GameEventListenerRegistry.NOOP;
|
||||
}
|
||||
|
||||
+ // Leaf start - Matter - Secure Seed
|
||||
+ public boolean isSlimeChunk() {
|
||||
+ if (!hasComputedSlimeChunk) {
|
||||
+ hasComputedSlimeChunk = true;
|
||||
+ slimeChunk = su.plo.matter.WorldgenCryptoRandom.seedSlimeChunk(chunkPos.x, chunkPos.z).nextInt(10) == 0;
|
||||
+ }
|
||||
+
|
||||
+ return slimeChunk;
|
||||
+ }
|
||||
+ // Leaf end - Matter - Secure Seed
|
||||
+
|
||||
public abstract BlockState getBlockState(final int x, final int y, final int z); // Paper
|
||||
|
||||
@Nullable
|
||||
diff --git a/net/minecraft/world/level/chunk/ChunkGenerator.java b/net/minecraft/world/level/chunk/ChunkGenerator.java
|
||||
index 857aa6e29b57a0a8eea4d7c14971b9dde59bb0d0..23806f5f0c6c4ec9a86a6ea13b89b4f57372e6f1 100644
|
||||
--- a/net/minecraft/world/level/chunk/ChunkGenerator.java
|
||||
+++ b/net/minecraft/world/level/chunk/ChunkGenerator.java
|
||||
@@ -342,7 +342,11 @@ public abstract class ChunkGenerator {
|
||||
Registry<Structure> registry = level.registryAccess().lookupOrThrow(Registries.STRUCTURE);
|
||||
Map<Integer, List<Structure>> map = registry.stream().collect(Collectors.groupingBy(structure1 -> structure1.step().ordinal()));
|
||||
List<FeatureSorter.StepFeatureData> list = this.featuresPerStep.get();
|
||||
- WorldgenRandom worldgenRandom = new WorldgenRandom(new XoroshiroRandomSource(RandomSupport.generateUniqueSeed()));
|
||||
+ // Leaf start - Matter - Secure Seed
|
||||
+ WorldgenRandom worldgenRandom = org.dreeam.leaf.config.modules.misc.SecureSeed.enabled
|
||||
+ ? new su.plo.matter.WorldgenCryptoRandom(blockPos.getX(), blockPos.getZ(), su.plo.matter.Globals.Salt.UNDEFINED, 0)
|
||||
+ : new WorldgenRandom(new XoroshiroRandomSource(RandomSupport.generateUniqueSeed()));
|
||||
+ // Leaf end - Matter - Secure Seed
|
||||
long l = worldgenRandom.setDecorationSeed(level.getSeed(), blockPos.getX(), blockPos.getZ());
|
||||
Set<Holder<Biome>> set = new ObjectArraySet<>();
|
||||
ChunkPos.rangeClosed(sectionPos.chunk(), 1).forEach(chunkPos -> {
|
||||
@@ -551,8 +555,15 @@ public abstract class ChunkGenerator {
|
||||
} else {
|
||||
ArrayList<StructureSet.StructureSelectionEntry> list1 = new ArrayList<>(list.size());
|
||||
list1.addAll(list);
|
||||
- WorldgenRandom worldgenRandom = new WorldgenRandom(new LegacyRandomSource(0L));
|
||||
- worldgenRandom.setLargeFeatureSeed(structureState.getLevelSeed(), pos.x, pos.z);
|
||||
+ // Leaf start - Matter - Secure Seed
|
||||
+ WorldgenRandom worldgenRandom;
|
||||
+ if (org.dreeam.leaf.config.modules.misc.SecureSeed.enabled) {
|
||||
+ worldgenRandom = new su.plo.matter.WorldgenCryptoRandom(pos.x, pos.z, su.plo.matter.Globals.Salt.GENERATE_FEATURE, 0);
|
||||
+ } else {
|
||||
+ worldgenRandom = new WorldgenRandom(new LegacyRandomSource(0L));
|
||||
+ worldgenRandom.setLargeFeatureSeed(structureState.getLevelSeed(), pos.x, pos.z);
|
||||
+ }
|
||||
+ // Leaf end - Matter - Secure Seed
|
||||
int i = 0;
|
||||
|
||||
for (StructureSet.StructureSelectionEntry structureSelectionEntry1 : list1) {
|
||||
diff --git a/net/minecraft/world/level/chunk/ChunkGeneratorStructureState.java b/net/minecraft/world/level/chunk/ChunkGeneratorStructureState.java
|
||||
index f07a5416e5dc7e9a798a78ce9573a0c42bc59d04..426692d9627f46d708f551bd22ce3c52b2a23b37 100644
|
||||
--- a/net/minecraft/world/level/chunk/ChunkGeneratorStructureState.java
|
||||
+++ b/net/minecraft/world/level/chunk/ChunkGeneratorStructureState.java
|
||||
@@ -205,7 +205,12 @@ public class ChunkGeneratorStructureState {
|
||||
List<CompletableFuture<ChunkPos>> list = new ArrayList<>(count);
|
||||
int spread = placement.spread();
|
||||
HolderSet<Biome> holderSet = placement.preferredBiomes();
|
||||
- RandomSource randomSource = RandomSource.create();
|
||||
+ // Leaf start - Matter - Secure Seed
|
||||
+ RandomSource randomSource = org.dreeam.leaf.config.modules.misc.SecureSeed.enabled
|
||||
+ ? new su.plo.matter.WorldgenCryptoRandom(0, 0, su.plo.matter.Globals.Salt.STRONGHOLDS, 0)
|
||||
+ : RandomSource.create();
|
||||
+ // Leaf end - Matter - Secure Seed
|
||||
+ if (!org.dreeam.leaf.config.modules.misc.SecureSeed.enabled) {
|
||||
// Paper start - Add missing structure set seed configs
|
||||
if (this.conf.strongholdSeed != null && structureSet.is(net.minecraft.world.level.levelgen.structure.BuiltinStructureSets.STRONGHOLDS)) {
|
||||
randomSource.setSeed(this.conf.strongholdSeed);
|
||||
@@ -213,6 +218,7 @@ public class ChunkGeneratorStructureState {
|
||||
// Paper end - Add missing structure set seed configs
|
||||
randomSource.setSeed(this.concentricRingsSeed);
|
||||
} // Paper - Add missing structure set seed configs
|
||||
+ } // Leaf - Matter - Secure Seed
|
||||
double d = randomSource.nextDouble() * Math.PI * 2.0;
|
||||
int i = 0;
|
||||
int i1 = 0;
|
||||
diff --git a/net/minecraft/world/level/chunk/status/ChunkStep.java b/net/minecraft/world/level/chunk/status/ChunkStep.java
|
||||
index b8348976e80578d9eff64eea68c04c603fed49ad..bc5c6ea1f1e4f1608a70116f03fb2a58ca3252c3 100644
|
||||
--- a/net/minecraft/world/level/chunk/status/ChunkStep.java
|
||||
+++ b/net/minecraft/world/level/chunk/status/ChunkStep.java
|
||||
@@ -60,6 +60,7 @@ public final class ChunkStep implements ca.spottedleaf.moonrise.patches.chunk_sy
|
||||
}
|
||||
|
||||
public CompletableFuture<ChunkAccess> apply(WorldGenContext worldGenContext, StaticCache2D<GenerationChunkHolder> cache, ChunkAccess chunk) {
|
||||
+ su.plo.matter.Globals.setupGlobals(worldGenContext.level()); // Leaf - Matter - Secure Seed
|
||||
if (chunk.getPersistedStatus().isBefore(this.targetStatus)) {
|
||||
ProfiledDuration profiledDuration = JvmProfiler.INSTANCE
|
||||
.onChunkGenerate(chunk.getPos(), worldGenContext.level().dimension(), this.targetStatus.getName());
|
||||
diff --git a/net/minecraft/world/level/levelgen/WorldOptions.java b/net/minecraft/world/level/levelgen/WorldOptions.java
|
||||
index c92508741439a8d0d833ea02d0104416adb83c92..c05da7cfcd3d97a1716cb305be36ba9c94217b6f 100644
|
||||
--- a/net/minecraft/world/level/levelgen/WorldOptions.java
|
||||
+++ b/net/minecraft/world/level/levelgen/WorldOptions.java
|
||||
@@ -9,8 +9,20 @@ import net.minecraft.util.RandomSource;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class WorldOptions {
|
||||
+ // Leaf start - Matter - Secure Seed
|
||||
+ private static final com.google.gson.Gson gson = new com.google.gson.Gson();
|
||||
+ private static final boolean isSecureSeedEnabled = org.dreeam.leaf.config.modules.misc.SecureSeed.enabled;
|
||||
public static final MapCodec<WorldOptions> CODEC = RecordCodecBuilder.mapCodec(
|
||||
- instance -> instance.group(
|
||||
+ instance -> isSecureSeedEnabled
|
||||
+ ? instance.group(
|
||||
+ Codec.LONG.fieldOf("seed").stable().forGetter(WorldOptions::seed),
|
||||
+ Codec.STRING.fieldOf("feature_seed").orElse(gson.toJson(su.plo.matter.Globals.createRandomWorldSeed())).stable().forGetter(WorldOptions::featureSeedSerialize),
|
||||
+ Codec.BOOL.fieldOf("generate_features").orElse(true).stable().forGetter(WorldOptions::generateStructures),
|
||||
+ Codec.BOOL.fieldOf("bonus_chest").orElse(false).stable().forGetter(WorldOptions::generateBonusChest),
|
||||
+ Codec.STRING.lenientOptionalFieldOf("legacy_custom_options").stable().forGetter(worldOptions -> worldOptions.legacyCustomOptions)
|
||||
+ )
|
||||
+ .apply(instance, instance.stable(WorldOptions::new))
|
||||
+ : instance.group(
|
||||
Codec.LONG.fieldOf("seed").stable().forGetter(WorldOptions::seed),
|
||||
Codec.BOOL.fieldOf("generate_features").orElse(true).stable().forGetter(WorldOptions::generateStructures),
|
||||
Codec.BOOL.fieldOf("bonus_chest").orElse(false).stable().forGetter(WorldOptions::generateBonusChest),
|
||||
@@ -18,8 +30,14 @@ public class WorldOptions {
|
||||
)
|
||||
.apply(instance, instance.stable(WorldOptions::new))
|
||||
);
|
||||
- public static final WorldOptions DEMO_OPTIONS = new WorldOptions("North Carolina".hashCode(), true, true);
|
||||
+ // Leaf end - Matter - Secure Seed
|
||||
+ // Leaf start - Matter - Secure Seed
|
||||
+ public static final WorldOptions DEMO_OPTIONS = isSecureSeedEnabled
|
||||
+ ? new WorldOptions((long) "North Carolina".hashCode(), su.plo.matter.Globals.createRandomWorldSeed(), true, true)
|
||||
+ : new WorldOptions("North Carolina".hashCode(), true, true);
|
||||
+ // Leaf end - Matter - Secure Seed
|
||||
private final long seed;
|
||||
+ private long[] featureSeed = su.plo.matter.Globals.createRandomWorldSeed(); // Leaf - Matter - Secure Seed
|
||||
private final boolean generateStructures;
|
||||
private final boolean generateBonusChest;
|
||||
private final Optional<String> legacyCustomOptions;
|
||||
@@ -28,14 +46,35 @@ public class WorldOptions {
|
||||
this(seed, generateStructures, generateBonusChest, Optional.empty());
|
||||
}
|
||||
|
||||
+ // Leaf start - Matter - Secure Seed
|
||||
+ public WorldOptions(long seed, long[] featureSeed, boolean generateStructures, boolean bonusChest) {
|
||||
+ this(seed, featureSeed, generateStructures, bonusChest, Optional.empty());
|
||||
+ }
|
||||
+
|
||||
+ private WorldOptions(long seed, String featureSeedJson, boolean generateStructures, boolean bonusChest, Optional<String> legacyCustomOptions) {
|
||||
+ this(seed, gson.fromJson(featureSeedJson, long[].class), generateStructures, bonusChest, legacyCustomOptions);
|
||||
+ }
|
||||
+ // Leaf end - Matter - Secure Seed
|
||||
+
|
||||
public static WorldOptions defaultWithRandomSeed() {
|
||||
- return new WorldOptions(randomSeed(), true, false);
|
||||
+ // Leaf start - Matter - Secure Seed
|
||||
+ return isSecureSeedEnabled
|
||||
+ ? new WorldOptions(randomSeed(), su.plo.matter.Globals.createRandomWorldSeed(), true, false)
|
||||
+ : new WorldOptions(randomSeed(), true, false);
|
||||
+ // Leaf end - Matter - Secure Seed
|
||||
}
|
||||
|
||||
public static WorldOptions testWorldWithRandomSeed() {
|
||||
return new WorldOptions(randomSeed(), false, false);
|
||||
}
|
||||
|
||||
+ // Leaf start - Matter - Secure Seed
|
||||
+ private WorldOptions(long seed, long[] featureSeed, boolean generateStructures, boolean bonusChest, Optional<String> legacyCustomOptions) {
|
||||
+ this(seed, generateStructures, bonusChest, legacyCustomOptions);
|
||||
+ this.featureSeed = featureSeed;
|
||||
+ }
|
||||
+ // Leaf end - Matter - Secure Seed
|
||||
+
|
||||
private WorldOptions(long seed, boolean generateStructures, boolean generateBonusChest, Optional<String> legacyCustomOptions) {
|
||||
this.seed = seed;
|
||||
this.generateStructures = generateStructures;
|
||||
@@ -47,6 +86,16 @@ public class WorldOptions {
|
||||
return this.seed;
|
||||
}
|
||||
|
||||
+ // Leaf start - Matter - Secure Seed
|
||||
+ public long[] featureSeed() {
|
||||
+ return this.featureSeed;
|
||||
+ }
|
||||
+
|
||||
+ private String featureSeedSerialize() {
|
||||
+ return gson.toJson(this.featureSeed);
|
||||
+ }
|
||||
+ // Leaf end - Matter - Secure Seed
|
||||
+
|
||||
public boolean generateStructures() {
|
||||
return this.generateStructures;
|
||||
}
|
||||
@@ -59,17 +108,25 @@ public class WorldOptions {
|
||||
return this.legacyCustomOptions.isPresent();
|
||||
}
|
||||
|
||||
+ // Leaf start - Matter - Secure Seed
|
||||
public WorldOptions withBonusChest(boolean generateBonusChest) {
|
||||
- return new WorldOptions(this.seed, this.generateStructures, generateBonusChest, this.legacyCustomOptions);
|
||||
+ return isSecureSeedEnabled
|
||||
+ ? new WorldOptions(this.seed, this.featureSeed, this.generateStructures, generateBonusChest, this.legacyCustomOptions)
|
||||
+ : new WorldOptions(this.seed, this.generateStructures, generateBonusChest, this.legacyCustomOptions);
|
||||
}
|
||||
|
||||
public WorldOptions withStructures(boolean generateStructures) {
|
||||
- return new WorldOptions(this.seed, generateStructures, this.generateBonusChest, this.legacyCustomOptions);
|
||||
+ return isSecureSeedEnabled
|
||||
+ ? new WorldOptions(this.seed, this.featureSeed, generateStructures, this.generateBonusChest, this.legacyCustomOptions)
|
||||
+ : new WorldOptions(this.seed, generateStructures, this.generateBonusChest, this.legacyCustomOptions);
|
||||
}
|
||||
|
||||
public WorldOptions withSeed(OptionalLong seed) {
|
||||
- return new WorldOptions(seed.orElse(randomSeed()), this.generateStructures, this.generateBonusChest, this.legacyCustomOptions);
|
||||
+ return isSecureSeedEnabled
|
||||
+ ? new WorldOptions(seed.orElse(randomSeed()), su.plo.matter.Globals.createRandomWorldSeed(), this.generateStructures, this.generateBonusChest, this.legacyCustomOptions)
|
||||
+ : new WorldOptions(seed.orElse(randomSeed()), this.generateStructures, this.generateBonusChest, this.legacyCustomOptions);
|
||||
}
|
||||
+ // Leaf end - Matter - Secure Seed
|
||||
|
||||
public static OptionalLong parseSeed(String seed) {
|
||||
seed = seed.trim();
|
||||
diff --git a/net/minecraft/world/level/levelgen/feature/GeodeFeature.java b/net/minecraft/world/level/levelgen/feature/GeodeFeature.java
|
||||
index 4e72eb49dbf4c70ae7556ba6eb210fcd5ef36aaa..8df6dadfeb2c282bc3c3f521d31f7277caa77790 100644
|
||||
--- a/net/minecraft/world/level/levelgen/feature/GeodeFeature.java
|
||||
+++ b/net/minecraft/world/level/levelgen/feature/GeodeFeature.java
|
||||
@@ -41,7 +41,11 @@ public class GeodeFeature extends Feature<GeodeConfiguration> {
|
||||
int i1 = geodeConfiguration.maxGenOffset;
|
||||
List<Pair<BlockPos, Integer>> list = Lists.newLinkedList();
|
||||
int i2 = geodeConfiguration.distributionPoints.sample(randomSource);
|
||||
- WorldgenRandom worldgenRandom = new WorldgenRandom(new LegacyRandomSource(worldGenLevel.getSeed()));
|
||||
+ // Leaf start - Matter - Secure Seed
|
||||
+ WorldgenRandom worldgenRandom = org.dreeam.leaf.config.modules.misc.SecureSeed.enabled
|
||||
+ ? new su.plo.matter.WorldgenCryptoRandom(0, 0, su.plo.matter.Globals.Salt.GEODE_FEATURE, 0)
|
||||
+ : new WorldgenRandom(new LegacyRandomSource(worldGenLevel.getSeed()));
|
||||
+ // Leaf end - Matter - Secure Seed
|
||||
NormalNoise normalNoise = NormalNoise.create(worldgenRandom, -4, 1.0);
|
||||
List<BlockPos> list1 = Lists.newLinkedList();
|
||||
double d = (double)i2 / geodeConfiguration.outerWallDistance.getMaxValue();
|
||||
diff --git a/net/minecraft/world/level/levelgen/structure/Structure.java b/net/minecraft/world/level/levelgen/structure/Structure.java
|
||||
index 8328e864c72b7a358d6bb1f33459b8c4df2ecb1a..28281491be6b54de18c49ff0d52e302575d3ad38 100644
|
||||
--- a/net/minecraft/world/level/levelgen/structure/Structure.java
|
||||
+++ b/net/minecraft/world/level/levelgen/structure/Structure.java
|
||||
@@ -249,6 +249,11 @@ public abstract class Structure {
|
||||
}
|
||||
|
||||
private static WorldgenRandom makeRandom(long seed, ChunkPos chunkPos) {
|
||||
+ // Leaf start - Matter - Secure Seed
|
||||
+ if (org.dreeam.leaf.config.modules.misc.SecureSeed.enabled) {
|
||||
+ return new su.plo.matter.WorldgenCryptoRandom(chunkPos.x, chunkPos.z, su.plo.matter.Globals.Salt.GENERATE_FEATURE, seed);
|
||||
+ }
|
||||
+ // Leaf end - Matter - Secure Seed
|
||||
WorldgenRandom worldgenRandom = new WorldgenRandom(new LegacyRandomSource(0L));
|
||||
worldgenRandom.setLargeFeatureSeed(seed, chunkPos.x, chunkPos.z);
|
||||
return worldgenRandom;
|
||||
diff --git a/net/minecraft/world/level/levelgen/structure/placement/RandomSpreadStructurePlacement.java b/net/minecraft/world/level/levelgen/structure/placement/RandomSpreadStructurePlacement.java
|
||||
index ee0d9dddb36b6879fa113299e24f1aa3b2b151cc..6584c9320361dbbdea1899ab9e43b444de5006a6 100644
|
||||
--- a/net/minecraft/world/level/levelgen/structure/placement/RandomSpreadStructurePlacement.java
|
||||
+++ b/net/minecraft/world/level/levelgen/structure/placement/RandomSpreadStructurePlacement.java
|
||||
@@ -67,8 +67,15 @@ public class RandomSpreadStructurePlacement extends StructurePlacement {
|
||||
public ChunkPos getPotentialStructureChunk(long seed, int regionX, int regionZ) {
|
||||
int i = Math.floorDiv(regionX, this.spacing);
|
||||
int i1 = Math.floorDiv(regionZ, this.spacing);
|
||||
- WorldgenRandom worldgenRandom = new WorldgenRandom(new LegacyRandomSource(0L));
|
||||
- worldgenRandom.setLargeFeatureWithSalt(seed, i, i1, this.salt());
|
||||
+ // Leaf start - Matter - Secure Seed
|
||||
+ WorldgenRandom worldgenRandom;
|
||||
+ if (org.dreeam.leaf.config.modules.misc.SecureSeed.enabled) {
|
||||
+ worldgenRandom = new su.plo.matter.WorldgenCryptoRandom(i, i1, su.plo.matter.Globals.Salt.POTENTIONAL_FEATURE, this.salt);
|
||||
+ } else {
|
||||
+ worldgenRandom = new WorldgenRandom(new LegacyRandomSource(0L));
|
||||
+ worldgenRandom.setLargeFeatureWithSalt(seed, i, i1, this.salt());
|
||||
+ }
|
||||
+ // Leaf end - Matter - Secure Seed
|
||||
int i2 = this.spacing - this.separation;
|
||||
int i3 = this.spreadType.evaluate(worldgenRandom, i2);
|
||||
int i4 = this.spreadType.evaluate(worldgenRandom, i2);
|
||||
diff --git a/net/minecraft/world/level/levelgen/structure/placement/StructurePlacement.java b/net/minecraft/world/level/levelgen/structure/placement/StructurePlacement.java
|
||||
index 1f939b325ec5291b3c4aabc4735c863f9436a6f8..ee60717e39928a9f89ad6c7a9b3b52ac156871e6 100644
|
||||
--- a/net/minecraft/world/level/levelgen/structure/placement/StructurePlacement.java
|
||||
+++ b/net/minecraft/world/level/levelgen/structure/placement/StructurePlacement.java
|
||||
@@ -119,8 +119,16 @@ public abstract class StructurePlacement {
|
||||
public abstract StructurePlacementType<?> type();
|
||||
|
||||
private static boolean probabilityReducer(long levelSeed, int regionX, int regionZ, int salt, float probability, @org.jetbrains.annotations.Nullable Integer saltOverride) { // Paper - Add missing structure set seed configs; ignore here
|
||||
- WorldgenRandom worldgenRandom = new WorldgenRandom(new LegacyRandomSource(0L));
|
||||
- worldgenRandom.setLargeFeatureWithSalt(levelSeed, regionX, regionZ, salt);
|
||||
+ // Leaf start - Matter - Secure Seed
|
||||
+ WorldgenRandom worldgenRandom;
|
||||
+ if (org.dreeam.leaf.config.modules.misc.SecureSeed.enabled) {
|
||||
+ worldgenRandom = new su.plo.matter.WorldgenCryptoRandom(regionX, regionZ, su.plo.matter.Globals.Salt.UNDEFINED, salt);
|
||||
+ } else {
|
||||
+ worldgenRandom = new WorldgenRandom(new LegacyRandomSource(0L));
|
||||
+ worldgenRandom.setLargeFeatureWithSalt(levelSeed, salt, regionX, regionZ);
|
||||
+ }
|
||||
+ // Leaf end - Matter - Secure Seed
|
||||
+
|
||||
return worldgenRandom.nextFloat() < probability;
|
||||
}
|
||||
|
||||
diff --git a/net/minecraft/world/level/levelgen/structure/pools/JigsawPlacement.java b/net/minecraft/world/level/levelgen/structure/pools/JigsawPlacement.java
|
||||
index 1cfa0fcd28685736fcdce4aef817e4d4cc4061cb..400e5d1c415835a87648ae0d1aa92ac4063ae93c 100644
|
||||
--- a/net/minecraft/world/level/levelgen/structure/pools/JigsawPlacement.java
|
||||
+++ b/net/minecraft/world/level/levelgen/structure/pools/JigsawPlacement.java
|
||||
@@ -64,7 +64,11 @@ public class JigsawPlacement {
|
||||
ChunkGenerator chunkGenerator = context.chunkGenerator();
|
||||
StructureTemplateManager structureTemplateManager = context.structureTemplateManager();
|
||||
LevelHeightAccessor levelHeightAccessor = context.heightAccessor();
|
||||
- WorldgenRandom worldgenRandom = context.random();
|
||||
+ // Leaf start - Matter - Secure Seed
|
||||
+ WorldgenRandom worldgenRandom = org.dreeam.leaf.config.modules.misc.SecureSeed.enabled
|
||||
+ ? new su.plo.matter.WorldgenCryptoRandom(context.chunkPos().x, context.chunkPos().z, su.plo.matter.Globals.Salt.JIGSAW_PLACEMENT, 0)
|
||||
+ : context.random();
|
||||
+ // Leaf end - Matter - Secure Seed
|
||||
Registry<StructureTemplatePool> registry = registryAccess.lookupOrThrow(Registries.TEMPLATE_POOL);
|
||||
Rotation random = Rotation.getRandom(worldgenRandom);
|
||||
StructureTemplatePool structureTemplatePool = startPool.unwrapKey()
|
||||
diff --git a/net/minecraft/world/level/levelgen/structure/structures/EndCityStructure.java b/net/minecraft/world/level/levelgen/structure/structures/EndCityStructure.java
|
||||
index 653c03d214d2e690852adc4d697e2b24c39ea3d0..807881ab3b647bff515df627543b8a2e1cad3c3f 100644
|
||||
--- a/net/minecraft/world/level/levelgen/structure/structures/EndCityStructure.java
|
||||
+++ b/net/minecraft/world/level/levelgen/structure/structures/EndCityStructure.java
|
||||
@@ -10,6 +10,7 @@ import net.minecraft.world.level.levelgen.structure.Structure;
|
||||
import net.minecraft.world.level.levelgen.structure.StructurePiece;
|
||||
import net.minecraft.world.level.levelgen.structure.StructureType;
|
||||
import net.minecraft.world.level.levelgen.structure.pieces.StructurePiecesBuilder;
|
||||
+//import su.plo.matter.WorldgenCryptoRandom; // Leaf - Matter - Secure Seed
|
||||
|
||||
public class EndCityStructure extends Structure {
|
||||
public static final MapCodec<EndCityStructure> CODEC = simpleCodec(EndCityStructure::new);
|
||||
diff --git a/net/minecraft/world/level/levelgen/structure/structures/MineshaftStructure.java b/net/minecraft/world/level/levelgen/structure/structures/MineshaftStructure.java
|
||||
index 5f2118f664c1013b99137c6d34a11c40c2559156..2acee0e8b5b80f7a40346befcafcd011edd37cf9 100644
|
||||
--- a/net/minecraft/world/level/levelgen/structure/structures/MineshaftStructure.java
|
||||
+++ b/net/minecraft/world/level/levelgen/structure/structures/MineshaftStructure.java
|
||||
@@ -20,6 +20,7 @@ import net.minecraft.world.level.levelgen.WorldgenRandom;
|
||||
import net.minecraft.world.level.levelgen.structure.Structure;
|
||||
import net.minecraft.world.level.levelgen.structure.StructureType;
|
||||
import net.minecraft.world.level.levelgen.structure.pieces.StructurePiecesBuilder;
|
||||
+//import su.plo.matter.WorldgenCryptoRandom; // Leaf - Matter - Secure Seed
|
||||
|
||||
public class MineshaftStructure extends Structure {
|
||||
public static final MapCodec<MineshaftStructure> CODEC = RecordCodecBuilder.mapCodec(
|
||||
@@ -0,0 +1,30 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Apehum <apehumchik@gmail.com>
|
||||
Date: Thu, 16 Dec 2021 04:23:40 +0800
|
||||
Subject: [PATCH] Matter: Secure Seed command
|
||||
|
||||
Original license: GPLv3
|
||||
Original project: https://github.com/plasmoapp/matter
|
||||
|
||||
diff --git a/net/minecraft/server/commands/SeedCommand.java b/net/minecraft/server/commands/SeedCommand.java
|
||||
index a65affc41a4fc299bc2281f0f53f2e075633899d..18dd6fa908104ea9fbb32faaca0725d4d6849b09 100644
|
||||
--- a/net/minecraft/server/commands/SeedCommand.java
|
||||
+++ b/net/minecraft/server/commands/SeedCommand.java
|
||||
@@ -12,6 +12,17 @@ public class SeedCommand {
|
||||
long seed = context.getSource().getLevel().getSeed();
|
||||
Component component = ComponentUtils.copyOnClickText(String.valueOf(seed));
|
||||
context.getSource().sendSuccess(() -> Component.translatable("commands.seed.success", component), false);
|
||||
+
|
||||
+ // Leaf start - Matter - Secure Seed command
|
||||
+ if (org.dreeam.leaf.config.modules.misc.SecureSeed.enabled) {
|
||||
+ su.plo.matter.Globals.setupGlobals(context.getSource().getLevel());
|
||||
+ String seedStr = su.plo.matter.Globals.seedToString(su.plo.matter.Globals.worldSeed);
|
||||
+ Component featureSeedComponent = ComponentUtils.copyOnClickText(seedStr);
|
||||
+
|
||||
+ context.getSource().sendSuccess(() -> Component.translatable(("Feature seed: %s"), featureSeedComponent), false);
|
||||
+ }
|
||||
+ // Leaf end - Matter - Secure Seed command
|
||||
+
|
||||
return (int)seed;
|
||||
}));
|
||||
}
|
||||
@@ -0,0 +1,369 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com>
|
||||
Date: Tue, 9 Nov 2077 00:00:00 +0800
|
||||
Subject: [PATCH] Faster random generator
|
||||
|
||||
This patch replaces LegacyRandomSource with FasterRandomSource by default,
|
||||
which is faster in general.
|
||||
|
||||
Benchmark results (10,000,000 iterations) (Azul Zulu 23.0.1)
|
||||
|
||||
FasterRandomSource (Leaf) (Backed by Xoroshiro128PlusPlus): 51,633,700 ns
|
||||
LegacyRandomSource (Vanilla): 254,857,500 ns
|
||||
ThreadUnsafeRandom (Moonrise): 102,265,100 ns
|
||||
SimpleThreadUnsafeRandom (Moonrise): 97,054,600 ns
|
||||
|
||||
diff --git a/net/minecraft/server/level/ServerChunkCache.java b/net/minecraft/server/level/ServerChunkCache.java
|
||||
index a9acfc3ba6c3447b4632d32fe24e9a09d55ba1e2..0f9d18dd29e210ad656da211a3cb1cb25cd4efb1 100644
|
||||
--- a/net/minecraft/server/level/ServerChunkCache.java
|
||||
+++ b/net/minecraft/server/level/ServerChunkCache.java
|
||||
@@ -154,7 +154,7 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
|
||||
}
|
||||
// Paper end - rewrite chunk system
|
||||
// Paper start - chunk tick iteration optimisations
|
||||
- private final ca.spottedleaf.moonrise.common.util.SimpleThreadUnsafeRandom shuffleRandom = new ca.spottedleaf.moonrise.common.util.SimpleThreadUnsafeRandom(0L);
|
||||
+ private final net.minecraft.world.level.levelgen.BitRandomSource shuffleRandom = org.dreeam.leaf.config.modules.opt.FastRNG.enabled ? new org.dreeam.leaf.util.math.random.FasterRandomSource(0L) : new ca.spottedleaf.moonrise.common.util.SimpleThreadUnsafeRandom(0L); // Leaf - Faster random generator
|
||||
private void iterateTickingChunksFaster() {
|
||||
final ServerLevel world = this.level;
|
||||
final int randomTickSpeed = world.getGameRules().getInt(GameRules.RULE_RANDOMTICKING);
|
||||
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
|
||||
index 27b9669330e43c9a5679a44cc105e8de0b36d184..2c65987f7dda5b46a232a69e46b91090801fc246 100644
|
||||
--- a/net/minecraft/server/level/ServerLevel.java
|
||||
+++ b/net/minecraft/server/level/ServerLevel.java
|
||||
@@ -847,7 +847,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
||||
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 ca.spottedleaf.moonrise.common.util.SimpleThreadUnsafeRandom simpleRandom = this.simpleRandom;
|
||||
+ 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();
|
||||
|
||||
final ChunkPos cpos = chunk.getPos();
|
||||
@@ -896,7 +896,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
||||
private int currentIceAndSnowTick = 0; protected void resetIceAndSnowTick() { this.currentIceAndSnowTick = this.simpleRandom.nextInt(16); } // Gale - Airplane - optimize random calls in chunk ticking
|
||||
|
||||
public void tickChunk(LevelChunk chunk, int randomTickSpeed) {
|
||||
- final ca.spottedleaf.moonrise.common.util.SimpleThreadUnsafeRandom simpleRandom = this.simpleRandom; // Paper - optimise random ticking
|
||||
+ final net.minecraft.world.level.levelgen.BitRandomSource simpleRandom = this.simpleRandom; // Paper - optimise random ticking // Leaf - Faster random generator - upcasting
|
||||
ChunkPos pos = chunk.getPos();
|
||||
int minBlockX = pos.getMinBlockX();
|
||||
int minBlockZ = pos.getMinBlockZ();
|
||||
diff --git a/net/minecraft/util/RandomSource.java b/net/minecraft/util/RandomSource.java
|
||||
index 8516d47b0ba79d91638837199e7ae0fb6cb44a79..4f4b55dd099dd2c2fea118b18b53588147e59bba 100644
|
||||
--- a/net/minecraft/util/RandomSource.java
|
||||
+++ b/net/minecraft/util/RandomSource.java
|
||||
@@ -15,18 +15,40 @@ public interface RandomSource {
|
||||
return create(RandomSupport.generateUniqueSeed());
|
||||
}
|
||||
|
||||
+ // Leaf start - Faster random generator
|
||||
@Deprecated
|
||||
static RandomSource createThreadSafe() {
|
||||
- return new ThreadSafeLegacyRandomSource(RandomSupport.generateUniqueSeed());
|
||||
+ return org.dreeam.leaf.config.modules.opt.FastRNG.enabled
|
||||
+ ? new org.dreeam.leaf.util.math.random.FasterRandomSource(RandomSupport.generateUniqueSeed())
|
||||
+ : new ThreadSafeLegacyRandomSource(RandomSupport.generateUniqueSeed());
|
||||
}
|
||||
|
||||
static RandomSource create(long seed) {
|
||||
- return new LegacyRandomSource(seed);
|
||||
+ return org.dreeam.leaf.config.modules.opt.FastRNG.enabled
|
||||
+ ? new org.dreeam.leaf.util.math.random.FasterRandomSource(seed)
|
||||
+ : new LegacyRandomSource(seed);
|
||||
+ }
|
||||
+
|
||||
+ static RandomSource createForSlimeChunk(long seed) {
|
||||
+ return org.dreeam.leaf.config.modules.opt.FastRNG.enabled && !org.dreeam.leaf.config.modules.opt.FastRNG.useLegacyForSlimeChunk
|
||||
+ ? new org.dreeam.leaf.util.math.random.FasterRandomSource(seed)
|
||||
+ : new LegacyRandomSource(seed);
|
||||
}
|
||||
|
||||
static RandomSource createNewThreadLocalInstance() {
|
||||
- return new SingleThreadedRandomSource(ThreadLocalRandom.current().nextLong());
|
||||
+ return org.dreeam.leaf.config.modules.opt.FastRNG.enabled
|
||||
+ ? new org.dreeam.leaf.util.math.random.FasterRandomSource(RandomSupport.generateUniqueSeed())
|
||||
+ : new SingleThreadedRandomSource(ThreadLocalRandom.current().nextLong());
|
||||
+ }
|
||||
+
|
||||
+ static RandomSource createLegacy() {
|
||||
+ return new LegacyRandomSource(RandomSupport.generateUniqueSeed());
|
||||
+ }
|
||||
+
|
||||
+ static RandomSource createLegacy(long seed) {
|
||||
+ return new LegacyRandomSource(seed);
|
||||
}
|
||||
+ // Leaf end - Faster random generator
|
||||
|
||||
RandomSource fork();
|
||||
|
||||
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
|
||||
index 209d897fdf5a5d19990f6dd8ee11d42d74bd0e92..8ac90cc10625f395dba660e2358bbac79431b0cf 100644
|
||||
--- a/net/minecraft/world/entity/Entity.java
|
||||
+++ b/net/minecraft/world/entity/Entity.java
|
||||
@@ -148,7 +148,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
||||
}
|
||||
|
||||
// Paper start - Share random for entities to make them more random
|
||||
- public static RandomSource SHARED_RANDOM = new RandomRandomSource();
|
||||
+ public static RandomSource SHARED_RANDOM = org.dreeam.leaf.config.modules.opt.FastRNG.enabled ? org.dreeam.leaf.util.math.random.FasterRandomSource.SHARED_INSTANCE : new RandomRandomSource(); // Leaf - Faster random generator
|
||||
// Paper start - replace random
|
||||
private static final class RandomRandomSource extends ca.spottedleaf.moonrise.common.util.ThreadUnsafeRandom {
|
||||
public RandomRandomSource() {
|
||||
diff --git a/net/minecraft/world/level/Level.java b/net/minecraft/world/level/Level.java
|
||||
index d56283aaf6726a5d71fb89f2c059db76c211d402..6b7efd6466d16276c37abfa1fd64df84b546f227 100644
|
||||
--- a/net/minecraft/world/level/Level.java
|
||||
+++ b/net/minecraft/world/level/Level.java
|
||||
@@ -117,7 +117,7 @@ public abstract class Level implements LevelAccessor, UUIDLookup<Entity>, AutoCl
|
||||
public float rainLevel;
|
||||
protected float oThunderLevel;
|
||||
public float thunderLevel;
|
||||
- public final RandomSource random = new ca.spottedleaf.moonrise.common.util.ThreadUnsafeRandom(net.minecraft.world.level.levelgen.RandomSupport.generateUniqueSeed()); // Paper - replace random
|
||||
+ public final RandomSource random = org.dreeam.leaf.config.modules.opt.FastRNG.enabled ? new org.dreeam.leaf.util.math.random.FasterRandomSource(net.minecraft.world.level.levelgen.RandomSupport.generateUniqueSeed()) : new ca.spottedleaf.moonrise.common.util.ThreadUnsafeRandom(net.minecraft.world.level.levelgen.RandomSupport.generateUniqueSeed()); // Paper - replace random // Leaf - Faster random generator
|
||||
@Deprecated
|
||||
private final RandomSource threadSafeRandom = RandomSource.createThreadSafe();
|
||||
private final Holder<DimensionType> dimensionTypeRegistration;
|
||||
@@ -168,7 +168,7 @@ public abstract class Level implements LevelAccessor, UUIDLookup<Entity>, AutoCl
|
||||
private int tileTickPosition;
|
||||
public final Map<ServerExplosion.CacheKey, Float> explosionDensityCache = new java.util.HashMap<>(); // Paper - Optimize explosions
|
||||
public java.util.ArrayDeque<net.minecraft.world.level.block.RedstoneTorchBlock.Toggle> redstoneUpdateInfos; // Paper - Faster redstone torch rapid clock removal; Move from Map in BlockRedstoneTorch to here
|
||||
- public final ca.spottedleaf.moonrise.common.util.SimpleThreadUnsafeRandom simpleRandom = new ca.spottedleaf.moonrise.common.util.SimpleThreadUnsafeRandom(net.minecraft.world.level.levelgen.RandomSupport.generateUniqueSeed()); // Gale - Pufferfish - move random tick random
|
||||
+ public final net.minecraft.world.level.levelgen.BitRandomSource simpleRandom = org.dreeam.leaf.config.modules.opt.FastRNG.enabled ? new org.dreeam.leaf.util.math.random.FasterRandomSource(net.minecraft.world.level.levelgen.RandomSupport.generateUniqueSeed()) : new ca.spottedleaf.moonrise.common.util.SimpleThreadUnsafeRandom(net.minecraft.world.level.levelgen.RandomSupport.generateUniqueSeed()); // Gale - Pufferfish - move random tick random // Leaf - Faster random generator
|
||||
|
||||
public CraftWorld getWorld() {
|
||||
return this.world;
|
||||
diff --git a/net/minecraft/world/level/biome/Biome.java b/net/minecraft/world/level/biome/Biome.java
|
||||
index bad1a03167f7586e5279592adcb43350c9b528cd..336d42d4e85716843633030ba1aa21b7901ca601 100644
|
||||
--- a/net/minecraft/world/level/biome/Biome.java
|
||||
+++ b/net/minecraft/world/level/biome/Biome.java
|
||||
@@ -55,14 +55,14 @@ public final class Biome {
|
||||
);
|
||||
public static final Codec<Holder<Biome>> CODEC = RegistryFileCodec.create(Registries.BIOME, DIRECT_CODEC);
|
||||
public static final Codec<HolderSet<Biome>> LIST_CODEC = RegistryCodecs.homogeneousList(Registries.BIOME, DIRECT_CODEC);
|
||||
- private static final PerlinSimplexNoise TEMPERATURE_NOISE = new PerlinSimplexNoise(new WorldgenRandom(new LegacyRandomSource(1234L)), ImmutableList.of(0));
|
||||
+ private static final PerlinSimplexNoise TEMPERATURE_NOISE = new PerlinSimplexNoise(new WorldgenRandom(org.dreeam.leaf.config.modules.opt.FastRNG.worldgenEnabled() ? new org.dreeam.leaf.util.math.random.FasterRandomSource(1234L) : new LegacyRandomSource(1234L)), ImmutableList.of(0)); // Leaf - Faster random generator
|
||||
static final PerlinSimplexNoise FROZEN_TEMPERATURE_NOISE = new PerlinSimplexNoise(
|
||||
- new WorldgenRandom(new LegacyRandomSource(3456L)), ImmutableList.of(-2, -1, 0)
|
||||
+ new WorldgenRandom(org.dreeam.leaf.config.modules.opt.FastRNG.worldgenEnabled() ? new org.dreeam.leaf.util.math.random.FasterRandomSource(3456L) : new LegacyRandomSource(3456L)), ImmutableList.of(-2, -1, 0) // Leaf - Faster random generator
|
||||
);
|
||||
@Deprecated(
|
||||
forRemoval = true
|
||||
)
|
||||
- public static final PerlinSimplexNoise BIOME_INFO_NOISE = new PerlinSimplexNoise(new WorldgenRandom(new LegacyRandomSource(2345L)), ImmutableList.of(0));
|
||||
+ public static final PerlinSimplexNoise BIOME_INFO_NOISE = new PerlinSimplexNoise(new WorldgenRandom(org.dreeam.leaf.config.modules.opt.FastRNG.worldgenEnabled() ? new org.dreeam.leaf.util.math.random.FasterRandomSource(2345L) : new LegacyRandomSource(2345L)), ImmutableList.of(0)); // Leaf - Faster random generator
|
||||
private static final int TEMPERATURE_CACHE_SIZE = 1024;
|
||||
public final Biome.ClimateSettings climateSettings;
|
||||
private final BiomeGenerationSettings generationSettings;
|
||||
diff --git a/net/minecraft/world/level/chunk/ChunkGenerator.java b/net/minecraft/world/level/chunk/ChunkGenerator.java
|
||||
index 23806f5f0c6c4ec9a86a6ea13b89b4f57372e6f1..e1ebbfab87aed9cc633f2fedb1e6edeca4ddc2ec 100644
|
||||
--- a/net/minecraft/world/level/chunk/ChunkGenerator.java
|
||||
+++ b/net/minecraft/world/level/chunk/ChunkGenerator.java
|
||||
@@ -455,7 +455,7 @@ public abstract class ChunkGenerator {
|
||||
int x = chunk.getPos().x;
|
||||
int z = chunk.getPos().z;
|
||||
for (org.bukkit.generator.BlockPopulator populator : world.getPopulators()) {
|
||||
- WorldgenRandom seededrandom = new WorldgenRandom(new net.minecraft.world.level.levelgen.LegacyRandomSource(level.getSeed()));
|
||||
+ WorldgenRandom seededrandom = new WorldgenRandom(org.dreeam.leaf.config.modules.opt.FastRNG.worldgenEnabled() ? new org.dreeam.leaf.util.math.random.FasterRandomSource(level.getSeed()) : new net.minecraft.world.level.levelgen.LegacyRandomSource(level.getSeed())); // Leaf - Faster random generator
|
||||
seededrandom.setDecorationSeed(level.getSeed(), x, z);
|
||||
populator.populate(world, new org.bukkit.craftbukkit.util.RandomSourceWrapper.RandomWrapper(seededrandom), x, z, limitedRegion);
|
||||
}
|
||||
@@ -560,7 +560,7 @@ public abstract class ChunkGenerator {
|
||||
if (org.dreeam.leaf.config.modules.misc.SecureSeed.enabled) {
|
||||
worldgenRandom = new su.plo.matter.WorldgenCryptoRandom(pos.x, pos.z, su.plo.matter.Globals.Salt.GENERATE_FEATURE, 0);
|
||||
} else {
|
||||
- worldgenRandom = new WorldgenRandom(new LegacyRandomSource(0L));
|
||||
+ worldgenRandom = new WorldgenRandom(org.dreeam.leaf.config.modules.opt.FastRNG.worldgenEnabled() ? new org.dreeam.leaf.util.math.random.FasterRandomSource(0L) : new LegacyRandomSource(0L)); // Leaf - Faster random generator
|
||||
worldgenRandom.setLargeFeatureSeed(structureState.getLevelSeed(), pos.x, pos.z);
|
||||
}
|
||||
// Leaf end - Matter - Secure Seed
|
||||
diff --git a/net/minecraft/world/level/chunk/ChunkGeneratorStructureState.java b/net/minecraft/world/level/chunk/ChunkGeneratorStructureState.java
|
||||
index 426692d9627f46d708f551bd22ce3c52b2a23b37..8a19fd2b816b07a7374cb9dc96896a122f95db20 100644
|
||||
--- a/net/minecraft/world/level/chunk/ChunkGeneratorStructureState.java
|
||||
+++ b/net/minecraft/world/level/chunk/ChunkGeneratorStructureState.java
|
||||
@@ -208,7 +208,7 @@ public class ChunkGeneratorStructureState {
|
||||
// Leaf start - Matter - Secure Seed
|
||||
RandomSource randomSource = org.dreeam.leaf.config.modules.misc.SecureSeed.enabled
|
||||
? new su.plo.matter.WorldgenCryptoRandom(0, 0, su.plo.matter.Globals.Salt.STRONGHOLDS, 0)
|
||||
- : RandomSource.create();
|
||||
+ : RandomSource.createLegacy(); // Leaf - Faster random generator
|
||||
// Leaf end - Matter - Secure Seed
|
||||
if (!org.dreeam.leaf.config.modules.misc.SecureSeed.enabled) {
|
||||
// Paper start - Add missing structure set seed configs
|
||||
diff --git a/net/minecraft/world/level/levelgen/DensityFunctions.java b/net/minecraft/world/level/levelgen/DensityFunctions.java
|
||||
index 04527a5c65ad630f794fed9071d485aedd02257a..15fc39f9c77fdd03a0ca4a39d173c851b9454f08 100644
|
||||
--- a/net/minecraft/world/level/levelgen/DensityFunctions.java
|
||||
+++ b/net/minecraft/world/level/levelgen/DensityFunctions.java
|
||||
@@ -518,7 +518,7 @@ public final class DensityFunctions {
|
||||
// Paper end - Perf: Optimize end generation
|
||||
|
||||
public EndIslandDensityFunction(long seed) {
|
||||
- RandomSource randomSource = new LegacyRandomSource(seed);
|
||||
+ RandomSource randomSource = org.dreeam.leaf.config.modules.opt.FastRNG.worldgenEnabled() ? new org.dreeam.leaf.util.math.random.FasterRandomSource(seed) : new LegacyRandomSource(seed); // Leaf - Faster random generator
|
||||
randomSource.consumeCount(17292);
|
||||
this.islandNoise = new SimplexNoise(randomSource);
|
||||
}
|
||||
diff --git a/net/minecraft/world/level/levelgen/NoiseBasedChunkGenerator.java b/net/minecraft/world/level/levelgen/NoiseBasedChunkGenerator.java
|
||||
index 65728ef17e63d71833677fdcbd5bb90794b4822b..57ae4aaf1431021daf77c5638038d4910a358155 100644
|
||||
--- a/net/minecraft/world/level/levelgen/NoiseBasedChunkGenerator.java
|
||||
+++ b/net/minecraft/world/level/levelgen/NoiseBasedChunkGenerator.java
|
||||
@@ -254,7 +254,7 @@ public final class NoiseBasedChunkGenerator extends ChunkGenerator {
|
||||
WorldGenRegion level, long seed, RandomState random, BiomeManager biomeManager, StructureManager structureManager, ChunkAccess chunk
|
||||
) {
|
||||
BiomeManager biomeManager1 = biomeManager.withDifferentSource((x, y, z) -> this.biomeSource.getNoiseBiome(x, y, z, random.sampler()));
|
||||
- WorldgenRandom worldgenRandom = new WorldgenRandom(new LegacyRandomSource(RandomSupport.generateUniqueSeed()));
|
||||
+ WorldgenRandom worldgenRandom = new WorldgenRandom(org.dreeam.leaf.config.modules.opt.FastRNG.worldgenEnabled() ? new org.dreeam.leaf.util.math.random.FasterRandomSource(RandomSupport.generateUniqueSeed()) : new LegacyRandomSource(RandomSupport.generateUniqueSeed())); // Leaf - Faster random generator
|
||||
int i = 8;
|
||||
ChunkPos pos = chunk.getPos();
|
||||
NoiseChunk noiseChunk = chunk.getOrCreateNoiseChunk(chunkAccess -> this.createNoiseChunk(chunkAccess, structureManager, Blender.of(level), random));
|
||||
@@ -420,7 +420,7 @@ public final class NoiseBasedChunkGenerator extends ChunkGenerator {
|
||||
if (!this.settings.value().disableMobGeneration()) {
|
||||
ChunkPos center = level.getCenter();
|
||||
Holder<Biome> biome = level.getBiome(center.getWorldPosition().atY(level.getMaxY()));
|
||||
- WorldgenRandom worldgenRandom = new WorldgenRandom(new LegacyRandomSource(RandomSupport.generateUniqueSeed()));
|
||||
+ WorldgenRandom worldgenRandom = new WorldgenRandom(org.dreeam.leaf.config.modules.opt.FastRNG.worldgenEnabled() ? new org.dreeam.leaf.util.math.random.FasterRandomSource(RandomSupport.generateUniqueSeed()) : new LegacyRandomSource(RandomSupport.generateUniqueSeed())); // Leaf - Faster random generator
|
||||
worldgenRandom.setDecorationSeed(level.getSeed(), center.getMinBlockX(), center.getMinBlockZ());
|
||||
NaturalSpawner.spawnMobsForChunkGeneration(level, biome, center, worldgenRandom);
|
||||
}
|
||||
diff --git a/net/minecraft/world/level/levelgen/WorldgenRandom.java b/net/minecraft/world/level/levelgen/WorldgenRandom.java
|
||||
index c2d7cd788071e25b8ba2503c30ae80c7a9f353ed..a22508c50b34ca48328595cc7b69e008bf17d370 100644
|
||||
--- a/net/minecraft/world/level/levelgen/WorldgenRandom.java
|
||||
+++ b/net/minecraft/world/level/levelgen/WorldgenRandom.java
|
||||
@@ -69,7 +69,7 @@ public class WorldgenRandom extends LegacyRandomSource {
|
||||
}
|
||||
|
||||
public static RandomSource seedSlimeChunk(int chunkX, int chunkZ, long levelSeed, long salt) {
|
||||
- return RandomSource.create(levelSeed + chunkX * chunkX * 4987142 + chunkX * 5947611 + chunkZ * chunkZ * 4392871L + chunkZ * 389711 ^ salt);
|
||||
+ return RandomSource.createForSlimeChunk(levelSeed + chunkX * chunkX * 4987142 + chunkX * 5947611 + chunkZ * chunkZ * 4392871L + chunkZ * 389711 ^ salt); // Leaf - Faster random generator
|
||||
}
|
||||
|
||||
public static enum Algorithm {
|
||||
diff --git a/net/minecraft/world/level/levelgen/feature/GeodeFeature.java b/net/minecraft/world/level/levelgen/feature/GeodeFeature.java
|
||||
index 8df6dadfeb2c282bc3c3f521d31f7277caa77790..e30dc383695727c31bee46f7dbaf82619bb8a6fa 100644
|
||||
--- a/net/minecraft/world/level/levelgen/feature/GeodeFeature.java
|
||||
+++ b/net/minecraft/world/level/levelgen/feature/GeodeFeature.java
|
||||
@@ -44,7 +44,7 @@ public class GeodeFeature extends Feature<GeodeConfiguration> {
|
||||
// Leaf start - Matter - Secure Seed
|
||||
WorldgenRandom worldgenRandom = org.dreeam.leaf.config.modules.misc.SecureSeed.enabled
|
||||
? new su.plo.matter.WorldgenCryptoRandom(0, 0, su.plo.matter.Globals.Salt.GEODE_FEATURE, 0)
|
||||
- : new WorldgenRandom(new LegacyRandomSource(worldGenLevel.getSeed()));
|
||||
+ : new WorldgenRandom(org.dreeam.leaf.config.modules.opt.FastRNG.worldgenEnabled() ? new org.dreeam.leaf.util.math.random.FasterRandomSource(worldGenLevel.getSeed()) : new LegacyRandomSource(worldGenLevel.getSeed())); // Leaf - Faster random generator
|
||||
// Leaf end - Matter - Secure Seed
|
||||
NormalNoise normalNoise = NormalNoise.create(worldgenRandom, -4, 1.0);
|
||||
List<BlockPos> list1 = Lists.newLinkedList();
|
||||
diff --git a/net/minecraft/world/level/levelgen/feature/stateproviders/DualNoiseProvider.java b/net/minecraft/world/level/levelgen/feature/stateproviders/DualNoiseProvider.java
|
||||
index 48ab8a568d97052fe205e6a1f89862ee23d65abb..a190b5e890cf34dd1aa46cb9e283f05154fbe3e5 100644
|
||||
--- a/net/minecraft/world/level/levelgen/feature/stateproviders/DualNoiseProvider.java
|
||||
+++ b/net/minecraft/world/level/levelgen/feature/stateproviders/DualNoiseProvider.java
|
||||
@@ -43,7 +43,7 @@ public class DualNoiseProvider extends NoiseProvider {
|
||||
this.variety = variety;
|
||||
this.slowNoiseParameters = slowNoiseParameters;
|
||||
this.slowScale = slowScale;
|
||||
- this.slowNoise = NormalNoise.create(new WorldgenRandom(new LegacyRandomSource(seed)), slowNoiseParameters);
|
||||
+ this.slowNoise = NormalNoise.create(new WorldgenRandom(org.dreeam.leaf.config.modules.opt.FastRNG.worldgenEnabled() ? new org.dreeam.leaf.util.math.random.FasterRandomSource(seed) : new LegacyRandomSource(seed)), slowNoiseParameters); // Leaf - Faster random generator
|
||||
}
|
||||
|
||||
@Override
|
||||
diff --git a/net/minecraft/world/level/levelgen/feature/stateproviders/NoiseBasedStateProvider.java b/net/minecraft/world/level/levelgen/feature/stateproviders/NoiseBasedStateProvider.java
|
||||
index f685372a39976f823202f2d9015c14f835b94a0c..bdd1b4ab758fc653df4adad7633ef430ebb89dbe 100644
|
||||
--- a/net/minecraft/world/level/levelgen/feature/stateproviders/NoiseBasedStateProvider.java
|
||||
+++ b/net/minecraft/world/level/levelgen/feature/stateproviders/NoiseBasedStateProvider.java
|
||||
@@ -28,7 +28,7 @@ public abstract class NoiseBasedStateProvider extends BlockStateProvider {
|
||||
this.seed = seed;
|
||||
this.parameters = parameters;
|
||||
this.scale = scale;
|
||||
- this.noise = NormalNoise.create(new WorldgenRandom(new LegacyRandomSource(seed)), parameters);
|
||||
+ this.noise = NormalNoise.create(new WorldgenRandom(org.dreeam.leaf.config.modules.opt.FastRNG.worldgenEnabled() ? new org.dreeam.leaf.util.math.random.FasterRandomSource(seed) : new LegacyRandomSource(seed)), parameters); // Leaf - Faster random generator
|
||||
}
|
||||
|
||||
protected double getNoiseValue(BlockPos pos, double delta) {
|
||||
diff --git a/net/minecraft/world/level/levelgen/structure/Structure.java b/net/minecraft/world/level/levelgen/structure/Structure.java
|
||||
index 28281491be6b54de18c49ff0d52e302575d3ad38..3aa35d67df8f9118c944cebfcb675cccd9d99be2 100644
|
||||
--- a/net/minecraft/world/level/levelgen/structure/Structure.java
|
||||
+++ b/net/minecraft/world/level/levelgen/structure/Structure.java
|
||||
@@ -254,7 +254,7 @@ public abstract class Structure {
|
||||
return new su.plo.matter.WorldgenCryptoRandom(chunkPos.x, chunkPos.z, su.plo.matter.Globals.Salt.GENERATE_FEATURE, seed);
|
||||
}
|
||||
// Leaf end - Matter - Secure Seed
|
||||
- WorldgenRandom worldgenRandom = new WorldgenRandom(new LegacyRandomSource(0L));
|
||||
+ WorldgenRandom worldgenRandom = new WorldgenRandom(org.dreeam.leaf.config.modules.opt.FastRNG.worldgenEnabled() ? new org.dreeam.leaf.util.math.random.FasterRandomSource(0L) : new LegacyRandomSource(0L)); // Leaf - Faster random generator
|
||||
worldgenRandom.setLargeFeatureSeed(seed, chunkPos.x, chunkPos.z);
|
||||
return worldgenRandom;
|
||||
}
|
||||
diff --git a/net/minecraft/world/level/levelgen/structure/placement/RandomSpreadStructurePlacement.java b/net/minecraft/world/level/levelgen/structure/placement/RandomSpreadStructurePlacement.java
|
||||
index 6584c9320361dbbdea1899ab9e43b444de5006a6..06083cc7612ef28bcd9264bb21ab0bbbe0837589 100644
|
||||
--- a/net/minecraft/world/level/levelgen/structure/placement/RandomSpreadStructurePlacement.java
|
||||
+++ b/net/minecraft/world/level/levelgen/structure/placement/RandomSpreadStructurePlacement.java
|
||||
@@ -72,7 +72,7 @@ public class RandomSpreadStructurePlacement extends StructurePlacement {
|
||||
if (org.dreeam.leaf.config.modules.misc.SecureSeed.enabled) {
|
||||
worldgenRandom = new su.plo.matter.WorldgenCryptoRandom(i, i1, su.plo.matter.Globals.Salt.POTENTIONAL_FEATURE, this.salt);
|
||||
} else {
|
||||
- worldgenRandom = new WorldgenRandom(new LegacyRandomSource(0L));
|
||||
+ worldgenRandom = new WorldgenRandom(org.dreeam.leaf.config.modules.opt.FastRNG.worldgenEnabled() ? new org.dreeam.leaf.util.math.random.FasterRandomSource(0L) : new LegacyRandomSource(0L)); // Leaf - Faster random generator
|
||||
worldgenRandom.setLargeFeatureWithSalt(seed, i, i1, this.salt());
|
||||
}
|
||||
// Leaf end - Matter - Secure Seed
|
||||
diff --git a/net/minecraft/world/level/levelgen/structure/placement/StructurePlacement.java b/net/minecraft/world/level/levelgen/structure/placement/StructurePlacement.java
|
||||
index ee60717e39928a9f89ad6c7a9b3b52ac156871e6..daed7cc619d5a0b7d7a75e013cb72ed88d57de6c 100644
|
||||
--- a/net/minecraft/world/level/levelgen/structure/placement/StructurePlacement.java
|
||||
+++ b/net/minecraft/world/level/levelgen/structure/placement/StructurePlacement.java
|
||||
@@ -124,7 +124,7 @@ public abstract class StructurePlacement {
|
||||
if (org.dreeam.leaf.config.modules.misc.SecureSeed.enabled) {
|
||||
worldgenRandom = new su.plo.matter.WorldgenCryptoRandom(regionX, regionZ, su.plo.matter.Globals.Salt.UNDEFINED, salt);
|
||||
} else {
|
||||
- worldgenRandom = new WorldgenRandom(new LegacyRandomSource(0L));
|
||||
+ worldgenRandom = new WorldgenRandom(org.dreeam.leaf.config.modules.opt.FastRNG.worldgenEnabled() ? new org.dreeam.leaf.util.math.random.FasterRandomSource(0L) : new LegacyRandomSource(0L)); // Leaf - Faster random generator
|
||||
worldgenRandom.setLargeFeatureWithSalt(levelSeed, salt, regionX, regionZ);
|
||||
}
|
||||
// Leaf end - Matter - Secure Seed
|
||||
@@ -133,7 +133,7 @@ public abstract class StructurePlacement {
|
||||
}
|
||||
|
||||
private static boolean legacyProbabilityReducerWithDouble(long baseSeed, int salt, int chunkX, int chunkZ, float probability, @org.jetbrains.annotations.Nullable Integer saltOverride) { // Paper - Add missing structure set seed configs
|
||||
- WorldgenRandom worldgenRandom = new WorldgenRandom(new LegacyRandomSource(0L));
|
||||
+ WorldgenRandom worldgenRandom = new WorldgenRandom(org.dreeam.leaf.config.modules.opt.FastRNG.worldgenEnabled() ? new org.dreeam.leaf.util.math.random.FasterRandomSource(0L) : new LegacyRandomSource(0L)); // Leaf - Faster random generator
|
||||
if (saltOverride == null) { // Paper - Add missing structure set seed configs
|
||||
worldgenRandom.setLargeFeatureSeed(baseSeed, chunkX, chunkZ);
|
||||
// Paper start - Add missing structure set seed configs
|
||||
@@ -145,7 +145,7 @@ public abstract class StructurePlacement {
|
||||
}
|
||||
|
||||
private static boolean legacyArbitrarySaltProbabilityReducer(long levelSeed, int salt, int regionX, int regionZ, float probability, @org.jetbrains.annotations.Nullable Integer saltOverride) { // Paper - Add missing structure set seed configs
|
||||
- WorldgenRandom worldgenRandom = new WorldgenRandom(new LegacyRandomSource(0L));
|
||||
+ WorldgenRandom worldgenRandom = new WorldgenRandom(org.dreeam.leaf.config.modules.opt.FastRNG.worldgenEnabled() ? new org.dreeam.leaf.util.math.random.FasterRandomSource(0L) : new LegacyRandomSource(0L)); // Leaf - Faster random generator
|
||||
worldgenRandom.setLargeFeatureWithSalt(levelSeed, regionX, regionZ, saltOverride != null ? saltOverride : HIGHLY_ARBITRARY_RANDOM_SALT); // Paper - Add missing structure set seed configs
|
||||
return worldgenRandom.nextFloat() < probability;
|
||||
}
|
||||
@@ -153,7 +153,7 @@ public abstract class StructurePlacement {
|
||||
private static boolean legacyPillagerOutpostReducer(long levelSeed, int salt, int regionX, int regionZ, float probability, @org.jetbrains.annotations.Nullable Integer saltOverride) { // Paper - Add missing structure set seed configs; ignore here
|
||||
int i = regionX >> 4;
|
||||
int i1 = regionZ >> 4;
|
||||
- WorldgenRandom worldgenRandom = new WorldgenRandom(new LegacyRandomSource(0L));
|
||||
+ WorldgenRandom worldgenRandom = new WorldgenRandom(org.dreeam.leaf.config.modules.opt.FastRNG.worldgenEnabled() ? new org.dreeam.leaf.util.math.random.FasterRandomSource(0L) : new LegacyRandomSource(0L)); // Leaf - Faster random generator
|
||||
worldgenRandom.setSeed(i ^ i1 << 4 ^ levelSeed);
|
||||
worldgenRandom.nextInt();
|
||||
return worldgenRandom.nextInt((int)(1.0F / probability)) == 0;
|
||||
diff --git a/net/minecraft/world/level/levelgen/structure/structures/OceanMonumentStructure.java b/net/minecraft/world/level/levelgen/structure/structures/OceanMonumentStructure.java
|
||||
index 6941b2c89df8a7c77166e3fb76150cbc852371d9..661c26c4b981d504988c7498be45a5ddacaf90d8 100644
|
||||
--- a/net/minecraft/world/level/levelgen/structure/structures/OceanMonumentStructure.java
|
||||
+++ b/net/minecraft/world/level/levelgen/structure/structures/OceanMonumentStructure.java
|
||||
@@ -56,7 +56,7 @@ public class OceanMonumentStructure extends Structure {
|
||||
if (piecesContainer.isEmpty()) {
|
||||
return piecesContainer;
|
||||
} else {
|
||||
- WorldgenRandom worldgenRandom = new WorldgenRandom(new LegacyRandomSource(RandomSupport.generateUniqueSeed()));
|
||||
+ WorldgenRandom worldgenRandom = new WorldgenRandom(org.dreeam.leaf.config.modules.opt.FastRNG.worldgenEnabled() ? new org.dreeam.leaf.util.math.random.FasterRandomSource(RandomSupport.generateUniqueSeed()) : new LegacyRandomSource(RandomSupport.generateUniqueSeed())); // Leaf - Faster random generator
|
||||
worldgenRandom.setLargeFeatureSeed(seed, chunkPos.x, chunkPos.z);
|
||||
StructurePiece structurePiece = piecesContainer.pieces().get(0);
|
||||
BoundingBox boundingBox = structurePiece.getBoundingBox();
|
||||
diff --git a/net/minecraft/world/level/levelgen/synth/PerlinSimplexNoise.java b/net/minecraft/world/level/levelgen/synth/PerlinSimplexNoise.java
|
||||
index 434e72fd770a259d67e5e7f110f49b09bab6c54e..720098d50ecefeff25e8f032e33742ad6bd6ab21 100644
|
||||
--- a/net/minecraft/world/level/levelgen/synth/PerlinSimplexNoise.java
|
||||
+++ b/net/minecraft/world/level/levelgen/synth/PerlinSimplexNoise.java
|
||||
@@ -43,7 +43,7 @@ public class PerlinSimplexNoise {
|
||||
|
||||
if (i1 > 0) {
|
||||
long l = (long)(simplexNoise.getValue(simplexNoise.xo, simplexNoise.yo, simplexNoise.zo) * 9.223372E18F);
|
||||
- RandomSource randomSource = new WorldgenRandom(new LegacyRandomSource(l));
|
||||
+ RandomSource randomSource = new WorldgenRandom(org.dreeam.leaf.config.modules.opt.FastRNG.worldgenEnabled() ? new org.dreeam.leaf.util.math.random.FasterRandomSource(l) : new LegacyRandomSource(l)); // Leaf - Faster random generator
|
||||
|
||||
for (int i5 = i3 - 1; i5 >= 0; i5--) {
|
||||
if (i5 < i2 && octaves.contains(i3 - i5)) {
|
||||
@@ -0,0 +1,22 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: nostalfinals <yuu8583@proton.me>
|
||||
Date: Mon, 29 Apr 2024 23:30:21 +0800
|
||||
Subject: [PATCH] Don't save primed tnt entity
|
||||
|
||||
|
||||
diff --git a/net/minecraft/world/entity/item/PrimedTnt.java b/net/minecraft/world/entity/item/PrimedTnt.java
|
||||
index 5d23d8754b304d5e2fd54400cc81c7fe5c14a804..edc003e4f0cc4280c90fda9c42a3faacc0f5c94d 100644
|
||||
--- a/net/minecraft/world/entity/item/PrimedTnt.java
|
||||
+++ b/net/minecraft/world/entity/item/PrimedTnt.java
|
||||
@@ -253,4 +253,11 @@ public class PrimedTnt extends Entity implements TraceableEntity {
|
||||
return !this.level().paperConfig().fixes.preventTntFromMovingInWater && super.isPushedByFluid();
|
||||
}
|
||||
// Paper end - Option to prevent TNT from moving in water
|
||||
+
|
||||
+ // Leaf start - PMC - Don't save primed tnt entity
|
||||
+ @Override
|
||||
+ public boolean shouldBeSaved() {
|
||||
+ return !org.dreeam.leaf.config.modules.opt.DontSaveEntity.dontSavePrimedTNT && super.shouldBeSaved();
|
||||
+ }
|
||||
+ // Leaf - PMC - Don't save primed tnt entity
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: nostalfinals <yuu8583@proton.me>
|
||||
Date: Mon, 29 Apr 2024 23:31:25 +0800
|
||||
Subject: [PATCH] Don't save falling block entity
|
||||
|
||||
|
||||
diff --git a/net/minecraft/world/entity/item/FallingBlockEntity.java b/net/minecraft/world/entity/item/FallingBlockEntity.java
|
||||
index 31edd0d45ac6c38887e4cebffe5a7cf377b47466..149d5845480c03fe4e29b09cac7fcd1bec147507 100644
|
||||
--- a/net/minecraft/world/entity/item/FallingBlockEntity.java
|
||||
+++ b/net/minecraft/world/entity/item/FallingBlockEntity.java
|
||||
@@ -385,4 +385,11 @@ public class FallingBlockEntity extends Entity {
|
||||
this.forceTickAfterTeleportToDuplicate = entity != null && flag && io.papermc.paper.configuration.GlobalConfiguration.get().unsupportedSettings.allowUnsafeEndPortalTeleportation; // Paper
|
||||
return entity;
|
||||
}
|
||||
+
|
||||
+ // Leaf start - PMC - Don't save falling block entity
|
||||
+ @Override
|
||||
+ public boolean shouldBeSaved() {
|
||||
+ return !org.dreeam.leaf.config.modules.opt.DontSaveEntity.dontSaveFallingBlock && super.shouldBeSaved();
|
||||
+ }
|
||||
+ // Leaf end - PMC - Don't save falling block entity
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
|
||||
Date: Sun, 2 Jun 2024 01:21:36 +0800
|
||||
Subject: [PATCH] Configurable connection message
|
||||
|
||||
|
||||
diff --git a/net/minecraft/server/players/PlayerList.java b/net/minecraft/server/players/PlayerList.java
|
||||
index a6340714eab6d7eafae639c6aeb2aeb75a0e6c07..0bc3908c8ab41fa11c8698dd8d87c1b52c6767da 100644
|
||||
--- a/net/minecraft/server/players/PlayerList.java
|
||||
+++ b/net/minecraft/server/players/PlayerList.java
|
||||
@@ -336,7 +336,7 @@ public abstract class PlayerList {
|
||||
// Ensure that player inventory is populated with its viewer
|
||||
player.containerMenu.transferTo(player.containerMenu, bukkitPlayer);
|
||||
|
||||
- org.bukkit.event.player.PlayerJoinEvent playerJoinEvent = new org.bukkit.event.player.PlayerJoinEvent(bukkitPlayer, io.papermc.paper.adventure.PaperAdventure.asAdventure(mutableComponent)); // Paper - Adventure
|
||||
+ org.bukkit.event.player.PlayerJoinEvent playerJoinEvent = new org.bukkit.event.player.PlayerJoinEvent(bukkitPlayer, getJoinMsg(mutableComponent, bukkitPlayer)); // Paper - Adventure // Leaf - Configurable connection message - join message
|
||||
this.cserver.getPluginManager().callEvent(playerJoinEvent);
|
||||
|
||||
if (!player.connection.isAcceptingMessages()) {
|
||||
@@ -347,7 +347,7 @@ public abstract class PlayerList {
|
||||
|
||||
final net.kyori.adventure.text.Component jm = playerJoinEvent.joinMessage();
|
||||
|
||||
- if (jm != null && !jm.equals(net.kyori.adventure.text.Component.empty())) { // Paper - Adventure
|
||||
+ if (org.dreeam.leaf.config.modules.misc.ConnectionMessage.joinEnabled && jm != null && !jm.equals(net.kyori.adventure.text.Component.empty())) { // Paper - Adventure // Leaf - Configurable connection message - join message
|
||||
joinMessage = io.papermc.paper.adventure.PaperAdventure.asVanilla(jm); // Paper - Adventure
|
||||
this.server.getPlayerList().broadcastSystemMessage(joinMessage, false); // Paper - Adventure
|
||||
}
|
||||
@@ -530,7 +530,7 @@ public abstract class PlayerList {
|
||||
player.closeContainer(org.bukkit.event.inventory.InventoryCloseEvent.Reason.DISCONNECT); // Paper - Inventory close reason
|
||||
}
|
||||
|
||||
- org.bukkit.event.player.PlayerQuitEvent playerQuitEvent = new org.bukkit.event.player.PlayerQuitEvent(player.getBukkitEntity(), leaveMessage, player.quitReason); // Paper - Adventure & Add API for quit reason
|
||||
+ org.bukkit.event.player.PlayerQuitEvent playerQuitEvent = new org.bukkit.event.player.PlayerQuitEvent(player.getBukkitEntity(), getQuitMsg(leaveMessage, player.getBukkitEntity()), player.quitReason); // Paper - Adventure & Add API for quit reason // Leaf - Configurable connection message - quit message
|
||||
this.cserver.getPluginManager().callEvent(playerQuitEvent);
|
||||
player.getBukkitEntity().disconnect(playerQuitEvent.getQuitMessage());
|
||||
|
||||
@@ -1488,4 +1488,34 @@ public abstract class PlayerList {
|
||||
public boolean isAllowCommandsForAllPlayers() {
|
||||
return this.allowCommandsForAllPlayers;
|
||||
}
|
||||
+
|
||||
+ // Leaf start - Configurable connection message
|
||||
+ private net.kyori.adventure.text.Component getJoinMsg(MutableComponent defaultJoinMsg, org.bukkit.craftbukkit.entity.CraftPlayer craftPlayer) {
|
||||
+ if (org.dreeam.leaf.config.modules.misc.ConnectionMessage.joinEnabled) {
|
||||
+ if ("default".equals(org.dreeam.leaf.config.modules.misc.ConnectionMessage.joinMessage)) {
|
||||
+ return io.papermc.paper.adventure.PaperAdventure.asAdventure(defaultJoinMsg);
|
||||
+ }
|
||||
+
|
||||
+ return net.kyori.adventure.text.minimessage.MiniMessage.miniMessage().deserialize(org.dreeam.leaf.config.modules.misc.ConnectionMessage.joinMessage)
|
||||
+ .replaceText(net.kyori.adventure.text.TextReplacementConfig.builder().matchLiteral("<player_name>").replacement(craftPlayer.getName()).build())
|
||||
+ .replaceText(net.kyori.adventure.text.TextReplacementConfig.builder().matchLiteral("<player_displayname>").replacement(craftPlayer.displayName()).build());
|
||||
+ }
|
||||
+
|
||||
+ return net.kyori.adventure.text.Component.empty();
|
||||
+ }
|
||||
+
|
||||
+ private net.kyori.adventure.text.Component getQuitMsg(net.kyori.adventure.text.Component defaultJoinMsg, org.bukkit.craftbukkit.entity.CraftPlayer craftPlayer) {
|
||||
+ if (org.dreeam.leaf.config.modules.misc.ConnectionMessage.quitEnabled) {
|
||||
+ if ("default".equals(org.dreeam.leaf.config.modules.misc.ConnectionMessage.quitMessage)) {
|
||||
+ return defaultJoinMsg;
|
||||
+ }
|
||||
+
|
||||
+ return net.kyori.adventure.text.minimessage.MiniMessage.miniMessage().deserialize(org.dreeam.leaf.config.modules.misc.ConnectionMessage.quitMessage)
|
||||
+ .replaceText(net.kyori.adventure.text.TextReplacementConfig.builder().matchLiteral("<player_name>").replacement(craftPlayer.getName()).build())
|
||||
+ .replaceText(net.kyori.adventure.text.TextReplacementConfig.builder().matchLiteral("<player_displayname>").replacement(craftPlayer.displayName()).build());
|
||||
+ }
|
||||
+
|
||||
+ return net.kyori.adventure.text.Component.empty();
|
||||
+ }
|
||||
+ // Leaf end - Configurable connection message
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
|
||||
Date: Wed, 7 Aug 2024 18:54:01 +0800
|
||||
Subject: [PATCH] Configurable unknown command message
|
||||
|
||||
|
||||
diff --git a/net/minecraft/commands/Commands.java b/net/minecraft/commands/Commands.java
|
||||
index 287edc8caecfd1ebb399d52789161f4d57d0801c..2d3a0d7735983065a41212b202bcb010ba0bf014 100644
|
||||
--- a/net/minecraft/commands/Commands.java
|
||||
+++ b/net/minecraft/commands/Commands.java
|
||||
@@ -394,31 +394,8 @@ public class Commands {
|
||||
// Paper start - Add UnknownCommandEvent
|
||||
final net.kyori.adventure.text.TextComponent.Builder builder = net.kyori.adventure.text.Component.text();
|
||||
// source.sendFailure(ComponentUtils.fromMessage(var7.getRawMessage()));
|
||||
- builder.color(net.kyori.adventure.text.format.NamedTextColor.RED).append(io.papermc.paper.command.brigadier.MessageComponentSerializer.message().deserialize(var7.getRawMessage()));
|
||||
// Paper end - Add UnknownCommandEvent
|
||||
- if (var7.getInput() != null && var7.getCursor() >= 0) {
|
||||
- int min = Math.min(var7.getInput().length(), var7.getCursor());
|
||||
- MutableComponent mutableComponent = Component.empty()
|
||||
- .withStyle(ChatFormatting.GRAY)
|
||||
- .withStyle(style -> style.withClickEvent(new ClickEvent.SuggestCommand("/" + label))); // CraftBukkit // Paper
|
||||
- if (min > 10) {
|
||||
- mutableComponent.append(CommonComponents.ELLIPSIS);
|
||||
- }
|
||||
-
|
||||
- mutableComponent.append(var7.getInput().substring(Math.max(0, min - 10), min));
|
||||
- if (min < var7.getInput().length()) {
|
||||
- Component component = Component.literal(var7.getInput().substring(min)).withStyle(ChatFormatting.RED, ChatFormatting.UNDERLINE);
|
||||
- mutableComponent.append(component);
|
||||
- }
|
||||
-
|
||||
- mutableComponent.append(Component.translatable("command.context.here").withStyle(ChatFormatting.RED, ChatFormatting.ITALIC));
|
||||
- // Paper start - Add UnknownCommandEvent
|
||||
- // source.sendFailure(mutableComponent);
|
||||
- builder
|
||||
- .append(net.kyori.adventure.text.Component.newline())
|
||||
- .append(io.papermc.paper.adventure.PaperAdventure.asAdventure(mutableComponent));
|
||||
- }
|
||||
- org.bukkit.event.command.UnknownCommandEvent event = new org.bukkit.event.command.UnknownCommandEvent(source.getBukkitSender(), command, org.spigotmc.SpigotConfig.unknownCommandMessage.isEmpty() ? null : builder.build());
|
||||
+ org.bukkit.event.command.UnknownCommandEvent event = new org.bukkit.event.command.UnknownCommandEvent(source.getBukkitSender(), command, getUnknownCommandMessage(builder, var7, label)); // Leaf - Configurable unknown command message
|
||||
org.bukkit.Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (event.message() != null) {
|
||||
source.sendFailure(io.papermc.paper.adventure.PaperAdventure.asVanilla(event.message()), false);
|
||||
@@ -668,6 +645,86 @@ public class Commands {
|
||||
};
|
||||
}
|
||||
|
||||
+ // Leaf start - Configurable unknown command message
|
||||
+ private static net.kyori.adventure.text.TextComponent getUnknownCommandMessage(
|
||||
+ net.kyori.adventure.text.TextComponent.Builder builder, CommandSyntaxException commandSyntaxException, String label
|
||||
+ ) {
|
||||
+ String rawMessage = org.dreeam.leaf.config.modules.misc.UnknownCommandMessage.unknownCommandMessage;
|
||||
+
|
||||
+ if (!"default".equals(rawMessage)) {
|
||||
+ final String input = commandSyntaxException.getInput();
|
||||
+ final int cursor = commandSyntaxException.getCursor();
|
||||
+
|
||||
+ if (rawMessage.contains("<detail>") && input != null && cursor >= 0) {
|
||||
+ final int min = Math.min(input.length(), cursor);
|
||||
+ final net.kyori.adventure.text.TextComponent.Builder detail = net.kyori.adventure.text.Component.text();
|
||||
+ final net.kyori.adventure.text.Component context = net.kyori.adventure.text.Component.translatable("command.context.here")
|
||||
+ .color(net.kyori.adventure.text.format.NamedTextColor.RED)
|
||||
+ .decorate(net.kyori.adventure.text.format.TextDecoration.ITALIC);
|
||||
+ final net.kyori.adventure.text.event.ClickEvent event = net.kyori.adventure.text.event.ClickEvent.suggestCommand("/" + label);
|
||||
+
|
||||
+ detail.color(net.kyori.adventure.text.format.NamedTextColor.GRAY);
|
||||
+
|
||||
+ if (min > 10) {
|
||||
+ detail.append(net.kyori.adventure.text.Component.text("..."));
|
||||
+ }
|
||||
+
|
||||
+ detail.append(net.kyori.adventure.text.Component.text(input.substring(Math.max(0, min - 10), min)));
|
||||
+ if (min < input.length()) {
|
||||
+ net.kyori.adventure.text.Component commandInput = net.kyori.adventure.text.Component.text(input.substring(min))
|
||||
+ .color(net.kyori.adventure.text.format.NamedTextColor.RED)
|
||||
+ .decorate(net.kyori.adventure.text.format.TextDecoration.UNDERLINED);
|
||||
+
|
||||
+ detail.append(commandInput);
|
||||
+ }
|
||||
+
|
||||
+ detail.append(context);
|
||||
+ detail.clickEvent(event);
|
||||
+
|
||||
+ builder.append(net.kyori.adventure.text.minimessage.MiniMessage.miniMessage().deserialize(rawMessage, net.kyori.adventure.text.minimessage.tag.resolver.Placeholder.component("detail", detail.build())));
|
||||
+ } else {
|
||||
+ rawMessage = rawMessage.replace("<detail>", "");
|
||||
+ builder.append(net.kyori.adventure.text.minimessage.MiniMessage.miniMessage().deserialize(rawMessage));
|
||||
+ }
|
||||
+
|
||||
+ return builder.build();
|
||||
+ }
|
||||
+
|
||||
+ return getVanillaUnknownCommandMessage(builder, commandSyntaxException, label);
|
||||
+ }
|
||||
+
|
||||
+ private static net.kyori.adventure.text.TextComponent getVanillaUnknownCommandMessage(
|
||||
+ net.kyori.adventure.text.TextComponent.Builder builder, CommandSyntaxException var7, String label
|
||||
+ ) {
|
||||
+ builder.color(net.kyori.adventure.text.format.NamedTextColor.RED).append(io.papermc.paper.command.brigadier.MessageComponentSerializer.message().deserialize(var7.getRawMessage()));
|
||||
+
|
||||
+ if (var7.getInput() != null && var7.getCursor() >= 0) {
|
||||
+ int min = Math.min(var7.getInput().length(), var7.getCursor());
|
||||
+ MutableComponent mutableComponent = Component.empty()
|
||||
+ .withStyle(ChatFormatting.GRAY)
|
||||
+ .withStyle(style -> style.withClickEvent(new ClickEvent.SuggestCommand("/" + label))); // CraftBukkit // Paper
|
||||
+ if (min > 10) {
|
||||
+ mutableComponent.append(CommonComponents.ELLIPSIS);
|
||||
+ }
|
||||
+
|
||||
+ mutableComponent.append(var7.getInput().substring(Math.max(0, min - 10), min));
|
||||
+ if (min < var7.getInput().length()) {
|
||||
+ Component component = Component.literal(var7.getInput().substring(min)).withStyle(ChatFormatting.RED, ChatFormatting.UNDERLINE);
|
||||
+ mutableComponent.append(component);
|
||||
+ }
|
||||
+
|
||||
+ mutableComponent.append(Component.translatable("command.context.here").withStyle(ChatFormatting.RED, ChatFormatting.ITALIC));
|
||||
+ // Paper start - Add UnknownCommandEvent
|
||||
+ // source.sendFailure(mutableComponent);
|
||||
+ builder
|
||||
+ .append(net.kyori.adventure.text.Component.newline())
|
||||
+ .append(io.papermc.paper.adventure.PaperAdventure.asAdventure(mutableComponent));
|
||||
+ }
|
||||
+
|
||||
+ return builder.build();
|
||||
+ }
|
||||
+ // Leaf end - Configurable unknown command message
|
||||
+
|
||||
public static void validate() {
|
||||
CommandBuildContext commandBuildContext = createValidationContext(VanillaRegistries.createLookup());
|
||||
CommandDispatcher<CommandSourceStack> dispatcher = new Commands(Commands.CommandSelection.ALL, commandBuildContext).getDispatcher();
|
||||
@@ -0,0 +1,27 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
|
||||
Date: Fri, 7 Jun 2024 17:43:43 +0800
|
||||
Subject: [PATCH] Remove stream in BlockBehaviour cache blockstate
|
||||
|
||||
|
||||
diff --git a/net/minecraft/world/level/block/state/BlockBehaviour.java b/net/minecraft/world/level/block/state/BlockBehaviour.java
|
||||
index 3741afd1b2a5cb5cfce5e14cb78aa5ff5c3b218e..331474bb33c8612283a0ec478c1ae8768180b22d 100644
|
||||
--- a/net/minecraft/world/level/block/state/BlockBehaviour.java
|
||||
+++ b/net/minecraft/world/level/block/state/BlockBehaviour.java
|
||||
@@ -1064,8 +1064,14 @@ public abstract class BlockBehaviour implements FeatureElement {
|
||||
)
|
||||
);
|
||||
} else {
|
||||
- this.largeCollisionShape = Arrays.stream(Direction.Axis.values())
|
||||
- .anyMatch(dir -> this.collisionShape.min(dir) < 0.0 || this.collisionShape.max(dir) > 1.0);
|
||||
+ // Leaf start - Remove stream in BlockBehaviour cache blockstate
|
||||
+ for (Direction.Axis axis : Direction.Axis.values()) {
|
||||
+ if (this.collisionShape.min(axis) < 0.0 || this.collisionShape.max(axis) > 1.0) {
|
||||
+ this.largeCollisionShape = true;
|
||||
+ break;
|
||||
+ }
|
||||
+ }
|
||||
+ // Leaf end - Remove stream in BlockBehaviour cache blockstate
|
||||
this.faceSturdy = new boolean[DIRECTIONS.length * SUPPORT_TYPE_COUNT];
|
||||
|
||||
for (Direction direction : DIRECTIONS) {
|
||||
@@ -0,0 +1,32 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
|
||||
Date: Tue, 17 Sep 2024 02:26:44 -0400
|
||||
Subject: [PATCH] Remove stream in entity visible effects filter
|
||||
|
||||
|
||||
diff --git a/net/minecraft/world/entity/LivingEntity.java b/net/minecraft/world/entity/LivingEntity.java
|
||||
index e65914c2623197031d50508af5c45a4db6b98836..d55a701d1f9a39b4734c8b02b655e1f1a53e616b 100644
|
||||
--- a/net/minecraft/world/entity/LivingEntity.java
|
||||
+++ b/net/minecraft/world/entity/LivingEntity.java
|
||||
@@ -975,12 +975,15 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
||||
}
|
||||
|
||||
private void updateSynchronizedMobEffectParticles() {
|
||||
- List<ParticleOptions> list = this.activeEffects
|
||||
- .values()
|
||||
- .stream()
|
||||
- .filter(MobEffectInstance::isVisible)
|
||||
- .map(MobEffectInstance::getParticleOptions)
|
||||
- .toList();
|
||||
+ // Leaf start - Remove stream in entity visible effects filter
|
||||
+ List<ParticleOptions> list = new ArrayList<>();
|
||||
+
|
||||
+ for (MobEffectInstance effect : this.activeEffects.values()) {
|
||||
+ if (effect.isVisible()) {
|
||||
+ list.add(effect.getParticleOptions());
|
||||
+ }
|
||||
+ }
|
||||
+ // Leaf end - Remove stream in entity visible effects filter
|
||||
this.entityData.set(DATA_EFFECT_PARTICLES, list);
|
||||
this.entityData.set(DATA_EFFECT_AMBIENCE_ID, areAllEffectsAmbient(this.activeEffects.values()));
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
|
||||
Date: Thu, 17 Oct 2024 01:51:38 -0400
|
||||
Subject: [PATCH] Remove stream and double iteration in enough deep sleeping
|
||||
player check
|
||||
|
||||
|
||||
diff --git a/net/minecraft/server/players/SleepStatus.java b/net/minecraft/server/players/SleepStatus.java
|
||||
index 2a7ae521654ad5c9f392baa5562e64bb71b13097..2d0033b18f46fb05df12536d68b4bce455abfeed 100644
|
||||
--- a/net/minecraft/server/players/SleepStatus.java
|
||||
+++ b/net/minecraft/server/players/SleepStatus.java
|
||||
@@ -15,9 +15,24 @@ public class SleepStatus {
|
||||
|
||||
public boolean areEnoughDeepSleeping(int requiredSleepPercentage, List<ServerPlayer> sleepingPlayers) {
|
||||
// CraftBukkit start
|
||||
- int i = (int) sleepingPlayers.stream().filter(player -> player.isSleepingLongEnough() || player.fauxSleeping).count();
|
||||
- boolean anyDeepSleep = sleepingPlayers.stream().anyMatch(Player::isSleepingLongEnough);
|
||||
- return anyDeepSleep && i >= this.sleepersNeeded(requiredSleepPercentage);
|
||||
+ // Leaf start - Remove stream and double iteration in enough deep sleeping player check
|
||||
+ int count = 0;
|
||||
+ boolean anyPlayerSleeping = false;
|
||||
+
|
||||
+ for (ServerPlayer player : sleepingPlayers) {
|
||||
+ final boolean isSleepingLongEnough = player.isSleepingLongEnough();
|
||||
+
|
||||
+ if (isSleepingLongEnough) {
|
||||
+ anyPlayerSleeping = true;
|
||||
+ }
|
||||
+
|
||||
+ if (isSleepingLongEnough || player.fauxSleeping || (player.level().purpurConfig.idleTimeoutCountAsSleeping && player.isAfk())) { // Purpur - AFK API
|
||||
+ count++;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ return anyPlayerSleeping && count >= this.sleepersNeeded(requiredSleepPercentage);
|
||||
+ // Leaf end - Remove stream and double iteration in enough deep sleeping player check
|
||||
// CraftBukkit end
|
||||
}
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
|
||||
Date: Sat, 5 Oct 2024 15:39:15 -0400
|
||||
Subject: [PATCH] Remove stream in trial spawner ticking
|
||||
|
||||
|
||||
diff --git a/net/minecraft/world/level/block/entity/trialspawner/TrialSpawnerState.java b/net/minecraft/world/level/block/entity/trialspawner/TrialSpawnerState.java
|
||||
index 6b3d92e76a16358c89ee07e1970c764ba4a8e2dc..5edc7278387c3fc61909582ebf34e905abc68fc4 100644
|
||||
--- a/net/minecraft/world/level/block/entity/trialspawner/TrialSpawnerState.java
|
||||
+++ b/net/minecraft/world/level/block/entity/trialspawner/TrialSpawnerState.java
|
||||
@@ -173,17 +173,21 @@ public enum TrialSpawnerState implements StringRepresentable {
|
||||
}
|
||||
|
||||
private static Optional<Vec3> calculatePositionToSpawnSpawner(ServerLevel level, BlockPos pos, TrialSpawner spawner, TrialSpawnerData spawnerData) {
|
||||
- List<Player> list = spawnerData.detectedPlayers
|
||||
- .stream()
|
||||
- .map(level::getPlayerByUUID)
|
||||
- .filter(Objects::nonNull)
|
||||
- .filter(
|
||||
- player -> !player.isCreative()
|
||||
- && !player.isSpectator()
|
||||
- && player.isAlive()
|
||||
- && player.distanceToSqr(pos.getCenter()) <= Mth.square(spawner.getRequiredPlayerRange())
|
||||
- )
|
||||
- .toList();
|
||||
+ // Leaf start - Remove stream in trial spawner ticking
|
||||
+ List<Player> list = new java.util.ArrayList<>();
|
||||
+
|
||||
+ for (UUID uuid : spawnerData.detectedPlayers) {
|
||||
+ Player player = level.getPlayerByUUID(uuid);
|
||||
+
|
||||
+ if (player != null
|
||||
+ && !player.isCreative()
|
||||
+ && !player.isSpectator()
|
||||
+ && player.isAlive()
|
||||
+ && player.distanceToSqr(pos.getCenter()) <= Mth.square(spawner.getRequiredPlayerRange())) {
|
||||
+ list.add(player);
|
||||
+ }
|
||||
+ }
|
||||
+ // Leaf end - Remove stream in trial spawner ticking
|
||||
if (list.isEmpty()) {
|
||||
return Optional.empty();
|
||||
} else {
|
||||
@@ -203,16 +207,29 @@ public enum TrialSpawnerState implements StringRepresentable {
|
||||
|
||||
@Nullable
|
||||
private static Entity selectEntityToSpawnItemAbove(List<Player> player, Set<UUID> currentMobs, TrialSpawner spawner, BlockPos pos, ServerLevel level) {
|
||||
- Stream<Entity> stream = currentMobs.stream()
|
||||
- .map(level::getEntity)
|
||||
- .filter(Objects::nonNull)
|
||||
- .filter(entity -> entity.isAlive() && entity.distanceToSqr(pos.getCenter()) <= Mth.square(spawner.getRequiredPlayerRange()));
|
||||
- List<? extends Entity> list = level.random.nextBoolean() ? stream.toList() : player;
|
||||
- if (list.isEmpty()) {
|
||||
- return null;
|
||||
+ // Leaf start - Remove stream in trial spawner ticking
|
||||
+ if (level.random.nextBoolean()) {
|
||||
+ List<Entity> list = new java.util.ArrayList<>();
|
||||
+ for (UUID uuid : currentMobs) {
|
||||
+ Entity entity = level.getEntity(uuid);
|
||||
+ if (entity != null && entity.isAlive() && entity.distanceToSqr(pos.getCenter()) <= Mth.square(spawner.getRequiredPlayerRange())) {
|
||||
+ list.add(entity);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ if (list.isEmpty()) {
|
||||
+ return null;
|
||||
+ } else {
|
||||
+ return list.size() == 1 ? list.getFirst() : Util.getRandom(list, level.random);
|
||||
+ }
|
||||
} else {
|
||||
- return list.size() == 1 ? list.getFirst() : Util.getRandom(list, level.random);
|
||||
+ if (player.isEmpty()) {
|
||||
+ return null;
|
||||
+ } else {
|
||||
+ return player.size() == 1 ? player.getFirst() : Util.getRandom(player, level.random);
|
||||
+ }
|
||||
}
|
||||
+ // Leaf end - Remove stream in trial spawner ticking
|
||||
}
|
||||
|
||||
private boolean timeToSpawnItemSpawner(ServerLevel level, TrialSpawnerData spawnerData) {
|
||||
@@ -0,0 +1,65 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com>
|
||||
Date: Sat, 26 Oct 2024 00:06:04 +0800
|
||||
Subject: [PATCH] Remove stream in Brain
|
||||
|
||||
|
||||
diff --git a/net/minecraft/world/entity/ai/Brain.java b/net/minecraft/world/entity/ai/Brain.java
|
||||
index 98652c2c549bd7657a606d25ba4fe3cffa0548da..29fdf94db0308031edfe7915fc587a2aa5a1a18a 100644
|
||||
--- a/net/minecraft/world/entity/ai/Brain.java
|
||||
+++ b/net/minecraft/world/entity/ai/Brain.java
|
||||
@@ -70,13 +70,22 @@ public class Brain<E extends LivingEntity> {
|
||||
(new MapCodec<Brain<E>>() {
|
||||
@Override
|
||||
public <T> Stream<T> keys(DynamicOps<T> ops) {
|
||||
- return memoryTypes.stream()
|
||||
- .flatMap(
|
||||
- memoryModuleType -> memoryModuleType.getCodec()
|
||||
- .map(codec -> BuiltInRegistries.MEMORY_MODULE_TYPE.getKey((MemoryModuleType<?>)memoryModuleType))
|
||||
- .stream()
|
||||
- )
|
||||
- .map(resourceLocation -> ops.createString(resourceLocation.toString()));
|
||||
+ // Leaf start - Remove stream in Brain
|
||||
+ List<T> results = new java.util.ArrayList<>();
|
||||
+
|
||||
+ for (MemoryModuleType<?> memoryModuleType : memoryTypes) {
|
||||
+ final Optional<?> codec = memoryModuleType.getCodec();
|
||||
+
|
||||
+ if (codec.isPresent()) {
|
||||
+ final net.minecraft.resources.ResourceLocation resourceLocation = BuiltInRegistries.MEMORY_MODULE_TYPE.getKey(memoryModuleType);
|
||||
+ final T opsResult = ops.createString(resourceLocation.toString());
|
||||
+
|
||||
+ results.add(opsResult);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ return results.stream();
|
||||
+ // Leaf end - Remove stream in Brain
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -111,7 +120,14 @@ public class Brain<E extends LivingEntity> {
|
||||
|
||||
@Override
|
||||
public <T> RecordBuilder<T> encode(Brain<E> input, DynamicOps<T> ops, RecordBuilder<T> prefix) {
|
||||
- input.memories().forEach(memoryValue -> memoryValue.serialize(ops, prefix));
|
||||
+ // Leaf start - Remove stream in Brain
|
||||
+ for (Entry<MemoryModuleType<?>, Optional<? extends ExpirableValue<?>>> memory : input.memories.entrySet()) {
|
||||
+ final Brain.MemoryValue<?> result = Brain.MemoryValue.createUnchecked(memory.getKey(), memory.getValue());
|
||||
+
|
||||
+ result.serialize(ops, prefix);
|
||||
+ }
|
||||
+ // Leaf end - Remove stream in Brain
|
||||
+
|
||||
return prefix;
|
||||
}
|
||||
})
|
||||
@@ -153,7 +169,7 @@ public class Brain<E extends LivingEntity> {
|
||||
}
|
||||
|
||||
Stream<Brain.MemoryValue<?>> memories() {
|
||||
- return this.memories.entrySet().stream().map(memory -> Brain.MemoryValue.createUnchecked(memory.getKey(), memory.getValue()));
|
||||
+ return this.memories.entrySet().stream().map(memory -> Brain.MemoryValue.createUnchecked(memory.getKey(), memory.getValue())); // Leaf - Remove stream in Brain - diff on change
|
||||
}
|
||||
|
||||
public boolean hasMemoryValue(MemoryModuleType<?> type) {
|
||||
@@ -0,0 +1,48 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com>
|
||||
Date: Sat, 26 Oct 2024 00:56:24 +0800
|
||||
Subject: [PATCH] Remove stream in BehaviorUtils
|
||||
|
||||
|
||||
diff --git a/net/minecraft/world/entity/ai/behavior/BehaviorUtils.java b/net/minecraft/world/entity/ai/behavior/BehaviorUtils.java
|
||||
index e7f74b4f54069ffdf74f029639cbf0756f2db095..b5257eefa04e930b45ffd9d46f28e53026ad728f 100644
|
||||
--- a/net/minecraft/world/entity/ai/behavior/BehaviorUtils.java
|
||||
+++ b/net/minecraft/world/entity/ai/behavior/BehaviorUtils.java
|
||||
@@ -110,10 +110,33 @@ public class BehaviorUtils {
|
||||
|
||||
public static SectionPos findSectionClosestToVillage(ServerLevel serverLevel, SectionPos sectionPos, int radius) {
|
||||
int i = serverLevel.sectionsToVillage(sectionPos);
|
||||
- return SectionPos.cube(sectionPos, radius)
|
||||
- .filter(pos -> serverLevel.sectionsToVillage(pos) < i)
|
||||
- .min(Comparator.comparingInt(serverLevel::sectionsToVillage))
|
||||
- .orElse(sectionPos);
|
||||
+ // Leaf start - Remove stream in BehaviorUtils
|
||||
+ SectionPos closestSection = sectionPos;
|
||||
+ int closestDistance = i;
|
||||
+
|
||||
+ final int lowerX = sectionPos.getX() - radius;
|
||||
+ final int lowerY = sectionPos.getY() - radius;
|
||||
+ final int lowerZ = sectionPos.getZ() - radius;
|
||||
+ final int upperX = sectionPos.getX() + radius;
|
||||
+ final int upperY = sectionPos.getY() + radius;
|
||||
+ final int upperZ = sectionPos.getZ() + radius;
|
||||
+
|
||||
+ for (int x = lowerX; x <= upperX; x++) {
|
||||
+ for (int z = lowerZ; z <= upperZ; z++) {
|
||||
+ for (int y = lowerY; y <= upperY; y++) {
|
||||
+ SectionPos pos = SectionPos.of(x, y, z);
|
||||
+ int distance = serverLevel.sectionsToVillage(pos);
|
||||
+
|
||||
+ if (distance < closestDistance) {
|
||||
+ closestDistance = distance;
|
||||
+ closestSection = pos;
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ return closestSection;
|
||||
+ // Leaf end - Remove stream in BehaviorUtils
|
||||
}
|
||||
|
||||
public static boolean isWithinAttackRange(Mob mob, LivingEntity target, int cooldown) {
|
||||
@@ -0,0 +1,53 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com>
|
||||
Date: Sat, 26 Oct 2024 14:04:54 +0800
|
||||
Subject: [PATCH] Remove stream in YieldJobSite
|
||||
|
||||
|
||||
diff --git a/net/minecraft/world/entity/ai/behavior/YieldJobSite.java b/net/minecraft/world/entity/ai/behavior/YieldJobSite.java
|
||||
index 44340aa26bc89faaf8842bb36048cf61dba34314..811cbeafaf907b1fc96cc0916073c5f0100c555e 100644
|
||||
--- a/net/minecraft/world/entity/ai/behavior/YieldJobSite.java
|
||||
+++ b/net/minecraft/world/entity/ai/behavior/YieldJobSite.java
|
||||
@@ -38,23 +38,26 @@ public class YieldJobSite {
|
||||
if (type.isEmpty()) {
|
||||
return true;
|
||||
} else {
|
||||
- instance.<List<LivingEntity>>get(nearestLivingEntities)
|
||||
- .stream()
|
||||
- .filter(nearEntity -> nearEntity instanceof Villager && nearEntity != villager)
|
||||
- .map(nearEntity -> (Villager)nearEntity)
|
||||
- .filter(LivingEntity::isAlive)
|
||||
- .filter(nearVillager -> nearbyWantsJobsite(type.get(), nearVillager, blockPos))
|
||||
- .findFirst()
|
||||
- .ifPresent(nearVillager -> {
|
||||
- walkTarget.erase();
|
||||
- lookTarget.erase();
|
||||
- potentialJobSite.erase();
|
||||
- if (nearVillager.getBrain().getMemory(MemoryModuleType.JOB_SITE).isEmpty()) {
|
||||
- BehaviorUtils.setWalkAndLookTargetMemories(nearVillager, blockPos, speedModifier, 1);
|
||||
- nearVillager.getBrain().setMemory(MemoryModuleType.POTENTIAL_JOB_SITE, GlobalPos.of(level.dimension(), blockPos));
|
||||
- DebugPackets.sendPoiTicketCountPacket(level, blockPos);
|
||||
+ // Leaf start - Remove stream in YieldJobSite
|
||||
+ List<LivingEntity> mobsList = instance.get(nearestLivingEntities);
|
||||
+ for (LivingEntity nearEntity : mobsList) {
|
||||
+ if (nearEntity instanceof Villager nearVillager && nearEntity != villager && nearEntity.isAlive()) {
|
||||
+ if (nearbyWantsJobsite(type.get(), nearVillager, blockPos)) {
|
||||
+ walkTarget.erase();
|
||||
+ lookTarget.erase();
|
||||
+ potentialJobSite.erase();
|
||||
+
|
||||
+ if (nearVillager.getBrain().getMemory(MemoryModuleType.JOB_SITE).isEmpty()) {
|
||||
+ BehaviorUtils.setWalkAndLookTargetMemories(nearVillager, blockPos, speedModifier, 1);
|
||||
+ nearVillager.getBrain().setMemory(MemoryModuleType.POTENTIAL_JOB_SITE, GlobalPos.of(level.dimension(), blockPos));
|
||||
+ DebugPackets.sendPoiTicketCountPacket(level, blockPos);
|
||||
+ }
|
||||
+
|
||||
+ break;
|
||||
}
|
||||
- });
|
||||
+ }
|
||||
+ }
|
||||
+ // Leaf end - Remove stream in YieldJobSite
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com>
|
||||
Date: Tue, 9 Nov 2077 00:00:00 +0800
|
||||
Subject: [PATCH] Remove stream in PlayerSensor
|
||||
|
||||
Stream operations in PlayerSensor take too much time
|
||||
while ticking Villager farms, so just replace it with for loop =-=
|
||||
Before: 164ms
|
||||
After: 18ms
|
||||
|
||||
diff --git a/net/minecraft/world/entity/ai/sensing/PlayerSensor.java b/net/minecraft/world/entity/ai/sensing/PlayerSensor.java
|
||||
index eb3ec4be63e1710d0ed9021eb8158d56eae89f8d..fa438315b4ed8e9394383b82b89ecb04bac3399f 100644
|
||||
--- a/net/minecraft/world/entity/ai/sensing/PlayerSensor.java
|
||||
+++ b/net/minecraft/world/entity/ai/sensing/PlayerSensor.java
|
||||
@@ -26,17 +26,39 @@ public class PlayerSensor extends Sensor<LivingEntity> {
|
||||
|
||||
@Override
|
||||
protected void doTick(ServerLevel level, LivingEntity entity) {
|
||||
- List<Player> list = level.players()
|
||||
- .stream()
|
||||
- .filter(EntitySelector.NO_SPECTATORS)
|
||||
- .filter(serverPlayer -> entity.closerThan(serverPlayer, this.getFollowDistance(entity)))
|
||||
- .sorted(Comparator.comparingDouble(entity::distanceToSqr))
|
||||
- .collect(Collectors.toList());
|
||||
+ // Leaf start - Remove stream in PlayerSensor
|
||||
+ List<Player> list = new java.util.ArrayList<>();
|
||||
+ for (Player serverPlayer : level.players()) {
|
||||
+ if (!EntitySelector.NO_SPECTATORS.test(serverPlayer)) {
|
||||
+ continue;
|
||||
+ }
|
||||
+ if (!entity.closerThan(serverPlayer, this.getFollowDistance(entity))) {
|
||||
+ continue;
|
||||
+ }
|
||||
+
|
||||
+ list.add(serverPlayer);
|
||||
+ }
|
||||
+ list.sort(Comparator.comparingDouble(entity::distanceToSqr));
|
||||
+ // Leaf end - Remove stream in PlayerSensor
|
||||
Brain<?> brain = entity.getBrain();
|
||||
brain.setMemory(MemoryModuleType.NEAREST_PLAYERS, list);
|
||||
- List<Player> list1 = list.stream().filter(player -> isEntityTargetable(level, entity, player)).collect(Collectors.toList());
|
||||
+ // Leaf start - Remove stream in PlayerSensor
|
||||
+ List<Player> list1 = new java.util.ArrayList<>(list.size());
|
||||
+ for (Player player : list) {
|
||||
+ if (isEntityTargetable(level, entity, player)) {
|
||||
+ list1.add(player);
|
||||
+ }
|
||||
+ }
|
||||
+ // Leaf end - Remove stream in PlayerSensor
|
||||
brain.setMemory(MemoryModuleType.NEAREST_VISIBLE_PLAYER, list1.isEmpty() ? null : list1.get(0));
|
||||
- List<Player> list2 = list1.stream().filter(player -> isEntityAttackable(level, entity, player)).toList();
|
||||
+ // Leaf start - Remove stream in PlayerSensor
|
||||
+ List<Player> list2 = new java.util.ArrayList<>(list1.size());
|
||||
+ for (Player player : list1) {
|
||||
+ if (isEntityAttackable(level, entity, player)) {
|
||||
+ list2.add(player);
|
||||
+ }
|
||||
+ }
|
||||
+ // Leaf end - Remove stream in PlayerSensor
|
||||
brain.setMemory(MemoryModuleType.NEAREST_VISIBLE_ATTACKABLE_PLAYERS, list2);
|
||||
brain.setMemory(MemoryModuleType.NEAREST_VISIBLE_ATTACKABLE_PLAYER, list2.isEmpty() ? null : list2.get(0));
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com>
|
||||
Date: Tue, 9 Nov 2077 00:00:00 +0800
|
||||
Subject: [PATCH] Remove stream in GolemSensor
|
||||
|
||||
Stream operations in GolemSensor is really expensive and takes
|
||||
up 80% time per method call.
|
||||
Before: 192ms
|
||||
After: 17ms
|
||||
|
||||
diff --git a/net/minecraft/world/entity/ai/sensing/GolemSensor.java b/net/minecraft/world/entity/ai/sensing/GolemSensor.java
|
||||
index 84d9e2a43adbabda8401e8ad8dd8d87f7dbeeea7..ed277d93254a30a817dd8246539c292240dc9669 100644
|
||||
--- a/net/minecraft/world/entity/ai/sensing/GolemSensor.java
|
||||
+++ b/net/minecraft/world/entity/ai/sensing/GolemSensor.java
|
||||
@@ -34,7 +34,15 @@ public class GolemSensor extends Sensor<LivingEntity> {
|
||||
public static void checkForNearbyGolem(LivingEntity livingEntity) {
|
||||
Optional<List<LivingEntity>> memory = livingEntity.getBrain().getMemory(MemoryModuleType.NEAREST_LIVING_ENTITIES);
|
||||
if (!memory.isEmpty()) {
|
||||
- boolean flag = memory.get().stream().anyMatch(entity -> entity.getType().equals(EntityType.IRON_GOLEM));
|
||||
+ // Leaf start - Remove stream in GolemSensor
|
||||
+ boolean flag = false;
|
||||
+ for (LivingEntity entity : memory.get()) {
|
||||
+ if (entity.getType().equals(EntityType.IRON_GOLEM)) {
|
||||
+ flag = true;
|
||||
+ break;
|
||||
+ }
|
||||
+ }
|
||||
+ // Leaf end - Remove stream in GolemSensor
|
||||
if (flag) {
|
||||
golemDetected(livingEntity);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Taiyou06 <kaandindar21@gmail.com>
|
||||
Date: Tue, 9 Nov 2077 00:00:00 +0800
|
||||
Subject: [PATCH] Remove stream in GateBehavior
|
||||
|
||||
|
||||
diff --git a/net/minecraft/world/entity/ai/behavior/GateBehavior.java b/net/minecraft/world/entity/ai/behavior/GateBehavior.java
|
||||
index bd31d1cac0d022a72bd536c41d1ef811886e7068..2830792cd98c0849280aa1e2116fa89f3c8d2c85 100644
|
||||
--- a/net/minecraft/world/entity/ai/behavior/GateBehavior.java
|
||||
+++ b/net/minecraft/world/entity/ai/behavior/GateBehavior.java
|
||||
@@ -73,9 +73,19 @@ public class GateBehavior<E extends LivingEntity> implements BehaviorControl<E>
|
||||
}
|
||||
}
|
||||
// Paper end - Perf: Remove streams from hot code
|
||||
- if (this.behaviors.stream().noneMatch(behavior -> behavior.getStatus() == Behavior.Status.RUNNING)) {
|
||||
+ // Leaf start - Remove more streams in GateBehavior
|
||||
+ boolean hasRunningTask = false;
|
||||
+ for (final BehaviorControl<? super E> behavior : this.behaviors) {
|
||||
+ if (behavior.getStatus() == Behavior.Status.RUNNING) {
|
||||
+ hasRunningTask = true;
|
||||
+ break;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ if (!hasRunningTask) {
|
||||
this.doStop(level, entity, gameTime);
|
||||
}
|
||||
+ // Leaf end - Remove more streams in GateBehavior
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -0,0 +1,77 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Taiyou06 <kaandindar21@gmail.com>
|
||||
Date: Mon, 11 Nov 2024 16:55:50 -0500
|
||||
Subject: [PATCH] Remove stream in updateFluidOnEyes
|
||||
|
||||
|
||||
diff --git a/net/minecraft/core/Holder.java b/net/minecraft/core/Holder.java
|
||||
index 6c7edbbf3935c40ccb78bee680ea75431718b9bd..a1b4dc70d555cce5e06c0298736d8b89e04a96be 100644
|
||||
--- a/net/minecraft/core/Holder.java
|
||||
+++ b/net/minecraft/core/Holder.java
|
||||
@@ -29,6 +29,8 @@ public interface Holder<T> {
|
||||
|
||||
Stream<TagKey<T>> tags();
|
||||
|
||||
+ Set<TagKey<T>> tagsAsSet(); // Leaf - Remove stream in updateFluidOnEyes
|
||||
+
|
||||
Either<ResourceKey<T>, T> unwrap();
|
||||
|
||||
Optional<ResourceKey<T>> unwrapKey();
|
||||
@@ -105,6 +107,13 @@ public interface Holder<T> {
|
||||
public Stream<TagKey<T>> tags() {
|
||||
return Stream.of();
|
||||
}
|
||||
+
|
||||
+ // Leaf start - Remove stream in updateFluidOnEyes
|
||||
+ @Override
|
||||
+ public Set<TagKey<T>> tagsAsSet() {
|
||||
+ return Set.of();
|
||||
+ }
|
||||
+ // Leaf end - Remove stream in updateFluidOnEyes
|
||||
}
|
||||
|
||||
public static enum Kind {
|
||||
@@ -238,6 +247,13 @@ public interface Holder<T> {
|
||||
return this.boundTags().stream();
|
||||
}
|
||||
|
||||
+ // Leaf start - Remove stream in updateFluidOnEyes
|
||||
+ @Override
|
||||
+ public Set<TagKey<T>> tagsAsSet() {
|
||||
+ return this.boundTags();
|
||||
+ }
|
||||
+ // Leaf end - Remove stream in updateFluidOnEyes
|
||||
+
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Reference{" + this.key + "=" + this.value + "}";
|
||||
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
|
||||
index 8ac90cc10625f395dba660e2358bbac79431b0cf..f71ab3764aa3bb8b2c48bcae8c7331b4d821e4b1 100644
|
||||
--- a/net/minecraft/world/entity/Entity.java
|
||||
+++ b/net/minecraft/world/entity/Entity.java
|
||||
@@ -1930,7 +1930,7 @@ 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) {
|
||||
- fluidState.getTags().forEach(this.fluidOnEyes::add);
|
||||
+ this.fluidOnEyes.addAll(fluidState.getTagsAsSet()); // Leaf - Remove stream in updateFluidOnEyes
|
||||
}
|
||||
}
|
||||
}
|
||||
diff --git a/net/minecraft/world/level/material/FluidState.java b/net/minecraft/world/level/material/FluidState.java
|
||||
index 0a5ae623a636923f3bbd3c01974497f39b7c4b62..f5bdd78b44881bd2b36b552165eca23d7dfac6b2 100644
|
||||
--- a/net/minecraft/world/level/material/FluidState.java
|
||||
+++ b/net/minecraft/world/level/material/FluidState.java
|
||||
@@ -167,6 +167,12 @@ public final class FluidState extends StateHolder<Fluid, FluidState> implements
|
||||
return this.owner.builtInRegistryHolder().tags();
|
||||
}
|
||||
|
||||
+ // Leaf start - Remove stream in updateFluidOnEyes
|
||||
+ public java.util.Set<TagKey<Fluid>> getTagsAsSet() {
|
||||
+ return this.owner.builtInRegistryHolder().tagsAsSet();
|
||||
+ }
|
||||
+ // Leaf end - Remove stream in updateFluidOnEyes
|
||||
+
|
||||
public void entityInside(Level level, BlockPos pos, Entity entity, InsideBlockEffectApplier effectApplier) {
|
||||
this.getType().entityInside(level, pos, entity, effectApplier);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Taiyou06 <kaandindar21@gmail.com>
|
||||
Date: Tue, 26 Nov 2024 19:58:29 -0500
|
||||
Subject: [PATCH] Remove stream in matchingSlot
|
||||
|
||||
|
||||
diff --git a/net/minecraft/world/item/enchantment/Enchantment.java b/net/minecraft/world/item/enchantment/Enchantment.java
|
||||
index 7a620eb92b1e672cedd72ec4d986c01eba337686..183874d90d576d740c5d924accc5c0d7fdb8450c 100644
|
||||
--- a/net/minecraft/world/item/enchantment/Enchantment.java
|
||||
+++ b/net/minecraft/world/item/enchantment/Enchantment.java
|
||||
@@ -126,7 +126,15 @@ public record Enchantment(Component description, Enchantment.EnchantmentDefiniti
|
||||
}
|
||||
|
||||
public boolean matchingSlot(EquipmentSlot slot) {
|
||||
- return this.definition.slots().stream().anyMatch(equipmentSlotGroup -> equipmentSlotGroup.test(slot));
|
||||
+ // Leaf start - Remove stream in matchingSlot
|
||||
+ for (EquipmentSlotGroup equipmentSlotGroup : this.definition.slots()) {
|
||||
+ if (equipmentSlotGroup.test(slot)) {
|
||||
+ return true;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ return false;
|
||||
+ // Leaf end - Remove stream in matchingSlot
|
||||
}
|
||||
|
||||
public boolean isPrimaryItem(ItemStack stack) {
|
||||
@@ -0,0 +1,41 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
|
||||
Date: Tue, 17 Sep 2024 02:35:13 -0400
|
||||
Subject: [PATCH] Replace Entity active effects map with optimized collection
|
||||
|
||||
Dreeam TODO: check this
|
||||
|
||||
diff --git a/net/minecraft/world/entity/LivingEntity.java b/net/minecraft/world/entity/LivingEntity.java
|
||||
index d55a701d1f9a39b4734c8b02b655e1f1a53e616b..82289f1b8b3097fe20c3508461c79ab42fbef0f6 100644
|
||||
--- a/net/minecraft/world/entity/LivingEntity.java
|
||||
+++ b/net/minecraft/world/entity/LivingEntity.java
|
||||
@@ -196,6 +196,10 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
||||
};
|
||||
private final AttributeMap attributes;
|
||||
public CombatTracker combatTracker = new CombatTracker(this);
|
||||
+ // Need to figure out the difference of mem access pattern between hash map and obj2obj hash map (separate chaining vs open addressing)
|
||||
+ // Benchmark is needed for get calls for this active effects map.
|
||||
+ // Also need to check whether call from out of main using bukkit api
|
||||
+ //public final Map<Holder<MobEffect>, MobEffectInstance> activeEffects = new it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<>(0); // Leaf - Replace Entity active effects map with optimized collection
|
||||
public final Map<Holder<MobEffect>, MobEffectInstance> activeEffects = Maps.newHashMap();
|
||||
private final Map<EquipmentSlot, ItemStack> lastEquipmentItems = Util.makeEnumMap(EquipmentSlot.class, slot -> ItemStack.EMPTY);
|
||||
public boolean swinging;
|
||||
@@ -977,15 +981,16 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
||||
private void updateSynchronizedMobEffectParticles() {
|
||||
// Leaf start - Remove stream in entity visible effects filter
|
||||
List<ParticleOptions> list = new ArrayList<>();
|
||||
+ final Collection<MobEffectInstance> effectsValues = this.activeEffects.values(); // Leaf - Replace Entity active effects map with optimized collection
|
||||
|
||||
- for (MobEffectInstance effect : this.activeEffects.values()) {
|
||||
+ for (MobEffectInstance effect : effectsValues) { // Leaf - Replace Entity active effects map with optimized collection
|
||||
if (effect.isVisible()) {
|
||||
list.add(effect.getParticleOptions());
|
||||
}
|
||||
}
|
||||
// Leaf end - Remove stream in entity visible effects filter
|
||||
this.entityData.set(DATA_EFFECT_PARTICLES, list);
|
||||
- this.entityData.set(DATA_EFFECT_AMBIENCE_ID, areAllEffectsAmbient(this.activeEffects.values()));
|
||||
+ this.entityData.set(DATA_EFFECT_AMBIENCE_ID, areAllEffectsAmbient(effectsValues)); // Leaf - Replace Entity active effects map with optimized collection
|
||||
}
|
||||
|
||||
private void updateGlowingStatus() {
|
||||
@@ -0,0 +1,19 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
|
||||
Date: Sat, 7 Sep 2024 02:12:55 -0400
|
||||
Subject: [PATCH] Replace criterion map with optimized collection
|
||||
|
||||
|
||||
diff --git a/net/minecraft/server/PlayerAdvancements.java b/net/minecraft/server/PlayerAdvancements.java
|
||||
index 741894ed6df81fce41d9f906d6198d038aab44a8..83ed64b9253f1fcde58267a510256cc18dfd8f8d 100644
|
||||
--- a/net/minecraft/server/PlayerAdvancements.java
|
||||
+++ b/net/minecraft/server/PlayerAdvancements.java
|
||||
@@ -60,7 +60,7 @@ public class PlayerAdvancements {
|
||||
private AdvancementHolder lastSelectedTab;
|
||||
private boolean isFirstPacket = true;
|
||||
private final Codec<PlayerAdvancements.Data> codec;
|
||||
- public final Map<net.minecraft.advancements.critereon.SimpleCriterionTrigger<?>, Set<CriterionTrigger.Listener<?>>> criterionData = new java.util.IdentityHashMap<>(); // Paper - fix advancement data player leakage
|
||||
+ public final Map<net.minecraft.advancements.critereon.SimpleCriterionTrigger<?>, Set<CriterionTrigger.Listener<?>>> criterionData = new it.unimi.dsi.fastutil.objects.Reference2ReferenceOpenHashMap<>(); // Paper - fix advancement data player leakage // Leaf - Replace criterion map with optimized collection
|
||||
|
||||
public PlayerAdvancements(DataFixer dataFixer, PlayerList playerList, ServerAdvancementManager manager, Path playerSavePath, ServerPlayer player) {
|
||||
this.playerList = playerList;
|
||||
@@ -0,0 +1,35 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com>
|
||||
Date: Sat, 26 Oct 2024 00:06:04 +0800
|
||||
Subject: [PATCH] Replace brain maps with optimized collection
|
||||
|
||||
|
||||
diff --git a/net/minecraft/world/entity/ai/Brain.java b/net/minecraft/world/entity/ai/Brain.java
|
||||
index 29fdf94db0308031edfe7915fc587a2aa5a1a18a..b946faf899561b9e4f8399e16600eede54bb55a5 100644
|
||||
--- a/net/minecraft/world/entity/ai/Brain.java
|
||||
+++ b/net/minecraft/world/entity/ai/Brain.java
|
||||
@@ -45,14 +45,18 @@ public class Brain<E extends LivingEntity> {
|
||||
static final Logger LOGGER = LogUtils.getLogger();
|
||||
private final Supplier<Codec<Brain<E>>> codec;
|
||||
private static final int SCHEDULE_UPDATE_DELAY = 20;
|
||||
- private final Map<MemoryModuleType<?>, Optional<? extends ExpirableValue<?>>> memories = Maps.newHashMap();
|
||||
- private final Map<SensorType<? extends Sensor<? super E>>, Sensor<? super E>> sensors = Maps.newLinkedHashMap();
|
||||
+ // Leaf start - Replace brain maps with optimized collection
|
||||
+ private final Map<MemoryModuleType<?>, Optional<? extends ExpirableValue<?>>> memories = new it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<>();
|
||||
+ private final Map<SensorType<? extends Sensor<? super E>>, Sensor<? super E>> sensors = new it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap<>();
|
||||
+ // Leaf end - Replace brain maps with optimized collection
|
||||
private final Map<Integer, Map<Activity, Set<BehaviorControl<? super E>>>> availableBehaviorsByPriority = Maps.newTreeMap();
|
||||
private Schedule schedule = Schedule.EMPTY;
|
||||
- private final Map<Activity, Set<Pair<MemoryModuleType<?>, MemoryStatus>>> activityRequirements = Maps.newHashMap();
|
||||
- private final Map<Activity, Set<MemoryModuleType<?>>> activityMemoriesToEraseWhenStopped = Maps.newHashMap();
|
||||
- private Set<Activity> coreActivities = Sets.newHashSet();
|
||||
- private final Set<Activity> activeActivities = Sets.newHashSet();
|
||||
+ // Leaf start - Replace brain maps with optimized collection
|
||||
+ private final Map<Activity, Set<Pair<MemoryModuleType<?>, MemoryStatus>>> activityRequirements = new it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<>();
|
||||
+ private final Map<Activity, Set<MemoryModuleType<?>>> activityMemoriesToEraseWhenStopped = new it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<>();
|
||||
+ private Set<Activity> coreActivities = new it.unimi.dsi.fastutil.objects.ObjectOpenHashSet<>();
|
||||
+ private final Set<Activity> activeActivities = new it.unimi.dsi.fastutil.objects.ObjectOpenHashSet<>();
|
||||
+ // Leaf end - Replace brain maps with optimized collection
|
||||
private Activity defaultActivity = Activity.IDLE;
|
||||
private long lastScheduleUpdate = -9999L;
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com>
|
||||
Date: Fri, 14 Jun 2024 23:19:55 +0800
|
||||
Subject: [PATCH] Reduce worldgen allocations
|
||||
|
||||
This change optimizes the way SurfaceRules update their biome supplier,avoiding unnecessary object creations and thus reducing memory allocations
|
||||
during world generation. The update method now reuses the existing PositionalBiomeGetter object if it's already present, otherwise it
|
||||
initializes a new one.
|
||||
Additionally, the tryApply method in SurfaceRules now avoids iterator
|
||||
allocation by directly accessing the rules list, which further contributes
|
||||
to reducing garbage collection pressure during world generation.
|
||||
|
||||
diff --git a/net/minecraft/world/level/levelgen/NoiseChunk.java b/net/minecraft/world/level/levelgen/NoiseChunk.java
|
||||
index f861f9e087182470a3bbb22678dbdacb8a73e943..a3d0d17178eedfaef83e2e0df6b1c2d7784d8656 100644
|
||||
--- a/net/minecraft/world/level/levelgen/NoiseChunk.java
|
||||
+++ b/net/minecraft/world/level/levelgen/NoiseChunk.java
|
||||
@@ -362,7 +362,17 @@ public class NoiseChunk implements DensityFunction.ContextProvider, DensityFunct
|
||||
}
|
||||
|
||||
protected DensityFunction wrap(DensityFunction densityFunction) {
|
||||
- return this.wrapped.computeIfAbsent(densityFunction, this::wrapNew);
|
||||
+ // Leaf start - Reduce worldgen allocations
|
||||
+ // Avoid lambda allocation
|
||||
+ DensityFunction func = this.wrapped.get(densityFunction);
|
||||
+
|
||||
+ if (func == null) {
|
||||
+ func = this.wrapNew(densityFunction);
|
||||
+ this.wrapped.put(densityFunction, func);
|
||||
+ }
|
||||
+
|
||||
+ return func;
|
||||
+ // Leaf end - Reduce worldgen allocations
|
||||
}
|
||||
|
||||
private DensityFunction wrapNew(DensityFunction densityFunction) {
|
||||
diff --git a/net/minecraft/world/level/levelgen/SurfaceRules.java b/net/minecraft/world/level/levelgen/SurfaceRules.java
|
||||
index 0948c8db90605a15a043b5c5bc74edecd7f9db1b..009e8a270c25614d03413d8b8b1f39c2da8ba12f 100644
|
||||
--- a/net/minecraft/world/level/levelgen/SurfaceRules.java
|
||||
+++ b/net/minecraft/world/level/levelgen/SurfaceRules.java
|
||||
@@ -313,8 +313,15 @@ public class SurfaceRules {
|
||||
}
|
||||
|
||||
protected void updateY(int stoneDepthAbove, int stoneDepthBelow, int waterHeight, int blockX, int blockY, int blockZ) {
|
||||
- this.lastUpdateY++;
|
||||
- this.biome = Suppliers.memoize(() -> this.biomeGetter.apply(this.pos.set(blockX, blockY, blockZ)));
|
||||
+ // Leaf start - Reduce worldgen allocations
|
||||
+ // Reuse supplier object instead of creating new ones every time
|
||||
+ ++this.lastUpdateY;
|
||||
+ Supplier<Holder<Biome>> getter = this.biome;
|
||||
+ if (getter == null) {
|
||||
+ this.biome = getter = new org.dreeam.leaf.util.biome.PositionalBiomeGetter(this.biomeGetter, this.pos);
|
||||
+ }
|
||||
+ ((org.dreeam.leaf.util.biome.PositionalBiomeGetter) getter).update(blockX, blockY, blockZ);
|
||||
+ // Leaf end - Reduce worldgen allocations
|
||||
this.blockY = blockY;
|
||||
this.waterHeight = waterHeight;
|
||||
this.stoneDepthBelow = stoneDepthBelow;
|
||||
@@ -582,8 +589,13 @@ public class SurfaceRules {
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockState tryApply(int x, int y, int z) {
|
||||
- for (SurfaceRules.SurfaceRule surfaceRule : this.rules) {
|
||||
- BlockState blockState = surfaceRule.tryApply(x, y, z);
|
||||
+ // Leaf start - Reduce worldgen allocations
|
||||
+ // Avoid iterator allocation
|
||||
+ int size = this.rules.size();
|
||||
+ //noinspection ForLoopReplaceableByForEach
|
||||
+ for (int i = 0; i < size; i++) {
|
||||
+ BlockState blockState = this.rules.get(i).tryApply(x, y, z);
|
||||
+ // Leaf end - Reduce worldgen allocations
|
||||
if (blockState != null) {
|
||||
return blockState;
|
||||
}
|
||||
diff --git a/net/minecraft/world/level/levelgen/material/MaterialRuleList.java b/net/minecraft/world/level/levelgen/material/MaterialRuleList.java
|
||||
index 1605cc013d5a89a5d3cb68365bdcc18e2dd0a921..a3b5f74b5f9a0f4e62dee67e50f51e9e6b78d7fd 100644
|
||||
--- a/net/minecraft/world/level/levelgen/material/MaterialRuleList.java
|
||||
+++ b/net/minecraft/world/level/levelgen/material/MaterialRuleList.java
|
||||
@@ -9,13 +9,17 @@ public record MaterialRuleList(NoiseChunk.BlockStateFiller[] materialRuleList) i
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockState calculate(DensityFunction.FunctionContext context) {
|
||||
- for (NoiseChunk.BlockStateFiller blockStateFiller : this.materialRuleList) {
|
||||
- BlockState blockState = blockStateFiller.calculate(context);
|
||||
- if (blockState != null) {
|
||||
- return blockState;
|
||||
- }
|
||||
+ // Leaf start - Reduce worldgen allocations
|
||||
+ // Avoid iterator allocation
|
||||
+ BlockState blockState = null;
|
||||
+ int length = this.materialRuleList.length;
|
||||
+
|
||||
+ for (int i = 0; blockState == null && i < length; i++) {
|
||||
+ NoiseChunk.BlockStateFiller blockStateFiller = this.materialRuleList[i];
|
||||
+ blockState = blockStateFiller.calculate(context);
|
||||
}
|
||||
|
||||
- return null;
|
||||
+ return blockState;
|
||||
+ // Leaf end - Reduce worldgen allocations
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user