2020-12-01 03:08:41 +01:00
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
2020-12-02 07:35:11 +01:00
index b5401eaf974857455c17c3f9cfdedf2eb4bde321..ec7ce458159e04b4d2bfda8fbb9b6974595747a6 100644
2020-12-01 03:08:41 +01:00
--- 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();
2020-12-02 07:35:11 +01:00
+ private static final Random RANDOM = new org.yatopiamc.yatopia.server.util.FastRandom(); //Yatopia Faster Random
2020-12-01 03:08:41 +01:00
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
2020-12-02 07:35:11 +01:00
index c9f4b69874e693c8e5c3346f09db7b5014dcfb63..e0101b688337d863ee873301368dcaced630d127 100644
2020-12-01 03:08:41 +01:00
--- 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();
2020-12-02 07:35:11 +01:00
+ Random random = new org.yatopiamc.yatopia.server.util.FastRandom(); //Yatopia Faster Random
2020-12-01 03:08:41 +01:00
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
2020-12-02 07:35:11 +01:00
index 73bff2ca1f09cf6f33479f175cae72e456e8db4b..8a09aa82d97b5096e62995bc3903e15a623c15ad 100644
2020-12-01 03:08:41 +01:00
--- 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();
2020-12-02 07:35:11 +01:00
+ this.h = new org.yatopiamc.yatopia.server.util.FastRandom(); //Yatopia Faster Random
2020-12-01 03:08:41 +01:00
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
2020-12-02 07:35:11 +01:00
index 38dc6086d18951e065d4048d1d8eee288c5c5fd1..4e094f0e1117cecbd39be645997eb9d3080c666f 100644
2020-12-01 03:08:41 +01:00
--- 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));
2020-12-02 07:35:11 +01:00
+ Collections.shuffle(this.gateways, new org.yatopiamc.yatopia.server.util.FastRandom(i)); // Yatopia - fast random
2020-12-01 03:08:41 +01:00
}
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
2020-12-13 16:18:57 +01:00
index 0bca08dc6ffd367de7cffab0433900d6bfe555cf..51c4ff1bd6948ab46d723c37af39c76cdf662be5 100644
2020-12-01 03:08:41 +01:00
--- 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() {
2020-12-02 07:35:11 +01:00
+ public static Random SHARED_RANDOM = new org.yatopiamc.yatopia.server.util.FastRandom() { //Yatopia Faster Random
2020-12-01 03:08:41 +01:00
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
2020-12-02 07:35:11 +01:00
index 6891e61bcfea82958e100abaef94865bf36a32c2..32ccc08455a88c510fe05713c8de7a5eed85e70b 100644
2020-12-01 03:08:41 +01:00
--- 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();
2020-12-02 07:35:11 +01:00
+ this.b = new org.yatopiamc.yatopia.server.util.FastRandom(); //Yatopia Faster Random
2020-12-01 03:08:41 +01:00
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
2020-12-17 08:48:17 +01:00
index bb8c5ba0eccc2633652f662bb7fe2dcae2f2db18..42c6d26131fa144707e0ecb244a8a3b26a19a383 100644
2020-12-01 03:08:41 +01:00
--- a/src/main/java/net/minecraft/server/EntityPlayer.java
+++ b/src/main/java/net/minecraft/server/EntityPlayer.java
2020-12-17 08:48:17 +01:00
@@ -188,7 +188,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
2020-12-01 03:08:41 +01:00
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;
2020-12-17 08:48:17 +01:00
@@ -226,7 +226,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
2020-12-01 03:08:41 +01:00
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
2020-12-02 07:35:11 +01:00
index 5ca4d03215c979a4d122a32178a1859b4d9c3334..a9006f3c8ccc3e46252343baa5104a5d0b48dc8b 100644
2020-12-01 03:08:41 +01:00
--- 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();
2020-12-02 07:35:11 +01:00
+ private final Random d = new org.yatopiamc.yatopia.server.util.FastRandom(); //Yatopia Faster Random
2020-12-01 03:08:41 +01:00
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
2020-12-02 07:35:11 +01:00
index c3b57e8d572d13ec74d6df5544072cdc55756690..99e5e2c6fe12e0deda1f5aeb3f8922efa5fa8cae 100644
2020-12-01 03:08:41 +01:00
--- 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();
2020-12-02 07:35:11 +01:00
+ protected static final Random RANDOM = new org.yatopiamc.yatopia.server.util.FastRandom(); //Yatopia Faster Random
2020-12-01 03:08:41 +01:00
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
2020-12-02 07:35:11 +01:00
index 9190caed195b9987e3af545f4de63b8d956788a6..178386cfb44152b50757234a624afef0d61e00d8 100644
2020-12-01 03:08:41 +01:00
--- 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();
2020-12-02 07:35:11 +01:00
+ private static final Random random = new org.yatopiamc.yatopia.server.util.FastRandom(); //Yatopia Faster Random
2020-12-01 03:08:41 +01:00
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
2020-12-13 16:18:57 +01:00
index 571483166c69079961c3297e1b40265b62f34217..55d22bfa2f30e2eaaf11836c29c90c86e764a41a 100644
2020-12-01 03:08:41 +01:00
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
2020-12-07 09:10:55 +01:00
@@ -197,7 +197,7 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
2020-12-01 03:08:41 +01:00
this.m = new GameProfilerSwitcher(SystemUtils.a, this::ai);
this.methodProfiler = GameProfilerDisabled.a;
this.serverPing = new ServerPing();
- this.r = new Random();
2020-12-02 07:35:11 +01:00
+ this.r = new org.yatopiamc.yatopia.server.util.FastRandom(); //Yatopia Faster Random
2020-12-01 03:08:41 +01:00
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
2020-12-02 07:35:11 +01:00
index 8d89f51182444852062d549d23c00a93e601eb38..3d07f8770d618ea03b2ee0838a86c5c545fe2b73 100644
2020-12-01 03:08:41 +01:00
--- 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();
2020-12-02 07:35:11 +01:00
+ private final Random a = new org.yatopiamc.yatopia.server.util.FastRandom(); //Yatopia Faster Random
2020-12-01 03:08:41 +01:00
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
2020-12-02 07:35:11 +01:00
index 0407fa1751d89a037da8cb01f5ceef9b9833dd18..c7bd1b7eff2de3ce51e096652998e1a44dfc514a 100644
2020-12-01 03:08:41 +01:00
--- 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;
2020-12-02 07:35:11 +01:00
+ return entityliving1.getEntityType() != EntityTypes.HOGLIN ? false : (new org.yatopiamc.yatopia.server.util.FastRandom(entityliving.world.getTime())).nextFloat() < 0.1F; // Yatopia - fast random
2020-12-01 03:08:41 +01:00
}
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
2020-12-02 07:35:11 +01:00
index 11f768e04d71b96350fdb586a280c52e062dfcf2..b1890e936696bdd04a1eaad65f77e4dc6ef1a664 100644
2020-12-01 03:08:41 +01:00
--- 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();
2020-12-02 07:35:11 +01:00
+ this.random = new org.yatopiamc.yatopia.server.util.FastRandom(); //Yatopia Faster Random
2020-12-01 03:08:41 +01:00
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();
2020-12-02 07:35:11 +01:00
+ this.random = new org.yatopiamc.yatopia.server.util.FastRandom(); //Yatopia Faster Random
2020-12-01 03:08:41 +01:00
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
2020-12-02 07:35:11 +01:00
index 6ea4bc31151bce2bdd3376a889029c4b999befac..22e8730adaa5fd489116a9730c82e90fd830514b 100644
2020-12-01 03:08:41 +01:00
--- 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();
2020-12-02 07:35:11 +01:00
+ private static final Random a = new org.yatopiamc.yatopia.server.util.FastRandom(); //Yatopia Faster Random
2020-12-01 03:08:41 +01:00
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
2020-12-02 07:35:11 +01:00
index 9b0c75332d9815657d96183e51e40cf14ee3ed75..c9066cb5f51cb2ad078aca3019e1df557062d286 100644
2020-12-01 03:08:41 +01:00
--- 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();
2020-12-02 07:35:11 +01:00
+ private static final Random n = new org.yatopiamc.yatopia.server.util.FastRandom(); //Yatopia Faster Random
2020-12-01 03:08:41 +01:00
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
2020-12-02 07:35:11 +01:00
index f0fdfd6891e59891e7370a2d682b65c647b28e9e..8d5fe0880f4f2bffe14dc1c7163cde69869422e7 100644
2020-12-01 03:08:41 +01:00
--- 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();
2020-12-02 07:35:11 +01:00
+ this.b = new org.yatopiamc.yatopia.server.util.FastRandom(); //Yatopia Faster Random
2020-12-01 03:08:41 +01:00
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
2020-12-16 07:15:14 +01:00
index 95b9663e072991004904365cfc2ba11edb01de20..c63d728082e28c13bc9724e74b154d02fbb2392e 100644
2020-12-01 03:08:41 +01:00
--- 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();
2020-12-02 07:35:11 +01:00
+ protected int n = (new org.yatopiamc.yatopia.server.util.FastRandom()).nextInt(); // Yatopia - wtf ? why doesn't this use the already initiated random!?
2020-12-01 03:08:41 +01:00
protected final int o = 1013904223;
protected float lastRainLevel;
protected float rainLevel;
protected float lastThunderLevel;
protected float thunderLevel;
- public final Random random = new Random();
2020-12-02 07:35:11 +01:00
+ public final Random random = new org.yatopiamc.yatopia.server.util.FastRandom(); //Yatopia Faster Random
2020-12-01 03:08:41 +01:00
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
2020-12-13 16:18:57 +01:00
index a69b38f293723a58691b2777d170f9cc146d1148..b746d1efbb06173e16a5b3a7f6bf0f3303a5ae05 100644
2020-12-01 03:08:41 +01:00
--- 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();
2020-12-02 07:35:11 +01:00
+ private static final Random rand = new org.yatopiamc.yatopia.server.util.FastRandom(); //Yatopia Faster Random
2020-12-01 03:08:41 +01:00
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
2020-12-02 07:35:11 +01:00
index f3066e6c781bcee72c235abcef5060fb080892d5..d002ec28a186939636652b98e5f0b77b5c1bed5c 100644
2020-12-01 03:08:41 +01:00
--- 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();
2020-12-02 07:35:11 +01:00
+ private final Random random = new org.yatopiamc.yatopia.server.util.FastRandom(); //Yatopia Faster Random
2020-12-01 03:08:41 +01:00
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
2020-12-02 07:35:11 +01:00
index 40ba97fb77dddafe7c792249ca343d5abee3e5d0..be5761e76abf6f9fbe5b0e047dac02fa605ecc30 100644
2020-12-01 03:08:41 +01:00
--- 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();
2020-12-02 07:35:11 +01:00
+ Random random = new org.yatopiamc.yatopia.server.util.FastRandom(); //Yatopia Faster Random
2020-12-01 03:08:41 +01:00
byte[] classic = new byte[NIBBLE_SIZE];
NibbleArray nibble = new NibbleArray();