587 lines
36 KiB
Diff
587 lines
36 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: etil2jz <81570777+etil2jz@users.noreply.github.com>
|
|
Date: Wed, 29 Jun 2022 02:49:45 +0200
|
|
Subject: [PATCH] CarpetFixes optimizations
|
|
|
|
Faster Sheep.getOffspringColor
|
|
|
|
Original license: MIT
|
|
Original project: https://github.com/fxmorin/carpet-fixes
|
|
|
|
Copyright (c) 2020 Fx Morin
|
|
|
|
Optimize `Math.round` and `Math.hypot` functions
|
|
|
|
Original license: MIT
|
|
Original project: https://github.com/fxmorin/carpet-fixes
|
|
|
|
Copyright (c) 2020 Fx Morin
|
|
|
|
diff --git a/src/main/java/carpetfixes/helpers/FastMath.java b/src/main/java/carpetfixes/helpers/FastMath.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..1563b21eac06ba0cc57336a639a2d83accb511c9
|
|
--- /dev/null
|
|
+++ b/src/main/java/carpetfixes/helpers/FastMath.java
|
|
@@ -0,0 +1,57 @@
|
|
+package carpetfixes.helpers;
|
|
+
|
|
+public class FastMath {
|
|
+
|
|
+ private static final double HYPOT_MAX_MAG = 2^511;
|
|
+ private static final double HYPOT_FACTOR = 2^750;
|
|
+
|
|
+ /**
|
|
+ * @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);
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * @author FX - PR0CESS
|
|
+ * Hypot implementation from the jafama library. Not 100% accurate! (3E-14%, 15 is perfectly accurate)
|
|
+ * ~1.6x faster than {@link Math#hypot(double,double)}
|
|
+ */
|
|
+ public static double hypot(double x, double y) {
|
|
+ x = Math.abs(x);
|
|
+ y = Math.abs(y);
|
|
+ if (y < x) { // Ensuring x <= y
|
|
+ final double a = x;
|
|
+ x = y;
|
|
+ y = a;
|
|
+ } else if (!(y >= x)) { // Testing if we have some NaN
|
|
+ return x == Double.POSITIVE_INFINITY ? Double.POSITIVE_INFINITY : Double.NaN;
|
|
+ }
|
|
+ if (y-x == y) { // x too small to subtract from y
|
|
+ return y;
|
|
+ } else {
|
|
+ double factor;
|
|
+ if (y > HYPOT_MAX_MAG) { // y is too large: scaling down
|
|
+ x *= (1/HYPOT_FACTOR);
|
|
+ y *= (1/HYPOT_FACTOR);
|
|
+ factor = HYPOT_FACTOR;
|
|
+ } else if (x < (1/HYPOT_MAX_MAG)) { // x is too small: scaling up
|
|
+ x *= HYPOT_FACTOR;
|
|
+ y *= HYPOT_FACTOR;
|
|
+ factor = (1/HYPOT_FACTOR);
|
|
+ } else {
|
|
+ factor = 1.0;
|
|
+ }
|
|
+ return factor * Math.sqrt(x*x+y*y);
|
|
+ }
|
|
+ }
|
|
+}
|
|
\ No newline at end of file
|
|
diff --git a/src/main/java/com/destroystokyo/paper/gui/RAMDetails.java b/src/main/java/com/destroystokyo/paper/gui/RAMDetails.java
|
|
index f9251183df72ddc56662fd3f02acf21641a2200c..525bbe1a07025179cb32d9182fdde1d472b5852e 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( carpetfixes.helpers.FastMath.round( tps * 100.0 ) / 100.0, 20.0 ); // Mirai
|
|
}
|
|
}
|
|
diff --git a/src/main/java/com/destroystokyo/paper/gui/RAMGraph.java b/src/main/java/com/destroystokyo/paper/gui/RAMGraph.java
|
|
index c3e54da4ab6440811aab2f9dd1e218802ac13285..db1319c51a5410ee106d023fce759f1e390872e2 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),
|
|
+ carpetfixes.helpers.FastMath.round(data.getUsedMem() / 1024F / 1024F), // Mirai
|
|
used, getTime(m.x)));
|
|
}
|
|
}
|
|
diff --git a/src/main/java/io/papermc/paper/chunk/PlayerChunkLoader.java b/src/main/java/io/papermc/paper/chunk/PlayerChunkLoader.java
|
|
index 0b060183429f4c72ec767075538477b4302bbf0d..75e7d181a8dff7247c6db8448cbf5f22772eab4b 100644
|
|
--- a/src/main/java/io/papermc/paper/chunk/PlayerChunkLoader.java
|
|
+++ b/src/main/java/io/papermc/paper/chunk/PlayerChunkLoader.java
|
|
@@ -387,11 +387,11 @@ public final class PlayerChunkLoader {
|
|
}
|
|
|
|
protected long getTargetSendPerPlayerAddend() {
|
|
- return GlobalConfiguration.get().chunkLoading.targetPlayerChunkSendRate <= 1.0 ? 0L : (long)Math.round(1.0e9 / GlobalConfiguration.get().chunkLoading.targetPlayerChunkSendRate);
|
|
+ return GlobalConfiguration.get().chunkLoading.targetPlayerChunkSendRate <= 1.0 ? 0L : (long)carpetfixes.helpers.FastMath.round(1.0e9 / GlobalConfiguration.get().chunkLoading.targetPlayerChunkSendRate); // Mirai
|
|
}
|
|
|
|
protected long getMaxSendAddend() {
|
|
- return GlobalConfiguration.get().chunkLoading.globalMaxChunkSendRate <= 1.0 ? 0L : (long)Math.round(1.0e9 / GlobalConfiguration.get().chunkLoading.globalMaxChunkSendRate);
|
|
+ return GlobalConfiguration.get().chunkLoading.globalMaxChunkSendRate <= 1.0 ? 0L : (long)carpetfixes.helpers.FastMath.round(1.0e9 / GlobalConfiguration.get().chunkLoading.globalMaxChunkSendRate); // Mirai
|
|
}
|
|
|
|
public void onChunkPlayerTickReady(final int chunkX, final int chunkZ) {
|
|
diff --git a/src/main/java/io/papermc/paper/command/subcommands/FixLightCommand.java b/src/main/java/io/papermc/paper/command/subcommands/FixLightCommand.java
|
|
index 7784d72ddd6db00c674e22759c00c430222c4b85..0f180d11774f6dec2667b3a3f6a63d1127bac869 100644
|
|
--- a/src/main/java/io/papermc/paper/command/subcommands/FixLightCommand.java
|
|
+++ b/src/main/java/io/papermc/paper/command/subcommands/FixLightCommand.java
|
|
@@ -95,12 +95,12 @@ public final class FixLightCommand implements PaperSubcommand {
|
|
++relitChunks[0];
|
|
sender.getBukkitEntity().sendMessage(text().color(DARK_AQUA).append(
|
|
text("Relit chunk ", BLUE), text(chunkPos.toString()),
|
|
- text(", progress: ", BLUE), text((int) (Math.round(100.0 * (double) (relitChunks[0]) / (double) pending[0])) + "%")
|
|
+ text(", progress: ", BLUE), text((int) (carpetfixes.helpers.FastMath.round(100.0 * (double) (relitChunks[0]) / (double) pending[0])) + "%") // Mirai
|
|
));
|
|
},
|
|
(final int totalRelit) -> {
|
|
final long end = System.nanoTime();
|
|
- final long diff = Math.round(1.0e-6 * (end - start));
|
|
+ final long diff = carpetfixes.helpers.FastMath.round(1.0e-6 * (end - start)); // Mirai
|
|
sender.getBukkitEntity().sendMessage(text().color(DARK_AQUA).append(
|
|
text("Relit ", BLUE), text(totalRelit),
|
|
text(" chunks. Took ", BLUE), text(diff + "ms")
|
|
diff --git a/src/main/java/net/minecraft/commands/arguments/TimeArgument.java b/src/main/java/net/minecraft/commands/arguments/TimeArgument.java
|
|
index e3e80db89c18588322ffdaa0f9fd85e398cb1471..d947011b80ee14e7aaf74af3d9081fc78e8cb4c3 100644
|
|
--- a/src/main/java/net/minecraft/commands/arguments/TimeArgument.java
|
|
+++ b/src/main/java/net/minecraft/commands/arguments/TimeArgument.java
|
|
@@ -35,7 +35,7 @@ public class TimeArgument implements ArgumentType<Integer> {
|
|
if (i == 0) {
|
|
throw ERROR_INVALID_UNIT.create();
|
|
} else {
|
|
- int j = Math.round(f * (float)i);
|
|
+ int j = carpetfixes.helpers.FastMath.round(f * (float)i); // Mirai
|
|
if (j < 0) {
|
|
throw ERROR_INVALID_TICK_COUNT.create(j);
|
|
} else {
|
|
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
index 735e01c550d561aa21c3c8f7f34a495ec3a0ab67..795c631bb5edc696a4e52703b1819fcddfb800e2 100644
|
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
@@ -2786,7 +2786,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
}
|
|
|
|
double overuseCount = (double)overuse/(double)MAX_CHUNK_EXEC_TIME;
|
|
- long extraSleep = (long)Math.round(overuseCount*CHUNK_TASK_QUEUE_BACKOFF_MIN_TIME);
|
|
+ long extraSleep = (long)carpetfixes.helpers.FastMath.round(overuseCount*CHUNK_TASK_QUEUE_BACKOFF_MIN_TIME); // Mirai
|
|
|
|
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..45b2aa542969798a5a3b73af78de21ccc57bcca1 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(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 // Mirai
|
|
}
|
|
// Paper end
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/util/Mth.java b/src/main/java/net/minecraft/util/Mth.java
|
|
index c852331f0c9dddbfe29e88e2dca1dceb2d7cee44..67ca2a39236ecfaeb54294b8b6b9fdb109b54513 100644
|
|
--- a/src/main/java/net/minecraft/util/Mth.java
|
|
+++ b/src/main/java/net/minecraft/util/Mth.java
|
|
@@ -792,7 +792,7 @@ public class Mth {
|
|
}
|
|
|
|
public static double length(double a, double b) {
|
|
- return Math.sqrt(lengthSquared(a, b));
|
|
+ return carpetfixes.helpers.FastMath.hypot(a, b); // Mirai
|
|
}
|
|
|
|
public static double lengthSquared(double a, double b, double c) {
|
|
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
index 219c7dcbe6bee5054aff0640a80d620eded812c0..87655d7c3dfbbd6bf348d693445c71d5601ed9c3 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
@@ -1529,7 +1529,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, carpetfixes.helpers.FastMath.round(f2 * 10.0F)); // Mirai
|
|
}
|
|
}
|
|
|
|
@@ -2097,9 +2097,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, carpetfixes.helpers.FastMath.round(f3 * 10.0F)); // Mirai
|
|
} 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, carpetfixes.helpers.FastMath.round(f3 * 10.0F)); // Mirai
|
|
}
|
|
}
|
|
}
|
|
@@ -2211,9 +2211,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, carpetfixes.helpers.FastMath.round(f3 * 10.0F)); // Mirai
|
|
} 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, carpetfixes.helpers.FastMath.round(f3 * 10.0F)); // Mirai
|
|
}
|
|
}
|
|
}
|
|
@@ -2245,10 +2245,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, carpetfixes.helpers.FastMath.round(f2 * 10.0F)); // Mirai
|
|
}
|
|
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, carpetfixes.helpers.FastMath.round(f2 * 10.0F)); // Mirai
|
|
}
|
|
|
|
// Purpur start
|
|
@@ -2270,7 +2270,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, carpetfixes.helpers.FastMath.round(f * 10.0F)); // Mirai
|
|
}
|
|
}
|
|
// CraftBukkit end
|
|
@@ -2292,7 +2292,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, carpetfixes.helpers.FastMath.round(originalDamage * 10.0F)); // Mirai
|
|
}
|
|
}
|
|
|
|
@@ -3097,13 +3097,13 @@ public abstract class LivingEntity extends Entity {
|
|
//this.level.getProfiler().push("rangeChecks"); // Purpur
|
|
|
|
// Paper start - stop large pitch and yaw changes from crashing the server
|
|
- this.yRotO += Math.round((this.getYRot() - this.yRotO) / 360.0F) * 360.0F;
|
|
+ this.yRotO += carpetfixes.helpers.FastMath.round((this.getYRot() - this.yRotO) / 360.0F) * 360.0F; // Mirai
|
|
|
|
- this.yBodyRotO += Math.round((this.yBodyRot - this.yBodyRotO) / 360.0F) * 360.0F;
|
|
+ this.yBodyRotO += carpetfixes.helpers.FastMath.round((this.yBodyRot - this.yBodyRotO) / 360.0F) * 360.0F; // Mirai
|
|
|
|
- this.xRotO += Math.round((this.getXRot() - this.xRotO) / 360.0F) * 360.0F;
|
|
+ this.xRotO += carpetfixes.helpers.FastMath.round((this.getXRot() - this.xRotO) / 360.0F) * 360.0F; // Mirai
|
|
|
|
- this.yHeadRotO += Math.round((this.yHeadRot - this.yHeadRotO) / 360.0F) * 360.0F;
|
|
+ this.yHeadRotO += carpetfixes.helpers.FastMath.round((this.yHeadRot - this.yHeadRotO) / 360.0F) * 360.0F; // Mirai
|
|
// Paper end
|
|
|
|
//this.level.getProfiler().pop(); // Purpur
|
|
diff --git a/src/main/java/net/minecraft/world/entity/animal/Sheep.java b/src/main/java/net/minecraft/world/entity/animal/Sheep.java
|
|
index 954a12c23da96a07cd175f6f2eb28e8c5d2a8c3d..e5bef70e9a5abfec859757bc47b003d24a0dd171 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/animal/Sheep.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/animal/Sheep.java
|
|
@@ -406,21 +406,56 @@ public class Sheep extends Animal implements Shearable {
|
|
return super.finalizeSpawn(world, difficulty, spawnReason, entityData, entityNbt);
|
|
}
|
|
|
|
+ // Mirai start
|
|
+ private static DyeColor properDye(DyeColor firstColor, DyeColor secondColor) {
|
|
+ if (firstColor.equals(secondColor)) return firstColor;
|
|
+ switch(firstColor) {
|
|
+ case WHITE -> {
|
|
+ switch(secondColor) {
|
|
+ case BLUE -> {return DyeColor.LIGHT_BLUE;}
|
|
+ case GRAY -> {return DyeColor.LIGHT_GRAY;}
|
|
+ case BLACK -> {return DyeColor.GRAY;}
|
|
+ case GREEN -> {return DyeColor.LIME;}
|
|
+ case RED -> {return DyeColor.PINK;}
|
|
+ }
|
|
+ }
|
|
+ case BLUE -> {
|
|
+ switch(secondColor) {
|
|
+ case WHITE -> {return DyeColor.LIGHT_BLUE;}
|
|
+ case GREEN -> {return DyeColor.CYAN;}
|
|
+ case RED -> {return DyeColor.PURPLE;}
|
|
+ }
|
|
+ }
|
|
+ case RED -> {
|
|
+ switch(secondColor) {
|
|
+ case YELLOW -> {return DyeColor.ORANGE;}
|
|
+ case WHITE -> {return DyeColor.PINK;}
|
|
+ case BLUE -> {return DyeColor.PURPLE;}
|
|
+ }
|
|
+ }
|
|
+ case GREEN -> {
|
|
+ switch(secondColor) {
|
|
+ case BLUE -> {return DyeColor.CYAN;}
|
|
+ case WHITE -> {return DyeColor.LIME;}
|
|
+ }
|
|
+ }
|
|
+ case YELLOW -> {if (secondColor.equals(DyeColor.RED)) return DyeColor.ORANGE;}
|
|
+ case PURPLE -> {if (secondColor.equals(DyeColor.PINK)) return DyeColor.MAGENTA;}
|
|
+ case PINK -> {if (secondColor.equals(DyeColor.PURPLE)) return DyeColor.MAGENTA;}
|
|
+ case GRAY -> {if (secondColor.equals(DyeColor.WHITE)) return DyeColor.LIGHT_GRAY;}
|
|
+ case BLACK -> {if (secondColor.equals(DyeColor.WHITE)) return DyeColor.GRAY;}
|
|
+ }
|
|
+ return null;
|
|
+ }
|
|
+
|
|
private DyeColor getOffspringColor(Animal firstParent, Animal secondParent) {
|
|
- DyeColor enumcolor = ((Sheep) firstParent).getColor();
|
|
- DyeColor enumcolor1 = ((Sheep) secondParent).getColor();
|
|
- CraftingContainer inventorycrafting = Sheep.makeContainer(enumcolor, enumcolor1);
|
|
- Optional<Item> optional = this.level.getRecipeManager().getRecipeFor(RecipeType.CRAFTING, inventorycrafting, this.level).map((recipecrafting) -> { // CraftBukkit - decompile error
|
|
- return recipecrafting.assemble(inventorycrafting);
|
|
- }).map(ItemStack::getItem);
|
|
-
|
|
- Objects.requireNonNull(DyeItem.class);
|
|
- optional = optional.filter(DyeItem.class::isInstance);
|
|
- Objects.requireNonNull(DyeItem.class);
|
|
- return (DyeColor) optional.map(DyeItem.class::cast).map(DyeItem::getDyeColor).orElseGet(() -> {
|
|
- return this.level.random.nextBoolean() ? enumcolor : enumcolor1;
|
|
- });
|
|
+ DyeColor firstColor = ((Sheep)firstParent).getColor();
|
|
+ DyeColor secondColor = ((Sheep)secondParent).getColor();
|
|
+ DyeColor col = properDye(firstColor,secondColor);
|
|
+ if (col == null) col = this.level.random.nextBoolean() ? firstColor : secondColor;
|
|
+ return col;
|
|
}
|
|
+ // Mirai end
|
|
|
|
private static CraftingContainer makeContainer(DyeColor firstColor, DyeColor secondColor) {
|
|
CraftingContainer inventorycrafting = new CraftingContainer(new AbstractContainerMenu((MenuType) null, -1) {
|
|
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 1b7e38538881ba00ffdbe9226952627151532c5c..ff57940690dd9a1f43dab16d5b26432210659cc4 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
|
|
@@ -1126,7 +1126,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, carpetfixes.helpers.FastMath.round(f2 * 10.0F)); // Mirai
|
|
}
|
|
|
|
if (f != 0.0F) {
|
|
@@ -1136,7 +1136,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, carpetfixes.helpers.FastMath.round(f * 10.0F)); // Mirai
|
|
}
|
|
|
|
}
|
|
@@ -1471,7 +1471,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, carpetfixes.helpers.FastMath.round(f5 * 10.0F)); // Mirai
|
|
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);
|
|
@@ -1744,29 +1744,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 = carpetfixes.helpers.FastMath.round((float) Math.sqrt(dx * dx + dy * dy + dz * dz) * 100.0F); // Mirai
|
|
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 = carpetfixes.helpers.FastMath.round((float) Math.sqrt(dx * dx + dy * dy + dz * dz) * 100.0F); // Mirai
|
|
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 = carpetfixes.helpers.FastMath.round((float) Math.sqrt(dx * dx + dz * dz) * 100.0F); // Mirai
|
|
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) carpetfixes.helpers.FastMath.round(dy * 100.0D)); // Mirai
|
|
}
|
|
} else if (this.onGround) {
|
|
- i = Math.round((float) Math.sqrt(dx * dx + dz * dz) * 100.0F);
|
|
+ i = carpetfixes.helpers.FastMath.round((float) Math.sqrt(dx * dx + dz * dz) * 100.0F); // Mirai
|
|
if (i > 0) {
|
|
if (this.isSprinting()) {
|
|
this.awardStat(Stats.SPRINT_ONE_CM, i);
|
|
@@ -1780,10 +1780,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 = carpetfixes.helpers.FastMath.round((float) Math.sqrt(dx * dx + dy * dy + dz * dz) * 100.0F); // Mirai
|
|
this.awardStat(Stats.AVIATE_ONE_CM, i);
|
|
} else {
|
|
- i = Math.round((float) Math.sqrt(dx * dx + dz * dz) * 100.0F);
|
|
+ i = carpetfixes.helpers.FastMath.round((float) Math.sqrt(dx * dx + dz * dz) * 100.0F); // Mirai
|
|
if (i > 25) {
|
|
this.awardStat(Stats.FLY_ONE_CM, i);
|
|
}
|
|
@@ -1794,7 +1794,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 = carpetfixes.helpers.FastMath.round((float) Math.sqrt(dx * dx + dy * dy + dz * dz) * 100.0F); // Mirai
|
|
|
|
if (i > 0) {
|
|
Entity entity = this.getVehicle();
|
|
@@ -1821,7 +1821,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) carpetfixes.helpers.FastMath.round((double) fallDistance * 100.0D)); // Mirai
|
|
}
|
|
|
|
return super.causeFallDamage(fallDistance, damageMultiplier, damageSource);
|
|
diff --git a/src/main/java/net/minecraft/world/item/Item.java b/src/main/java/net/minecraft/world/item/Item.java
|
|
index 8b250dab8f3cb788ae1cfad43737afda31b72c0f..7e57163c82f7a4f9df0774f049f724c9b201e023 100644
|
|
--- a/src/main/java/net/minecraft/world/item/Item.java
|
|
+++ b/src/main/java/net/minecraft/world/item/Item.java
|
|
@@ -166,7 +166,7 @@ public class Item implements ItemLike {
|
|
}
|
|
|
|
public int getBarWidth(ItemStack stack) {
|
|
- return Math.round(13.0F - (float)stack.getDamageValue() * 13.0F / (float)this.maxDamage);
|
|
+ return carpetfixes.helpers.FastMath.round(13.0F - (float)stack.getDamageValue() * 13.0F / (float)this.maxDamage); // Mirai
|
|
}
|
|
|
|
public int getBarColor(ItemStack stack) {
|
|
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 1d79da7f8405f7dff3b2e10022a564a9cf2609eb..1d697e31e4bf5a94341f8044b8d580da019e94d7 100644
|
|
--- a/src/main/java/net/minecraft/world/item/enchantment/EnchantmentHelper.java
|
|
+++ b/src/main/java/net/minecraft/world/item/enchantment/EnchantmentHelper.java
|
|
@@ -369,7 +369,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(carpetfixes.helpers.FastMath.round((float)level + (float)level * f), 1, Integer.MAX_VALUE); // Mirai
|
|
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 16504b8be08064e61b013fa943f692816612cbd0..38f6759501dcc2a0adb9608a9f639c2411acf277 100644
|
|
--- a/src/main/java/net/minecraft/world/level/block/DaylightDetectorBlock.java
|
|
+++ b/src/main/java/net/minecraft/world/level/block/DaylightDetectorBlock.java
|
|
@@ -62,7 +62,7 @@ public class DaylightDetectorBlock extends BaseEntityBlock {
|
|
float f1 = f < 3.1415927F ? 0.0F : 6.2831855F;
|
|
|
|
f += (f1 - f) * 0.2F;
|
|
- i = Math.round((float) i * Mth.cos(f));
|
|
+ i = carpetfixes.helpers.FastMath.round((float) i * Mth.cos(f)); // Mirai
|
|
}
|
|
|
|
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 9579889e4c7dedefc4f901ccac6157c425740481..7904e80ff9476221ffac153494c1ecbd9b9cd9d9 100644
|
|
--- a/src/main/java/net/minecraft/world/level/chunk/ChunkGenerator.java
|
|
+++ b/src/main/java/net/minecraft/world/level/chunk/ChunkGenerator.java
|
|
@@ -254,8 +254,8 @@ public abstract class ChunkGenerator {
|
|
|
|
for (int j1 = 0; j1 < j; ++j1) {
|
|
double d1 = (double) (4 * i + i * i1 * 6) + (randomsource.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) carpetfixes.helpers.FastMath.round(Math.cos(d0) * d1); // Mirai
|
|
+ int l1 = (int) carpetfixes.helpers.FastMath.round(Math.sin(d0) * d1); // Mirai
|
|
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/levelgen/SurfaceSystem.java b/src/main/java/net/minecraft/world/level/levelgen/SurfaceSystem.java
|
|
index b20ba0b10b5b1682bb5435d9d0bbe4aad25e8062..22a23580ccd861d14031f46b72f309cca6584d3b 100644
|
|
--- a/src/main/java/net/minecraft/world/level/levelgen/SurfaceSystem.java
|
|
+++ b/src/main/java/net/minecraft/world/level/levelgen/SurfaceSystem.java
|
|
@@ -300,7 +300,7 @@ public class SurfaceSystem {
|
|
}
|
|
|
|
protected BlockState getBand(int x, int y, int z) {
|
|
- int i = (int)Math.round(this.clayBandsOffsetNoise.getValue((double)x, 0.0D, (double)z) * 4.0D);
|
|
+ int i = (int)carpetfixes.helpers.FastMath.round(this.clayBandsOffsetNoise.getValue((double)x, 0.0D, (double)z) * 4.0D); // Mirai
|
|
return this.clayBands[(y + i + this.clayBands.length) % this.clayBands.length];
|
|
}
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/world/level/levelgen/feature/ScatteredOreFeature.java b/src/main/java/net/minecraft/world/level/levelgen/feature/ScatteredOreFeature.java
|
|
index 06f27fc8eda9ec160c54759ec95fdade19876d29..567d653469c964922dc5662e48c45dc289222bc2 100644
|
|
--- a/src/main/java/net/minecraft/world/level/levelgen/feature/ScatteredOreFeature.java
|
|
+++ b/src/main/java/net/minecraft/world/level/levelgen/feature/ScatteredOreFeature.java
|
|
@@ -46,6 +46,6 @@ public class ScatteredOreFeature extends Feature<OreConfiguration> {
|
|
}
|
|
|
|
private int getRandomPlacementInOneAxisRelativeToOrigin(RandomSource randomSource, int spread) {
|
|
- return Math.round((randomSource.nextFloat() - randomSource.nextFloat()) * (float)spread);
|
|
+ return carpetfixes.helpers.FastMath.round((randomSource.nextFloat() - randomSource.nextFloat()) * (float)spread); // Mirai
|
|
}
|
|
}
|
|
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 15d8e9261a89da30529ac347462c520920ca4e7d..477003d735548ef2f8152681a31fef3354e1f949 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
|
|
@@ -68,7 +68,7 @@ public class LootingEnchantFunction extends LootItemConditionalFunction {
|
|
|
|
float f = (float) i * this.value.getFloat(context);
|
|
|
|
- stack.grow(Math.round(f));
|
|
+ stack.grow(carpetfixes.helpers.FastMath.round(f)); // Mirai
|
|
if (this.hasLimit() && stack.getCount() > this.limit) {
|
|
stack.setCount(this.limit);
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/world/level/storage/loot/providers/number/NumberProvider.java b/src/main/java/net/minecraft/world/level/storage/loot/providers/number/NumberProvider.java
|
|
index 2a7c75ea447b179ea1ab9db56e8a39d03faa0bce..53ca87c7659a4fff9e99d21217d1ad08c8765836 100644
|
|
--- a/src/main/java/net/minecraft/world/level/storage/loot/providers/number/NumberProvider.java
|
|
+++ b/src/main/java/net/minecraft/world/level/storage/loot/providers/number/NumberProvider.java
|
|
@@ -7,7 +7,7 @@ public interface NumberProvider extends LootContextUser {
|
|
float getFloat(LootContext context);
|
|
|
|
default int getInt(LootContext context) {
|
|
- return Math.round(this.getFloat(context));
|
|
+ return carpetfixes.helpers.FastMath.round(this.getFloat(context)); // Mirai
|
|
}
|
|
|
|
LootNumberProviderType getType();
|
|
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..24a82111a5485da1e3903977d0519e9ed502f34d 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)carpetfixes.helpers.FastMath.round(d)) < 1.0E-7D * (double)j; // Mirai
|
|
+ boolean bl2 = Math.abs(e - (double)carpetfixes.helpers.FastMath.round(e)) < 1.0E-7D * (double)j; // Mirai
|
|
if (bl && bl2) {
|
|
return i;
|
|
}
|
|
diff --git a/src/main/java/org/spigotmc/TicksPerSecondCommand.java b/src/main/java/org/spigotmc/TicksPerSecondCommand.java
|
|
index 088239d17aa8178cf8af09ec23cfd4deaaf2bbb6..6a02c713c9e5b0a2fb4f8d2a47a62344af12ef95 100644
|
|
--- a/src/main/java/org/spigotmc/TicksPerSecondCommand.java
|
|
+++ b/src/main/java/org/spigotmc/TicksPerSecondCommand.java
|
|
@@ -48,6 +48,6 @@ 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( 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 // Mirai
|
|
}
|
|
}
|