Fixes to vanilla parity
Also made FastMath.round toggleable. Risky method, use it with cautious.
This commit is contained in:
@@ -6,89 +6,6 @@ Subject: [PATCH] Yatopia Utilities
|
||||
Original code by YatopiaMC, licensed under MIT
|
||||
You can find the original code on https://github.com/YatopiaMC/Yatopia
|
||||
|
||||
diff --git a/build.gradle.kts b/build.gradle.kts
|
||||
index 6a8786790cfeb4373d23d7e743f06b19efa45c35..ea185d933980fa453e933e0e503d7eaa17f6f14f 100644
|
||||
--- a/build.gradle.kts
|
||||
+++ b/build.gradle.kts
|
||||
@@ -40,6 +40,7 @@ dependencies {
|
||||
implementation("org.apache.logging.log4j:log4j-slf4j18-impl:2.17.1") // Paper
|
||||
implementation("org.ow2.asm:asm:9.2")
|
||||
implementation("org.ow2.asm:asm-commons:9.2") // Paper - ASM event executor generation
|
||||
+ implementation("org.apache.commons:commons-rng-core:1.4") // Yatopia
|
||||
runtimeOnly("org.xerial:sqlite-jdbc:3.36.0.3")
|
||||
runtimeOnly("mysql:mysql-connector-java:8.0.27")
|
||||
runtimeOnly("com.lmax:disruptor:3.4.4") // Paper
|
||||
diff --git a/src/main/java/org/yatopiamc/yatopia/server/util/FastRandom.java b/src/main/java/org/yatopiamc/yatopia/server/util/FastRandom.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..13cf05fa0c34414a686856df8053a2af8346330e
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/org/yatopiamc/yatopia/server/util/FastRandom.java
|
||||
@@ -0,0 +1,64 @@
|
||||
+package org.yatopiamc.yatopia.server.util;
|
||||
+
|
||||
+import org.apache.commons.rng.core.source64.XoRoShiRo128PlusPlus;
|
||||
+
|
||||
+import java.util.Random;
|
||||
+import java.util.SplittableRandom;
|
||||
+
|
||||
+public class FastRandom extends Random {
|
||||
+
|
||||
+ private XoRoShiRo128PlusPlus random;
|
||||
+
|
||||
+ public FastRandom() {
|
||||
+ super();
|
||||
+ SplittableRandom randomseed = new SplittableRandom();
|
||||
+ this.random = new XoRoShiRo128PlusPlus(randomseed.nextLong(), randomseed.nextLong());
|
||||
+ }
|
||||
+
|
||||
+ public FastRandom(long seed) {
|
||||
+ super(seed);
|
||||
+ SplittableRandom randomseed = new SplittableRandom(seed);
|
||||
+ this.random = new XoRoShiRo128PlusPlus(randomseed.nextLong(), randomseed.nextLong());
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public boolean nextBoolean() {
|
||||
+ return random.nextBoolean();
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public int nextInt() {
|
||||
+ return random.nextInt();
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public float nextFloat() {
|
||||
+ return (float) random.nextDouble();
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public double nextDouble() {
|
||||
+ return random.nextDouble();
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public synchronized void setSeed(long seed) {
|
||||
+ SplittableRandom randomseed = new SplittableRandom(seed);
|
||||
+ this.random = new XoRoShiRo128PlusPlus(randomseed.nextLong(), randomseed.nextLong());
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void nextBytes(byte[] bytes) {
|
||||
+ random.nextBytes(bytes);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public int nextInt(int bound) {
|
||||
+ return random.nextInt(bound);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public long nextLong() {
|
||||
+ return random.nextLong();
|
||||
+ }
|
||||
+}
|
||||
\ No newline at end of file
|
||||
diff --git a/src/main/java/org/yatopiamc/yatopia/server/util/TimeUtils.java b/src/main/java/org/yatopiamc/yatopia/server/util/TimeUtils.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..bb023bcb4b1e1ab5261c83358ce0951cc35ba16d
|
||||
|
||||
486
patches/server/0017-Use-XoRoShiRoRandom.patch
Normal file
486
patches/server/0017-Use-XoRoShiRoRandom.patch
Normal file
@@ -0,0 +1,486 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Simon Gardling <titaniumtown@gmail.com>
|
||||
Date: Wed, 5 Jan 2022 12:25:37 -0500
|
||||
Subject: [PATCH] Use XoRoShiRoRandom
|
||||
|
||||
Original code by Titaniumtown, licensed under GNU General Public License v3.0
|
||||
You can find the original code on https://gitlab.com/Titaniumtown/JettPack
|
||||
|
||||
diff --git a/src/main/java/com/destroystokyo/paper/loottable/PaperLootableInventoryData.java b/src/main/java/com/destroystokyo/paper/loottable/PaperLootableInventoryData.java
|
||||
index 20cfe7b9b7127ddeb97aa91d759fc17b4a548eaf..34665a768285fd99e49d57d3879deb1fe3c7df32 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 wtf.etil.mirai.server.util.XoRoShiRoRandom(); // JettPack
|
||||
|
||||
private long lastFill = -1;
|
||||
private long nextRefill = -1;
|
||||
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
index 40fe4111a52ab754094d462b0d1889e740797d4d..fe39556aa0b5ae0ef465aa561a08900d2fd0d6ee 100644
|
||||
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
@@ -415,7 +415,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||||
this.onMetricsRecordingFinished = (path) -> {
|
||||
};
|
||||
this.status = new ServerStatus();
|
||||
- this.random = new Random();
|
||||
+ this.random = new wtf.etil.mirai.server.util.XoRoShiRoRandom(); // JettPack
|
||||
this.port = -1;
|
||||
this.levels = Maps.newLinkedHashMap(); // CraftBukkit - keep order, k+v already use identity methods
|
||||
this.running = true;
|
||||
diff --git a/src/main/java/net/minecraft/server/commands/SpreadPlayersCommand.java b/src/main/java/net/minecraft/server/commands/SpreadPlayersCommand.java
|
||||
index 62f26f5d3ef5546f26424185e378fea64c08ce2f..54559b015813ca1c5dae9cb229a4a63f3bc3d47a 100644
|
||||
--- a/src/main/java/net/minecraft/server/commands/SpreadPlayersCommand.java
|
||||
+++ b/src/main/java/net/minecraft/server/commands/SpreadPlayersCommand.java
|
||||
@@ -55,7 +55,7 @@ public class SpreadPlayersCommand {
|
||||
}
|
||||
|
||||
private static int spreadPlayers(CommandSourceStack source, Vec2 center, float spreadDistance, float maxRange, int maxY, boolean respectTeams, Collection<? extends Entity> players) throws CommandSyntaxException {
|
||||
- Random random = new Random();
|
||||
+ Random random = new wtf.etil.mirai.server.util.XoRoShiRoRandom(); // JettPack
|
||||
double d0 = (double) (center.x - maxRange);
|
||||
double d1 = (double) (center.y - maxRange);
|
||||
double d2 = (double) (center.x + maxRange);
|
||||
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
||||
index 7b23535a680d2a8534dcb8dd87770f66fb982c13..5e9c7f428e4a0d920569c2a02e999da910fc9397 100644
|
||||
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
||||
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
||||
@@ -368,7 +368,7 @@ public class ServerPlayer extends Player {
|
||||
long l = k * k;
|
||||
int i1 = l > 2147483647L ? Integer.MAX_VALUE : (int) l;
|
||||
int j1 = this.getCoprime(i1);
|
||||
- int k1 = (new Random()).nextInt(i1);
|
||||
+ int k1 = (wtf.etil.mirai.server.util.XoRoShiRoRandom()).nextInt(i1); // JettPack
|
||||
|
||||
for (int l1 = 0; l1 < i1; ++l1) {
|
||||
int i2 = (k1 + j1 * l1) % i1;
|
||||
@@ -405,7 +405,7 @@ public class ServerPlayer extends Player {
|
||||
long l = k * k;
|
||||
int i1 = l > 2147483647L ? Integer.MAX_VALUE : (int) l;
|
||||
int j1 = this.getCoprime(i1);
|
||||
- int k1 = (new Random()).nextInt(i1);
|
||||
+ int k1 = (wtf.etil.mirai.server.util.XoRoShiRoRandom()).nextInt(i1); // JettPack
|
||||
|
||||
for (int l1 = 0; l1 < i1; ++l1) {
|
||||
int i2 = (k1 + j1 * l1) % i1;
|
||||
diff --git a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
||||
index 462d8c36166c63a4dc8fa74ac7f82859e6f4b83a..1be5ae3162f2e2b5a48310c162edf8bdc8a08c2b 100644
|
||||
--- a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
||||
+++ b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
||||
@@ -52,7 +52,7 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener
|
||||
private static final AtomicInteger UNIQUE_THREAD_ID = new AtomicInteger(0);
|
||||
static final Logger LOGGER = LogManager.getLogger();
|
||||
private static final int MAX_TICKS_BEFORE_LOGIN = 600;
|
||||
- private static final Random RANDOM = new Random();
|
||||
+ private static final Random RANDOM = new wtf.etil.mirai.server.util.XoRoShiRoRandom(); // JettPack
|
||||
private final byte[] nonce = new byte[4];
|
||||
final MinecraftServer server;
|
||||
public final Connection connection;
|
||||
diff --git a/src/main/java/net/minecraft/server/rcon/thread/QueryThreadGs4.java b/src/main/java/net/minecraft/server/rcon/thread/QueryThreadGs4.java
|
||||
index 25ae440839f1d286550a77d0a4c61e1dc02b369d..f42bce03c21309efbb208be21263b6c09927ed6c 100644
|
||||
--- a/src/main/java/net/minecraft/server/rcon/thread/QueryThreadGs4.java
|
||||
+++ b/src/main/java/net/minecraft/server/rcon/thread/QueryThreadGs4.java
|
||||
@@ -348,7 +348,7 @@ public class QueryThreadGs4 extends GenericThread {
|
||||
this.identBytes[2] = bs[5];
|
||||
this.identBytes[3] = bs[6];
|
||||
this.ident = new String(this.identBytes, StandardCharsets.UTF_8);
|
||||
- this.challenge = (new Random()).nextInt(16777216);
|
||||
+ this.challenge = (wtf.etil.mirai.server.util.XoRoShiRoRandom()).nextInt(16777216); // JettPack
|
||||
this.challengeBytes = String.format("\t%s%d\u0000", this.ident, this.challenge).getBytes(StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/ai/behavior/ShufflingList.java b/src/main/java/net/minecraft/world/entity/ai/behavior/ShufflingList.java
|
||||
index 204ca4fbd89bdadd902529f1f191df46fce3cace..fa0845fffc358ae11dc81e6119afce8ffdc78571 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/ai/behavior/ShufflingList.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/ai/behavior/ShufflingList.java
|
||||
@@ -13,7 +13,7 @@ import java.util.stream.Stream;
|
||||
|
||||
public class ShufflingList<U> {
|
||||
public final List<ShufflingList.WeightedEntry<U>> entries; // Paper - public
|
||||
- private final Random random = new Random();
|
||||
+ private final Random random = new wtf.etil.mirai.server.util.XoRoShiRoRandom(); // JettPack
|
||||
private final boolean isUnsafe; // Paper
|
||||
|
||||
public ShufflingList() {
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/ai/sensing/Sensor.java b/src/main/java/net/minecraft/world/entity/ai/sensing/Sensor.java
|
||||
index f3b8e253a5bfc3f68121dbe656ae7e2ac0f0eb1c..4b7dd3f2157d0f78bc35ec865555682d0f61445f 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/ai/sensing/Sensor.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/ai/sensing/Sensor.java
|
||||
@@ -8,7 +8,7 @@ import net.minecraft.world.entity.ai.memory.MemoryModuleType;
|
||||
import net.minecraft.world.entity.ai.targeting.TargetingConditions;
|
||||
|
||||
public abstract class Sensor<E extends LivingEntity> {
|
||||
- private static final Random RANDOM = new Random();
|
||||
+ private static final Random RANDOM = new wtf.etil.mirai.server.util.XoRoShiRoRandom(); // JettPack
|
||||
private static final int DEFAULT_SCAN_RATE = 20;
|
||||
protected static final int TARGETING_RANGE = 16;
|
||||
private static final TargetingConditions TARGET_CONDITIONS = TargetingConditions.forNonCombat().range(16.0D);
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/npc/WanderingTraderSpawner.java b/src/main/java/net/minecraft/world/entity/npc/WanderingTraderSpawner.java
|
||||
index 323eea2bccacfcc85849b5d82c2b30d991e0c0d8..20668da3594346511b065146a2b7478c98283b9b 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/npc/WanderingTraderSpawner.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/npc/WanderingTraderSpawner.java
|
||||
@@ -35,7 +35,7 @@ public class WanderingTraderSpawner implements CustomSpawner {
|
||||
private static final int SPAWN_CHANCE_INCREASE = 25;
|
||||
private static final int SPAWN_ONE_IN_X_CHANCE = 10;
|
||||
private static final int NUMBER_OF_SPAWN_ATTEMPTS = 10;
|
||||
- private final Random random = new Random();
|
||||
+ private final Random random = new wtf.etil.mirai.server.util.XoRoShiRoRandom(); // JettPack
|
||||
private final ServerLevelData serverLevelData;
|
||||
private int tickDelay;
|
||||
private int spawnDelay;
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java b/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java
|
||||
index 2015223c1703935faef52a8b88263ab3f1fbe92a..e34b4036a8a2efadd18f62c5037b75f6b59c53e0 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java
|
||||
@@ -76,7 +76,7 @@ public class FishingHook extends Projectile {
|
||||
|
||||
private FishingHook(EntityType<? extends FishingHook> type, Level world, int luckOfTheSeaLevel, int lureLevel) {
|
||||
super(type, world);
|
||||
- this.syncronizedRandom = new Random();
|
||||
+ this.syncronizedRandom = new wtf.etil.mirai.server.util.XoRoShiRoRandom(); // JettPack
|
||||
this.openWater = true;
|
||||
this.currentState = FishingHook.FishHookState.FLYING;
|
||||
this.noCulling = true;
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/raid/Raid.java b/src/main/java/net/minecraft/world/entity/raid/Raid.java
|
||||
index 7131226de05bc57830f7a68ba545ebfd19d33a59..9c14b6049f3b8109c42d3c8825c87ae43f981938 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/raid/Raid.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/raid/Raid.java
|
||||
@@ -110,7 +110,7 @@ public class Raid {
|
||||
|
||||
public Raid(int id, ServerLevel world, BlockPos pos) {
|
||||
this.raidEvent = new ServerBossEvent(Raid.RAID_NAME_COMPONENT, BossEvent.BossBarColor.RED, BossEvent.BossBarOverlay.NOTCHED_10);
|
||||
- this.random = new Random();
|
||||
+ this.random = new wtf.etil.mirai.server.util.XoRoShiRoRandom(); // JettPack
|
||||
this.waveSpawnPos = Optional.empty();
|
||||
this.id = id;
|
||||
this.level = world;
|
||||
@@ -124,7 +124,7 @@ public class Raid {
|
||||
|
||||
public Raid(ServerLevel world, CompoundTag nbt) {
|
||||
this.raidEvent = new ServerBossEvent(Raid.RAID_NAME_COMPONENT, BossEvent.BossBarColor.RED, BossEvent.BossBarOverlay.NOTCHED_10);
|
||||
- this.random = new Random();
|
||||
+ this.random = new wtf.etil.mirai.server.util.XoRoShiRoRandom(); // JettPack
|
||||
this.waveSpawnPos = Optional.empty();
|
||||
this.level = world;
|
||||
this.id = nbt.getInt("Id");
|
||||
diff --git a/src/main/java/net/minecraft/world/inventory/EnchantmentMenu.java b/src/main/java/net/minecraft/world/inventory/EnchantmentMenu.java
|
||||
index d75f14e23d94deee2b6af20c8af3bcd42c1fbbc3..7c21d59bb9052d2e2c690f31a24277066c20f9b7 100644
|
||||
--- a/src/main/java/net/minecraft/world/inventory/EnchantmentMenu.java
|
||||
+++ b/src/main/java/net/minecraft/world/inventory/EnchantmentMenu.java
|
||||
@@ -68,7 +68,7 @@ public class EnchantmentMenu extends AbstractContainerMenu {
|
||||
}
|
||||
// CraftBukkit end
|
||||
};
|
||||
- this.random = new Random();
|
||||
+ this.random = new wtf.etil.mirai.server.util.XoRoShiRoRandom(); // JettPack
|
||||
this.enchantmentSeed = DataSlot.standalone();
|
||||
this.costs = new int[3];
|
||||
this.enchantClue = new int[]{-1, -1, -1};
|
||||
diff --git a/src/main/java/net/minecraft/world/level/BaseSpawner.java b/src/main/java/net/minecraft/world/level/BaseSpawner.java
|
||||
index 03726227fdd60e9cf77213d50184abff438e01ef..8220cb49c2d4d46120615b298ce36d10b29dba6d 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/BaseSpawner.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/BaseSpawner.java
|
||||
@@ -41,7 +41,7 @@ public abstract class BaseSpawner {
|
||||
public int maxNearbyEntities = 6;
|
||||
public int requiredPlayerRange = 16;
|
||||
public int spawnRange = 4;
|
||||
- private final Random random = new Random();
|
||||
+ private final Random random = new wtf.etil.mirai.server.util.XoRoShiRoRandom(); // JettPack
|
||||
private int tickDelay = 0; // Paper
|
||||
|
||||
public BaseSpawner() {}
|
||||
diff --git a/src/main/java/net/minecraft/world/level/Explosion.java b/src/main/java/net/minecraft/world/level/Explosion.java
|
||||
index 6795132318a4e8b4c7a33b6f4b89a730ea66b97f..b8d83a0d56ce2285ee17c0b0226bd08d4cc304c0 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/Explosion.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/Explosion.java
|
||||
@@ -88,7 +88,7 @@ public class Explosion {
|
||||
}
|
||||
|
||||
public Explosion(Level world, @Nullable Entity entity, @Nullable DamageSource damageSource, @Nullable ExplosionDamageCalculator behavior, double x, double y, double z, float power, boolean createFire, Explosion.BlockInteraction destructionType) {
|
||||
- this.random = new Random();
|
||||
+ this.random = new wtf.etil.mirai.server.util.XoRoShiRoRandom(); // JettPack
|
||||
this.toBlow = Lists.newArrayList();
|
||||
this.hitPlayers = Maps.newHashMap();
|
||||
this.level = world;
|
||||
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
|
||||
index 96c6ef03a64e425472c64884c91ac4951950362b..1b6fc6511c32e6509f773d5259e7a07c3b8e79bf 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/Level.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/Level.java
|
||||
@@ -123,13 +123,13 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
|
||||
public final Thread thread;
|
||||
private final boolean isDebug;
|
||||
private int skyDarken;
|
||||
- protected int randValue = (new Random()).nextInt();
|
||||
+ protected int randValue = (new wtf.etil.mirai.server.util.XoRoShiRoRandom()).nextInt(); // JettPack
|
||||
protected final int addend = 1013904223;
|
||||
protected float oRainLevel;
|
||||
public float rainLevel;
|
||||
protected float oThunderLevel;
|
||||
public float thunderLevel;
|
||||
- public final Random random = new Random();
|
||||
+ public final Random random = new wtf.etil.mirai.server.util.XoRoShiRoRandom(); // JettPack
|
||||
private final DimensionType dimensionType;
|
||||
public final WritableLevelData levelData;
|
||||
private final Supplier<ProfilerFiller> profiler;
|
||||
diff --git a/src/main/java/net/minecraft/world/level/block/entity/DispenserBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/DispenserBlockEntity.java
|
||||
index f74c5bb8e1ba42c77c59d481b871fd992483b128..5552b6ff8f673fb6846c730fed060ea5abf51867 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/block/entity/DispenserBlockEntity.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/block/entity/DispenserBlockEntity.java
|
||||
@@ -21,7 +21,7 @@ import org.bukkit.entity.HumanEntity;
|
||||
|
||||
public class DispenserBlockEntity extends RandomizableContainerBlockEntity {
|
||||
|
||||
- private static final Random RANDOM = new Random();
|
||||
+ private static final Random RANDOM = new wtf.etil.mirai.server.util.XoRoShiRoRandom(); // JettPack
|
||||
public static final int CONTAINER_SIZE = 9;
|
||||
private NonNullList<ItemStack> items;
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/world/level/storage/loot/LootContext.java b/src/main/java/net/minecraft/world/level/storage/loot/LootContext.java
|
||||
index d33af84300db18ea2b71dba2c9ed43390a293500..e60d244c44396ec09ecff889d8b9543b7224ce1b 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/storage/loot/LootContext.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/storage/loot/LootContext.java
|
||||
@@ -201,7 +201,7 @@ public class LootContext {
|
||||
} else {
|
||||
Random random = this.random;
|
||||
if (random == null) {
|
||||
- random = new Random();
|
||||
+ random = new wtf.etil.mirai.server.util.XoRoShiRoRandom(); // JettPack
|
||||
}
|
||||
|
||||
MinecraftServer minecraftServer = this.level.getServer();
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
||||
index ac41bc23d2f7e16bbacdc9b33fcf6c0d706fa023..010c4761ba43c9c856e2daf33615967b4687fb82 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
||||
@@ -204,7 +204,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
||||
}
|
||||
// Paper end
|
||||
|
||||
- private static final Random rand = new Random();
|
||||
+ private static final Random rand = new wtf.etil.mirai.server.util.XoRoShiRoRandom(); // JettPack
|
||||
|
||||
public CraftWorld(ServerLevel world, ChunkGenerator gen, BiomeProvider biomeProvider, 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 be86114eac3975b82ca74d4d6ed3f0402a642e8a..9120c11c2c37252c41835536d581d51f8e9f9ef7 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 wtf.etil.mirai.server.util.XoRoShiRoRandom(); // JettPack
|
||||
private final CraftItemStack item;
|
||||
|
||||
public CraftFirework(CraftServer server, FireworkRocketEntity entity) {
|
||||
diff --git a/src/main/java/wtf/etil/mirai/server/util/SplitMixRandom.java b/src/main/java/wtf/etil/mirai/server/util/SplitMixRandom.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..57fe47e8d93e61c457f888559bbc7e840e0461ca
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/wtf/etil/mirai/server/util/SplitMixRandom.java
|
||||
@@ -0,0 +1,38 @@
|
||||
+package wtf.etil.mirai.server.util;
|
||||
+
|
||||
+import it.unimi.dsi.fastutil.HashCommon;
|
||||
+
|
||||
+/*
|
||||
+Note, this implementation was taken from sodium under the LGPLv3 License: https://github.com/CaffeineMC/sodium-fabric/blob/6390562feee9537461a7822b43d2f87691378e55/src/main/java/me/jellysquid/mods/sodium/client/util/rand/XoRoShiRoRandom.java
|
||||
+SplitMixRandom implementation from DSI Utilities, adopted in a minimal implementation to not import Apache Commons.
|
||||
+
|
||||
+http://xoshiro.di.unimi.it/
|
||||
+*/
|
||||
+public class SplitMixRandom {
|
||||
+ private static final long PHI = 0x9E3779B97F4A7C15L;
|
||||
+
|
||||
+ private long x;
|
||||
+
|
||||
+ public SplitMixRandom(final long seed) {
|
||||
+ this.setSeed(seed);
|
||||
+ }
|
||||
+
|
||||
+ private static long staffordMix13(long z) {
|
||||
+ z = (z ^ (z >>> 30)) * 0xBF58476D1CE4E5B9L;
|
||||
+ z = (z ^ (z >>> 27)) * 0x94D049BB133111EBL;
|
||||
+
|
||||
+ return z ^ (z >>> 31);
|
||||
+ }
|
||||
+
|
||||
+ public long nextLong() {
|
||||
+ return staffordMix13(this.x += PHI);
|
||||
+ }
|
||||
+
|
||||
+ public void setSeed(final long seed) {
|
||||
+ this.x = HashCommon.murmurHash3(seed);
|
||||
+ }
|
||||
+
|
||||
+ public void setState(final long state) {
|
||||
+ this.x = state;
|
||||
+ }
|
||||
+}
|
||||
\ No newline at end of file
|
||||
diff --git a/src/main/java/wtf/etil/mirai/server/util/XoRoShiRoRandom.java b/src/main/java/wtf/etil/mirai/server/util/XoRoShiRoRandom.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..c880f054d784e5e20ee656c81b1c4e55cb9e76d2
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/wtf/etil/mirai/server/util/XoRoShiRoRandom.java
|
||||
@@ -0,0 +1,154 @@
|
||||
+package wtf.etil.mirai.server.util;
|
||||
+
|
||||
+import java.util.Random;
|
||||
+
|
||||
+/*
|
||||
+Note, this implementation was taken from sodium under the LGPLv3 License: https://github.com/CaffeineMC/sodium-fabric/blob/6390562feee9537461a7822b43d2f87691378e55/src/main/java/me/jellysquid/mods/sodium/client/util/rand/XoRoShiRoRandom.java
|
||||
+
|
||||
+XoRoShiRo128** implementation from DSI Utilities, adopted in a minimal implementation to not import Apache Commons.
|
||||
+
|
||||
+http://xoshiro.di.unimi.it/
|
||||
+*/
|
||||
+public class XoRoShiRoRandom extends Random {
|
||||
+ private static final long serialVersionUID = 1L;
|
||||
+
|
||||
+ private SplitMixRandom mixer;
|
||||
+ private long seed = Long.MIN_VALUE;
|
||||
+ private long p0, p1; // The initialization words for the current seed
|
||||
+ private long s0, s1; // The current random words
|
||||
+ private boolean hasSavedState; // True if we can be quickly reseed by using resetting the words
|
||||
+
|
||||
+ private static final SplitMixRandom seedUniquifier = new SplitMixRandom(System.nanoTime());
|
||||
+
|
||||
+ public static long randomSeed() {
|
||||
+ final long x;
|
||||
+
|
||||
+ synchronized (XoRoShiRoRandom.seedUniquifier) {
|
||||
+ x = XoRoShiRoRandom.seedUniquifier.nextLong();
|
||||
+ }
|
||||
+
|
||||
+ return x ^ System.nanoTime();
|
||||
+ }
|
||||
+
|
||||
+ public XoRoShiRoRandom() {
|
||||
+ this(XoRoShiRoRandom.randomSeed());
|
||||
+ }
|
||||
+
|
||||
+ public XoRoShiRoRandom(final long seed) {
|
||||
+ this.setSeed(seed);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public long nextLong() {
|
||||
+ final long s0 = this.s0;
|
||||
+
|
||||
+ long s1 = this.s1;
|
||||
+
|
||||
+ final long result = s0 + s1;
|
||||
+
|
||||
+ s1 ^= s0;
|
||||
+
|
||||
+ this.s0 = Long.rotateLeft(s0, 24) ^ s1 ^ s1 << 16;
|
||||
+ this.s1 = Long.rotateLeft(s1, 37);
|
||||
+
|
||||
+ return result;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public int nextInt() {
|
||||
+ return (int) this.nextLong();
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public int nextInt(final int n) {
|
||||
+ return (int) this.nextLong(n);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public long nextLong(final long n) {
|
||||
+ if (n <= 0) {
|
||||
+ throw new IllegalArgumentException("illegal bound " + n + " (must be positive)");
|
||||
+ }
|
||||
+
|
||||
+ long t = this.nextLong();
|
||||
+
|
||||
+ final long nMinus1 = n - 1;
|
||||
+
|
||||
+ // Shortcut for powers of two--high bits
|
||||
+ if ((n & nMinus1) == 0) {
|
||||
+ return (t >>> Long.numberOfLeadingZeros(nMinus1)) & nMinus1;
|
||||
+ }
|
||||
+
|
||||
+ // Rejection-based algorithm to get uniform integers in the general case
|
||||
+ long u = t >>> 1;
|
||||
+
|
||||
+ while (u + nMinus1 - (t = u % n) < 0) {
|
||||
+ u = this.nextLong() >>> 1;
|
||||
+ }
|
||||
+
|
||||
+ return t;
|
||||
+
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public double nextDouble() {
|
||||
+ return Double.longBitsToDouble(0x3FFL << 52 | this.nextLong() >>> 12) - 1.0;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public float nextFloat() {
|
||||
+ return (this.nextLong() >>> 40) * 0x1.0p-24f;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public boolean nextBoolean() {
|
||||
+ return this.nextLong() < 0;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void nextBytes(final byte[] bytes) {
|
||||
+ int i = bytes.length, n;
|
||||
+
|
||||
+ while (i != 0) {
|
||||
+ n = Math.min(i, 8);
|
||||
+
|
||||
+ for (long bits = this.nextLong(); n-- != 0; bits >>= 8) {
|
||||
+ bytes[--i] = (byte) bits;
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void setSeed(final long seed) {
|
||||
+ // Restore the previous initial state if the seed hasn't changed
|
||||
+ // Setting and mixing the seed is expensive, so this saves some CPU cycles
|
||||
+ if (this.hasSavedState && this.seed == seed) {
|
||||
+ this.s0 = this.p0;
|
||||
+ this.s1 = this.p1;
|
||||
+ } else {
|
||||
+ SplitMixRandom mixer = this.mixer;
|
||||
+
|
||||
+ // Avoid allocations of SplitMixRandom
|
||||
+ if (mixer == null) {
|
||||
+ mixer = this.mixer = new SplitMixRandom(seed);
|
||||
+ } else {
|
||||
+ mixer.setSeed(seed);
|
||||
+ }
|
||||
+
|
||||
+ this.s0 = mixer.nextLong();
|
||||
+ this.s1 = mixer.nextLong();
|
||||
+
|
||||
+ this.p0 = this.s0;
|
||||
+ this.p1 = this.s1;
|
||||
+
|
||||
+ this.seed = seed;
|
||||
+ this.hasSavedState = true;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ public XoRoShiRoRandom setSeedAndReturn(final long seed) {
|
||||
+ this.setSeed(seed);
|
||||
+
|
||||
+ return this;
|
||||
+ }
|
||||
+}
|
||||
\ No newline at end of file
|
||||
@@ -1,513 +0,0 @@
|
||||
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
|
||||
|
||||
Original code by YatopiaMC, licensed under MIT
|
||||
You can find the original code on https://github.com/YatopiaMC/Yatopia
|
||||
|
||||
diff --git a/src/main/java/com/destroystokyo/paper/loottable/PaperLootableInventoryData.java b/src/main/java/com/destroystokyo/paper/loottable/PaperLootableInventoryData.java
|
||||
index 20cfe7b9b7127ddeb97aa91d759fc17b4a548eaf..ad89f296c6cde5698326891183d3c55bd8c9ed7a 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(); // Mirai
|
||||
|
||||
private long lastFill = -1;
|
||||
private long nextRefill = -1;
|
||||
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
index 40fe4111a52ab754094d462b0d1889e740797d4d..98bebaab40390418681b2ee42af0dd4b14df6330 100644
|
||||
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
@@ -415,7 +415,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||||
this.onMetricsRecordingFinished = (path) -> {
|
||||
};
|
||||
this.status = new ServerStatus();
|
||||
- this.random = new Random();
|
||||
+ this.random = new org.yatopiamc.yatopia.server.util.FastRandom(); // Mirai
|
||||
this.port = -1;
|
||||
this.levels = Maps.newLinkedHashMap(); // CraftBukkit - keep order, k+v already use identity methods
|
||||
this.running = true;
|
||||
@@ -650,7 +650,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||||
|
||||
if (worlddimension == null) {
|
||||
dimensionmanager = (DimensionType) this.registryHolder.registryOrThrow(Registry.DIMENSION_TYPE_REGISTRY).getOrThrow(DimensionType.OVERWORLD_LOCATION);
|
||||
- chunkgenerator = WorldGenSettings.makeDefaultOverworld(this.registryHolder, (new Random()).nextLong());
|
||||
+ chunkgenerator = WorldGenSettings.makeDefaultOverworld(this.registryHolder, (new org.yatopiamc.yatopia.server.util.FastRandom()).nextLong()); // Mirai
|
||||
} else {
|
||||
dimensionmanager = worlddimension.type();
|
||||
chunkgenerator = worlddimension.generator();
|
||||
@@ -778,7 +778,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||||
ChunkPos chunkcoordintpair = new ChunkPos(chunkgenerator.climateSampler().findSpawnPosition());
|
||||
// CraftBukkit start
|
||||
if (world.generator != null) {
|
||||
- Random rand = new Random(world.getSeed());
|
||||
+ Random rand = new org.yatopiamc.yatopia.server.util.FastRandom(world.getSeed()); // Mirai
|
||||
org.bukkit.Location spawn = world.generator.getFixedSpawnLocation(world.getWorld(), rand);
|
||||
|
||||
if (spawn != null) {
|
||||
diff --git a/src/main/java/net/minecraft/server/commands/SpreadPlayersCommand.java b/src/main/java/net/minecraft/server/commands/SpreadPlayersCommand.java
|
||||
index 62f26f5d3ef5546f26424185e378fea64c08ce2f..e897dee08dfd1ed80b6a2d2c505a7f7c844b0f77 100644
|
||||
--- a/src/main/java/net/minecraft/server/commands/SpreadPlayersCommand.java
|
||||
+++ b/src/main/java/net/minecraft/server/commands/SpreadPlayersCommand.java
|
||||
@@ -55,7 +55,7 @@ public class SpreadPlayersCommand {
|
||||
}
|
||||
|
||||
private static int spreadPlayers(CommandSourceStack source, Vec2 center, float spreadDistance, float maxRange, int maxY, boolean respectTeams, Collection<? extends Entity> players) throws CommandSyntaxException {
|
||||
- Random random = new Random();
|
||||
+ Random random = new org.yatopiamc.yatopia.server.util.FastRandom(); // Mirai
|
||||
double d0 = (double) (center.x - maxRange);
|
||||
double d1 = (double) (center.y - maxRange);
|
||||
double d2 = (double) (center.x + maxRange);
|
||||
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
||||
index 7b23535a680d2a8534dcb8dd87770f66fb982c13..1615be3540b878ce3182676d235365046d636c12 100644
|
||||
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
||||
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
||||
@@ -368,7 +368,7 @@ public class ServerPlayer extends Player {
|
||||
long l = k * k;
|
||||
int i1 = l > 2147483647L ? Integer.MAX_VALUE : (int) l;
|
||||
int j1 = this.getCoprime(i1);
|
||||
- int k1 = (new Random()).nextInt(i1);
|
||||
+ int k1 = (new org.yatopiamc.yatopia.server.util.FastRandom()).nextInt(i1); // Mirai
|
||||
|
||||
for (int l1 = 0; l1 < i1; ++l1) {
|
||||
int i2 = (k1 + j1 * l1) % i1;
|
||||
@@ -405,7 +405,7 @@ public class ServerPlayer extends Player {
|
||||
long l = k * k;
|
||||
int i1 = l > 2147483647L ? Integer.MAX_VALUE : (int) l;
|
||||
int j1 = this.getCoprime(i1);
|
||||
- int k1 = (new Random()).nextInt(i1);
|
||||
+ int k1 = (new org.yatopiamc.yatopia.server.util.FastRandom()).nextInt(i1); // Mirai
|
||||
|
||||
for (int l1 = 0; l1 < i1; ++l1) {
|
||||
int i2 = (k1 + j1 * l1) % i1;
|
||||
diff --git a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
||||
index 462d8c36166c63a4dc8fa74ac7f82859e6f4b83a..9dcae48cd94c411176368312adf9f44b11af5760 100644
|
||||
--- a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
||||
+++ b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
||||
@@ -52,7 +52,7 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener
|
||||
private static final AtomicInteger UNIQUE_THREAD_ID = new AtomicInteger(0);
|
||||
static final Logger LOGGER = LogManager.getLogger();
|
||||
private static final int MAX_TICKS_BEFORE_LOGIN = 600;
|
||||
- private static final Random RANDOM = new Random();
|
||||
+ private static final Random RANDOM = new org.yatopiamc.yatopia.server.util.FastRandom(); // Mirai
|
||||
private final byte[] nonce = new byte[4];
|
||||
final MinecraftServer server;
|
||||
public final Connection connection;
|
||||
diff --git a/src/main/java/net/minecraft/server/rcon/thread/QueryThreadGs4.java b/src/main/java/net/minecraft/server/rcon/thread/QueryThreadGs4.java
|
||||
index 25ae440839f1d286550a77d0a4c61e1dc02b369d..4c6d10d3ce7a9b5cc4cc04d57fe06ec07a2793e2 100644
|
||||
--- a/src/main/java/net/minecraft/server/rcon/thread/QueryThreadGs4.java
|
||||
+++ b/src/main/java/net/minecraft/server/rcon/thread/QueryThreadGs4.java
|
||||
@@ -348,7 +348,7 @@ public class QueryThreadGs4 extends GenericThread {
|
||||
this.identBytes[2] = bs[5];
|
||||
this.identBytes[3] = bs[6];
|
||||
this.ident = new String(this.identBytes, StandardCharsets.UTF_8);
|
||||
- this.challenge = (new Random()).nextInt(16777216);
|
||||
+ this.challenge = (new org.yatopiamc.yatopia.server.util.FastRandom()).nextInt(16777216); // Mirai
|
||||
this.challengeBytes = String.format("\t%s%d\u0000", this.ident, this.challenge).getBytes(StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/util/Mth.java b/src/main/java/net/minecraft/util/Mth.java
|
||||
index 19f77e377342ee461f0da8bc5378f2002fb9e94a..37364bcaab17be5dddea25f12ccb853f712bfe33 100644
|
||||
--- a/src/main/java/net/minecraft/util/Mth.java
|
||||
+++ b/src/main/java/net/minecraft/util/Mth.java
|
||||
@@ -31,7 +31,7 @@ public class Mth {
|
||||
}
|
||||
|
||||
});
|
||||
- private static final Random RANDOM = new Random();
|
||||
+ private static final Random RANDOM = new org.yatopiamc.yatopia.server.util.FastRandom(); // Mirai
|
||||
public static float[] getSinTable() { return SIN; }
|
||||
private static final int[] MULTIPLY_DE_BRUIJN_BIT_POSITION = new int[]{0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9};
|
||||
private static final double ONE_SIXTH = 0.16666666666666666D;
|
||||
@@ -758,7 +758,7 @@ public class Mth {
|
||||
}
|
||||
|
||||
public static double wobble(double d) {
|
||||
- return d + (2.0D * (new Random((long)floor(d * 3000.0D))).nextDouble() - 1.0D) * 1.0E-7D / 2.0D;
|
||||
+ return d + (2.0D * (new org.yatopiamc.yatopia.server.util.FastRandom((long)floor(d * 3000.0D))).nextDouble() - 1.0D) * 1.0E-7D / 2.0D; // Mirai
|
||||
}
|
||||
|
||||
public static int roundToward(int value, int divisor) {
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
|
||||
index 136ec7851f26c39b5b9a02ec791682fd5be2dbf1..879cf684753ba9cb0d5d1803651c93a230c531c2 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
||||
@@ -158,7 +158,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, i
|
||||
}
|
||||
|
||||
// Paper start
|
||||
- public static Random SHARED_RANDOM = new Random() {
|
||||
+ public static Random SHARED_RANDOM = new org.yatopiamc.yatopia.server.util.FastRandom() { // Mirai
|
||||
private boolean locked = false;
|
||||
@Override
|
||||
public synchronized void setSeed(long seed) {
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/ai/behavior/ShufflingList.java b/src/main/java/net/minecraft/world/entity/ai/behavior/ShufflingList.java
|
||||
index 204ca4fbd89bdadd902529f1f191df46fce3cace..087dc4fdb0ce52fdd531d6dcb3e089948906f9ad 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/ai/behavior/ShufflingList.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/ai/behavior/ShufflingList.java
|
||||
@@ -13,7 +13,7 @@ import java.util.stream.Stream;
|
||||
|
||||
public class ShufflingList<U> {
|
||||
public final List<ShufflingList.WeightedEntry<U>> entries; // Paper - public
|
||||
- private final Random random = new Random();
|
||||
+ private final Random random = new org.yatopiamc.yatopia.server.util.FastRandom(); // Mirai
|
||||
private final boolean isUnsafe; // Paper
|
||||
|
||||
public ShufflingList() {
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/ai/sensing/Sensor.java b/src/main/java/net/minecraft/world/entity/ai/sensing/Sensor.java
|
||||
index f3b8e253a5bfc3f68121dbe656ae7e2ac0f0eb1c..888bc1c81cef04679e0e55614d5c111d7d210ba5 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/ai/sensing/Sensor.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/ai/sensing/Sensor.java
|
||||
@@ -8,7 +8,7 @@ import net.minecraft.world.entity.ai.memory.MemoryModuleType;
|
||||
import net.minecraft.world.entity.ai.targeting.TargetingConditions;
|
||||
|
||||
public abstract class Sensor<E extends LivingEntity> {
|
||||
- private static final Random RANDOM = new Random();
|
||||
+ private static final Random RANDOM = new org.yatopiamc.yatopia.server.util.FastRandom(); // Mirai
|
||||
private static final int DEFAULT_SCAN_RATE = 20;
|
||||
protected static final int TARGETING_RANGE = 16;
|
||||
private static final TargetingConditions TARGET_CONDITIONS = TargetingConditions.forNonCombat().range(16.0D);
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/monster/piglin/PiglinAi.java b/src/main/java/net/minecraft/world/entity/monster/piglin/PiglinAi.java
|
||||
index f362e007aece208036a37d9bda8bb481a78eeaff..dd41941fbd4a568dcf2239eca03be593c9782af9 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/monster/piglin/PiglinAi.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/monster/piglin/PiglinAi.java
|
||||
@@ -374,7 +374,7 @@ public class PiglinAi {
|
||||
}
|
||||
|
||||
private static boolean wantsToDance(LivingEntity piglin, LivingEntity target) {
|
||||
- return target.getType() != EntityType.HOGLIN ? false : (new Random(piglin.level.getGameTime())).nextFloat() < 0.1F;
|
||||
+ return target.getType() != EntityType.HOGLIN ? false : (new org.yatopiamc.yatopia.server.util.FastRandom(piglin.level.getGameTime())).nextFloat() < 0.1F; // Mirai
|
||||
}
|
||||
|
||||
protected static boolean wantsToPickup(Piglin piglin, ItemStack stack) {
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/npc/WanderingTraderSpawner.java b/src/main/java/net/minecraft/world/entity/npc/WanderingTraderSpawner.java
|
||||
index 323eea2bccacfcc85849b5d82c2b30d991e0c0d8..6a4e2d8c2d53e4dedea71e7ee82132a7abfb2cd3 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/npc/WanderingTraderSpawner.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/npc/WanderingTraderSpawner.java
|
||||
@@ -35,7 +35,7 @@ public class WanderingTraderSpawner implements CustomSpawner {
|
||||
private static final int SPAWN_CHANCE_INCREASE = 25;
|
||||
private static final int SPAWN_ONE_IN_X_CHANCE = 10;
|
||||
private static final int NUMBER_OF_SPAWN_ATTEMPTS = 10;
|
||||
- private final Random random = new Random();
|
||||
+ private final Random random = new org.yatopiamc.yatopia.server.util.FastRandom(); // Mirai
|
||||
private final ServerLevelData serverLevelData;
|
||||
private int tickDelay;
|
||||
private int spawnDelay;
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java b/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java
|
||||
index 2015223c1703935faef52a8b88263ab3f1fbe92a..d312dcdce3e1c8a8e0cdb5c5fdf019504c50dc48 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/projectile/FishingHook.java
|
||||
@@ -76,7 +76,7 @@ public class FishingHook extends Projectile {
|
||||
|
||||
private FishingHook(EntityType<? extends FishingHook> type, Level world, int luckOfTheSeaLevel, int lureLevel) {
|
||||
super(type, world);
|
||||
- this.syncronizedRandom = new Random();
|
||||
+ this.syncronizedRandom = new org.yatopiamc.yatopia.server.util.FastRandom(); // Mirai
|
||||
this.openWater = true;
|
||||
this.currentState = FishingHook.FishHookState.FLYING;
|
||||
this.noCulling = true;
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/raid/Raid.java b/src/main/java/net/minecraft/world/entity/raid/Raid.java
|
||||
index 7131226de05bc57830f7a68ba545ebfd19d33a59..c7665038764e626dcac40f3e577c268090b89741 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/raid/Raid.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/raid/Raid.java
|
||||
@@ -110,7 +110,7 @@ public class Raid {
|
||||
|
||||
public Raid(int id, ServerLevel world, BlockPos pos) {
|
||||
this.raidEvent = new ServerBossEvent(Raid.RAID_NAME_COMPONENT, BossEvent.BossBarColor.RED, BossEvent.BossBarOverlay.NOTCHED_10);
|
||||
- this.random = new Random();
|
||||
+ this.random = new org.yatopiamc.yatopia.server.util.FastRandom(); // Mirai
|
||||
this.waveSpawnPos = Optional.empty();
|
||||
this.id = id;
|
||||
this.level = world;
|
||||
@@ -124,7 +124,7 @@ public class Raid {
|
||||
|
||||
public Raid(ServerLevel world, CompoundTag nbt) {
|
||||
this.raidEvent = new ServerBossEvent(Raid.RAID_NAME_COMPONENT, BossEvent.BossBarColor.RED, BossEvent.BossBarOverlay.NOTCHED_10);
|
||||
- this.random = new Random();
|
||||
+ this.random = new org.yatopiamc.yatopia.server.util.FastRandom(); // Mirai
|
||||
this.waveSpawnPos = Optional.empty();
|
||||
this.level = world;
|
||||
this.id = nbt.getInt("Id");
|
||||
diff --git a/src/main/java/net/minecraft/world/inventory/EnchantmentMenu.java b/src/main/java/net/minecraft/world/inventory/EnchantmentMenu.java
|
||||
index d75f14e23d94deee2b6af20c8af3bcd42c1fbbc3..9a9b88b76f9a94256ade95fe0edc407f2e4ee57e 100644
|
||||
--- a/src/main/java/net/minecraft/world/inventory/EnchantmentMenu.java
|
||||
+++ b/src/main/java/net/minecraft/world/inventory/EnchantmentMenu.java
|
||||
@@ -68,7 +68,7 @@ public class EnchantmentMenu extends AbstractContainerMenu {
|
||||
}
|
||||
// CraftBukkit end
|
||||
};
|
||||
- this.random = new Random();
|
||||
+ this.random = new org.yatopiamc.yatopia.server.util.FastRandom(); // Mirai
|
||||
this.enchantmentSeed = DataSlot.standalone();
|
||||
this.costs = new int[3];
|
||||
this.enchantClue = new int[]{-1, -1, -1};
|
||||
diff --git a/src/main/java/net/minecraft/world/level/BaseSpawner.java b/src/main/java/net/minecraft/world/level/BaseSpawner.java
|
||||
index 03726227fdd60e9cf77213d50184abff438e01ef..3c37becef230e85fb84a9d39eee0190e3061c4f9 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/BaseSpawner.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/BaseSpawner.java
|
||||
@@ -41,7 +41,7 @@ public abstract class BaseSpawner {
|
||||
public int maxNearbyEntities = 6;
|
||||
public int requiredPlayerRange = 16;
|
||||
public int spawnRange = 4;
|
||||
- private final Random random = new Random();
|
||||
+ private final Random random = new org.yatopiamc.yatopia.server.util.FastRandom(); // Mirai
|
||||
private int tickDelay = 0; // Paper
|
||||
|
||||
public BaseSpawner() {}
|
||||
diff --git a/src/main/java/net/minecraft/world/level/Explosion.java b/src/main/java/net/minecraft/world/level/Explosion.java
|
||||
index 6795132318a4e8b4c7a33b6f4b89a730ea66b97f..9f045f2dc7b9677dfd62ddcb2f3d277ba0c1076c 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/Explosion.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/Explosion.java
|
||||
@@ -88,7 +88,7 @@ public class Explosion {
|
||||
}
|
||||
|
||||
public Explosion(Level world, @Nullable Entity entity, @Nullable DamageSource damageSource, @Nullable ExplosionDamageCalculator behavior, double x, double y, double z, float power, boolean createFire, Explosion.BlockInteraction destructionType) {
|
||||
- this.random = new Random();
|
||||
+ this.random = new org.yatopiamc.yatopia.server.util.FastRandom(); // Mirai
|
||||
this.toBlow = Lists.newArrayList();
|
||||
this.hitPlayers = Maps.newHashMap();
|
||||
this.level = world;
|
||||
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
|
||||
index 96c6ef03a64e425472c64884c91ac4951950362b..519010d391853629b752ffa1bdbe70f5ef6f1b32 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/Level.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/Level.java
|
||||
@@ -123,13 +123,13 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
|
||||
public final Thread thread;
|
||||
private final boolean isDebug;
|
||||
private int skyDarken;
|
||||
- protected int randValue = (new Random()).nextInt();
|
||||
+ protected int randValue = (new org.yatopiamc.yatopia.server.util.FastRandom()).nextInt(); // Mirai
|
||||
protected final int addend = 1013904223;
|
||||
protected float oRainLevel;
|
||||
public float rainLevel;
|
||||
protected float oThunderLevel;
|
||||
public float thunderLevel;
|
||||
- public final Random random = new Random();
|
||||
+ public final Random random = new org.yatopiamc.yatopia.server.util.FastRandom(); // Mirai
|
||||
private final DimensionType dimensionType;
|
||||
public final WritableLevelData levelData;
|
||||
private final Supplier<ProfilerFiller> profiler;
|
||||
diff --git a/src/main/java/net/minecraft/world/level/block/entity/DispenserBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/DispenserBlockEntity.java
|
||||
index f74c5bb8e1ba42c77c59d481b871fd992483b128..2c7df921e948de9d7747dd32b9c4ed84c2b8196e 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/block/entity/DispenserBlockEntity.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/block/entity/DispenserBlockEntity.java
|
||||
@@ -21,7 +21,7 @@ import org.bukkit.entity.HumanEntity;
|
||||
|
||||
public class DispenserBlockEntity extends RandomizableContainerBlockEntity {
|
||||
|
||||
- private static final Random RANDOM = new Random();
|
||||
+ private static final Random RANDOM = new org.yatopiamc.yatopia.server.util.FastRandom(); // Mirai
|
||||
public static final int CONTAINER_SIZE = 9;
|
||||
private NonNullList<ItemStack> items;
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/world/level/block/entity/TheEndGatewayBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/TheEndGatewayBlockEntity.java
|
||||
index 6278115e3511fe2176b29122e2c733498f31bb5a..85abf95d161101b5632bc8f871136938600f2448 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/block/entity/TheEndGatewayBlockEntity.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/block/entity/TheEndGatewayBlockEntity.java
|
||||
@@ -265,7 +265,7 @@ public class TheEndGatewayBlockEntity extends TheEndPortalBlockEntity {
|
||||
if (blockposition1 == null) {
|
||||
blockposition1 = new BlockPos(vec3d.x + 0.5D, 75.0D, vec3d.z + 0.5D);
|
||||
TheEndGatewayBlockEntity.LOGGER.debug("Failed to find a suitable block to teleport to, spawning an island on {}", blockposition1);
|
||||
- EndFeatures.END_ISLAND.place(world, world.getChunkSource().getGenerator(), new Random(blockposition1.asLong()), blockposition1);
|
||||
+ EndFeatures.END_ISLAND.place(world, world.getChunkSource().getGenerator(), new org.yatopiamc.yatopia.server.util.FastRandom(blockposition1.asLong()), blockposition1); // Mirai
|
||||
} else {
|
||||
TheEndGatewayBlockEntity.LOGGER.debug("Found suitable block to teleport to: {}", blockposition1);
|
||||
}
|
||||
@@ -353,7 +353,7 @@ public class TheEndGatewayBlockEntity extends TheEndPortalBlockEntity {
|
||||
}
|
||||
|
||||
private static void spawnGatewayPortal(ServerLevel world, BlockPos pos, EndGatewayConfiguration config) {
|
||||
- Feature.END_GATEWAY.configured(config).place(world, world.getChunkSource().getGenerator(), new Random(), pos);
|
||||
+ Feature.END_GATEWAY.configured(config).place(world, world.getChunkSource().getGenerator(), new org.yatopiamc.yatopia.server.util.FastRandom(), pos); // Mirai
|
||||
}
|
||||
|
||||
@Override
|
||||
diff --git a/src/main/java/net/minecraft/world/level/chunk/ChunkGenerator.java b/src/main/java/net/minecraft/world/level/chunk/ChunkGenerator.java
|
||||
index e4591c0b3c8547cc6f4e2a0891fc378ee4334d9e..d8b790f0288cfffbc2720b31c6686a3524e76436 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/chunk/ChunkGenerator.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/chunk/ChunkGenerator.java
|
||||
@@ -109,7 +109,7 @@ public abstract class ChunkGenerator implements BiomeManager.NoiseBiomeSource {
|
||||
int i = structuresettingsstronghold.distance();
|
||||
int j = structuresettingsstronghold.count();
|
||||
int k = structuresettingsstronghold.spread();
|
||||
- Random random = new Random();
|
||||
+ Random random = new org.yatopiamc.yatopia.server.util.FastRandom(); // Mirai
|
||||
|
||||
random.setSeed(this.strongholdSeed);
|
||||
double d0 = random.nextDouble() * 3.141592653589793D * 2.0D;
|
||||
diff --git a/src/main/java/net/minecraft/world/level/dimension/end/EndDragonFight.java b/src/main/java/net/minecraft/world/level/dimension/end/EndDragonFight.java
|
||||
index be5952133720bf0ac3483cc2fed334967e6fc0c4..de00b1d45c13b0cdfc7eb78a667fe0d356e0507e 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/dimension/end/EndDragonFight.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/dimension/end/EndDragonFight.java
|
||||
@@ -124,7 +124,7 @@ public class EndDragonFight {
|
||||
}
|
||||
} else {
|
||||
this.gateways.addAll(ContiguousSet.create(Range.closedOpen(0, 20), DiscreteDomain.integers()));
|
||||
- Collections.shuffle(this.gateways, new Random(gatewaysSeed));
|
||||
+ Collections.shuffle(this.gateways, new org.yatopiamc.yatopia.server.util.FastRandom(gatewaysSeed)); // Mirai
|
||||
}
|
||||
|
||||
this.exitPortalPattern = BlockPatternBuilder.start().aisle(" ", " ", " ", " # ", " ", " ", " ").aisle(" ", " ", " ", " # ", " ", " ", " ").aisle(" ", " ", " ", " # ", " ", " ", " ").aisle(" ### ", " # # ", "# #", "# # #", "# #", " # # ", " ### ").aisle(" ", " ### ", " ##### ", " ##### ", " ##### ", " ### ", " ").where('#', BlockInWorld.hasState(BlockPredicate.forBlock(Blocks.BEDROCK))).build();
|
||||
@@ -402,7 +402,7 @@ public class EndDragonFight {
|
||||
|
||||
private void spawnNewGateway(BlockPos pos) {
|
||||
this.level.levelEvent(3000, pos, 0);
|
||||
- EndFeatures.END_GATEWAY_DELAYED.place(this.level, this.level.getChunkSource().getGenerator(), new Random(), pos);
|
||||
+ EndFeatures.END_GATEWAY_DELAYED.place(this.level, this.level.getChunkSource().getGenerator(), new org.yatopiamc.yatopia.server.util.FastRandom(), pos); // Mirai
|
||||
}
|
||||
|
||||
public void spawnExitPortal(boolean previouslyKilled) {
|
||||
@@ -418,7 +418,7 @@ public class EndDragonFight {
|
||||
}
|
||||
// Paper end
|
||||
|
||||
- endPodiumFeature.configured(FeatureConfiguration.NONE).place(this.level, this.level.getChunkSource().getGenerator(), new Random(), this.portalLocation);
|
||||
+ endPodiumFeature.configured(FeatureConfiguration.NONE).place(this.level, this.level.getChunkSource().getGenerator(), new org.yatopiamc.yatopia.server.util.FastRandom(), this.portalLocation); // Mirai
|
||||
}
|
||||
|
||||
private EnderDragon createNewDragon() {
|
||||
diff --git a/src/main/java/net/minecraft/world/level/levelgen/WorldGenSettings.java b/src/main/java/net/minecraft/world/level/levelgen/WorldGenSettings.java
|
||||
index 286c75989282c6d370ca64ac714ab15d784210ab..4c4c9ea4575306d08a34e19bba06a4a63f562809 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/levelgen/WorldGenSettings.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/levelgen/WorldGenSettings.java
|
||||
@@ -86,7 +86,7 @@ public class WorldGenSettings {
|
||||
}
|
||||
|
||||
public static WorldGenSettings makeDefault(RegistryAccess registryManager) {
|
||||
- long i = (new Random()).nextLong();
|
||||
+ long i = (new org.yatopiamc.yatopia.server.util.FastRandom()).nextLong(); // Mirai
|
||||
|
||||
return new WorldGenSettings(i, true, false, WorldGenSettings.withOverworld(registryManager.registryOrThrow(Registry.DIMENSION_TYPE_REGISTRY), DimensionType.defaultDimensions(registryManager, i), WorldGenSettings.makeDefaultOverworld(registryManager, i)));
|
||||
}
|
||||
@@ -215,7 +215,7 @@ public class WorldGenSettings {
|
||||
}).orElse("default");
|
||||
|
||||
properties.put("level-type", s4);
|
||||
- long i = (new Random()).nextLong();
|
||||
+ long i = (new org.yatopiamc.yatopia.server.util.FastRandom()).nextLong(); // Mirai
|
||||
|
||||
if (!s1.isEmpty()) {
|
||||
try {
|
||||
diff --git a/src/main/java/net/minecraft/world/level/levelgen/feature/SpikeFeature.java b/src/main/java/net/minecraft/world/level/levelgen/feature/SpikeFeature.java
|
||||
index c03bf5bdb67b00c75f9fcfead882c4d944282244..36af2ab1d6b80ec6d27a41371c52618ba2717a22 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/levelgen/feature/SpikeFeature.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/levelgen/feature/SpikeFeature.java
|
||||
@@ -36,7 +36,7 @@ public class SpikeFeature extends Feature<SpikeConfiguration> {
|
||||
}
|
||||
|
||||
public static List<SpikeFeature.EndSpike> getSpikesForLevel(WorldGenLevel world) {
|
||||
- Random random = new Random(world.getSeed());
|
||||
+ Random random = new org.yatopiamc.yatopia.server.util.FastRandom(world.getSeed()); // Mirai
|
||||
long l = random.nextLong() & 65535L;
|
||||
return SPIKE_CACHE.getUnchecked(l);
|
||||
}
|
||||
@@ -167,7 +167,7 @@ public class SpikeFeature extends Feature<SpikeConfiguration> {
|
||||
@Override
|
||||
public List<SpikeFeature.EndSpike> load(Long long_) {
|
||||
List<Integer> list = IntStream.range(0, 10).boxed().collect(Collectors.toList());
|
||||
- Collections.shuffle(list, new Random(long_));
|
||||
+ Collections.shuffle(list, new org.yatopiamc.yatopia.server.util.FastRandom(long_)); // Mirai
|
||||
List<SpikeFeature.EndSpike> list2 = Lists.newArrayList();
|
||||
|
||||
for(int i = 0; i < 10; ++i) {
|
||||
diff --git a/src/main/java/net/minecraft/world/level/levelgen/structure/templatesystem/StructurePlaceSettings.java b/src/main/java/net/minecraft/world/level/levelgen/structure/templatesystem/StructurePlaceSettings.java
|
||||
index c75141f96bdbee9ec070e81bd4f1ce0e7f1054fa..d10d9e4a45852555cd037247cd66ceb0e0e14c73 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/levelgen/structure/templatesystem/StructurePlaceSettings.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/levelgen/structure/templatesystem/StructurePlaceSettings.java
|
||||
@@ -120,7 +120,7 @@ public class StructurePlaceSettings {
|
||||
}
|
||||
|
||||
public Random getRandom(@Nullable BlockPos pos) {
|
||||
- return this.random != null ? this.random : (pos == null ? new Random(Util.getMillis()) : new Random(Mth.getSeed(pos)));
|
||||
+ return this.random != null ? this.random : (pos == null ? new org.yatopiamc.yatopia.server.util.FastRandom(Util.getMillis()) : new org.yatopiamc.yatopia.server.util.FastRandom(Mth.getSeed(pos))); // Mirai
|
||||
}
|
||||
|
||||
public boolean isIgnoreEntities() {
|
||||
diff --git a/src/main/java/net/minecraft/world/level/storage/loot/LootContext.java b/src/main/java/net/minecraft/world/level/storage/loot/LootContext.java
|
||||
index d33af84300db18ea2b71dba2c9ed43390a293500..91fcdd628f487599f051edaa6a529cddec22fd15 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/storage/loot/LootContext.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/storage/loot/LootContext.java
|
||||
@@ -127,7 +127,7 @@ public class LootContext {
|
||||
|
||||
public LootContext.Builder withOptionalRandomSeed(long seed) {
|
||||
if (seed != 0L) {
|
||||
- this.random = new Random(seed);
|
||||
+ this.random = new org.yatopiamc.yatopia.server.util.FastRandom(seed); // Mirai
|
||||
}
|
||||
|
||||
return this;
|
||||
@@ -137,7 +137,7 @@ public class LootContext {
|
||||
if (seed == 0L) {
|
||||
this.random = random;
|
||||
} else {
|
||||
- this.random = new Random(seed);
|
||||
+ this.random = new org.yatopiamc.yatopia.server.util.FastRandom(seed); // Mirai
|
||||
}
|
||||
|
||||
return this;
|
||||
@@ -201,7 +201,7 @@ public class LootContext {
|
||||
} else {
|
||||
Random random = this.random;
|
||||
if (random == null) {
|
||||
- random = new Random();
|
||||
+ random = new org.yatopiamc.yatopia.server.util.FastRandom(); // Mirai
|
||||
}
|
||||
|
||||
MinecraftServer minecraftServer = this.level.getServer();
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
index 6f885434f0576d2738b9c74fa9cc202e66ede262..0ab224b093e18f7e49c366c9e4862e0a97e7573c 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
@@ -1237,7 +1237,7 @@ public final class CraftServer implements Server {
|
||||
|
||||
if (worlddimension == null) {
|
||||
dimensionmanager = (DimensionType) console.registryHolder.registryOrThrow(Registry.DIMENSION_TYPE_REGISTRY).getOrThrow(DimensionType.OVERWORLD_LOCATION);
|
||||
- chunkgenerator = WorldGenSettings.makeDefaultOverworld(console.registryHolder, (new Random()).nextLong());
|
||||
+ chunkgenerator = WorldGenSettings.makeDefaultOverworld(console.registryHolder, (new org.yatopiamc.yatopia.server.util.FastRandom()).nextLong());
|
||||
} else {
|
||||
dimensionmanager = worlddimension.type();
|
||||
chunkgenerator = worlddimension.generator();
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
||||
index ac41bc23d2f7e16bbacdc9b33fcf6c0d706fa023..f9b8cc877649436b9d7bf93b429661b76e3b53cf 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
||||
@@ -204,7 +204,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
||||
}
|
||||
// Paper end
|
||||
|
||||
- private static final Random rand = new Random();
|
||||
+ private static final Random rand = new org.yatopiamc.yatopia.server.util.FastRandom(); // Mirai
|
||||
|
||||
public CraftWorld(ServerLevel world, ChunkGenerator gen, BiomeProvider biomeProvider, 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 be86114eac3975b82ca74d4d6ed3f0402a642e8a..09332333c0b39f11da2953e343e7eedcc17f02c9 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(); // Mirai
|
||||
private final CraftItemStack item;
|
||||
|
||||
public CraftFirework(CraftServer server, FireworkRocketEntity entity) {
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/generator/CustomChunkGenerator.java b/src/main/java/org/bukkit/craftbukkit/generator/CustomChunkGenerator.java
|
||||
index dd453548e1a1ac26ce611f5a96bd3ea81b0971da..be3c3ff10d81327c7869948de191ddcdec6acc9b 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/generator/CustomChunkGenerator.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/generator/CustomChunkGenerator.java
|
||||
@@ -44,7 +44,7 @@ public class CustomChunkGenerator extends InternalChunkGenerator {
|
||||
public final net.minecraft.world.level.chunk.ChunkGenerator delegate;
|
||||
private final ChunkGenerator generator;
|
||||
private final ServerLevel world;
|
||||
- private final Random random = new Random();
|
||||
+ private final Random random = new org.yatopiamc.yatopia.server.util.FastRandom(); // Mirai
|
||||
private boolean newApi;
|
||||
private boolean implementBaseHeight = true;
|
||||
|
||||
@@ -1,34 +1,19 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: foss-mc <69294560+foss-mc@users.noreply.github.com>
|
||||
Date: Thu, 1 Jul 2021 12:17:44 +0000
|
||||
From: Etil <81570777+etil2jz@users.noreply.github.com>
|
||||
Date: Wed, 5 Jan 2022 20:49:49 +0100
|
||||
Subject: [PATCH] Don't create new random instance
|
||||
|
||||
Original code by PatinaMC, licensed under GNU General Public License v3.0
|
||||
You can find the original code on https://github.com/PatinaMC/Patina
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
index 66b67c42d223dab3daf98e9088f1277b17342ac5..41557a97b1bc1d4986efa9d4a5d7691ec250882f 100644
|
||||
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
@@ -650,7 +650,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<Runnab
|
||||
|
||||
if (worlddimension == null) {
|
||||
dimensionmanager = (DimensionType) this.registryHolder.registryOrThrow(Registry.DIMENSION_TYPE_REGISTRY).getOrThrow(DimensionType.OVERWORLD_LOCATION);
|
||||
- chunkgenerator = WorldGenSettings.makeDefaultOverworld(this.registryHolder, (new org.yatopiamc.yatopia.server.util.FastRandom()).nextLong()); // Mirai
|
||||
+ chunkgenerator = WorldGenSettings.makeDefaultOverworld(this.registryHolder, java.util.concurrent.ThreadLocalRandom.current().nextLong()); // Mirai // Patina - don't create new random instance
|
||||
} else {
|
||||
dimensionmanager = worlddimension.type();
|
||||
chunkgenerator = worlddimension.generator();
|
||||
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
||||
index 1615be3540b878ce3182676d235365046d636c12..8ac654cb16195bb51bbd179ea77462bbe16f525d 100644
|
||||
index 5e9c7f428e4a0d920569c2a02e999da910fc9397..0011192cdba6dcb7ca125ae4a49ca89a93cc40f2 100644
|
||||
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
||||
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
||||
@@ -368,7 +368,7 @@ public class ServerPlayer extends Player {
|
||||
long l = k * k;
|
||||
int i1 = l > 2147483647L ? Integer.MAX_VALUE : (int) l;
|
||||
int j1 = this.getCoprime(i1);
|
||||
- int k1 = (new org.yatopiamc.yatopia.server.util.FastRandom()).nextInt(i1); // Mirai
|
||||
+ int k1 = worldserver.random.nextInt(i1); // Mirai // Patina - don't create new random instance
|
||||
- int k1 = (wtf.etil.mirai.server.util.XoRoShiRoRandom()).nextInt(i1); // JettPack
|
||||
+ int k1 = worldserver.random.nextInt(i1); // Patina - don't create new random instance
|
||||
|
||||
for (int l1 = 0; l1 < i1; ++l1) {
|
||||
int i2 = (k1 + j1 * l1) % i1;
|
||||
@@ -36,76 +21,41 @@ index 1615be3540b878ce3182676d235365046d636c12..8ac654cb16195bb51bbd179ea77462bb
|
||||
long l = k * k;
|
||||
int i1 = l > 2147483647L ? Integer.MAX_VALUE : (int) l;
|
||||
int j1 = this.getCoprime(i1);
|
||||
- int k1 = (new org.yatopiamc.yatopia.server.util.FastRandom()).nextInt(i1); // Mirai
|
||||
+ int k1 = world.random.nextInt(i1); // Mirai // Patina - don't create new random instance
|
||||
- int k1 = (wtf.etil.mirai.server.util.XoRoShiRoRandom()).nextInt(i1); // JettPack
|
||||
+ int k1 = world.random.nextInt(i1); // Patina - 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/rcon/thread/QueryThreadGs4.java b/src/main/java/net/minecraft/server/rcon/thread/QueryThreadGs4.java
|
||||
index 4c6d10d3ce7a9b5cc4cc04d57fe06ec07a2793e2..e02c1ee3c0ec3c9e32902d61ea12fa227996ad4c 100644
|
||||
index f42bce03c21309efbb208be21263b6c09927ed6c..711d5dc2a8b3a5f2a2a35cab59b5ecfdeb152141 100644
|
||||
--- a/src/main/java/net/minecraft/server/rcon/thread/QueryThreadGs4.java
|
||||
+++ b/src/main/java/net/minecraft/server/rcon/thread/QueryThreadGs4.java
|
||||
@@ -348,7 +348,7 @@ public class QueryThreadGs4 extends GenericThread {
|
||||
this.identBytes[2] = bs[5];
|
||||
this.identBytes[3] = bs[6];
|
||||
this.ident = new String(this.identBytes, StandardCharsets.UTF_8);
|
||||
- this.challenge = (new org.yatopiamc.yatopia.server.util.FastRandom()).nextInt(16777216); // Mirai
|
||||
+ this.challenge = java.util.concurrent.ThreadLocalRandom.current().nextInt(16777216); // Mirai // Patina - don't create new random instance
|
||||
- this.challenge = (wtf.etil.mirai.server.util.XoRoShiRoRandom()).nextInt(16777216); // JettPack
|
||||
+ this.challenge = java.util.concurrent.ThreadLocalRandom.current().nextInt(16777216); // Patina - don't create new random instance
|
||||
this.challengeBytes = String.format("\t%s%d\u0000", this.ident, this.challenge).getBytes(StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
|
||||
index 519010d391853629b752ffa1bdbe70f5ef6f1b32..d4704fb641e25679367ffa92be485bc329c97e2c 100644
|
||||
index 1b6fc6511c32e6509f773d5259e7a07c3b8e79bf..bda7ec47f0a91055a4e86b8968c695a71c2c95aa 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/Level.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/Level.java
|
||||
@@ -123,13 +123,14 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
|
||||
public final Thread thread;
|
||||
private final boolean isDebug;
|
||||
private int skyDarken;
|
||||
- protected int randValue = (new org.yatopiamc.yatopia.server.util.FastRandom()).nextInt(); // Mirai
|
||||
+ //protected int randValue = (new org.yatopiamc.yatopia.server.util.FastRandom()).nextInt(); // Mirai // Patina - moved down
|
||||
- protected int randValue = (new wtf.etil.mirai.server.util.XoRoShiRoRandom()).nextInt(); // JettPack
|
||||
+ //protected int randValue = (wtf.etil.mirai.server.util.XoRoShiRoRandom()).nextInt(); // JettPack // Patina - moved down
|
||||
protected final int addend = 1013904223;
|
||||
protected float oRainLevel;
|
||||
public float rainLevel;
|
||||
protected float oThunderLevel;
|
||||
public float thunderLevel;
|
||||
public final Random random = new org.yatopiamc.yatopia.server.util.FastRandom(); // Mirai
|
||||
public final Random random = new wtf.etil.mirai.server.util.XoRoShiRoRandom(); // JettPack
|
||||
+ protected int randValue = random.nextInt(); // Patina - don't create new random instance
|
||||
private final DimensionType dimensionType;
|
||||
public final WritableLevelData levelData;
|
||||
private final Supplier<ProfilerFiller> profiler;
|
||||
diff --git a/src/main/java/net/minecraft/world/level/levelgen/WorldGenSettings.java b/src/main/java/net/minecraft/world/level/levelgen/WorldGenSettings.java
|
||||
index 4c4c9ea4575306d08a34e19bba06a4a63f562809..e06db106202d1227e3ca061d98c1006783fe7dde 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/levelgen/WorldGenSettings.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/levelgen/WorldGenSettings.java
|
||||
@@ -86,7 +86,7 @@ public class WorldGenSettings {
|
||||
}
|
||||
|
||||
public static WorldGenSettings makeDefault(RegistryAccess registryManager) {
|
||||
- long i = (new org.yatopiamc.yatopia.server.util.FastRandom()).nextLong(); // Mirai
|
||||
+ long i = java.util.concurrent.ThreadLocalRandom.current().nextLong(); // Mirai // Patina - don't create new random instance
|
||||
|
||||
return new WorldGenSettings(i, true, false, WorldGenSettings.withOverworld(registryManager.registryOrThrow(Registry.DIMENSION_TYPE_REGISTRY), DimensionType.defaultDimensions(registryManager, i), WorldGenSettings.makeDefaultOverworld(registryManager, i)));
|
||||
}
|
||||
@@ -215,7 +215,7 @@ public class WorldGenSettings {
|
||||
}).orElse("default");
|
||||
|
||||
properties.put("level-type", s4);
|
||||
- long i = (new org.yatopiamc.yatopia.server.util.FastRandom()).nextLong(); // Mirai
|
||||
+ long i = java.util.concurrent.ThreadLocalRandom.current().nextLong(); // Mirai // Patina - don't create new random instance
|
||||
|
||||
if (!s1.isEmpty()) {
|
||||
try {
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
index 0ab224b093e18f7e49c366c9e4862e0a97e7573c..8219faec47215d7ac618d54ae996d156e3a631ff 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
@@ -1237,7 +1237,7 @@ public final class CraftServer implements Server {
|
||||
|
||||
if (worlddimension == null) {
|
||||
dimensionmanager = (DimensionType) console.registryHolder.registryOrThrow(Registry.DIMENSION_TYPE_REGISTRY).getOrThrow(DimensionType.OVERWORLD_LOCATION);
|
||||
- chunkgenerator = WorldGenSettings.makeDefaultOverworld(console.registryHolder, (new org.yatopiamc.yatopia.server.util.FastRandom()).nextLong());
|
||||
+ chunkgenerator = WorldGenSettings.makeDefaultOverworld(console.registryHolder, java.util.concurrent.ThreadLocalRandom.current().nextLong()); // Mirai // Patina - don't create new random instance
|
||||
} else {
|
||||
dimensionmanager = worlddimension.type();
|
||||
chunkgenerator = worlddimension.generator();
|
||||
|
||||
@@ -7,10 +7,10 @@ Original code by YatopiaMC, licensed under MIT
|
||||
You can find the original code on https://github.com/YatopiaMC/Yatopia
|
||||
|
||||
diff --git a/build.gradle.kts b/build.gradle.kts
|
||||
index ea185d933980fa453e933e0e503d7eaa17f6f14f..4f85686bac51abf5e6d00fcbaefca53fd43b29f4 100644
|
||||
index 6a8786790cfeb4373d23d7e743f06b19efa45c35..6e66a19c1c9ce284359e3b65552df68a40804aab 100644
|
||||
--- a/build.gradle.kts
|
||||
+++ b/build.gradle.kts
|
||||
@@ -107,6 +107,7 @@ relocation {
|
||||
@@ -106,6 +106,7 @@ relocation {
|
||||
relocate("org.bukkit.craftbukkit" to "org.bukkit.craftbukkit.v$packageVersion") {
|
||||
exclude("org.bukkit.craftbukkit.Main*")
|
||||
}
|
||||
|
||||
@@ -1,368 +0,0 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: FX - PR0CESS <fx.e.morin@gmail.com>
|
||||
Date: Tue, 21 Dec 2021 17:59:30 +0100
|
||||
Subject: [PATCH] lithium: fast math
|
||||
|
||||
Original code by CaffeineMC, licensed under GNU Lesser General Public License v3.0
|
||||
You can find the original code on https://github.com/CaffeineMC/lithium-fabric (Yarn mappings)
|
||||
|
||||
diff --git a/src/main/java/com/destroystokyo/paper/PaperCommand.java b/src/main/java/com/destroystokyo/paper/PaperCommand.java
|
||||
index 7764b1f86aca33dc227bf4357c20839b8820eb67..9fc782fadc1daffb12ce02a6b1c3b4c4e60d8ae7 100644
|
||||
--- a/src/main/java/com/destroystokyo/paper/PaperCommand.java
|
||||
+++ b/src/main/java/com/destroystokyo/paper/PaperCommand.java
|
||||
@@ -725,12 +725,12 @@ public class PaperCommand extends Command {
|
||||
++relitChunks[0];
|
||||
sender.getBukkitEntity().sendMessage(
|
||||
ChatColor.BLUE + "Relit chunk " + ChatColor.DARK_AQUA + chunkPos + ChatColor.BLUE +
|
||||
- ", progress: " + ChatColor.DARK_AQUA + (int)(Math.round(100.0 * (double)(relitChunks[0])/(double)pending[0])) + "%"
|
||||
+ ", progress: " + ChatColor.DARK_AQUA + (int)(wtf.etil.mirai.server.util.math.FastMath.round(100.0 * (double)(relitChunks[0])/(double)pending[0])) + "%"
|
||||
);
|
||||
},
|
||||
(int totalRelit) -> {
|
||||
final long end = System.nanoTime();
|
||||
- final long diff = Math.round(1.0e-6*(end - start));
|
||||
+ final long diff = wtf.etil.mirai.server.util.math.FastMath.round(1.0e-6*(end - start));
|
||||
sender.getBukkitEntity().sendMessage(
|
||||
ChatColor.BLUE + "Relit " + ChatColor.DARK_AQUA + totalRelit + ChatColor.BLUE + " chunks. Took " +
|
||||
ChatColor.DARK_AQUA + diff + "ms"
|
||||
diff --git a/src/main/java/com/destroystokyo/paper/gui/RAMDetails.java b/src/main/java/com/destroystokyo/paper/gui/RAMDetails.java
|
||||
index f9251183df72ddc56662fd3f02acf21641a2200c..ca7d580c77519a7ee9e6003ca67c5da8cbaae9e0 100644
|
||||
--- a/src/main/java/com/destroystokyo/paper/gui/RAMDetails.java
|
||||
+++ b/src/main/java/com/destroystokyo/paper/gui/RAMDetails.java
|
||||
@@ -81,6 +81,6 @@ public class RAMDetails extends JList<String> {
|
||||
}
|
||||
|
||||
private static String format(double tps) {
|
||||
- return ( ( tps > 21.0 ) ? "*" : "" ) + Math.min( Math.round( tps * 100.0 ) / 100.0, 20.0 );
|
||||
+ return ( ( tps > 21.0 ) ? "*" : "" ) + Math.min( wtf.etil.mirai.server.util.math.FastMath.round( tps * 100.0 ) / 100.0, 20.0 );
|
||||
}
|
||||
}
|
||||
diff --git a/src/main/java/com/destroystokyo/paper/gui/RAMGraph.java b/src/main/java/com/destroystokyo/paper/gui/RAMGraph.java
|
||||
index c3e54da4ab6440811aab2f9dd1e218802ac13285..5780eeebb40e4a218ed02d33d7bd8f1dd01cf056 100644
|
||||
--- a/src/main/java/com/destroystokyo/paper/gui/RAMGraph.java
|
||||
+++ b/src/main/java/com/destroystokyo/paper/gui/RAMGraph.java
|
||||
@@ -128,7 +128,7 @@ public class RAMGraph extends JComponent {
|
||||
graphics.setColor(data.getLineColor());
|
||||
graphics.fillOval(m.x - 2, 100 - used - 2, 5, 5);
|
||||
setToolTipText(String.format("<html><body>Used: %s mb (%s%%)<br/>%s</body></html>",
|
||||
- Math.round(data.getUsedMem() / 1024F / 1024F),
|
||||
+ wtf.etil.mirai.server.util.math.FastMath.round(data.getUsedMem() / 1024F / 1024F),
|
||||
used, getTime(m.x)));
|
||||
}
|
||||
}
|
||||
diff --git a/src/main/java/gg/pufferfish/pufferfish/flare/collectors/TPSCollector.java b/src/main/java/gg/pufferfish/pufferfish/flare/collectors/TPSCollector.java
|
||||
index 40447d00aefb5ffedb8a2ee87155a04088f0649f..3a8c0aedb51c65c3b5cc6922068ece771f97bf49 100644
|
||||
--- a/src/main/java/gg/pufferfish/pufferfish/flare/collectors/TPSCollector.java
|
||||
+++ b/src/main/java/gg/pufferfish/pufferfish/flare/collectors/TPSCollector.java
|
||||
@@ -25,7 +25,7 @@ public class TPSCollector extends LiveCollector {
|
||||
long[] times = MinecraftServer.getServer().tickTimes5s.getTimes();
|
||||
double mspt = ((double) Arrays.stream(times).sum() / (double) times.length) * 1.0E-6D;
|
||||
|
||||
- this.report(TPS, Math.min(20D, Math.round(Bukkit.getServer().getTPS()[0] * 100d) / 100d));
|
||||
- this.report(MSPT, (double) Math.round(mspt * 100d) / 100d);
|
||||
+ this.report(TPS, Math.min(20D, wtf.etil.mirai.server.util.math.FastMath.round(Bukkit.getServer().getTPS()[0] * 100d) / 100d));
|
||||
+ this.report(MSPT, (double) wtf.etil.mirai.server.util.math.FastMath.round(mspt * 100d) / 100d);
|
||||
}
|
||||
}
|
||||
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
index db5279dd944214802bafc75af7ec46c9eead605c..79a5bfab6c91900e40cb125ae2f77d405641bbf6 100644
|
||||
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
@@ -393,7 +393,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<Runnab
|
||||
}
|
||||
|
||||
double overuseCount = (double)overuse/(double)MAX_CHUNK_EXEC_TIME;
|
||||
- long extraSleep = (long)Math.round(overuseCount*CHUNK_TASK_QUEUE_BACKOFF_MIN_TIME);
|
||||
+ long extraSleep = (long)wtf.etil.mirai.server.util.math.FastMath.round(overuseCount*CHUNK_TASK_QUEUE_BACKOFF_MIN_TIME);
|
||||
|
||||
lastMidTickExecute = currTime + extraSleep;
|
||||
return;
|
||||
diff --git a/src/main/java/net/minecraft/server/gui/StatsComponent.java b/src/main/java/net/minecraft/server/gui/StatsComponent.java
|
||||
index 88f10d729aa1e0a01790521821d691a0ecd373a2..b990694dc5fc0568f346d3a4fa734f837ccb7040 100644
|
||||
--- a/src/main/java/net/minecraft/server/gui/StatsComponent.java
|
||||
+++ b/src/main/java/net/minecraft/server/gui/StatsComponent.java
|
||||
@@ -88,7 +88,7 @@ public class StatsComponent extends JComponent {
|
||||
|
||||
// Paper - start Add tps entry
|
||||
private static String format(double tps) {
|
||||
- return (( tps > 21.0 ) ? "*" : "") + Math.min(Math.round(tps * 100.0) / 100.0, 20.0); // only print * at 21, we commonly peak to 20.02 as the tick sleep is not accurate enough, stop the noise
|
||||
+ return (( tps > 21.0 ) ? "*" : "") + Math.min(wtf.etil.mirai.server.util.math.FastMath.round(tps * 100.0) / 100.0, 20.0); // only print * at 21, we commonly peak to 20.02 as the tick sleep is not accurate enough, stop the noise
|
||||
}
|
||||
// Paper end
|
||||
}
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
||||
index b9cc4aa7cd5694976c43f834bbf60412992c269f..fb62ae09dde3550fade48ae5a120ddb49b2d3dd1 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
||||
@@ -1472,7 +1472,7 @@ public abstract class LivingEntity extends Entity {
|
||||
if (this instanceof ServerPlayer) {
|
||||
CriteriaTriggers.ENTITY_HURT_PLAYER.trigger((ServerPlayer) this, source, f1, amount, flag);
|
||||
if (f2 > 0.0F && f2 < 3.4028235E37F) {
|
||||
- ((ServerPlayer) this).awardStat(Stats.DAMAGE_BLOCKED_BY_SHIELD, Math.round(f2 * 10.0F));
|
||||
+ ((ServerPlayer) this).awardStat(Stats.DAMAGE_BLOCKED_BY_SHIELD, wtf.etil.mirai.server.util.math.FastMath.round(f2 * 10.0F));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1985,9 +1985,9 @@ public abstract class LivingEntity extends Entity {
|
||||
|
||||
if (f3 > 0.0F && f3 < 3.4028235E37F) {
|
||||
if (this instanceof ServerPlayer) {
|
||||
- ((ServerPlayer) this).awardStat(Stats.DAMAGE_RESISTED, Math.round(f3 * 10.0F));
|
||||
+ ((ServerPlayer) this).awardStat(Stats.DAMAGE_RESISTED, wtf.etil.mirai.server.util.math.FastMath.round(f3 * 10.0F));
|
||||
} else if (source.getEntity() instanceof ServerPlayer) {
|
||||
- ((ServerPlayer) source.getEntity()).awardStat(Stats.DAMAGE_DEALT_RESISTED, Math.round(f3 * 10.0F));
|
||||
+ ((ServerPlayer) source.getEntity()).awardStat(Stats.DAMAGE_DEALT_RESISTED, wtf.etil.mirai.server.util.math.FastMath.round(f3 * 10.0F));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2097,9 +2097,9 @@ public abstract class LivingEntity extends Entity {
|
||||
float f3 = (float) -event.getDamage(DamageModifier.RESISTANCE);
|
||||
if (f3 > 0.0F && f3 < 3.4028235E37F) {
|
||||
if (this instanceof ServerPlayer) {
|
||||
- ((ServerPlayer) this).awardStat(Stats.DAMAGE_RESISTED, Math.round(f3 * 10.0F));
|
||||
+ ((ServerPlayer) this).awardStat(Stats.DAMAGE_RESISTED, wtf.etil.mirai.server.util.math.FastMath.round(f3 * 10.0F));
|
||||
} else if (damagesource.getEntity() instanceof ServerPlayer) {
|
||||
- ((ServerPlayer) damagesource.getEntity()).awardStat(Stats.DAMAGE_DEALT_RESISTED, Math.round(f3 * 10.0F));
|
||||
+ ((ServerPlayer) damagesource.getEntity()).awardStat(Stats.DAMAGE_DEALT_RESISTED, wtf.etil.mirai.server.util.math.FastMath.round(f3 * 10.0F));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2131,10 +2131,10 @@ public abstract class LivingEntity extends Entity {
|
||||
float f2 = absorptionModifier;
|
||||
|
||||
if (f2 > 0.0F && f2 < 3.4028235E37F && this instanceof net.minecraft.world.entity.player.Player) {
|
||||
- ((net.minecraft.world.entity.player.Player) this).awardStat(Stats.DAMAGE_ABSORBED, Math.round(f2 * 10.0F));
|
||||
+ ((net.minecraft.world.entity.player.Player) this).awardStat(Stats.DAMAGE_ABSORBED, wtf.etil.mirai.server.util.math.FastMath.round(f2 * 10.0F));
|
||||
}
|
||||
if (f2 > 0.0F && f2 < 3.4028235E37F && damagesource.getEntity() instanceof ServerPlayer) {
|
||||
- ((ServerPlayer) damagesource.getEntity()).awardStat(Stats.DAMAGE_DEALT_ABSORBED, Math.round(f2 * 10.0F));
|
||||
+ ((ServerPlayer) damagesource.getEntity()).awardStat(Stats.DAMAGE_DEALT_ABSORBED, wtf.etil.mirai.server.util.math.FastMath.round(f2 * 10.0F));
|
||||
}
|
||||
|
||||
if (f > 0 || !human) {
|
||||
@@ -2142,7 +2142,7 @@ public abstract class LivingEntity extends Entity {
|
||||
// PAIL: Be sure to drag all this code from the EntityHuman subclass each update.
|
||||
((net.minecraft.world.entity.player.Player) this).causeFoodExhaustion(damagesource.getFoodExhaustion(), org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.DAMAGED); // CraftBukkit - EntityExhaustionEvent
|
||||
if (f < 3.4028235E37F) {
|
||||
- ((net.minecraft.world.entity.player.Player) this).awardStat(Stats.DAMAGE_TAKEN, Math.round(f * 10.0F));
|
||||
+ ((net.minecraft.world.entity.player.Player) this).awardStat(Stats.DAMAGE_TAKEN, wtf.etil.mirai.server.util.math.FastMath.round(f * 10.0F));
|
||||
}
|
||||
}
|
||||
// CraftBukkit end
|
||||
@@ -2164,7 +2164,7 @@ public abstract class LivingEntity extends Entity {
|
||||
CriteriaTriggers.ENTITY_HURT_PLAYER.trigger((ServerPlayer) this, damagesource, f, originalDamage, true);
|
||||
f2 = (float) -event.getDamage(DamageModifier.BLOCKING);
|
||||
if (f2 > 0.0F && f2 < 3.4028235E37F) {
|
||||
- ((ServerPlayer) this).awardStat(Stats.DAMAGE_BLOCKED_BY_SHIELD, Math.round(originalDamage * 10.0F));
|
||||
+ ((ServerPlayer) this).awardStat(Stats.DAMAGE_BLOCKED_BY_SHIELD, wtf.etil.mirai.server.util.math.FastMath.round(originalDamage * 10.0F));
|
||||
}
|
||||
}
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/player/Player.java b/src/main/java/net/minecraft/world/entity/player/Player.java
|
||||
index b871d89d16e0bb08cc8ce87e74ced974734be418..981fa09173a2dc28579c985d011c71fb106f1fbf 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
|
||||
@@ -1026,7 +1026,7 @@ public abstract class Player extends LivingEntity {
|
||||
float f2 = f1 - f;
|
||||
|
||||
if (f2 > 0.0F && f2 < 3.4028235E37F) {
|
||||
- this.awardStat(Stats.DAMAGE_ABSORBED, Math.round(f2 * 10.0F));
|
||||
+ this.awardStat(Stats.DAMAGE_ABSORBED, wtf.etil.mirai.server.util.math.FastMath.round(f2 * 10.0F));
|
||||
}
|
||||
|
||||
if (f != 0.0F) {
|
||||
@@ -1036,7 +1036,7 @@ public abstract class Player extends LivingEntity {
|
||||
this.setHealth(this.getHealth() - f);
|
||||
this.getCombatTracker().recordDamage(damagesource, f3, f);
|
||||
if (f < 3.4028235E37F) {
|
||||
- this.awardStat(Stats.DAMAGE_TAKEN, Math.round(f * 10.0F));
|
||||
+ this.awardStat(Stats.DAMAGE_TAKEN, wtf.etil.mirai.server.util.math.FastMath.round(f * 10.0F));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1362,7 +1362,7 @@ public abstract class Player extends LivingEntity {
|
||||
if (target instanceof LivingEntity) {
|
||||
float f5 = f3 - ((LivingEntity) target).getHealth();
|
||||
|
||||
- this.awardStat(Stats.DAMAGE_DEALT, Math.round(f5 * 10.0F));
|
||||
+ this.awardStat(Stats.DAMAGE_DEALT, wtf.etil.mirai.server.util.math.FastMath.round(f5 * 10.0F));
|
||||
if (j > 0) {
|
||||
// CraftBukkit start - Call a combust event when somebody hits with a fire enchanted item
|
||||
EntityCombustByEntityEvent combustEvent = new EntityCombustByEntityEvent(this.getBukkitEntity(), target.getBukkitEntity(), j * 4);
|
||||
@@ -1626,29 +1626,29 @@ public abstract class Player extends LivingEntity {
|
||||
int i;
|
||||
|
||||
if (this.isSwimming()) {
|
||||
- i = Math.round((float) Math.sqrt(dx * dx + dy * dy + dz * dz) * 100.0F);
|
||||
+ i = wtf.etil.mirai.server.util.math.FastMath.round((float) Math.sqrt(dx * dx + dy * dy + dz * dz) * 100.0F);
|
||||
if (i > 0) {
|
||||
this.awardStat(Stats.SWIM_ONE_CM, i);
|
||||
this.causeFoodExhaustion(level.spigotConfig.swimMultiplier * (float) i * 0.01F, EntityExhaustionEvent.ExhaustionReason.SWIM); // CraftBukkit - EntityExhaustionEvent // Spigot
|
||||
}
|
||||
} else if (this.isEyeInFluid(FluidTags.WATER)) {
|
||||
- i = Math.round((float) Math.sqrt(dx * dx + dy * dy + dz * dz) * 100.0F);
|
||||
+ i = wtf.etil.mirai.server.util.math.FastMath.round((float) Math.sqrt(dx * dx + dy * dy + dz * dz) * 100.0F);
|
||||
if (i > 0) {
|
||||
this.awardStat(Stats.WALK_UNDER_WATER_ONE_CM, i);
|
||||
this.causeFoodExhaustion(level.spigotConfig.swimMultiplier * (float) i * 0.01F, EntityExhaustionEvent.ExhaustionReason.WALK_UNDERWATER); // CraftBukkit - EntityExhaustionEvent // Spigot
|
||||
}
|
||||
} else if (this.isInWater()) {
|
||||
- i = Math.round((float) Math.sqrt(dx * dx + dz * dz) * 100.0F);
|
||||
+ i = wtf.etil.mirai.server.util.math.FastMath.round((float) Math.sqrt(dx * dx + dz * dz) * 100.0F);
|
||||
if (i > 0) {
|
||||
this.awardStat(Stats.WALK_ON_WATER_ONE_CM, i);
|
||||
this.causeFoodExhaustion(level.spigotConfig.swimMultiplier * (float) i * 0.01F, EntityExhaustionEvent.ExhaustionReason.WALK_ON_WATER); // CraftBukkit - EntityExhaustionEvent // Spigot
|
||||
}
|
||||
} else if (this.onClimbable()) {
|
||||
if (dy > 0.0D) {
|
||||
- this.awardStat(Stats.CLIMB_ONE_CM, (int) Math.round(dy * 100.0D));
|
||||
+ this.awardStat(Stats.CLIMB_ONE_CM, (int) wtf.etil.mirai.server.util.math.FastMath.round(dy * 100.0D));
|
||||
}
|
||||
} else if (this.onGround) {
|
||||
- i = Math.round((float) Math.sqrt(dx * dx + dz * dz) * 100.0F);
|
||||
+ i = wtf.etil.mirai.server.util.math.FastMath.round((float) Math.sqrt(dx * dx + dz * dz) * 100.0F);
|
||||
if (i > 0) {
|
||||
if (this.isSprinting()) {
|
||||
this.awardStat(Stats.SPRINT_ONE_CM, i);
|
||||
@@ -1662,10 +1662,10 @@ public abstract class Player extends LivingEntity {
|
||||
}
|
||||
}
|
||||
} else if (this.isFallFlying()) {
|
||||
- i = Math.round((float) Math.sqrt(dx * dx + dy * dy + dz * dz) * 100.0F);
|
||||
+ i = wtf.etil.mirai.server.util.math.FastMath.round((float) Math.sqrt(dx * dx + dy * dy + dz * dz) * 100.0F);
|
||||
this.awardStat(Stats.AVIATE_ONE_CM, i);
|
||||
} else {
|
||||
- i = Math.round((float) Math.sqrt(dx * dx + dz * dz) * 100.0F);
|
||||
+ i = wtf.etil.mirai.server.util.math.FastMath.round((float) Math.sqrt(dx * dx + dz * dz) * 100.0F);
|
||||
if (i > 25) {
|
||||
this.awardStat(Stats.FLY_ONE_CM, i);
|
||||
}
|
||||
@@ -1676,7 +1676,7 @@ public abstract class Player extends LivingEntity {
|
||||
|
||||
public void checkRidingStatistics(double dx, double dy, double dz) {
|
||||
if (this.isPassenger()) {
|
||||
- int i = Math.round((float) Math.sqrt(dx * dx + dy * dy + dz * dz) * 100.0F);
|
||||
+ int i = wtf.etil.mirai.server.util.math.FastMath.round((float) Math.sqrt(dx * dx + dy * dy + dz * dz) * 100.0F);
|
||||
|
||||
if (i > 0) {
|
||||
Entity entity = this.getVehicle();
|
||||
@@ -1703,7 +1703,7 @@ public abstract class Player extends LivingEntity {
|
||||
return false;
|
||||
} else {
|
||||
if (fallDistance >= 2.0F) {
|
||||
- this.awardStat(Stats.FALL_ONE_CM, (int) Math.round((double) fallDistance * 100.0D));
|
||||
+ this.awardStat(Stats.FALL_ONE_CM, (int) wtf.etil.mirai.server.util.math.FastMath.round((double) fallDistance * 100.0D));
|
||||
}
|
||||
|
||||
return super.causeFallDamage(fallDistance, damageMultiplier, damageSource);
|
||||
diff --git a/src/main/java/net/minecraft/world/item/enchantment/EnchantmentHelper.java b/src/main/java/net/minecraft/world/item/enchantment/EnchantmentHelper.java
|
||||
index 7bc5aa35b52de0027cf58a6127a9903464ccaf47..23b8e6a8db6a9a640ca42e00b8e5d2e2851b8934 100644
|
||||
--- a/src/main/java/net/minecraft/world/item/enchantment/EnchantmentHelper.java
|
||||
+++ b/src/main/java/net/minecraft/world/item/enchantment/EnchantmentHelper.java
|
||||
@@ -345,7 +345,7 @@ public class EnchantmentHelper {
|
||||
} else {
|
||||
level += 1 + random.nextInt(i / 4 + 1) + random.nextInt(i / 4 + 1);
|
||||
float f = (random.nextFloat() + random.nextFloat() - 1.0F) * 0.15F;
|
||||
- level = Mth.clamp(Math.round((float)level + (float)level * f), 1, Integer.MAX_VALUE);
|
||||
+ level = Mth.clamp(wtf.etil.mirai.server.util.math.FastMath.round((float)level + (float)level * f), 1, Integer.MAX_VALUE);
|
||||
List<EnchantmentInstance> list2 = getAvailableEnchantmentResults(level, stack, treasureAllowed);
|
||||
if (!list2.isEmpty()) {
|
||||
WeightedRandom.getRandomItem(random, list2).ifPresent(list::add);
|
||||
diff --git a/src/main/java/net/minecraft/world/level/block/DaylightDetectorBlock.java b/src/main/java/net/minecraft/world/level/block/DaylightDetectorBlock.java
|
||||
index d212774a4e7c578683394fb4a6c90ce5ce875711..d82fbd657a615d84afb0c6dfdc4b1a58f2a10f31 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/block/DaylightDetectorBlock.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/block/DaylightDetectorBlock.java
|
||||
@@ -69,7 +69,7 @@ public class DaylightDetectorBlock extends BaseEntityBlock implements IBlock {
|
||||
float f1 = f < 3.1415927F ? 0.0F : 6.2831855F;
|
||||
|
||||
f += (f1 - f) * 0.2F;
|
||||
- i = Math.round((float) i * Mth.cos(f));
|
||||
+ i = wtf.etil.mirai.server.util.math.FastMath.round((float) i * Mth.cos(f));
|
||||
}
|
||||
|
||||
i = Mth.clamp(i, (int) 0, (int) 15);
|
||||
diff --git a/src/main/java/net/minecraft/world/level/chunk/ChunkGenerator.java b/src/main/java/net/minecraft/world/level/chunk/ChunkGenerator.java
|
||||
index d8b790f0288cfffbc2720b31c6686a3524e76436..6620dc44f106285c193116e8fda3a556b4d7ab17 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/chunk/ChunkGenerator.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/chunk/ChunkGenerator.java
|
||||
@@ -118,8 +118,8 @@ public abstract class ChunkGenerator implements BiomeManager.NoiseBiomeSource {
|
||||
|
||||
for (int j1 = 0; j1 < j; ++j1) {
|
||||
double d1 = (double) (4 * i + i * i1 * 6) + (random.nextDouble() - 0.5D) * (double) i * 2.5D;
|
||||
- int k1 = (int) Math.round(Math.cos(d0) * d1);
|
||||
- int l1 = (int) Math.round(Math.sin(d0) * d1);
|
||||
+ int k1 = (int) wtf.etil.mirai.server.util.math.FastMath.round(Math.cos(d0) * d1);
|
||||
+ int l1 = (int) wtf.etil.mirai.server.util.math.FastMath.round(Math.sin(d0) * d1);
|
||||
BiomeSource worldchunkmanager = this.biomeSource;
|
||||
int i2 = SectionPos.sectionToBlockCoord(k1, 8);
|
||||
int j2 = SectionPos.sectionToBlockCoord(l1, 8);
|
||||
diff --git a/src/main/java/net/minecraft/world/level/storage/loot/functions/LootingEnchantFunction.java b/src/main/java/net/minecraft/world/level/storage/loot/functions/LootingEnchantFunction.java
|
||||
index 31918fa2eb38e42a5ea5366e559f25ea9d7d59ae..1f7419ed17cae2c6cc116147f6bbf51904225cb3 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/storage/loot/functions/LootingEnchantFunction.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/storage/loot/functions/LootingEnchantFunction.java
|
||||
@@ -61,7 +61,7 @@ public class LootingEnchantFunction extends LootItemConditionalFunction {
|
||||
|
||||
float f = (float) i * this.value.getFloat(context);
|
||||
|
||||
- stack.grow(Math.round(f));
|
||||
+ stack.grow(wtf.etil.mirai.server.util.math.FastMath.round(f));
|
||||
if (this.hasLimit() && stack.getCount() > this.limit) {
|
||||
stack.setCount(this.limit);
|
||||
}
|
||||
diff --git a/src/main/java/net/minecraft/world/phys/shapes/Shapes.java b/src/main/java/net/minecraft/world/phys/shapes/Shapes.java
|
||||
index 731c7dd15f131dc124be6af8f342b122cb89491b..383ea0171fe0ab9d81b2be3eea177604ecfd60f0 100644
|
||||
--- a/src/main/java/net/minecraft/world/phys/shapes/Shapes.java
|
||||
+++ b/src/main/java/net/minecraft/world/phys/shapes/Shapes.java
|
||||
@@ -59,8 +59,8 @@ public final class Shapes {
|
||||
int j = 1 << i;
|
||||
double d = min * (double)j;
|
||||
double e = max * (double)j;
|
||||
- boolean bl = Math.abs(d - (double)Math.round(d)) < 1.0E-7D * (double)j;
|
||||
- boolean bl2 = Math.abs(e - (double)Math.round(e)) < 1.0E-7D * (double)j;
|
||||
+ boolean bl = Math.abs(d - (double)wtf.etil.mirai.server.util.math.FastMath.round(d)) < 1.0E-7D * (double)j;
|
||||
+ boolean bl2 = Math.abs(e - (double)wtf.etil.mirai.server.util.math.FastMath.round(e)) < 1.0E-7D * (double)j;
|
||||
if (bl && bl2) {
|
||||
return i;
|
||||
}
|
||||
diff --git a/src/main/java/org/spigotmc/TicksPerSecondCommand.java b/src/main/java/org/spigotmc/TicksPerSecondCommand.java
|
||||
index 0ecac76577eb440a0c3104ef4603acec826c474d..cb9433221b1c6a4573d7965b78e0c20548b3a3a7 100644
|
||||
--- a/src/main/java/org/spigotmc/TicksPerSecondCommand.java
|
||||
+++ b/src/main/java/org/spigotmc/TicksPerSecondCommand.java
|
||||
@@ -52,7 +52,7 @@ public class TicksPerSecondCommand extends Command
|
||||
private static String format(double tps) // Paper - Made static
|
||||
{
|
||||
return ( ( tps > 18.0 ) ? ChatColor.GREEN : ( tps > 16.0 ) ? ChatColor.YELLOW : ChatColor.RED ).toString()
|
||||
- + ( ( tps > 21.0 ) ? "*" : "" ) + Math.min( Math.round( tps * 100.0 ) / 100.0, 20.0 ); // Paper - only print * at 21, we commonly peak to 20.02 as the tick sleep is not accurate enough, stop the noise
|
||||
+ + ( ( tps > 21.0 ) ? "*" : "" ) + Math.min( wtf.etil.mirai.server.util.math.FastMath.round( tps * 100.0 ) / 100.0, 20.0 ); // Paper - only print * at 21, we commonly peak to 20.02 as the tick sleep is not accurate enough, stop the noise
|
||||
}
|
||||
|
||||
// Yatopia start - Last tick time API
|
||||
diff --git a/src/main/java/wtf/etil/mirai/server/util/math/FastMath.java b/src/main/java/wtf/etil/mirai/server/util/math/FastMath.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..8258074e0f912e5ac1b95fd601d08114f224ac7b
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/wtf/etil/mirai/server/util/math/FastMath.java
|
||||
@@ -0,0 +1,22 @@
|
||||
+package wtf.etil.mirai.server.util.math;
|
||||
+
|
||||
+public class FastMath {
|
||||
+
|
||||
+ /**
|
||||
+ * @author FX - PR0CESS
|
||||
+ * Custom rounding method which is even faster while keeping 100% accuracy
|
||||
+ * ~1.25x faster than {@link Math#round(float)}
|
||||
+ */
|
||||
+ public static int round(float a) {
|
||||
+ return a > 0F ? (int)(a + .5F) : (int)(a - .5F);
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * @author FX - PR0CESS
|
||||
+ * Custom rounding method which is even faster while keeping 100% accuracy
|
||||
+ * ~1.28x faster than {@link Math#round(double)}
|
||||
+ */
|
||||
+ public static long round(double a) {
|
||||
+ return a > 0D ? (long)(a + .5D) : (long)(a - .5D);
|
||||
+ }
|
||||
+}
|
||||
\ No newline at end of file
|
||||
@@ -7,7 +7,7 @@ Original code by PurpurMC, licensed under MIT
|
||||
You can find the original code on https://github.com/PurpurMC/Purpur
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
||||
index 638fb5ea3409d2531135567dc03f6319fa849db4..ccaf4c3090b33c9911bac76ae62c6b916349dc74 100644
|
||||
index b9cc4aa7cd5694976c43f834bbf60412992c269f..fcf6606d7fde0a9f93a2bd1a8e20f8f6ddb9374b 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
||||
@@ -251,6 +251,7 @@ public abstract class LivingEntity extends Entity {
|
||||
@@ -5,7 +5,7 @@ Subject: [PATCH] Configurable server metrics
|
||||
|
||||
|
||||
diff --git a/src/main/java/com/destroystokyo/paper/PaperConfig.java b/src/main/java/com/destroystokyo/paper/PaperConfig.java
|
||||
index 1e11147554dbd3dbc809440c8795ced668224c01..dfebdd89c9741c10095f8bd0a788c87e337fe3ab 100644
|
||||
index 2a19037d3ad734d1cf746d02b72926dd702fd23a..0297e176e2e4b29b4aeeaee30d43653bfbc228bf 100644
|
||||
--- a/src/main/java/com/destroystokyo/paper/PaperConfig.java
|
||||
+++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java
|
||||
@@ -123,7 +123,7 @@ public class PaperConfig {
|
||||
592
patches/server/0091-Configurable-FastMath.round.patch
Normal file
592
patches/server/0091-Configurable-FastMath.round.patch
Normal file
@@ -0,0 +1,592 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: FX - PR0CESS <fx.e.morin@gmail.com>
|
||||
Date: Wed, 22 Dec 2021 18:39:21 +0100
|
||||
Subject: [PATCH] Configurable FastMath.round
|
||||
|
||||
Original code by fxmorin, licensed under MIT
|
||||
You can find the original code on https://github.com/fxmorin/carpet-fixes
|
||||
|
||||
diff --git a/src/main/java/carpetfixes/helpers/FastMath.java b/src/main/java/carpetfixes/helpers/FastMath.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..265bffa41a748c9d5684973af7309ed7fa37064c
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/carpetfixes/helpers/FastMath.java
|
||||
@@ -0,0 +1,20 @@
|
||||
+package carpetfixes.helpers;
|
||||
+
|
||||
+public class FastMath {
|
||||
+
|
||||
+ /**
|
||||
+ * @author FX - PR0CESS
|
||||
+ * ~1.25x faster than {@link Math#round(float)}
|
||||
+ */
|
||||
+ public static int round(float a) {
|
||||
+ return a > 0F ? (int)(a + .5F) : (int)(a - .5F);
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * @author FX - PR0CESS
|
||||
+ * ~1.28x faster than {@link Math#round(double)}
|
||||
+ */
|
||||
+ public static long round(double a) {
|
||||
+ return a > 0D ? (long)(a + .5D) : (long)(a - .5D);
|
||||
+ }
|
||||
+}
|
||||
\ No newline at end of file
|
||||
diff --git a/src/main/java/com/destroystokyo/paper/PaperCommand.java b/src/main/java/com/destroystokyo/paper/PaperCommand.java
|
||||
index 7764b1f86aca33dc227bf4357c20839b8820eb67..3f8860e456bd8b841dbe5f624dace4f7d48a235b 100644
|
||||
--- a/src/main/java/com/destroystokyo/paper/PaperCommand.java
|
||||
+++ b/src/main/java/com/destroystokyo/paper/PaperCommand.java
|
||||
@@ -723,14 +723,30 @@ public class PaperCommand extends Command {
|
||||
lightengine.relight(chunks,
|
||||
(ChunkPos chunkPos) -> {
|
||||
++relitChunks[0];
|
||||
- sender.getBukkitEntity().sendMessage(
|
||||
- ChatColor.BLUE + "Relit chunk " + ChatColor.DARK_AQUA + chunkPos + ChatColor.BLUE +
|
||||
- ", progress: " + ChatColor.DARK_AQUA + (int)(Math.round(100.0 * (double)(relitChunks[0])/(double)pending[0])) + "%"
|
||||
- );
|
||||
+ // Mirai start
|
||||
+ if (wtf.etil.mirai.MiraiConfig.riskyMathRoundOpt) {
|
||||
+ sender.getBukkitEntity().sendMessage(
|
||||
+ ChatColor.BLUE + "Relit chunk " + ChatColor.DARK_AQUA + chunkPos + ChatColor.BLUE +
|
||||
+ ", progress: " + ChatColor.DARK_AQUA + (int)(carpetfixes.helpers.FastMath.round(100.0 * (double)(relitChunks[0])/(double)pending[0])) + "%"
|
||||
+ );
|
||||
+ } else {
|
||||
+ sender.getBukkitEntity().sendMessage(
|
||||
+ ChatColor.BLUE + "Relit chunk " + ChatColor.DARK_AQUA + chunkPos + ChatColor.BLUE +
|
||||
+ ", progress: " + ChatColor.DARK_AQUA + (int)(Math.round(100.0 * (double)(relitChunks[0])/(double)pending[0])) + "%"
|
||||
+ );
|
||||
+ }
|
||||
+ // Mirai end
|
||||
},
|
||||
(int totalRelit) -> {
|
||||
final long end = System.nanoTime();
|
||||
- final long diff = Math.round(1.0e-6*(end - start));
|
||||
+ // Mirai start
|
||||
+ final long diff;
|
||||
+ if (wtf.etil.mirai.MiraiConfig.riskyMathRoundOpt) {
|
||||
+ diff = carpetfixes.helpers.FastMath.round(1.0e-6*(end - start));
|
||||
+ } else {
|
||||
+ diff = Math.round(1.0e-6*(end - start));
|
||||
+ }
|
||||
+ // Mirai end
|
||||
sender.getBukkitEntity().sendMessage(
|
||||
ChatColor.BLUE + "Relit " + ChatColor.DARK_AQUA + totalRelit + ChatColor.BLUE + " chunks. Took " +
|
||||
ChatColor.DARK_AQUA + diff + "ms"
|
||||
diff --git a/src/main/java/com/destroystokyo/paper/gui/RAMDetails.java b/src/main/java/com/destroystokyo/paper/gui/RAMDetails.java
|
||||
index f9251183df72ddc56662fd3f02acf21641a2200c..d87ba2e05870ad9ebb7dd8374b7206bdb4c4e4cb 100644
|
||||
--- a/src/main/java/com/destroystokyo/paper/gui/RAMDetails.java
|
||||
+++ b/src/main/java/com/destroystokyo/paper/gui/RAMDetails.java
|
||||
@@ -81,6 +81,12 @@ public class RAMDetails extends JList<String> {
|
||||
}
|
||||
|
||||
private static String format(double tps) {
|
||||
- return ( ( tps > 21.0 ) ? "*" : "" ) + Math.min( Math.round( tps * 100.0 ) / 100.0, 20.0 );
|
||||
+ // Mirai start
|
||||
+ if (wtf.etil.mirai.MiraiConfig.riskyMathRoundOpt) {
|
||||
+ return ( ( tps > 21.0 ) ? "*" : "" ) + Math.min( carpetfixes.helpers.FastMath.round( tps * 100.0 ) / 100.0, 20.0 );
|
||||
+ } else {
|
||||
+ return ( ( tps > 21.0 ) ? "*" : "" ) + Math.min( Math.round( tps * 100.0 ) / 100.0, 20.0 );
|
||||
+ }
|
||||
+ // Mirai end
|
||||
}
|
||||
}
|
||||
diff --git a/src/main/java/com/destroystokyo/paper/gui/RAMGraph.java b/src/main/java/com/destroystokyo/paper/gui/RAMGraph.java
|
||||
index c3e54da4ab6440811aab2f9dd1e218802ac13285..abaee3564a6187dd3ddb5fe63ae4689469474ae7 100644
|
||||
--- a/src/main/java/com/destroystokyo/paper/gui/RAMGraph.java
|
||||
+++ b/src/main/java/com/destroystokyo/paper/gui/RAMGraph.java
|
||||
@@ -127,9 +127,17 @@ public class RAMGraph extends JComponent {
|
||||
graphics.drawOval(m.x - 2, 100 - used - 2, 5, 5);
|
||||
graphics.setColor(data.getLineColor());
|
||||
graphics.fillOval(m.x - 2, 100 - used - 2, 5, 5);
|
||||
- setToolTipText(String.format("<html><body>Used: %s mb (%s%%)<br/>%s</body></html>",
|
||||
- Math.round(data.getUsedMem() / 1024F / 1024F),
|
||||
- used, getTime(m.x)));
|
||||
+ // Mirai start
|
||||
+ if (wtf.etil.mirai.MiraiConfig.riskyMathRoundOpt) {
|
||||
+ setToolTipText(String.format("<html><body>Used: %s mb (%s%%)<br/>%s</body></html>",
|
||||
+ carpetfixes.helpers.FastMath.round(data.getUsedMem() / 1024F / 1024F),
|
||||
+ used, getTime(m.x)));
|
||||
+ } else {
|
||||
+ setToolTipText(String.format("<html><body>Used: %s mb (%s%%)<br/>%s</body></html>",
|
||||
+ Math.round(data.getUsedMem() / 1024F / 1024F),
|
||||
+ used, getTime(m.x)));
|
||||
+ }
|
||||
+ // Mirai end
|
||||
}
|
||||
}
|
||||
|
||||
diff --git a/src/main/java/gg/pufferfish/pufferfish/flare/collectors/TPSCollector.java b/src/main/java/gg/pufferfish/pufferfish/flare/collectors/TPSCollector.java
|
||||
index 40447d00aefb5ffedb8a2ee87155a04088f0649f..c087b864ca193eb5ecf232b63da30349cf08d61d 100644
|
||||
--- a/src/main/java/gg/pufferfish/pufferfish/flare/collectors/TPSCollector.java
|
||||
+++ b/src/main/java/gg/pufferfish/pufferfish/flare/collectors/TPSCollector.java
|
||||
@@ -25,7 +25,14 @@ public class TPSCollector extends LiveCollector {
|
||||
long[] times = MinecraftServer.getServer().tickTimes5s.getTimes();
|
||||
double mspt = ((double) Arrays.stream(times).sum() / (double) times.length) * 1.0E-6D;
|
||||
|
||||
- this.report(TPS, Math.min(20D, Math.round(Bukkit.getServer().getTPS()[0] * 100d) / 100d));
|
||||
- this.report(MSPT, (double) Math.round(mspt * 100d) / 100d);
|
||||
+ // Mirai start
|
||||
+ if (wtf.etil.mirai.MiraiConfig.riskyMathRoundOpt) {
|
||||
+ this.report(TPS, Math.min(20D, carpetfixes.helpers.FastMath.round(Bukkit.getServer().getTPS()[0] * 100d) / 100d));
|
||||
+ this.report(MSPT, (double) carpetfixes.helpers.FastMath.round(mspt * 100d) / 100d);
|
||||
+ } else {
|
||||
+ this.report(TPS, Math.min(20D, Math.round(Bukkit.getServer().getTPS()[0] * 100d) / 100d));
|
||||
+ this.report(MSPT, (double) Math.round(mspt * 100d) / 100d);
|
||||
+ }
|
||||
+ // Mirai end
|
||||
}
|
||||
}
|
||||
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
index 0f69380a5c6d4a2ac1aed2185122ec11c2ed4720..cbed49b6bdc251388579cbdfe2d1c911283c3212 100644
|
||||
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
@@ -393,7 +393,14 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<Runnab
|
||||
}
|
||||
|
||||
double overuseCount = (double)overuse/(double)MAX_CHUNK_EXEC_TIME;
|
||||
- long extraSleep = (long)Math.round(overuseCount*CHUNK_TASK_QUEUE_BACKOFF_MIN_TIME);
|
||||
+ // Mirai start
|
||||
+ long extraSleep;
|
||||
+ if (wtf.etil.mirai.MiraiConfig.riskyMathRoundOpt) {
|
||||
+ extraSleep = (long)carpetfixes.helpers.FastMath.round(overuseCount*CHUNK_TASK_QUEUE_BACKOFF_MIN_TIME);
|
||||
+ } else {
|
||||
+ extraSleep = (long)Math.round(overuseCount*CHUNK_TASK_QUEUE_BACKOFF_MIN_TIME);
|
||||
+ }
|
||||
+ // Mirai end
|
||||
|
||||
lastMidTickExecute = currTime + extraSleep;
|
||||
return;
|
||||
diff --git a/src/main/java/net/minecraft/server/gui/StatsComponent.java b/src/main/java/net/minecraft/server/gui/StatsComponent.java
|
||||
index 88f10d729aa1e0a01790521821d691a0ecd373a2..eb90e203ce2998edb2918170d4df1fab3f729a8e 100644
|
||||
--- a/src/main/java/net/minecraft/server/gui/StatsComponent.java
|
||||
+++ b/src/main/java/net/minecraft/server/gui/StatsComponent.java
|
||||
@@ -88,7 +88,13 @@ public class StatsComponent extends JComponent {
|
||||
|
||||
// Paper - start Add tps entry
|
||||
private static String format(double tps) {
|
||||
- return (( tps > 21.0 ) ? "*" : "") + Math.min(Math.round(tps * 100.0) / 100.0, 20.0); // only print * at 21, we commonly peak to 20.02 as the tick sleep is not accurate enough, stop the noise
|
||||
+ // Mirai start
|
||||
+ if (wtf.etil.mirai.MiraiConfig.riskyMathRoundOpt) {
|
||||
+ return (( tps > 21.0 ) ? "*" : "") + Math.min(carpetfixes.helpers.FastMath.round(tps * 100.0) / 100.0, 20.0); // only print * at 21, we commonly peak to 20.02 as the tick sleep is not accurate enough, stop the noise
|
||||
+ } else {
|
||||
+ return (( tps > 21.0 ) ? "*" : "") + Math.min(Math.round(tps * 100.0) / 100.0, 20.0); // only print * at 21, we commonly peak to 20.02 as the tick sleep is not accurate enough, stop the noise
|
||||
+ }
|
||||
+ // Mirai end
|
||||
}
|
||||
// Paper end
|
||||
}
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
||||
index fcf6606d7fde0a9f93a2bd1a8e20f8f6ddb9374b..9f33aeeedd03746cdc26709cd3593f9e4078aad8 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
||||
@@ -1473,7 +1473,13 @@ public abstract class LivingEntity extends Entity {
|
||||
if (this instanceof ServerPlayer) {
|
||||
CriteriaTriggers.ENTITY_HURT_PLAYER.trigger((ServerPlayer) this, source, f1, amount, flag);
|
||||
if (f2 > 0.0F && f2 < 3.4028235E37F) {
|
||||
- ((ServerPlayer) this).awardStat(Stats.DAMAGE_BLOCKED_BY_SHIELD, Math.round(f2 * 10.0F));
|
||||
+ // Mirai start
|
||||
+ if (wtf.etil.mirai.MiraiConfig.riskyMathRoundOpt) {
|
||||
+ ((ServerPlayer) this).awardStat(Stats.DAMAGE_BLOCKED_BY_SHIELD, carpetfixes.helpers.FastMath.round(f2 * 10.0F));
|
||||
+ } else {
|
||||
+ ((ServerPlayer) this).awardStat(Stats.DAMAGE_BLOCKED_BY_SHIELD, Math.round(f2 * 10.0F));
|
||||
+ }
|
||||
+ // Mirai end
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1985,11 +1991,21 @@ public abstract class LivingEntity extends Entity {
|
||||
float f3 = f2 - amount;
|
||||
|
||||
if (f3 > 0.0F && f3 < 3.4028235E37F) {
|
||||
- if (this instanceof ServerPlayer) {
|
||||
- ((ServerPlayer) this).awardStat(Stats.DAMAGE_RESISTED, Math.round(f3 * 10.0F));
|
||||
- } else if (source.getEntity() instanceof ServerPlayer) {
|
||||
- ((ServerPlayer) source.getEntity()).awardStat(Stats.DAMAGE_DEALT_RESISTED, Math.round(f3 * 10.0F));
|
||||
+ // Mirai start
|
||||
+ if (wtf.etil.mirai.MiraiConfig.riskyMathRoundOpt) {
|
||||
+ if (this instanceof ServerPlayer) {
|
||||
+ ((ServerPlayer) this).awardStat(Stats.DAMAGE_RESISTED, carpetfixes.helpers.FastMath.round(f3 * 10.0F));
|
||||
+ } else if (source.getEntity() instanceof ServerPlayer) {
|
||||
+ ((ServerPlayer) source.getEntity()).awardStat(Stats.DAMAGE_DEALT_RESISTED, carpetfixes.helpers.FastMath.round(f3 * 10.0F));
|
||||
+ }
|
||||
+ } else {
|
||||
+ if (this instanceof ServerPlayer) {
|
||||
+ ((ServerPlayer) this).awardStat(Stats.DAMAGE_RESISTED, Math.round(f3 * 10.0F));
|
||||
+ } else if (source.getEntity() instanceof ServerPlayer) {
|
||||
+ ((ServerPlayer) source.getEntity()).awardStat(Stats.DAMAGE_DEALT_RESISTED, Math.round(f3 * 10.0F));
|
||||
+ }
|
||||
}
|
||||
+ // Mirai end
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2097,11 +2113,21 @@ public abstract class LivingEntity extends Entity {
|
||||
if (event.getDamage(DamageModifier.RESISTANCE) < 0) {
|
||||
float f3 = (float) -event.getDamage(DamageModifier.RESISTANCE);
|
||||
if (f3 > 0.0F && f3 < 3.4028235E37F) {
|
||||
- if (this instanceof ServerPlayer) {
|
||||
- ((ServerPlayer) this).awardStat(Stats.DAMAGE_RESISTED, Math.round(f3 * 10.0F));
|
||||
- } else if (damagesource.getEntity() instanceof ServerPlayer) {
|
||||
- ((ServerPlayer) damagesource.getEntity()).awardStat(Stats.DAMAGE_DEALT_RESISTED, Math.round(f3 * 10.0F));
|
||||
+ // Mirai start
|
||||
+ if (wtf.etil.mirai.MiraiConfig.riskyMathRoundOpt) {
|
||||
+ if (this instanceof ServerPlayer) {
|
||||
+ ((ServerPlayer) this).awardStat(Stats.DAMAGE_RESISTED, carpetfixes.helpers.FastMath.round(f3 * 10.0F));
|
||||
+ } else if (damagesource.getEntity() instanceof ServerPlayer) {
|
||||
+ ((ServerPlayer) damagesource.getEntity()).awardStat(Stats.DAMAGE_DEALT_RESISTED, carpetfixes.helpers.FastMath.round(f3 * 10.0F));
|
||||
+ }
|
||||
+ } else {
|
||||
+ if (this instanceof ServerPlayer) {
|
||||
+ ((ServerPlayer) this).awardStat(Stats.DAMAGE_RESISTED, Math.round(f3 * 10.0F));
|
||||
+ } else if (damagesource.getEntity() instanceof ServerPlayer) {
|
||||
+ ((ServerPlayer) damagesource.getEntity()).awardStat(Stats.DAMAGE_DEALT_RESISTED, Math.round(f3 * 10.0F));
|
||||
+ }
|
||||
}
|
||||
+ // Mirai end
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2132,10 +2158,22 @@ public abstract class LivingEntity extends Entity {
|
||||
float f2 = absorptionModifier;
|
||||
|
||||
if (f2 > 0.0F && f2 < 3.4028235E37F && this instanceof net.minecraft.world.entity.player.Player) {
|
||||
- ((net.minecraft.world.entity.player.Player) this).awardStat(Stats.DAMAGE_ABSORBED, Math.round(f2 * 10.0F));
|
||||
+ // Mirai start
|
||||
+ if (wtf.etil.mirai.MiraiConfig.riskyMathRoundOpt) {
|
||||
+ ((net.minecraft.world.entity.player.Player) this).awardStat(Stats.DAMAGE_ABSORBED, carpetfixes.helpers.FastMath.round(f2 * 10.0F));
|
||||
+ } else {
|
||||
+ ((net.minecraft.world.entity.player.Player) this).awardStat(Stats.DAMAGE_ABSORBED, Math.round(f2 * 10.0F));
|
||||
+ }
|
||||
+ // Mirai end
|
||||
}
|
||||
if (f2 > 0.0F && f2 < 3.4028235E37F && damagesource.getEntity() instanceof ServerPlayer) {
|
||||
- ((ServerPlayer) damagesource.getEntity()).awardStat(Stats.DAMAGE_DEALT_ABSORBED, Math.round(f2 * 10.0F));
|
||||
+ // Mirai start
|
||||
+ if (wtf.etil.mirai.MiraiConfig.riskyMathRoundOpt) {
|
||||
+ ((ServerPlayer) damagesource.getEntity()).awardStat(Stats.DAMAGE_DEALT_ABSORBED, carpetfixes.helpers.FastMath.round(f2 * 10.0F));
|
||||
+ } else {
|
||||
+ ((ServerPlayer) damagesource.getEntity()).awardStat(Stats.DAMAGE_DEALT_ABSORBED, Math.round(f2 * 10.0F));
|
||||
+ }
|
||||
+ // Mirai end
|
||||
}
|
||||
|
||||
if (f > 0 || !human) {
|
||||
@@ -2143,7 +2181,13 @@ public abstract class LivingEntity extends Entity {
|
||||
// PAIL: Be sure to drag all this code from the EntityHuman subclass each update.
|
||||
((net.minecraft.world.entity.player.Player) this).causeFoodExhaustion(damagesource.getFoodExhaustion(), org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.DAMAGED); // CraftBukkit - EntityExhaustionEvent
|
||||
if (f < 3.4028235E37F) {
|
||||
- ((net.minecraft.world.entity.player.Player) this).awardStat(Stats.DAMAGE_TAKEN, Math.round(f * 10.0F));
|
||||
+ // Mirai start
|
||||
+ if (wtf.etil.mirai.MiraiConfig.riskyMathRoundOpt) {
|
||||
+ ((net.minecraft.world.entity.player.Player) this).awardStat(Stats.DAMAGE_TAKEN, carpetfixes.helpers.FastMath.round(f * 10.0F));
|
||||
+ } else {
|
||||
+ ((net.minecraft.world.entity.player.Player) this).awardStat(Stats.DAMAGE_TAKEN, Math.round(f * 10.0F));
|
||||
+ }
|
||||
+ // Mirai end
|
||||
}
|
||||
}
|
||||
// CraftBukkit end
|
||||
@@ -2165,7 +2209,13 @@ public abstract class LivingEntity extends Entity {
|
||||
CriteriaTriggers.ENTITY_HURT_PLAYER.trigger((ServerPlayer) this, damagesource, f, originalDamage, true);
|
||||
f2 = (float) -event.getDamage(DamageModifier.BLOCKING);
|
||||
if (f2 > 0.0F && f2 < 3.4028235E37F) {
|
||||
- ((ServerPlayer) this).awardStat(Stats.DAMAGE_BLOCKED_BY_SHIELD, Math.round(originalDamage * 10.0F));
|
||||
+ // Mirai start
|
||||
+ if (wtf.etil.mirai.MiraiConfig.riskyMathRoundOpt) {
|
||||
+ ((ServerPlayer) this).awardStat(Stats.DAMAGE_BLOCKED_BY_SHIELD, carpetfixes.helpers.FastMath.round(originalDamage * 10.0F));
|
||||
+ } else {
|
||||
+ ((ServerPlayer) this).awardStat(Stats.DAMAGE_BLOCKED_BY_SHIELD, Math.round(originalDamage * 10.0F));
|
||||
+ }
|
||||
+ // Mirai end
|
||||
}
|
||||
}
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/player/Player.java b/src/main/java/net/minecraft/world/entity/player/Player.java
|
||||
index b871d89d16e0bb08cc8ce87e74ced974734be418..fda2f91ef20542cc11037c9bf74f71bd17061d49 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
|
||||
@@ -1026,7 +1026,13 @@ public abstract class Player extends LivingEntity {
|
||||
float f2 = f1 - f;
|
||||
|
||||
if (f2 > 0.0F && f2 < 3.4028235E37F) {
|
||||
- this.awardStat(Stats.DAMAGE_ABSORBED, Math.round(f2 * 10.0F));
|
||||
+ // Mirai start
|
||||
+ if (wtf.etil.mirai.MiraiConfig.riskyMathRoundOpt) {
|
||||
+ this.awardStat(Stats.DAMAGE_ABSORBED, carpetfixes.helpers.FastMath.round(f2 * 10.0F));
|
||||
+ } else {
|
||||
+ this.awardStat(Stats.DAMAGE_ABSORBED, Math.round(f2 * 10.0F));
|
||||
+ }
|
||||
+ // Mirai end
|
||||
}
|
||||
|
||||
if (f != 0.0F) {
|
||||
@@ -1036,7 +1042,13 @@ public abstract class Player extends LivingEntity {
|
||||
this.setHealth(this.getHealth() - f);
|
||||
this.getCombatTracker().recordDamage(damagesource, f3, f);
|
||||
if (f < 3.4028235E37F) {
|
||||
- this.awardStat(Stats.DAMAGE_TAKEN, Math.round(f * 10.0F));
|
||||
+ // Mirai start
|
||||
+ if (wtf.etil.mirai.MiraiConfig.riskyMathRoundOpt) {
|
||||
+ this.awardStat(Stats.DAMAGE_TAKEN, carpetfixes.helpers.FastMath.round(f * 10.0F));
|
||||
+ } else {
|
||||
+ this.awardStat(Stats.DAMAGE_TAKEN, Math.round(f * 10.0F));
|
||||
+ }
|
||||
+ // Mirai end
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1362,7 +1374,13 @@ public abstract class Player extends LivingEntity {
|
||||
if (target instanceof LivingEntity) {
|
||||
float f5 = f3 - ((LivingEntity) target).getHealth();
|
||||
|
||||
- this.awardStat(Stats.DAMAGE_DEALT, Math.round(f5 * 10.0F));
|
||||
+ // Mirai start
|
||||
+ if (wtf.etil.mirai.MiraiConfig.riskyMathRoundOpt) {
|
||||
+ this.awardStat(Stats.DAMAGE_DEALT, carpetfixes.helpers.FastMath.round(f5 * 10.0F));
|
||||
+ } else {
|
||||
+ this.awardStat(Stats.DAMAGE_DEALT, Math.round(f5 * 10.0F));
|
||||
+ }
|
||||
+ // Mirai end
|
||||
if (j > 0) {
|
||||
// CraftBukkit start - Call a combust event when somebody hits with a fire enchanted item
|
||||
EntityCombustByEntityEvent combustEvent = new EntityCombustByEntityEvent(this.getBukkitEntity(), target.getBukkitEntity(), j * 4);
|
||||
@@ -1626,29 +1644,59 @@ public abstract class Player extends LivingEntity {
|
||||
int i;
|
||||
|
||||
if (this.isSwimming()) {
|
||||
- i = Math.round((float) Math.sqrt(dx * dx + dy * dy + dz * dz) * 100.0F);
|
||||
+ // Mirai start
|
||||
+ if (wtf.etil.mirai.MiraiConfig.riskyMathRoundOpt) {
|
||||
+ i = carpetfixes.helpers.FastMath.round((float) Math.sqrt(dx * dx + dy * dy + dz * dz) * 100.0F);
|
||||
+ } else {
|
||||
+ i = Math.round((float) Math.sqrt(dx * dx + dy * dy + dz * dz) * 100.0F);
|
||||
+ }
|
||||
+ // Mirai end
|
||||
if (i > 0) {
|
||||
this.awardStat(Stats.SWIM_ONE_CM, i);
|
||||
this.causeFoodExhaustion(level.spigotConfig.swimMultiplier * (float) i * 0.01F, EntityExhaustionEvent.ExhaustionReason.SWIM); // CraftBukkit - EntityExhaustionEvent // Spigot
|
||||
}
|
||||
} else if (this.isEyeInFluid(FluidTags.WATER)) {
|
||||
- i = Math.round((float) Math.sqrt(dx * dx + dy * dy + dz * dz) * 100.0F);
|
||||
+ // Mirai start
|
||||
+ if (wtf.etil.mirai.MiraiConfig.riskyMathRoundOpt) {
|
||||
+ i = carpetfixes.helpers.FastMath.round((float) Math.sqrt(dx * dx + dy * dy + dz * dz) * 100.0F);
|
||||
+ } else {
|
||||
+ i = Math.round((float) Math.sqrt(dx * dx + dy * dy + dz * dz) * 100.0F);
|
||||
+ }
|
||||
+ // Mirai end
|
||||
if (i > 0) {
|
||||
this.awardStat(Stats.WALK_UNDER_WATER_ONE_CM, i);
|
||||
this.causeFoodExhaustion(level.spigotConfig.swimMultiplier * (float) i * 0.01F, EntityExhaustionEvent.ExhaustionReason.WALK_UNDERWATER); // CraftBukkit - EntityExhaustionEvent // Spigot
|
||||
}
|
||||
} else if (this.isInWater()) {
|
||||
- i = Math.round((float) Math.sqrt(dx * dx + dz * dz) * 100.0F);
|
||||
+ // Mirai start
|
||||
+ if (wtf.etil.mirai.MiraiConfig.riskyMathRoundOpt) {
|
||||
+ i = carpetfixes.helpers.FastMath.round((float) Math.sqrt(dx * dx + dz * dz) * 100.0F);
|
||||
+ } else {
|
||||
+ i = Math.round((float) Math.sqrt(dx * dx + dz * dz) * 100.0F);
|
||||
+ }
|
||||
+ // Mirai end
|
||||
if (i > 0) {
|
||||
this.awardStat(Stats.WALK_ON_WATER_ONE_CM, i);
|
||||
this.causeFoodExhaustion(level.spigotConfig.swimMultiplier * (float) i * 0.01F, EntityExhaustionEvent.ExhaustionReason.WALK_ON_WATER); // CraftBukkit - EntityExhaustionEvent // Spigot
|
||||
}
|
||||
} else if (this.onClimbable()) {
|
||||
if (dy > 0.0D) {
|
||||
- this.awardStat(Stats.CLIMB_ONE_CM, (int) Math.round(dy * 100.0D));
|
||||
+ // Mirai start
|
||||
+ if (wtf.etil.mirai.MiraiConfig.riskyMathRoundOpt) {
|
||||
+ this.awardStat(Stats.CLIMB_ONE_CM, (int) carpetfixes.helpers.FastMath.round(dy * 100.0D));
|
||||
+ } else {
|
||||
+ this.awardStat(Stats.CLIMB_ONE_CM, (int) Math.round(dy * 100.0D));
|
||||
+ }
|
||||
+ // Mirai end
|
||||
}
|
||||
} else if (this.onGround) {
|
||||
- i = Math.round((float) Math.sqrt(dx * dx + dz * dz) * 100.0F);
|
||||
+ // Mirai start
|
||||
+ if (wtf.etil.mirai.MiraiConfig.riskyMathRoundOpt) {
|
||||
+ i = carpetfixes.helpers.FastMath.round((float) Math.sqrt(dx * dx + dz * dz) * 100.0F);
|
||||
+ } else {
|
||||
+ i = Math.round((float) Math.sqrt(dx * dx + dz * dz) * 100.0F);
|
||||
+ }
|
||||
+ // Mirai end
|
||||
if (i > 0) {
|
||||
if (this.isSprinting()) {
|
||||
this.awardStat(Stats.SPRINT_ONE_CM, i);
|
||||
@@ -1662,10 +1710,22 @@ public abstract class Player extends LivingEntity {
|
||||
}
|
||||
}
|
||||
} else if (this.isFallFlying()) {
|
||||
- i = Math.round((float) Math.sqrt(dx * dx + dy * dy + dz * dz) * 100.0F);
|
||||
+ // Mirai start
|
||||
+ if (wtf.etil.mirai.MiraiConfig.riskyMathRoundOpt) {
|
||||
+ i = carpetfixes.helpers.FastMath.round((float) Math.sqrt(dx * dx + dy * dy + dz * dz) * 100.0F);
|
||||
+ } else {
|
||||
+ i = Math.round((float) Math.sqrt(dx * dx + dy * dy + dz * dz) * 100.0F);
|
||||
+ }
|
||||
+ // Mirai end
|
||||
this.awardStat(Stats.AVIATE_ONE_CM, i);
|
||||
} else {
|
||||
- i = Math.round((float) Math.sqrt(dx * dx + dz * dz) * 100.0F);
|
||||
+ // Mirai start
|
||||
+ if (wtf.etil.mirai.MiraiConfig.riskyMathRoundOpt) {
|
||||
+ i = carpetfixes.helpers.FastMath.round((float) Math.sqrt(dx * dx + dz * dz) * 100.0F);
|
||||
+ } else {
|
||||
+ i = Math.round((float) Math.sqrt(dx * dx + dz * dz) * 100.0F);
|
||||
+ }
|
||||
+ // Mirai end
|
||||
if (i > 25) {
|
||||
this.awardStat(Stats.FLY_ONE_CM, i);
|
||||
}
|
||||
@@ -1676,7 +1736,14 @@ public abstract class Player extends LivingEntity {
|
||||
|
||||
public void checkRidingStatistics(double dx, double dy, double dz) {
|
||||
if (this.isPassenger()) {
|
||||
- int i = Math.round((float) Math.sqrt(dx * dx + dy * dy + dz * dz) * 100.0F);
|
||||
+ // Mirai start
|
||||
+ int i;
|
||||
+ if (wtf.etil.mirai.MiraiConfig.riskyMathRoundOpt) {
|
||||
+ i = carpetfixes.helpers.FastMath.round((float) Math.sqrt(dx * dx + dy * dy + dz * dz) * 100.0F);
|
||||
+ } else {
|
||||
+ i = Math.round((float) Math.sqrt(dx * dx + dy * dy + dz * dz) * 100.0F);
|
||||
+ }
|
||||
+ // Mirai end
|
||||
|
||||
if (i > 0) {
|
||||
Entity entity = this.getVehicle();
|
||||
@@ -1703,7 +1770,13 @@ public abstract class Player extends LivingEntity {
|
||||
return false;
|
||||
} else {
|
||||
if (fallDistance >= 2.0F) {
|
||||
- this.awardStat(Stats.FALL_ONE_CM, (int) Math.round((double) fallDistance * 100.0D));
|
||||
+ // Mirai start
|
||||
+ if (wtf.etil.mirai.MiraiConfig.riskyMathRoundOpt) {
|
||||
+ this.awardStat(Stats.FALL_ONE_CM, (int) carpetfixes.helpers.FastMath.round((double) fallDistance * 100.0D));
|
||||
+ } else {
|
||||
+ this.awardStat(Stats.FALL_ONE_CM, (int) Math.round((double) fallDistance * 100.0D));
|
||||
+ }
|
||||
+ // Mirai end
|
||||
}
|
||||
|
||||
return super.causeFallDamage(fallDistance, damageMultiplier, damageSource);
|
||||
diff --git a/src/main/java/net/minecraft/world/item/enchantment/EnchantmentHelper.java b/src/main/java/net/minecraft/world/item/enchantment/EnchantmentHelper.java
|
||||
index 7bc5aa35b52de0027cf58a6127a9903464ccaf47..f34fe699ecfbe1531ba793a0baede5fc49591c48 100644
|
||||
--- a/src/main/java/net/minecraft/world/item/enchantment/EnchantmentHelper.java
|
||||
+++ b/src/main/java/net/minecraft/world/item/enchantment/EnchantmentHelper.java
|
||||
@@ -345,7 +345,13 @@ public class EnchantmentHelper {
|
||||
} else {
|
||||
level += 1 + random.nextInt(i / 4 + 1) + random.nextInt(i / 4 + 1);
|
||||
float f = (random.nextFloat() + random.nextFloat() - 1.0F) * 0.15F;
|
||||
- level = Mth.clamp(Math.round((float)level + (float)level * f), 1, Integer.MAX_VALUE);
|
||||
+ // Mirai start
|
||||
+ if (wtf.etil.mirai.MiraiConfig.riskyMathRoundOpt) {
|
||||
+ level = Mth.clamp(carpetfixes.helpers.FastMath.round((float)level + (float)level * f), 1, Integer.MAX_VALUE);
|
||||
+ } else {
|
||||
+ level = Mth.clamp(Math.round((float)level + (float)level * f), 1, Integer.MAX_VALUE);
|
||||
+ }
|
||||
+ // Mirai end
|
||||
List<EnchantmentInstance> list2 = getAvailableEnchantmentResults(level, stack, treasureAllowed);
|
||||
if (!list2.isEmpty()) {
|
||||
WeightedRandom.getRandomItem(random, list2).ifPresent(list::add);
|
||||
diff --git a/src/main/java/net/minecraft/world/level/block/DaylightDetectorBlock.java b/src/main/java/net/minecraft/world/level/block/DaylightDetectorBlock.java
|
||||
index d212774a4e7c578683394fb4a6c90ce5ce875711..89288c924fd1a024e2eab5119ce7888f6693dc25 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/block/DaylightDetectorBlock.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/block/DaylightDetectorBlock.java
|
||||
@@ -69,7 +69,13 @@ public class DaylightDetectorBlock extends BaseEntityBlock implements IBlock {
|
||||
float f1 = f < 3.1415927F ? 0.0F : 6.2831855F;
|
||||
|
||||
f += (f1 - f) * 0.2F;
|
||||
- i = Math.round((float) i * Mth.cos(f));
|
||||
+ // Mirai start
|
||||
+ if (wtf.etil.mirai.MiraiConfig.riskyMathRoundOpt) {
|
||||
+ i = carpetfixes.helpers.FastMath.round((float) i * Mth.cos(f));
|
||||
+ } else {
|
||||
+ i = Math.round((float) i * Mth.cos(f));
|
||||
+ }
|
||||
+ // Mirai end
|
||||
}
|
||||
|
||||
i = Mth.clamp(i, (int) 0, (int) 15);
|
||||
diff --git a/src/main/java/net/minecraft/world/level/storage/loot/functions/LootingEnchantFunction.java b/src/main/java/net/minecraft/world/level/storage/loot/functions/LootingEnchantFunction.java
|
||||
index 31918fa2eb38e42a5ea5366e559f25ea9d7d59ae..58ca673fb7b9c87ccea67631e3b808da9718330e 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/storage/loot/functions/LootingEnchantFunction.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/storage/loot/functions/LootingEnchantFunction.java
|
||||
@@ -61,7 +61,13 @@ public class LootingEnchantFunction extends LootItemConditionalFunction {
|
||||
|
||||
float f = (float) i * this.value.getFloat(context);
|
||||
|
||||
- stack.grow(Math.round(f));
|
||||
+ // Mirai start
|
||||
+ if (wtf.etil.mirai.MiraiConfig.riskyMathRoundOpt) {
|
||||
+ stack.grow(carpetfixes.helpers.FastMath.round(f));
|
||||
+ } else {
|
||||
+ stack.grow(Math.round(f));
|
||||
+ }
|
||||
+ // Mirai end
|
||||
if (this.hasLimit() && stack.getCount() > this.limit) {
|
||||
stack.setCount(this.limit);
|
||||
}
|
||||
diff --git a/src/main/java/net/minecraft/world/phys/shapes/Shapes.java b/src/main/java/net/minecraft/world/phys/shapes/Shapes.java
|
||||
index 731c7dd15f131dc124be6af8f342b122cb89491b..7a44d9905523d21bb13ebd2edf177175b66a7e52 100644
|
||||
--- a/src/main/java/net/minecraft/world/phys/shapes/Shapes.java
|
||||
+++ b/src/main/java/net/minecraft/world/phys/shapes/Shapes.java
|
||||
@@ -59,8 +59,17 @@ public final class Shapes {
|
||||
int j = 1 << i;
|
||||
double d = min * (double)j;
|
||||
double e = max * (double)j;
|
||||
- boolean bl = Math.abs(d - (double)Math.round(d)) < 1.0E-7D * (double)j;
|
||||
- boolean bl2 = Math.abs(e - (double)Math.round(e)) < 1.0E-7D * (double)j;
|
||||
+ // Mirai start
|
||||
+ boolean bl;
|
||||
+ boolean bl2;
|
||||
+ if (wtf.etil.mirai.MiraiConfig.riskyMathRoundOpt) {
|
||||
+ bl = Math.abs(d - (double)carpetfixes.helpers.FastMath.round(d)) < 1.0E-7D * (double)j;
|
||||
+ bl2 = Math.abs(e - (double)carpetfixes.helpers.FastMath.round(e)) < 1.0E-7D * (double)j;
|
||||
+ } else {
|
||||
+ bl = Math.abs(d - (double)Math.round(d)) < 1.0E-7D * (double)j;
|
||||
+ bl2 = Math.abs(e - (double)Math.round(e)) < 1.0E-7D * (double)j;
|
||||
+ }
|
||||
+ // Mirai end
|
||||
if (bl && bl2) {
|
||||
return i;
|
||||
}
|
||||
diff --git a/src/main/java/org/spigotmc/TicksPerSecondCommand.java b/src/main/java/org/spigotmc/TicksPerSecondCommand.java
|
||||
index 0ecac76577eb440a0c3104ef4603acec826c474d..4ca3e92765426e9d80796c97d1af7c14fbe1f1c3 100644
|
||||
--- a/src/main/java/org/spigotmc/TicksPerSecondCommand.java
|
||||
+++ b/src/main/java/org/spigotmc/TicksPerSecondCommand.java
|
||||
@@ -51,8 +51,15 @@ public class TicksPerSecondCommand extends Command
|
||||
private boolean hasShownMemoryWarning; // Paper
|
||||
private static String format(double tps) // Paper - Made static
|
||||
{
|
||||
- return ( ( tps > 18.0 ) ? ChatColor.GREEN : ( tps > 16.0 ) ? ChatColor.YELLOW : ChatColor.RED ).toString()
|
||||
- + ( ( tps > 21.0 ) ? "*" : "" ) + Math.min( Math.round( tps * 100.0 ) / 100.0, 20.0 ); // Paper - only print * at 21, we commonly peak to 20.02 as the tick sleep is not accurate enough, stop the noise
|
||||
+ // Mirai start
|
||||
+ if (wtf.etil.mirai.MiraiConfig.riskyMathRoundOpt) {
|
||||
+ return ( ( tps > 18.0 ) ? ChatColor.GREEN : ( tps > 16.0 ) ? ChatColor.YELLOW : ChatColor.RED ).toString()
|
||||
+ + ( ( tps > 21.0 ) ? "*" : "" ) + Math.min( carpetfixes.helpers.FastMath.round( tps * 100.0 ) / 100.0, 20.0 ); // Paper - only print * at 21, we commonly peak to 20.02 as the tick sleep is not accurate enough, stop the noise
|
||||
+ } else {
|
||||
+ return ( ( tps > 18.0 ) ? ChatColor.GREEN : ( tps > 16.0 ) ? ChatColor.YELLOW : ChatColor.RED ).toString()
|
||||
+ + ( ( tps > 21.0 ) ? "*" : "" ) + Math.min( Math.round( tps * 100.0 ) / 100.0, 20.0 ); // Paper - only print * at 21, we commonly peak to 20.02 as the tick sleep is not accurate enough, stop the noise
|
||||
+ }
|
||||
+ // Mirai end
|
||||
}
|
||||
|
||||
// Yatopia start - Last tick time API
|
||||
diff --git a/src/main/java/wtf/etil/mirai/MiraiConfig.java b/src/main/java/wtf/etil/mirai/MiraiConfig.java
|
||||
index a41334314a731e8ec6dc3efa77aa564446d26ef8..f4e4ace7dbad9fcbda2537dc024377d1f0770ebc 100644
|
||||
--- a/src/main/java/wtf/etil/mirai/MiraiConfig.java
|
||||
+++ b/src/main/java/wtf/etil/mirai/MiraiConfig.java
|
||||
@@ -257,4 +257,9 @@ public class MiraiConfig {
|
||||
serverMetrics = getBoolean("enable-server-metrics", serverMetrics);
|
||||
}
|
||||
|
||||
+ public static boolean riskyMathRoundOpt = false;
|
||||
+ private static void fastMathRound() {
|
||||
+ riskyMathRoundOpt = getBoolean("use-risky-mathround-opt", riskyMathRoundOpt);
|
||||
+ }
|
||||
+
|
||||
}
|
||||
\ No newline at end of file
|
||||
@@ -34,4 +34,4 @@ index d0c4a1dd2b11cfdbd3972dec5b5622e2f013ab48..9444e3dcdf3fa307c93adb2f790876fc
|
||||
+ // Mirai end
|
||||
}
|
||||
|
||||
public static <T> SetTag<T> empty() {
|
||||
public static <T> SetTag<T> empty() {
|
||||
Reference in New Issue
Block a user