-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from KosmX/port_18
Move forge resource loading to client package
- Loading branch information
Showing
3 changed files
with
38 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 0 additions & 29 deletions
29
minecraft/forge/src/main/java/dev/kosmx/playerAnim/impl/ForgeModInterface.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
minecraft/forge/src/main/java/dev/kosmx/playerAnim/impl/forge/ForgeClientEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} | ||
}); | ||
} | ||
|
||
} |