9
0
mirror of https://github.com/LeavesMC/Leaves.git synced 2025-12-23 08:59:31 +00:00

Cache CubeVoxelShape shape array

This commit is contained in:
violetc
2023-07-18 14:43:54 +08:00
parent 183b6a618e
commit c29856f53a
2 changed files with 48 additions and 2 deletions

View File

@@ -128,10 +128,10 @@ index 35d2da9d91dcdd89de7c0f4af028fd182376ea8d..d73482fb1e71fe2951e96ae0593de268
.withRequiredArg() .withRequiredArg()
diff --git a/src/main/java/top/leavesmc/leaves/LeavesConfig.java b/src/main/java/top/leavesmc/leaves/LeavesConfig.java diff --git a/src/main/java/top/leavesmc/leaves/LeavesConfig.java b/src/main/java/top/leavesmc/leaves/LeavesConfig.java
new file mode 100644 new file mode 100644
index 0000000000000000000000000000000000000000..1f11a6fbd0dda3e6734f421a3a06276a072c1f43 index 0000000000000000000000000000000000000000..98b93ea28c1f89d237bcc0494117c34025889f65
--- /dev/null --- /dev/null
+++ b/src/main/java/top/leavesmc/leaves/LeavesConfig.java +++ b/src/main/java/top/leavesmc/leaves/LeavesConfig.java
@@ -0,0 +1,861 @@ @@ -0,0 +1,866 @@
+package top.leavesmc.leaves; +package top.leavesmc.leaves;
+ +
+import com.destroystokyo.paper.util.SneakyThrow; +import com.destroystokyo.paper.util.SneakyThrow;
@@ -818,6 +818,11 @@ index 0000000000000000000000000000000000000000..1f11a6fbd0dda3e6734f421a3a06276a
+ skipSecondaryPOISensorIfAbsent = getBoolean("settings.performance.skip-secondary-POI-sensor-if-absent", skipSecondaryPOISensorIfAbsent); + skipSecondaryPOISensorIfAbsent = getBoolean("settings.performance.skip-secondary-POI-sensor-if-absent", skipSecondaryPOISensorIfAbsent);
+ } + }
+ +
+ public static boolean cacheCubeVoxelShapeShapeArray = true;
+ private static void cacheCubeVoxelShapeShapeArray() {
+ cacheCubeVoxelShapeShapeArray = getBoolean("settings.performance.cache-CubeVoxelShape-shape-array", cacheCubeVoxelShapeShapeArray);
+ }
+
+ public static final class WorldConfig { + public static final class WorldConfig {
+ +
+ public final String worldName; + public final String worldName;

View File

@@ -0,0 +1,41 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: violetc <58360096+s-yh-china@users.noreply.github.com>
Date: Tue, 18 Jul 2023 14:43:18 +0800
Subject: [PATCH] Cache CubeVoxelShape shape array
This patch is Powered by Gale(https://github.com/GaleMC/Gale)
diff --git a/src/main/java/net/minecraft/world/phys/shapes/CubeVoxelShape.java b/src/main/java/net/minecraft/world/phys/shapes/CubeVoxelShape.java
index 68e89dbd79171627046e89699057964e44c40e7d..3d260c355e374402e10baaa4f1a1d24f9c391ff5 100644
--- a/src/main/java/net/minecraft/world/phys/shapes/CubeVoxelShape.java
+++ b/src/main/java/net/minecraft/world/phys/shapes/CubeVoxelShape.java
@@ -5,13 +5,28 @@ import net.minecraft.core.Direction;
import net.minecraft.util.Mth;
public final class CubeVoxelShape extends VoxelShape {
+
+ private DoubleList[] list = null; // Leaves - cache CubeVoxelShape shape array
+
protected CubeVoxelShape(DiscreteVoxelShape voxels) {
super(voxels);
}
@Override
protected DoubleList getCoords(Direction.Axis axis) {
- return new CubePointRange(this.shape.getSize(axis));
+ // Leaves start - cache CubeVoxelShape shape array
+ if (!top.leavesmc.leaves.LeavesConfig.cacheCubeVoxelShapeShapeArray) {
+ return new CubePointRange(this.shape.getSize(axis));
+ } else {
+ if (this.list == null) {
+ this.list = new DoubleList[Direction.Axis.VALUES.length];
+ for (Direction.Axis existingAxis : Direction.Axis.VALUES) {
+ this.list[existingAxis.ordinal()] = new CubePointRange(this.shape.getSize(axis));
+ }
+ }
+ return this.list[axis.ordinal()];
+ }
+ // Leaves end - cache CubeVoxelShape shape array
}
@Override