Yatopia/patches/server/0063-Use-faster-random-implementation.patch
Ivan Pekov cc7670f815
Updated Upstream and Sidestream(s) (Tuinity/EMC/Purpur/AirplaneLite)
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:
de6c239 Merge branch 'master' of https://github.com/Spottedleaf/Tuinity into ver/1.16.4
cc34294 Copy passenger list in enderTeleportTo
8c5d945 Improve abnormal server shutdown process
0ae7e67 Do not load chunks during a crash report
0fbcf78 Fix small issue with handling of step height in colliding
4722d59 Updated Upstream (Paper)

EMC Changes:
1d0cc885 Updated Paper

Purpur Changes:
3776636 Implement TPSBar
258ae07 Updated Upstream (Paper)
c51e391 Add back --zero-commit
ef0b93d Rebuild patches
0ae637c Option for chests to open even with a solid block on top
ce4ab83 Phantom flames on swoop
5e2d697 Don't apply potion effects on load either
bbe5a58 Don't apply potion effect to wolves during worldgen
06c4f83 Get max health attribute even closer to vanilla
41f23a7 Updated Upstream (Tuinity)
787e35c Get max health equations for horse types closer to vanilla
aed0867 Fix CraftSound backwards compatibility
dfabf51 Start of the configurable base attributes
a1fa221 Updated Upstream (Paper)
0174fcd Configurable default wolf collar color (#116)
da48e0a [ci-skip] fix comment in last patch
65fde28 Add option for using milk to cure wolves
38efb4d Use a ThreadLocal SimpleDateFormat for CriterionProgress deserialization
4e6e1ff Revert "Fix concurrency issue with CriterionProgress deserialization"
55bde37 Fix concurrency issue with CriterionProgress deserialization
b4be9ab Small fixes to rabid wolves patch
5943978 Updated Upstream (Paper)
ac34692 Chance to spawn wolves as "rabid" (#114)
1b40f87 Updated Upstream (Paper)
69790ff Alphabetize in-game /plugins list

AirplaneLite Changes:
76810f1 Updated Upstream (Tuinity)
2020-12-13 17:18:57 +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 0bca08dc6ffd367de7cffab0433900d6bfe555cf..51c4ff1bd6948ab46d723c37af39c76cdf662be5 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 1f54ce29006749e59cb4088b260b70596884a45d..6fe7151ba7d8ad105bf21aa89be5a7ab2f2aa0ca 100644
--- a/src/main/java/net/minecraft/server/EntityPlayer.java
+++ b/src/main/java/net/minecraft/server/EntityPlayer.java
@@ -186,7 +186,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;
@@ -224,7 +224,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 571483166c69079961c3297e1b40265b62f34217..55d22bfa2f30e2eaaf11836c29c90c86e764a41a 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -197,7 +197,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 de7ca87e74084c5cca109a6eff071da351dec91b..84fb0492abca5a2443e89adc18b3fa17c636054f 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 a69b38f293723a58691b2777d170f9cc146d1148..b746d1efbb06173e16a5b3a7f6bf0f3303a5ae05 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();