9
0
mirror of https://github.com/LeavesMC/Leaves.git synced 2025-12-20 15:29:35 +00:00
Files
LeavesMC/patches/server/0084-Cache-CubeVoxelShape-shape-array.patch
violetc f40d340092 1.20.6 (#216)
---------

Co-authored-by: MC_XiaoHei <xiaohei.xor7studio@foxmail.com>
Co-authored-by: Bluemangoo <chenfy2006@qq.com>
2024-05-20 23:03:56 +08:00

43 lines
1.9 KiB
Diff

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 b9af1d14c7815c99273bce8165cf384d669c1a75..832f9d8ee74823fb50b243033ce3de0e27ab4837 100644
--- a/src/main/java/net/minecraft/world/phys/shapes/CubeVoxelShape.java
+++ b/src/main/java/net/minecraft/world/phys/shapes/CubeVoxelShape.java
@@ -5,6 +5,9 @@ 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);
this.initCache(); // Paper - optimise collisions
@@ -12,7 +15,19 @@ public final class CubeVoxelShape extends VoxelShape {
@Override
protected DoubleList getCoords(Direction.Axis axis) {
- return new CubePointRange(this.shape.getSize(axis));
+ // Leaves start - cache CubeVoxelShape shape array
+ if (!org.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