9
0
mirror of https://github.com/BX-Team/DivineMC.git synced 2025-12-19 14:59:25 +00:00
Files
DivineMC/patches/server/0036-lithium-precompute-shape-arrays.patch
Artem Ostrasev 774a111315 [ci-skip] New patches and optimisations (#11)
I'll make some changes now, so skipping build

Changelog:

* add CarpetFixes optimizations

* fix optimizations config

* lithium optimizations

* add Carpet Fixes Sheep Optimization

* add Async Pathfinding; add C2ME opts math

* add 2 vmp patches

* New performance patches; update README and wiki README

* update configuration on wiki

* update wiki main page

* Updated Upstream (Purpur)

* fix conflicts

* make "Don't save Fireworks" patch configurable

* Disable memory reserve allocating

* Fix MC-172801

* resolve conflicts

* add bstats to readme

* dd custom list of forks

* update logo link
2024-02-11 15:04:54 +03:00

77 lines
3.7 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Sat, 13 Jan 2024 20:29:38 +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 b805e57d5a67d77d226cd8154e970050e2e8ef4a..c72ea0514baadc8d5fde93ff573d91a9fe7cc04c 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
private static final Direction[] BY_3D_DATA = Arrays.stream(VALUES).sorted(Comparator.comparingInt((direction) -> {
return direction.data3d;
})).toArray((i) -> {
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 110405e6e70d980d3e09f04d79562b32a7413071..ef6027b0d664d0dfdff80ed023c9f4790d4f0f5a 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