Files
MiraiMC/patches/server/0007-lithium-MixinDirection.patch
2021-12-09 16:10:30 +01:00

43 lines
1.5 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Etil <81570777+etil2jz@users.noreply.github.com>
Date: Thu, 2 Dec 2021 17:00:23 +0100
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 6d883db5c04cbcf454952c0f361029ecbfe4f037..53d853a4e9d8e3de4747a75f08f42545b048bbbb 100644
--- a/src/main/java/net/minecraft/core/Direction.java
+++ b/src/main/java/net/minecraft/core/Direction.java
@@ -190,8 +190,13 @@ public enum Direction implements StringRepresentable {
return var10000;
}
+ /*
+ @reason Avoid the modulo/abs operations
+ @author JellySquid
+ */
+
public Direction getOpposite() {
- return from3DDataValue(this.oppositeIndex);
+ return VALUES[this.oppositeIndex];
}
public Direction getClockWise(Direction.Axis axis) {
@@ -440,8 +445,13 @@ public enum Direction implements StringRepresentable {
return (float)((this.data2d & 3) * 90);
}
+ /*
+ @reason Do not allocate an excessive number of Direction arrays
+ @author JellySquid
+ */
+
public static Direction getRandom(Random random) {
- return Util.getRandom(VALUES, random);
+ return VALUES[random.nextInt(VALUES.length)];
}
public static Direction getNearest(double x, double y, double z) {