mirror of
https://github.com/BX-Team/DivineMC.git
synced 2025-12-19 14:59:25 +00:00
76 lines
3.6 KiB
Diff
76 lines
3.6 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
|
|
Date: Wed, 17 Apr 2024 02:08:02 +0300
|
|
Subject: [PATCH] lithium: precompute shape arrays
|
|
|
|
Original code by CaffeineMC, licensed under LGPL v3
|
|
You can find the original code on https://github.com/CaffeineMC/lithium-fabric (Yarn mappings)
|
|
|
|
diff --git a/src/main/java/net/minecraft/core/Direction.java b/src/main/java/net/minecraft/core/Direction.java
|
|
index 03c45ee77276462818a6f774b5945b25924aa3f0..7c56228639027d0bfcf8901a5f3c996c6b1faa8c 100644
|
|
--- a/src/main/java/net/minecraft/core/Direction.java
|
|
+++ b/src/main/java/net/minecraft/core/Direction.java
|
|
@@ -46,7 +46,7 @@ public enum Direction implements StringRepresentable {
|
|
private final Direction.Axis axis;
|
|
private final Direction.AxisDirection axisDirection;
|
|
private final Vec3i normal;
|
|
- private static final Direction[] VALUES = values();
|
|
+ public static final Direction[] VALUES = values(); // DivineMC - lithium: precompute shape arrays
|
|
private static final Direction[] BY_3D_DATA = Arrays.stream(VALUES)
|
|
.sorted(Comparator.comparingInt(direction -> direction.data3d))
|
|
.toArray(Direction[]::new);
|
|
diff --git a/src/main/java/net/minecraft/world/phys/shapes/CubePointRange.java b/src/main/java/net/minecraft/world/phys/shapes/CubePointRange.java
|
|
index ad02cdb00360165f6405eb3044bd8320f01a7ef1..61f6f612470076c7b6930dcb63911a2ac6d45be1 100644
|
|
--- a/src/main/java/net/minecraft/world/phys/shapes/CubePointRange.java
|
|
+++ b/src/main/java/net/minecraft/world/phys/shapes/CubePointRange.java
|
|
@@ -4,6 +4,7 @@ import it.unimi.dsi.fastutil.doubles.AbstractDoubleList;
|
|
|
|
public class CubePointRange extends AbstractDoubleList {
|
|
private final int parts;
|
|
+ private double scale; // DivineMC - lithium: precompute shape arrays
|
|
|
|
public CubePointRange(int sectionCount) {
|
|
if (sectionCount <= 0) {
|
|
@@ -11,10 +12,11 @@ public class CubePointRange extends AbstractDoubleList {
|
|
} else {
|
|
this.parts = sectionCount;
|
|
}
|
|
+ this.scale = 1.0D / sectionCount; // DivineMC - lithium: precompute shape arrays
|
|
}
|
|
|
|
public double getDouble(int i) {
|
|
- return (double)i / (double)this.parts;
|
|
+ return i * this.scale; // DivineMC - lithium: precompute shape arrays
|
|
}
|
|
|
|
public int size() {
|
|
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..98e218c65d489822f334c06fddd1ab608662597b 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,23 @@ import net.minecraft.core.Direction;
|
|
import net.minecraft.util.Mth;
|
|
|
|
public final class CubeVoxelShape extends VoxelShape {
|
|
+ private DoubleList[] list; // DivineMC - lithium: precompute shape arrays
|
|
+
|
|
protected CubeVoxelShape(DiscreteVoxelShape voxels) {
|
|
super(voxels);
|
|
}
|
|
|
|
@Override
|
|
public DoubleList getCoords(Direction.Axis axis) {
|
|
- return new CubePointRange(this.shape.getSize(axis));
|
|
+ // DivineMC start - lithium: precompute shape arrays
|
|
+ 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()];
|
|
+ // DivineMC end
|
|
}
|
|
|
|
@Override
|