mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-19 15:09:25 +00:00
141 lines
8.6 KiB
Diff
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 92a820d48057ffe2ef35919341b6cdf605ca939e..b9b1bf351070cd2a744cdb683974fb2aa048d0d2 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/PlayerSpawnFinder.java b/net/minecraft/server/level/PlayerSpawnFinder.java
|
|
index 85a3c9c5fa59f336a687a1029a7fc8160e9777aa..064672576fdbc032566b8c8ec24ebde0b53db803 100644
|
|
--- a/net/minecraft/server/level/PlayerSpawnFinder.java
|
|
+++ b/net/minecraft/server/level/PlayerSpawnFinder.java
|
|
@@ -44,7 +44,7 @@ public class PlayerSpawnFinder {
|
|
long l = radius * 2L + 1L;
|
|
this.candidateCount = (int)Math.min(1024L, l * l);
|
|
this.coprime = getCoprime(this.candidateCount);
|
|
- this.offset = RandomSource.create().nextInt(this.candidateCount);
|
|
+ this.offset = level.random.nextInt(this.candidateCount); // Gale - Patina - reduce RandomSource instances
|
|
}
|
|
|
|
public static CompletableFuture<Vec3> findSpawn(ServerLevel level, BlockPos pos) {
|
|
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 89767d2e8b2438db0f9bfe3504e637934725e995..7d310e21e226a0459e494e96baee2eed4a03f025 100644
|
|
--- a/net/minecraft/world/entity/projectile/FishingHook.java
|
|
+++ b/net/minecraft/world/entity/projectile/FishingHook.java
|
|
@@ -51,7 +51,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;
|
|
@@ -90,6 +90,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 dcfade2efe209b87a169738fc2ff23d8e24b53a6..7a1b00de908a495b8d5bf819bac937bcbba946e5 100644
|
|
--- a/net/minecraft/world/entity/raid/Raid.java
|
|
+++ b/net/minecraft/world/entity/raid/Raid.java
|
|
@@ -123,7 +123,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;
|
|
@@ -530,7 +530,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();
|
|
@@ -554,7 +554,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 150b30d0cb17ebd9517b89e14065de64d2609d41..11c8f959fd323254a4ae01838a641adfe3d51a3d 100644
|
|
--- a/net/minecraft/world/level/block/entity/TheEndGatewayBlockEntity.java
|
|
+++ b/net/minecraft/world/level/block/entity/TheEndGatewayBlockEntity.java
|
|
@@ -248,7 +248,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 7f9bd256da15da915db1c45099572d9eb3286166..62ffb8e88b76f9765283d40d5ddcd9320063ca55 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);
|