diff --git a/gradle.properties b/gradle.properties index d06fe22..a768b47 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ mod_version=0.4.0-test0 maven_group=dev.kosmx.player-anim -fabric_loader_version=0.14.8 +fabric_loader_version=0.14.9 fabric_api_version=0.58.0+1.18.2 forge_version=1.18.2-40.1.80 diff --git a/minecraft/forge/src/main/java/dev/kosmx/playerAnim/impl/ForgeModInterface.java b/minecraft/forge/src/main/java/dev/kosmx/playerAnim/impl/ForgeModInterface.java index 411708f..c4fd106 100644 --- a/minecraft/forge/src/main/java/dev/kosmx/playerAnim/impl/ForgeModInterface.java +++ b/minecraft/forge/src/main/java/dev/kosmx/playerAnim/impl/ForgeModInterface.java @@ -1,40 +1,11 @@ package dev.kosmx.playerAnim.impl; -import dev.kosmx.playerAnim.core.data.gson.AnimationSerializing; -import dev.kosmx.playerAnim.minecraftApi.PlayerAnimationRegistry; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.packs.resources.ResourceManagerReloadListener; -import net.minecraftforge.client.event.RegisterClientReloadListenersEvent; import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import org.spongepowered.asm.mixin.Mixins; -import java.io.IOException; - @Mod("playeranimator") public class ForgeModInterface { public ForgeModInterface() { - FMLJavaModLoadingContext.get().getModEventBus().addListener(this::resourceLoadingListener); - } - - private void resourceLoadingListener(RegisterClientReloadListenersEvent event) { - event.registerReloadListener((ResourceManagerReloadListener) manager -> { - PlayerAnimationRegistry.clearAnimation(); - for (var resource: manager.listResources("player_animation", location -> location.endsWith(".json"))) { - try (var input = manager.getResource(resource).getInputStream()) { - - //Deserialize the animation json. GeckoLib animation json can contain multiple animations. - for (var animation : AnimationSerializing.deserializeAnimation(input)) { - - //Save the animation for later use. - PlayerAnimationRegistry.addAnimation(new ResourceLocation(resource.getNamespace(), PlayerAnimationRegistry.serializeTextToString((String) animation.extraData.get("name"))), animation); - } - } catch(IOException e) { - throw new RuntimeException(e);//Somehow handle invalid animations - } - } - }); - } diff --git a/minecraft/forge/src/main/java/dev/kosmx/playerAnim/impl/forge/ForgeClientEvent.java b/minecraft/forge/src/main/java/dev/kosmx/playerAnim/impl/forge/ForgeClientEvent.java new file mode 100644 index 0000000..a030bbe --- /dev/null +++ b/minecraft/forge/src/main/java/dev/kosmx/playerAnim/impl/forge/ForgeClientEvent.java @@ -0,0 +1,37 @@ +package dev.kosmx.playerAnim.impl.forge; + +import dev.kosmx.playerAnim.core.data.gson.AnimationSerializing; +import dev.kosmx.playerAnim.minecraftApi.PlayerAnimationRegistry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.packs.resources.ResourceManagerReloadListener; +import net.minecraftforge.client.event.RegisterClientReloadListenersEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; +import org.jetbrains.annotations.NotNull; + +import java.io.IOException; + +@Mod.EventBusSubscriber(modid = "playeranimator", bus = Mod.EventBusSubscriber.Bus.MOD) +public class ForgeClientEvent { + + @SubscribeEvent + public static void resourceLoadingListener(@NotNull RegisterClientReloadListenersEvent event) { + event.registerReloadListener((ResourceManagerReloadListener) manager -> { + PlayerAnimationRegistry.clearAnimation(); + for (var resource: manager.listResources("player_animation", location -> location.getPath().endsWith(".json")).entrySet()) { + try (var input = resource.getValue().open()) { + + //Deserialize the animation json. GeckoLib animation json can contain multiple animations. + for (var animation : AnimationSerializing.deserializeAnimation(input)) { + + //Save the animation for later use. + PlayerAnimationRegistry.addAnimation(new ResourceLocation(resource.getKey().getNamespace(), PlayerAnimationRegistry.serializeTextToString((String) animation.extraData.get("name"))), animation); + } + } catch(IOException e) { + throw new RuntimeException(e);//Somehow handle invalid animations + } + } + }); + } + +}