mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-19 15:09:25 +00:00
Upstream has released updates that appear to apply and compile correctly Paper Changes: PaperMC/Paper@51345a1c Correct nullable fall location type PaperMC/Paper@93246a07 Fix errors when loading raid files without a PDC PaperMC/Paper@cb3ffd0b Don't store empty PDCs on raids PaperMC/Paper@d637ae85 Fix NoSuchElementException in EntityTransformEvent for slimes (#12510) PaperMC/Paper@10742373 Pass correct draw strength for EntityShootBowEvent (#12308) PaperMC/Paper@825685f8 Add PlayerPickBlockEvent and PlayerPickEntityEvent (#12425) PaperMC/Paper@2bd84f6f Expand PotionMeta Api to allow getting effective potion colour and effects (#12390) PaperMC/Paper@6f1f5b67 Fix ArmorStand items for canceled EntityDeathEvent (#12288)
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 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 08a4454a8dbbd75b60b8aaeafc03d2323a583c12..29e61a4cc550e4a627f4da99d116da5d4af9a45d 100644
|
|
--- a/net/minecraft/server/level/ServerPlayer.java
|
|
+++ b/net/minecraft/server/level/ServerPlayer.java
|
|
@@ -496,7 +496,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 9476a33ff4ec272a2c3b3cf9685cb4653138c57e..1ecfcb37a0d1c3f3810c5c8ce8043626ce8c25a9 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);
|