mirror of
https://github.com/LeavesMC/Leaves.git
synced 2025-12-20 15:29:35 +00:00
56 lines
2.9 KiB
Diff
56 lines
2.9 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: violetc <58360096+s-yh-china@users.noreply.github.com>
|
|
Date: Sun, 14 Aug 2022 08:17:28 +0800
|
|
Subject: [PATCH] Optimize entity coordinate key
|
|
|
|
This patch is Powered by Pufferfish(https://github.com/pufferfish-gg/Pufferfish)
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/MCUtil.java b/src/main/java/net/minecraft/server/MCUtil.java
|
|
index 13082cd8de1a79a3b2fac6055bdaa163dbc7897b..cf70c8cb1ad5da3a8681760f69f4250c5627600d 100644
|
|
--- a/src/main/java/net/minecraft/server/MCUtil.java
|
|
+++ b/src/main/java/net/minecraft/server/MCUtil.java
|
|
@@ -208,7 +208,13 @@ public final class MCUtil {
|
|
}
|
|
|
|
public static long getCoordinateKey(final Entity entity) {
|
|
- return ((long)(MCUtil.fastFloor(entity.getZ()) >> 4) << 32) | ((MCUtil.fastFloor(entity.getX()) >> 4) & 0xFFFFFFFFL);
|
|
+ // Leaves start - eliminate double -> long cast in hotpath
|
|
+ if (top.leavesmc.leaves.LeavesConfig.optimizeEntityCoordinateKey) {
|
|
+ return ((long)(entity.blockPosition.getZ() >> 4) << 32) | ((entity.blockPosition.getX() >> 4) & 0xFFFFFFFFL);
|
|
+ } else {
|
|
+ return ((long)(MCUtil.fastFloor(entity.getZ()) >> 4) << 32) | ((MCUtil.fastFloor(entity.getX()) >> 4) & 0xFFFFFFFFL);
|
|
+ }
|
|
+ // Leaves end - eliminate double -> long cast in hotpath
|
|
}
|
|
|
|
public static long getCoordinateKey(final ChunkPos pair) {
|
|
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
index e0cc8171151f9db0d4b29980f097f81cacfe9718..a20930d2c09005a210e5242401cfb2e6c6082a01 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
@@ -291,7 +291,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
|
|
public double yo;
|
|
public double zo;
|
|
private Vec3 position;
|
|
- private BlockPos blockPosition;
|
|
+ public BlockPos blockPosition; // Leaves - private -> public
|
|
private ChunkPos chunkPosition;
|
|
private Vec3 deltaMovement;
|
|
private float yRot;
|
|
diff --git a/src/main/java/top/leavesmc/leaves/LeavesConfig.java b/src/main/java/top/leavesmc/leaves/LeavesConfig.java
|
|
index 3907bbfae224be1467bead2e13a7eace7e75e579..c234e6de433fa83055edc87c02e1d935cf3860df 100644
|
|
--- a/src/main/java/top/leavesmc/leaves/LeavesConfig.java
|
|
+++ b/src/main/java/top/leavesmc/leaves/LeavesConfig.java
|
|
@@ -256,6 +256,11 @@ public final class LeavesConfig {
|
|
fixPaper6045 = getBoolean("settings.performance.fix.fix-paper-6045", fixPaper6045);
|
|
}
|
|
|
|
+ public static boolean optimizeEntityCoordinateKey = true;
|
|
+ private static void optimizeEntityCoordinateKey() {
|
|
+ optimizeEntityCoordinateKey = getBoolean("settings.performance.optimize-entity-coordinate-key", optimizeEntityCoordinateKey);
|
|
+ }
|
|
+
|
|
public static final class WorldConfig {
|
|
|
|
public final String worldName;
|