From f60eec80bbc296391cd32126bd6f7241f4e164f3 Mon Sep 17 00:00:00 2001 From: tr7zw Date: Sun, 14 Jan 2024 22:54:06 +0100 Subject: [PATCH] Update template --- .gitignore | 2 + .../dev/tr7zw/firstperson/LogicHandler.java | 8 +- .../java/dev/tr7zw/util/ModLoaderUtil.java | 168 ------------------ src/main/java/dev/tr7zw/util/NMSHelper.java | 63 ------- 4 files changed, 3 insertions(+), 238 deletions(-) delete mode 100644 src/main/java/dev/tr7zw/util/ModLoaderUtil.java delete mode 100644 src/main/java/dev/tr7zw/util/NMSHelper.java diff --git a/.gitignore b/.gitignore index f02e69d3..5e8d7b7d 100644 --- a/.gitignore +++ b/.gitignore @@ -47,3 +47,5 @@ src/main/neoforge-resources/META-INF/mods.toml **/src/main/java/dev/tr7zw/config/CustomConfigScreen.java **/src/main/java/dev/tr7zw/util/ComponentProvider.java src/main/resources/pack.mcmeta +src/main/java/dev/tr7zw/util/NMSHelper.java +src/main/java/dev/tr7zw/util/ModLoaderUtil.java diff --git a/src/main/java/dev/tr7zw/firstperson/LogicHandler.java b/src/main/java/dev/tr7zw/firstperson/LogicHandler.java index 29622f9c..61a356f2 100644 --- a/src/main/java/dev/tr7zw/firstperson/LogicHandler.java +++ b/src/main/java/dev/tr7zw/firstperson/LogicHandler.java @@ -105,13 +105,7 @@ public void updatePositionOffset(Entity player, Vec3 defValue) { ((LivingEntity) abstractClientPlayerEntity_1.getVehicle()).yBodyRot); } else { realYaw = Mth.rotLerp(client.getFrameTime(), abstractClientPlayerEntity_1.getVehicle().yRotO, - // spotless:off - //#if MC >= 11700 - abstractClientPlayerEntity_1.getVehicle().getYRot()); - //#else - //$$ abstractClientPlayerEntity_1.getVehicle().yRot); - //#endif - //spotless:on + NMSHelper.getYRot(abstractClientPlayerEntity_1.getVehicle())); } bodyOffset = Constants.inVehicleBodyOffset + (FirstPersonModelCore.config.sitXOffset / 100f); } else { diff --git a/src/main/java/dev/tr7zw/util/ModLoaderUtil.java b/src/main/java/dev/tr7zw/util/ModLoaderUtil.java deleted file mode 100644 index e50fdad1..00000000 --- a/src/main/java/dev/tr7zw/util/ModLoaderUtil.java +++ /dev/null @@ -1,168 +0,0 @@ -package dev.tr7zw.util; - -import java.util.function.Function; - -import lombok.experimental.UtilityClass; -import net.minecraft.client.KeyMapping; -import net.minecraft.client.gui.screens.Screen; -//spotless:off -//#if FABRIC -import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; -import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; -import net.fabricmc.loader.api.FabricLoader; -//#elseif FORGE -//$$ import net.minecraft.client.Minecraft; -//$$ import org.apache.commons.lang3.ArrayUtils; -//$$ import net.minecraftforge.common.MinecraftForge; -//$$ import net.minecraftforge.event.TickEvent.ClientTickEvent; -//$$ import java.util.function.Consumer; -//$$ import net.minecraftforge.fml.ModLoadingContext; -//$$ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; -//$$ import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; -//$$ import net.minecraftforge.eventbus.api.Event; -//#if MC <= 11605 -//$$ import net.minecraftforge.fml.ExtensionPoint; -//$$ import net.minecraftforge.fml.network.FMLNetworkConstants; -//$$ import org.apache.commons.lang3.tuple.Pair; -//#elseif MC <= 11701 -//$$ import net.minecraftforge.fml.IExtensionPoint; -//$$ import net.minecraftforge.fmlclient.ConfigGuiHandler.ConfigGuiFactory; -//#elseif MC <= 11802 -//$$ import net.minecraftforge.fml.IExtensionPoint; -//$$ import net.minecraftforge.client.ConfigGuiHandler.ConfigGuiFactory; -//#else -//$$ import net.minecraftforge.fml.IExtensionPoint; -//$$ import net.minecraftforge.client.ConfigScreenHandler.ConfigScreenFactory; -//#endif -//#elseif NEOFORGE -//$$ import net.minecraft.client.Minecraft; -//$$ import org.apache.commons.lang3.ArrayUtils; -//$$ import java.util.function.Consumer; -//$$ import net.neoforged.fml.ModLoadingContext; -//$$ import net.neoforged.fml.IExtensionPoint; -//$$ import net.neoforged.bus.api.Event; -//$$ import net.neoforged.fml.javafmlmod.FMLJavaModLoadingContext; -//$$ import net.neoforged.neoforge.common.NeoForge; -//$$ import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent; -//$$ import net.neoforged.neoforge.event.TickEvent.ClientTickEvent; -//$$ import net.neoforged.neoforge.client.ConfigScreenHandler.ConfigScreenFactory; -//#endif -//spotless:on - -@UtilityClass -public class ModLoaderUtil { - - public static void registerKeybind(KeyMapping keyBinding) { - // spotless:off - //#if FABRIC - KeyBindingHelper.registerKeyBinding(keyBinding); - //#elseif FORGE || NEOFORGE - //$$ Minecraft.getInstance().options.keyMappings = ArrayUtils.add(Minecraft.getInstance().options.keyMappings, keyBinding); - //#endif - //spotless:on - - } - - public static void registerClientTickListener(Runnable runnable) { - // spotless:off - //#if FABRIC - ClientTickEvents.END_CLIENT_TICK.register(e -> { - runnable.run(); - }); - //#elseif FORGE - //$$ MinecraftForge.EVENT_BUS.addListener(new Consumer() { - //$$ - //$$ @Override - //$$ public void accept(ClientTickEvent t) { - //$$ runnable.run(); - //$$ } - //$$ - //$$ }); - //#elseif NEOFORGE - //$$ NeoForge.EVENT_BUS.addListener(new Consumer() { - //$$ - //$$ @Override - //$$ public void accept(ClientTickEvent t) { - //$$ runnable.run(); - //$$ } - //$$ - //$$ }); - //#endif - //spotless:on - } - - public static boolean isModLoaded(String name) { - // spotless:off - //#if FABRIC - return FabricLoader.getInstance().isModLoaded(name); - //#else - //$$ return false; - //#endif - //spotless:on - } - - public static void disableDisplayTest() { - // spotless:off - //#if FORGE || NEOFORGE - //#if MC <= 11605 - //$$ ModLoadingContext.get().registerExtensionPoint(ExtensionPoint.DISPLAYTEST, - //$$ () -> Pair.of(() -> FMLNetworkConstants.IGNORESERVERONLY, (remote, isServer) -> true)); - //#else - //$$ ModLoadingContext.get().registerExtensionPoint(IExtensionPoint.DisplayTest.class, - //$$ () -> new IExtensionPoint.DisplayTest( - //$$ () -> ModLoadingContext.get().getActiveContainer().getModInfo().getVersion().toString(), - //$$ (remote, isServer) -> true)); - //#endif - //#endif - //spotless:on - } - - public static void registerConfigScreen(Function createScreen) { - // spotless:off - //#if FORGE || NEOFORGE - //#if MC <= 11605 - //$$ ModLoadingContext.get().registerExtensionPoint( - //$$ ExtensionPoint.CONFIGGUIFACTORY, - //$$ () -> (mc, screen) -> createScreen.apply(screen)); - //#elseif MC <= 11802 - //$$ ModLoadingContext.get().registerExtensionPoint(ConfigGuiFactory.class, () - //$$ -> new ConfigGuiFactory((mc, screen) -> { - //$$ return createScreen.apply(screen); - //$$ })); - //#else - //$$ ModLoadingContext.get().registerExtensionPoint(ConfigScreenFactory.class, () -> new ConfigScreenFactory((mc, screen) -> { - //$$ return createScreen.apply(screen); - //$$ })); - //#endif - //#endif - //spotless:on - } - - public static void registerClientSetupListener(Runnable runnable) { - // spotless:off - //#if FORGE || NEOFORGE - //$$ FMLJavaModLoadingContext.get().getModEventBus().addListener(new Consumer() { - //$$ - //$$ @Override - //$$ public void accept(FMLClientSetupEvent t) { - //$$ runnable.run(); - //$$ } - //$$ - //$$ }); - //#endif - //spotless:on - } - - // spotless:off - //#if FORGE - //$$ public static void registerForgeEvent(Consumer handler) { - //$$ MinecraftForge.EVENT_BUS.addListener(handler); - //$$ } - //#elseif NEOFORGE - //$$ public static void registerForgeEvent(Consumer handler) { - //$$ NeoForge.EVENT_BUS.addListener(handler); - //$$ } - //#endif - //spotless:on - -} diff --git a/src/main/java/dev/tr7zw/util/NMSHelper.java b/src/main/java/dev/tr7zw/util/NMSHelper.java deleted file mode 100644 index 4bb91c1f..00000000 --- a/src/main/java/dev/tr7zw/util/NMSHelper.java +++ /dev/null @@ -1,63 +0,0 @@ -package dev.tr7zw.util; - -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.item.Item; - -//spotless:off -//#if MC >= 11903 -import net.minecraft.core.registries.BuiltInRegistries; - -import org.joml.Quaternionf; -import com.mojang.math.Axis; -//#else -//$$ import net.minecraft.core.Registry; -//$$ import com.mojang.math.Vector3f; -//#endif -//spotless:on - -public class NMSHelper { - - public static final float PI = (float) Math.PI; - public static final float HALF_PI = (float) (Math.PI / 2); - public static final float TWO_PI = (float) (Math.PI * 2); - - // spotless:off - //#if MC >= 11903 - public static Axis XN = f -> new Quaternionf().rotationX(-f); - public static Axis XP = f -> new Quaternionf().rotationX(f); - public static Axis YN = f -> new Quaternionf().rotationY(-f); - public static Axis YP = f -> new Quaternionf().rotationY(f); - public static Axis ZN = f -> new Quaternionf().rotationZ(-f); - public static Axis ZP = f -> new Quaternionf().rotationZ(f); - //#else - //$$ public static Vector3f XN = new Vector3f(-1.0F, 0.0F, 0.0F); - //$$ public static Vector3f XP = new Vector3f(1.0F, 0.0F, 0.0F); - //$$ public static Vector3f YN = new Vector3f(0.0F, -1.0F, 0.0F); - //$$ public static Vector3f YP = new Vector3f(0.0F, 1.0F, 0.0F); - //$$ public static Vector3f ZN = new Vector3f(0.0F, 0.0F, -1.0F); - //$$ public static Vector3f ZP = new Vector3f(0.0F, 0.0F, 1.0F); - //#endif - //spotless:on - - public static Item getItem(ResourceLocation key) { - // spotless:off - //#if MC >= 11903 - return BuiltInRegistries.ITEM.get(key); - //#else - //$$ return Registry.ITEM.get(key); - //#endif - //spotless:on - } - - public static float getXRot(Entity ent) { - // spotless:off - //#if MC >= 11700 - return ent.getXRot(); - //#else - //$$ return ent.xRot; - //#endif - //spotless:on - } - -}