mirror of
https://github.com/BX-Team/DivineMC.git
synced 2025-12-19 14:59:25 +00:00
77 lines
3.7 KiB
Diff
77 lines
3.7 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 84a760fdc50bdafc9150f977e9c5d557a30ee220..8bfe5c8c559d5e68f5b95bea37f63363b343e9b1 100644
|
|
--- a/src/main/java/net/minecraft/core/Direction.java
|
|
+++ b/src/main/java/net/minecraft/core/Direction.java
|
|
@@ -39,7 +39,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 a544db042c8d2ecec8d323770552c4f10ca758a6..fc6a8b1cf33427320a60e3f2d9894ed2f0177bf7 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
|
|
|
|
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 b9af1d14c7815c99273bce8165cf384d669c1a75..16bf73856465c10e1ab84c17e7b317ef9081704d 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,8 @@ 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);
|
|
this.initCache(); // Paper - optimise collisions
|
|
@@ -12,7 +14,15 @@ public final class CubeVoxelShape extends VoxelShape {
|
|
|
|
@Override
|
|
protected 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
|