mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-26 18:39:23 +00:00
ClassInstanceMultiMap belongs to Minecraft vanilla entity storage. And is unused, since replaced by spottedleaf's entity storage (rewrite chunk system). However these patches might be useful for vanilla entity storage if is used.
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/ServerPlayer.java b/net/minecraft/server/level/ServerPlayer.java
|
|
index bbe123fd18fe97ae93bf562f32af73cdde722f70..feb4f7c70220e9c48a17a815631298bcb8366ded 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 5f3abbe943be394e9cb987945a238208940b5015..5b831ecd8f094bcae2ff50b96ccfc0d75b43a495 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 afcf185c4e2c0648c96a872fbe1fbebb6012d513..aaa990b01e886812cc1dbad819e922b23d08889c 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 c8b577a5d5f059aed368fa082bc4518cc2dbd0b0..ac5ab4ae88c8188635f5784a10002a6cdcad49b6 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 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);
|