|
| 1 | +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | +From: HaHaWTH <id_cn00@outlook.com> |
| 3 | +Date: Tue, 30 Apr 2024 11:28:41 +0800 |
| 4 | +Subject: [PATCH] Carpet-fast-math-round |
| 5 | + |
| 6 | + |
| 7 | +diff --git a/src/main/java/com/homomc/beast/math/FastMath.java b/src/main/java/com/homomc/beast/math/FastMath.java |
| 8 | +new file mode 100644 |
| 9 | +index 0000000000000000000000000000000000000000..42af7aca584bf580c11484ea179ddda1ab2efb73 |
| 10 | +--- /dev/null |
| 11 | ++++ b/src/main/java/com/homomc/beast/math/FastMath.java |
| 12 | +@@ -0,0 +1,21 @@ |
| 13 | ++package com.homomc.beast.math; |
| 14 | ++ |
| 15 | ++public class FastMath { |
| 16 | ++ /** |
| 17 | ++ * @author FX - PR0CESS |
| 18 | ++ * ~1.25x faster than {@link Math#round(float)} |
| 19 | ++ */ |
| 20 | ++ public static int round(float a) { |
| 21 | ++ if (true) return a > 0F ? (int)(a + .5F) : (int)(a - .5F); |
| 22 | ++ return Math.round(a); |
| 23 | ++ } |
| 24 | ++ |
| 25 | ++ /** |
| 26 | ++ * @author FX - PR0CESS |
| 27 | ++ * ~1.28x faster than {@link Math#round(double)} |
| 28 | ++ */ |
| 29 | ++ public static long round(double a) { |
| 30 | ++ if (true) return a > 0D ? (long)(a + .5D) : (long)(a - .5D); |
| 31 | ++ return Math.round(a); |
| 32 | ++ } |
| 33 | ++} |
| 34 | +diff --git a/src/main/java/net/minecraft/server/BiomeMesa.java b/src/main/java/net/minecraft/server/BiomeMesa.java |
| 35 | +index 57067c0910b4de438b8b44edcfc59187da129a51..c2826f05d4cb5760424d2c36621c320ef0ff1482 100644 |
| 36 | +--- a/src/main/java/net/minecraft/server/BiomeMesa.java |
| 37 | ++++ b/src/main/java/net/minecraft/server/BiomeMesa.java |
| 38 | +@@ -248,7 +248,7 @@ public class BiomeMesa extends BiomeBase { |
| 39 | + } |
| 40 | + |
| 41 | + private IBlockData a(int i, int j, int k) { |
| 42 | +- int l = (int) Math.round(this.H.a((double) i / 512.0D, (double) i / 512.0D) * 2.0D); |
| 43 | ++ int l = (int) com.homomc.beast.math.FastMath.round(this.H.a((double) i / 512.0D, (double) i / 512.0D) * 2.0D); |
| 44 | + |
| 45 | + return this.D[(j + l + 64) % 64]; |
| 46 | + } |
| 47 | +diff --git a/src/main/java/net/minecraft/server/BlockDaylightDetector.java b/src/main/java/net/minecraft/server/BlockDaylightDetector.java |
| 48 | +index e9a909080d5176f351ca71b45b3d44af5292d649..713467bfe0b47a3d7939c63308b5fe6e6edd8696 100644 |
| 49 | +--- a/src/main/java/net/minecraft/server/BlockDaylightDetector.java |
| 50 | ++++ b/src/main/java/net/minecraft/server/BlockDaylightDetector.java |
| 51 | +@@ -40,7 +40,7 @@ public class BlockDaylightDetector extends BlockTileEntity { |
| 52 | + float f1 = f < 3.1415927F ? 0.0F : 6.2831855F; |
| 53 | + |
| 54 | + f += (f1 - f) * 0.2F; |
| 55 | +- i = Math.round((float) i * MathHelper.cos(f)); |
| 56 | ++ i = com.homomc.beast.math.FastMath.round((float) i * MathHelper.cos(f)); |
| 57 | + } |
| 58 | + |
| 59 | + i = MathHelper.clamp(i, 0, 15); |
| 60 | +diff --git a/src/main/java/net/minecraft/server/EnchantmentManager.java b/src/main/java/net/minecraft/server/EnchantmentManager.java |
| 61 | +index 563ebe80ef1317b67c0518be8de7b4c3be5f2dca..b649c84c6dd6403b833c67d98f0df03c10437327 100644 |
| 62 | +--- a/src/main/java/net/minecraft/server/EnchantmentManager.java |
| 63 | ++++ b/src/main/java/net/minecraft/server/EnchantmentManager.java |
| 64 | +@@ -323,7 +323,7 @@ public class EnchantmentManager { |
| 65 | + i += 1 + random.nextInt(j / 4 + 1) + random.nextInt(j / 4 + 1); |
| 66 | + float f = (random.nextFloat() + random.nextFloat() - 1.0F) * 0.15F; |
| 67 | + |
| 68 | +- i = MathHelper.clamp(Math.round((float) i + (float) i * f), 1, Integer.MAX_VALUE); |
| 69 | ++ i = MathHelper.clamp(com.homomc.beast.math.FastMath.round((float) i + (float) i * f), 1, Integer.MAX_VALUE); |
| 70 | + List list = a(i, itemstack, flag); |
| 71 | + |
| 72 | + if (!list.isEmpty()) { |
| 73 | +diff --git a/src/main/java/net/minecraft/server/EntityHuman.java b/src/main/java/net/minecraft/server/EntityHuman.java |
| 74 | +index 727bc5c094ecaeb4b3e51764ae853c98a8a6b175..9c1fb77261eafc4bba11d9f1a3f717701852ce39 100644 |
| 75 | +--- a/src/main/java/net/minecraft/server/EntityHuman.java |
| 76 | ++++ b/src/main/java/net/minecraft/server/EntityHuman.java |
| 77 | +@@ -882,7 +882,7 @@ public abstract class EntityHuman extends EntityLiving { |
| 78 | + this.setHealth(this.getHealth() - f); |
| 79 | + this.getCombatTracker().trackDamage(damagesource, f2, f); |
| 80 | + if (f < 3.4028235E37F) { |
| 81 | +- this.a(StatisticList.z, Math.round(f * 10.0F)); |
| 82 | ++ this.a(StatisticList.z, com.homomc.beast.math.FastMath.round(f * 10.0F)); |
| 83 | + } |
| 84 | + |
| 85 | + } |
| 86 | +@@ -1157,7 +1157,7 @@ public abstract class EntityHuman extends EntityLiving { |
| 87 | + if (entity instanceof EntityLiving) { |
| 88 | + float f5 = f3 - ((EntityLiving) entity).getHealth(); |
| 89 | + |
| 90 | +- this.a(StatisticList.y, Math.round(f5 * 10.0F)); |
| 91 | ++ this.a(StatisticList.y, com.homomc.beast.math.FastMath.round(f5 * 10.0F)); |
| 92 | + if (j > 0) { |
| 93 | + // CraftBukkit start - Call a combust event when somebody hits with a fire enchanted item |
| 94 | + EntityCombustByEntityEvent combustEvent = new EntityCombustByEntityEvent(this.getBukkitEntity(), entity.getBukkitEntity(), j * 4); |
| 95 | +@@ -1498,23 +1498,23 @@ public abstract class EntityHuman extends EntityLiving { |
| 96 | + int i; |
| 97 | + |
| 98 | + if (this.a(Material.WATER)) { |
| 99 | +- i = Math.round(MathHelper.sqrt(d0 * d0 + d1 * d1 + d2 * d2) * 100.0F); |
| 100 | ++ i = com.homomc.beast.math.FastMath.round(MathHelper.sqrt(d0 * d0 + d1 * d1 + d2 * d2) * 100.0F); |
| 101 | + if (i > 0) { |
| 102 | + this.a(StatisticList.q, i); |
| 103 | + this.applyExhaustion(world.spigotConfig.swimMultiplier * (float) i * 0.01F); // Spigot |
| 104 | + } |
| 105 | + } else if (this.isInWater()) { |
| 106 | +- i = Math.round(MathHelper.sqrt(d0 * d0 + d2 * d2) * 100.0F); |
| 107 | ++ i = com.homomc.beast.math.FastMath.round(MathHelper.sqrt(d0 * d0 + d2 * d2) * 100.0F); |
| 108 | + if (i > 0) { |
| 109 | + this.a(StatisticList.m, i); |
| 110 | + this.applyExhaustion(world.spigotConfig.swimMultiplier * (float) i * 0.01F); // Spigot |
| 111 | + } |
| 112 | + } else if (this.m_()) { |
| 113 | + if (d1 > 0.0D) { |
| 114 | +- this.a(StatisticList.o, (int) Math.round(d1 * 100.0D)); |
| 115 | ++ this.a(StatisticList.o, (int) com.homomc.beast.math.FastMath.round(d1 * 100.0D)); |
| 116 | + } |
| 117 | + } else if (this.onGround) { |
| 118 | +- i = Math.round(MathHelper.sqrt(d0 * d0 + d2 * d2) * 100.0F); |
| 119 | ++ i = com.homomc.beast.math.FastMath.round(MathHelper.sqrt(d0 * d0 + d2 * d2) * 100.0F); |
| 120 | + if (i > 0) { |
| 121 | + if (this.isSprinting()) { |
| 122 | + this.a(StatisticList.l, i); |
| 123 | +@@ -1528,10 +1528,10 @@ public abstract class EntityHuman extends EntityLiving { |
| 124 | + } |
| 125 | + } |
| 126 | + } else if (this.cP()) { |
| 127 | +- i = Math.round(MathHelper.sqrt(d0 * d0 + d1 * d1 + d2 * d2) * 100.0F); |
| 128 | ++ i = com.homomc.beast.math.FastMath.round(MathHelper.sqrt(d0 * d0 + d1 * d1 + d2 * d2) * 100.0F); |
| 129 | + this.a(StatisticList.v, i); |
| 130 | + } else { |
| 131 | +- i = Math.round(MathHelper.sqrt(d0 * d0 + d2 * d2) * 100.0F); |
| 132 | ++ i = com.homomc.beast.math.FastMath.round(MathHelper.sqrt(d0 * d0 + d2 * d2) * 100.0F); |
| 133 | + if (i > 25) { |
| 134 | + this.a(StatisticList.p, i); |
| 135 | + } |
| 136 | +@@ -1542,7 +1542,7 @@ public abstract class EntityHuman extends EntityLiving { |
| 137 | + |
| 138 | + private void l(double d0, double d1, double d2) { |
| 139 | + if (this.isPassenger()) { |
| 140 | +- int i = Math.round(MathHelper.sqrt(d0 * d0 + d1 * d1 + d2 * d2) * 100.0F); |
| 141 | ++ int i = com.homomc.beast.math.FastMath.round(MathHelper.sqrt(d0 * d0 + d1 * d1 + d2 * d2) * 100.0F); |
| 142 | + |
| 143 | + if (i > 0) { |
| 144 | + if (this.bJ() instanceof EntityMinecartAbstract) { |
| 145 | +@@ -1562,7 +1562,7 @@ public abstract class EntityHuman extends EntityLiving { |
| 146 | + public void e(float f, float f1) { |
| 147 | + if (!this.abilities.canFly) { |
| 148 | + if (f >= 2.0F) { |
| 149 | +- this.a(StatisticList.n, (int) Math.round((double) f * 100.0D)); |
| 150 | ++ this.a(StatisticList.n, (int) com.homomc.beast.math.FastMath.round((double) f * 100.0D)); |
| 151 | + } |
| 152 | + |
| 153 | + super.e(f, f1); |
| 154 | +diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java |
| 155 | +index 78e5231e566f1ec7788064a3800317bfd7cfc495..c80ada2ad5d858e63755206b63c9b19a22ad4050 100644 |
| 156 | +--- a/src/main/java/net/minecraft/server/EntityLiving.java |
| 157 | ++++ b/src/main/java/net/minecraft/server/EntityLiving.java |
| 158 | +@@ -1475,7 +1475,7 @@ public abstract class EntityLiving extends Entity { |
| 159 | + // PAIL: Be sure to drag all this code from the EntityHuman subclass each update. |
| 160 | + ((EntityHuman) this).applyExhaustion(damagesource.getExhaustionCost()); |
| 161 | + if (f < 3.4028235E37F) { |
| 162 | +- ((EntityHuman) this).a(StatisticList.z, Math.round(f * 10.0F)); |
| 163 | ++ ((EntityHuman) this).a(StatisticList.z, com.homomc.beast.math.FastMath.round(f * 10.0F)); |
| 164 | + } |
| 165 | + } |
| 166 | + // CraftBukkit end |
| 167 | +diff --git a/src/main/java/net/minecraft/server/EntitySkeletonAbstract.java b/src/main/java/net/minecraft/server/EntitySkeletonAbstract.java |
| 168 | +index b28de2bc4b6da926135b9ef1f0eac307ebf11db3..d84ff1fe7b8303021c576991e4d589de2da4e2bf 100644 |
| 169 | +--- a/src/main/java/net/minecraft/server/EntitySkeletonAbstract.java |
| 170 | ++++ b/src/main/java/net/minecraft/server/EntitySkeletonAbstract.java |
| 171 | +@@ -64,7 +64,7 @@ public abstract class EntitySkeletonAbstract extends EntityMonster implements IR |
| 172 | + public void n() { |
| 173 | + if (this.world.D()) { // Beast - Remove isClientSide check |
| 174 | + float f = this.aw(); |
| 175 | +- BlockPosition blockposition = this.bJ() instanceof EntityBoat ? (new BlockPosition(this.locX, (double) Math.round(this.locY), this.locZ)).up() : new BlockPosition(this.locX, (double) Math.round(this.locY), this.locZ); |
| 176 | ++ BlockPosition blockposition = this.bJ() instanceof EntityBoat ? (new BlockPosition(this.locX, (double) com.homomc.beast.math.FastMath.round(this.locY), this.locZ)).up() : new BlockPosition(this.locX, (double) com.homomc.beast.math.FastMath.round(this.locY), this.locZ); |
| 177 | + |
| 178 | + if (f > 0.5F && this.random.nextFloat() * 30.0F < (f - 0.4F) * 2.0F && this.world.h(blockposition)) { |
| 179 | + boolean flag = true; |
| 180 | +diff --git a/src/main/java/net/minecraft/server/WorldGenStronghold.java b/src/main/java/net/minecraft/server/WorldGenStronghold.java |
| 181 | +index a3b958e0109ea54e478d543324151e9972d86541..3d0317cf5df5be7829ac45bdb0f221768e2a6600 100644 |
| 182 | +--- a/src/main/java/net/minecraft/server/WorldGenStronghold.java |
| 183 | ++++ b/src/main/java/net/minecraft/server/WorldGenStronghold.java |
| 184 | +@@ -130,8 +130,8 @@ public class WorldGenStronghold extends StructureGenerator { |
| 185 | + if (l < this.d.length) { |
| 186 | + for (int i1 = 0; i1 < this.d.length; ++i1) { |
| 187 | + double d1 = 4.0D * this.h + this.h * (double) j * 6.0D + (random.nextDouble() - 0.5D) * this.h * 2.5D; |
| 188 | +- int j1 = (int) Math.round(Math.cos(d0) * d1); |
| 189 | +- int k1 = (int) Math.round(Math.sin(d0) * d1); |
| 190 | ++ int j1 = (int) com.homomc.beast.math.FastMath.round(Math.cos(d0) * d1); |
| 191 | ++ int k1 = (int) com.homomc.beast.math.FastMath.round(Math.sin(d0) * d1); |
| 192 | + BlockPosition blockposition = this.g.getWorldChunkManager().a((j1 << 4) + 8, (k1 << 4) + 8, 112, this.a, random); |
| 193 | + |
| 194 | + if (blockposition != null) { |
0 commit comments