9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-19 15:09:25 +00:00
Files
Leaf/leaf-server/minecraft-patches/features/0092-Reduce-RandomSource-instances.patch
Dreeam 5ddabb083e Updated Upstream (Paper/Purpur)
Upstream has released updates that appear to apply and compile correctly

Paper Changes:
PaperMC/Paper@88a3a870 Configurable xp orb merge group count (#12503)
PaperMC/Paper@53d1d04e Disable Item Obfuscation for entity related stacks (#12297)
PaperMC/Paper@c98cd658 Add configuration interface to expose certain config values (#12273)
PaperMC/Paper@42a2a6c2 Supports the ability for commands to be registered internally (#12520)
PaperMC/Paper@753cff7c Improvements for Dump paper commands (#12512)
PaperMC/Paper@e2da5d2f Registry API for supported Mob Variants (#12417)
PaperMC/Paper@ab0253fe Expand PlayerDeathEvent API (#12221)
PaperMC/Paper@cbcf75a5 Update visual fire handling with TriState support (#12303)
PaperMC/Paper@6c3964d2 Properly save level data async (#12530)
PaperMC/Paper@d2ad2e66 Add missing EntityLookup#getAllMapped from Moonrise
PaperMC/Paper@358e72ec Remove simplify remote item matching stuff for now
PaperMC/Paper@04ffca0b Also remove CraftPlayer methods
PaperMC/Paper@a2525819 Update mache
PaperMC/Paper@d683970d Add FishHookStateChangeEvent (#12165)
PaperMC/Paper@369ad170 Cached tag parser for itemstack reading (#12547)
PaperMC/Paper@841d6342 Fix ItemStack#addUnsafeEnchantment ignored for missing enchantment component (#12549)
PaperMC/Paper@c000b352 fix(bukkit-brig-forwarding-map): Invert isEmpty method (#12555)
PaperMC/Paper@28d7df75 Backport HeroesOfTheVillage datafixer fix
PaperMC/Paper@f1dbed07 Implement BlocksAttack DamageReduction and ItemDamage (#12538)
PaperMC/Paper@cc38032b Deprecate TeleportCause CHORUS_FRUIT for CONSUMABLE_EFFECT (#12546)
PaperMC/Paper@35878677 [ci/skip] Fix format and mentions for ItemDamageFunction (#12560)
PaperMC/Paper@7171d299 [ci/skip] Mention CAN_PLACE/CAN_BREAK component in ItemMeta (#12559)
PaperMC/Paper@6f73e62e Add getPickItemStack (#12552)
PaperMC/Paper@ce0fa4c4 Replace old version command with brigadier equivalent (#12502)
PaperMC/Paper@fa360aa8 Add some missing annotations and an incorrect one (#12204)
PaperMC/Paper@113b18ee Update paperweight and Gradle wrapper (#12573)
PaperMC/Paper@f303a076 fix: Don't hardcode checks for translation registries (#12571)
PaperMC/Paper@87349c31 Fix CombatTracker stale on death (#12562)
PaperMC/Paper@b70bca6b Revert "fix: Don't hardcode checks for translation registries (#12571)"

Purpur Changes:
PurpurMC/Purpur@93011bc1 Add configuration setting to re-add End void rings (#1656)
PurpurMC/Purpur@c2f48591 [ci/skip] only set default world config values once
PurpurMC/Purpur@6f5bbae5 [ci/skip] move some code around
PurpurMC/Purpur@5c1a9835 fix issue with `shift-right-click-repairs-mending-points`
PurpurMC/Purpur@3156e446 check damage value of tool correctly
PurpurMC/Purpur@a9fe4f25 Updated Upstream (Paper)
PurpurMC/Purpur@9d0aa8eb Updated Upstream (Paper)
PurpurMC/Purpur@603c7557 Updated Upstream (Paper)
PurpurMC/Purpur@eca78060 Updated Upstream (Paper)
PurpurMC/Purpur@e4e9cfdf Updated Upstream (Paper)
PurpurMC/Purpur@3de2fc7d Updated Upstream (Paper)
PurpurMC/Purpur@09f547de add `mob-griefing-override` config options (#1661)
PurpurMC/Purpur@1dd9bd0c Updated Upstream (Paper)
PurpurMC/Purpur@7a8aa86a finish updating gradle
PurpurMC/Purpur@fd78b90f bandaid fix: increase the daemon heap for now
2025-05-24 22:06:41 +08:00

141 lines
8.6 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martijn Muijsers <martijnmuijsers@live.nl>
Date: Tue, 29 Nov 2022 00:45:45 +0100
Subject: [PATCH] Reduce RandomSource instances
License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
Gale - https://galemc.org
This patch is based on the following patch:
"don't create new random instance"
By: foss-mc <69294560+foss-mc@users.noreply.github.com>
As part of: Patina (https://github.com/PatinaMC/Patina)
Licensed under: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
diff --git a/net/minecraft/server/commands/SpreadPlayersCommand.java b/net/minecraft/server/commands/SpreadPlayersCommand.java
index d381800ad054be6b054dcca43fbe80d3f0c0c771..5904b9d985487ff8bd1f330667c43096aa298b98 100644
--- a/net/minecraft/server/commands/SpreadPlayersCommand.java
+++ b/net/minecraft/server/commands/SpreadPlayersCommand.java
@@ -107,7 +107,7 @@ public class SpreadPlayersCommand {
if (maxHeight < minY) {
throw ERROR_INVALID_MAX_HEIGHT.create(maxHeight, minY);
} else {
- RandomSource randomSource = RandomSource.create();
+ RandomSource randomSource = source.getLevel().random; // Gale - Patina - reduce RandomSource instances
double d = center.x - maxRange;
double d1 = center.y - maxRange;
double d2 = center.x + maxRange;
diff --git a/net/minecraft/server/level/ServerPlayer.java b/net/minecraft/server/level/ServerPlayer.java
index f1fb5a87844ca7fb1de6afc532e7e0b058e6f580..7f18fb7f61e9219eb23073d9215f3bd6c57dc320 100644
--- a/net/minecraft/server/level/ServerPlayer.java
+++ b/net/minecraft/server/level/ServerPlayer.java
@@ -488,7 +488,7 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
long l1 = l * l;
int i = l1 > 2147483647L ? Integer.MAX_VALUE : (int)l1;
int coprime = this.getCoprime(i);
- int randomInt = RandomSource.create().nextInt(i);
+ int randomInt = level.random.nextInt(i); // Gale - Patina - reduce RandomSource instances
for (int i1 = 0; i1 < i; i1++) {
int i2 = (randomInt + coprime * i1) % i;
diff --git a/net/minecraft/server/rcon/thread/QueryThreadGs4.java b/net/minecraft/server/rcon/thread/QueryThreadGs4.java
index 0b8d279a53196f3998b1f6901738ca8e02ef7311..9add567d2ec2f5e9cd5bee84423c5a44433fe188 100644
--- a/net/minecraft/server/rcon/thread/QueryThreadGs4.java
+++ b/net/minecraft/server/rcon/thread/QueryThreadGs4.java
@@ -341,7 +341,7 @@ public class QueryThreadGs4 extends GenericThread {
this.identBytes[2] = data[5];
this.identBytes[3] = data[6];
this.ident = new String(this.identBytes, StandardCharsets.UTF_8);
- this.challenge = RandomSource.create().nextInt(16777216);
+ this.challenge = java.util.concurrent.ThreadLocalRandom.current().nextInt(16777216); // Gale - Patina - reduce RandomSource instances
this.challengeBytes = String.format(Locale.ROOT, "\t%s%d\u0000", this.ident, this.challenge).getBytes(StandardCharsets.UTF_8);
}
diff --git a/net/minecraft/world/entity/projectile/FishingHook.java b/net/minecraft/world/entity/projectile/FishingHook.java
index ca5cd9354d53c6c05bd7ba50c6e1dbd1ed548f67..6cfd384aea8c8e90b4e4ae08ece86d52640c95d7 100644
--- a/net/minecraft/world/entity/projectile/FishingHook.java
+++ b/net/minecraft/world/entity/projectile/FishingHook.java
@@ -48,7 +48,7 @@ import org.slf4j.Logger;
public class FishingHook extends Projectile {
private static final Logger LOGGER = LogUtils.getLogger();
- private final RandomSource syncronizedRandom = RandomSource.create();
+ private final RandomSource syncronizedRandom; // Gale - Patina - reduce RandomSource instances
private boolean biting;
public int outOfWaterTime;
private static final int MAX_OUT_OF_WATER_TIME = 10;
@@ -86,6 +86,7 @@ public class FishingHook extends Projectile {
this.minWaitTime = level.paperConfig().fishingTimeRange.minimum;
this.maxWaitTime = level.paperConfig().fishingTimeRange.maximum;
// Paper end - Configurable fishing time ranges
+ this.syncronizedRandom = level.random; // Gale - Patina - reduce RandomSource instances
}
public FishingHook(EntityType<? extends FishingHook> entityType, Level level) {
diff --git a/net/minecraft/world/entity/raid/Raid.java b/net/minecraft/world/entity/raid/Raid.java
index 71166fbf93d62e8e1bff3db8161932ee2fc5ea86..c7ca8a71070f15c573a5748f1df9810af23febdb 100644
--- a/net/minecraft/world/entity/raid/Raid.java
+++ b/net/minecraft/world/entity/raid/Raid.java
@@ -121,7 +121,7 @@ public class Raid {
public final ServerBossEvent raidEvent = new ServerBossEvent(RAID_NAME_COMPONENT, BossEvent.BossBarColor.RED, BossEvent.BossBarOverlay.NOTCHED_10);
private int postRaidTicks;
private int raidCooldownTicks;
- private final RandomSource random = RandomSource.create();
+ //private final RandomSource random = RandomSource.create(); // Gale - Patina - reduce RandomSource instances
public final int numGroups;
private Raid.RaidStatus status;
private int celebrationTicks;
@@ -508,7 +508,7 @@ public class Raid {
float f = 13.0F;
int i = 64;
Collection<ServerPlayer> players = this.raidEvent.getPlayers();
- long randomLong = this.random.nextLong();
+ long randomLong = level.random.nextLong(); // Gale - Patina - reduce RandomSource instances
for (ServerPlayer serverPlayer : level.players()) {
Vec3 vec3 = serverPlayer.position();
@@ -532,7 +532,7 @@ public class Raid {
for (Raid.RaiderType raiderType : Raid.RaiderType.VALUES) {
int i1 = this.getDefaultNumSpawns(raiderType, i, shouldSpawnBonusGroup)
- + this.getPotentialBonusSpawns(raiderType, this.random, i, currentDifficultyAt, shouldSpawnBonusGroup);
+ + this.getPotentialBonusSpawns(raiderType, level.random, i, currentDifficultyAt, shouldSpawnBonusGroup); // Gale - Patina - reduce RandomSource instances
int i2 = 0;
for (int i3 = 0; i3 < i1; i3++) {
diff --git a/net/minecraft/world/level/block/entity/TheEndGatewayBlockEntity.java b/net/minecraft/world/level/block/entity/TheEndGatewayBlockEntity.java
index 8bb0926130a14351507b2b74feca42278c080381..f7884610d5a94bb1680c1ec8bd4f3ec917b8bc8a 100644
--- a/net/minecraft/world/level/block/entity/TheEndGatewayBlockEntity.java
+++ b/net/minecraft/world/level/block/entity/TheEndGatewayBlockEntity.java
@@ -246,7 +246,7 @@ public class TheEndGatewayBlockEntity extends TheEndPortalBlockEntity {
}
private static void spawnGatewayPortal(ServerLevel level, BlockPos pos, EndGatewayConfiguration config) {
- Feature.END_GATEWAY.place(config, level, level.getChunkSource().getGenerator(), RandomSource.create(), pos);
+ Feature.END_GATEWAY.place(config, level, level.getChunkSource().getGenerator(), level.random, pos); // Gale - Patina - reduce RandomSource instances
}
@Override
diff --git a/net/minecraft/world/level/dimension/end/EndDragonFight.java b/net/minecraft/world/level/dimension/end/EndDragonFight.java
index 8ccd40c70e150bd5a8d89818c229258642f2349e..75d7ea8e6d5c8c707444c0db644d54707ca6ef29 100644
--- a/net/minecraft/world/level/dimension/end/EndDragonFight.java
+++ b/net/minecraft/world/level/dimension/end/EndDragonFight.java
@@ -433,7 +433,7 @@ public class EndDragonFight {
.registryAccess()
.lookup(Registries.CONFIGURED_FEATURE)
.flatMap(registry -> registry.get(EndFeatures.END_GATEWAY_DELAYED))
- .ifPresent(endGatewayFeature -> endGatewayFeature.value().place(this.level, this.level.getChunkSource().getGenerator(), RandomSource.create(), pos));
+ .ifPresent(endGatewayFeature -> endGatewayFeature.value().place(this.level, this.level.getChunkSource().getGenerator(), this.level.random, pos)); // Gale - Patina - reduce RandomSource instances
}
public void spawnExitPortal(boolean active) {
@@ -454,7 +454,7 @@ public class EndDragonFight {
}
// Paper end - Prevent "softlocked" exit portal generation
if (endPodiumFeature.place(
- FeatureConfiguration.NONE, this.level, this.level.getChunkSource().getGenerator(), RandomSource.create(), this.portalLocation
+ FeatureConfiguration.NONE, this.level, this.level.getChunkSource().getGenerator(), this.level.random, this.portalLocation // Gale - Patina - reduce RandomSource instances
)) {
int i = Mth.positiveCeilDiv(4, 16);
this.level.getChunkSource().chunkMap.waitForLightBeforeSending(new ChunkPos(this.portalLocation), i);