mirror of
https://github.com/BX-Team/DivineMC.git
synced 2026-01-06 15:41:52 +00:00
add config (useless now)
This commit is contained in:
112
patches/server/0008-lithium-shapes.blockstate_cache.patch
Normal file
112
patches/server/0008-lithium-shapes.blockstate_cache.patch
Normal file
@@ -0,0 +1,112 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Gegy <gegy1000@gmail.com>
|
||||
Date: Fri, 21 Jan 2022 10:19:06 -0500
|
||||
Subject: [PATCH] lithium: shapes.blockstate_cache
|
||||
|
||||
Original code by CaffeineMC, licensed under GNU Lesser General Public License v3.0
|
||||
You can find the original code on https://github.com/CaffeineMC/lithium-fabric (Yarn mappings)
|
||||
|
||||
diff --git a/src/main/java/me/jellysquid/mods/lithium/common/util/collections/Object2BooleanCacheTable.java b/src/main/java/me/jellysquid/mods/lithium/common/util/collections/Object2BooleanCacheTable.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..a833ec84b2053c805dd33821cc08939c1cb79e96
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/me/jellysquid/mods/lithium/common/util/collections/Object2BooleanCacheTable.java
|
||||
@@ -0,0 +1,59 @@
|
||||
+package me.jellysquid.mods.lithium.common.util.collections;
|
||||
+
|
||||
+import it.unimi.dsi.fastutil.HashCommon;
|
||||
+import java.util.function.Predicate;
|
||||
+import net.minecraft.util.Mth;
|
||||
+
|
||||
+/**
|
||||
+ * A lossy hashtable implementation that stores a mapping between an object and a boolean.
|
||||
+ * <p>
|
||||
+ * Any hash collisions will result in an overwrite: this is safe because the correct value can always be recomputed,
|
||||
+ * given that the given operator is deterministic.
|
||||
+ * <p>
|
||||
+ * This implementation is safe to use from multiple threads
|
||||
+ */
|
||||
+public final class Object2BooleanCacheTable<T> {
|
||||
+ private final int mask;
|
||||
+
|
||||
+ private final Node<T>[] nodes;
|
||||
+
|
||||
+ private final Predicate<T> operator;
|
||||
+
|
||||
+ @SuppressWarnings("unchecked")
|
||||
+ public Object2BooleanCacheTable(int capacity, Predicate<T> operator) {
|
||||
+ int capacity1 = Mth.smallestEncompassingPowerOfTwo(capacity);
|
||||
+ this.mask = capacity1 - 1;
|
||||
+
|
||||
+ this.nodes = (Node<T>[]) new Node[capacity1];
|
||||
+
|
||||
+ this.operator = operator;
|
||||
+ }
|
||||
+
|
||||
+ private static <T> int hash(T key) {
|
||||
+ return HashCommon.mix(key.hashCode());
|
||||
+ }
|
||||
+
|
||||
+ public boolean get(T key) {
|
||||
+ int idx = hash(key) & this.mask;
|
||||
+
|
||||
+ Node<T> node = this.nodes[idx];
|
||||
+ if (node != null && key.equals(node.key)) {
|
||||
+ return node.value;
|
||||
+ }
|
||||
+
|
||||
+ boolean test = this.operator.test(key);
|
||||
+ this.nodes[idx] = new Node<>(key, test);
|
||||
+
|
||||
+ return test;
|
||||
+ }
|
||||
+
|
||||
+ static class Node<T> {
|
||||
+ final T key;
|
||||
+ final boolean value;
|
||||
+
|
||||
+ Node(T key, boolean value) {
|
||||
+ this.key = key;
|
||||
+ this.value = value;
|
||||
+ }
|
||||
+ }
|
||||
+}
|
||||
\ No newline at end of file
|
||||
diff --git a/src/main/java/net/minecraft/world/level/block/Block.java b/src/main/java/net/minecraft/world/level/block/Block.java
|
||||
index 7b71073027f4cf79736546500ededdfbb83d968e..40f0e57bed6866bff69231b9135987ca53125ba3 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/block/Block.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/block/Block.java
|
||||
@@ -62,17 +62,19 @@ import net.minecraft.world.phys.shapes.BooleanOp;
|
||||
import net.minecraft.world.phys.shapes.Shapes;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import org.slf4j.Logger;
|
||||
+import me.jellysquid.mods.lithium.common.util.collections.Object2BooleanCacheTable; // JettPack
|
||||
|
||||
public class Block extends BlockBehaviour implements ItemLike {
|
||||
|
||||
private static final Logger LOGGER = LogUtils.getLogger();
|
||||
private final Holder.Reference<Block> builtInRegistryHolder;
|
||||
public static final IdMapper<BlockState> BLOCK_STATE_REGISTRY = new IdMapper<>();
|
||||
- private static final LoadingCache<VoxelShape, Boolean> SHAPE_FULL_BLOCK_CACHE = CacheBuilder.newBuilder().maximumSize(512L).weakKeys().build(new CacheLoader<VoxelShape, Boolean>() {
|
||||
- public Boolean load(VoxelShape voxelshape) {
|
||||
- return !Shapes.joinIsNotEmpty(Shapes.block(), voxelshape, BooleanOp.NOT_SAME);
|
||||
- }
|
||||
- });
|
||||
+ // JettPack start - lithium: shapes.blockstate_cache
|
||||
+ private static final Object2BooleanCacheTable<VoxelShape> FULL_CUBE_CACHE = new Object2BooleanCacheTable<>(
|
||||
+ 512,
|
||||
+ shape -> !Shapes.joinIsNotEmpty(Shapes.block(), shape, BooleanOp.NOT_SAME)
|
||||
+ );
|
||||
+ // JettPack end
|
||||
public static final int UPDATE_NEIGHBORS = 1;
|
||||
public static final int UPDATE_CLIENTS = 2;
|
||||
public static final int UPDATE_INVISIBLE = 4;
|
||||
@@ -279,7 +281,7 @@ public class Block extends BlockBehaviour implements ItemLike {
|
||||
}
|
||||
|
||||
public static boolean isShapeFullBlock(VoxelShape shape) {
|
||||
- return (Boolean) Block.SHAPE_FULL_BLOCK_CACHE.getUnchecked(shape);
|
||||
+ return FULL_CUBE_CACHE.get(shape); // JettPack - lithium: shapes.blockstate_cache
|
||||
}
|
||||
|
||||
public boolean propagatesSkylightDown(BlockState state, BlockGetter world, BlockPos pos) {
|
||||
Reference in New Issue
Block a user