Yatopia/patches/server/0064-lithium-shape.patch
Simon Gardling 6bf2b9226a
Upstream (#505)
* Updated Upstream and Sidestream(s) (Paper/Tuinity/Airplane/Purpur/Empirecraft/Origami)

Upstream/An Sidestream has released updates that appears to apply and compile correctly
This update has NOT been tested by YatopiaMC and as with ANY update, please do your own testing.

Paper Changes:
b94a99b03 Updated Upstream (CraftBukkit) (#5762)
f5cb169e0 [Auto] Updated Upstream (CraftBukkit)
407ad043c Add ElderGuardianAppearanceEvent (#5394)
a04ad7bfb Fix invulnerable end crystals: MC-108513 (#5734)
c894e8bbb Fix issue with soft despawn distance (#5755)
302e5101a Add BellRevealRaiderEvent (#5729)
34e6b2dc3 editMeta: tighten contract via docs (#5714)
db2d501ba Do not print spawn loaded chunks
86ffde038 Add getHandRaised to LivingEntity (#5752)
9072c349a Fix broadcast event and add Adventure broadcast (#5477)

Tuinity Changes:
f7c4249 Fix dangerous end portal logic
3eda860 Updated Upstream (Paper)

Airplane Changes:
3e07ea8 Patch container checks for WildChests compat
d04adc9 Updated Upstream (Tuinity)
489bb76 Update gradle
0d5670e Merge pull request #24 from HexedHero/spelling-mistake-lightning
c605be6 Fix typo

Purpur Changes:
d2204a3d Updated Upstream (Paper, Tuinity & Airplane)
2b35782c Fix #364 - isCritical always false
6ab78311 Fix empty shulker boxes disappearing when broken
afaf8b4f Updated Upstream (Paper)
b97feb78 [ci-skip] readme
eb77666a Updated Upstream (Paper)

Empirecraft Changes:
105217a9 Move more files out of nms package
548a13f4 Move some server patches out nms package
f24d7b4c Updated Paper
99745711 Updated Paper
deb9886e Add a fix for piglins picking up too much - SPIGOT-6482
8c662d78 Add javadoc description to reload api
1af9bbc8 Adjust comments on vehicle event patch
2aa479b8 cleanup ItemStack isSimilar api patches
f344cb62 Updated Paper
dbb49189 Re-add EMC User API
a6c40eb2 Updated Paper
a57940b2 Remove EMC specific User API patches

Origami Changes:
d0cdf96 Fix issues with disabling the chunk loading of the feature search
529f5b6 Fix creature type despawn distances not applying
1af8601 Fix Endermen being able to load chunks on teleport

* Updated Upstream and Sidestream(s) (Airplane/Purpur)

Upstream/An Sidestream has released updates that appears to apply and compile correctly
This update has NOT been tested by YatopiaMC and as with ANY update, please do your own testing.

Airplane Changes:
8c50125 Switch bitset to long storage
617dfe2 Patch Paper to use fast item merge raytracing
16104e8 Updated Upstream (Tuinity)

Purpur Changes:
5824eb8f Beacon Activation Range Configurable (#372)
baa20a6b Config MobEffect by world (#369)
ff09f9e6 Updated Upstream (Tuinity & Airplane)

* Updated Upstream and Sidestream(s) (Paper/Purpur/Empirecraft)

Upstream/An Sidestream has released updates that appears to apply and compile correctly
This update has NOT been tested by YatopiaMC and as with ANY update, please do your own testing.

Paper Changes:
f89be1281 [CI-SKIP] Fixup patch header
acbb69e67 Restore vanilla water animal limit
ea381dde3 Reset villager inventory on cancelled pickup event (again) (#5766) (Fixes #5765)

Purpur Changes:
6fe21994 Updated Upstream (Paper)

Empirecraft Changes:
0e568e7c Updated Paper
bbd2a014 Fire FurnaceExtractEvent more often for null players

* Updated Upstream and Sidestream(s) (Paper)

Upstream/An Sidestream has released updates that appears to apply and compile correctly
This update has NOT been tested by YatopiaMC and as with ANY update, please do your own testing.

Paper Changes:
5d05da257 Use original user input instead of legacy event result for AbstractChatEvent#originalMessage (#5770)

* remove Purpur

* Updated Upstream and Sidestream(s) (Paper)

Upstream/An Sidestream has released updates that appears to apply and compile correctly
This update has NOT been tested by YatopiaMC and as with ANY update, please do your own testing.

Paper Changes:
af1a50993 [Auto] Updated Upstream (CraftBukkit)

* Updated Upstream and Sidestream(s) (Paper/Tuinity/Airplane/Empirecraft/Origami)

Upstream/An Sidestream has released updates that appears to apply and compile correctly
This update has NOT been tested by YatopiaMC and as with ANY update, please do your own testing.

Paper Changes:
0daded2f2 Add more line of sight methods (#5749)
8fd4e70db Improve seed based feature search to not load chunk (#5760)
7ad8498c3 Make item validations configurable (#5775)
3673d6758 Fix Cannot be adventure component serialized when the legacy component is null (#5754)
afb0748a2 [Auto] Updated Upstream (Bukkit)
7d751ad8d Fix dangerous end portal logic (#5776)
12716324d Do not tick Chunk TickS for every chunk

Tuinity Changes:
2683c77 Use area map for nearby players in mob spawning (#283)

Airplane Changes:
2be99de Toggle for DEAR
3485304 Updated Upstream (Tuinity)

Empirecraft Changes:
33438474 Refine FurnaceExtractEvent patch

Origami Changes:
35c6a27 Re-add removed patch for MC-2025
a19a185 Fix missing particles

* Updated Upstream and Sidestream(s) (Paper/Tuinity/Airplane/Empirecraft)

Upstream/An Sidestream has released updates that appears to apply and compile correctly
This update has NOT been tested by YatopiaMC and as with ANY update, please do your own testing.

Paper Changes:
c64958508 fix: wrong return in javadocs for bookmeta (#5579)
3dbb8926e Fix PotionSplashEvent for water splash potions (#5697)
b759d006e Adds per-world spawn limits (#4837)
81de619d3 Updated Upstream (CraftBukkit) (#5786)
5e3604f1b Better fix for invulnerable crystals and improve Origin API (#5761)
d5fe9c817 Updated Upstream (CraftBukkit) (#5784)
d20e5b195 Fix timings sometimes incorrectly marking commands (#5783)

Tuinity Changes:
df76b3c Updated Upstream (Paper)

Airplane Changes:
a13c511 Simple item block collision toggle
3cd9d1c Updated Upstream (Tuinity)

Empirecraft Changes:
c7ef1a7a Updated Paper

* Updated Upstream and Sidestream(s) (Tuinity/Airplane/Origami)

Upstream/An Sidestream has released updates that appears to apply and compile correctly
This update has NOT been tested by YatopiaMC and as with ANY update, please do your own testing.

Tuinity Changes:
f32fe9a Updated Upstream (Paper)

Airplane Changes:
125aff7 Updated Upstream (Tuinity)

Origami Changes:
756162f Update Paper
2f9721c Update snakeyaml and enable comment loading/saving

* fix

* fix

* Updated Upstream and Sidestream(s) (Tuinity)

Upstream/An Sidestream has released updates that appears to apply and compile correctly
This update has NOT been tested by YatopiaMC and as with ANY update, please do your own testing.

Tuinity Changes:
901ac35 Optimise BlockSoil nearby water lookup

* Updated Upstream and Sidestream(s) (Paper/Empirecraft)

Upstream/An Sidestream has released updates that appears to apply and compile correctly
This update has NOT been tested by YatopiaMC and as with ANY update, please do your own testing.

Paper Changes:
e04368045 Updated Upstream (Bukkit/CraftBukkit) (#5794)

Empirecraft Changes:
e187791e Updated Paper
2021-06-14 14:31:04 -04:00

359 lines
14 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: JellySquid <jellysquid+atwork@protonmail.com>
Date: Wed, 27 Jan 2021 21:05:05 +0100
Subject: [PATCH] lithium shape
Co-authored-by: Hugo Planque <hookwood01@gmail.com>
diff --git a/src/main/java/me/jellysquid/mods/lithium/common/block/LithiumEntityShapeContext.java b/src/main/java/me/jellysquid/mods/lithium/common/block/LithiumEntityShapeContext.java
new file mode 100644
index 0000000000000000000000000000000000000000..85d55d144a38a16d0f148a29cd11985d7febe880
--- /dev/null
+++ b/src/main/java/me/jellysquid/mods/lithium/common/block/LithiumEntityShapeContext.java
@@ -0,0 +1,55 @@
+package me.jellysquid.mods.lithium.common.block;
+
+import net.minecraft.core.BlockPosition;
+import net.minecraft.world.entity.Entity;
+import net.minecraft.world.entity.EntityLiving;
+import net.minecraft.core.EnumDirection;
+import net.minecraft.world.level.material.Fluid;
+import net.minecraft.world.level.material.FluidTypeFlowing;
+import net.minecraft.world.item.Item;
+import net.minecraft.world.item.Items;
+import net.minecraft.world.phys.shapes.VoxelShape;
+import net.minecraft.world.phys.shapes.VoxelShapeCollision;
+
+/**
+ * A replacement for EntityShapeContext that does not calculate the heldItem on construction. As most instances never
+ * use this field, a lazy evaluation is faster on average. The initialization of the heldItem field takes about 1% of
+ * the server thread CPU time in a fresh world with lots of animals (singleplayer 1.16.5, renderdistance 24).
+ *
+ * @author 2No2Name
+ */
+public class LithiumEntityShapeContext implements VoxelShapeCollision {
+ private final Entity entity;
+ private final boolean descending;
+ private final double minY;
+ private Item heldItem;
+
+ public LithiumEntityShapeContext(Entity entity) {
+ this.entity = entity;
+ this.descending = entity.isDescending();
+ this.minY = entity.locY();
+ }
+
+ @Override
+ public boolean a(Item item) {
+ if (this.heldItem == null) {
+ this.heldItem = entity instanceof EntityLiving ? ((EntityLiving)entity).getItemInMainHand().getItem() : Items.AIR;
+ }
+ return this.heldItem == item;
+ }
+
+ @Override
+ public boolean a(Fluid aboveState, FluidTypeFlowing fluid) {
+ return this.entity instanceof EntityLiving && ((EntityLiving) this.entity).a(fluid) && !aboveState.getType().a(fluid);
+ }
+
+ @Override
+ public boolean b() {
+ return this.descending;
+ }
+
+ @Override
+ public boolean a(VoxelShape shape, BlockPosition pos, boolean defaultValue) {
+ return this.minY > (double)pos.getY() + shape.getMax(EnumDirection.EnumAxis.Y) - 9.999999747378752E-6D;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/me/jellysquid/mods/lithium/common/shapes/pairs/LithiumDoublePairList.java b/src/main/java/me/jellysquid/mods/lithium/common/shapes/pairs/LithiumDoublePairList.java
new file mode 100644
index 0000000000000000000000000000000000000000..bfa06e714050260779fc8727b4b2cabb6f811398
--- /dev/null
+++ b/src/main/java/me/jellysquid/mods/lithium/common/shapes/pairs/LithiumDoublePairList.java
@@ -0,0 +1,117 @@
+package me.jellysquid.mods.lithium.common.shapes.pairs;
+
+import it.unimi.dsi.fastutil.doubles.DoubleArrayList;
+import it.unimi.dsi.fastutil.doubles.DoubleList;
+import net.minecraft.world.phys.shapes.VoxelShapeMerger;
+
+/**
+ * Optimized variant of {@link net.minecraft.util.shape.SimplePairList}. This implementation works directly against
+ * flat arrays and tries to organize code in a manner that hits the JIT's happy path. In my testing, this is about
+ * ~50% faster than the vanilla implementation.
+ */
+public final class LithiumDoublePairList implements VoxelShapeMerger {
+ private final double[] merged;
+ private final int[] indicesFirst;
+ private final int[] indicesSecond;
+
+ private final DoubleArrayList pairs;
+
+ public LithiumDoublePairList(DoubleList aPoints, DoubleList bPoints, boolean flag1, boolean flag2) {
+ int size = aPoints.size() + bPoints.size();
+
+ this.merged = new double[size];
+ this.indicesFirst = new int[size];
+ this.indicesSecond = new int[size];
+
+ this.pairs = DoubleArrayList.wrap(this.merged);
+
+ this.merge(getArray(aPoints), getArray(bPoints), aPoints.size(), bPoints.size(), flag1, flag2);
+ }
+
+ private void merge(double[] aPoints, double[] bPoints, int aSize, int bSize, boolean flag1, boolean flag2) {
+ int aIdx = 0;
+ int bIdx = 0;
+
+ double prev = 0.0D;
+
+ int a1 = 0, a2 = 0;
+
+ while (true) {
+ boolean aWithinBounds = aIdx < aSize;
+ boolean bWithinBounds = bIdx < bSize;
+
+ if (!aWithinBounds && !bWithinBounds) {
+ break;
+ }
+
+ boolean flip = aWithinBounds && (!bWithinBounds || aPoints[aIdx] < bPoints[bIdx] + 1.0E-7D);
+
+ double value;
+
+ if (flip) {
+ value = aPoints[aIdx++];
+ } else {
+ value = bPoints[bIdx++];
+ }
+
+ if ((aIdx == 0 || !aWithinBounds) && !flip && !flag2) {
+ continue;
+ }
+
+ if ((bIdx == 0 || !bWithinBounds) && flip && !flag1) {
+ continue;
+ }
+
+ if (a2 == 0 || prev < value - 1.0E-7D) {
+ this.indicesFirst[a1] = aIdx - 1;
+ this.indicesSecond[a1] = bIdx - 1;
+ this.merged[a2] = value;
+
+ a1++;
+ a2++;
+ prev = value;
+ } else if (a2 > 0) {
+ this.indicesFirst[a1 - 1] = aIdx - 1;
+ this.indicesSecond[a1 - 1] = bIdx - 1;
+ }
+ }
+
+ if (a2 == 0) {
+ this.merged[a2++] = Math.min(aPoints[aSize - 1], bPoints[bSize - 1]);
+ }
+
+ this.pairs.size(a2);
+ }
+
+ @Override
+ public boolean a(VoxelShapeMerger.a predicate) {
+ int l = this.pairs.size() - 1;
+
+ for (int i = 0; i < l; i++) {
+ if (!predicate.merge(this.indicesFirst[i], this.indicesSecond[i], i)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ @Override
+ public DoubleList a() {
+ return this.pairs;
+ }
+
+ private static double[] getArray(DoubleList list) {
+ if (list instanceof DoubleArrayList) {
+ return ((DoubleArrayList) list).elements();
+ }
+
+ double[] points = new double[list.size()];
+
+ for (int i = 0; i < points.length; i++) {
+ points[i] = list.getDouble(i);
+ }
+
+ return points;
+ }
+}
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..e210e0fa39b74805429832c3d232fadb33975414
--- /dev/null
+++ b/src/main/java/me/jellysquid/mods/lithium/common/util/collections/Object2BooleanCacheTable.java
@@ -0,0 +1,61 @@
+package me.jellysquid.mods.lithium.common.util.collections;
+
+import it.unimi.dsi.fastutil.HashCommon;
+import net.minecraft.util.MathHelper;
+
+import java.util.function.Predicate;
+
+/**
+ * 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 capacity;
+ private final int mask;
+
+ private final Node<T>[] nodes;
+
+ private final Predicate<T> operator;
+
+ @SuppressWarnings("unchecked")
+ public Object2BooleanCacheTable(int capacity, Predicate<T> operator) {
+ this.capacity = MathHelper.smallestEncompassingPowerOfTwo(capacity);
+ this.mask = this.capacity - 1;
+
+ this.nodes = (Node<T>[]) new Node[this.capacity];
+
+ 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;
+ }
+ }
+}
diff --git a/src/main/java/net/minecraft/util/MathHelper.java b/src/main/java/net/minecraft/util/MathHelper.java
index b95115aca72ba0cf6451096ddbd8b50a8f3bb5c6..0afb8c643cb3e5938e12183c6132797d6ed645bb 100644
--- a/src/main/java/net/minecraft/util/MathHelper.java
+++ b/src/main/java/net/minecraft/util/MathHelper.java
@@ -198,6 +198,7 @@ public class MathHelper {
return c(f, f + f3, f2);
}
+ public static int smallestEncompassingPowerOfTwo(int i){ return c(i); } // Yatopia - OBFHELPER
public static int c(int i) {
int j = i - 1;
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index c4d3f716dda0e33b444de6caa6f336d8d33daf5b..d212e9c4ffe44b6fdcb78d0cf2a7547bc98f57a3 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -2687,6 +2687,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, ne
return this.isSneaking();
}
+ public boolean isDescending() { return by(); } // Yatopia - OBFHELPER
public boolean by() {
return this.isSneaking();
}
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 96d7990c66bd569b1b5ee287c0238c7dbb4c503e..505d760b7c2e9aea29d76d0f3b3f1d1d14a3e961 100644
--- a/src/main/java/net/minecraft/world/level/block/Block.java
+++ b/src/main/java/net/minecraft/world/level/block/Block.java
@@ -49,6 +49,7 @@ import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.phys.shapes.VoxelShapes;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+import me.jellysquid.mods.lithium.common.util.collections.Object2BooleanCacheTable;
public class Block extends BlockBase implements IMaterial {
@@ -209,8 +210,14 @@ public class Block extends BlockBase implements IMaterial {
return a(voxelshape1);
}
+ // Yatopia start - Port lithium
+ private static final Object2BooleanCacheTable<VoxelShape> FULL_CUBE_CACHE = new Object2BooleanCacheTable<>(
+ 512,
+ shape -> !VoxelShapes.applyOperation(VoxelShapes.fullCube(), shape, OperatorBoolean.NOT_SAME)
+ );
+
public static boolean a(VoxelShape voxelshape) {
- return (Boolean) Block.a.getUnchecked(voxelshape);
+ return FULL_CUBE_CACHE.get(voxelshape); // Yatopia end
}
public boolean b(IBlockData iblockdata, IBlockAccess iblockaccess, BlockPosition blockposition) {
diff --git a/src/main/java/net/minecraft/world/phys/shapes/VoxelShape.java b/src/main/java/net/minecraft/world/phys/shapes/VoxelShape.java
index fbc5fab9946b6f9233f3014f0e69f2576b2138d7..012892063405616c8ae35b6e06020008dfd147df 100644
--- a/src/main/java/net/minecraft/world/phys/shapes/VoxelShape.java
+++ b/src/main/java/net/minecraft/world/phys/shapes/VoxelShape.java
@@ -71,6 +71,7 @@ public abstract class VoxelShape {
return i >= this.a.c(enumdirection_enumaxis) ? Double.POSITIVE_INFINITY : this.a(enumdirection_enumaxis, i);
}
+ public double getMax(EnumDirection.EnumAxis enumdirection_enumaxis) { return c(enumdirection_enumaxis); } // Yatopia - OBFHELPER
public double c(EnumDirection.EnumAxis enumdirection_enumaxis) {
int i = this.a.b(enumdirection_enumaxis);
diff --git a/src/main/java/net/minecraft/world/phys/shapes/VoxelShapeMerger.java b/src/main/java/net/minecraft/world/phys/shapes/VoxelShapeMerger.java
index d2a46ce0c5c980d34dc2f4b716a174a81a68f1d0..0c594866cb291abb2e90b149d52445a628331879 100644
--- a/src/main/java/net/minecraft/world/phys/shapes/VoxelShapeMerger.java
+++ b/src/main/java/net/minecraft/world/phys/shapes/VoxelShapeMerger.java
@@ -2,7 +2,7 @@ package net.minecraft.world.phys.shapes;
import it.unimi.dsi.fastutil.doubles.DoubleList;
-interface VoxelShapeMerger {
+public interface VoxelShapeMerger { // Yatopia - make Public
DoubleList a();
diff --git a/src/main/java/net/minecraft/world/phys/shapes/VoxelShapes.java b/src/main/java/net/minecraft/world/phys/shapes/VoxelShapes.java
index 049aa5f51e7517744b25f8c2c4b5e7a7de24a73e..173197e9dc6acb31aa41ce645224fd9a2733f27c 100644
--- a/src/main/java/net/minecraft/world/phys/shapes/VoxelShapes.java
+++ b/src/main/java/net/minecraft/world/phys/shapes/VoxelShapes.java
@@ -5,6 +5,8 @@ import com.google.common.math.DoubleMath;
import com.google.common.math.IntMath;
import it.unimi.dsi.fastutil.doubles.DoubleArrayList;
import it.unimi.dsi.fastutil.doubles.DoubleList;
+import me.jellysquid.mods.lithium.common.shapes.pairs.LithiumDoublePairList; // Yatopia
+
import java.util.Arrays;
import java.util.Iterator;
import java.util.Objects;
@@ -476,7 +478,7 @@ public final class VoxelShapes {
// doublelist is usually a DoubleArrayList with Infinite head/tails that falls to the final else clause
// This is actually the most common path, so jump to it straight away
if (doublelist.getDouble(0) == Double.NEGATIVE_INFINITY && doublelist.getDouble(doublelist.size() - 1) == Double.POSITIVE_INFINITY) {
- return new VoxelShapeMergerList(doublelist, doublelist1, flag, flag1);
+ return new LithiumDoublePairList(doublelist, doublelist1, flag, flag1); // Yatopia - Port lithium
}
// Split out rest to hopefully inline the above
return lessCommonMerge(i, doublelist, doublelist1, flag, flag1);