Yatopia/patches/server/0061-Use-faster-random-implementation.patch
Ivan Pekov ea14d2c947
Updated Upstream and Sidestream(s) (Tuinity)
Upstream/An Sidestream has released updates that appears to apply and compile correctly
This update has NOT been tested by YatopiaMC and as with ANY update, please do your own testing.

Tuinity Changes:
076174a Updated Upstream (Paper)
2021-01-04 10:38:27 +02:00

306 lines
19 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Mykyta Komarnytskyy <nkomarn@hotmail.com>
Date: Fri, 27 Nov 2020 10:33:59 -0600
Subject: [PATCH] Use faster random implementation
Replace usages of random in world and entity classes with FastRandom, an adapter for XoRoShiRo128PlusPlus. This nearly doubles random performance across the board.
diff --git a/src/main/java/com/destroystokyo/paper/loottable/PaperLootableInventoryData.java b/src/main/java/com/destroystokyo/paper/loottable/PaperLootableInventoryData.java
index b5401eaf974857455c17c3f9cfdedf2eb4bde321..ec7ce458159e04b4d2bfda8fbb9b6974595747a6 100644
--- a/src/main/java/com/destroystokyo/paper/loottable/PaperLootableInventoryData.java
+++ b/src/main/java/com/destroystokyo/paper/loottable/PaperLootableInventoryData.java
@@ -13,7 +13,7 @@ import java.util.UUID;
public class PaperLootableInventoryData {
- private static final Random RANDOM = new Random();
+ private static final Random RANDOM = new org.yatopiamc.yatopia.server.util.FastRandom(); //Yatopia Faster Random
private long lastFill = -1;
private long nextRefill = -1;
diff --git a/src/main/java/net/minecraft/server/CommandSpreadPlayers.java b/src/main/java/net/minecraft/server/CommandSpreadPlayers.java
index c9f4b69874e693c8e5c3346f09db7b5014dcfb63..e0101b688337d863ee873301368dcaced630d127 100644
--- a/src/main/java/net/minecraft/server/CommandSpreadPlayers.java
+++ b/src/main/java/net/minecraft/server/CommandSpreadPlayers.java
@@ -37,7 +37,7 @@ public class CommandSpreadPlayers {
}
private static int a(CommandListenerWrapper commandlistenerwrapper, Vec2F vec2f, float f, float f1, int i, boolean flag, Collection<? extends Entity> collection) throws CommandSyntaxException {
- Random random = new Random();
+ Random random = new org.yatopiamc.yatopia.server.util.FastRandom(); //Yatopia Faster Random
double d0 = (double) (vec2f.i - f1);
double d1 = (double) (vec2f.j - f1);
double d2 = (double) (vec2f.i + f1);
diff --git a/src/main/java/net/minecraft/server/ContainerEnchantTable.java b/src/main/java/net/minecraft/server/ContainerEnchantTable.java
index 73bff2ca1f09cf6f33479f175cae72e456e8db4b..8a09aa82d97b5096e62995bc3903e15a623c15ad 100644
--- a/src/main/java/net/minecraft/server/ContainerEnchantTable.java
+++ b/src/main/java/net/minecraft/server/ContainerEnchantTable.java
@@ -52,7 +52,7 @@ public class ContainerEnchantTable extends Container {
}
// CraftBukkit end
};
- this.h = new Random();
+ this.h = new org.yatopiamc.yatopia.server.util.FastRandom(); //Yatopia Faster Random
this.i = ContainerProperty.a();
this.costs = new int[3];
this.enchantments = new int[]{-1, -1, -1};
diff --git a/src/main/java/net/minecraft/server/EnderDragonBattle.java b/src/main/java/net/minecraft/server/EnderDragonBattle.java
index 38dc6086d18951e065d4048d1d8eee288c5c5fd1..4e094f0e1117cecbd39be645997eb9d3080c666f 100644
--- a/src/main/java/net/minecraft/server/EnderDragonBattle.java
+++ b/src/main/java/net/minecraft/server/EnderDragonBattle.java
@@ -73,7 +73,7 @@ public class EnderDragonBattle {
}
} else {
this.gateways.addAll(ContiguousSet.create(Range.closedOpen(0, 20), DiscreteDomain.integers()));
- Collections.shuffle(this.gateways, new Random(i));
+ Collections.shuffle(this.gateways, new org.yatopiamc.yatopia.server.util.FastRandom(i)); // Yatopia - fast random
}
this.f = ShapeDetectorBuilder.a().a(" ", " ", " ", " # ", " ", " ", " ").a(" ", " ", " ", " # ", " ", " ", " ").a(" ", " ", " ", " # ", " ", " ", " ").a(" ### ", " # # ", "# #", "# # #", "# #", " # # ", " ### ").a(" ", " ### ", " ##### ", " ##### ", " ##### ", " ### ", " ").a('#', ShapeDetectorBlock.a(BlockPredicate.a(Blocks.BEDROCK))).b();
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
index 540bd5ccb01789d9130ea64a78dc125f94f94bb6..cbf9c61d535f1f99f08b1ee71a890a74d7f6d834 100644
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
@@ -61,7 +61,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
// Paper start
boolean isQueuedForRegister = false;
- public static Random SHARED_RANDOM = new Random() {
+ public static Random SHARED_RANDOM = new org.yatopiamc.yatopia.server.util.FastRandom() { //Yatopia Faster Random
private boolean locked = false;
@Override
public synchronized void setSeed(long seed) {
diff --git a/src/main/java/net/minecraft/server/EntityFishingHook.java b/src/main/java/net/minecraft/server/EntityFishingHook.java
index 6891e61bcfea82958e100abaef94865bf36a32c2..32ccc08455a88c510fe05713c8de7a5eed85e70b 100644
--- a/src/main/java/net/minecraft/server/EntityFishingHook.java
+++ b/src/main/java/net/minecraft/server/EntityFishingHook.java
@@ -38,7 +38,7 @@ public class EntityFishingHook extends IProjectile {
private EntityFishingHook(World world, EntityHuman entityhuman, int i, int j) {
super(EntityTypes.FISHING_BOBBER, world);
- this.b = new Random();
+ this.b = new org.yatopiamc.yatopia.server.util.FastRandom(); //Yatopia Faster Random
this.ak = true;
this.am = EntityFishingHook.HookState.FLYING;
this.Y = true;
diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java
index bb8c5ba0eccc2633652f662bb7fe2dcae2f2db18..42c6d26131fa144707e0ecb244a8a3b26a19a383 100644
--- a/src/main/java/net/minecraft/server/EntityPlayer.java
+++ b/src/main/java/net/minecraft/server/EntityPlayer.java
@@ -188,7 +188,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
long l = k * k;
int i1 = l > 2147483647L ? Integer.MAX_VALUE : (int) l;
int j1 = this.u(i1);
- int k1 = (new Random()).nextInt(i1);
+ int k1 = worldserver.random.nextInt(i1); // Yatopia - don't create new random instance
for (int l1 = 0; l1 < i1; ++l1) {
int i2 = (k1 + j1 * l1) % i1;
@@ -226,7 +226,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
long l = k * k;
int i1 = l > 2147483647L ? Integer.MAX_VALUE : (int) l;
int j1 = this.u(i1);
- int k1 = (new Random()).nextInt(i1);
+ int k1 = worldserver.random.nextInt(i1); // Yatopia - don't create new random instance
for (int l1 = 0; l1 < i1; ++l1) {
int i2 = (k1 + j1 * l1) % i1;
diff --git a/src/main/java/net/minecraft/server/Explosion.java b/src/main/java/net/minecraft/server/Explosion.java
index 5ca4d03215c979a4d122a32178a1859b4d9c3334..a9006f3c8ccc3e46252343baa5104a5d0b48dc8b 100644
--- a/src/main/java/net/minecraft/server/Explosion.java
+++ b/src/main/java/net/minecraft/server/Explosion.java
@@ -27,7 +27,7 @@ public class Explosion {
private static final ExplosionDamageCalculator a = new ExplosionDamageCalculator();
private final boolean b;
private final Explosion.Effect c;
- private final Random d = new Random();
+ private final Random d = new org.yatopiamc.yatopia.server.util.FastRandom(); //Yatopia Faster Random
private final World world;
private final double posX;
private final double posY;
diff --git a/src/main/java/net/minecraft/server/Item.java b/src/main/java/net/minecraft/server/Item.java
index c3b57e8d572d13ec74d6df5544072cdc55756690..99e5e2c6fe12e0deda1f5aeb3f8922efa5fa8cae 100644
--- a/src/main/java/net/minecraft/server/Item.java
+++ b/src/main/java/net/minecraft/server/Item.java
@@ -13,7 +13,7 @@ public class Item implements IMaterial {
public static final Map<Block, Item> e = Maps.newHashMap();
protected static final UUID f = UUID.fromString("CB3F55D3-645C-4F38-A497-9C13A33DB5CF");
protected static final UUID g = UUID.fromString("FA233E1C-4180-4865-B01B-BCCE9785ACA3");
- protected static final Random RANDOM = new Random();
+ protected static final Random RANDOM = new org.yatopiamc.yatopia.server.util.FastRandom(); //Yatopia Faster Random
protected final CreativeModeTab i;
private final EnumItemRarity a;
private final int maxStackSize;
diff --git a/src/main/java/net/minecraft/server/LoginListener.java b/src/main/java/net/minecraft/server/LoginListener.java
index 9190caed195b9987e3af545f4de63b8d956788a6..178386cfb44152b50757234a624afef0d61e00d8 100644
--- a/src/main/java/net/minecraft/server/LoginListener.java
+++ b/src/main/java/net/minecraft/server/LoginListener.java
@@ -32,7 +32,7 @@ public class LoginListener implements PacketLoginInListener {
private static final AtomicInteger b = new AtomicInteger(0);
private static final Logger LOGGER = LogManager.getLogger();
- private static final Random random = new Random();
+ private static final Random random = new org.yatopiamc.yatopia.server.util.FastRandom(); //Yatopia Faster Random
private final byte[] e = new byte[4];
private final MinecraftServer server;
public final NetworkManager networkManager;
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 5bc6b4acb86fcc774d7d90308dc7e8d0f9c9ff77..0d23591fffcda1f8121e7bc7a6aa00d088b6e80b 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -192,7 +192,7 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
this.m = new GameProfilerSwitcher(SystemUtils.a, this::ai);
this.methodProfiler = GameProfilerDisabled.a;
this.serverPing = new ServerPing();
- this.r = new Random();
+ this.r = new org.yatopiamc.yatopia.server.util.FastRandom(); //Yatopia Faster Random
this.serverPort = -1;
this.worldServer = Maps.newLinkedHashMap(); // CraftBukkit - keep order, k+v already use identity methods
this.isRunning = true;
diff --git a/src/main/java/net/minecraft/server/MobSpawnerTrader.java b/src/main/java/net/minecraft/server/MobSpawnerTrader.java
index 8d89f51182444852062d549d23c00a93e601eb38..3d07f8770d618ea03b2ee0838a86c5c545fe2b73 100644
--- a/src/main/java/net/minecraft/server/MobSpawnerTrader.java
+++ b/src/main/java/net/minecraft/server/MobSpawnerTrader.java
@@ -7,7 +7,7 @@ import javax.annotation.Nullable;
public class MobSpawnerTrader implements MobSpawner {
- private final Random a = new Random();
+ private final Random a = new org.yatopiamc.yatopia.server.util.FastRandom(); //Yatopia Faster Random
private final IWorldDataServer b;
private int c; public final int getMinuteTimer() { return this.c; } public final void setMinuteTimer(int x) { this.c = x; } // Paper - OBFHELPER
private int d; public final int getDayTimer() { return this.d; } public final void setDayTimer(int x) { this.d = x; } // Paper - OBFHELPER
diff --git a/src/main/java/net/minecraft/server/PiglinAI.java b/src/main/java/net/minecraft/server/PiglinAI.java
index 0407fa1751d89a037da8cb01f5ceef9b9833dd18..c7bd1b7eff2de3ce51e096652998e1a44dfc514a 100644
--- a/src/main/java/net/minecraft/server/PiglinAI.java
+++ b/src/main/java/net/minecraft/server/PiglinAI.java
@@ -273,7 +273,7 @@ public class PiglinAI {
}
private static boolean a(EntityLiving entityliving, EntityLiving entityliving1) {
- return entityliving1.getEntityType() != EntityTypes.HOGLIN ? false : (new Random(entityliving.world.getTime())).nextFloat() < 0.1F;
+ return entityliving1.getEntityType() != EntityTypes.HOGLIN ? false : (new org.yatopiamc.yatopia.server.util.FastRandom(entityliving.world.getTime())).nextFloat() < 0.1F; // Yatopia - fast random
}
protected static boolean a(EntityPiglin entitypiglin, ItemStack itemstack) {
diff --git a/src/main/java/net/minecraft/server/Raid.java b/src/main/java/net/minecraft/server/Raid.java
index 11f768e04d71b96350fdb586a280c52e062dfcf2..b1890e936696bdd04a1eaad65f77e4dc6ef1a664 100644
--- a/src/main/java/net/minecraft/server/Raid.java
+++ b/src/main/java/net/minecraft/server/Raid.java
@@ -47,7 +47,7 @@ public class Raid {
public Raid(int i, WorldServer worldserver, BlockPosition blockposition) {
this.bossBattle = new BossBattleServer(Raid.a, BossBattle.BarColor.RED, BossBattle.BarStyle.NOTCHED_10);
- this.random = new Random();
+ this.random = new org.yatopiamc.yatopia.server.util.FastRandom(); //Yatopia Faster Random
this.y = Optional.empty();
this.id = i;
this.world = worldserver;
@@ -61,7 +61,7 @@ public class Raid {
public Raid(WorldServer worldserver, NBTTagCompound nbttagcompound) {
this.bossBattle = new BossBattleServer(Raid.a, BossBattle.BarColor.RED, BossBattle.BarStyle.NOTCHED_10);
- this.random = new Random();
+ this.random = new org.yatopiamc.yatopia.server.util.FastRandom(); //Yatopia Faster Random
this.y = Optional.empty();
this.world = worldserver;
this.id = nbttagcompound.getInt("Id");
diff --git a/src/main/java/net/minecraft/server/TileEntityDispenser.java b/src/main/java/net/minecraft/server/TileEntityDispenser.java
index 6ea4bc31151bce2bdd3376a889029c4b999befac..22e8730adaa5fd489116a9730c82e90fd830514b 100644
--- a/src/main/java/net/minecraft/server/TileEntityDispenser.java
+++ b/src/main/java/net/minecraft/server/TileEntityDispenser.java
@@ -10,7 +10,7 @@ import org.bukkit.entity.HumanEntity;
public class TileEntityDispenser extends TileEntityLootable {
- private static final Random a = new Random();
+ private static final Random a = new org.yatopiamc.yatopia.server.util.FastRandom(); //Yatopia Faster Random
private NonNullList<ItemStack> items;
// CraftBukkit start - add fields and methods
diff --git a/src/main/java/net/minecraft/server/TileEntityEnchantTable.java b/src/main/java/net/minecraft/server/TileEntityEnchantTable.java
index 9b0c75332d9815657d96183e51e40cf14ee3ed75..c9066cb5f51cb2ad078aca3019e1df557062d286 100644
--- a/src/main/java/net/minecraft/server/TileEntityEnchantTable.java
+++ b/src/main/java/net/minecraft/server/TileEntityEnchantTable.java
@@ -15,7 +15,7 @@ public class TileEntityEnchantTable extends TileEntity implements INamableTileEn
public float k;
public float l;
public float m;
- private static final Random n = new Random();
+ private static final Random n = new org.yatopiamc.yatopia.server.util.FastRandom(); //Yatopia Faster Random
private IChatBaseComponent o;
public TileEntityEnchantTable() {
diff --git a/src/main/java/net/minecraft/server/WeightedList.java b/src/main/java/net/minecraft/server/WeightedList.java
index f0fdfd6891e59891e7370a2d682b65c647b28e9e..8d5fe0880f4f2bffe14dc1c7163cde69869422e7 100644
--- a/src/main/java/net/minecraft/server/WeightedList.java
+++ b/src/main/java/net/minecraft/server/WeightedList.java
@@ -28,7 +28,7 @@ public class WeightedList<U> {
private WeightedList(List<WeightedList.a<U>> list, boolean isUnsafe) {
this.isUnsafe = isUnsafe;
// Paper end
- this.b = new Random();
+ this.b = new org.yatopiamc.yatopia.server.util.FastRandom(); //Yatopia Faster Random
this.list = Lists.newArrayList(list); // Paper - decompile conflict
}
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
index ed2f75195d7a39882675af9ff0a7e8e7d208f906..b9a4d29382f4693eb94b39cabfc46b7e952b9306 100644
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
@@ -48,13 +48,13 @@ public abstract class World implements GeneratorAccess, AutoCloseable {
public final Thread serverThread;
private final boolean debugWorld;
private int d;
- protected int n = (new Random()).nextInt();
+ protected int n = (new org.yatopiamc.yatopia.server.util.FastRandom()).nextInt(); // Yatopia - wtf ? why doesn't this use the already initiated random!?
protected final int o = 1013904223;
protected float lastRainLevel;
protected float rainLevel;
protected float lastThunderLevel;
protected float thunderLevel;
- public final Random random = new Random();
+ public final Random random = new org.yatopiamc.yatopia.server.util.FastRandom(); //Yatopia Faster Random
private final DimensionManager x;
public final WorldDataMutable worldData;
private final Supplier<GameProfilerFiller> methodProfiler;
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
index 8904b39db2203118fe3589133cb7e64334c20f33..d37c1e1f05b40ea672145478aa608a4002bc09bd 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -334,7 +334,7 @@ public class CraftWorld implements World {
}
// Paper end
- private static final Random rand = new Random();
+ private static final Random rand = new org.yatopiamc.yatopia.server.util.FastRandom(); //Yatopia Faster Random
public CraftWorld(WorldServer world, ChunkGenerator gen, Environment env) {
this.world = world;
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftFirework.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftFirework.java
index f3066e6c781bcee72c235abcef5060fb080892d5..d002ec28a186939636652b98e5f0b77b5c1bed5c 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftFirework.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftFirework.java
@@ -13,7 +13,7 @@ import org.bukkit.inventory.meta.FireworkMeta;
public class CraftFirework extends CraftProjectile implements Firework {
- private final Random random = new Random();
+ private final Random random = new org.yatopiamc.yatopia.server.util.FastRandom(); //Yatopia Faster Random
private final CraftItemStack item;
public CraftFirework(CraftServer server, EntityFireworks entity) {
diff --git a/src/test/java/org/bukkit/NibbleArrayTest.java b/src/test/java/org/bukkit/NibbleArrayTest.java
index 40ba97fb77dddafe7c792249ca343d5abee3e5d0..be5761e76abf6f9fbe5b0e047dac02fa605ecc30 100644
--- a/src/test/java/org/bukkit/NibbleArrayTest.java
+++ b/src/test/java/org/bukkit/NibbleArrayTest.java
@@ -11,7 +11,7 @@ public class NibbleArrayTest {
@Test
public void testNibble() {
- Random random = new Random();
+ Random random = new org.yatopiamc.yatopia.server.util.FastRandom(); //Yatopia Faster Random
byte[] classic = new byte[NIBBLE_SIZE];
NibbleArray nibble = new NibbleArray();