mirror of
https://github.com/Dreeam-qwq/Gale.git
synced 2025-12-21 15:59:28 +00:00
159 lines
10 KiB
Diff
159 lines
10 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/src/main/java/net/minecraft/server/commands/SpreadPlayersCommand.java b/src/main/java/net/minecraft/server/commands/SpreadPlayersCommand.java
|
|
index 23dcdc71a8a6fd5472cdc1c22331b56c6bb3ded9..c3f88980f1ea2f7b04ad110494962725274d25a4 100644
|
|
--- a/src/main/java/net/minecraft/server/commands/SpreadPlayersCommand.java
|
|
+++ b/src/main/java/net/minecraft/server/commands/SpreadPlayersCommand.java
|
|
@@ -65,7 +65,7 @@ public class SpreadPlayersCommand {
|
|
if (maxY < j) {
|
|
throw SpreadPlayersCommand.ERROR_INVALID_MAX_HEIGHT.create(maxY, j);
|
|
} else {
|
|
- RandomSource randomsource = RandomSource.create();
|
|
+ RandomSource randomsource = source.getLevel().random; // Gale - Patina - reduce RandomSource instances
|
|
double d0 = (double) (center.x - maxRange);
|
|
double d1 = (double) (center.y - maxRange);
|
|
double d2 = (double) (center.x + maxRange);
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
index 9d74ef6973f6a9e12861256aa7032f8d746a97f5..6ed357bff6cafce563774ca2f5e2944bcdfb7f92 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
@@ -391,7 +391,7 @@ public class ServerPlayer extends Player {
|
|
long l = k * k;
|
|
int i1 = l > 2147483647L ? Integer.MAX_VALUE : (int) l;
|
|
int j1 = this.getCoprime(i1);
|
|
- int k1 = RandomSource.create().nextInt(i1);
|
|
+ int k1 = worldserver.random.nextInt(i1); // Gale - Patina - reduce RandomSource instances
|
|
|
|
for (int l1 = 0; l1 < i1; ++l1) {
|
|
int i2 = (k1 + j1 * l1) % i1;
|
|
@@ -428,7 +428,7 @@ public class ServerPlayer extends Player {
|
|
long l = k * k;
|
|
int i1 = l > 2147483647L ? Integer.MAX_VALUE : (int) l;
|
|
int j1 = this.getCoprime(i1);
|
|
- int k1 = RandomSource.create().nextInt(i1);
|
|
+ int k1 = world.random.nextInt(i1); // Gale - Patina - reduce RandomSource instances
|
|
|
|
for (int l1 = 0; l1 < i1; ++l1) {
|
|
int i2 = (k1 + j1 * l1) % i1;
|
|
diff --git a/src/main/java/net/minecraft/server/rcon/thread/QueryThreadGs4.java b/src/main/java/net/minecraft/server/rcon/thread/QueryThreadGs4.java
|
|
index 1ef089dbf83de35d875c00efdf468c397be56978..b9f5dc95f859acb8f8fd4739537485af7187ae3b 100644
|
|
--- a/src/main/java/net/minecraft/server/rcon/thread/QueryThreadGs4.java
|
|
+++ b/src/main/java/net/minecraft/server/rcon/thread/QueryThreadGs4.java
|
|
@@ -349,7 +349,7 @@ public class QueryThreadGs4 extends GenericThread {
|
|
this.identBytes[2] = bs[5];
|
|
this.identBytes[3] = bs[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/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java b/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java
|
|
index 7f3a7a769afec8449547c26453112064b9bcb04a..3da68454b8114cd52554670280107d5b5b156eab 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java
|
|
@@ -80,7 +80,7 @@ public class FishingHook extends Projectile {
|
|
|
|
private FishingHook(EntityType<? extends FishingHook> type, Level world, int luckOfTheSeaLevel, int lureLevel) {
|
|
super(type, world);
|
|
- this.syncronizedRandom = RandomSource.create();
|
|
+ this.syncronizedRandom = world.random; // Gale - Patina - reduce RandomSource instances
|
|
this.openWater = true;
|
|
this.currentState = FishingHook.FishHookState.FLYING;
|
|
this.noCulling = true;
|
|
diff --git a/src/main/java/net/minecraft/world/entity/raid/Raid.java b/src/main/java/net/minecraft/world/entity/raid/Raid.java
|
|
index b13ef853419d2783d09b3e685b9b506a4ff5676e..7a7e87954868c3eb267d3255652d67d34f7b04d2 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/raid/Raid.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/raid/Raid.java
|
|
@@ -111,7 +111,7 @@ public class Raid {
|
|
|
|
public Raid(int id, ServerLevel world, BlockPos pos) {
|
|
this.raidEvent = new ServerBossEvent(Raid.RAID_NAME_COMPONENT, BossEvent.BossBarColor.RED, BossEvent.BossBarOverlay.NOTCHED_10);
|
|
- this.random = RandomSource.create();
|
|
+ this.random = world.random; // Gale - Patina - reduce RandomSource instances
|
|
this.waveSpawnPos = Optional.empty();
|
|
this.id = id;
|
|
this.level = world;
|
|
@@ -125,7 +125,7 @@ public class Raid {
|
|
|
|
public Raid(ServerLevel world, CompoundTag nbt) {
|
|
this.raidEvent = new ServerBossEvent(Raid.RAID_NAME_COMPONENT, BossEvent.BossBarColor.RED, BossEvent.BossBarOverlay.NOTCHED_10);
|
|
- this.random = RandomSource.create();
|
|
+ this.random = world.random; // Gale - Patina - reduce RandomSource instances
|
|
this.waveSpawnPos = Optional.empty();
|
|
this.level = world;
|
|
this.id = nbt.getInt("Id");
|
|
diff --git a/src/main/java/net/minecraft/world/level/Explosion.java b/src/main/java/net/minecraft/world/level/Explosion.java
|
|
index d3ade2eb7c492cd8fdb24c78fa2886db8986fc09..b6e537dd77f2eda819b00962284f36546a2bd158 100644
|
|
--- a/src/main/java/net/minecraft/world/level/Explosion.java
|
|
+++ b/src/main/java/net/minecraft/world/level/Explosion.java
|
|
@@ -81,7 +81,7 @@ public class Explosion {
|
|
}
|
|
|
|
public Explosion(Level world, @Nullable Entity entity, @Nullable DamageSource damageSource, @Nullable ExplosionDamageCalculator behavior, double x, double y, double z, float power, boolean createFire, Explosion.BlockInteraction destructionType) {
|
|
- this.random = RandomSource.create();
|
|
+ this.random = world == null || world.random == null ? RandomSource.create() : world.random; // Gale - Patina - reduce RandomSource instances
|
|
this.toBlow = new ObjectArrayList();
|
|
this.hitPlayers = Maps.newHashMap();
|
|
this.level = world;
|
|
diff --git a/src/main/java/net/minecraft/world/level/block/entity/TheEndGatewayBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/TheEndGatewayBlockEntity.java
|
|
index 2a596cc374206a85bb692f5e09ee2dd83cf6d1b1..74686aa52113fcd0cbd5531e4161f6a1993dba60 100644
|
|
--- a/src/main/java/net/minecraft/world/level/block/entity/TheEndGatewayBlockEntity.java
|
|
+++ b/src/main/java/net/minecraft/world/level/block/entity/TheEndGatewayBlockEntity.java
|
|
@@ -361,7 +361,7 @@ public class TheEndGatewayBlockEntity extends TheEndPortalBlockEntity {
|
|
}
|
|
|
|
private static void spawnGatewayPortal(ServerLevel world, BlockPos pos, EndGatewayConfiguration config) {
|
|
- Feature.END_GATEWAY.place(config, world, world.getChunkSource().getGenerator(), RandomSource.create(), pos);
|
|
+ Feature.END_GATEWAY.place(config, world, world.getChunkSource().getGenerator(), world.random, pos); // Gale - Patina - reduce RandomSource instances
|
|
}
|
|
|
|
@Override
|
|
diff --git a/src/main/java/net/minecraft/world/level/dimension/end/EndDragonFight.java b/src/main/java/net/minecraft/world/level/dimension/end/EndDragonFight.java
|
|
index e9eb32469a5c03f7a3677ef50fd4541c1ed662ad..dc0eb8eb2bf39e33bdee4daa3647510d24535091 100644
|
|
--- a/src/main/java/net/minecraft/world/level/dimension/end/EndDragonFight.java
|
|
+++ b/src/main/java/net/minecraft/world/level/dimension/end/EndDragonFight.java
|
|
@@ -411,7 +411,7 @@ public class EndDragonFight {
|
|
this.level.registryAccess().registry(Registries.CONFIGURED_FEATURE).flatMap((registry) -> {
|
|
return registry.getHolder(EndFeatures.END_GATEWAY_DELAYED);
|
|
}).ifPresent((reference) -> {
|
|
- reference.value().place(this.level, this.level.getChunkSource().getGenerator(), RandomSource.create(), pos);
|
|
+ reference.value().place(this.level, this.level.getChunkSource().getGenerator(), this.level.random, pos); // Gale - Patina - reduce RandomSource instances
|
|
});
|
|
}
|
|
|
|
@@ -427,7 +427,7 @@ public class EndDragonFight {
|
|
this.portalLocation = this.portalLocation.atY(this.level.getMinBuildHeight() + 1);
|
|
}
|
|
// Paper end
|
|
- endPodiumFeature.place(FeatureConfiguration.NONE, this.level, this.level.getChunkSource().getGenerator(), RandomSource.create(), this.portalLocation);
|
|
+ endPodiumFeature.place(FeatureConfiguration.NONE, this.level, this.level.getChunkSource().getGenerator(), this.level.random, this.portalLocation); // Gale - Patina - reduce RandomSource instances
|
|
}
|
|
|
|
@Nullable
|
|
diff --git a/src/main/java/net/minecraft/world/level/storage/loot/LootContext.java b/src/main/java/net/minecraft/world/level/storage/loot/LootContext.java
|
|
index eb399244af70c8fe735657d429d883c48215af0a..e78a8d68c4af056af9e1452f76651fea545189ba 100644
|
|
--- a/src/main/java/net/minecraft/world/level/storage/loot/LootContext.java
|
|
+++ b/src/main/java/net/minecraft/world/level/storage/loot/LootContext.java
|
|
@@ -202,7 +202,7 @@ public class LootContext {
|
|
} else {
|
|
RandomSource randomSource = this.random;
|
|
if (randomSource == null) {
|
|
- randomSource = RandomSource.create();
|
|
+ randomSource = level.random; // Gale - Patina - reduce RandomSource instances
|
|
}
|
|
|
|
MinecraftServer minecraftServer = this.level.getServer();
|