Lithium patches

This commit is contained in:
tr7zw 2020-06-27 19:00:18 +02:00
parent 3d9a4d9a9b
commit 3977242dcf
7 changed files with 486 additions and 0 deletions

View File

@ -0,0 +1,39 @@
From a3915a2ad6aed21a8cf260cd1c8dd89d885a38f9 Mon Sep 17 00:00:00 2001
From: tr7zw <tr7zw@live.de>
Date: Tue, 21 Apr 2020 16:14:10 +0200
Subject: [PATCH] Modify default configs
---
src/main/java/com/destroystokyo/paper/PaperConfig.java | 2 +-
src/main/java/com/destroystokyo/paper/PaperWorldConfig.java | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/main/java/com/destroystokyo/paper/PaperConfig.java b/src/main/java/com/destroystokyo/paper/PaperConfig.java
index 3b0f3127b..afb1d30ca 100644
--- a/src/main/java/com/destroystokyo/paper/PaperConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java
@@ -201,7 +201,7 @@ public class PaperConfig {
public static String timingsServerName;
private static void timings() {
- boolean timings = getBoolean("timings.enabled", true);
+ boolean timings = getBoolean("timings.enabled", false); // YAPFA don't profile by default
boolean verboseTimings = getBoolean("timings.verbose", true);
TimingsManager.privacy = getBoolean("timings.server-name-privacy", false);
TimingsManager.hiddenConfigs = getList("timings.hidden-config-entries", Lists.newArrayList("database", "settings.bungeecord-addresses"));
diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
index 0f4fca90f..9d02268c8 100644
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
@@ -605,7 +605,7 @@ public class PaperWorldConfig {
}
public boolean cooldownHopperWhenFull = true;
- public boolean disableHopperMoveEvents = false;
+ public boolean disableHopperMoveEvents = true; // YAPFA disable by default
private void hopperOptimizations() {
cooldownHopperWhenFull = getBoolean("hopper.cooldown-when-full", cooldownHopperWhenFull);
log("Cooldown Hoppers when Full: " + (cooldownHopperWhenFull ? "enabled" : "disabled"));
--
2.25.1.windows.1

View File

@ -0,0 +1,60 @@
From 55c54a6f3befd035220a10fdfe640663a4021ae3 Mon Sep 17 00:00:00 2001
From: tr7zw <tr7zw@live.de>
Date: Mon, 11 May 2020 21:00:44 +0200
Subject: [PATCH] lithium MixinDirection
---
.../java/net/minecraft/server/EnumDirection.java | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/src/main/java/net/minecraft/server/EnumDirection.java b/src/main/java/net/minecraft/server/EnumDirection.java
index 5a0465465..e60310a53 100644
--- a/src/main/java/net/minecraft/server/EnumDirection.java
+++ b/src/main/java/net/minecraft/server/EnumDirection.java
@@ -20,13 +20,13 @@ public enum EnumDirection implements INamable {
DOWN(0, 1, -1, "down", EnumDirection.EnumAxisDirection.NEGATIVE, EnumDirection.EnumAxis.Y, new BaseBlockPosition(0, -1, 0)), UP(1, 0, -1, "up", EnumDirection.EnumAxisDirection.POSITIVE, EnumDirection.EnumAxis.Y, new BaseBlockPosition(0, 1, 0)), NORTH(2, 3, 2, "north", EnumDirection.EnumAxisDirection.NEGATIVE, EnumDirection.EnumAxis.Z, new BaseBlockPosition(0, 0, -1)), SOUTH(3, 2, 0, "south", EnumDirection.EnumAxisDirection.POSITIVE, EnumDirection.EnumAxis.Z, new BaseBlockPosition(0, 0, 1)), WEST(4, 5, 1, "west", EnumDirection.EnumAxisDirection.NEGATIVE, EnumDirection.EnumAxis.X, new BaseBlockPosition(-1, 0, 0)), EAST(5, 4, 3, "east", EnumDirection.EnumAxisDirection.POSITIVE, EnumDirection.EnumAxis.X, new BaseBlockPosition(1, 0, 0));
private final int g;
- private final int h;
+ private final int h; // YAPFA this is idOpposit(yarn)
private final int i;
private final String j;
private final EnumDirection.EnumAxis k;
private final EnumDirection.EnumAxisDirection l;
private final BaseBlockPosition m;
- private static final EnumDirection[] n = values();
+ private static final EnumDirection[] n = values(); private static final EnumDirection[] ALL = n;// YAPFA OBF HELPER
private static final Map<String, EnumDirection> o = (Map) Arrays.stream(EnumDirection.n).collect(Collectors.toMap(EnumDirection::m, (enumdirection) -> {
return enumdirection;
}));
@@ -98,8 +98,12 @@ public enum EnumDirection implements INamable {
return this.l;
}
+ /**
+ * @reason Avoid the modulo/abs operations
+ * @author JellySquid
+ */
public EnumDirection opposite() {
- return fromType1(this.h);
+ return ALL[this.h];
}
public EnumDirection g() {
@@ -185,8 +189,12 @@ public enum EnumDirection implements INamable {
return (float) ((this.i & 3) * 90);
}
+ /**
+ * @reason Do not allocate an excessive number of Direction arrays
+ * @author JellySquid
+ */
public static EnumDirection a(Random random) {
- return (EnumDirection) SystemUtils.a((Object[]) EnumDirection.n, random);
+ return ALL[random.nextInt(ALL.length)];
}
public static EnumDirection a(double d0, double d1, double d2) {
--
2.25.1.windows.1

View File

@ -0,0 +1,59 @@
From 48bab6a46e0ddd8b02af16b3d75d2ba81458d05f Mon Sep 17 00:00:00 2001
From: tr7zw <tr7zw@live.de>
Date: Mon, 11 May 2020 21:02:57 +0200
Subject: [PATCH] lithium MixinBox
---
.../net/minecraft/server/AxisAlignedBB.java | 34 ++++++++++++++++---
1 file changed, 30 insertions(+), 4 deletions(-)
diff --git a/src/main/java/net/minecraft/server/AxisAlignedBB.java b/src/main/java/net/minecraft/server/AxisAlignedBB.java
index d54bf7140..661331bc0 100644
--- a/src/main/java/net/minecraft/server/AxisAlignedBB.java
+++ b/src/main/java/net/minecraft/server/AxisAlignedBB.java
@@ -155,12 +155,38 @@ public class AxisAlignedBB {
return new AxisAlignedBB(vec3d.x, vec3d.y, vec3d.z, vec3d.x + 1.0D, vec3d.y + 1.0D, vec3d.z + 1.0D);
}
+ /**
+ * @reason Simplify the code to better help the JVM optimize it
+ * @author JellySquid
+ */
public double a(EnumDirection.EnumAxis enumdirection_enumaxis) {
- return enumdirection_enumaxis.a(this.minX, this.minY, this.minZ);
- }
-
+ switch (enumdirection_enumaxis) {
+ case X:
+ return this.minX;
+ case Y:
+ return this.minY;
+ case Z:
+ return this.minZ;
+ }
+
+ throw new IllegalArgumentException();
+ }
+
+ /**
+ * @reason Simplify the code to better help the JVM optimize it
+ * @author JellySquid
+ */
public double b(EnumDirection.EnumAxis enumdirection_enumaxis) {
- return enumdirection_enumaxis.a(this.maxX, this.maxY, this.maxZ);
+ switch (enumdirection_enumaxis) {
+ case X:
+ return this.maxX;
+ case Y:
+ return this.maxY;
+ case Z:
+ return this.maxZ;
+ }
+
+ throw new IllegalArgumentException();
}
public boolean equals(Object object) {
--
2.25.1.windows.1

View File

@ -0,0 +1,81 @@
From 5bae4d02da3220c14432d6cdbeb60bc5f15f950e Mon Sep 17 00:00:00 2001
From: tr7zw <tr7zw@live.de>
Date: Mon, 11 May 2020 21:37:44 +0200
Subject: [PATCH] lithium enum_values
---
src/main/java/net/minecraft/server/BlockPiston.java | 8 ++++----
src/main/java/net/minecraft/server/EntityLiving.java | 6 +++++-
.../java/net/minecraft/server/PistonExtendsChecker.java | 4 +++-
3 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/src/main/java/net/minecraft/server/BlockPiston.java b/src/main/java/net/minecraft/server/BlockPiston.java
index 4f10ca5ad..7f2ee293a 100644
--- a/src/main/java/net/minecraft/server/BlockPiston.java
+++ b/src/main/java/net/minecraft/server/BlockPiston.java
@@ -128,8 +128,9 @@ public class BlockPiston extends BlockDirectional {
}
+ private final static EnumDirection[] aenumdirection = EnumDirection.values(); // YAPFA - don't recreate
+
private boolean a(World world, BlockPosition blockposition, EnumDirection enumdirection) {
- EnumDirection[] aenumdirection = EnumDirection.values();
int i = aenumdirection.length;
int j;
@@ -146,12 +147,11 @@ public class BlockPiston extends BlockDirectional {
return true;
} else {
BlockPosition blockposition1 = blockposition.up();
- EnumDirection[] aenumdirection1 = EnumDirection.values();
- j = aenumdirection1.length;
+ j = aenumdirection.length;
for (int k = 0; k < j; ++k) {
- EnumDirection enumdirection2 = aenumdirection1[k];
+ EnumDirection enumdirection2 = aenumdirection[k];
if (enumdirection2 != EnumDirection.DOWN && world.isBlockFacePowered(blockposition1.shift(enumdirection2), enumdirection2)) {
return true;
diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java
index 617358db7..029454d1a 100644
--- a/src/main/java/net/minecraft/server/EntityLiving.java
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
@@ -2566,10 +2566,14 @@ public abstract class EntityLiving extends Entity {
}
+ /**
+ * @reason Avoid cloning enum values
+ */
+ private final static EnumItemSlot[] aenumitemslot = EnumItemSlot.values();
+
@Nullable
private Map<EnumItemSlot, ItemStack> r() {
Map<EnumItemSlot, ItemStack> map = null;
- EnumItemSlot[] aenumitemslot = EnumItemSlot.values();
int i = aenumitemslot.length;
for (int j = 0; j < i; ++j) {
diff --git a/src/main/java/net/minecraft/server/PistonExtendsChecker.java b/src/main/java/net/minecraft/server/PistonExtendsChecker.java
index dd64aad1e..18a136213 100644
--- a/src/main/java/net/minecraft/server/PistonExtendsChecker.java
+++ b/src/main/java/net/minecraft/server/PistonExtendsChecker.java
@@ -167,9 +167,11 @@ public class PistonExtendsChecker {
this.f.addAll(list2);
}
+ private final static EnumDirection[] aenumdirection = EnumDirection.values(); // YAPFA - don't recreate
+
private boolean a(BlockPosition blockposition) {
IBlockData iblockdata = this.a.getType(blockposition);
- EnumDirection[] aenumdirection = EnumDirection.values();
+
int i = aenumdirection.length;
for (int j = 0; j < i; ++j) {
--
2.25.1.windows.1

View File

@ -0,0 +1,109 @@
From ad0c0ae4648157fe26fe74cb934c51fa81827b24 Mon Sep 17 00:00:00 2001
From: tr7zw <tr7zw@live.de>
Date: Mon, 11 May 2020 21:50:18 +0200
Subject: [PATCH] lithium MixinAxisCycleDirection
---
.../net/minecraft/server/EnumAxisCycle.java | 90 +++++++++++++++++++
1 file changed, 90 insertions(+)
create mode 100644 src/main/java/net/minecraft/server/EnumAxisCycle.java
diff --git a/src/main/java/net/minecraft/server/EnumAxisCycle.java b/src/main/java/net/minecraft/server/EnumAxisCycle.java
new file mode 100644
index 000000000..d05cddcc9
--- /dev/null
+++ b/src/main/java/net/minecraft/server/EnumAxisCycle.java
@@ -0,0 +1,90 @@
+package net.minecraft.server;
+
+public enum EnumAxisCycle {
+
+ NONE {
+ @Override
+ public int a(int i, int j, int k, EnumDirection.EnumAxis enumdirection_enumaxis) {
+ return enumdirection_enumaxis.a(i, j, k);
+ }
+
+ @Override
+ public EnumDirection.EnumAxis a(EnumDirection.EnumAxis enumdirection_enumaxis) {
+ return enumdirection_enumaxis;
+ }
+
+ @Override
+ public EnumAxisCycle a() {
+ return this;
+ }
+ },
+ FORWARD {
+ @Override
+ public int a(int i, int j, int k, EnumDirection.EnumAxis enumdirection_enumaxis) {
+ return enumdirection_enumaxis.a(k, i, j);
+ }
+
+ /**
+ * The JVM has difficulty optimizing these functions due to the use of dynamic dispatch. They can trivially be
+ * implemented as a simple switch lookup table.
+ */
+ @Override
+ public EnumDirection.EnumAxis a(EnumDirection.EnumAxis enumdirection_enumaxis) {
+ switch (enumdirection_enumaxis) {
+ case X:
+ return EnumDirection.EnumAxis.Y;
+ case Y:
+ return EnumDirection.EnumAxis.Z;
+ case Z:
+ return EnumDirection.EnumAxis.X;
+ }
+
+ throw new IllegalArgumentException();
+ }
+
+ @Override
+ public EnumAxisCycle a() {
+ return BACKWARD;
+ }
+ },
+ BACKWARD {
+ @Override
+ public int a(int i, int j, int k, EnumDirection.EnumAxis enumdirection_enumaxis) {
+ return enumdirection_enumaxis.a(j, k, i);
+ }
+
+ @Override
+ public EnumDirection.EnumAxis a(EnumDirection.EnumAxis enumdirection_enumaxis) {
+ switch (enumdirection_enumaxis) {
+ case X:
+ return EnumDirection.EnumAxis.Z;
+ case Y:
+ return EnumDirection.EnumAxis.X;
+ case Z:
+ return EnumDirection.EnumAxis.Y;
+ }
+
+ throw new IllegalArgumentException();
+ }
+
+ @Override
+ public EnumAxisCycle a() {
+ return FORWARD;
+ }
+ };
+
+ public static final EnumDirection.EnumAxis[] d = EnumDirection.EnumAxis.values();
+ public static final EnumAxisCycle[] e = values();
+
+ private EnumAxisCycle() {}
+
+ public abstract int a(int i, int j, int k, EnumDirection.EnumAxis enumdirection_enumaxis);
+
+ public abstract EnumDirection.EnumAxis a(EnumDirection.EnumAxis enumdirection_enumaxis);
+
+ public abstract EnumAxisCycle a();
+
+ public static EnumAxisCycle a(EnumDirection.EnumAxis enumdirection_enumaxis, EnumDirection.EnumAxis enumdirection_enumaxis1) {
+ return EnumAxisCycle.e[Math.floorMod(enumdirection_enumaxis1.ordinal() - enumdirection_enumaxis.ordinal(), 3)];
+ }
+}
--
2.25.1.windows.1

View File

@ -0,0 +1,36 @@
From 742f9a3ff915a3d72d74d99e2c601a9f15feaa1e Mon Sep 17 00:00:00 2001
From: tr7zw <tr7zw@live.de>
Date: Mon, 11 May 2020 22:07:17 +0200
Subject: [PATCH] lithium MixinGoalSelector
Only replaces the set type, might want to also port the logic rewrite in the future
---
.../java/net/minecraft/server/PathfinderGoalSelector.java | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/main/java/net/minecraft/server/PathfinderGoalSelector.java b/src/main/java/net/minecraft/server/PathfinderGoalSelector.java
index cce7cac92..3bfbb169f 100644
--- a/src/main/java/net/minecraft/server/PathfinderGoalSelector.java
+++ b/src/main/java/net/minecraft/server/PathfinderGoalSelector.java
@@ -1,7 +1,8 @@
package net.minecraft.server;
import com.destroystokyo.paper.util.set.OptimizedSmallEnumSet; // Paper - remove streams from pathfindergoalselector
-import com.google.common.collect.Sets;
+import it.unimi.dsi.fastutil.objects.ObjectLinkedOpenHashSet;
+
import java.util.EnumMap;
import java.util.EnumSet;
import java.util.Iterator; // Paper - remove streams from pathfindergoalselector
@@ -27,7 +28,7 @@ public class PathfinderGoalSelector {
}
};
private final Map<PathfinderGoal.Type, PathfinderGoalWrapped> c = new EnumMap(PathfinderGoal.Type.class);
- private final Set<PathfinderGoalWrapped> d = Sets.newLinkedHashSet(); public final Set<PathfinderGoalWrapped> getTasks() { return d; }// Paper - OBFHELPER // Paper - private -> public
+ private final Set<PathfinderGoalWrapped> d = new ObjectLinkedOpenHashSet<PathfinderGoalWrapped>();/* YAPFA better set */ public final Set<PathfinderGoalWrapped> getTasks() { return d; }// Paper - OBFHELPER // Paper - private -> public
private final Supplier<GameProfilerFiller> e;
private final EnumSet<PathfinderGoal.Type> f = EnumSet.noneOf(PathfinderGoal.Type.class); // Paper unused, but dummy to prevent plugins from crashing as hard. Theyll need to support paper in a special case if this is super important, but really doesn't seem like it would be.
private final OptimizedSmallEnumSet<PathfinderGoal.Type> goalTypes = new OptimizedSmallEnumSet<>(PathfinderGoal.Type.class); // Paper - remove streams from pathfindergoalselector
--
2.25.1.windows.1

View File

@ -0,0 +1,102 @@
From e8af8f1c75a60a935b84cad9356ed7ddc5f4dae4 Mon Sep 17 00:00:00 2001
From: tr7zw <tr7zw@live.de>
Date: Mon, 11 May 2020 22:56:27 +0200
Subject: [PATCH] lithium MixinLandPathNodeMaker
---
.../minecraft/server/PathfinderNormal.java | 57 +++++++++++++++++--
1 file changed, 51 insertions(+), 6 deletions(-)
diff --git a/src/main/java/net/minecraft/server/PathfinderNormal.java b/src/main/java/net/minecraft/server/PathfinderNormal.java
index ec55785af..87d6caa40 100644
--- a/src/main/java/net/minecraft/server/PathfinderNormal.java
+++ b/src/main/java/net/minecraft/server/PathfinderNormal.java
@@ -4,12 +4,23 @@ import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2BooleanMap;
import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap;
+import com.google.common.collect.Sets;
+
+import it.unimi.dsi.fastutil.objects.Reference2ReferenceMap;
+import it.unimi.dsi.fastutil.objects.Reference2ReferenceOpenHashMap;
+
import java.util.EnumSet;
import java.util.Iterator;
import javax.annotation.Nullable;
public class PathfinderNormal extends PathfinderAbstract {
+ // YAPFA start
+
+ // This is not thread-safe!
+ private static final Reference2ReferenceMap<IBlockData, PathType> commonTypes = new Reference2ReferenceOpenHashMap<>();
+ // YAPFA end
+
protected float j;
private final Long2ObjectMap<PathType> k = new Long2ObjectOpenHashMap();
private final Object2BooleanMap<AxisAlignedBB> l = new Object2BooleanOpenHashMap();
@@ -508,13 +519,44 @@ public class PathfinderNormal extends PathfinderAbstract {
protected static PathType b(IBlockAccess iblockaccess, BlockPosition blockposition) {
IBlockData iblockdata = iblockaccess.getTypeIfLoaded(blockposition); // Paper
if (iblockdata == null) return PathType.BLOCKED; // Paper
- Block block = iblockdata.getBlock();
- Material material = iblockdata.getMaterial();
+ // Check early if the block is air as it will always be open regardless of other conditions
+ if(iblockdata.isAir())return PathType.OPEN;
+
+ // Get the cached type for this block state
+ PathType type = commonTypes.get(iblockdata);
+
+ // No result has been cached for this block state yet, so calculate and cache it
+ if (type == null) {
+ commonTypes.put(iblockdata, type = getPathType(iblockaccess, blockposition, iblockdata));
+ }
+ // If the node type is open, it means that we were unable to determine a more specific type, so we need
+ // to check the fallback path.
+ if (type == PathType.OPEN) {
+ // This is only ever called in vanilla after all other possibilities are exhausted, but before fluid checks
+ // It should be safe to perform it last in actuality and take advantage of the cache for fluid types as well
+ // since fluids will always pass this check.
+ if (!iblockdata.a(iblockaccess, blockposition, PathMode.LAND)) {
+ return PathType.BLOCKED;
+ }
- if (iblockdata.isAir()) {
+ // All checks succeed, this path node really is open!
return PathType.OPEN;
- } else if (!iblockdata.a((Tag) TagsBlock.TRAPDOORS) && !iblockdata.a(Blocks.LILY_PAD)) {
- if (iblockdata.a(Blocks.CACTUS)) {
+ }
+
+ // Return the cached value since we found an obstacle earlier
+ return type;
+
+ }
+
+ private static PathType getPathType(IBlockAccess iblockaccess, BlockPosition blockposition,
+ IBlockData iblockdata) {
+ Block block = iblockdata.getBlock();
+ Material material = iblockdata.getMaterial();
+
+ if (!block.a(TagsBlock.TRAPDOORS) && block != Blocks.LILY_PAD) {
+ if (block == Blocks.FIRE) {
+ return PathType.DAMAGE_FIRE;
+ } else if (block == Blocks.CACTUS) {
return PathType.DAMAGE_CACTUS;
} else if (iblockdata.a(Blocks.SWEET_BERRY_BUSH)) {
return PathType.DAMAGE_OTHER;
@@ -540,7 +582,10 @@ public class PathfinderNormal extends PathfinderAbstract {
} else {
Fluid fluid = iblockdata.getFluid(); // Tuinity - remove another getType call
- return fluid.a((Tag) TagsFluid.WATER) ? PathType.WATER : (fluid.a((Tag) TagsFluid.LAVA) ? PathType.LAVA : PathType.OPEN);
+ if(fluid.a(TagsFluid.WATER))return PathType.WATER;
+ if(fluid.a(TagsFluid.LAVA))return PathType.LAVA;
+
+ return PathType.OPEN;
}
} else {
return PathType.FENCE;
--
2.25.1.windows.1