Yatopia/patches/server/0014-lithium-enum_values.patch
2020-08-05 14:38:36 -05:00

127 lines
5.3 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: JellySquid <jellysquid+atwork@protonmail.com>
Date: Fri, 31 Jul 2020 21:44:22 -0500
Subject: [PATCH] lithium enum_values
Original code by JellySquid, licensed under GNU Lesser General Public License v3.0
you can find the original code on https://github.com/jellysquid3/lithium-fabric/tree/1.15.x/fabric (Yarn mappings)
diff --git a/src/main/java/net/minecraft/server/BlockPiston.java b/src/main/java/net/minecraft/server/BlockPiston.java
index 4f10ca5ada741b4f5ef941bb9d92a2fa6a7c44ff..3d6f8d948d293ca57bf158bcd1f58e289d937fb5 100644
--- a/src/main/java/net/minecraft/server/BlockPiston.java
+++ b/src/main/java/net/minecraft/server/BlockPiston.java
@@ -127,9 +127,9 @@ public class BlockPiston extends BlockDirectional {
}
}
+ private final static EnumDirection[] aenumdirection = EnumDirection.values(); // Yatopia - don't recreate
private boolean a(World world, BlockPosition blockposition, EnumDirection enumdirection) {
- EnumDirection[] aenumdirection = EnumDirection.values();
int i = aenumdirection.length;
int j;
@@ -146,12 +146,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 2edebae8a1127c9214c7c2974700db9f207fa05f..ce96eea39425792eda9aacd656d2bffda8bc3803 100644
--- a/src/main/java/net/minecraft/server/EntityLiving.java
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
@@ -2567,11 +2567,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/EnumAxisCycle.java b/src/main/java/net/minecraft/server/EnumAxisCycle.java
index a7c2543fdd4d5f6a04c45ec42472837ccaea9619..ccfa23af36f66618f4ef18b0d86c86a73de9ea9f 100644
--- a/src/main/java/net/minecraft/server/EnumAxisCycle.java
+++ b/src/main/java/net/minecraft/server/EnumAxisCycle.java
@@ -26,12 +26,21 @@ public enum EnumAxisCycle {
@Override
public EnumDirection.EnumAxis a(EnumDirection.EnumAxis enumdirection_enumaxis) {
- return null.d[Math.floorMod(enumdirection_enumaxis.ordinal() + 1, 3)];
+ 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 null.BACKWARD;
+ return BACKWARD;
}
},
BACKWARD {
@@ -42,12 +51,21 @@ public enum EnumAxisCycle {
@Override
public EnumDirection.EnumAxis a(EnumDirection.EnumAxis enumdirection_enumaxis) {
- return null.d[Math.floorMod(enumdirection_enumaxis.ordinal() - 1, 3)];
+ 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 null.FORWARD;
+ return FORWARD;
}
};
diff --git a/src/main/java/net/minecraft/server/PistonExtendsChecker.java b/src/main/java/net/minecraft/server/PistonExtendsChecker.java
index 89385896af6f6088a9749a13ad5c1d0c581fa502..4fd1a98e8309bec2ef270ac70c4d79d143002b86 100644
--- a/src/main/java/net/minecraft/server/PistonExtendsChecker.java
+++ b/src/main/java/net/minecraft/server/PistonExtendsChecker.java
@@ -166,10 +166,10 @@ public class PistonExtendsChecker {
this.f.addAll(list1);
this.f.addAll(list2);
}
+ private final static EnumDirection[] aenumdirection = EnumDirection.values(); // Yatopia - 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) {