Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 2.3.1 #11

Merged
merged 1 commit into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
Now has flashback, replaymod, and reforgedplay compatibility.
Will now play currently active animations for players that weren't there when it started.
API changes, check the wiki fr fr.
Fixed very major bug.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import dev.kosmx.playerAnim.minecraftApi.PlayerAnimationRegistry;
import dev.kosmx.playerAnim.minecraftApi.codec.AnimationCodecs;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.Resource;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.server.packs.resources.ResourceManagerReloadListener;
import net.minecraft.util.GsonHelper;
Expand All @@ -16,6 +17,7 @@
import java.io.IOException;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

public class ResourceReloadListener implements ResourceManagerReloadListener {

Expand All @@ -26,35 +28,42 @@ public void onResourceManagerReload(ResourceManager resourceManager) {
PlayerAnimations.animLengthsMap = new HashMap<>();
PlayerAnimations.geckoMap = new HashMap<>();
for (var resource : resourceManager.listResources("player_animation", location -> location.getPath().endsWith(".json")).entrySet()) {
try {
JsonObject jsonObject = GsonHelper.convertToJsonObject(JsonParser.parseReader(resource.getValue().openAsReader()), "resource");
if (jsonObject.has("animations")) {
for (var object : jsonObject.get("animations").getAsJsonObject().asMap().entrySet()) {
ResourceLocation resourceLocation = ResourceLocation.fromNamespaceAndPath(resource.getKey().getNamespace(), object.getKey().toLowerCase(Locale.ROOT));
PlayerAnimations.animLengthsMap.put(resourceLocation, object.getValue().getAsJsonObject().get("animation_length").getAsFloat());
if (object.getValue().getAsJsonObject().has("geckoResource")) {
PlayerAnimations.geckoMap.put(resourceLocation, ResourceLocation.parse(object.getValue().getAsJsonObject().get("geckoResource").getAsString()));
}
processResource(resource);
}
for (var resource : resourceManager.listResources("player_animations", location -> location.getPath().endsWith(".json")).entrySet()) {
processResource(resource);
}
}

public void processResource(Map.Entry<ResourceLocation, Resource> resource) {
try {
JsonObject jsonObject = GsonHelper.convertToJsonObject(JsonParser.parseReader(resource.getValue().openAsReader()), "resource");
if (jsonObject.has("animations")) {
for (var object : jsonObject.get("animations").getAsJsonObject().asMap().entrySet()) {
ResourceLocation resourceLocation = ResourceLocation.fromNamespaceAndPath(resource.getKey().getNamespace(), object.getKey().toLowerCase(Locale.ROOT));
PlayerAnimations.animLengthsMap.put(resourceLocation, object.getValue().getAsJsonObject().get("animation_length").getAsFloat());
if (object.getValue().getAsJsonObject().has("geckoResource")) {
PlayerAnimations.geckoMap.put(resourceLocation, ResourceLocation.parse(object.getValue().getAsJsonObject().get("geckoResource").getAsString()));
}
} else {
for (var animation : AnimationCodecs.deserialize(AnimationCodecs.getExtension(resource.getKey().getPath()), () -> {
try {
return resource.getValue().open();
} catch (IOException e) {
throw new RuntimeException(e);
}})) {
}
} else {
for (var animation : AnimationCodecs.deserialize(AnimationCodecs.getExtension(resource.getKey().getPath()), () -> {
try {
return resource.getValue().open();
} catch (IOException e) {
throw new RuntimeException(e);
}})) {

if (animation instanceof KeyframeAnimation) {
PlayerAnimations.animLengthsMap.put(ResourceLocation.fromNamespaceAndPath(resource.getKey().getNamespace(), PlayerAnimationRegistry.serializeTextToString((String) ((KeyframeAnimation)animation).extraData.get("name")).toLowerCase(Locale.ROOT)), (float) (((KeyframeAnimation)animation).endTick / 20));
if (jsonObject.has("geckoResource")) {
PlayerAnimations.geckoMap.put(ResourceLocation.fromNamespaceAndPath(resource.getKey().getNamespace(), PlayerAnimationRegistry.serializeTextToString((String) ((KeyframeAnimation)animation).extraData.get("name")).toLowerCase(Locale.ROOT)), ResourceLocation.parse(jsonObject.get("geckoResource").getAsString()));
}
if (animation instanceof KeyframeAnimation) {
PlayerAnimations.animLengthsMap.put(ResourceLocation.fromNamespaceAndPath(resource.getKey().getNamespace(), PlayerAnimationRegistry.serializeTextToString((String) ((KeyframeAnimation)animation).extraData.get("name")).toLowerCase(Locale.ROOT)), (float) (((KeyframeAnimation)animation).endTick / 20));
if (jsonObject.has("geckoResource")) {
PlayerAnimations.geckoMap.put(ResourceLocation.fromNamespaceAndPath(resource.getKey().getNamespace(), PlayerAnimationRegistry.serializeTextToString((String) ((KeyframeAnimation)animation).extraData.get("name")).toLowerCase(Locale.ROOT)), ResourceLocation.parse(jsonObject.get("geckoResource").getAsString()));
}
}
}
} catch (IOException | NullPointerException e) {
logger.warn("Could not load animation resource " + resource.getKey().toString() + " " + e);
}
} catch (IOException | NullPointerException e) {
logger.warn("Could not load animation resource " + resource.getKey().toString() + " " + e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.ApiStatus;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

Expand Down Expand Up @@ -52,8 +53,8 @@ public PlayerAnimationData decode(FriendlyByteBuf buf) {
public void encode(FriendlyByteBuf buf, PlayerAnimationData obj) {
UUID_STREAM_CODEC.encode(buf, obj.playerUUID());
ModCodecs.RESOURCELOCATION.encode(buf, obj.animationID());
PlayerParts.STREAM_CODEC.encode(buf, obj.parts());
CommonModifier.STREAM_CODEC.apply(ByteBufCodecs.list()).encode(buf, obj.modifiers());
PlayerParts.STREAM_CODEC.encode(buf, obj.parts() != null ? obj.parts() : PlayerParts.allEnabled);
CommonModifier.STREAM_CODEC.apply(ByteBufCodecs.list()).encode(buf, obj.modifiers() != null ? obj.modifiers() : new ArrayList<>());
ByteBufCodecs.INT.encode(buf, obj.fadeLength());
ByteBufCodecs.INT.encode(buf, obj.easeID());
ByteBufCodecs.INT.encode(buf, obj.priority());
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ java_version=21
enabled_platforms=fabric,forge
archives_base_name=playeranimatorapi
mod_id=playeranimatorapi
mod_version=2.3.0
mod_version=2.3.1
maven_group=zigy.playeranimatorapi
fabric_loader_version=0.15.11
fabric_api_version=0.100.6+1.21
Expand Down
2 changes: 1 addition & 1 deletion neoforge/src/main/resources/META-INF/neoforge.mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ config = "playeranimatorapi.mixins.json"

[[mods]]
modId = "playeranimatorapi"
version = "2.3.0"
version = "2.3.1"
displayName = "Zigy's Player Animator API"
authors = "Zigy"
description = '''
Expand Down