mirror of
https://github.com/LeavesMC/Leaves.git
synced 2025-12-19 23:09:34 +00:00
--------- Co-authored-by: Lumine1909 <133463833+Lumine1909@users.noreply.github.com> Co-authored-by: LittleChest <81231195+LittleChest@users.noreply.github.com>
40 lines
2.1 KiB
Diff
40 lines
2.1 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/io/papermc/paper/util/MCUtil.java b/src/main/java/io/papermc/paper/util/MCUtil.java
|
|
index 02d6c98b7a2212b13ffd9859ebfdc0a8357ebe65..8add631c0614879d24455a96d94bc6711456f223 100644
|
|
--- a/src/main/java/io/papermc/paper/util/MCUtil.java
|
|
+++ b/src/main/java/io/papermc/paper/util/MCUtil.java
|
|
@@ -199,7 +199,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 (org.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 2dc27d27908a50101e5671809d1331db0cb2a96c..9e984f4bad722244d70d8b45755ca3abd0a22d4a 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
@@ -316,7 +316,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
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;
|