9
0
mirror of https://github.com/Dreeam-qwq/Gale.git synced 2025-12-19 23:09:30 +00:00
Files
Gale/patches/server/0090-Cache-CubeVoxelShape-shape-array.patch
2023-12-13 22:49:59 -05:00

50 lines
2.2 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martijn Muijsers <martijnmuijsers@live.nl>
Date: Wed, 30 Nov 2022 17:19:01 +0100
Subject: [PATCH] Cache CubeVoxelShape shape array
License: LGPL-3.0 (https://www.gnu.org/licenses/lgpl-3.0.html)
Gale - https://galemc.org
This patch is based on the following mixin:
"me/jellysquid/mods/lithium/mixin/shapes/precompute_shape_arrays/SimpleVoxelShapeMixin.java"
By: Angeline <jellysquid3@users.noreply.github.com>
As part of: Lithium (https://github.com/CaffeineMC/lithium-fabric)
Licensed under: LGPL-3.0 (https://www.gnu.org/licenses/lgpl-3.0.html)
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 110405e6e70d980d3e09f04d79562b32a7413071..80ac976e1fcf8b9e584a19aad03b204bea4875b4 100644
--- a/src/main/java/net/minecraft/world/phys/shapes/CubeVoxelShape.java
+++ b/src/main/java/net/minecraft/world/phys/shapes/CubeVoxelShape.java
@@ -3,8 +3,13 @@ package net.minecraft.world.phys.shapes;
import it.unimi.dsi.fastutil.doubles.DoubleList;
import net.minecraft.core.Direction;
import net.minecraft.util.Mth;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
public final class CubeVoxelShape extends VoxelShape {
+
+ private @NotNull DoubleList @Nullable [] list; // Gale - Lithium - cache CubeVoxelShape shape array
+
protected CubeVoxelShape(DiscreteVoxelShape voxels) {
super(voxels);
this.initCache(); // Paper - optimise collisions
@@ -12,7 +17,15 @@ public final class CubeVoxelShape extends VoxelShape {
@Override
protected DoubleList getCoords(Direction.Axis axis) {
- return new CubePointRange(this.shape.getSize(axis));
+ // Gale start - Lithium - cache CubeVoxelShape shape array
+ 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()];
+ // Gale end - Lithium - cache CubeVoxelShape shape array
}
@Override