From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Etil <81570777+etil2jz@users.noreply.github.com> Date: Sat, 18 Sep 2021 00:02:37 +0200 Subject: [PATCH] (Lithium) MixinDirection 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) {