Files
MiraiMC/patches/server/0006-Lithium-MixinDirection.patch
2021-09-27 17:09:53 +02:00

44 lines
1.6 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: JellySquid <jellysquid+atwork@protonmail.com>
Date: Mon, 11 May 2020 21:00:44 +0200
Subject: [PATCH] (Lithium) MixinDirection
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/net/minecraft/core/Direction.java b/src/main/java/net/minecraft/core/Direction.java
index 593d6251c75ec337175d08b85000239ba7da1af2..c2c280a45baf7e64bc822cc8ed21f9f9bea7c867 100644
--- a/src/main/java/net/minecraft/core/Direction.java
+++ b/src/main/java/net/minecraft/core/Direction.java
@@ -171,8 +171,12 @@ public enum Direction implements StringRepresentable {
}
}
- public Direction getOpposite() {
- return from3DDataValue(this.oppositeIndex);
+ /**
+ * @reason Avoid the modulo/abs operations
+ * @author JellySquid
+ */
+ public Direction getOpposite() {
+ return VALUES[this.oppositeIndex];
}
public Direction getClockWise(Direction.Axis axis) {
@@ -386,8 +390,13 @@ public enum Direction implements StringRepresentable {
return (float)((this.data2d & 3) * 90);
}
- public static Direction getRandom(Random random) {
- return Util.getRandom(VALUES, random);
+ /**
+ *
+ * @reason Do not allocate an excessive number of Direction arrays
+ * @author JellySquid
+ */
+ public static Direction getRandom(Random random) {
+ return VALUES[random.nextInt(VALUES.length)];
}
public static Direction getNearest(double x, double y, double z) {