From df879012d6734c37204a8b3be30ea5d2f12fdb28 Mon Sep 17 00:00:00 2001 From: LostInLinearPast <1283411677@qq.com> Date: Mon, 1 Dec 2025 17:22:23 +0800 Subject: [PATCH] version 0.1.1 --- gradle.properties | 2 +- .../2a65ee2815744be1ef1ffdae1c9a37f2a9cbe2ac | 4 +- .../c622617f6fabf890a00b9275cd5f643584a8a2c8 | 4 +- .../resources/assets/sccore/lang/en_us.json | 11 +- .../resources/assets/sccore/lang/zh_cn.json | 11 +- .../linearpast/sccore/SnowyCrescentCore.java | 4 +- .../sccore/animation/AnimationApi.java | 32 +- .../capability/AnimationDataCapability.java | 26 +- .../RawAnimationDataCapability.java | 58 --- .../animation/command/ApplyCommand.java | 12 +- .../animation/command/InviteCommand.java | 20 +- .../sccore/animation/command/JsonCommand.java | 8 +- .../sccore/animation/command/PlayCommand.java | 26 +- .../animation/command/RequestCommand.java | 20 +- .../command/client/RefreshCommand.java | 4 +- .../animation/entity/AnimationRideEntity.java | 29 +- .../entity/RawAnimationRideEntity.java | 198 ---------- .../animation/event/PlayerTickEvent.java | 9 - .../event/client/CameraAnglesModify.java | 4 +- .../event/client/ClientPlayerEvent.java | 4 +- .../animation/helper/AnimationDataHelper.java | 66 ++++ .../animation/helper/AnimationHelper.java | 374 ++++++++++-------- ...onHelper.java => AnimationJsonHelper.java} | 8 +- .../helper/AnimationServiceGetterHelper.java | 58 +++ .../helper/HelperGetterFromAnimation.java | 20 - .../helper/IAnimationServiceGetter.java | 34 ++ .../animation/helper/IHelperGetter.java | 31 -- ...erPacket.java => ServiceGetterPacket.java} | 24 +- .../RawAnimationCapabilityPacket.java | 10 - .../network/toclient/SyncAnimationPacket.java | 1 - .../toserver/ApplyAnimationPacket.java | 14 +- .../toserver/InviteAnimationPacket.java | 16 +- .../network/toserver/PlayAnimationPacket.java | 16 +- .../toserver/PlayAnimationRidePacket.java | 20 +- .../toserver/RequestAnimationPacket.java | 14 +- .../animation/register/AnimationCommands.java | 6 +- .../animation/register/AnimationRegistry.java | 8 +- .../animation/service/AnimationService.java | 168 ++++++++ .../IAnimationService.java} | 67 +++- .../RawAnimationService.java} | 51 +-- .../animation/utils/AnimationUtils.java | 47 +-- .../linearpast/sccore/core/IModLazyRun.java | 35 ++ .../linearpast/sccore/core/ModCompatRun.java | 29 ++ .../linearpast/sccore/core/ModLazyRun.java | 52 --- .../example/animation/ModAnimation.java | 4 +- .../event/ExamplePlayerAttackEvent.java | 18 +- .../sccore/mixin/SCCoreMixinPlugin.java | 4 +- .../sccore/mixin/animation/MixinEntity.java | 10 +- .../mixin/animation/client/MixinEntity.java | 4 +- .../animation/client/MixinHumanoidModel.java | 4 +- 50 files changed, 850 insertions(+), 849 deletions(-) delete mode 100644 src/main/java/com/linearpast/sccore/animation/entity/RawAnimationRideEntity.java create mode 100644 src/main/java/com/linearpast/sccore/animation/helper/AnimationDataHelper.java rename src/main/java/com/linearpast/sccore/animation/helper/{JsonHelper.java => AnimationJsonHelper.java} (93%) create mode 100644 src/main/java/com/linearpast/sccore/animation/helper/AnimationServiceGetterHelper.java delete mode 100644 src/main/java/com/linearpast/sccore/animation/helper/HelperGetterFromAnimation.java create mode 100644 src/main/java/com/linearpast/sccore/animation/helper/IAnimationServiceGetter.java delete mode 100644 src/main/java/com/linearpast/sccore/animation/helper/IHelperGetter.java rename src/main/java/com/linearpast/sccore/animation/network/{HelperGetterPacket.java => ServiceGetterPacket.java} (51%) create mode 100644 src/main/java/com/linearpast/sccore/animation/service/AnimationService.java rename src/main/java/com/linearpast/sccore/animation/{helper/IAnimationHelper.java => service/IAnimationService.java} (90%) rename src/main/java/com/linearpast/sccore/animation/{helper/RawAnimationHelper.java => service/RawAnimationService.java} (69%) create mode 100644 src/main/java/com/linearpast/sccore/core/IModLazyRun.java create mode 100644 src/main/java/com/linearpast/sccore/core/ModCompatRun.java delete mode 100644 src/main/java/com/linearpast/sccore/core/ModLazyRun.java diff --git a/gradle.properties b/gradle.properties index a04dede..872372d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,7 @@ mapping_version=2023.09.03-1.20.1 mod_id=sccore mod_name=SnowyCrescentCore mod_license=GNU AGPL 3.0 -mod_version=1.20.1-0.1.0-pre +mod_version=1.20.1-0.1.1 mod_group_id=com.linearpast mod_authors=LostInLinearPast mod_description=A lib about capability and player animator. diff --git a/src/generated/resources/.cache/2a65ee2815744be1ef1ffdae1c9a37f2a9cbe2ac b/src/generated/resources/.cache/2a65ee2815744be1ef1ffdae1c9a37f2a9cbe2ac index eefa914..afd6be6 100644 --- a/src/generated/resources/.cache/2a65ee2815744be1ef1ffdae1c9a37f2a9cbe2ac +++ b/src/generated/resources/.cache/2a65ee2815744be1ef1ffdae1c9a37f2a9cbe2ac @@ -1,2 +1,2 @@ -// 1.20.1 2025-11-26T10:22:37.4821986 Languages: zh_cn -bfd0415418a7b7d284a9b445fd35a7242782beea assets/sccore/lang/zh_cn.json +// 1.20.1 2025-11-28T18:32:27.7132485 Languages: zh_cn +33a56369fb517ec3b528128539e1e160666d9602 assets/sccore/lang/zh_cn.json diff --git a/src/generated/resources/.cache/c622617f6fabf890a00b9275cd5f643584a8a2c8 b/src/generated/resources/.cache/c622617f6fabf890a00b9275cd5f643584a8a2c8 index 579b6a3..9af5879 100644 --- a/src/generated/resources/.cache/c622617f6fabf890a00b9275cd5f643584a8a2c8 +++ b/src/generated/resources/.cache/c622617f6fabf890a00b9275cd5f643584a8a2c8 @@ -1,2 +1,2 @@ -// 1.20.1 2025-11-26T10:22:37.4835694 Languages: en_us -874336226401ae3f556eec3296550b37f72d8831 assets/sccore/lang/en_us.json +// 1.20.1 2025-11-28T18:32:27.715234 Languages: en_us +941682565bf7998e144253f88be175d198e43566 assets/sccore/lang/en_us.json diff --git a/src/generated/resources/assets/sccore/lang/en_us.json b/src/generated/resources/assets/sccore/lang/en_us.json index 7fc321f..dafce58 100644 --- a/src/generated/resources/assets/sccore/lang/en_us.json +++ b/src/generated/resources/assets/sccore/lang/en_us.json @@ -1,14 +1,15 @@ { - "translation.sccore.animation.animation_cooldown": "You cannot perform this operation: Cooling down (%s second(s)).", - "translation.sccore.animation.animation_expire": "You cannot perform this operation: It has expired.", - "translation.sccore.animation.animation_operation_unsupported": "Error: Unsupported operation.", - "translation.sccore.animation.animation_out_range": "You cannot perform this operation: The distance is not within %s blocks.", - "translation.sccore.animation.animation_resource_not_found": "Error: Resource not found, please check if there are any errors in the resource or operation.", "translation.sccore.command.animation.accept_apply_success": "%s has accepted the application of %s.", "translation.sccore.command.animation.accept_invite_success": "Invitation accepted.", "translation.sccore.command.animation.accept_message_click": "Click here to accept.", "translation.sccore.command.animation.accept_request_success": "Request accepted.", + "translation.sccore.command.animation.animation_cooldown": "You cannot perform this operation: Cooling down (%s second(s)).", + "translation.sccore.command.animation.animation_expire": "You cannot perform this operation: It has expired.", "translation.sccore.command.animation.animation_json_path": "%s", + "translation.sccore.command.animation.animation_operation_cancelled": "Exception: Operation cancelled.", + "translation.sccore.command.animation.animation_operation_unsupported": "Error: Unsupported operation.", + "translation.sccore.command.animation.animation_out_range": "You cannot perform this operation: The distance is not within %s blocks.", + "translation.sccore.command.animation.animation_resource_not_found": "Error: Resource not found, please check if there are any errors in the resource or operation.", "translation.sccore.command.animation.animation_to_json": "The animation %s has been stored in the path on %s:", "translation.sccore.command.animation.applied_join_message": "%S§b§l Apply for §r to join your animation. ", "translation.sccore.command.animation.apply_join_message": "Application sent.", diff --git a/src/generated/resources/assets/sccore/lang/zh_cn.json b/src/generated/resources/assets/sccore/lang/zh_cn.json index cf29b01..9556549 100644 --- a/src/generated/resources/assets/sccore/lang/zh_cn.json +++ b/src/generated/resources/assets/sccore/lang/zh_cn.json @@ -1,14 +1,15 @@ { - "translation.sccore.animation.animation_cooldown": "你不能执行该操作: 冷却中(%s 秒)。", - "translation.sccore.animation.animation_expire": "你不能执行该操作: 已过期。", - "translation.sccore.animation.animation_operation_unsupported": "错误: 不支持这样做。", - "translation.sccore.animation.animation_out_range": "你不能执行该操作: 距离不在%s格以内。", - "translation.sccore.animation.animation_resource_not_found": "错误: 资源未找到,请检查资源或操作是否有误。", "translation.sccore.command.animation.accept_apply_success": "%s 接受了 %s 的申请。", "translation.sccore.command.animation.accept_invite_success": "已接受邀请。", "translation.sccore.command.animation.accept_message_click": "单击此处同意。", "translation.sccore.command.animation.accept_request_success": "已接受请求。", + "translation.sccore.command.animation.animation_cooldown": "你不能执行该操作: 冷却中(%s秒)。", + "translation.sccore.command.animation.animation_expire": "你不能执行该操作: 已过期。", "translation.sccore.command.animation.animation_json_path": "%s", + "translation.sccore.command.animation.animation_operation_cancelled": "异常: 操作被取消。", + "translation.sccore.command.animation.animation_operation_unsupported": "错误: 不支持这样做。", + "translation.sccore.command.animation.animation_out_range": "你不能执行该操作: 距离不在%s格以内。", + "translation.sccore.command.animation.animation_resource_not_found": "错误: 资源未找到,请检查资源或操作是否有误。", "translation.sccore.command.animation.animation_to_json": "动画%s已经存储到%s路径:", "translation.sccore.command.animation.applied_join_message": "%s§b§l 申请§r加入动画。", "translation.sccore.command.animation.apply_join_message": "已发送申请。", diff --git a/src/main/java/com/linearpast/sccore/SnowyCrescentCore.java b/src/main/java/com/linearpast/sccore/SnowyCrescentCore.java index e1b770d..ec6f8ca 100644 --- a/src/main/java/com/linearpast/sccore/SnowyCrescentCore.java +++ b/src/main/java/com/linearpast/sccore/SnowyCrescentCore.java @@ -1,7 +1,7 @@ package com.linearpast.sccore; -import com.linearpast.sccore.animation.helper.IAnimationHelper; +import com.linearpast.sccore.animation.service.IAnimationService; import com.linearpast.sccore.capability.CapabilityUtils; import com.linearpast.sccore.core.ModChannel; import com.linearpast.sccore.core.ModCommands; @@ -34,7 +34,7 @@ public class SnowyCrescentCore { CapabilityUtils.registerHandler(forgeBus); ModChannel.register(); - IAnimationHelper.register(forgeBus, modBus); + IAnimationService.register(forgeBus, modBus); ModCommands.registerCommands(forgeBus, modBus); if(!FMLEnvironment.production || Boolean.getBoolean(ENABLE_EXAMPLES_PROPERTY_KEY)) { diff --git a/src/main/java/com/linearpast/sccore/animation/AnimationApi.java b/src/main/java/com/linearpast/sccore/animation/AnimationApi.java index 3532b84..d7d17ea 100644 --- a/src/main/java/com/linearpast/sccore/animation/AnimationApi.java +++ b/src/main/java/com/linearpast/sccore/animation/AnimationApi.java @@ -1,33 +1,31 @@ package com.linearpast.sccore.animation; -import com.linearpast.sccore.animation.helper.*; +import com.linearpast.sccore.animation.helper.AnimationDataHelper; +import com.linearpast.sccore.animation.helper.AnimationHelper; +import com.linearpast.sccore.animation.helper.AnimationJsonHelper; +import com.linearpast.sccore.animation.helper.AnimationServiceGetterHelper; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; - -import java.util.Set; +import net.minecraft.world.entity.player.Player; public class AnimationApi { - public static AnimationApi getInstance() { - return new AnimationApi(); + public static AnimationJsonHelper getJsonHelper(MinecraftServer server) { + return AnimationJsonHelper.getHelper(server); } - public AnimationHelper getAnimationHelper() { - return AnimationHelper.INSTANCE; + public static AnimationDataHelper getDataHelper() { + return AnimationDataHelper.getHelper(); } - public RawAnimationHelper getRawAnimationHelper() { - return RawAnimationHelper.INSTANCE; + public static AnimationServiceGetterHelper getServiceGetterHelper(ResourceLocation location) { + return new AnimationServiceGetterHelper(location); } - public JsonHelper getJsonHelper(MinecraftServer server) { - return JsonHelper.getHelper(server); + public static AnimationServiceGetterHelper getServiceGetterHelper() { + return new AnimationServiceGetterHelper(); } - public IAnimationHelper getHelperFromAnimKey(ResourceLocation location) { - return new HelperGetterFromAnimation(location).getHelper(); - } - - public Set> getAllHelpers() { - return IHelperGetter.HELPERS; + public static AnimationHelper getHelper(Player player) { + return AnimationHelper.getHelper(player); } } diff --git a/src/main/java/com/linearpast/sccore/animation/capability/AnimationDataCapability.java b/src/main/java/com/linearpast/sccore/animation/capability/AnimationDataCapability.java index 4586a18..f2e2381 100644 --- a/src/main/java/com/linearpast/sccore/animation/capability/AnimationDataCapability.java +++ b/src/main/java/com/linearpast/sccore/animation/capability/AnimationDataCapability.java @@ -2,9 +2,9 @@ package com.linearpast.sccore.animation.capability; import com.linearpast.sccore.SnowyCrescentCore; import com.linearpast.sccore.animation.capability.inter.IAnimationCapability; -import com.linearpast.sccore.animation.helper.AnimationHelper; import com.linearpast.sccore.animation.network.toclient.AnimationCapabilityPacket; import com.linearpast.sccore.animation.register.AnimationRegistry; +import com.linearpast.sccore.animation.service.AnimationService; import com.linearpast.sccore.capability.CapabilityUtils; import com.linearpast.sccore.capability.data.ICapabilitySync; import com.linearpast.sccore.capability.data.player.SimplePlayerCapabilitySync; @@ -35,7 +35,7 @@ public class AnimationDataCapability extends SimplePlayerCapabilitySync implemen public void mergeAnimations(Map animations) { animations.forEach((key, value) -> { if (AnimationRegistry.getLayers().containsKey(key)) { - if (AnimationHelper.INSTANCE.isAnimationPresent(value)) { + if (AnimationService.INSTANCE.isAnimationPresent(value)) { if(Objects.equals(rideAnimLayer, key)) { removeRiderAnimation(); } @@ -49,7 +49,7 @@ public class AnimationDataCapability extends SimplePlayerCapabilitySync implemen @Override public boolean mergeAnimation(ResourceLocation layer, ResourceLocation animation) { if (AnimationRegistry.getLayers().containsKey(layer)) { - if (AnimationHelper.INSTANCE.isAnimationPresent(animation)) { + if (AnimationService.INSTANCE.isAnimationPresent(animation)) { if(Objects.equals(rideAnimLayer, layer)) { removeRiderAnimation(); } @@ -105,15 +105,13 @@ public class AnimationDataCapability extends SimplePlayerCapabilitySync implemen @Override public void setRiderAnimation(@NotNull ResourceLocation layer, @NotNull ResourceLocation animation) { - if(AnimationHelper.INSTANCE.isAnimationLayerPresent(layer)) { - if(AnimationHelper.INSTANCE.isAnimationPresent(animation)) { - this.rideAnimLayer = layer; - this.rideAnimation = animation; - if(animMap.get(layer) != null) { - animMap.remove(layer); - } - setDirty(true); + if(AnimationService.INSTANCE.isAnimationLayerPresent(layer)) { + this.rideAnimLayer = layer; + this.rideAnimation = animation; + if(animMap.get(layer) != null) { + animMap.remove(layer); } + setDirty(true); } } @@ -177,10 +175,10 @@ public class AnimationDataCapability extends SimplePlayerCapabilitySync implemen public void attachInit(Player player) { Map map = new HashMap<>(this.animMap); map.forEach((key, value) -> { - if(!AnimationHelper.INSTANCE.isAnimationLayerPresent(key)) this.animMap.remove(key); - if(!AnimationHelper.INSTANCE.isAnimationPresent(value)) this.animMap.remove(key); + if(!AnimationService.INSTANCE.isAnimationLayerPresent(key)) this.animMap.remove(key); + if(!AnimationService.INSTANCE.isAnimationPresent(value)) this.animMap.remove(key); }); - if(rideAnimLayer != null && !AnimationHelper.INSTANCE.isAnimationLayerPresent(rideAnimLayer)) { + if(rideAnimLayer != null && !AnimationService.INSTANCE.isAnimationLayerPresent(rideAnimLayer)) { removeRiderAnimation(); } } diff --git a/src/main/java/com/linearpast/sccore/animation/capability/RawAnimationDataCapability.java b/src/main/java/com/linearpast/sccore/animation/capability/RawAnimationDataCapability.java index 8a10f74..7f517af 100644 --- a/src/main/java/com/linearpast/sccore/animation/capability/RawAnimationDataCapability.java +++ b/src/main/java/com/linearpast/sccore/animation/capability/RawAnimationDataCapability.java @@ -2,7 +2,6 @@ package com.linearpast.sccore.animation.capability; import com.linearpast.sccore.SnowyCrescentCore; import com.linearpast.sccore.animation.capability.inter.IAnimationCapability; -import com.linearpast.sccore.animation.helper.AnimationHelper; import com.linearpast.sccore.animation.network.toclient.RawAnimationCapabilityPacket; import com.linearpast.sccore.animation.register.AnimationRegistry; import com.linearpast.sccore.capability.CapabilityUtils; @@ -11,34 +10,22 @@ import com.linearpast.sccore.capability.data.player.SimplePlayerCapabilitySync; import com.linearpast.sccore.capability.network.SimpleCapabilityPacket; import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.player.Player; -import net.minecraftforge.server.ServerLifecycleHooks; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.HashMap; import java.util.Map; -import java.util.Objects; import java.util.Optional; public class RawAnimationDataCapability extends SimplePlayerCapabilitySync { public static final ResourceLocation key = new ResourceLocation(SnowyCrescentCore.MODID, "raw_animation_data"); public static final String AnimMap = "AnimMap"; - public static final String RideAnimLayer = "RideAnimLayer"; - public static final String RideAnimation = "RideAnimation"; private final Map animMap = new HashMap<>(); - private ResourceLocation rideAnimLayer; - private ResourceLocation rideAnimation; public boolean mergeAnimation(ResourceLocation layer, ResourceLocation animation) { if (AnimationRegistry.getLayers().containsKey(layer)) { - if(Objects.equals(rideAnimLayer, layer)) { - removeRiderAnimation(); - } this.animMap.put(layer, animation); setDirty(true); return true; @@ -73,49 +60,11 @@ public class RawAnimationDataCapability extends SimplePlayerCapabilitySync { return animMap.containsKey(layer); } - public ResourceLocation getRiderAnimLayer() { - return rideAnimLayer; - } - - public ResourceLocation getRiderAnimation() { - return rideAnimation; - } - - public void setRiderAnimation(@NotNull ResourceLocation layer, @NotNull ResourceLocation animation) { - if(AnimationHelper.INSTANCE.isAnimationLayerPresent(layer)) { - MinecraftServer currentServer = ServerLifecycleHooks.getCurrentServer(); - if(currentServer == null) return; - ServerPlayer serverPlayer = currentServer.getPlayerList().getPlayer(this.getOwnerUUID()); - if(serverPlayer == null) return; - IAnimationCapability data = AnimationDataCapability.getCapability(serverPlayer).orElse(null); - if(data == null) return; - if(data.getRiderAnimation() != null) return; - if(data.getRiderAnimLayer() != null) { - data.removeRiderAnimation(); - return; - } - this.rideAnimLayer = layer; - this.rideAnimation = animation; - if(animMap.get(layer) != null) { - animMap.remove(layer); - } - setDirty(true); - } - } - - public void removeRiderAnimation() { - this.rideAnimLayer = null; - this.rideAnimation = null; - setDirty(true); - } - @Override public void copyFrom(ICapabilitySync oldData) { IAnimationCapability data = (IAnimationCapability) oldData; this.animMap.clear(); this.animMap.putAll(data.getAnimations()); - this.rideAnimLayer = data.getRiderAnimLayer(); - this.rideAnimation = data.getRiderAnimation(); } @Override @@ -127,16 +76,12 @@ public class RawAnimationDataCapability extends SimplePlayerCapabilitySync { ); tag.put(AnimMap, animMapTag); } - if(rideAnimLayer != null) tag.putString(RideAnimLayer, rideAnimLayer.toString()); - if(rideAnimation != null) tag.putString(RideAnimation, rideAnimation.toString()); return tag; } @Override public void fromTag(CompoundTag tag) { this.animMap.clear(); - this.rideAnimLayer = null; - this.rideAnimation = null; if(tag.contains(AnimMap)) { CompoundTag animMapTag = tag.getCompound(AnimMap); animMapTag.getAllKeys().forEach(key -> this.animMap.put( @@ -144,8 +89,6 @@ public class RawAnimationDataCapability extends SimplePlayerCapabilitySync { new ResourceLocation(animMapTag.getString(key)) )); } - if(tag.contains(RideAnimLayer)) this.rideAnimLayer = new ResourceLocation(tag.getString(RideAnimLayer)); - if(tag.contains(RideAnimation)) this.rideAnimation = new ResourceLocation(tag.getString(RideAnimation)); } @Override @@ -161,7 +104,6 @@ public class RawAnimationDataCapability extends SimplePlayerCapabilitySync { @Override public void attachInit(Player entity) { clearAnimations(); - removeRiderAnimation(); } public static Optional getCapability(Player player){ diff --git a/src/main/java/com/linearpast/sccore/animation/command/ApplyCommand.java b/src/main/java/com/linearpast/sccore/animation/command/ApplyCommand.java index 0fd8ad9..362d11c 100644 --- a/src/main/java/com/linearpast/sccore/animation/command/ApplyCommand.java +++ b/src/main/java/com/linearpast/sccore/animation/command/ApplyCommand.java @@ -1,10 +1,8 @@ package com.linearpast.sccore.animation.command; import com.linearpast.sccore.SnowyCrescentCore; +import com.linearpast.sccore.animation.AnimationApi; import com.linearpast.sccore.animation.command.exception.ApiBackException; -import com.linearpast.sccore.animation.helper.AnimationHelper; -import com.linearpast.sccore.animation.helper.IAnimationHelper; -import com.linearpast.sccore.animation.helper.IHelperGetter; import com.linearpast.sccore.animation.utils.ApiBack; import com.linearpast.sccore.core.configs.ModConfigs; import com.linearpast.sccore.core.datagen.ModLang; @@ -47,7 +45,7 @@ public class ApplyCommand { Entity vehicle = target.getVehicle(); if(vehicle == null) throw new ApiBackException(ApiBack.UNSUPPORTED); - ApiBack back = AnimationHelper.INSTANCE.apply(player, target); + ApiBack back = AnimationApi.getHelper(player).applyAnimation(target); if(back == ApiBack.COOLDOWN) { int cooldown = ModConfigs.Server.applyCooldown.get(); throw ApiBackException.withCooldown(cooldown); @@ -92,11 +90,7 @@ public class ApplyCommand { Entity vehicle = player.getVehicle(); if(vehicle == null) throw new ApiBackException(ApiBack.UNSUPPORTED); - ApiBack back = ApiBack.RESOURCE_NOT_FOUND; - for (IAnimationHelper helper : IHelperGetter.HELPERS) { - back = helper.acceptApply(player, applier); - if(back == ApiBack.SUCCESS) break; - } + ApiBack back = AnimationApi.getHelper(player).acceptApply(applier); if(back == ApiBack.OUT_RANGE) throw ApiBackException.withOutRange(ModConfigs.Server.applyValidDistance.get()); if(back != ApiBack.SUCCESS) throw new ApiBackException(back); diff --git a/src/main/java/com/linearpast/sccore/animation/command/InviteCommand.java b/src/main/java/com/linearpast/sccore/animation/command/InviteCommand.java index dac2bca..ed5a070 100644 --- a/src/main/java/com/linearpast/sccore/animation/command/InviteCommand.java +++ b/src/main/java/com/linearpast/sccore/animation/command/InviteCommand.java @@ -1,14 +1,10 @@ package com.linearpast.sccore.animation.command; import com.linearpast.sccore.SnowyCrescentCore; +import com.linearpast.sccore.animation.AnimationApi; import com.linearpast.sccore.animation.command.argument.AnimationArgument; import com.linearpast.sccore.animation.command.argument.AnimationLayerArgument; import com.linearpast.sccore.animation.command.exception.ApiBackException; -import com.linearpast.sccore.animation.data.AnimationData; -import com.linearpast.sccore.animation.data.RawAnimationData; -import com.linearpast.sccore.animation.helper.HelperGetterFromAnimation; -import com.linearpast.sccore.animation.helper.IAnimationHelper; -import com.linearpast.sccore.animation.helper.IHelperGetter; import com.linearpast.sccore.animation.utils.ApiBack; import com.linearpast.sccore.core.configs.ModConfigs; import com.linearpast.sccore.core.datagen.ModLang; @@ -61,14 +57,8 @@ public class InviteCommand { ResourceLocation anim = new ResourceLocation(animString); //test info present - IAnimationHelper helper = HelperGetterFromAnimation.create(anim).getHelper(); - if (helper == null) throw new ApiBackException(ApiBack.RESOURCE_NOT_FOUND); - AnimationData animationData; - if(helper.isAnimationPresent(anim)) animationData = helper.getAnimation(anim); - else animationData = RawAnimationData.create(anim); - List targets = players.stream().map(Entity::getUUID).toList(); - ApiBack back = helper.invite(player, layer, animationData, targets); + ApiBack back = AnimationApi.getHelper(player).inviteAnimation(layer, anim, targets); if(back == ApiBack.COOLDOWN) { int cooldown = ModConfigs.Server.inviteCooldown.get(); throw ApiBackException.withCooldown(cooldown); @@ -111,11 +101,7 @@ public class InviteCommand { ServerPlayer inviter = EntityArgument.getPlayer(context, "player"); //play animation - ApiBack back = ApiBack.RESOURCE_NOT_FOUND; - for (IAnimationHelper helper : IHelperGetter.HELPERS) { - back = helper.acceptInvite(player, inviter); - if(back == ApiBack.SUCCESS) break; - } + ApiBack back = AnimationApi.getHelper(player).acceptInvite(inviter); if(back == ApiBack.OUT_RANGE) throw ApiBackException.withOutRange(ModConfigs.Server.inviteValidDistance.get()); if(back != ApiBack.SUCCESS) throw new ApiBackException(back); diff --git a/src/main/java/com/linearpast/sccore/animation/command/JsonCommand.java b/src/main/java/com/linearpast/sccore/animation/command/JsonCommand.java index c884588..ed786a8 100644 --- a/src/main/java/com/linearpast/sccore/animation/command/JsonCommand.java +++ b/src/main/java/com/linearpast/sccore/animation/command/JsonCommand.java @@ -1,7 +1,7 @@ package com.linearpast.sccore.animation.command; import com.linearpast.sccore.SnowyCrescentCore; -import com.linearpast.sccore.animation.helper.JsonHelper; +import com.linearpast.sccore.animation.helper.AnimationJsonHelper; import com.linearpast.sccore.core.datagen.ModLang; import com.mojang.brigadier.arguments.BoolArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; @@ -46,7 +46,7 @@ public class JsonCommand { CommandSourceStack source = context.getSource(); try { //generate - JsonHelper helper = JsonHelper.getHelper(source.getServer()); + AnimationJsonHelper helper = AnimationJsonHelper.getHelper(source.getServer()); Path path = helper.generateJson(isLayer, isReset); if(path == null) throw new Exception(); @@ -75,7 +75,7 @@ public class JsonCommand { CommandSourceStack source = context.getSource(); try { //clear path - JsonHelper.getHelper(source.getServer()).clearPath(); + AnimationJsonHelper.getHelper(source.getServer()).clearPath(); } catch (Exception e) { source.sendFailure(Component.translatable( ModLang.TranslatableMessage.COMMAND_RUN_FAIL.getKey() @@ -90,7 +90,7 @@ public class JsonCommand { CommandSourceStack source = context.getSource(); try { //generate - JsonHelper helper = JsonHelper.getHelper(source.getServer()); + AnimationJsonHelper helper = AnimationJsonHelper.getHelper(source.getServer()); Path path = helper.generateExample(); if(path == null) throw new Exception(); diff --git a/src/main/java/com/linearpast/sccore/animation/command/PlayCommand.java b/src/main/java/com/linearpast/sccore/animation/command/PlayCommand.java index c47e185..c10b7b5 100644 --- a/src/main/java/com/linearpast/sccore/animation/command/PlayCommand.java +++ b/src/main/java/com/linearpast/sccore/animation/command/PlayCommand.java @@ -1,11 +1,15 @@ package com.linearpast.sccore.animation.command; import com.linearpast.sccore.SnowyCrescentCore; +import com.linearpast.sccore.animation.AnimationApi; import com.linearpast.sccore.animation.command.argument.AnimationArgument; import com.linearpast.sccore.animation.command.argument.AnimationLayerArgument; import com.linearpast.sccore.animation.command.exception.ApiBackException; import com.linearpast.sccore.animation.data.AnimationData; -import com.linearpast.sccore.animation.helper.*; +import com.linearpast.sccore.animation.helper.AnimationHelper; +import com.linearpast.sccore.animation.helper.AnimationServiceGetterHelper; +import com.linearpast.sccore.animation.service.IAnimationService; +import com.linearpast.sccore.animation.service.RawAnimationService; import com.linearpast.sccore.animation.utils.ApiBack; import com.linearpast.sccore.core.datagen.ModLang; import com.mojang.brigadier.arguments.BoolArgumentType; @@ -90,7 +94,7 @@ public class PlayCommand { ResourceLocation anim = new ResourceLocation(animString); //play with players - IAnimationHelper helper = HelperGetterFromAnimation.create(anim).getHelper(); + IAnimationService helper = AnimationServiceGetterHelper.create(anim).getService(); if (helper == null) throw new ApiBackException(ApiBack.RESOURCE_NOT_FOUND); AnimationData animationData = helper.getAnimation(anim); if(animationData == null) throw new ApiBackException(ApiBack.RESOURCE_NOT_FOUND); @@ -134,7 +138,7 @@ public class PlayCommand { } else { //play with self ApiBack back; - RawAnimationHelper instance = RawAnimationHelper.INSTANCE; + RawAnimationService instance = RawAnimationService.INSTANCE; if(withRide) back = instance.playAnimationWithRide(player, layer, animationData, false); else back = instance.playAnimation(player, layer, animationData); @@ -166,11 +170,10 @@ public class PlayCommand { ResourceLocation layerLocation = new ResourceLocation(layer); //remove with players - AnimationHelper instance = AnimationHelper.INSTANCE; if(!targets.isEmpty()) { Set playerSet = Set.copyOf(targets); playerSet.forEach(p -> { - ApiBack back = instance.removeAnimation(p, layerLocation); + ApiBack back = AnimationApi.getHelper(p).removeAnimation(layerLocation); if (back == ApiBack.SUCCESS) targets.remove(p); }); int successNum = playerSet.size() - targets.size(); @@ -196,7 +199,7 @@ public class PlayCommand { ).withStyle(ChatFormatting.RED)); } } else { - ApiBack back = instance.removeAnimation(player, layerLocation); + ApiBack back = AnimationApi.getHelper(player).removeAnimation(layerLocation); if (back != ApiBack.SUCCESS) throw new ApiBackException(back); source.sendSuccess(() -> Component.translatable( @@ -221,12 +224,11 @@ public class PlayCommand { Collection players; try {players = EntityArgument.getPlayers(context, "players");} catch (Exception ignored) { players = Set.of(source.getPlayerOrException()); } - Set.copyOf(players).forEach(player -> IHelperGetter.HELPERS.forEach( - helper -> { - helper.clearAnimations(player); - helper.detachAnimation(player); - } - )); + Set.copyOf(players).forEach(player -> { + AnimationHelper helper = AnimationApi.getHelper(player); + helper.clearAnimation(); + helper.detachAnimation(); + }); source.sendSuccess(() -> Component.translatable( ModLang.TranslatableMessage.CLEAR_ANIMATIONS.getKey() ).withStyle(ChatFormatting.GREEN), true); diff --git a/src/main/java/com/linearpast/sccore/animation/command/RequestCommand.java b/src/main/java/com/linearpast/sccore/animation/command/RequestCommand.java index 4bf887a..777bd20 100644 --- a/src/main/java/com/linearpast/sccore/animation/command/RequestCommand.java +++ b/src/main/java/com/linearpast/sccore/animation/command/RequestCommand.java @@ -1,14 +1,10 @@ package com.linearpast.sccore.animation.command; import com.linearpast.sccore.SnowyCrescentCore; +import com.linearpast.sccore.animation.AnimationApi; import com.linearpast.sccore.animation.command.argument.AnimationArgument; import com.linearpast.sccore.animation.command.argument.AnimationLayerArgument; import com.linearpast.sccore.animation.command.exception.ApiBackException; -import com.linearpast.sccore.animation.data.AnimationData; -import com.linearpast.sccore.animation.data.RawAnimationData; -import com.linearpast.sccore.animation.helper.HelperGetterFromAnimation; -import com.linearpast.sccore.animation.helper.IAnimationHelper; -import com.linearpast.sccore.animation.helper.IHelperGetter; import com.linearpast.sccore.animation.utils.ApiBack; import com.linearpast.sccore.core.configs.ModConfigs; import com.linearpast.sccore.core.datagen.ModLang; @@ -63,13 +59,7 @@ public class RequestCommand { ResourceLocation layer = new ResourceLocation(layerString); ResourceLocation anim = new ResourceLocation(animString); - IAnimationHelper helper = HelperGetterFromAnimation.create(anim).getHelper(); - if (helper == null) throw new ApiBackException(ApiBack.RESOURCE_NOT_FOUND); - AnimationData animationData; - if(helper.isAnimationPresent(anim)) animationData = helper.getAnimation(anim); - else animationData = RawAnimationData.create(anim); - - ApiBack back = helper.request(player, target, layer, animationData, withRide); + ApiBack back = AnimationApi.getHelper(player).requestAnimation(target, layer, anim, withRide); if(back == ApiBack.COOLDOWN) { int cooldown = ModConfigs.Server.requestCooldown.get(); throw ApiBackException.withCooldown(cooldown); @@ -111,11 +101,7 @@ public class RequestCommand { ServerPlayer requestor = EntityArgument.getPlayer(context, "requestor"); //play - ApiBack back = ApiBack.RESOURCE_NOT_FOUND; - for (IAnimationHelper helper : IHelperGetter.HELPERS) { - back = helper.acceptRequest(player, requestor); - if(back == ApiBack.SUCCESS) break; - } + ApiBack back = AnimationApi.getHelper(player).acceptRequest(requestor); if(back != ApiBack.SUCCESS) throw new ApiBackException(back); //send message diff --git a/src/main/java/com/linearpast/sccore/animation/command/client/RefreshCommand.java b/src/main/java/com/linearpast/sccore/animation/command/client/RefreshCommand.java index 31ca466..c80e836 100644 --- a/src/main/java/com/linearpast/sccore/animation/command/client/RefreshCommand.java +++ b/src/main/java/com/linearpast/sccore/animation/command/client/RefreshCommand.java @@ -1,7 +1,7 @@ package com.linearpast.sccore.animation.command.client; import com.linearpast.sccore.SnowyCrescentCore; -import com.linearpast.sccore.animation.helper.AnimationHelper; +import com.linearpast.sccore.animation.AnimationApi; import com.linearpast.sccore.core.datagen.ModLang; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.context.CommandContext; @@ -27,7 +27,7 @@ public class RefreshCommand { Minecraft instance = Minecraft.getInstance(); LocalPlayer player = instance.player; if(player == null) throw new RuntimeException(); - AnimationHelper.INSTANCE.refreshAnimation(player); + AnimationApi.getHelper(player).refreshAnimation(); source.sendSuccess(() -> Component.translatable( ModLang.TranslatableMessage.REFRESH_ANIMATIONS.getKey() ).withStyle(ChatFormatting.GREEN), true); diff --git a/src/main/java/com/linearpast/sccore/animation/entity/AnimationRideEntity.java b/src/main/java/com/linearpast/sccore/animation/entity/AnimationRideEntity.java index f8ef8c5..67073c2 100644 --- a/src/main/java/com/linearpast/sccore/animation/entity/AnimationRideEntity.java +++ b/src/main/java/com/linearpast/sccore/animation/entity/AnimationRideEntity.java @@ -2,10 +2,10 @@ package com.linearpast.sccore.animation.entity; import com.linearpast.sccore.animation.capability.AnimationDataCapability; import com.linearpast.sccore.animation.capability.inter.IAnimationCapability; -import com.linearpast.sccore.animation.data.GenericAnimationData; +import com.linearpast.sccore.animation.data.AnimationData; import com.linearpast.sccore.animation.data.Ride; -import com.linearpast.sccore.animation.helper.AnimationHelper; import com.linearpast.sccore.animation.register.AnimationEntities; +import com.linearpast.sccore.animation.service.AnimationService; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.ClientGamePacketListener; @@ -17,6 +17,7 @@ import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; import net.minecraftforge.network.NetworkHooks; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.*; @@ -28,10 +29,10 @@ public class AnimationRideEntity extends Entity { private final Set players = new HashSet<>(); private final Map animationPair = new HashMap<>(); - private GenericAnimationData animation; + private AnimationData animation; private ServerPlayer player; private ResourceLocation layer; - public AnimationRideEntity(ServerPlayer pPlayer, ResourceLocation layer, GenericAnimationData animation) { + public AnimationRideEntity(ServerPlayer pPlayer, ResourceLocation layer, AnimationData animation) { this(pPlayer.level()); this.player = pPlayer; this.layer = layer; @@ -57,7 +58,7 @@ public class AnimationRideEntity extends Entity { return player; } - public GenericAnimationData getAnimation() { + public AnimationData getAnimation() { return animation; } @@ -101,13 +102,13 @@ public class AnimationRideEntity extends Entity { return NetworkHooks.getEntitySpawningPacket(this); } - public static boolean create(ServerPlayer pPlayer, ResourceLocation layer, ResourceLocation animation, boolean force) { - GenericAnimationData anim = AnimationHelper.INSTANCE.getAnimation(animation); - if(anim == null) return false; - if(anim.getRide() == null) return false; + @Nullable + public static AnimationRideEntity create(ServerPlayer pPlayer, ResourceLocation layer, AnimationData anim, boolean force) { + if(anim == null) return null; + if(anim.getRide() == null) return null; IAnimationCapability data = AnimationDataCapability.getCapability(pPlayer).orElse(null); - if(data == null) return false; - data.setRiderAnimation(layer, animation); + if(data == null) return null; + data.setRiderAnimation(layer, anim.getKey()); AnimationRideEntity seat = new AnimationRideEntity(pPlayer, layer, anim); float xRot = anim.getRide().getXRot(); float yRot = anim.getRide().getYRot(); @@ -118,7 +119,7 @@ public class AnimationRideEntity extends Entity { seat.setPos(pos.x, pos.y + 0.35f, pos.z); pPlayer.level().addFreshEntity(seat); pPlayer.startRiding(seat, force); - return true; + return seat; } @Override @@ -163,7 +164,7 @@ public class AnimationRideEntity extends Entity { IAnimationCapability data = AnimationDataCapability.getCapability(serverPlayer).orElse(null); if(data == null) return; data.setRiderAnimation(layer, animLocation); - AnimationHelper.INSTANCE.syncAnimation(serverPlayer, player); + AnimationService.INSTANCE.syncAnimation(serverPlayer, player); players.add(serverPlayer); } } @@ -172,7 +173,7 @@ public class AnimationRideEntity extends Entity { protected void removePassenger(@NotNull Entity entity) { super.removePassenger(entity); if(entity instanceof ServerPlayer serverPlayer) { - AnimationHelper.INSTANCE.removeAnimation(serverPlayer, layer); + AnimationService.INSTANCE.removeAnimation(serverPlayer, layer); players.remove(serverPlayer); new HashMap<>(animationPair).forEach((key, value) -> { if(Objects.equals(value, serverPlayer.getUUID())) { diff --git a/src/main/java/com/linearpast/sccore/animation/entity/RawAnimationRideEntity.java b/src/main/java/com/linearpast/sccore/animation/entity/RawAnimationRideEntity.java deleted file mode 100644 index c8ecc9c..0000000 --- a/src/main/java/com/linearpast/sccore/animation/entity/RawAnimationRideEntity.java +++ /dev/null @@ -1,198 +0,0 @@ -package com.linearpast.sccore.animation.entity; - -import com.linearpast.sccore.animation.capability.RawAnimationDataCapability; -import com.linearpast.sccore.animation.data.RawAnimationData; -import com.linearpast.sccore.animation.data.Ride; -import com.linearpast.sccore.animation.helper.RawAnimationHelper; -import com.linearpast.sccore.animation.register.AnimationEntities; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.protocol.Packet; -import net.minecraft.network.protocol.game.ClientGamePacketListener; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.level.Level; -import net.minecraft.world.phys.Vec3; -import net.minecraftforge.network.NetworkHooks; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.*; - -public class RawAnimationRideEntity extends Entity { - public RawAnimationRideEntity(Level pLevel) { - super(AnimationEntities.RIDE.get(), pLevel); - this.noPhysics = true; - } - - private final Set players = new HashSet<>(); - private final Map animationPair = new HashMap<>(); - private RawAnimationData rawAnimation; - private ServerPlayer player; - private ResourceLocation layer; - public RawAnimationRideEntity(ServerPlayer pPlayer, ResourceLocation layer, RawAnimationData rawAnimation) { - this(pPlayer.level()); - this.player = pPlayer; - this.layer = layer; - this.rawAnimation = rawAnimation; - Ride ride = rawAnimation.getRide(); - if(ride != null) { - List componentAnimations = ride.getComponentAnimations(); - for (ResourceLocation componentAnimation : componentAnimations) { - animationPair.put(componentAnimation, null); - } - } - } - - public ResourceLocation getLayer() { - return layer; - } - - public Set getPlayers() { - return players; - } - - public ServerPlayer getPlayer() { - return player; - } - - public RawAnimationData getAnimation() { - return rawAnimation; - } - - @Override - protected void defineSynchedData() {} - - @Override - protected void readAdditionalSaveData(@NotNull CompoundTag pCompound) {} - - @Override - protected void addAdditionalSaveData(@NotNull CompoundTag pCompound) {} - - @Override - public void tick() { - super.tick(); - if(!this.level().isClientSide) { - Ride ride = rawAnimation == null ? null : rawAnimation.getRide(); - if(!this.getPassengers().contains(player) || (ride != null && ride.getExistTick() > 0 && this.tickCount >= ride.getExistTick())) { - this.remove(RemovalReason.DISCARDED); - } - } - } - - @Override - public double getPassengersRidingOffset() { - return 0.0; - } - - @Override - protected boolean canRide(@NotNull Entity entity) { - return true; - } - - @Override - public boolean shouldRiderSit() { - return false; - } - - @Override - public @NotNull Packet getAddEntityPacket(){ - return NetworkHooks.getEntitySpawningPacket(this); - } - - @Nullable - public static RawAnimationRideEntity create(ServerPlayer pPlayer, ResourceLocation layer, RawAnimationData animation) { - if(animation.getRide() == null) return null; - RawAnimationDataCapability data = RawAnimationDataCapability.getCapability(pPlayer).orElse(null); - if(data == null) return null; - data.setRiderAnimation(layer, animation.getKey()); - RawAnimationRideEntity seat = new RawAnimationRideEntity(pPlayer, layer, animation); - float xRot = animation.getRide().getXRot(); - float yRot = animation.getRide().getYRot(); - if(xRot == 0 && yRot == 0) seat.setRot(pPlayer.getXRot(), pPlayer.getYRot()); - else seat.setRot(yRot, xRot); - Vec3 pos = pPlayer.position(); - pos.add(animation.getRide().getOffset()); - seat.setPos(pos.x, pos.y + 0.35f, pos.z); - pPlayer.level().addFreshEntity(seat); - pPlayer.startRiding(seat, false); - return seat; - } - - @Override - protected void positionRider(@NotNull Entity pPassenger, @NotNull MoveFunction pCallback) { - super.positionRider(pPassenger, pCallback); - pPassenger.setYBodyRot(this.getYRot()); - } - - @Override - public void onPassengerTurned(@NotNull Entity pEntityToUpdate) { - pEntityToUpdate.setYBodyRot(this.getYRot()); - } - - @Override - public @NotNull Vec3 getDismountLocationForPassenger(@NotNull LivingEntity entity) { - Ride ride = rawAnimation.getRide(); - if(ride != null) { - Vec3 position = entity.position(); - return position.subtract(ride.getOffset()); - } - return entity.position(); - } - - @Override - protected void addPassenger(@NotNull Entity entity) { - int passengerNum = getPassengers().size(); - super.addPassenger(entity); - if(passengerNum == 0) return; - if(entity instanceof ServerPlayer serverPlayer) { - Ride ride = rawAnimation.getRide(); - if(ride == null) return; - List componentAnimations = ride.getComponentAnimations(); - if(componentAnimations.isEmpty()) return; - if(passengerNum > componentAnimations.size()) return; - ResourceLocation animLocation = null; - for (ResourceLocation location : animationPair.keySet()) { - if(animationPair.get(location) == null) - animLocation = location; - } - if(animLocation == null) return; - animationPair.put(animLocation, serverPlayer.getUUID()); - RawAnimationDataCapability data = RawAnimationDataCapability.getCapability(serverPlayer).orElse(null); - if(data == null) return; - data.setRiderAnimation(layer, animLocation); - RawAnimationHelper.INSTANCE.syncAnimation(serverPlayer, player); - players.add(serverPlayer); - } - } - - @Override - protected void removePassenger(@NotNull Entity entity) { - super.removePassenger(entity); - if(entity instanceof ServerPlayer serverPlayer) { - RawAnimationHelper.INSTANCE.removeAnimation(serverPlayer, layer); - players.remove(serverPlayer); - new HashMap<>(animationPair).forEach((key, value) -> { - if(Objects.equals(value, serverPlayer.getUUID())) { - animationPair.put(key, null); - } - }); - RawAnimationDataCapability.getCapability(serverPlayer).ifPresent( - RawAnimationDataCapability::removeRiderAnimation - ); - } - } - - @Override - public boolean canAddPassenger(@NotNull Entity pPassenger) { - if(!(pPassenger instanceof ServerPlayer)) return false; - int size = players.size(); - Ride ride = rawAnimation.getRide(); - if(ride == null) return false; - int maxSize = ride.getComponentAnimations().size(); - boolean flag1 = size < maxSize; - boolean flag2 = !(pPassenger.getVehicle() instanceof AnimationRideEntity); - return flag1 && flag2; - } -} diff --git a/src/main/java/com/linearpast/sccore/animation/event/PlayerTickEvent.java b/src/main/java/com/linearpast/sccore/animation/event/PlayerTickEvent.java index 0cb1488..315b9b5 100644 --- a/src/main/java/com/linearpast/sccore/animation/event/PlayerTickEvent.java +++ b/src/main/java/com/linearpast/sccore/animation/event/PlayerTickEvent.java @@ -1,9 +1,7 @@ package com.linearpast.sccore.animation.event; import com.linearpast.sccore.animation.capability.AnimationDataCapability; -import com.linearpast.sccore.animation.capability.RawAnimationDataCapability; import com.linearpast.sccore.animation.entity.AnimationRideEntity; -import com.linearpast.sccore.animation.entity.RawAnimationRideEntity; import net.minecraft.world.entity.player.Player; import net.minecraftforge.event.TickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; @@ -21,13 +19,6 @@ public class PlayerTickEvent { } }); } - if(!(player.getVehicle() instanceof RawAnimationRideEntity)){ - RawAnimationDataCapability.getCapability(player).ifPresent(capability -> { - if(capability.getRiderAnimLayer() != null) { - capability.removeRiderAnimation(); - } - }); - } } } } diff --git a/src/main/java/com/linearpast/sccore/animation/event/client/CameraAnglesModify.java b/src/main/java/com/linearpast/sccore/animation/event/client/CameraAnglesModify.java index b982fe1..3072dc6 100644 --- a/src/main/java/com/linearpast/sccore/animation/event/client/CameraAnglesModify.java +++ b/src/main/java/com/linearpast/sccore/animation/event/client/CameraAnglesModify.java @@ -3,7 +3,7 @@ package com.linearpast.sccore.animation.event.client; import com.linearpast.sccore.animation.capability.AnimationDataCapability; import com.linearpast.sccore.animation.capability.inter.IAnimationCapability; import com.linearpast.sccore.animation.data.GenericAnimationData; -import com.linearpast.sccore.animation.helper.AnimationHelper; +import com.linearpast.sccore.animation.service.AnimationService; import dev.kosmx.playerAnim.core.util.MathHelper; import net.minecraft.client.Minecraft; import net.minecraft.client.player.LocalPlayer; @@ -35,7 +35,7 @@ public class CameraAnglesModify { GenericAnimationData animation = null; try { animation = data.getAnimations().values().stream() - .map(AnimationHelper.INSTANCE::getAnimation) + .map(AnimationService.INSTANCE::getAnimation) .min(Comparator.comparingDouble(anim -> { if (anim == null) return 1.0f; return anim.getHeightModifier(); diff --git a/src/main/java/com/linearpast/sccore/animation/event/client/ClientPlayerEvent.java b/src/main/java/com/linearpast/sccore/animation/event/client/ClientPlayerEvent.java index cd40d3b..38341b0 100644 --- a/src/main/java/com/linearpast/sccore/animation/event/client/ClientPlayerEvent.java +++ b/src/main/java/com/linearpast/sccore/animation/event/client/ClientPlayerEvent.java @@ -1,6 +1,6 @@ package com.linearpast.sccore.animation.event.client; -import com.linearpast.sccore.animation.helper.AnimationHelper; +import com.linearpast.sccore.animation.service.AnimationService; import net.minecraft.client.player.AbstractClientPlayer; import net.minecraft.world.entity.player.Player; import net.minecraftforge.api.distmarker.Dist; @@ -19,7 +19,7 @@ public class ClientPlayerEvent { Player player = event.player; if(player.tickCount % 10 != 0) return; if (!(player instanceof AbstractClientPlayer clientPlayer)) return; - AnimationHelper.INSTANCE.refreshAnimation(clientPlayer); + AnimationService.INSTANCE.refreshAnimation(clientPlayer); } } diff --git a/src/main/java/com/linearpast/sccore/animation/helper/AnimationDataHelper.java b/src/main/java/com/linearpast/sccore/animation/helper/AnimationDataHelper.java new file mode 100644 index 0000000..a131a8a --- /dev/null +++ b/src/main/java/com/linearpast/sccore/animation/helper/AnimationDataHelper.java @@ -0,0 +1,66 @@ +package com.linearpast.sccore.animation.helper; + +import com.linearpast.sccore.animation.AnimationApi; +import com.linearpast.sccore.animation.data.AnimationData; +import com.linearpast.sccore.animation.register.AnimationRegistry; +import com.linearpast.sccore.animation.register.RawAnimationRegistry; +import com.linearpast.sccore.animation.service.IAnimationService; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; +import net.minecraftforge.fml.DistExecutor; +import org.jetbrains.annotations.Nullable; + +import java.util.HashSet; +import java.util.Set; + +public class AnimationDataHelper { + AnimationDataHelper() {} + public static AnimationDataHelper getHelper() { + return new AnimationDataHelper(); + } + + public Set getAllAnimations() { + Set set = new HashSet<>(getAnimationNames()); + Set strings = DistExecutor.unsafeCallWhenOn(Dist.CLIENT, + () -> this::getAnimationsClient); + if (strings != null && !strings.isEmpty()) set.addAll(strings); + return set; + } + + @OnlyIn(Dist.CLIENT) + private Set getAnimationsClient() { + return new HashSet<>(RawAnimationRegistry.getAnimations().keySet()); + } + + private Set getAnimationNames(){ + return new HashSet<>(AnimationRegistry.getAnimations().keySet()); + } + + public Set getLayers() { + return new HashSet<>(AnimationRegistry.getLayers().keySet()); + } + + public boolean isLayerPresent(ResourceLocation location) { + return getLayers().contains(location); + } + + public boolean isAnimationPresent(ResourceLocation location) { + return getAllAnimations().contains(location); + } + + public @Nullable AnimationData getAnimationData(ResourceLocation location) { + IAnimationService helper = AnimationApi.getServiceGetterHelper(location).getService(); + if(helper == null) return null; + return helper.getAnimation(location); + } + + public AnimationData getDataByCompoundTag(CompoundTag tag) { + AnimationData animationData = new AnimationData(); + animationData.deserializeNBT(tag); + IAnimationService service = AnimationApi.getServiceGetterHelper(animationData.getKey()).getService(); + if(service == null) return animationData; + return service.getAnimation(tag); + } +} diff --git a/src/main/java/com/linearpast/sccore/animation/helper/AnimationHelper.java b/src/main/java/com/linearpast/sccore/animation/helper/AnimationHelper.java index 17d5ebf..581ecba 100644 --- a/src/main/java/com/linearpast/sccore/animation/helper/AnimationHelper.java +++ b/src/main/java/com/linearpast/sccore/animation/helper/AnimationHelper.java @@ -1,211 +1,253 @@ package com.linearpast.sccore.animation.helper; -import com.linearpast.sccore.animation.capability.AnimationDataCapability; -import com.linearpast.sccore.animation.capability.inter.IAnimationCapability; +import com.linearpast.sccore.animation.AnimationApi; import com.linearpast.sccore.animation.data.AnimationData; -import com.linearpast.sccore.animation.data.GenericAnimationData; -import com.linearpast.sccore.animation.entity.AnimationRideEntity; -import com.linearpast.sccore.animation.register.AnimationRegistry; -import com.linearpast.sccore.animation.utils.AnimationUtils; +import com.linearpast.sccore.animation.service.IAnimationService; import com.linearpast.sccore.animation.utils.ApiBack; +import com.linearpast.sccore.core.IModLazyRun; +import net.minecraft.client.Minecraft; +import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.player.AbstractClientPlayer; -import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.common.util.FakePlayer; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.HashSet; -import java.util.Optional; -import java.util.Set; +import java.util.Collection; +import java.util.List; +import java.util.Objects; +import java.util.UUID; -/** - * Animation Util. May be you can call it Api. - */ -public class AnimationHelper implements IAnimationHelper { - public static final AnimationHelper INSTANCE = new AnimationHelper(); - - /** - * Get the LyingType when there are animations which playing on player.
- * And It will return the first which be found. - * @param player Target player - * @return The first LyingType it find. - */ - @Nullable - public GenericAnimationData.LyingType getSideView(Player player) { - return ANIMATION_RUNNER.testLoadedAndCall(() -> { - IAnimationCapability data = AnimationDataCapability.getCapability(player).orElse(null); - if(data == null) return null; - GenericAnimationData.LyingType lyingType = null; - for (ResourceLocation value : data.getAnimations().values()) { - GenericAnimationData animation = getAnimation(value); - if(animation == null) return null; - GenericAnimationData.LyingType type = animation.getLyingType(); - if(type == null) continue; - switch (type) { - case FRONT,BACK -> {} - case LEFT,RIGHT -> lyingType = animation.getLyingType(); - } - } - return lyingType; - }); +public class AnimationHelper { + private final Player player; + private final AnimationLazyHelper lazyRun; + AnimationHelper(Player player) { + this.player = player; + this.lazyRun = new AnimationLazyHelper(player); } - /** - * Get the HeightModifier when there are animations which playing on player.
- * And It will return the first which be found. - * @param player Target player - * @return The first HeightModifier it find. - */ - public float getHeightModifier(Player player) { - Float result = ANIMATION_RUNNER.testLoadedAndCall(() -> { - IAnimationCapability data = AnimationDataCapability.getCapability(player).orElse(null); - if (data == null) return 1.0f; - float heightModifier = 1.0f; - for (ResourceLocation value : data.getAnimations().values()) { - GenericAnimationData animation = getAnimation(value); - if (animation == null) continue; - float animationHeightModifier = animation.getHeightModifier(); - heightModifier = Math.min(heightModifier, animationHeightModifier); - } - return heightModifier; - }); - return result == null ? 1.0f : result; + public static AnimationHelper getHelper(Player player) { + return new AnimationHelper(player); } - - @Override - public @Nullable GenericAnimationData getAnimation(ResourceLocation location) { - return AnimationRegistry.getAnimations().getOrDefault(location, null); + public ApiBack playAnimation(ResourceLocation layer, ResourceLocation location) { + IAnimationService service = AnimationApi.getServiceGetterHelper(location).getService(); + if(service == null) return ApiBack.FAIL; + AnimationData data = service.getAnimation(location); + if(data == null) return ApiBack.FAIL; + return lazyRun.testLoadedAndCall( + () -> service.playAnimation(lazyRun.getServerPlayer(), layer, data), + () -> service.playAnimation(lazyRun.getClientPlayer(), layer, location) + ); } - @Override - public @Nullable GenericAnimationData getAnimation(CompoundTag tag) { - return new GenericAnimationData(){{deserializeNBT(tag);}}; + public ApiBack playAnimationWithRide(ResourceLocation layer, AnimationData animation, boolean isForce) { + IAnimationService service = AnimationApi.getServiceGetterHelper(animation.getKey()).getService(); + if(service == null) return ApiBack.FAIL; + return lazyRun.testLoadedAndCall( + () -> service.playAnimationWithRide(lazyRun.getServerPlayer(), layer, animation, isForce), + () -> service.playAnimationWithRide(lazyRun.getClientPlayer(), layer, animation.getKey(), isForce) + ); } - @Override - public @Nullable IAnimationCapability getCapability(Player player) { - return AnimationDataCapability.getCapability(player).orElse(null); + public void clearAnimation() { + for (IAnimationService service : AnimationApi.getServiceGetterHelper().getAllServices()) { + lazyRun.testLoadedAndRun( + () -> service.clearAnimations(lazyRun.getServerPlayer()), + () -> service.clearAnimations(lazyRun.getClientPlayer()) + ); + } } - @Override - public void clearAnimations(ServerPlayer serverPlayer) { - ANIMATION_RUNNER.testLoadedAndRun(() -> { - Optional.ofNullable(getCapability(serverPlayer)).ifPresent(IAnimationCapability::clearAnimations); - detachAnimation(serverPlayer); - }); + public ApiBack detachAnimation() { + ApiBack result = ApiBack.FAIL; + for (IAnimationService service : AnimationApi.getServiceGetterHelper().getAllServices()) { + ApiBack back = lazyRun.testLoadedAndCall(() -> service.detachAnimation(lazyRun.getServerPlayer())); + if(back == ApiBack.SUCCESS) return back; + else result = back; + } + return result; } - @Override - public boolean isAnimationPresent(ResourceLocation location) { - return ANIMATION_RUNNER.testLoadedAndCall(() -> AnimationRegistry.getAnimations().containsKey(location)); + public ApiBack joinAnimation(Player target, boolean force) { + ApiBack result = ApiBack.FAIL; + for (IAnimationService service : AnimationApi.getServiceGetterHelper().getAllServices()) { + ApiBack apiBack = lazyRun.testLoadedAndCall(() -> { + if(!(target instanceof ServerPlayer targetPlayer)) return ApiBack.UNSUPPORTED; + return service.joinAnimation(lazyRun.getServerPlayer(), targetPlayer, force); + }); + if(apiBack == ApiBack.SUCCESS) return apiBack; + else result = apiBack; + } + return result; } - @Override - public ApiBack detachAnimation(ServerPlayer player) { - return ANIMATION_RUNNER.testLoadedAndCall(() -> { - if(player.getVehicle() instanceof AnimationRideEntity) { - player.stopRiding(); + public ApiBack syncToAnimation(Player target) { + ApiBack result = ApiBack.FAIL; + for (IAnimationService service : AnimationApi.getServiceGetterHelper().getAllServices()) { + ApiBack apiBack = lazyRun.testLoadedAndCall(() -> { + if(!(target instanceof ServerPlayer targetPlayer)) return ApiBack.UNSUPPORTED; + service.syncAnimation(lazyRun.getServerPlayer(), targetPlayer); return ApiBack.SUCCESS; - } - return ApiBack.UNSUPPORTED; - }); + }, () -> { + if(!(target instanceof AbstractClientPlayer targetPlayer)) return ApiBack.UNSUPPORTED; + service.syncAnimation(lazyRun.getClientPlayer(), targetPlayer); + return ApiBack.SUCCESS; + }); + if(apiBack == ApiBack.SUCCESS) return apiBack; + else result = apiBack; + } + return result; } - @Override - public ApiBack joinAnimationServer(ServerPlayer player, ServerPlayer target, boolean force) { - return ANIMATION_RUNNER.testLoadedAndCall(() -> { - Entity vehicle = target.getVehicle(); - if(vehicle instanceof AnimationRideEntity) { - boolean result = player.startRiding(vehicle, force); - return result ? ApiBack.SUCCESS : ApiBack.FAIL; - } - return ApiBack.UNSUPPORTED; - }); - } - - @Override @OnlyIn(Dist.CLIENT) - public void refreshAnimation(AbstractClientPlayer clientPlayer) { - ANIMATION_RUNNER.testLoadedAndRun(() -> { - IAnimationCapability data = getCapability(clientPlayer); - if(data == null) return; - Set oldLayers = new HashSet<>(data.getAnimations().keySet()); - for (ResourceLocation layer : Set.copyOf(oldLayers)) { - if (AnimationUtils.isClientAnimationStop(clientPlayer, layer)) { - removeAnimation(clientPlayer, layer); + public void refreshAnimation() { + for (IAnimationService service : AnimationApi.getServiceGetterHelper().getAllServices()) { + service.refreshAnimation(lazyRun.getClientPlayer()); + } + } + + @OnlyIn(Dist.CLIENT) + public void refreshAnimationUnsafe() { + for (IAnimationService service : AnimationApi.getServiceGetterHelper().getAllServices()) { + service.refreshAnimationUnsafe(lazyRun.getClientPlayer()); + } + } + + @Nullable + public ResourceLocation getAnimationPlaying(@Nullable ResourceLocation layer) { + for (IAnimationService service : AnimationApi.getServiceGetterHelper().getAllServices()) { + ResourceLocation playing = service.getAnimationPlaying(player, layer); + if(playing != null) return playing; + } + return null; + } + + public ApiBack removeAnimation(ResourceLocation layer) { + ApiBack result = ApiBack.FAIL; + for (IAnimationService service : AnimationApi.getServiceGetterHelper().getAllServices()) { + ApiBack apiBack = lazyRun.testLoadedAndCall( + () -> service.removeAnimation(lazyRun.getServerPlayer(), layer), + () -> service.removeAnimation(lazyRun.getClientPlayer(), layer) + ); + if(apiBack == ApiBack.SUCCESS) return apiBack; + else result = apiBack; + } + return result; + } + + public ApiBack inviteAnimation(ResourceLocation layer, ResourceLocation location, Collection targets) { + IAnimationService service = AnimationApi.getServiceGetterHelper(location).getService(); + if(service == null) return ApiBack.FAIL; + return lazyRun.testLoadedAndCall( + () -> { + AnimationData data = service.getAnimation(location); + if(data == null) return ApiBack.FAIL; + return service.invite(lazyRun.getServerPlayer(), layer, data, targets); + }, + () -> { + ClientLevel level = Minecraft.getInstance().level; + if(level == null) return ApiBack.FAIL; + List list = targets.stream().map(level::getPlayerByUUID) + .filter(Objects::nonNull).map(AbstractClientPlayer.class::cast).toList(); + if(list.isEmpty()) return ApiBack.FAIL; + return service.invite(layer, location, list.toArray(new AbstractClientPlayer[]{})); } - } - }); + ); } - @Override - public @Nullable ResourceLocation getAnimationPlaying(Player player, @Nullable ResourceLocation layer) { - return ANIMATION_RUNNER.testLoadedAndCall(() -> { - IAnimationCapability data = getCapability(player); - if(data == null) return null; - if(layer == null){ - for (ResourceLocation value : data.getAnimations().values()) { - if(value != null) return value; + public ApiBack applyAnimation(Player target) { + ApiBack result = ApiBack.FAIL; + for (IAnimationService service : AnimationApi.getServiceGetterHelper().getAllServices()) { + ApiBack apiBack = lazyRun.testLoadedAndCall(() -> { + if(!(target instanceof ServerPlayer targetPlayer)) return ApiBack.UNSUPPORTED; + return service.apply(lazyRun.getServerPlayer(), targetPlayer); + }, () -> { + if(!(target instanceof AbstractClientPlayer targetPlayer)) return ApiBack.UNSUPPORTED; + return service.apply(targetPlayer); + }); + if(apiBack == ApiBack.SUCCESS) return apiBack; + else result = apiBack; + } + return result; + } + + public ApiBack requestAnimation(Player target, ResourceLocation layer, ResourceLocation location, boolean isRide) { + IAnimationService service = AnimationApi.getServiceGetterHelper(location).getService(); + if(service == null) return ApiBack.FAIL; + return lazyRun.testLoadedAndCall( + () -> { + AnimationData data = service.getAnimation(location); + if(data == null) return ApiBack.FAIL; + if(!(target instanceof ServerPlayer targetPlayer)) return ApiBack.UNSUPPORTED; + return service.request(lazyRun.getServerPlayer(), targetPlayer, layer, data, isRide); + }, + () -> { + if(!(target instanceof AbstractClientPlayer targetPlayer)) return ApiBack.UNSUPPORTED; + return service.request(targetPlayer, layer, location); } - } else if (isAnimationLayerPresent(layer)) { - if(data.isAnimationPresent(layer)){ - return data.getAnimation(layer); - } - } - return null; - }); + ); } - @Override - public ApiBack removeAnimation(@NotNull ServerPlayer serverPlayer, ResourceLocation layer) { - boolean result = ANIMATION_RUNNER.testLoadedAndCall(() -> Optional.ofNullable(getCapability(serverPlayer)) - .map(data -> data.removeAnimation(layer)).orElse(false)); - return result ? ApiBack.SUCCESS : ApiBack.FAIL; + public ApiBack acceptInvite(Player inviter) { + ApiBack result = ApiBack.FAIL; + for (IAnimationService service : AnimationApi.getServiceGetterHelper().getAllServices()) { + ApiBack apiBack = lazyRun.testLoadedAndCall(() -> { + if(!(inviter instanceof ServerPlayer inviterPlayer)) return ApiBack.UNSUPPORTED; + return service.acceptInvite(lazyRun.getServerPlayer(), inviterPlayer); + }); + if(apiBack == ApiBack.SUCCESS) return apiBack; + else result = apiBack; + } + return result; } - @Override - public ApiBack playAnimationWithRide(@NotNull ServerPlayer player, ResourceLocation layer, AnimationData animation, boolean force) { - return ANIMATION_RUNNER.testLoadedAndCall(() -> { - ResourceLocation key = animation.getKey(); - if(!isAnimationLayerPresent(layer) || !isAnimationPresent(key)) - return ApiBack.RESOURCE_NOT_FOUND; - if(animation.getRide() == null) - return ApiBack.RESOURCE_NOT_FOUND; - if(player instanceof FakePlayer) - return ApiBack.UNSUPPORTED; - boolean flag = player.getVehicle() != null; - if(flag && force) player.unRide(); - else if(flag) return ApiBack.UNSUPPORTED; - boolean result = AnimationRideEntity.create(player, layer, key, force); - return result ? ApiBack.SUCCESS : ApiBack.FAIL; - }); + public ApiBack acceptApply(Player applier) { + ApiBack result = ApiBack.FAIL; + for (IAnimationService service : AnimationApi.getServiceGetterHelper().getAllServices()) { + ApiBack apiBack = lazyRun.testLoadedAndCall(() -> { + if(!(applier instanceof ServerPlayer applierPlayer)) return ApiBack.UNSUPPORTED; + return service.acceptApply(lazyRun.getServerPlayer(), applierPlayer); + }); + if(apiBack == ApiBack.SUCCESS) return apiBack; + else result = apiBack; + } + return result; } - @Override - public ApiBack playAnimationServer(@NotNull ServerPlayer player, ResourceLocation layer, AnimationData animation) { - return ANIMATION_RUNNER.testLoadedAndCall(() -> { - ResourceLocation key = animation.getKey(); - if(!isAnimationLayerPresent(layer) || !isAnimationPresent(key)) - return ApiBack.RESOURCE_NOT_FOUND; - if(player instanceof FakePlayer) - return ApiBack.UNSUPPORTED; - Boolean flag = Optional.ofNullable(getCapability(player)).map(data -> - data.mergeAnimation(layer, key)).orElse(false); - return flag ? ApiBack.SUCCESS : ApiBack.FAIL; - }); + public ApiBack acceptRequest(Player requestor) { + ApiBack result = ApiBack.FAIL; + for (IAnimationService service : AnimationApi.getServiceGetterHelper().getAllServices()) { + ApiBack apiBack = lazyRun.testLoadedAndCall(() -> { + if(!(requestor instanceof ServerPlayer requestorPlayer)) return ApiBack.UNSUPPORTED; + return service.acceptRequest(lazyRun.getServerPlayer(), requestorPlayer); + }); + if(apiBack == ApiBack.SUCCESS) return apiBack; + else result = apiBack; + } + return result; } - public ApiBack playAnimation(@NotNull ServerPlayer player, ResourceLocation layer, ResourceLocation animation) { - return playAnimation(player, layer, getAnimation(animation)); - } - public ApiBack playAnimationWithRide(@NotNull ServerPlayer player, ResourceLocation layer, ResourceLocation animation, boolean force) { - return playAnimationWithRide(player, layer, getAnimation(animation), force); + static class AnimationLazyHelper implements IModLazyRun { + private final Player player; + AnimationLazyHelper(Player player) { + this.player = player; + } + + @Override + public boolean testCondition() { + return player instanceof ServerPlayer; + } + + public ServerPlayer getServerPlayer() { + return (ServerPlayer) player; + } + + @OnlyIn(Dist.CLIENT) + public AbstractClientPlayer getClientPlayer() { + return (AbstractClientPlayer) player; + } } } diff --git a/src/main/java/com/linearpast/sccore/animation/helper/JsonHelper.java b/src/main/java/com/linearpast/sccore/animation/helper/AnimationJsonHelper.java similarity index 93% rename from src/main/java/com/linearpast/sccore/animation/helper/JsonHelper.java rename to src/main/java/com/linearpast/sccore/animation/helper/AnimationJsonHelper.java index cc14b87..b376391 100644 --- a/src/main/java/com/linearpast/sccore/animation/helper/JsonHelper.java +++ b/src/main/java/com/linearpast/sccore/animation/helper/AnimationJsonHelper.java @@ -13,14 +13,14 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.Comparator; -public class JsonHelper { +public class AnimationJsonHelper { private final MinecraftServer server; - JsonHelper(MinecraftServer server) { + AnimationJsonHelper(MinecraftServer server) { this.server = server; } - public static JsonHelper getHelper(MinecraftServer server) { - return new JsonHelper(server); + public static AnimationJsonHelper getHelper(MinecraftServer server) { + return new AnimationJsonHelper(server); } /** diff --git a/src/main/java/com/linearpast/sccore/animation/helper/AnimationServiceGetterHelper.java b/src/main/java/com/linearpast/sccore/animation/helper/AnimationServiceGetterHelper.java new file mode 100644 index 0000000..82c4b87 --- /dev/null +++ b/src/main/java/com/linearpast/sccore/animation/helper/AnimationServiceGetterHelper.java @@ -0,0 +1,58 @@ +package com.linearpast.sccore.animation.helper; + +import com.linearpast.sccore.animation.data.AnimationData; +import com.linearpast.sccore.animation.service.IAnimationService; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Optional; +import java.util.Set; + +public class AnimationServiceGetterHelper implements IAnimationServiceGetter { + private final @Nullable ResourceLocation location; + private final @Nullable CompoundTag tag; + + public AnimationServiceGetterHelper(@NotNull ResourceLocation location) { + this.location = location; + this.tag = null; + } + + public AnimationServiceGetterHelper(@NotNull CompoundTag tag) { + this.tag = tag; + this.location = null; + } + + public AnimationServiceGetterHelper(){ + this.tag = null; + this.location = null; + } + + public static IAnimationServiceGetter create(ResourceLocation location) { + return new AnimationServiceGetterHelper(location); + } + + @Override + public boolean filter(IAnimationService helper) { + if(location != null && helper.isAnimationPresent(location)) return true; + return Optional.ofNullable(tag).map(helper::getAnimation).map(AnimationData::getKey) + .map(helper::isAnimationPresent).isPresent(); + } + + @Override + public @Nullable IAnimationService getService() { + return IAnimationServiceGetter.super.getService(); + } + + public Set> getAllServices() { + return IAnimationServiceGetter.HELPERS; + } + + @Nullable + public > T getService(Class tClass) { + IAnimationService service = getService(); + if(tClass.isInstance(service)) return tClass.cast(service); + return null; + } +} diff --git a/src/main/java/com/linearpast/sccore/animation/helper/HelperGetterFromAnimation.java b/src/main/java/com/linearpast/sccore/animation/helper/HelperGetterFromAnimation.java deleted file mode 100644 index 75cedfa..0000000 --- a/src/main/java/com/linearpast/sccore/animation/helper/HelperGetterFromAnimation.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.linearpast.sccore.animation.helper; - -import net.minecraft.resources.ResourceLocation; - -public class HelperGetterFromAnimation implements IHelperGetter { - private final ResourceLocation location; - - public HelperGetterFromAnimation(ResourceLocation location) { - this.location = location; - } - - public static IHelperGetter create(ResourceLocation location) { - return new HelperGetterFromAnimation(location); - } - - @Override - public boolean filter(IAnimationHelper helper) { - return helper.isAnimationPresent(location); - } -} diff --git a/src/main/java/com/linearpast/sccore/animation/helper/IAnimationServiceGetter.java b/src/main/java/com/linearpast/sccore/animation/helper/IAnimationServiceGetter.java new file mode 100644 index 0000000..333a8a9 --- /dev/null +++ b/src/main/java/com/linearpast/sccore/animation/helper/IAnimationServiceGetter.java @@ -0,0 +1,34 @@ +package com.linearpast.sccore.animation.helper; + +import com.linearpast.sccore.animation.service.AnimationService; +import com.linearpast.sccore.animation.service.IAnimationService; +import com.linearpast.sccore.animation.service.RawAnimationService; +import org.jetbrains.annotations.Nullable; + +import java.util.LinkedHashSet; +import java.util.Set; + +public interface IAnimationServiceGetter { + /** + * Get helper + */ + Set> HELPERS = new LinkedHashSet<>(){{ + add(AnimationService.INSTANCE); + add(RawAnimationService.INSTANCE); + }}; + + /** + * @see IAnimationServiceGetter#filter + */ + @Nullable + default IAnimationService getService() { + for (IAnimationService helper : HELPERS) { + if (filter(helper)) { + return helper; + } + } + return null; + } + + boolean filter(IAnimationService helper); +} diff --git a/src/main/java/com/linearpast/sccore/animation/helper/IHelperGetter.java b/src/main/java/com/linearpast/sccore/animation/helper/IHelperGetter.java deleted file mode 100644 index cc5f487..0000000 --- a/src/main/java/com/linearpast/sccore/animation/helper/IHelperGetter.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.linearpast.sccore.animation.helper; - -import org.jetbrains.annotations.Nullable; - -import java.util.LinkedHashSet; -import java.util.Set; - -public interface IHelperGetter { - /** - * Get helper - */ - Set> HELPERS = new LinkedHashSet<>(){{ - add(AnimationHelper.INSTANCE); - add(RawAnimationHelper.INSTANCE); - }}; - - /** - * @see IHelperGetter#filter - */ - @Nullable - default IAnimationHelper getHelper() { - for (IAnimationHelper helper : HELPERS) { - if (filter(helper)) { - return helper; - } - } - return null; - } - - boolean filter(IAnimationHelper helper); -} diff --git a/src/main/java/com/linearpast/sccore/animation/network/HelperGetterPacket.java b/src/main/java/com/linearpast/sccore/animation/network/ServiceGetterPacket.java similarity index 51% rename from src/main/java/com/linearpast/sccore/animation/network/HelperGetterPacket.java rename to src/main/java/com/linearpast/sccore/animation/network/ServiceGetterPacket.java index 0e4619e..19b969f 100644 --- a/src/main/java/com/linearpast/sccore/animation/network/HelperGetterPacket.java +++ b/src/main/java/com/linearpast/sccore/animation/network/ServiceGetterPacket.java @@ -1,26 +1,26 @@ package com.linearpast.sccore.animation.network; -import com.linearpast.sccore.animation.helper.AnimationHelper; -import com.linearpast.sccore.animation.helper.IAnimationHelper; -import com.linearpast.sccore.animation.helper.IHelperGetter; -import com.linearpast.sccore.animation.helper.RawAnimationHelper; +import com.linearpast.sccore.animation.helper.IAnimationServiceGetter; +import com.linearpast.sccore.animation.service.AnimationService; +import com.linearpast.sccore.animation.service.IAnimationService; +import com.linearpast.sccore.animation.service.RawAnimationService; import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.Nullable; -public abstract class HelperGetterPacket implements IHelperGetter { +public abstract class ServiceGetterPacket implements IAnimationServiceGetter { /** * Override it to filter helper in network packet * @param helper helper * @return Is right helper */ - public boolean filter(IAnimationHelper helper) { - if(helper instanceof AnimationHelper animationHelper) { + public boolean filter(IAnimationService helper) { + if(helper instanceof AnimationService service) { ResourceLocation animation = getAnimation(); - if(animation != null) return animationHelper.isAnimationPresent(animation); - } else if (helper instanceof RawAnimationHelper rawHelper) { + if(animation != null) return service.isAnimationPresent(animation); + } else if (helper instanceof RawAnimationService service) { CompoundTag tag = getAnimationTag(); - if(tag != null) return rawHelper.getAnimation(tag) != null; + if(tag != null) return service.getAnimation(tag) != null; } return false; } @@ -28,7 +28,7 @@ public abstract class HelperGetterPacket implements IHelperGetter { /** * Selectable to override it * @return Animation loacation - * @see HelperGetterPacket#filter + * @see ServiceGetterPacket#filter */ @Nullable protected ResourceLocation getAnimation() { @@ -38,7 +38,7 @@ public abstract class HelperGetterPacket implements IHelperGetter { /** * Selectable to override it * @return Animation data - * @see HelperGetterPacket#filter + * @see ServiceGetterPacket#filter */ @Nullable protected CompoundTag getAnimationTag() { diff --git a/src/main/java/com/linearpast/sccore/animation/network/toclient/RawAnimationCapabilityPacket.java b/src/main/java/com/linearpast/sccore/animation/network/toclient/RawAnimationCapabilityPacket.java index 0a75e1f..de7364e 100644 --- a/src/main/java/com/linearpast/sccore/animation/network/toclient/RawAnimationCapabilityPacket.java +++ b/src/main/java/com/linearpast/sccore/animation/network/toclient/RawAnimationCapabilityPacket.java @@ -45,16 +45,6 @@ public class RawAnimationCapabilityPacket extends SimpleCapabilityPacket private void testPlayAnimations(AbstractClientPlayer player, CompoundTag tag, RawAnimationDataCapability data) { if(data == null) return; - ResourceLocation oldRiderAnimLayer = data.getRiderAnimLayer(); - String riderAnimLayerString = tag.getString(RawAnimationDataCapability.RideAnimLayer); - ResourceLocation newRiderAnimLayer = riderAnimLayerString.isEmpty() ? null : new ResourceLocation(riderAnimLayerString); - if(!Objects.equals(oldRiderAnimLayer, newRiderAnimLayer)) { - String riderAnimationString = tag.getString(RawAnimationDataCapability.RideAnimation); - ResourceLocation newRiderAnimation = riderAnimationString.isEmpty() ? null : new ResourceLocation(riderAnimationString); - if(oldRiderAnimLayer != null) AnimationUtils.playAnimation(player, oldRiderAnimLayer, null); - if(newRiderAnimLayer != null) AnimationUtils.playAnimation(player, newRiderAnimLayer, newRiderAnimation); - } - Set oldLayerSet = new HashSet<>(data.getAnimations().keySet()); CompoundTag animMap = tag.getCompound(RawAnimationDataCapability.AnimMap); for (String newLayerString : animMap.getAllKeys()) { diff --git a/src/main/java/com/linearpast/sccore/animation/network/toclient/SyncAnimationPacket.java b/src/main/java/com/linearpast/sccore/animation/network/toclient/SyncAnimationPacket.java index 7370ba8..db1361a 100644 --- a/src/main/java/com/linearpast/sccore/animation/network/toclient/SyncAnimationPacket.java +++ b/src/main/java/com/linearpast/sccore/animation/network/toclient/SyncAnimationPacket.java @@ -43,7 +43,6 @@ public class SyncAnimationPacket { () -> AnimationUtils.syncAnimation(player, target), new AbstractMap.SimpleEntry<>(5, 0) ); - }); } } diff --git a/src/main/java/com/linearpast/sccore/animation/network/toserver/ApplyAnimationPacket.java b/src/main/java/com/linearpast/sccore/animation/network/toserver/ApplyAnimationPacket.java index 135b2c9..024625d 100644 --- a/src/main/java/com/linearpast/sccore/animation/network/toserver/ApplyAnimationPacket.java +++ b/src/main/java/com/linearpast/sccore/animation/network/toserver/ApplyAnimationPacket.java @@ -1,7 +1,7 @@ package com.linearpast.sccore.animation.network.toserver; -import com.linearpast.sccore.animation.helper.IAnimationHelper; -import com.linearpast.sccore.animation.network.HelperGetterPacket; +import com.linearpast.sccore.animation.network.ServiceGetterPacket; +import com.linearpast.sccore.animation.service.IAnimationService; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.server.level.ServerPlayer; import net.minecraftforge.network.NetworkEvent; @@ -9,7 +9,7 @@ import net.minecraftforge.network.NetworkEvent; import java.util.UUID; import java.util.function.Supplier; -public class ApplyAnimationPacket extends HelperGetterPacket { +public class ApplyAnimationPacket extends ServiceGetterPacket { private final UUID targetUUID; public ApplyAnimationPacket(UUID targetUUID) { @@ -34,15 +34,15 @@ public class ApplyAnimationPacket extends HelperGetterPacket { if(this.targetUUID == null) target = sender; else target = sender.getServer().getPlayerList().getPlayer(this.targetUUID); if(target == null) return; - IAnimationHelper helper = getHelper(); - if(helper == null) return; + IAnimationService service = getService(); + if(service == null) return; if(target == sender) return; - helper.apply(sender, target); + service.apply(sender, target); }); } @Override - public boolean filter(IAnimationHelper helper) { + public boolean filter(IAnimationService helper) { return true; } } diff --git a/src/main/java/com/linearpast/sccore/animation/network/toserver/InviteAnimationPacket.java b/src/main/java/com/linearpast/sccore/animation/network/toserver/InviteAnimationPacket.java index 2de2070..19f71ca 100644 --- a/src/main/java/com/linearpast/sccore/animation/network/toserver/InviteAnimationPacket.java +++ b/src/main/java/com/linearpast/sccore/animation/network/toserver/InviteAnimationPacket.java @@ -1,8 +1,8 @@ package com.linearpast.sccore.animation.network.toserver; import com.linearpast.sccore.animation.data.AnimationData; -import com.linearpast.sccore.animation.helper.IAnimationHelper; -import com.linearpast.sccore.animation.network.HelperGetterPacket; +import com.linearpast.sccore.animation.network.ServiceGetterPacket; +import com.linearpast.sccore.animation.service.IAnimationService; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; @@ -14,7 +14,7 @@ import java.util.Collection; import java.util.UUID; import java.util.function.Supplier; -public class InviteAnimationPacket extends HelperGetterPacket { +public class InviteAnimationPacket extends ServiceGetterPacket { private final @Nullable CompoundTag animationTag; private final ResourceLocation layer; private final ResourceLocation animation; @@ -47,12 +47,12 @@ public class InviteAnimationPacket extends HelperGetterPacket { context.setPacketHandled(true); ServerPlayer sender = context.getSender(); if(sender == null) return; - IAnimationHelper helper = getHelper(); - if(helper == null) return; - AnimationData data = helper.getAnimation(animationTag); + IAnimationService service = getService(); + if(service == null) return; + AnimationData data = service.getAnimation(animationTag); if(data == null) return; - if(!targets.isEmpty()) helper.invite(sender, layer, data, targets); - else helper.playAnimationWithRide(sender, layer, data, false); + if(!targets.isEmpty()) service.invite(sender, layer, data, targets); + else service.playAnimationWithRide(sender, layer, data, false); }); } diff --git a/src/main/java/com/linearpast/sccore/animation/network/toserver/PlayAnimationPacket.java b/src/main/java/com/linearpast/sccore/animation/network/toserver/PlayAnimationPacket.java index 34a432a..67b64f8 100644 --- a/src/main/java/com/linearpast/sccore/animation/network/toserver/PlayAnimationPacket.java +++ b/src/main/java/com/linearpast/sccore/animation/network/toserver/PlayAnimationPacket.java @@ -1,8 +1,8 @@ package com.linearpast.sccore.animation.network.toserver; import com.linearpast.sccore.animation.data.AnimationData; -import com.linearpast.sccore.animation.helper.IAnimationHelper; -import com.linearpast.sccore.animation.network.HelperGetterPacket; +import com.linearpast.sccore.animation.network.ServiceGetterPacket; +import com.linearpast.sccore.animation.service.IAnimationService; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; @@ -13,7 +13,7 @@ import org.jetbrains.annotations.Nullable; import java.util.UUID; import java.util.function.Supplier; -public class PlayAnimationPacket extends HelperGetterPacket { +public class PlayAnimationPacket extends ServiceGetterPacket { private final @Nullable CompoundTag animationTag; private final ResourceLocation layer; private final ResourceLocation animation; @@ -50,12 +50,12 @@ public class PlayAnimationPacket extends HelperGetterPacket { if(this.uuid == null) target = sender; else target = sender.getServer().getPlayerList().getPlayer(this.uuid); if(target == null) return; - IAnimationHelper helper = getHelper(); - if(helper == null) return; - AnimationData data = helper.getAnimation(animationTag); + IAnimationService service = getService(); + if(service == null) return; + AnimationData data = service.getAnimation(animationTag); if(data == null) return; - if(target == sender) helper.playAnimation(target, layer, data); - else helper.request(sender, target, layer, data, false); + if(target == sender) service.playAnimation(target, layer, data); + else service.request(sender, target, layer, data, false); }); } diff --git a/src/main/java/com/linearpast/sccore/animation/network/toserver/PlayAnimationRidePacket.java b/src/main/java/com/linearpast/sccore/animation/network/toserver/PlayAnimationRidePacket.java index 4a900fb..2f251e8 100644 --- a/src/main/java/com/linearpast/sccore/animation/network/toserver/PlayAnimationRidePacket.java +++ b/src/main/java/com/linearpast/sccore/animation/network/toserver/PlayAnimationRidePacket.java @@ -1,8 +1,8 @@ package com.linearpast.sccore.animation.network.toserver; import com.linearpast.sccore.animation.data.AnimationData; -import com.linearpast.sccore.animation.helper.IAnimationHelper; -import com.linearpast.sccore.animation.network.HelperGetterPacket; +import com.linearpast.sccore.animation.network.ServiceGetterPacket; +import com.linearpast.sccore.animation.service.IAnimationService; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; @@ -13,15 +13,15 @@ import org.jetbrains.annotations.Nullable; import java.util.UUID; import java.util.function.Supplier; -public class PlayAnimationRidePacket extends HelperGetterPacket { +public class PlayAnimationRidePacket extends ServiceGetterPacket { private final @Nullable CompoundTag animationTag; private final ResourceLocation layer; private final ResourceLocation animation; private final @Nullable UUID uuid; private final boolean force; - public PlayAnimationRidePacket(AnimationData data, ResourceLocation layer, ResourceLocation animation, @Nullable UUID uuid, boolean force) { - this.animationTag = data.serializeNBT(); + public PlayAnimationRidePacket(@Nullable AnimationData data, ResourceLocation layer, ResourceLocation animation, @Nullable UUID uuid, boolean force) { + this.animationTag = data != null ? data.serializeNBT() : null; this.layer = layer; this.animation = animation; this.uuid = uuid; @@ -54,12 +54,12 @@ public class PlayAnimationRidePacket extends HelperGetterPacket { if(this.uuid == null) target = sender; else target = sender.getServer().getPlayerList().getPlayer(this.uuid); if(target == null) return; - IAnimationHelper helper = getHelper(); - if(helper == null) return; - AnimationData data = helper.getAnimation(animationTag); + IAnimationService service = getService(); + if(service == null) return; + AnimationData data = service.getAnimation(animationTag); if(data == null) return; - if(target == sender) helper.playAnimationWithRide(target, layer, data, force); - else helper.request(sender, target, layer, data, true); + if(target == sender) service.playAnimationWithRide(target, layer, data, force); + else service.request(sender, target, layer, data, true); }); } diff --git a/src/main/java/com/linearpast/sccore/animation/network/toserver/RequestAnimationPacket.java b/src/main/java/com/linearpast/sccore/animation/network/toserver/RequestAnimationPacket.java index c9d6dfc..d71d13b 100644 --- a/src/main/java/com/linearpast/sccore/animation/network/toserver/RequestAnimationPacket.java +++ b/src/main/java/com/linearpast/sccore/animation/network/toserver/RequestAnimationPacket.java @@ -1,8 +1,8 @@ package com.linearpast.sccore.animation.network.toserver; import com.linearpast.sccore.animation.data.AnimationData; -import com.linearpast.sccore.animation.helper.IAnimationHelper; -import com.linearpast.sccore.animation.network.HelperGetterPacket; +import com.linearpast.sccore.animation.network.ServiceGetterPacket; +import com.linearpast.sccore.animation.service.IAnimationService; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; @@ -13,7 +13,7 @@ import org.jetbrains.annotations.Nullable; import java.util.UUID; import java.util.function.Supplier; -public class RequestAnimationPacket extends HelperGetterPacket { +public class RequestAnimationPacket extends ServiceGetterPacket { private final @Nullable CompoundTag animationTag; private final ResourceLocation layer; private final ResourceLocation animation; @@ -50,12 +50,12 @@ public class RequestAnimationPacket extends HelperGetterPacket { if(this.targetUUID == null) target = sender; else target = sender.getServer().getPlayerList().getPlayer(this.targetUUID); if(target == null) return; - IAnimationHelper helper = getHelper(); - if(helper == null) return; - AnimationData data = helper.getAnimation(animationTag); + IAnimationService service = getService(); + if(service == null) return; + AnimationData data = service.getAnimation(animationTag); if(data == null) return; if(target == sender) return; - helper.request(sender, target, layer, data, false); + service.request(sender, target, layer, data, false); }); } diff --git a/src/main/java/com/linearpast/sccore/animation/register/AnimationCommands.java b/src/main/java/com/linearpast/sccore/animation/register/AnimationCommands.java index 6ddbfcc..3612894 100644 --- a/src/main/java/com/linearpast/sccore/animation/register/AnimationCommands.java +++ b/src/main/java/com/linearpast/sccore/animation/register/AnimationCommands.java @@ -5,7 +5,7 @@ import com.linearpast.sccore.animation.command.argument.AnimationArgument; import com.linearpast.sccore.animation.command.argument.AnimationLayerArgument; import com.linearpast.sccore.animation.command.client.ListClientCommand; import com.linearpast.sccore.animation.command.client.RefreshCommand; -import com.linearpast.sccore.animation.helper.IAnimationHelper; +import com.linearpast.sccore.animation.service.IAnimationService; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.synchronization.ArgumentTypeInfo; @@ -17,7 +17,7 @@ import static net.minecraft.commands.Commands.literal; public class AnimationCommands { public static void commonCommandRegister(LiteralArgumentBuilder builder) { - if(IAnimationHelper.ANIMATION_RUNNER.isModLoaded()){ + if(IAnimationService.ANIMATION_RUNNER.testCondition()){ LiteralArgumentBuilder anim = literal("anim"); ApplyCommand.register(anim); InviteCommand.register(anim); @@ -30,7 +30,7 @@ public class AnimationCommands { } public static void clientCommandRegister(LiteralArgumentBuilder builder) { - if(IAnimationHelper.ANIMATION_RUNNER.isModLoaded()) { + if(IAnimationService.ANIMATION_RUNNER.testCondition()) { LiteralArgumentBuilder anim = literal("anim"); ListClientCommand.register(anim); RefreshCommand.register(anim); diff --git a/src/main/java/com/linearpast/sccore/animation/register/AnimationRegistry.java b/src/main/java/com/linearpast/sccore/animation/register/AnimationRegistry.java index c7c54e5..39d55e8 100644 --- a/src/main/java/com/linearpast/sccore/animation/register/AnimationRegistry.java +++ b/src/main/java/com/linearpast/sccore/animation/register/AnimationRegistry.java @@ -10,10 +10,10 @@ import com.linearpast.sccore.animation.data.RawAnimationData; import com.linearpast.sccore.animation.data.util.AnimJson; import com.linearpast.sccore.animation.data.util.AnimLayerJson; import com.linearpast.sccore.animation.event.create.AnimationRegisterEvent; -import com.linearpast.sccore.animation.helper.RawAnimationHelper; import com.linearpast.sccore.animation.mixin.IMixinPlayerAnimationFactoryHolder; import com.linearpast.sccore.animation.network.toclient.AnimationClientStatusPacket; import com.linearpast.sccore.animation.network.toclient.AnimationJsonPacket; +import com.linearpast.sccore.animation.service.RawAnimationService; import com.linearpast.sccore.core.ModChannel; import com.linearpast.sccore.utils.ModuleAccess; import dev.kosmx.playerAnim.api.layered.AnimationStack; @@ -297,10 +297,6 @@ public class AnimationRegistry { if(riderAnimLayer != null) { dataAnimations.put(riderAnimLayer, data.getRiderAnimation()); } - ResourceLocation rawRiderAnimLayer = rawData.getRiderAnimLayer(); - if(rawRiderAnimLayer != null) { - dataAnimations.put(rawRiderAnimLayer, rawData.getRiderAnimation()); - } for (ResourceLocation location : dataAnimations.keySet()) { ModifierLayer modifierLayer = (ModifierLayer) PlayerAnimationAccess .getPlayerAssociatedData(player).get(location); @@ -309,7 +305,7 @@ public class AnimationRegistry { ResourceLocation animationLocation = dataAnimations.get(location); GenericAnimationData anim = animations.get(animationLocation); if(anim == null) { - RawAnimationData rawAnim = RawAnimationHelper.INSTANCE.getAnimation(animationLocation); + RawAnimationData rawAnim = RawAnimationService.INSTANCE.getAnimation(animationLocation); if(rawAnim == null) return; keyframeAnimation = rawAnim.getAnimation(); } else keyframeAnimation = anim.getAnimation(); diff --git a/src/main/java/com/linearpast/sccore/animation/service/AnimationService.java b/src/main/java/com/linearpast/sccore/animation/service/AnimationService.java new file mode 100644 index 0000000..f4f4c5c --- /dev/null +++ b/src/main/java/com/linearpast/sccore/animation/service/AnimationService.java @@ -0,0 +1,168 @@ +package com.linearpast.sccore.animation.service; + +import com.linearpast.sccore.animation.capability.AnimationDataCapability; +import com.linearpast.sccore.animation.capability.inter.IAnimationCapability; +import com.linearpast.sccore.animation.data.AnimationData; +import com.linearpast.sccore.animation.data.GenericAnimationData; +import com.linearpast.sccore.animation.register.AnimationRegistry; +import com.linearpast.sccore.animation.utils.AnimationUtils; +import com.linearpast.sccore.animation.utils.ApiBack; +import net.minecraft.client.player.AbstractClientPlayer; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.player.Player; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; +import net.minecraftforge.common.util.FakePlayer; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.HashSet; +import java.util.Optional; +import java.util.Set; + +/** + * Animation Util. May be you can call it Api. + */ +public class AnimationService implements IAnimationService { + public static final AnimationService INSTANCE = new AnimationService(); + + /** + * Get the LyingType when there are animations which playing on player.
+ * And It will return the first which be found. + * @param player Target player + * @return The first LyingType it find. + */ + @Nullable + public GenericAnimationData.LyingType getSideView(Player player) { + return ANIMATION_RUNNER.testLoadedAndCall(() -> { + IAnimationCapability data = AnimationDataCapability.getCapability(player).orElse(null); + if(data == null) return null; + GenericAnimationData.LyingType lyingType = null; + for (ResourceLocation value : data.getAnimations().values()) { + GenericAnimationData animation = getAnimation(value); + if(animation == null) return null; + GenericAnimationData.LyingType type = animation.getLyingType(); + if(type == null) continue; + switch (type) { + case FRONT,BACK -> {} + case LEFT,RIGHT -> lyingType = animation.getLyingType(); + } + } + return lyingType; + }); + } + + /** + * Get the HeightModifier when there are animations which playing on player.
+ * And It will return the first which be found. + * @param player Target player + * @return The first HeightModifier it find. + */ + public float getHeightModifier(Player player) { + Float result = ANIMATION_RUNNER.testLoadedAndCall(() -> { + IAnimationCapability data = AnimationDataCapability.getCapability(player).orElse(null); + if (data == null) return 1.0f; + float heightModifier = 1.0f; + for (ResourceLocation value : data.getAnimations().values()) { + GenericAnimationData animation = getAnimation(value); + if (animation == null) continue; + float animationHeightModifier = animation.getHeightModifier(); + heightModifier = Math.min(heightModifier, animationHeightModifier); + } + return heightModifier; + }); + return result == null ? 1.0f : result; + } + + + @Override + public @Nullable GenericAnimationData getAnimation(ResourceLocation location) { + return AnimationRegistry.getAnimations().getOrDefault(location, null); + } + + @Override + public @Nullable GenericAnimationData getAnimation(CompoundTag tag) { + return new GenericAnimationData(){{deserializeNBT(tag);}}; + } + + @Override + public @Nullable IAnimationCapability getCapability(Player player) { + return AnimationDataCapability.getCapability(player).orElse(null); + } + + @Override + public void clearAnimations(ServerPlayer serverPlayer) { + ANIMATION_RUNNER.testLoadedAndRun(() -> { + Optional.ofNullable(getCapability(serverPlayer)).ifPresent(IAnimationCapability::clearAnimations); + detachAnimation(serverPlayer); + }); + } + + @Override + public boolean isAnimationPresent(ResourceLocation location) { + return ANIMATION_RUNNER.testLoadedAndCall(() -> AnimationRegistry.getAnimations().containsKey(location)); + } + + @Override + @OnlyIn(Dist.CLIENT) + public void refreshAnimation(AbstractClientPlayer clientPlayer) { + ANIMATION_RUNNER.testLoadedAndRun(() -> { + IAnimationCapability data = getCapability(clientPlayer); + if(data == null) return; + Set oldLayers = new HashSet<>(data.getAnimations().keySet()); + for (ResourceLocation layer : Set.copyOf(oldLayers)) { + if (AnimationUtils.isClientAnimationStop(clientPlayer, layer)) { + removeAnimation(clientPlayer, layer); + } + } + }); + } + + @Override + public @Nullable ResourceLocation getAnimationPlaying(Player player, @Nullable ResourceLocation layer) { + return ANIMATION_RUNNER.testLoadedAndCall(() -> { + IAnimationCapability data = getCapability(player); + if(data == null) return null; + if(layer == null){ + for (ResourceLocation value : data.getAnimations().values()) { + if(value != null) return value; + } + } else if (isAnimationLayerPresent(layer)) { + if(data.isAnimationPresent(layer)){ + return data.getAnimation(layer); + } + } + return null; + }); + } + + @Override + public ApiBack removeAnimation(@NotNull ServerPlayer serverPlayer, ResourceLocation layer) { + boolean result = ANIMATION_RUNNER.testLoadedAndCall(() -> Optional.ofNullable(getCapability(serverPlayer)) + .map(data -> data.removeAnimation(layer)).orElse(false)); + return result ? ApiBack.SUCCESS : ApiBack.FAIL; + } + + @Override + public ApiBack playAnimationServer(@NotNull ServerPlayer player, ResourceLocation layer, AnimationData animation) { + return ANIMATION_RUNNER.testLoadedAndCall(() -> { + ResourceLocation key = animation.getKey(); + if(!isAnimationLayerPresent(layer) || !isAnimationPresent(key)) + return ApiBack.RESOURCE_NOT_FOUND; + if(player instanceof FakePlayer) + return ApiBack.UNSUPPORTED; + Boolean flag = Optional.ofNullable(getCapability(player)).map(data -> + data.mergeAnimation(layer, key)).orElse(false); + return flag ? ApiBack.SUCCESS : ApiBack.FAIL; + }); + } + + public ApiBack playAnimation(@NotNull ServerPlayer player, ResourceLocation layer, ResourceLocation animation) { + return playAnimation(player, layer, getAnimation(animation)); + } + public ApiBack playAnimationWithRide(@NotNull ServerPlayer player, ResourceLocation layer, ResourceLocation animation, boolean force) { + return playAnimationWithRide(player, layer, getAnimation(animation), force); + } +} diff --git a/src/main/java/com/linearpast/sccore/animation/helper/IAnimationHelper.java b/src/main/java/com/linearpast/sccore/animation/service/IAnimationService.java similarity index 90% rename from src/main/java/com/linearpast/sccore/animation/helper/IAnimationHelper.java rename to src/main/java/com/linearpast/sccore/animation/service/IAnimationService.java index 90b7530..f98a823 100644 --- a/src/main/java/com/linearpast/sccore/animation/helper/IAnimationHelper.java +++ b/src/main/java/com/linearpast/sccore/animation/service/IAnimationService.java @@ -1,6 +1,7 @@ -package com.linearpast.sccore.animation.helper; +package com.linearpast.sccore.animation.service; import com.linearpast.sccore.animation.data.AnimationData; +import com.linearpast.sccore.animation.entity.AnimationRideEntity; import com.linearpast.sccore.animation.event.PlayerTickEvent; import com.linearpast.sccore.animation.event.client.CameraAnglesModify; import com.linearpast.sccore.animation.event.client.ClientPlayerEvent; @@ -16,7 +17,7 @@ import com.linearpast.sccore.animation.utils.AnimationUtils; import com.linearpast.sccore.animation.utils.ApiBack; import com.linearpast.sccore.capability.data.ICapabilitySync; import com.linearpast.sccore.core.ModChannel; -import com.linearpast.sccore.core.ModLazyRun; +import com.linearpast.sccore.core.ModCompatRun; import com.linearpast.sccore.core.configs.ModConfigs; import dev.kosmx.playerAnim.core.data.KeyframeAnimation; import dev.kosmx.playerAnim.minecraftApi.PlayerAnimationRegistry; @@ -24,10 +25,12 @@ import net.minecraft.client.player.AbstractClientPlayer; import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.common.util.FakePlayer; import net.minecraftforge.eventbus.api.Event; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.fml.LogicalSide; @@ -44,12 +47,12 @@ import java.util.stream.Collectors; * @param Capability */ @SuppressWarnings({"UnusedReturnValue", "unused"}) -public interface IAnimationHelper>{ +public interface IAnimationService>{ String AnimModId = "playeranimator"; /** * Lazy runner */ - ModLazyRun ANIMATION_RUNNER = new ModLazyRun(AnimModId) { + ModCompatRun ANIMATION_RUNNER = new ModCompatRun(AnimModId) { @Override public void addCommonListener(IEventBus forgeBus, IEventBus modBus) { AnimationEntities.register(modBus); @@ -125,14 +128,37 @@ public interface IAnimationHelper { + if(player.getVehicle() instanceof AnimationRideEntity) { + player.stopRiding(); + return ApiBack.SUCCESS; + } + return ApiBack.UNSUPPORTED; + }); + }; //start ride - ApiBack joinAnimationServer(ServerPlayer player, ServerPlayer target, boolean force); + default ApiBack joinAnimationServer(ServerPlayer player, ServerPlayer target, boolean force){ + return ANIMATION_RUNNER.testLoadedAndCall(() -> { + Entity vehicle = target.getVehicle(); + if(vehicle instanceof AnimationRideEntity) { + boolean result = player.startRiding(vehicle, force); + return result ? ApiBack.SUCCESS : ApiBack.FAIL; + } + return ApiBack.UNSUPPORTED; + }); + }; /** * Trigger event and let implementation class handle @@ -254,7 +280,22 @@ public interface IAnimationHelper { + ResourceLocation key = animation.getKey(); + if(!isAnimationLayerPresent(layer) || !isAnimationPresent(key)) + return ApiBack.RESOURCE_NOT_FOUND; + if(animation.getRide() == null) + return ApiBack.RESOURCE_NOT_FOUND; + if(player instanceof FakePlayer) + return ApiBack.UNSUPPORTED; + boolean flag = player.getVehicle() != null; + if(flag && force) player.unRide(); + else if(flag) return ApiBack.UNSUPPORTED; + boolean result = AnimationRideEntity.create(player, layer, animation, force) != null; + return result ? ApiBack.SUCCESS : ApiBack.FAIL; + }); + }; /** *
@@ -624,11 +665,13 @@ public interface IAnimationHelper {
-    public static final RawAnimationHelper INSTANCE = new RawAnimationHelper();
+public class RawAnimationService implements IAnimationService {
+    public static final RawAnimationService INSTANCE = new RawAnimationService();
 
     /**
      * Trigger raw animation registry. 
@@ -71,29 +69,6 @@ public class RawAnimationHelper implements IAnimationHelper { - if(player.getVehicle() instanceof RawAnimationRideEntity) { - player.stopRiding(); - return ApiBack.SUCCESS; - } - return ApiBack.UNSUPPORTED; - }); - } - - @Override - public ApiBack joinAnimationServer(ServerPlayer player, ServerPlayer target, boolean force) { - return ANIMATION_RUNNER.testLoadedAndCall(() -> { - Entity vehicle = target.getVehicle(); - if(vehicle instanceof RawAnimationRideEntity) { - boolean result = player.startRiding(vehicle, force); - return result ? ApiBack.SUCCESS : ApiBack.FAIL; - } - return ApiBack.UNSUPPORTED; - }); - } - @Override @OnlyIn(Dist.CLIENT) public void refreshAnimation(AbstractClientPlayer clientPlayer) { @@ -134,26 +109,6 @@ public class RawAnimationHelper implements IAnimationHelper { - if(!isAnimationLayerPresent(layer)) - return ApiBack.RESOURCE_NOT_FOUND; - if(animation.getRide() == null) - return ApiBack.RESOURCE_NOT_FOUND; - if(player instanceof FakePlayer) - return ApiBack.UNSUPPORTED; - boolean flag = player.getVehicle() != null; - if(flag && force) player.unRide(); - else if(flag) return ApiBack.UNSUPPORTED; - if(!(animation instanceof RawAnimationData data)) - return ApiBack.UNSUPPORTED; - RawAnimationRideEntity rawAnimationRideEntity = RawAnimationRideEntity.create(player, layer, data); - boolean result = rawAnimationRideEntity != null; - return result ? ApiBack.SUCCESS : ApiBack.FAIL; - }); - } - @Override public ApiBack playAnimationServer(@NotNull ServerPlayer player, ResourceLocation layer, AnimationData animation) { return ANIMATION_RUNNER.testLoadedAndCall(() -> { diff --git a/src/main/java/com/linearpast/sccore/animation/utils/AnimationUtils.java b/src/main/java/com/linearpast/sccore/animation/utils/AnimationUtils.java index 4a8b8e4..c4b254f 100644 --- a/src/main/java/com/linearpast/sccore/animation/utils/AnimationUtils.java +++ b/src/main/java/com/linearpast/sccore/animation/utils/AnimationUtils.java @@ -2,14 +2,14 @@ package com.linearpast.sccore.animation.utils; import com.linearpast.sccore.SnowyCrescentCore; import com.linearpast.sccore.animation.capability.AnimationDataCapability; -import com.linearpast.sccore.animation.capability.RawAnimationDataCapability; +import com.linearpast.sccore.animation.capability.inter.IAnimationCapability; import com.linearpast.sccore.animation.data.GenericAnimationData; import com.linearpast.sccore.animation.data.RawAnimationData; -import com.linearpast.sccore.animation.helper.AnimationHelper; -import com.linearpast.sccore.animation.helper.IAnimationHelper; -import com.linearpast.sccore.animation.helper.RawAnimationHelper; import com.linearpast.sccore.animation.mixin.IMixinKeyframeAnimationPlayer; import com.linearpast.sccore.animation.register.AnimationRegistry; +import com.linearpast.sccore.animation.service.AnimationService; +import com.linearpast.sccore.animation.service.IAnimationService; +import com.linearpast.sccore.animation.service.RawAnimationService; import com.linearpast.sccore.core.datagen.ModLang; import dev.kosmx.playerAnim.api.layered.IAnimation; import dev.kosmx.playerAnim.api.layered.KeyframeAnimationPlayer; @@ -30,7 +30,6 @@ import org.jetbrains.annotations.Nullable; import java.util.HashSet; import java.util.Set; -import java.util.concurrent.atomic.AtomicReference; public class AnimationUtils { /** @@ -43,7 +42,7 @@ public class AnimationUtils { @SuppressWarnings("unchecked") @OnlyIn(Dist.CLIENT) public static boolean isClientAnimationNotEnd(AbstractClientPlayer player, @Nullable ResourceLocation layer) { - return IAnimationHelper.ANIMATION_RUNNER.testLoadedAndCall(() -> { + return IAnimationService.ANIMATION_RUNNER.testLoadedAndCall(() -> { try { Set resourceLocations = new HashSet<>(); if(layer == null) resourceLocations.addAll(AnimationRegistry.getLayers().keySet()); @@ -74,7 +73,7 @@ public class AnimationUtils { @SuppressWarnings("unchecked") @OnlyIn(Dist.CLIENT) public static boolean isClientAnimationStop(AbstractClientPlayer player, @Nullable ResourceLocation layer) { - return IAnimationHelper.ANIMATION_RUNNER.testLoadedAndCall(() -> { + return IAnimationService.ANIMATION_RUNNER.testLoadedAndCall(() -> { try { Set resourceLocations = new HashSet<>(); if(layer == null) resourceLocations.addAll(AnimationRegistry.getLayers().keySet()); @@ -102,30 +101,18 @@ public class AnimationUtils { @SuppressWarnings("unchecked") @OnlyIn(Dist.CLIENT) public static void syncAnimation(AbstractClientPlayer clientPlayer, AbstractClientPlayer target) { - AtomicReference clientPlayerLayer = new AtomicReference<>(); - AtomicReference targetLayer = new AtomicReference<>(); - clientPlayerLayer.set(null); - targetLayer.set(null); - AnimationDataCapability.getCapability(clientPlayer).ifPresent(clientPlayerData -> - AnimationDataCapability.getCapability(target).ifPresent(targetData -> { - clientPlayerLayer.set(clientPlayerData.getRiderAnimLayer()); - targetLayer.set(targetData.getRiderAnimLayer()); - }) - ); - if(clientPlayerLayer.get() == null || targetLayer.get() == null) { - RawAnimationDataCapability.getCapability(clientPlayer).ifPresent(clientPlayerData -> - RawAnimationDataCapability.getCapability(target).ifPresent(targetData -> { - clientPlayerLayer.set(clientPlayerData.getRiderAnimLayer()); - targetLayer.set(targetData.getRiderAnimLayer()); - }) - ); - } + IAnimationCapability clientPlayerData = AnimationDataCapability.getCapability(clientPlayer).orElse(null); + IAnimationCapability targetData = AnimationDataCapability.getCapability(target).orElse(null); + if(clientPlayerData == null) return; + if(targetData == null) return; + ResourceLocation clientPlayerLayer = clientPlayerData.getRiderAnimLayer(); + ResourceLocation targetLayer = targetData.getRiderAnimLayer(); try { - if(clientPlayerLayer.get() == null || targetLayer.get() == null) return; + if(clientPlayerLayer == null || targetLayer == null) return; ModifierLayer modifierLayer = (ModifierLayer) PlayerAnimationAccess - .getPlayerAssociatedData(clientPlayer).get(clientPlayerLayer.get()); + .getPlayerAssociatedData(clientPlayer).get(clientPlayerLayer); ModifierLayer targetModifierLayer = (ModifierLayer) PlayerAnimationAccess - .getPlayerAssociatedData(target).get(targetLayer.get()); + .getPlayerAssociatedData(target).get(targetLayer); if(modifierLayer == null || targetModifierLayer == null) return; IMixinKeyframeAnimationPlayer animation = (IMixinKeyframeAnimationPlayer) modifierLayer.getAnimation(); KeyframeAnimationPlayer targetAnimation = (KeyframeAnimationPlayer) targetModifierLayer.getAnimation(); @@ -171,9 +158,9 @@ public class AnimationUtils { } if(modifierLayer == null) return; KeyframeAnimation keyframeAnimation; - GenericAnimationData anim = AnimationHelper.INSTANCE.getAnimation(animation); + GenericAnimationData anim = AnimationService.INSTANCE.getAnimation(animation); if(anim == null) { - RawAnimationData rawAnim = RawAnimationHelper.INSTANCE.getAnimation(animation); + RawAnimationData rawAnim = RawAnimationService.INSTANCE.getAnimation(animation); if(rawAnim == null) return; keyframeAnimation = rawAnim.getAnimation(); } else keyframeAnimation = anim.getAnimation(); diff --git a/src/main/java/com/linearpast/sccore/core/IModLazyRun.java b/src/main/java/com/linearpast/sccore/core/IModLazyRun.java new file mode 100644 index 0000000..d5eeab9 --- /dev/null +++ b/src/main/java/com/linearpast/sccore/core/IModLazyRun.java @@ -0,0 +1,35 @@ +package com.linearpast.sccore.core; + +import java.util.concurrent.Callable; + +@SuppressWarnings("UnusedReturnValue") +public interface IModLazyRun { + default boolean testLoadedAndRun(Runnable runnable){ + if(testCondition()) runnable.run(); + else return false; + return true; + } + + default void testLoadedAndRun(Runnable runnable, Runnable elseRun){ + if(testCondition()) runnable.run(); + else elseRun.run(); + } + + default T testLoadedAndCall(Callable callable) { + try { + if(testCondition()) return callable.call(); + } catch (Exception ignored) {} + return null; + } + + default T testLoadedAndCall(Callable callable, Callable elseCall) { + try { + if(testCondition()) return callable.call(); + else return elseCall.call(); + }catch(Exception ignored) { + return null; + } + } + + boolean testCondition(); +} diff --git a/src/main/java/com/linearpast/sccore/core/ModCompatRun.java b/src/main/java/com/linearpast/sccore/core/ModCompatRun.java new file mode 100644 index 0000000..bc508db --- /dev/null +++ b/src/main/java/com/linearpast/sccore/core/ModCompatRun.java @@ -0,0 +1,29 @@ +package com.linearpast.sccore.core; + +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.eventbus.api.IEventBus; +import net.minecraftforge.fml.ModList; +import net.minecraftforge.fml.loading.FMLLoader; + +public abstract class ModCompatRun implements IModLazyRun{ + private final String modId; + public ModCompatRun(String modId) { + this.modId = modId; + } + + @Override + public boolean testCondition() { + return ModList.get().isLoaded(modId); + } + + public void addCommonListener(IEventBus forgeBus, IEventBus modBus){} + public void addClientListener(IEventBus forgeBus, IEventBus modBus){} + public void testLoadedAndAddListener(IEventBus forgeBus, IEventBus modBus) { + if(testCondition()){ + addCommonListener(forgeBus, modBus); + if(FMLLoader.getDist() == Dist.CLIENT){ + addClientListener(forgeBus, modBus); + } + } + } +} diff --git a/src/main/java/com/linearpast/sccore/core/ModLazyRun.java b/src/main/java/com/linearpast/sccore/core/ModLazyRun.java deleted file mode 100644 index 9821c1f..0000000 --- a/src/main/java/com/linearpast/sccore/core/ModLazyRun.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.linearpast.sccore.core; - -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.eventbus.api.IEventBus; -import net.minecraftforge.fml.ModList; -import net.minecraftforge.fml.loading.FMLLoader; - -import java.util.concurrent.Callable; - -public abstract class ModLazyRun { - private final String modId; - public ModLazyRun(String modId) { - this.modId = modId; - } - - public boolean testLoadedAndRun(Runnable runnable){ - if(isModLoaded()) runnable.run(); - else return false; - return true; - } - - public T testLoadedAndCall(Callable callable) { - try { - if(isModLoaded()) return callable.call(); - } catch (Exception ignored) {} - return null; - } - - public T testLoadedAndCall(Callable callable, Callable elseCall) { - try { - if(isModLoaded()) return callable.call(); - else return elseCall.call(); - }catch(Exception ignored) { - return null; - } - } - - public void addCommonListener(IEventBus forgeBus, IEventBus modBus){} - public void addClientListener(IEventBus forgeBus, IEventBus modBus){} - public void testLoadedAndAddListener(IEventBus forgeBus, IEventBus modBus) { - if(isModLoaded()){ - addCommonListener(forgeBus, modBus); - if(FMLLoader.getDist() == Dist.CLIENT){ - addClientListener(forgeBus, modBus); - } - } - } - - public boolean isModLoaded() { - return ModList.get().isLoaded(modId); - }; -} diff --git a/src/main/java/com/linearpast/sccore/example/animation/ModAnimation.java b/src/main/java/com/linearpast/sccore/example/animation/ModAnimation.java index 54e4a84..e081101 100644 --- a/src/main/java/com/linearpast/sccore/example/animation/ModAnimation.java +++ b/src/main/java/com/linearpast/sccore/example/animation/ModAnimation.java @@ -4,7 +4,7 @@ import com.linearpast.sccore.SnowyCrescentCore; import com.linearpast.sccore.animation.data.RawAnimationData; import com.linearpast.sccore.animation.data.Ride; import com.linearpast.sccore.animation.event.create.AnimationRegisterEvent; -import com.linearpast.sccore.animation.helper.AnimationHelper; +import com.linearpast.sccore.animation.service.AnimationService; import com.linearpast.sccore.example.animation.event.ExamplePlayerAttackEvent; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.api.distmarker.Dist; @@ -12,7 +12,7 @@ import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.fml.loading.FMLEnvironment; /** - * @see AnimationHelper + * @see AnimationService */ public class ModAnimation { /** diff --git a/src/main/java/com/linearpast/sccore/example/animation/event/ExamplePlayerAttackEvent.java b/src/main/java/com/linearpast/sccore/example/animation/event/ExamplePlayerAttackEvent.java index 9df60f9..20419a7 100644 --- a/src/main/java/com/linearpast/sccore/example/animation/event/ExamplePlayerAttackEvent.java +++ b/src/main/java/com/linearpast/sccore/example/animation/event/ExamplePlayerAttackEvent.java @@ -1,7 +1,7 @@ package com.linearpast.sccore.example.animation.event; -import com.linearpast.sccore.animation.helper.AnimationHelper; -import com.linearpast.sccore.animation.helper.RawAnimationHelper; +import com.linearpast.sccore.animation.service.AnimationService; +import com.linearpast.sccore.animation.service.RawAnimationService; import com.linearpast.sccore.example.animation.ModAnimation; import net.minecraft.client.Minecraft; import net.minecraft.client.player.AbstractClientPlayer; @@ -26,11 +26,11 @@ public class ExamplePlayerAttackEvent { Player entity = event.getEntity(); if(entity instanceof ServerPlayer player) { if(target instanceof Sheep){ - ResourceLocation playing = AnimationHelper.INSTANCE.getAnimationPlaying(player, ModAnimation.normalLayers); + ResourceLocation playing = AnimationService.INSTANCE.getAnimationPlaying(player, ModAnimation.normalLayers); if(playing == null) { - AnimationHelper.INSTANCE.playAnimation(player, ModAnimation.normalLayers, ModAnimation.AmStandToLying); + AnimationService.INSTANCE.playAnimation(player, ModAnimation.normalLayers, ModAnimation.AmStandToLying); } else { - AnimationHelper.INSTANCE.removeAnimation(player, ModAnimation.normalLayers); + AnimationService.INSTANCE.removeAnimation(player, ModAnimation.normalLayers); } } } @@ -41,7 +41,7 @@ public class ExamplePlayerAttackEvent { Player entity = event.getEntity(); if(entity instanceof AbstractClientPlayer player && target instanceof AbstractClientPlayer targetPlayer) { if(player == Minecraft.getInstance().player){ - RawAnimationHelper.INSTANCE.invite( + RawAnimationService.INSTANCE.invite( ModAnimation.normalLayers, ModAnimation.WaltzGentleman, targetPlayer @@ -49,7 +49,7 @@ public class ExamplePlayerAttackEvent { } } if(entity instanceof ServerPlayer player && target instanceof ServerPlayer targetPlayer) { - RawAnimationHelper.INSTANCE.acceptInvite(player, targetPlayer); + RawAnimationService.INSTANCE.acceptInvite(player, targetPlayer); } } @@ -63,9 +63,9 @@ public class ExamplePlayerAttackEvent { LocalPlayer player = instance.player; if (player == null) return; if(instance.options.keyCommand.isDown()) { - ResourceLocation playing = AnimationHelper.INSTANCE.getAnimationPlaying(player, ModAnimation.normalLayers); + ResourceLocation playing = AnimationService.INSTANCE.getAnimationPlaying(player, ModAnimation.normalLayers); if(playing == null) { - AnimationHelper.INSTANCE.playAnimationWithRide((AbstractClientPlayer) null, ModAnimation.normalLayers, ModAnimation.AmLyingToRightLying, true); + AnimationService.INSTANCE.playAnimationWithRide((AbstractClientPlayer) null, ModAnimation.normalLayers, ModAnimation.AmLyingToRightLying, true); } } } diff --git a/src/main/java/com/linearpast/sccore/mixin/SCCoreMixinPlugin.java b/src/main/java/com/linearpast/sccore/mixin/SCCoreMixinPlugin.java index 759c9d6..3b84bc0 100644 --- a/src/main/java/com/linearpast/sccore/mixin/SCCoreMixinPlugin.java +++ b/src/main/java/com/linearpast/sccore/mixin/SCCoreMixinPlugin.java @@ -1,7 +1,7 @@ package com.linearpast.sccore.mixin; import com.linearpast.sccore.SnowyCrescentCore; -import com.linearpast.sccore.animation.helper.AnimationHelper; +import com.linearpast.sccore.animation.service.AnimationService; import net.minecraftforge.fml.ModList; import org.objectweb.asm.tree.ClassNode; import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; @@ -27,7 +27,7 @@ public class SCCoreMixinPlugin implements IMixinConfigPlugin { return "runData".equals(System.getProperty("gradle.task")); } if (mixinClassName.startsWith("com\\.linearpast\\." + SnowyCrescentCore.MODID + "\\.mixin\\.animation")) { - return ModList.get().isLoaded(AnimationHelper.AnimModId); + return ModList.get().isLoaded(AnimationService.AnimModId); } return true; } diff --git a/src/main/java/com/linearpast/sccore/mixin/animation/MixinEntity.java b/src/main/java/com/linearpast/sccore/mixin/animation/MixinEntity.java index 05a56a3..ac10ff0 100644 --- a/src/main/java/com/linearpast/sccore/mixin/animation/MixinEntity.java +++ b/src/main/java/com/linearpast/sccore/mixin/animation/MixinEntity.java @@ -3,7 +3,7 @@ package com.linearpast.sccore.mixin.animation; import com.linearpast.sccore.animation.capability.AnimationDataCapability; import com.linearpast.sccore.animation.capability.inter.IAnimationCapability; import com.linearpast.sccore.animation.data.GenericAnimationData; -import com.linearpast.sccore.animation.helper.AnimationHelper; +import com.linearpast.sccore.animation.service.AnimationService; import com.llamalad7.mixinextras.injector.ModifyReturnValue; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.Entity; @@ -36,7 +36,7 @@ public abstract class MixinEntity { if(data == null) return; Float camYModifier = null; for (ResourceLocation value : data.getAnimations().values()) { - GenericAnimationData animation = AnimationHelper.INSTANCE.getAnimation(value); + GenericAnimationData animation = AnimationService.INSTANCE.getAnimation(value); if(animation == null) continue; float animationCamY = animation.getCamY(); if(camYModifier == null) camYModifier = animationCamY; @@ -56,7 +56,7 @@ public abstract class MixinEntity { private void redefinedBoundingBox(CallbackInfoReturnable cir){ Entity self = Entity.class.cast(this); if(self instanceof Player player){ - float heightModifier = AnimationHelper.INSTANCE.getHeightModifier(player); + float heightModifier = AnimationService.INSTANCE.getHeightModifier(player); if(heightModifier == 1.0f) return; double modifyHeight = 1.8f * heightModifier; cir.setReturnValue(this.bb.setMaxY(modifyHeight + this.bb.minY)); @@ -70,7 +70,7 @@ public abstract class MixinEntity { private float redefinedBbHeight(float original){ Entity self = Entity.class.cast(this); if(self instanceof Player player){ - float heightModifier = AnimationHelper.INSTANCE.getHeightModifier(player); + float heightModifier = AnimationService.INSTANCE.getHeightModifier(player); if(heightModifier == 1.0f) return original; return original * heightModifier; } @@ -87,7 +87,7 @@ public abstract class MixinEntity { private void redefinedPose(CallbackInfoReturnable cir){ Entity self = Entity.class.cast(this); if(self instanceof Player player){ - float heightModifier = AnimationHelper.INSTANCE.getHeightModifier(player); + float heightModifier = AnimationService.INSTANCE.getHeightModifier(player); if(heightModifier == 1.0f) return; setPose(Pose.STANDING); cir.setReturnValue(Pose.STANDING); diff --git a/src/main/java/com/linearpast/sccore/mixin/animation/client/MixinEntity.java b/src/main/java/com/linearpast/sccore/mixin/animation/client/MixinEntity.java index 713da24..0084562 100644 --- a/src/main/java/com/linearpast/sccore/mixin/animation/client/MixinEntity.java +++ b/src/main/java/com/linearpast/sccore/mixin/animation/client/MixinEntity.java @@ -1,7 +1,7 @@ package com.linearpast.sccore.mixin.animation.client; import com.linearpast.sccore.animation.data.GenericAnimationData; -import com.linearpast.sccore.animation.helper.AnimationHelper; +import com.linearpast.sccore.animation.service.AnimationService; import net.minecraft.client.Minecraft; import net.minecraft.util.Mth; import net.minecraft.world.entity.Entity; @@ -36,7 +36,7 @@ public abstract class MixinEntity { private void turnPosePlayer(double pYRot, double pXRot, CallbackInfo ci) { Entity self = Entity.class.cast(this); if(self instanceof Player player){ - GenericAnimationData.LyingType lyingType = AnimationHelper.INSTANCE.getSideView(player); + GenericAnimationData.LyingType lyingType = AnimationService.INSTANCE.getSideView(player); if(lyingType != null && Minecraft.getInstance().options.getCameraType().isFirstPerson()) { float f = (float)pXRot * 0.15F; float f1 = (float)pYRot * 0.15F; diff --git a/src/main/java/com/linearpast/sccore/mixin/animation/client/MixinHumanoidModel.java b/src/main/java/com/linearpast/sccore/mixin/animation/client/MixinHumanoidModel.java index 7820f7c..9c6da5e 100644 --- a/src/main/java/com/linearpast/sccore/mixin/animation/client/MixinHumanoidModel.java +++ b/src/main/java/com/linearpast/sccore/mixin/animation/client/MixinHumanoidModel.java @@ -1,7 +1,7 @@ package com.linearpast.sccore.mixin.animation.client; import com.linearpast.sccore.animation.data.GenericAnimationData; -import com.linearpast.sccore.animation.helper.AnimationHelper; +import com.linearpast.sccore.animation.service.AnimationService; import net.minecraft.client.model.AgeableListModel; import net.minecraft.client.model.ArmedModel; import net.minecraft.client.model.HeadedModel; @@ -26,7 +26,7 @@ public abstract class MixinHumanoidModel extends Ageable ) private void modifyHeadRot(T pEntity, float pLimbSwing, float pLimbSwingAmount, float pAgeInTicks, float pNetHeadYaw, float pHeadPitch, CallbackInfo ci){ if(pEntity instanceof Player player){ - GenericAnimationData.LyingType lyingType = AnimationHelper.INSTANCE.getSideView(player); + GenericAnimationData.LyingType lyingType = AnimationService.INSTANCE.getSideView(player); if(lyingType != null) { float pitch = pHeadPitch - 90.0f; float yaw = pNetHeadYaw * -1.0f;