From 6800d76eae2f9eb8bc308d60ce82488706048e21 Mon Sep 17 00:00:00 2001 From: DoggySazHi Date: Sat, 24 Feb 2024 18:49:18 -0800 Subject: [PATCH] Implement 0005-lithium-fast-util.patch --- .../nitori/core/MixinAABB.java | 70 +++++++++++++++++++ .../nitori/core/MixinDirection.java | 46 ++++++++++++ src/main/resources/mixins.core.json | 4 +- 3 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 src/main/java/net/gensokyoreimagined/nitori/core/MixinAABB.java create mode 100644 src/main/java/net/gensokyoreimagined/nitori/core/MixinDirection.java diff --git a/src/main/java/net/gensokyoreimagined/nitori/core/MixinAABB.java b/src/main/java/net/gensokyoreimagined/nitori/core/MixinAABB.java new file mode 100644 index 0000000..51125c9 --- /dev/null +++ b/src/main/java/net/gensokyoreimagined/nitori/core/MixinAABB.java @@ -0,0 +1,70 @@ +// Nitori Copyright (C) 2024 Gensokyo Reimagined +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +package net.gensokyoreimagined.nitori.core; + +import net.minecraft.core.Direction; +import net.minecraft.world.phys.AABB; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(AABB.class) +public class MixinAABB { + @Shadow @Final public double minX; + @Shadow @Final public double minY; + @Shadow @Final public double minZ; + @Shadow @Final public double maxX; + @Shadow @Final public double maxY; + @Shadow @Final public double maxZ; + + /* + * Note: did not impelment the static constructor in the original patch, as it is not needed for the patch to work + */ + + /** + * @author DoggySazHi + * @reason Implementation of 0005-lithium-fast-util.patch, requires a overwrite to avoid calling `axis.choose` + */ + @Overwrite + public double min(Direction.Axis axis) { + return switch (axis.ordinal()) { + case 0 -> // X + this.minX; + case 1 -> // Y + this.minY; + case 2 -> // Z + this.minZ; + default -> throw new IllegalArgumentException(); + }; + } + + /** + * @author DoggySazHi + * @reason Implementation of 0005-lithium-fast-util.patch, requires a overwrite to avoid calling `axis.choose` + */ + @Overwrite + public double max(Direction.Axis axis) { + return switch (axis.ordinal()) { + case 0 -> // X + this.maxX; + case 1 -> // Y + this.maxY; + case 2 -> // Z + this.maxZ; + default -> throw new IllegalArgumentException(); + }; + } +} diff --git a/src/main/java/net/gensokyoreimagined/nitori/core/MixinDirection.java b/src/main/java/net/gensokyoreimagined/nitori/core/MixinDirection.java new file mode 100644 index 0000000..c4bc32d --- /dev/null +++ b/src/main/java/net/gensokyoreimagined/nitori/core/MixinDirection.java @@ -0,0 +1,46 @@ +// Nitori Copyright (C) 2024 Gensokyo Reimagined +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +package net.gensokyoreimagined.nitori.core; + +import net.minecraft.core.Direction; +import net.minecraft.util.RandomSource; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(Direction.class) +public class MixinDirection { + @Shadow @Final private static Direction[] VALUES; + @Shadow @Final private int oppositeIndex; + + /** + * @author DoggySazHi + * @reason Implementation of 0005-lithium-fast-util.patch, requires a overwrite to avoid calling `from3DDataValue` + */ + @Overwrite + public Direction getOpposite() { + return VALUES[this.oppositeIndex]; + } + + /** + * @author DoggySazHi + * @reason Implementation of 0005-lithium-fast-util.patch, requires a overwrite to avoid calling `Util.getRandom` + */ + @Overwrite + public static Direction getRandom(RandomSource random) { + return VALUES[random.nextInt(VALUES.length)]; + } +} diff --git a/src/main/resources/mixins.core.json b/src/main/resources/mixins.core.json index 6bfe290..e9b607c 100644 --- a/src/main/resources/mixins.core.json +++ b/src/main/resources/mixins.core.json @@ -7,6 +7,8 @@ "compatibilityLevel": "JAVA_17", "server": [ "ChunkMapMixin", - "MixinSpongeSIMD" + "MixinSpongeSIMD", + "MixinAABB", + "MixinDirection" ] }