From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Martijn Muijsers 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 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 d812949c7329ae2696b38dc792fa011ba87decb9..746e9e280eb47356475484eb1f658c0728cd65cf 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,24 @@ import net.minecraft.core.Direction; import net.minecraft.util.Mth; public final class CubeVoxelShape extends VoxelShape { + + private @org.jetbrains.annotations.NotNull DoubleList @org.jetbrains.annotations.Nullable [] list; // Gale - Lithium - cache CubeVoxelShape shape array + protected CubeVoxelShape(DiscreteVoxelShape voxels) { super(voxels); } @Override public 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