version 0.1.1
This commit is contained in:
parent
e51810c408
commit
df879012d6
|
|
@ -12,7 +12,7 @@ mapping_version=2023.09.03-1.20.1
|
||||||
mod_id=sccore
|
mod_id=sccore
|
||||||
mod_name=SnowyCrescentCore
|
mod_name=SnowyCrescentCore
|
||||||
mod_license=GNU AGPL 3.0
|
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_group_id=com.linearpast
|
||||||
mod_authors=LostInLinearPast
|
mod_authors=LostInLinearPast
|
||||||
mod_description=A lib about capability and player animator.
|
mod_description=A lib about capability and player animator.
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
// 1.20.1 2025-11-26T10:22:37.4821986 Languages: zh_cn
|
// 1.20.1 2025-11-28T18:32:27.7132485 Languages: zh_cn
|
||||||
bfd0415418a7b7d284a9b445fd35a7242782beea assets/sccore/lang/zh_cn.json
|
33a56369fb517ec3b528128539e1e160666d9602 assets/sccore/lang/zh_cn.json
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
// 1.20.1 2025-11-26T10:22:37.4835694 Languages: en_us
|
// 1.20.1 2025-11-28T18:32:27.715234 Languages: en_us
|
||||||
874336226401ae3f556eec3296550b37f72d8831 assets/sccore/lang/en_us.json
|
941682565bf7998e144253f88be175d198e43566 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_apply_success": "%s has accepted the application of %s.",
|
||||||
"translation.sccore.command.animation.accept_invite_success": "Invitation accepted.",
|
"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_message_click": "Click here to accept.",
|
||||||
"translation.sccore.command.animation.accept_request_success": "Request accepted.",
|
"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_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.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.applied_join_message": "%S§b§l Apply for §r to join your animation. ",
|
||||||
"translation.sccore.command.animation.apply_join_message": "Application sent.",
|
"translation.sccore.command.animation.apply_join_message": "Application sent.",
|
||||||
|
|
|
||||||
|
|
@ -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_apply_success": "%s 接受了 %s 的申请。",
|
||||||
"translation.sccore.command.animation.accept_invite_success": "已接受邀请。",
|
"translation.sccore.command.animation.accept_invite_success": "已接受邀请。",
|
||||||
"translation.sccore.command.animation.accept_message_click": "单击此处同意。",
|
"translation.sccore.command.animation.accept_message_click": "单击此处同意。",
|
||||||
"translation.sccore.command.animation.accept_request_success": "已接受请求。",
|
"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_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.animation_to_json": "动画%s已经存储到%s路径:",
|
||||||
"translation.sccore.command.animation.applied_join_message": "%s§b§l 申请§r加入动画。",
|
"translation.sccore.command.animation.applied_join_message": "%s§b§l 申请§r加入动画。",
|
||||||
"translation.sccore.command.animation.apply_join_message": "已发送申请。",
|
"translation.sccore.command.animation.apply_join_message": "已发送申请。",
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package com.linearpast.sccore;
|
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.capability.CapabilityUtils;
|
||||||
import com.linearpast.sccore.core.ModChannel;
|
import com.linearpast.sccore.core.ModChannel;
|
||||||
import com.linearpast.sccore.core.ModCommands;
|
import com.linearpast.sccore.core.ModCommands;
|
||||||
|
|
@ -34,7 +34,7 @@ public class SnowyCrescentCore {
|
||||||
|
|
||||||
CapabilityUtils.registerHandler(forgeBus);
|
CapabilityUtils.registerHandler(forgeBus);
|
||||||
ModChannel.register();
|
ModChannel.register();
|
||||||
IAnimationHelper.register(forgeBus, modBus);
|
IAnimationService.register(forgeBus, modBus);
|
||||||
ModCommands.registerCommands(forgeBus, modBus);
|
ModCommands.registerCommands(forgeBus, modBus);
|
||||||
|
|
||||||
if(!FMLEnvironment.production || Boolean.getBoolean(ENABLE_EXAMPLES_PROPERTY_KEY)) {
|
if(!FMLEnvironment.production || Boolean.getBoolean(ENABLE_EXAMPLES_PROPERTY_KEY)) {
|
||||||
|
|
|
||||||
|
|
@ -1,33 +1,31 @@
|
||||||
package com.linearpast.sccore.animation;
|
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.resources.ResourceLocation;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class AnimationApi {
|
public class AnimationApi {
|
||||||
public static AnimationApi getInstance() {
|
public static AnimationJsonHelper getJsonHelper(MinecraftServer server) {
|
||||||
return new AnimationApi();
|
return AnimationJsonHelper.getHelper(server);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AnimationHelper getAnimationHelper() {
|
public static AnimationDataHelper getDataHelper() {
|
||||||
return AnimationHelper.INSTANCE;
|
return AnimationDataHelper.getHelper();
|
||||||
}
|
}
|
||||||
|
|
||||||
public RawAnimationHelper getRawAnimationHelper() {
|
public static AnimationServiceGetterHelper getServiceGetterHelper(ResourceLocation location) {
|
||||||
return RawAnimationHelper.INSTANCE;
|
return new AnimationServiceGetterHelper(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
public JsonHelper getJsonHelper(MinecraftServer server) {
|
public static AnimationServiceGetterHelper getServiceGetterHelper() {
|
||||||
return JsonHelper.getHelper(server);
|
return new AnimationServiceGetterHelper();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IAnimationHelper<?, ?> getHelperFromAnimKey(ResourceLocation location) {
|
public static AnimationHelper getHelper(Player player) {
|
||||||
return new HelperGetterFromAnimation(location).getHelper();
|
return AnimationHelper.getHelper(player);
|
||||||
}
|
|
||||||
|
|
||||||
public Set<IAnimationHelper<?, ?>> getAllHelpers() {
|
|
||||||
return IHelperGetter.HELPERS;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,9 @@ package com.linearpast.sccore.animation.capability;
|
||||||
|
|
||||||
import com.linearpast.sccore.SnowyCrescentCore;
|
import com.linearpast.sccore.SnowyCrescentCore;
|
||||||
import com.linearpast.sccore.animation.capability.inter.IAnimationCapability;
|
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.network.toclient.AnimationCapabilityPacket;
|
||||||
import com.linearpast.sccore.animation.register.AnimationRegistry;
|
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.CapabilityUtils;
|
||||||
import com.linearpast.sccore.capability.data.ICapabilitySync;
|
import com.linearpast.sccore.capability.data.ICapabilitySync;
|
||||||
import com.linearpast.sccore.capability.data.player.SimplePlayerCapabilitySync;
|
import com.linearpast.sccore.capability.data.player.SimplePlayerCapabilitySync;
|
||||||
|
|
@ -35,7 +35,7 @@ public class AnimationDataCapability extends SimplePlayerCapabilitySync implemen
|
||||||
public void mergeAnimations(Map<ResourceLocation, ResourceLocation> animations) {
|
public void mergeAnimations(Map<ResourceLocation, ResourceLocation> animations) {
|
||||||
animations.forEach((key, value) -> {
|
animations.forEach((key, value) -> {
|
||||||
if (AnimationRegistry.getLayers().containsKey(key)) {
|
if (AnimationRegistry.getLayers().containsKey(key)) {
|
||||||
if (AnimationHelper.INSTANCE.isAnimationPresent(value)) {
|
if (AnimationService.INSTANCE.isAnimationPresent(value)) {
|
||||||
if(Objects.equals(rideAnimLayer, key)) {
|
if(Objects.equals(rideAnimLayer, key)) {
|
||||||
removeRiderAnimation();
|
removeRiderAnimation();
|
||||||
}
|
}
|
||||||
|
|
@ -49,7 +49,7 @@ public class AnimationDataCapability extends SimplePlayerCapabilitySync implemen
|
||||||
@Override
|
@Override
|
||||||
public boolean mergeAnimation(ResourceLocation layer, ResourceLocation animation) {
|
public boolean mergeAnimation(ResourceLocation layer, ResourceLocation animation) {
|
||||||
if (AnimationRegistry.getLayers().containsKey(layer)) {
|
if (AnimationRegistry.getLayers().containsKey(layer)) {
|
||||||
if (AnimationHelper.INSTANCE.isAnimationPresent(animation)) {
|
if (AnimationService.INSTANCE.isAnimationPresent(animation)) {
|
||||||
if(Objects.equals(rideAnimLayer, layer)) {
|
if(Objects.equals(rideAnimLayer, layer)) {
|
||||||
removeRiderAnimation();
|
removeRiderAnimation();
|
||||||
}
|
}
|
||||||
|
|
@ -105,8 +105,7 @@ public class AnimationDataCapability extends SimplePlayerCapabilitySync implemen
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setRiderAnimation(@NotNull ResourceLocation layer, @NotNull ResourceLocation animation) {
|
public void setRiderAnimation(@NotNull ResourceLocation layer, @NotNull ResourceLocation animation) {
|
||||||
if(AnimationHelper.INSTANCE.isAnimationLayerPresent(layer)) {
|
if(AnimationService.INSTANCE.isAnimationLayerPresent(layer)) {
|
||||||
if(AnimationHelper.INSTANCE.isAnimationPresent(animation)) {
|
|
||||||
this.rideAnimLayer = layer;
|
this.rideAnimLayer = layer;
|
||||||
this.rideAnimation = animation;
|
this.rideAnimation = animation;
|
||||||
if(animMap.get(layer) != null) {
|
if(animMap.get(layer) != null) {
|
||||||
|
|
@ -115,7 +114,6 @@ public class AnimationDataCapability extends SimplePlayerCapabilitySync implemen
|
||||||
setDirty(true);
|
setDirty(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeRiderAnimation() {
|
public void removeRiderAnimation() {
|
||||||
|
|
@ -177,10 +175,10 @@ public class AnimationDataCapability extends SimplePlayerCapabilitySync implemen
|
||||||
public void attachInit(Player player) {
|
public void attachInit(Player player) {
|
||||||
Map<ResourceLocation, ResourceLocation> map = new HashMap<>(this.animMap);
|
Map<ResourceLocation, ResourceLocation> map = new HashMap<>(this.animMap);
|
||||||
map.forEach((key, value) -> {
|
map.forEach((key, value) -> {
|
||||||
if(!AnimationHelper.INSTANCE.isAnimationLayerPresent(key)) this.animMap.remove(key);
|
if(!AnimationService.INSTANCE.isAnimationLayerPresent(key)) this.animMap.remove(key);
|
||||||
if(!AnimationHelper.INSTANCE.isAnimationPresent(value)) 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();
|
removeRiderAnimation();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ package com.linearpast.sccore.animation.capability;
|
||||||
|
|
||||||
import com.linearpast.sccore.SnowyCrescentCore;
|
import com.linearpast.sccore.SnowyCrescentCore;
|
||||||
import com.linearpast.sccore.animation.capability.inter.IAnimationCapability;
|
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.network.toclient.RawAnimationCapabilityPacket;
|
||||||
import com.linearpast.sccore.animation.register.AnimationRegistry;
|
import com.linearpast.sccore.animation.register.AnimationRegistry;
|
||||||
import com.linearpast.sccore.capability.CapabilityUtils;
|
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 com.linearpast.sccore.capability.network.SimpleCapabilityPacket;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
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.minecraft.world.entity.player.Player;
|
||||||
import net.minecraftforge.server.ServerLifecycleHooks;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public class RawAnimationDataCapability extends SimplePlayerCapabilitySync {
|
public class RawAnimationDataCapability extends SimplePlayerCapabilitySync {
|
||||||
public static final ResourceLocation key = new ResourceLocation(SnowyCrescentCore.MODID, "raw_animation_data");
|
public static final ResourceLocation key = new ResourceLocation(SnowyCrescentCore.MODID, "raw_animation_data");
|
||||||
|
|
||||||
public static final String AnimMap = "AnimMap";
|
public static final String AnimMap = "AnimMap";
|
||||||
public static final String RideAnimLayer = "RideAnimLayer";
|
|
||||||
public static final String RideAnimation = "RideAnimation";
|
|
||||||
|
|
||||||
private final Map<ResourceLocation, ResourceLocation> animMap = new HashMap<>();
|
private final Map<ResourceLocation, ResourceLocation> animMap = new HashMap<>();
|
||||||
private ResourceLocation rideAnimLayer;
|
|
||||||
private ResourceLocation rideAnimation;
|
|
||||||
|
|
||||||
public boolean mergeAnimation(ResourceLocation layer, ResourceLocation animation) {
|
public boolean mergeAnimation(ResourceLocation layer, ResourceLocation animation) {
|
||||||
if (AnimationRegistry.getLayers().containsKey(layer)) {
|
if (AnimationRegistry.getLayers().containsKey(layer)) {
|
||||||
if(Objects.equals(rideAnimLayer, layer)) {
|
|
||||||
removeRiderAnimation();
|
|
||||||
}
|
|
||||||
this.animMap.put(layer, animation);
|
this.animMap.put(layer, animation);
|
||||||
setDirty(true);
|
setDirty(true);
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -73,49 +60,11 @@ public class RawAnimationDataCapability extends SimplePlayerCapabilitySync {
|
||||||
return animMap.containsKey(layer);
|
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
|
@Override
|
||||||
public void copyFrom(ICapabilitySync<?> oldData) {
|
public void copyFrom(ICapabilitySync<?> oldData) {
|
||||||
IAnimationCapability data = (IAnimationCapability) oldData;
|
IAnimationCapability data = (IAnimationCapability) oldData;
|
||||||
this.animMap.clear();
|
this.animMap.clear();
|
||||||
this.animMap.putAll(data.getAnimations());
|
this.animMap.putAll(data.getAnimations());
|
||||||
this.rideAnimLayer = data.getRiderAnimLayer();
|
|
||||||
this.rideAnimation = data.getRiderAnimation();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -127,16 +76,12 @@ public class RawAnimationDataCapability extends SimplePlayerCapabilitySync {
|
||||||
);
|
);
|
||||||
tag.put(AnimMap, animMapTag);
|
tag.put(AnimMap, animMapTag);
|
||||||
}
|
}
|
||||||
if(rideAnimLayer != null) tag.putString(RideAnimLayer, rideAnimLayer.toString());
|
|
||||||
if(rideAnimation != null) tag.putString(RideAnimation, rideAnimation.toString());
|
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fromTag(CompoundTag tag) {
|
public void fromTag(CompoundTag tag) {
|
||||||
this.animMap.clear();
|
this.animMap.clear();
|
||||||
this.rideAnimLayer = null;
|
|
||||||
this.rideAnimation = null;
|
|
||||||
if(tag.contains(AnimMap)) {
|
if(tag.contains(AnimMap)) {
|
||||||
CompoundTag animMapTag = tag.getCompound(AnimMap);
|
CompoundTag animMapTag = tag.getCompound(AnimMap);
|
||||||
animMapTag.getAllKeys().forEach(key -> this.animMap.put(
|
animMapTag.getAllKeys().forEach(key -> this.animMap.put(
|
||||||
|
|
@ -144,8 +89,6 @@ public class RawAnimationDataCapability extends SimplePlayerCapabilitySync {
|
||||||
new ResourceLocation(animMapTag.getString(key))
|
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
|
@Override
|
||||||
|
|
@ -161,7 +104,6 @@ public class RawAnimationDataCapability extends SimplePlayerCapabilitySync {
|
||||||
@Override
|
@Override
|
||||||
public void attachInit(Player entity) {
|
public void attachInit(Player entity) {
|
||||||
clearAnimations();
|
clearAnimations();
|
||||||
removeRiderAnimation();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Optional<RawAnimationDataCapability> getCapability(Player player){
|
public static Optional<RawAnimationDataCapability> getCapability(Player player){
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,8 @@
|
||||||
package com.linearpast.sccore.animation.command;
|
package com.linearpast.sccore.animation.command;
|
||||||
|
|
||||||
import com.linearpast.sccore.SnowyCrescentCore;
|
import com.linearpast.sccore.SnowyCrescentCore;
|
||||||
|
import com.linearpast.sccore.animation.AnimationApi;
|
||||||
import com.linearpast.sccore.animation.command.exception.ApiBackException;
|
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.animation.utils.ApiBack;
|
||||||
import com.linearpast.sccore.core.configs.ModConfigs;
|
import com.linearpast.sccore.core.configs.ModConfigs;
|
||||||
import com.linearpast.sccore.core.datagen.ModLang;
|
import com.linearpast.sccore.core.datagen.ModLang;
|
||||||
|
|
@ -47,7 +45,7 @@ public class ApplyCommand {
|
||||||
Entity vehicle = target.getVehicle();
|
Entity vehicle = target.getVehicle();
|
||||||
if(vehicle == null) throw new ApiBackException(ApiBack.UNSUPPORTED);
|
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) {
|
if(back == ApiBack.COOLDOWN) {
|
||||||
int cooldown = ModConfigs.Server.applyCooldown.get();
|
int cooldown = ModConfigs.Server.applyCooldown.get();
|
||||||
throw ApiBackException.withCooldown(cooldown);
|
throw ApiBackException.withCooldown(cooldown);
|
||||||
|
|
@ -92,11 +90,7 @@ public class ApplyCommand {
|
||||||
Entity vehicle = player.getVehicle();
|
Entity vehicle = player.getVehicle();
|
||||||
if(vehicle == null) throw new ApiBackException(ApiBack.UNSUPPORTED);
|
if(vehicle == null) throw new ApiBackException(ApiBack.UNSUPPORTED);
|
||||||
|
|
||||||
ApiBack back = ApiBack.RESOURCE_NOT_FOUND;
|
ApiBack back = AnimationApi.getHelper(player).acceptApply(applier);
|
||||||
for (IAnimationHelper<?, ?> helper : IHelperGetter.HELPERS) {
|
|
||||||
back = helper.acceptApply(player, applier);
|
|
||||||
if(back == ApiBack.SUCCESS) break;
|
|
||||||
}
|
|
||||||
if(back == ApiBack.OUT_RANGE) throw ApiBackException.withOutRange(ModConfigs.Server.applyValidDistance.get());
|
if(back == ApiBack.OUT_RANGE) throw ApiBackException.withOutRange(ModConfigs.Server.applyValidDistance.get());
|
||||||
if(back != ApiBack.SUCCESS) throw new ApiBackException(back);
|
if(back != ApiBack.SUCCESS) throw new ApiBackException(back);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,10 @@
|
||||||
package com.linearpast.sccore.animation.command;
|
package com.linearpast.sccore.animation.command;
|
||||||
|
|
||||||
import com.linearpast.sccore.SnowyCrescentCore;
|
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.AnimationArgument;
|
||||||
import com.linearpast.sccore.animation.command.argument.AnimationLayerArgument;
|
import com.linearpast.sccore.animation.command.argument.AnimationLayerArgument;
|
||||||
import com.linearpast.sccore.animation.command.exception.ApiBackException;
|
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.animation.utils.ApiBack;
|
||||||
import com.linearpast.sccore.core.configs.ModConfigs;
|
import com.linearpast.sccore.core.configs.ModConfigs;
|
||||||
import com.linearpast.sccore.core.datagen.ModLang;
|
import com.linearpast.sccore.core.datagen.ModLang;
|
||||||
|
|
@ -61,14 +57,8 @@ public class InviteCommand {
|
||||||
ResourceLocation anim = new ResourceLocation(animString);
|
ResourceLocation anim = new ResourceLocation(animString);
|
||||||
|
|
||||||
//test info present
|
//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<UUID> targets = players.stream().map(Entity::getUUID).toList();
|
List<UUID> 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) {
|
if(back == ApiBack.COOLDOWN) {
|
||||||
int cooldown = ModConfigs.Server.inviteCooldown.get();
|
int cooldown = ModConfigs.Server.inviteCooldown.get();
|
||||||
throw ApiBackException.withCooldown(cooldown);
|
throw ApiBackException.withCooldown(cooldown);
|
||||||
|
|
@ -111,11 +101,7 @@ public class InviteCommand {
|
||||||
ServerPlayer inviter = EntityArgument.getPlayer(context, "player");
|
ServerPlayer inviter = EntityArgument.getPlayer(context, "player");
|
||||||
|
|
||||||
//play animation
|
//play animation
|
||||||
ApiBack back = ApiBack.RESOURCE_NOT_FOUND;
|
ApiBack back = AnimationApi.getHelper(player).acceptInvite(inviter);
|
||||||
for (IAnimationHelper<?, ?> helper : IHelperGetter.HELPERS) {
|
|
||||||
back = helper.acceptInvite(player, inviter);
|
|
||||||
if(back == ApiBack.SUCCESS) break;
|
|
||||||
}
|
|
||||||
if(back == ApiBack.OUT_RANGE) throw ApiBackException.withOutRange(ModConfigs.Server.inviteValidDistance.get());
|
if(back == ApiBack.OUT_RANGE) throw ApiBackException.withOutRange(ModConfigs.Server.inviteValidDistance.get());
|
||||||
if(back != ApiBack.SUCCESS) throw new ApiBackException(back);
|
if(back != ApiBack.SUCCESS) throw new ApiBackException(back);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package com.linearpast.sccore.animation.command;
|
package com.linearpast.sccore.animation.command;
|
||||||
|
|
||||||
import com.linearpast.sccore.SnowyCrescentCore;
|
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.linearpast.sccore.core.datagen.ModLang;
|
||||||
import com.mojang.brigadier.arguments.BoolArgumentType;
|
import com.mojang.brigadier.arguments.BoolArgumentType;
|
||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
|
|
@ -46,7 +46,7 @@ public class JsonCommand {
|
||||||
CommandSourceStack source = context.getSource();
|
CommandSourceStack source = context.getSource();
|
||||||
try {
|
try {
|
||||||
//generate
|
//generate
|
||||||
JsonHelper helper = JsonHelper.getHelper(source.getServer());
|
AnimationJsonHelper helper = AnimationJsonHelper.getHelper(source.getServer());
|
||||||
Path path = helper.generateJson(isLayer, isReset);
|
Path path = helper.generateJson(isLayer, isReset);
|
||||||
|
|
||||||
if(path == null) throw new Exception();
|
if(path == null) throw new Exception();
|
||||||
|
|
@ -75,7 +75,7 @@ public class JsonCommand {
|
||||||
CommandSourceStack source = context.getSource();
|
CommandSourceStack source = context.getSource();
|
||||||
try {
|
try {
|
||||||
//clear path
|
//clear path
|
||||||
JsonHelper.getHelper(source.getServer()).clearPath();
|
AnimationJsonHelper.getHelper(source.getServer()).clearPath();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
source.sendFailure(Component.translatable(
|
source.sendFailure(Component.translatable(
|
||||||
ModLang.TranslatableMessage.COMMAND_RUN_FAIL.getKey()
|
ModLang.TranslatableMessage.COMMAND_RUN_FAIL.getKey()
|
||||||
|
|
@ -90,7 +90,7 @@ public class JsonCommand {
|
||||||
CommandSourceStack source = context.getSource();
|
CommandSourceStack source = context.getSource();
|
||||||
try {
|
try {
|
||||||
//generate
|
//generate
|
||||||
JsonHelper helper = JsonHelper.getHelper(source.getServer());
|
AnimationJsonHelper helper = AnimationJsonHelper.getHelper(source.getServer());
|
||||||
Path path = helper.generateExample();
|
Path path = helper.generateExample();
|
||||||
if(path == null) throw new Exception();
|
if(path == null) throw new Exception();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,15 @@
|
||||||
package com.linearpast.sccore.animation.command;
|
package com.linearpast.sccore.animation.command;
|
||||||
|
|
||||||
import com.linearpast.sccore.SnowyCrescentCore;
|
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.AnimationArgument;
|
||||||
import com.linearpast.sccore.animation.command.argument.AnimationLayerArgument;
|
import com.linearpast.sccore.animation.command.argument.AnimationLayerArgument;
|
||||||
import com.linearpast.sccore.animation.command.exception.ApiBackException;
|
import com.linearpast.sccore.animation.command.exception.ApiBackException;
|
||||||
import com.linearpast.sccore.animation.data.AnimationData;
|
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.animation.utils.ApiBack;
|
||||||
import com.linearpast.sccore.core.datagen.ModLang;
|
import com.linearpast.sccore.core.datagen.ModLang;
|
||||||
import com.mojang.brigadier.arguments.BoolArgumentType;
|
import com.mojang.brigadier.arguments.BoolArgumentType;
|
||||||
|
|
@ -90,7 +94,7 @@ public class PlayCommand {
|
||||||
ResourceLocation anim = new ResourceLocation(animString);
|
ResourceLocation anim = new ResourceLocation(animString);
|
||||||
|
|
||||||
//play with players
|
//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);
|
if (helper == null) throw new ApiBackException(ApiBack.RESOURCE_NOT_FOUND);
|
||||||
AnimationData animationData = helper.getAnimation(anim);
|
AnimationData animationData = helper.getAnimation(anim);
|
||||||
if(animationData == null) throw new ApiBackException(ApiBack.RESOURCE_NOT_FOUND);
|
if(animationData == null) throw new ApiBackException(ApiBack.RESOURCE_NOT_FOUND);
|
||||||
|
|
@ -134,7 +138,7 @@ public class PlayCommand {
|
||||||
} else {
|
} else {
|
||||||
//play with self
|
//play with self
|
||||||
ApiBack back;
|
ApiBack back;
|
||||||
RawAnimationHelper instance = RawAnimationHelper.INSTANCE;
|
RawAnimationService instance = RawAnimationService.INSTANCE;
|
||||||
if(withRide) back = instance.playAnimationWithRide(player, layer, animationData, false);
|
if(withRide) back = instance.playAnimationWithRide(player, layer, animationData, false);
|
||||||
else back = instance.playAnimation(player, layer, animationData);
|
else back = instance.playAnimation(player, layer, animationData);
|
||||||
|
|
||||||
|
|
@ -166,11 +170,10 @@ public class PlayCommand {
|
||||||
ResourceLocation layerLocation = new ResourceLocation(layer);
|
ResourceLocation layerLocation = new ResourceLocation(layer);
|
||||||
|
|
||||||
//remove with players
|
//remove with players
|
||||||
AnimationHelper instance = AnimationHelper.INSTANCE;
|
|
||||||
if(!targets.isEmpty()) {
|
if(!targets.isEmpty()) {
|
||||||
Set<ServerPlayer> playerSet = Set.copyOf(targets);
|
Set<ServerPlayer> playerSet = Set.copyOf(targets);
|
||||||
playerSet.forEach(p -> {
|
playerSet.forEach(p -> {
|
||||||
ApiBack back = instance.removeAnimation(p, layerLocation);
|
ApiBack back = AnimationApi.getHelper(p).removeAnimation(layerLocation);
|
||||||
if (back == ApiBack.SUCCESS) targets.remove(p);
|
if (back == ApiBack.SUCCESS) targets.remove(p);
|
||||||
});
|
});
|
||||||
int successNum = playerSet.size() - targets.size();
|
int successNum = playerSet.size() - targets.size();
|
||||||
|
|
@ -196,7 +199,7 @@ public class PlayCommand {
|
||||||
).withStyle(ChatFormatting.RED));
|
).withStyle(ChatFormatting.RED));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ApiBack back = instance.removeAnimation(player, layerLocation);
|
ApiBack back = AnimationApi.getHelper(player).removeAnimation(layerLocation);
|
||||||
if (back != ApiBack.SUCCESS) throw new ApiBackException(back);
|
if (back != ApiBack.SUCCESS) throw new ApiBackException(back);
|
||||||
|
|
||||||
source.sendSuccess(() -> Component.translatable(
|
source.sendSuccess(() -> Component.translatable(
|
||||||
|
|
@ -221,12 +224,11 @@ public class PlayCommand {
|
||||||
Collection<ServerPlayer> players;
|
Collection<ServerPlayer> players;
|
||||||
try {players = EntityArgument.getPlayers(context, "players");}
|
try {players = EntityArgument.getPlayers(context, "players");}
|
||||||
catch (Exception ignored) { players = Set.of(source.getPlayerOrException()); }
|
catch (Exception ignored) { players = Set.of(source.getPlayerOrException()); }
|
||||||
Set.copyOf(players).forEach(player -> IHelperGetter.HELPERS.forEach(
|
Set.copyOf(players).forEach(player -> {
|
||||||
helper -> {
|
AnimationHelper helper = AnimationApi.getHelper(player);
|
||||||
helper.clearAnimations(player);
|
helper.clearAnimation();
|
||||||
helper.detachAnimation(player);
|
helper.detachAnimation();
|
||||||
}
|
});
|
||||||
));
|
|
||||||
source.sendSuccess(() -> Component.translatable(
|
source.sendSuccess(() -> Component.translatable(
|
||||||
ModLang.TranslatableMessage.CLEAR_ANIMATIONS.getKey()
|
ModLang.TranslatableMessage.CLEAR_ANIMATIONS.getKey()
|
||||||
).withStyle(ChatFormatting.GREEN), true);
|
).withStyle(ChatFormatting.GREEN), true);
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,10 @@
|
||||||
package com.linearpast.sccore.animation.command;
|
package com.linearpast.sccore.animation.command;
|
||||||
|
|
||||||
import com.linearpast.sccore.SnowyCrescentCore;
|
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.AnimationArgument;
|
||||||
import com.linearpast.sccore.animation.command.argument.AnimationLayerArgument;
|
import com.linearpast.sccore.animation.command.argument.AnimationLayerArgument;
|
||||||
import com.linearpast.sccore.animation.command.exception.ApiBackException;
|
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.animation.utils.ApiBack;
|
||||||
import com.linearpast.sccore.core.configs.ModConfigs;
|
import com.linearpast.sccore.core.configs.ModConfigs;
|
||||||
import com.linearpast.sccore.core.datagen.ModLang;
|
import com.linearpast.sccore.core.datagen.ModLang;
|
||||||
|
|
@ -63,13 +59,7 @@ public class RequestCommand {
|
||||||
ResourceLocation layer = new ResourceLocation(layerString);
|
ResourceLocation layer = new ResourceLocation(layerString);
|
||||||
ResourceLocation anim = new ResourceLocation(animString);
|
ResourceLocation anim = new ResourceLocation(animString);
|
||||||
|
|
||||||
IAnimationHelper<?, ?> helper = HelperGetterFromAnimation.create(anim).getHelper();
|
ApiBack back = AnimationApi.getHelper(player).requestAnimation(target, layer, anim, withRide);
|
||||||
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);
|
|
||||||
if(back == ApiBack.COOLDOWN) {
|
if(back == ApiBack.COOLDOWN) {
|
||||||
int cooldown = ModConfigs.Server.requestCooldown.get();
|
int cooldown = ModConfigs.Server.requestCooldown.get();
|
||||||
throw ApiBackException.withCooldown(cooldown);
|
throw ApiBackException.withCooldown(cooldown);
|
||||||
|
|
@ -111,11 +101,7 @@ public class RequestCommand {
|
||||||
ServerPlayer requestor = EntityArgument.getPlayer(context, "requestor");
|
ServerPlayer requestor = EntityArgument.getPlayer(context, "requestor");
|
||||||
|
|
||||||
//play
|
//play
|
||||||
ApiBack back = ApiBack.RESOURCE_NOT_FOUND;
|
ApiBack back = AnimationApi.getHelper(player).acceptRequest(requestor);
|
||||||
for (IAnimationHelper<?, ?> helper : IHelperGetter.HELPERS) {
|
|
||||||
back = helper.acceptRequest(player, requestor);
|
|
||||||
if(back == ApiBack.SUCCESS) break;
|
|
||||||
}
|
|
||||||
if(back != ApiBack.SUCCESS) throw new ApiBackException(back);
|
if(back != ApiBack.SUCCESS) throw new ApiBackException(back);
|
||||||
|
|
||||||
//send message
|
//send message
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package com.linearpast.sccore.animation.command.client;
|
package com.linearpast.sccore.animation.command.client;
|
||||||
|
|
||||||
import com.linearpast.sccore.SnowyCrescentCore;
|
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.linearpast.sccore.core.datagen.ModLang;
|
||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
import com.mojang.brigadier.context.CommandContext;
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
|
|
@ -27,7 +27,7 @@ public class RefreshCommand {
|
||||||
Minecraft instance = Minecraft.getInstance();
|
Minecraft instance = Minecraft.getInstance();
|
||||||
LocalPlayer player = instance.player;
|
LocalPlayer player = instance.player;
|
||||||
if(player == null) throw new RuntimeException();
|
if(player == null) throw new RuntimeException();
|
||||||
AnimationHelper.INSTANCE.refreshAnimation(player);
|
AnimationApi.getHelper(player).refreshAnimation();
|
||||||
source.sendSuccess(() -> Component.translatable(
|
source.sendSuccess(() -> Component.translatable(
|
||||||
ModLang.TranslatableMessage.REFRESH_ANIMATIONS.getKey()
|
ModLang.TranslatableMessage.REFRESH_ANIMATIONS.getKey()
|
||||||
).withStyle(ChatFormatting.GREEN), true);
|
).withStyle(ChatFormatting.GREEN), true);
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,10 @@ package com.linearpast.sccore.animation.entity;
|
||||||
|
|
||||||
import com.linearpast.sccore.animation.capability.AnimationDataCapability;
|
import com.linearpast.sccore.animation.capability.AnimationDataCapability;
|
||||||
import com.linearpast.sccore.animation.capability.inter.IAnimationCapability;
|
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.data.Ride;
|
||||||
import com.linearpast.sccore.animation.helper.AnimationHelper;
|
|
||||||
import com.linearpast.sccore.animation.register.AnimationEntities;
|
import com.linearpast.sccore.animation.register.AnimationEntities;
|
||||||
|
import com.linearpast.sccore.animation.service.AnimationService;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.network.protocol.Packet;
|
import net.minecraft.network.protocol.Packet;
|
||||||
import net.minecraft.network.protocol.game.ClientGamePacketListener;
|
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.minecraft.world.phys.Vec3;
|
||||||
import net.minecraftforge.network.NetworkHooks;
|
import net.minecraftforge.network.NetworkHooks;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
|
@ -28,10 +29,10 @@ public class AnimationRideEntity extends Entity {
|
||||||
|
|
||||||
private final Set<ServerPlayer> players = new HashSet<>();
|
private final Set<ServerPlayer> players = new HashSet<>();
|
||||||
private final Map<ResourceLocation, UUID> animationPair = new HashMap<>();
|
private final Map<ResourceLocation, UUID> animationPair = new HashMap<>();
|
||||||
private GenericAnimationData animation;
|
private AnimationData animation;
|
||||||
private ServerPlayer player;
|
private ServerPlayer player;
|
||||||
private ResourceLocation layer;
|
private ResourceLocation layer;
|
||||||
public AnimationRideEntity(ServerPlayer pPlayer, ResourceLocation layer, GenericAnimationData animation) {
|
public AnimationRideEntity(ServerPlayer pPlayer, ResourceLocation layer, AnimationData animation) {
|
||||||
this(pPlayer.level());
|
this(pPlayer.level());
|
||||||
this.player = pPlayer;
|
this.player = pPlayer;
|
||||||
this.layer = layer;
|
this.layer = layer;
|
||||||
|
|
@ -57,7 +58,7 @@ public class AnimationRideEntity extends Entity {
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GenericAnimationData getAnimation() {
|
public AnimationData getAnimation() {
|
||||||
return animation;
|
return animation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -101,13 +102,13 @@ public class AnimationRideEntity extends Entity {
|
||||||
return NetworkHooks.getEntitySpawningPacket(this);
|
return NetworkHooks.getEntitySpawningPacket(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean create(ServerPlayer pPlayer, ResourceLocation layer, ResourceLocation animation, boolean force) {
|
@Nullable
|
||||||
GenericAnimationData anim = AnimationHelper.INSTANCE.getAnimation(animation);
|
public static AnimationRideEntity create(ServerPlayer pPlayer, ResourceLocation layer, AnimationData anim, boolean force) {
|
||||||
if(anim == null) return false;
|
if(anim == null) return null;
|
||||||
if(anim.getRide() == null) return false;
|
if(anim.getRide() == null) return null;
|
||||||
IAnimationCapability data = AnimationDataCapability.getCapability(pPlayer).orElse(null);
|
IAnimationCapability data = AnimationDataCapability.getCapability(pPlayer).orElse(null);
|
||||||
if(data == null) return false;
|
if(data == null) return null;
|
||||||
data.setRiderAnimation(layer, animation);
|
data.setRiderAnimation(layer, anim.getKey());
|
||||||
AnimationRideEntity seat = new AnimationRideEntity(pPlayer, layer, anim);
|
AnimationRideEntity seat = new AnimationRideEntity(pPlayer, layer, anim);
|
||||||
float xRot = anim.getRide().getXRot();
|
float xRot = anim.getRide().getXRot();
|
||||||
float yRot = anim.getRide().getYRot();
|
float yRot = anim.getRide().getYRot();
|
||||||
|
|
@ -118,7 +119,7 @@ public class AnimationRideEntity extends Entity {
|
||||||
seat.setPos(pos.x, pos.y + 0.35f, pos.z);
|
seat.setPos(pos.x, pos.y + 0.35f, pos.z);
|
||||||
pPlayer.level().addFreshEntity(seat);
|
pPlayer.level().addFreshEntity(seat);
|
||||||
pPlayer.startRiding(seat, force);
|
pPlayer.startRiding(seat, force);
|
||||||
return true;
|
return seat;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -163,7 +164,7 @@ public class AnimationRideEntity extends Entity {
|
||||||
IAnimationCapability data = AnimationDataCapability.getCapability(serverPlayer).orElse(null);
|
IAnimationCapability data = AnimationDataCapability.getCapability(serverPlayer).orElse(null);
|
||||||
if(data == null) return;
|
if(data == null) return;
|
||||||
data.setRiderAnimation(layer, animLocation);
|
data.setRiderAnimation(layer, animLocation);
|
||||||
AnimationHelper.INSTANCE.syncAnimation(serverPlayer, player);
|
AnimationService.INSTANCE.syncAnimation(serverPlayer, player);
|
||||||
players.add(serverPlayer);
|
players.add(serverPlayer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -172,7 +173,7 @@ public class AnimationRideEntity extends Entity {
|
||||||
protected void removePassenger(@NotNull Entity entity) {
|
protected void removePassenger(@NotNull Entity entity) {
|
||||||
super.removePassenger(entity);
|
super.removePassenger(entity);
|
||||||
if(entity instanceof ServerPlayer serverPlayer) {
|
if(entity instanceof ServerPlayer serverPlayer) {
|
||||||
AnimationHelper.INSTANCE.removeAnimation(serverPlayer, layer);
|
AnimationService.INSTANCE.removeAnimation(serverPlayer, layer);
|
||||||
players.remove(serverPlayer);
|
players.remove(serverPlayer);
|
||||||
new HashMap<>(animationPair).forEach((key, value) -> {
|
new HashMap<>(animationPair).forEach((key, value) -> {
|
||||||
if(Objects.equals(value, serverPlayer.getUUID())) {
|
if(Objects.equals(value, serverPlayer.getUUID())) {
|
||||||
|
|
|
||||||
|
|
@ -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<ServerPlayer> players = new HashSet<>();
|
|
||||||
private final Map<ResourceLocation, UUID> 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<ResourceLocation> componentAnimations = ride.getComponentAnimations();
|
|
||||||
for (ResourceLocation componentAnimation : componentAnimations) {
|
|
||||||
animationPair.put(componentAnimation, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public ResourceLocation getLayer() {
|
|
||||||
return layer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<ServerPlayer> 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<ClientGamePacketListener> 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<ResourceLocation> 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,9 +1,7 @@
|
||||||
package com.linearpast.sccore.animation.event;
|
package com.linearpast.sccore.animation.event;
|
||||||
|
|
||||||
import com.linearpast.sccore.animation.capability.AnimationDataCapability;
|
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.AnimationRideEntity;
|
||||||
import com.linearpast.sccore.animation.entity.RawAnimationRideEntity;
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraftforge.event.TickEvent;
|
import net.minecraftforge.event.TickEvent;
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
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();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ package com.linearpast.sccore.animation.event.client;
|
||||||
import com.linearpast.sccore.animation.capability.AnimationDataCapability;
|
import com.linearpast.sccore.animation.capability.AnimationDataCapability;
|
||||||
import com.linearpast.sccore.animation.capability.inter.IAnimationCapability;
|
import com.linearpast.sccore.animation.capability.inter.IAnimationCapability;
|
||||||
import com.linearpast.sccore.animation.data.GenericAnimationData;
|
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 dev.kosmx.playerAnim.core.util.MathHelper;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.player.LocalPlayer;
|
import net.minecraft.client.player.LocalPlayer;
|
||||||
|
|
@ -35,7 +35,7 @@ public class CameraAnglesModify {
|
||||||
GenericAnimationData animation = null;
|
GenericAnimationData animation = null;
|
||||||
try {
|
try {
|
||||||
animation = data.getAnimations().values().stream()
|
animation = data.getAnimations().values().stream()
|
||||||
.map(AnimationHelper.INSTANCE::getAnimation)
|
.map(AnimationService.INSTANCE::getAnimation)
|
||||||
.min(Comparator.comparingDouble(anim -> {
|
.min(Comparator.comparingDouble(anim -> {
|
||||||
if (anim == null) return 1.0f;
|
if (anim == null) return 1.0f;
|
||||||
return anim.getHeightModifier();
|
return anim.getHeightModifier();
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package com.linearpast.sccore.animation.event.client;
|
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.client.player.AbstractClientPlayer;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
|
|
@ -19,7 +19,7 @@ public class ClientPlayerEvent {
|
||||||
Player player = event.player;
|
Player player = event.player;
|
||||||
if(player.tickCount % 10 != 0) return;
|
if(player.tickCount % 10 != 0) return;
|
||||||
if (!(player instanceof AbstractClientPlayer clientPlayer)) return;
|
if (!(player instanceof AbstractClientPlayer clientPlayer)) return;
|
||||||
AnimationHelper.INSTANCE.refreshAnimation(clientPlayer);
|
AnimationService.INSTANCE.refreshAnimation(clientPlayer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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<ResourceLocation> getAllAnimations() {
|
||||||
|
Set<ResourceLocation> set = new HashSet<>(getAnimationNames());
|
||||||
|
Set<ResourceLocation> strings = DistExecutor.unsafeCallWhenOn(Dist.CLIENT,
|
||||||
|
() -> this::getAnimationsClient);
|
||||||
|
if (strings != null && !strings.isEmpty()) set.addAll(strings);
|
||||||
|
return set;
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnlyIn(Dist.CLIENT)
|
||||||
|
private Set<ResourceLocation> getAnimationsClient() {
|
||||||
|
return new HashSet<>(RawAnimationRegistry.getAnimations().keySet());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Set<ResourceLocation> getAnimationNames(){
|
||||||
|
return new HashSet<>(AnimationRegistry.getAnimations().keySet());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<ResourceLocation> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,211 +1,253 @@
|
||||||
package com.linearpast.sccore.animation.helper;
|
package com.linearpast.sccore.animation.helper;
|
||||||
|
|
||||||
import com.linearpast.sccore.animation.capability.AnimationDataCapability;
|
import com.linearpast.sccore.animation.AnimationApi;
|
||||||
import com.linearpast.sccore.animation.capability.inter.IAnimationCapability;
|
|
||||||
import com.linearpast.sccore.animation.data.AnimationData;
|
import com.linearpast.sccore.animation.data.AnimationData;
|
||||||
import com.linearpast.sccore.animation.data.GenericAnimationData;
|
import com.linearpast.sccore.animation.service.IAnimationService;
|
||||||
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.utils.ApiBack;
|
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.client.player.AbstractClientPlayer;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.world.entity.Entity;
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||||
import net.minecraftforge.common.util.FakePlayer;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.Collection;
|
||||||
import java.util.Optional;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Objects;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
public class AnimationHelper {
|
||||||
* Animation Util. May be you can call it Api.
|
private final Player player;
|
||||||
*/
|
private final AnimationLazyHelper lazyRun;
|
||||||
public class AnimationHelper implements IAnimationHelper<GenericAnimationData, IAnimationCapability> {
|
AnimationHelper(Player player) {
|
||||||
public static final AnimationHelper INSTANCE = new AnimationHelper();
|
this.player = player;
|
||||||
|
this.lazyRun = new AnimationLazyHelper(player);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
public static AnimationHelper getHelper(Player player) {
|
||||||
* Get the LyingType when there are animations which playing on player. <br>
|
return new AnimationHelper(player);
|
||||||
* And It will return the first which be found.
|
}
|
||||||
* @param player Target player
|
|
||||||
* @return The first LyingType it find.
|
public ApiBack playAnimation(ResourceLocation layer, ResourceLocation location) {
|
||||||
*/
|
IAnimationService<?, ?> service = AnimationApi.getServiceGetterHelper(location).getService();
|
||||||
@Nullable
|
if(service == null) return ApiBack.FAIL;
|
||||||
public GenericAnimationData.LyingType getSideView(Player player) {
|
AnimationData data = service.getAnimation(location);
|
||||||
return ANIMATION_RUNNER.testLoadedAndCall(() -> {
|
if(data == null) return ApiBack.FAIL;
|
||||||
IAnimationCapability data = AnimationDataCapability.getCapability(player).orElse(null);
|
return lazyRun.testLoadedAndCall(
|
||||||
if(data == null) return null;
|
() -> service.playAnimation(lazyRun.getServerPlayer(), layer, data),
|
||||||
GenericAnimationData.LyingType lyingType = null;
|
() -> service.playAnimation(lazyRun.getClientPlayer(), layer, location)
|
||||||
for (ResourceLocation value : data.getAnimations().values()) {
|
);
|
||||||
GenericAnimationData animation = getAnimation(value);
|
}
|
||||||
if(animation == null) return null;
|
|
||||||
GenericAnimationData.LyingType type = animation.getLyingType();
|
public ApiBack playAnimationWithRide(ResourceLocation layer, AnimationData animation, boolean isForce) {
|
||||||
if(type == null) continue;
|
IAnimationService<?, ?> service = AnimationApi.getServiceGetterHelper(animation.getKey()).getService();
|
||||||
switch (type) {
|
if(service == null) return ApiBack.FAIL;
|
||||||
case FRONT,BACK -> {}
|
return lazyRun.testLoadedAndCall(
|
||||||
case LEFT,RIGHT -> lyingType = animation.getLyingType();
|
() -> service.playAnimationWithRide(lazyRun.getServerPlayer(), layer, animation, isForce),
|
||||||
|
() -> service.playAnimationWithRide(lazyRun.getClientPlayer(), layer, animation.getKey(), isForce)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearAnimation() {
|
||||||
|
for (IAnimationService<?, ?> service : AnimationApi.getServiceGetterHelper().getAllServices()) {
|
||||||
|
lazyRun.testLoadedAndRun(
|
||||||
|
() -> service.clearAnimations(lazyRun.getServerPlayer()),
|
||||||
|
() -> service.clearAnimations(lazyRun.getClientPlayer())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return lyingType;
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public ApiBack syncToAnimation(Player target) {
|
||||||
* Get the HeightModifier when there are animations which playing on player. <br>
|
ApiBack result = ApiBack.FAIL;
|
||||||
* And It will return the first which be found.
|
for (IAnimationService<?, ?> service : AnimationApi.getServiceGetterHelper().getAllServices()) {
|
||||||
* @param player Target player
|
ApiBack apiBack = lazyRun.testLoadedAndCall(() -> {
|
||||||
* @return The first HeightModifier it find.
|
if(!(target instanceof ServerPlayer targetPlayer)) return ApiBack.UNSUPPORTED;
|
||||||
*/
|
service.syncAnimation(lazyRun.getServerPlayer(), targetPlayer);
|
||||||
public float getHeightModifier(Player player) {
|
return ApiBack.SUCCESS;
|
||||||
Float result = ANIMATION_RUNNER.testLoadedAndCall(() -> {
|
}, () -> {
|
||||||
IAnimationCapability data = AnimationDataCapability.getCapability(player).orElse(null);
|
if(!(target instanceof AbstractClientPlayer targetPlayer)) return ApiBack.UNSUPPORTED;
|
||||||
if (data == null) return 1.0f;
|
service.syncAnimation(lazyRun.getClientPlayer(), targetPlayer);
|
||||||
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
|
|
||||||
public ApiBack detachAnimation(ServerPlayer player) {
|
|
||||||
return ANIMATION_RUNNER.testLoadedAndCall(() -> {
|
|
||||||
if(player.getVehicle() instanceof AnimationRideEntity) {
|
|
||||||
player.stopRiding();
|
|
||||||
return ApiBack.SUCCESS;
|
return ApiBack.SUCCESS;
|
||||||
}
|
|
||||||
return ApiBack.UNSUPPORTED;
|
|
||||||
});
|
});
|
||||||
|
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)
|
@OnlyIn(Dist.CLIENT)
|
||||||
public void refreshAnimation(AbstractClientPlayer clientPlayer) {
|
public void refreshAnimation() {
|
||||||
ANIMATION_RUNNER.testLoadedAndRun(() -> {
|
for (IAnimationService<?, ?> service : AnimationApi.getServiceGetterHelper().getAllServices()) {
|
||||||
IAnimationCapability data = getCapability(clientPlayer);
|
service.refreshAnimation(lazyRun.getClientPlayer());
|
||||||
if(data == null) return;
|
|
||||||
Set<ResourceLocation> oldLayers = new HashSet<>(data.getAnimations().keySet());
|
|
||||||
for (ResourceLocation layer : Set.copyOf(oldLayers)) {
|
|
||||||
if (AnimationUtils.isClientAnimationStop(clientPlayer, layer)) {
|
|
||||||
removeAnimation(clientPlayer, layer);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@OnlyIn(Dist.CLIENT)
|
||||||
public @Nullable ResourceLocation getAnimationPlaying(Player player, @Nullable ResourceLocation layer) {
|
public void refreshAnimationUnsafe() {
|
||||||
return ANIMATION_RUNNER.testLoadedAndCall(() -> {
|
for (IAnimationService<?, ?> service : AnimationApi.getServiceGetterHelper().getAllServices()) {
|
||||||
IAnimationCapability data = getCapability(player);
|
service.refreshAnimationUnsafe(lazyRun.getClientPlayer());
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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;
|
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<UUID> 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<AbstractClientPlayer> 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[]{}));
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
static class AnimationLazyHelper implements IModLazyRun {
|
||||||
|
private final Player player;
|
||||||
|
AnimationLazyHelper(Player player) {
|
||||||
|
this.player = player;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ApiBack removeAnimation(@NotNull ServerPlayer serverPlayer, ResourceLocation layer) {
|
public boolean testCondition() {
|
||||||
boolean result = ANIMATION_RUNNER.testLoadedAndCall(() -> Optional.ofNullable(getCapability(serverPlayer))
|
return player instanceof ServerPlayer;
|
||||||
.map(data -> data.removeAnimation(layer)).orElse(false));
|
|
||||||
return result ? ApiBack.SUCCESS : ApiBack.FAIL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public ServerPlayer getServerPlayer() {
|
||||||
public ApiBack playAnimationWithRide(@NotNull ServerPlayer player, ResourceLocation layer, AnimationData animation, boolean force) {
|
return (ServerPlayer) player;
|
||||||
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;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@OnlyIn(Dist.CLIENT)
|
||||||
public ApiBack playAnimationServer(@NotNull ServerPlayer player, ResourceLocation layer, AnimationData animation) {
|
public AbstractClientPlayer getClientPlayer() {
|
||||||
return ANIMATION_RUNNER.testLoadedAndCall(() -> {
|
return (AbstractClientPlayer) player;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,14 +13,14 @@ import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
|
||||||
public class JsonHelper {
|
public class AnimationJsonHelper {
|
||||||
private final MinecraftServer server;
|
private final MinecraftServer server;
|
||||||
JsonHelper(MinecraftServer server) {
|
AnimationJsonHelper(MinecraftServer server) {
|
||||||
this.server = server;
|
this.server = server;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JsonHelper getHelper(MinecraftServer server) {
|
public static AnimationJsonHelper getHelper(MinecraftServer server) {
|
||||||
return new JsonHelper(server);
|
return new AnimationJsonHelper(server);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -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<IAnimationService<?, ?>> getAllServices() {
|
||||||
|
return IAnimationServiceGetter.HELPERS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public <T extends IAnimationService<?, ?>> T getService(Class<T> tClass) {
|
||||||
|
IAnimationService<?, ?> service = getService();
|
||||||
|
if(tClass.isInstance(service)) return tClass.cast(service);
|
||||||
|
return 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -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<IAnimationService<?, ?>> 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);
|
||||||
|
}
|
||||||
|
|
@ -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<IAnimationHelper<?, ?>> 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);
|
|
||||||
}
|
|
||||||
|
|
@ -1,26 +1,26 @@
|
||||||
package com.linearpast.sccore.animation.network;
|
package com.linearpast.sccore.animation.network;
|
||||||
|
|
||||||
import com.linearpast.sccore.animation.helper.AnimationHelper;
|
import com.linearpast.sccore.animation.helper.IAnimationServiceGetter;
|
||||||
import com.linearpast.sccore.animation.helper.IAnimationHelper;
|
import com.linearpast.sccore.animation.service.AnimationService;
|
||||||
import com.linearpast.sccore.animation.helper.IHelperGetter;
|
import com.linearpast.sccore.animation.service.IAnimationService;
|
||||||
import com.linearpast.sccore.animation.helper.RawAnimationHelper;
|
import com.linearpast.sccore.animation.service.RawAnimationService;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import org.jetbrains.annotations.Nullable;
|
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
|
* Override it to filter helper in network packet
|
||||||
* @param helper helper
|
* @param helper helper
|
||||||
* @return Is right helper
|
* @return Is right helper
|
||||||
*/
|
*/
|
||||||
public boolean filter(IAnimationHelper<?, ?> helper) {
|
public boolean filter(IAnimationService<?, ?> helper) {
|
||||||
if(helper instanceof AnimationHelper animationHelper) {
|
if(helper instanceof AnimationService service) {
|
||||||
ResourceLocation animation = getAnimation();
|
ResourceLocation animation = getAnimation();
|
||||||
if(animation != null) return animationHelper.isAnimationPresent(animation);
|
if(animation != null) return service.isAnimationPresent(animation);
|
||||||
} else if (helper instanceof RawAnimationHelper rawHelper) {
|
} else if (helper instanceof RawAnimationService service) {
|
||||||
CompoundTag tag = getAnimationTag();
|
CompoundTag tag = getAnimationTag();
|
||||||
if(tag != null) return rawHelper.getAnimation(tag) != null;
|
if(tag != null) return service.getAnimation(tag) != null;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -28,7 +28,7 @@ public abstract class HelperGetterPacket implements IHelperGetter {
|
||||||
/**
|
/**
|
||||||
* Selectable to override it
|
* Selectable to override it
|
||||||
* @return Animation loacation
|
* @return Animation loacation
|
||||||
* @see HelperGetterPacket#filter
|
* @see ServiceGetterPacket#filter
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
protected ResourceLocation getAnimation() {
|
protected ResourceLocation getAnimation() {
|
||||||
|
|
@ -38,7 +38,7 @@ public abstract class HelperGetterPacket implements IHelperGetter {
|
||||||
/**
|
/**
|
||||||
* Selectable to override it
|
* Selectable to override it
|
||||||
* @return Animation data
|
* @return Animation data
|
||||||
* @see HelperGetterPacket#filter
|
* @see ServiceGetterPacket#filter
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
protected CompoundTag getAnimationTag() {
|
protected CompoundTag getAnimationTag() {
|
||||||
|
|
@ -45,16 +45,6 @@ public class RawAnimationCapabilityPacket extends SimpleCapabilityPacket<Player>
|
||||||
|
|
||||||
private void testPlayAnimations(AbstractClientPlayer player, CompoundTag tag, RawAnimationDataCapability data) {
|
private void testPlayAnimations(AbstractClientPlayer player, CompoundTag tag, RawAnimationDataCapability data) {
|
||||||
if(data == null) return;
|
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<ResourceLocation> oldLayerSet = new HashSet<>(data.getAnimations().keySet());
|
Set<ResourceLocation> oldLayerSet = new HashSet<>(data.getAnimations().keySet());
|
||||||
CompoundTag animMap = tag.getCompound(RawAnimationDataCapability.AnimMap);
|
CompoundTag animMap = tag.getCompound(RawAnimationDataCapability.AnimMap);
|
||||||
for (String newLayerString : animMap.getAllKeys()) {
|
for (String newLayerString : animMap.getAllKeys()) {
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,6 @@ public class SyncAnimationPacket {
|
||||||
() -> AnimationUtils.syncAnimation(player, target),
|
() -> AnimationUtils.syncAnimation(player, target),
|
||||||
new AbstractMap.SimpleEntry<>(5, 0)
|
new AbstractMap.SimpleEntry<>(5, 0)
|
||||||
);
|
);
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package com.linearpast.sccore.animation.network.toserver;
|
package com.linearpast.sccore.animation.network.toserver;
|
||||||
|
|
||||||
import com.linearpast.sccore.animation.helper.IAnimationHelper;
|
import com.linearpast.sccore.animation.network.ServiceGetterPacket;
|
||||||
import com.linearpast.sccore.animation.network.HelperGetterPacket;
|
import com.linearpast.sccore.animation.service.IAnimationService;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraftforge.network.NetworkEvent;
|
import net.minecraftforge.network.NetworkEvent;
|
||||||
|
|
@ -9,7 +9,7 @@ import net.minecraftforge.network.NetworkEvent;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class ApplyAnimationPacket extends HelperGetterPacket {
|
public class ApplyAnimationPacket extends ServiceGetterPacket {
|
||||||
private final UUID targetUUID;
|
private final UUID targetUUID;
|
||||||
|
|
||||||
public ApplyAnimationPacket(UUID targetUUID) {
|
public ApplyAnimationPacket(UUID targetUUID) {
|
||||||
|
|
@ -34,15 +34,15 @@ public class ApplyAnimationPacket extends HelperGetterPacket {
|
||||||
if(this.targetUUID == null) target = sender;
|
if(this.targetUUID == null) target = sender;
|
||||||
else target = sender.getServer().getPlayerList().getPlayer(this.targetUUID);
|
else target = sender.getServer().getPlayerList().getPlayer(this.targetUUID);
|
||||||
if(target == null) return;
|
if(target == null) return;
|
||||||
IAnimationHelper<?, ?> helper = getHelper();
|
IAnimationService<?, ?> service = getService();
|
||||||
if(helper == null) return;
|
if(service == null) return;
|
||||||
if(target == sender) return;
|
if(target == sender) return;
|
||||||
helper.apply(sender, target);
|
service.apply(sender, target);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean filter(IAnimationHelper<?, ?> helper) {
|
public boolean filter(IAnimationService<?, ?> helper) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
package com.linearpast.sccore.animation.network.toserver;
|
package com.linearpast.sccore.animation.network.toserver;
|
||||||
|
|
||||||
import com.linearpast.sccore.animation.data.AnimationData;
|
import com.linearpast.sccore.animation.data.AnimationData;
|
||||||
import com.linearpast.sccore.animation.helper.IAnimationHelper;
|
import com.linearpast.sccore.animation.network.ServiceGetterPacket;
|
||||||
import com.linearpast.sccore.animation.network.HelperGetterPacket;
|
import com.linearpast.sccore.animation.service.IAnimationService;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
|
@ -14,7 +14,7 @@ import java.util.Collection;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class InviteAnimationPacket extends HelperGetterPacket {
|
public class InviteAnimationPacket extends ServiceGetterPacket {
|
||||||
private final @Nullable CompoundTag animationTag;
|
private final @Nullable CompoundTag animationTag;
|
||||||
private final ResourceLocation layer;
|
private final ResourceLocation layer;
|
||||||
private final ResourceLocation animation;
|
private final ResourceLocation animation;
|
||||||
|
|
@ -47,12 +47,12 @@ public class InviteAnimationPacket extends HelperGetterPacket {
|
||||||
context.setPacketHandled(true);
|
context.setPacketHandled(true);
|
||||||
ServerPlayer sender = context.getSender();
|
ServerPlayer sender = context.getSender();
|
||||||
if(sender == null) return;
|
if(sender == null) return;
|
||||||
IAnimationHelper<?, ?> helper = getHelper();
|
IAnimationService<?, ?> service = getService();
|
||||||
if(helper == null) return;
|
if(service == null) return;
|
||||||
AnimationData data = helper.getAnimation(animationTag);
|
AnimationData data = service.getAnimation(animationTag);
|
||||||
if(data == null) return;
|
if(data == null) return;
|
||||||
if(!targets.isEmpty()) helper.invite(sender, layer, data, targets);
|
if(!targets.isEmpty()) service.invite(sender, layer, data, targets);
|
||||||
else helper.playAnimationWithRide(sender, layer, data, false);
|
else service.playAnimationWithRide(sender, layer, data, false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
package com.linearpast.sccore.animation.network.toserver;
|
package com.linearpast.sccore.animation.network.toserver;
|
||||||
|
|
||||||
import com.linearpast.sccore.animation.data.AnimationData;
|
import com.linearpast.sccore.animation.data.AnimationData;
|
||||||
import com.linearpast.sccore.animation.helper.IAnimationHelper;
|
import com.linearpast.sccore.animation.network.ServiceGetterPacket;
|
||||||
import com.linearpast.sccore.animation.network.HelperGetterPacket;
|
import com.linearpast.sccore.animation.service.IAnimationService;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
|
@ -13,7 +13,7 @@ import org.jetbrains.annotations.Nullable;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class PlayAnimationPacket extends HelperGetterPacket {
|
public class PlayAnimationPacket extends ServiceGetterPacket {
|
||||||
private final @Nullable CompoundTag animationTag;
|
private final @Nullable CompoundTag animationTag;
|
||||||
private final ResourceLocation layer;
|
private final ResourceLocation layer;
|
||||||
private final ResourceLocation animation;
|
private final ResourceLocation animation;
|
||||||
|
|
@ -50,12 +50,12 @@ public class PlayAnimationPacket extends HelperGetterPacket {
|
||||||
if(this.uuid == null) target = sender;
|
if(this.uuid == null) target = sender;
|
||||||
else target = sender.getServer().getPlayerList().getPlayer(this.uuid);
|
else target = sender.getServer().getPlayerList().getPlayer(this.uuid);
|
||||||
if(target == null) return;
|
if(target == null) return;
|
||||||
IAnimationHelper<?, ?> helper = getHelper();
|
IAnimationService<?, ?> service = getService();
|
||||||
if(helper == null) return;
|
if(service == null) return;
|
||||||
AnimationData data = helper.getAnimation(animationTag);
|
AnimationData data = service.getAnimation(animationTag);
|
||||||
if(data == null) return;
|
if(data == null) return;
|
||||||
if(target == sender) helper.playAnimation(target, layer, data);
|
if(target == sender) service.playAnimation(target, layer, data);
|
||||||
else helper.request(sender, target, layer, data, false);
|
else service.request(sender, target, layer, data, false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
package com.linearpast.sccore.animation.network.toserver;
|
package com.linearpast.sccore.animation.network.toserver;
|
||||||
|
|
||||||
import com.linearpast.sccore.animation.data.AnimationData;
|
import com.linearpast.sccore.animation.data.AnimationData;
|
||||||
import com.linearpast.sccore.animation.helper.IAnimationHelper;
|
import com.linearpast.sccore.animation.network.ServiceGetterPacket;
|
||||||
import com.linearpast.sccore.animation.network.HelperGetterPacket;
|
import com.linearpast.sccore.animation.service.IAnimationService;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
|
@ -13,15 +13,15 @@ import org.jetbrains.annotations.Nullable;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class PlayAnimationRidePacket extends HelperGetterPacket {
|
public class PlayAnimationRidePacket extends ServiceGetterPacket {
|
||||||
private final @Nullable CompoundTag animationTag;
|
private final @Nullable CompoundTag animationTag;
|
||||||
private final ResourceLocation layer;
|
private final ResourceLocation layer;
|
||||||
private final ResourceLocation animation;
|
private final ResourceLocation animation;
|
||||||
private final @Nullable UUID uuid;
|
private final @Nullable UUID uuid;
|
||||||
private final boolean force;
|
private final boolean force;
|
||||||
|
|
||||||
public PlayAnimationRidePacket(AnimationData data, ResourceLocation layer, ResourceLocation animation, @Nullable UUID uuid, boolean force) {
|
public PlayAnimationRidePacket(@Nullable AnimationData data, ResourceLocation layer, ResourceLocation animation, @Nullable UUID uuid, boolean force) {
|
||||||
this.animationTag = data.serializeNBT();
|
this.animationTag = data != null ? data.serializeNBT() : null;
|
||||||
this.layer = layer;
|
this.layer = layer;
|
||||||
this.animation = animation;
|
this.animation = animation;
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
|
|
@ -54,12 +54,12 @@ public class PlayAnimationRidePacket extends HelperGetterPacket {
|
||||||
if(this.uuid == null) target = sender;
|
if(this.uuid == null) target = sender;
|
||||||
else target = sender.getServer().getPlayerList().getPlayer(this.uuid);
|
else target = sender.getServer().getPlayerList().getPlayer(this.uuid);
|
||||||
if(target == null) return;
|
if(target == null) return;
|
||||||
IAnimationHelper<?, ?> helper = getHelper();
|
IAnimationService<?, ?> service = getService();
|
||||||
if(helper == null) return;
|
if(service == null) return;
|
||||||
AnimationData data = helper.getAnimation(animationTag);
|
AnimationData data = service.getAnimation(animationTag);
|
||||||
if(data == null) return;
|
if(data == null) return;
|
||||||
if(target == sender) helper.playAnimationWithRide(target, layer, data, force);
|
if(target == sender) service.playAnimationWithRide(target, layer, data, force);
|
||||||
else helper.request(sender, target, layer, data, true);
|
else service.request(sender, target, layer, data, true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
package com.linearpast.sccore.animation.network.toserver;
|
package com.linearpast.sccore.animation.network.toserver;
|
||||||
|
|
||||||
import com.linearpast.sccore.animation.data.AnimationData;
|
import com.linearpast.sccore.animation.data.AnimationData;
|
||||||
import com.linearpast.sccore.animation.helper.IAnimationHelper;
|
import com.linearpast.sccore.animation.network.ServiceGetterPacket;
|
||||||
import com.linearpast.sccore.animation.network.HelperGetterPacket;
|
import com.linearpast.sccore.animation.service.IAnimationService;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
|
@ -13,7 +13,7 @@ import org.jetbrains.annotations.Nullable;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class RequestAnimationPacket extends HelperGetterPacket {
|
public class RequestAnimationPacket extends ServiceGetterPacket {
|
||||||
private final @Nullable CompoundTag animationTag;
|
private final @Nullable CompoundTag animationTag;
|
||||||
private final ResourceLocation layer;
|
private final ResourceLocation layer;
|
||||||
private final ResourceLocation animation;
|
private final ResourceLocation animation;
|
||||||
|
|
@ -50,12 +50,12 @@ public class RequestAnimationPacket extends HelperGetterPacket {
|
||||||
if(this.targetUUID == null) target = sender;
|
if(this.targetUUID == null) target = sender;
|
||||||
else target = sender.getServer().getPlayerList().getPlayer(this.targetUUID);
|
else target = sender.getServer().getPlayerList().getPlayer(this.targetUUID);
|
||||||
if(target == null) return;
|
if(target == null) return;
|
||||||
IAnimationHelper<?, ?> helper = getHelper();
|
IAnimationService<?, ?> service = getService();
|
||||||
if(helper == null) return;
|
if(service == null) return;
|
||||||
AnimationData data = helper.getAnimation(animationTag);
|
AnimationData data = service.getAnimation(animationTag);
|
||||||
if(data == null) return;
|
if(data == null) return;
|
||||||
if(target == sender) return;
|
if(target == sender) return;
|
||||||
helper.request(sender, target, layer, data, false);
|
service.request(sender, target, layer, data, false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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.argument.AnimationLayerArgument;
|
||||||
import com.linearpast.sccore.animation.command.client.ListClientCommand;
|
import com.linearpast.sccore.animation.command.client.ListClientCommand;
|
||||||
import com.linearpast.sccore.animation.command.client.RefreshCommand;
|
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 com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.commands.synchronization.ArgumentTypeInfo;
|
import net.minecraft.commands.synchronization.ArgumentTypeInfo;
|
||||||
|
|
@ -17,7 +17,7 @@ import static net.minecraft.commands.Commands.literal;
|
||||||
|
|
||||||
public class AnimationCommands {
|
public class AnimationCommands {
|
||||||
public static void commonCommandRegister(LiteralArgumentBuilder<CommandSourceStack> builder) {
|
public static void commonCommandRegister(LiteralArgumentBuilder<CommandSourceStack> builder) {
|
||||||
if(IAnimationHelper.ANIMATION_RUNNER.isModLoaded()){
|
if(IAnimationService.ANIMATION_RUNNER.testCondition()){
|
||||||
LiteralArgumentBuilder<CommandSourceStack> anim = literal("anim");
|
LiteralArgumentBuilder<CommandSourceStack> anim = literal("anim");
|
||||||
ApplyCommand.register(anim);
|
ApplyCommand.register(anim);
|
||||||
InviteCommand.register(anim);
|
InviteCommand.register(anim);
|
||||||
|
|
@ -30,7 +30,7 @@ public class AnimationCommands {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void clientCommandRegister(LiteralArgumentBuilder<CommandSourceStack> builder) {
|
public static void clientCommandRegister(LiteralArgumentBuilder<CommandSourceStack> builder) {
|
||||||
if(IAnimationHelper.ANIMATION_RUNNER.isModLoaded()) {
|
if(IAnimationService.ANIMATION_RUNNER.testCondition()) {
|
||||||
LiteralArgumentBuilder<CommandSourceStack> anim = literal("anim");
|
LiteralArgumentBuilder<CommandSourceStack> anim = literal("anim");
|
||||||
ListClientCommand.register(anim);
|
ListClientCommand.register(anim);
|
||||||
RefreshCommand.register(anim);
|
RefreshCommand.register(anim);
|
||||||
|
|
|
||||||
|
|
@ -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.AnimJson;
|
||||||
import com.linearpast.sccore.animation.data.util.AnimLayerJson;
|
import com.linearpast.sccore.animation.data.util.AnimLayerJson;
|
||||||
import com.linearpast.sccore.animation.event.create.AnimationRegisterEvent;
|
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.mixin.IMixinPlayerAnimationFactoryHolder;
|
||||||
import com.linearpast.sccore.animation.network.toclient.AnimationClientStatusPacket;
|
import com.linearpast.sccore.animation.network.toclient.AnimationClientStatusPacket;
|
||||||
import com.linearpast.sccore.animation.network.toclient.AnimationJsonPacket;
|
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.core.ModChannel;
|
||||||
import com.linearpast.sccore.utils.ModuleAccess;
|
import com.linearpast.sccore.utils.ModuleAccess;
|
||||||
import dev.kosmx.playerAnim.api.layered.AnimationStack;
|
import dev.kosmx.playerAnim.api.layered.AnimationStack;
|
||||||
|
|
@ -297,10 +297,6 @@ public class AnimationRegistry {
|
||||||
if(riderAnimLayer != null) {
|
if(riderAnimLayer != null) {
|
||||||
dataAnimations.put(riderAnimLayer, data.getRiderAnimation());
|
dataAnimations.put(riderAnimLayer, data.getRiderAnimation());
|
||||||
}
|
}
|
||||||
ResourceLocation rawRiderAnimLayer = rawData.getRiderAnimLayer();
|
|
||||||
if(rawRiderAnimLayer != null) {
|
|
||||||
dataAnimations.put(rawRiderAnimLayer, rawData.getRiderAnimation());
|
|
||||||
}
|
|
||||||
for (ResourceLocation location : dataAnimations.keySet()) {
|
for (ResourceLocation location : dataAnimations.keySet()) {
|
||||||
ModifierLayer<IAnimation> modifierLayer = (ModifierLayer<IAnimation>) PlayerAnimationAccess
|
ModifierLayer<IAnimation> modifierLayer = (ModifierLayer<IAnimation>) PlayerAnimationAccess
|
||||||
.getPlayerAssociatedData(player).get(location);
|
.getPlayerAssociatedData(player).get(location);
|
||||||
|
|
@ -309,7 +305,7 @@ public class AnimationRegistry {
|
||||||
ResourceLocation animationLocation = dataAnimations.get(location);
|
ResourceLocation animationLocation = dataAnimations.get(location);
|
||||||
GenericAnimationData anim = animations.get(animationLocation);
|
GenericAnimationData anim = animations.get(animationLocation);
|
||||||
if(anim == null) {
|
if(anim == null) {
|
||||||
RawAnimationData rawAnim = RawAnimationHelper.INSTANCE.getAnimation(animationLocation);
|
RawAnimationData rawAnim = RawAnimationService.INSTANCE.getAnimation(animationLocation);
|
||||||
if(rawAnim == null) return;
|
if(rawAnim == null) return;
|
||||||
keyframeAnimation = rawAnim.getAnimation();
|
keyframeAnimation = rawAnim.getAnimation();
|
||||||
} else keyframeAnimation = anim.getAnimation();
|
} else keyframeAnimation = anim.getAnimation();
|
||||||
|
|
|
||||||
|
|
@ -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<GenericAnimationData, IAnimationCapability> {
|
||||||
|
public static final AnimationService INSTANCE = new AnimationService();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the LyingType when there are animations which playing on player. <br>
|
||||||
|
* 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. <br>
|
||||||
|
* 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<ResourceLocation> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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.data.AnimationData;
|
||||||
|
import com.linearpast.sccore.animation.entity.AnimationRideEntity;
|
||||||
import com.linearpast.sccore.animation.event.PlayerTickEvent;
|
import com.linearpast.sccore.animation.event.PlayerTickEvent;
|
||||||
import com.linearpast.sccore.animation.event.client.CameraAnglesModify;
|
import com.linearpast.sccore.animation.event.client.CameraAnglesModify;
|
||||||
import com.linearpast.sccore.animation.event.client.ClientPlayerEvent;
|
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.animation.utils.ApiBack;
|
||||||
import com.linearpast.sccore.capability.data.ICapabilitySync;
|
import com.linearpast.sccore.capability.data.ICapabilitySync;
|
||||||
import com.linearpast.sccore.core.ModChannel;
|
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 com.linearpast.sccore.core.configs.ModConfigs;
|
||||||
import dev.kosmx.playerAnim.core.data.KeyframeAnimation;
|
import dev.kosmx.playerAnim.core.data.KeyframeAnimation;
|
||||||
import dev.kosmx.playerAnim.minecraftApi.PlayerAnimationRegistry;
|
import dev.kosmx.playerAnim.minecraftApi.PlayerAnimationRegistry;
|
||||||
|
|
@ -24,10 +25,12 @@ import net.minecraft.client.player.AbstractClientPlayer;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
|
import net.minecraftforge.common.util.FakePlayer;
|
||||||
import net.minecraftforge.eventbus.api.Event;
|
import net.minecraftforge.eventbus.api.Event;
|
||||||
import net.minecraftforge.eventbus.api.IEventBus;
|
import net.minecraftforge.eventbus.api.IEventBus;
|
||||||
import net.minecraftforge.fml.LogicalSide;
|
import net.minecraftforge.fml.LogicalSide;
|
||||||
|
|
@ -44,12 +47,12 @@ import java.util.stream.Collectors;
|
||||||
* @param <C> Capability
|
* @param <C> Capability
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({"UnusedReturnValue", "unused"})
|
@SuppressWarnings({"UnusedReturnValue", "unused"})
|
||||||
public interface IAnimationHelper<D extends AnimationData, C extends ICapabilitySync<?>>{
|
public interface IAnimationService<D extends AnimationData, C extends ICapabilitySync<?>>{
|
||||||
String AnimModId = "playeranimator";
|
String AnimModId = "playeranimator";
|
||||||
/**
|
/**
|
||||||
* Lazy runner
|
* Lazy runner
|
||||||
*/
|
*/
|
||||||
ModLazyRun ANIMATION_RUNNER = new ModLazyRun(AnimModId) {
|
ModCompatRun ANIMATION_RUNNER = new ModCompatRun(AnimModId) {
|
||||||
@Override
|
@Override
|
||||||
public void addCommonListener(IEventBus forgeBus, IEventBus modBus) {
|
public void addCommonListener(IEventBus forgeBus, IEventBus modBus) {
|
||||||
AnimationEntities.register(modBus);
|
AnimationEntities.register(modBus);
|
||||||
|
|
@ -125,14 +128,37 @@ public interface IAnimationHelper<D extends AnimationData, C extends ICapability
|
||||||
ANIMATION_RUNNER.testLoadedAndAddListener(forgeBus, modBus);
|
ANIMATION_RUNNER.testLoadedAndAddListener(forgeBus, modBus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default void clearAnimations(AbstractClientPlayer player){
|
||||||
|
for (ResourceLocation layer : getLayers()) {
|
||||||
|
AnimationUtils.removeAnimation(player, layer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//clear animations
|
//clear animations
|
||||||
void clearAnimations(ServerPlayer serverPlayer);
|
void clearAnimations(ServerPlayer serverPlayer);
|
||||||
//according to location, judge if animation is present
|
//according to location, judge if animation is present
|
||||||
boolean isAnimationPresent(ResourceLocation location);
|
boolean isAnimationPresent(ResourceLocation location);
|
||||||
//stop riding
|
//stop riding
|
||||||
ApiBack detachAnimation(ServerPlayer player);
|
default ApiBack detachAnimation(ServerPlayer player){
|
||||||
|
return ANIMATION_RUNNER.testLoadedAndCall(() -> {
|
||||||
|
if(player.getVehicle() instanceof AnimationRideEntity) {
|
||||||
|
player.stopRiding();
|
||||||
|
return ApiBack.SUCCESS;
|
||||||
|
}
|
||||||
|
return ApiBack.UNSUPPORTED;
|
||||||
|
});
|
||||||
|
};
|
||||||
//start ride
|
//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
|
* Trigger event and let implementation class handle
|
||||||
|
|
@ -254,7 +280,22 @@ public interface IAnimationHelper<D extends AnimationData, C extends ICapability
|
||||||
return ApiBack.SUCCESS;
|
return ApiBack.SUCCESS;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
ApiBack playAnimationWithRide(@NotNull ServerPlayer player, ResourceLocation layer, AnimationData animationTag, boolean force);
|
default 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, animation, force) != null;
|
||||||
|
return result ? ApiBack.SUCCESS : ApiBack.FAIL;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <pre>
|
* <pre>
|
||||||
|
|
@ -624,11 +665,13 @@ public interface IAnimationHelper<D extends AnimationData, C extends ICapability
|
||||||
}
|
}
|
||||||
case ALLOW : {
|
case ALLOW : {
|
||||||
//done
|
//done
|
||||||
playAnimationWithRide(inviter, record.layer(), record.animation(), false);
|
ApiBack apiBack = playAnimationWithRide(inviter, record.layer(), record.animation(), false);
|
||||||
|
if(apiBack == ApiBack.SUCCESS) {
|
||||||
if(record.targets().isEmpty()) inviteMap.remove(inviter.getUUID());
|
if(record.targets().isEmpty()) inviteMap.remove(inviter.getUUID());
|
||||||
ApiBack back = joinAnimation(player, inviter, false);
|
ApiBack back = joinAnimation(player, inviter, false);
|
||||||
if(back == ApiBack.SUCCESS) record.targets().remove(uuid);
|
if(back == ApiBack.SUCCESS) record.targets().remove(uuid);
|
||||||
return back;
|
return back;
|
||||||
|
} else return apiBack;
|
||||||
}
|
}
|
||||||
default: return ApiBack.UNSUPPORTED;
|
default: return ApiBack.UNSUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
package com.linearpast.sccore.animation.helper;
|
package com.linearpast.sccore.animation.service;
|
||||||
|
|
||||||
import com.linearpast.sccore.animation.capability.RawAnimationDataCapability;
|
import com.linearpast.sccore.animation.capability.RawAnimationDataCapability;
|
||||||
import com.linearpast.sccore.animation.data.AnimationData;
|
import com.linearpast.sccore.animation.data.AnimationData;
|
||||||
import com.linearpast.sccore.animation.data.RawAnimationData;
|
import com.linearpast.sccore.animation.data.RawAnimationData;
|
||||||
import com.linearpast.sccore.animation.entity.RawAnimationRideEntity;
|
|
||||||
import com.linearpast.sccore.animation.event.create.AnimationRegisterEvent;
|
import com.linearpast.sccore.animation.event.create.AnimationRegisterEvent;
|
||||||
import com.linearpast.sccore.animation.register.RawAnimationRegistry;
|
import com.linearpast.sccore.animation.register.RawAnimationRegistry;
|
||||||
import com.linearpast.sccore.animation.utils.AnimationUtils;
|
import com.linearpast.sccore.animation.utils.AnimationUtils;
|
||||||
|
|
@ -12,7 +11,6 @@ import net.minecraft.client.player.AbstractClientPlayer;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.world.entity.Entity;
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||||
|
|
@ -25,8 +23,8 @@ import java.util.HashSet;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class RawAnimationHelper implements IAnimationHelper<RawAnimationData, RawAnimationDataCapability> {
|
public class RawAnimationService implements IAnimationService<RawAnimationData, RawAnimationDataCapability> {
|
||||||
public static final RawAnimationHelper INSTANCE = new RawAnimationHelper();
|
public static final RawAnimationService INSTANCE = new RawAnimationService();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Trigger raw animation registry. <br>
|
* Trigger raw animation registry. <br>
|
||||||
|
|
@ -71,29 +69,6 @@ public class RawAnimationHelper implements IAnimationHelper<RawAnimationData, Ra
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ApiBack detachAnimation(ServerPlayer player) {
|
|
||||||
return ANIMATION_RUNNER.testLoadedAndCall(() -> {
|
|
||||||
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
|
@Override
|
||||||
@OnlyIn(Dist.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
public void refreshAnimation(AbstractClientPlayer clientPlayer) {
|
public void refreshAnimation(AbstractClientPlayer clientPlayer) {
|
||||||
|
|
@ -134,26 +109,6 @@ public class RawAnimationHelper implements IAnimationHelper<RawAnimationData, Ra
|
||||||
return result ? ApiBack.SUCCESS : ApiBack.FAIL;
|
return result ? ApiBack.SUCCESS : ApiBack.FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ApiBack playAnimationWithRide(@NotNull ServerPlayer player, ResourceLocation layer, AnimationData animation, boolean force) {
|
|
||||||
return ANIMATION_RUNNER.testLoadedAndCall(() -> {
|
|
||||||
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
|
@Override
|
||||||
public ApiBack playAnimationServer(@NotNull ServerPlayer player, ResourceLocation layer, AnimationData animation) {
|
public ApiBack playAnimationServer(@NotNull ServerPlayer player, ResourceLocation layer, AnimationData animation) {
|
||||||
return ANIMATION_RUNNER.testLoadedAndCall(() -> {
|
return ANIMATION_RUNNER.testLoadedAndCall(() -> {
|
||||||
|
|
@ -2,14 +2,14 @@ package com.linearpast.sccore.animation.utils;
|
||||||
|
|
||||||
import com.linearpast.sccore.SnowyCrescentCore;
|
import com.linearpast.sccore.SnowyCrescentCore;
|
||||||
import com.linearpast.sccore.animation.capability.AnimationDataCapability;
|
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.GenericAnimationData;
|
||||||
import com.linearpast.sccore.animation.data.RawAnimationData;
|
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.mixin.IMixinKeyframeAnimationPlayer;
|
||||||
import com.linearpast.sccore.animation.register.AnimationRegistry;
|
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 com.linearpast.sccore.core.datagen.ModLang;
|
||||||
import dev.kosmx.playerAnim.api.layered.IAnimation;
|
import dev.kosmx.playerAnim.api.layered.IAnimation;
|
||||||
import dev.kosmx.playerAnim.api.layered.KeyframeAnimationPlayer;
|
import dev.kosmx.playerAnim.api.layered.KeyframeAnimationPlayer;
|
||||||
|
|
@ -30,7 +30,6 @@ import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
|
||||||
|
|
||||||
public class AnimationUtils {
|
public class AnimationUtils {
|
||||||
/**
|
/**
|
||||||
|
|
@ -43,7 +42,7 @@ public class AnimationUtils {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@OnlyIn(Dist.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
public static boolean isClientAnimationNotEnd(AbstractClientPlayer player, @Nullable ResourceLocation layer) {
|
public static boolean isClientAnimationNotEnd(AbstractClientPlayer player, @Nullable ResourceLocation layer) {
|
||||||
return IAnimationHelper.ANIMATION_RUNNER.testLoadedAndCall(() -> {
|
return IAnimationService.ANIMATION_RUNNER.testLoadedAndCall(() -> {
|
||||||
try {
|
try {
|
||||||
Set<ResourceLocation> resourceLocations = new HashSet<>();
|
Set<ResourceLocation> resourceLocations = new HashSet<>();
|
||||||
if(layer == null) resourceLocations.addAll(AnimationRegistry.getLayers().keySet());
|
if(layer == null) resourceLocations.addAll(AnimationRegistry.getLayers().keySet());
|
||||||
|
|
@ -74,7 +73,7 @@ public class AnimationUtils {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@OnlyIn(Dist.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
public static boolean isClientAnimationStop(AbstractClientPlayer player, @Nullable ResourceLocation layer) {
|
public static boolean isClientAnimationStop(AbstractClientPlayer player, @Nullable ResourceLocation layer) {
|
||||||
return IAnimationHelper.ANIMATION_RUNNER.testLoadedAndCall(() -> {
|
return IAnimationService.ANIMATION_RUNNER.testLoadedAndCall(() -> {
|
||||||
try {
|
try {
|
||||||
Set<ResourceLocation> resourceLocations = new HashSet<>();
|
Set<ResourceLocation> resourceLocations = new HashSet<>();
|
||||||
if(layer == null) resourceLocations.addAll(AnimationRegistry.getLayers().keySet());
|
if(layer == null) resourceLocations.addAll(AnimationRegistry.getLayers().keySet());
|
||||||
|
|
@ -102,30 +101,18 @@ public class AnimationUtils {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@OnlyIn(Dist.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
public static void syncAnimation(AbstractClientPlayer clientPlayer, AbstractClientPlayer target) {
|
public static void syncAnimation(AbstractClientPlayer clientPlayer, AbstractClientPlayer target) {
|
||||||
AtomicReference<ResourceLocation> clientPlayerLayer = new AtomicReference<>();
|
IAnimationCapability clientPlayerData = AnimationDataCapability.getCapability(clientPlayer).orElse(null);
|
||||||
AtomicReference<ResourceLocation> targetLayer = new AtomicReference<>();
|
IAnimationCapability targetData = AnimationDataCapability.getCapability(target).orElse(null);
|
||||||
clientPlayerLayer.set(null);
|
if(clientPlayerData == null) return;
|
||||||
targetLayer.set(null);
|
if(targetData == null) return;
|
||||||
AnimationDataCapability.getCapability(clientPlayer).ifPresent(clientPlayerData ->
|
ResourceLocation clientPlayerLayer = clientPlayerData.getRiderAnimLayer();
|
||||||
AnimationDataCapability.getCapability(target).ifPresent(targetData -> {
|
ResourceLocation targetLayer = targetData.getRiderAnimLayer();
|
||||||
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());
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
if(clientPlayerLayer.get() == null || targetLayer.get() == null) return;
|
if(clientPlayerLayer == null || targetLayer == null) return;
|
||||||
ModifierLayer<IAnimation> modifierLayer = (ModifierLayer<IAnimation>) PlayerAnimationAccess
|
ModifierLayer<IAnimation> modifierLayer = (ModifierLayer<IAnimation>) PlayerAnimationAccess
|
||||||
.getPlayerAssociatedData(clientPlayer).get(clientPlayerLayer.get());
|
.getPlayerAssociatedData(clientPlayer).get(clientPlayerLayer);
|
||||||
ModifierLayer<IAnimation> targetModifierLayer = (ModifierLayer<IAnimation>) PlayerAnimationAccess
|
ModifierLayer<IAnimation> targetModifierLayer = (ModifierLayer<IAnimation>) PlayerAnimationAccess
|
||||||
.getPlayerAssociatedData(target).get(targetLayer.get());
|
.getPlayerAssociatedData(target).get(targetLayer);
|
||||||
if(modifierLayer == null || targetModifierLayer == null) return;
|
if(modifierLayer == null || targetModifierLayer == null) return;
|
||||||
IMixinKeyframeAnimationPlayer animation = (IMixinKeyframeAnimationPlayer) modifierLayer.getAnimation();
|
IMixinKeyframeAnimationPlayer animation = (IMixinKeyframeAnimationPlayer) modifierLayer.getAnimation();
|
||||||
KeyframeAnimationPlayer targetAnimation = (KeyframeAnimationPlayer) targetModifierLayer.getAnimation();
|
KeyframeAnimationPlayer targetAnimation = (KeyframeAnimationPlayer) targetModifierLayer.getAnimation();
|
||||||
|
|
@ -171,9 +158,9 @@ public class AnimationUtils {
|
||||||
}
|
}
|
||||||
if(modifierLayer == null) return;
|
if(modifierLayer == null) return;
|
||||||
KeyframeAnimation keyframeAnimation;
|
KeyframeAnimation keyframeAnimation;
|
||||||
GenericAnimationData anim = AnimationHelper.INSTANCE.getAnimation(animation);
|
GenericAnimationData anim = AnimationService.INSTANCE.getAnimation(animation);
|
||||||
if(anim == null) {
|
if(anim == null) {
|
||||||
RawAnimationData rawAnim = RawAnimationHelper.INSTANCE.getAnimation(animation);
|
RawAnimationData rawAnim = RawAnimationService.INSTANCE.getAnimation(animation);
|
||||||
if(rawAnim == null) return;
|
if(rawAnim == null) return;
|
||||||
keyframeAnimation = rawAnim.getAnimation();
|
keyframeAnimation = rawAnim.getAnimation();
|
||||||
} else keyframeAnimation = anim.getAnimation();
|
} else keyframeAnimation = anim.getAnimation();
|
||||||
|
|
|
||||||
35
src/main/java/com/linearpast/sccore/core/IModLazyRun.java
Normal file
35
src/main/java/com/linearpast/sccore/core/IModLazyRun.java
Normal file
|
|
@ -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> T testLoadedAndCall(Callable<T> callable) {
|
||||||
|
try {
|
||||||
|
if(testCondition()) return callable.call();
|
||||||
|
} catch (Exception ignored) {}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
default <T> T testLoadedAndCall(Callable<T> callable, Callable<T> elseCall) {
|
||||||
|
try {
|
||||||
|
if(testCondition()) return callable.call();
|
||||||
|
else return elseCall.call();
|
||||||
|
}catch(Exception ignored) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean testCondition();
|
||||||
|
}
|
||||||
29
src/main/java/com/linearpast/sccore/core/ModCompatRun.java
Normal file
29
src/main/java/com/linearpast/sccore/core/ModCompatRun.java
Normal file
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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> T testLoadedAndCall(Callable<T> callable) {
|
|
||||||
try {
|
|
||||||
if(isModLoaded()) return callable.call();
|
|
||||||
} catch (Exception ignored) {}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T> T testLoadedAndCall(Callable<T> callable, Callable<T> 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);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
@ -4,7 +4,7 @@ import com.linearpast.sccore.SnowyCrescentCore;
|
||||||
import com.linearpast.sccore.animation.data.RawAnimationData;
|
import com.linearpast.sccore.animation.data.RawAnimationData;
|
||||||
import com.linearpast.sccore.animation.data.Ride;
|
import com.linearpast.sccore.animation.data.Ride;
|
||||||
import com.linearpast.sccore.animation.event.create.AnimationRegisterEvent;
|
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 com.linearpast.sccore.example.animation.event.ExamplePlayerAttackEvent;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
|
|
@ -12,7 +12,7 @@ import net.minecraftforge.eventbus.api.IEventBus;
|
||||||
import net.minecraftforge.fml.loading.FMLEnvironment;
|
import net.minecraftforge.fml.loading.FMLEnvironment;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see AnimationHelper
|
* @see AnimationService
|
||||||
*/
|
*/
|
||||||
public class ModAnimation {
|
public class ModAnimation {
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package com.linearpast.sccore.example.animation.event;
|
package com.linearpast.sccore.example.animation.event;
|
||||||
|
|
||||||
import com.linearpast.sccore.animation.helper.AnimationHelper;
|
import com.linearpast.sccore.animation.service.AnimationService;
|
||||||
import com.linearpast.sccore.animation.helper.RawAnimationHelper;
|
import com.linearpast.sccore.animation.service.RawAnimationService;
|
||||||
import com.linearpast.sccore.example.animation.ModAnimation;
|
import com.linearpast.sccore.example.animation.ModAnimation;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.player.AbstractClientPlayer;
|
import net.minecraft.client.player.AbstractClientPlayer;
|
||||||
|
|
@ -26,11 +26,11 @@ public class ExamplePlayerAttackEvent {
|
||||||
Player entity = event.getEntity();
|
Player entity = event.getEntity();
|
||||||
if(entity instanceof ServerPlayer player) {
|
if(entity instanceof ServerPlayer player) {
|
||||||
if(target instanceof Sheep){
|
if(target instanceof Sheep){
|
||||||
ResourceLocation playing = AnimationHelper.INSTANCE.getAnimationPlaying(player, ModAnimation.normalLayers);
|
ResourceLocation playing = AnimationService.INSTANCE.getAnimationPlaying(player, ModAnimation.normalLayers);
|
||||||
if(playing == null) {
|
if(playing == null) {
|
||||||
AnimationHelper.INSTANCE.playAnimation(player, ModAnimation.normalLayers, ModAnimation.AmStandToLying);
|
AnimationService.INSTANCE.playAnimation(player, ModAnimation.normalLayers, ModAnimation.AmStandToLying);
|
||||||
} else {
|
} else {
|
||||||
AnimationHelper.INSTANCE.removeAnimation(player, ModAnimation.normalLayers);
|
AnimationService.INSTANCE.removeAnimation(player, ModAnimation.normalLayers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -41,7 +41,7 @@ public class ExamplePlayerAttackEvent {
|
||||||
Player entity = event.getEntity();
|
Player entity = event.getEntity();
|
||||||
if(entity instanceof AbstractClientPlayer player && target instanceof AbstractClientPlayer targetPlayer) {
|
if(entity instanceof AbstractClientPlayer player && target instanceof AbstractClientPlayer targetPlayer) {
|
||||||
if(player == Minecraft.getInstance().player){
|
if(player == Minecraft.getInstance().player){
|
||||||
RawAnimationHelper.INSTANCE.invite(
|
RawAnimationService.INSTANCE.invite(
|
||||||
ModAnimation.normalLayers,
|
ModAnimation.normalLayers,
|
||||||
ModAnimation.WaltzGentleman,
|
ModAnimation.WaltzGentleman,
|
||||||
targetPlayer
|
targetPlayer
|
||||||
|
|
@ -49,7 +49,7 @@ public class ExamplePlayerAttackEvent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(entity instanceof ServerPlayer player && target instanceof ServerPlayer targetPlayer) {
|
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;
|
LocalPlayer player = instance.player;
|
||||||
if (player == null) return;
|
if (player == null) return;
|
||||||
if(instance.options.keyCommand.isDown()) {
|
if(instance.options.keyCommand.isDown()) {
|
||||||
ResourceLocation playing = AnimationHelper.INSTANCE.getAnimationPlaying(player, ModAnimation.normalLayers);
|
ResourceLocation playing = AnimationService.INSTANCE.getAnimationPlaying(player, ModAnimation.normalLayers);
|
||||||
if(playing == null) {
|
if(playing == null) {
|
||||||
AnimationHelper.INSTANCE.playAnimationWithRide((AbstractClientPlayer) null, ModAnimation.normalLayers, ModAnimation.AmLyingToRightLying, true);
|
AnimationService.INSTANCE.playAnimationWithRide((AbstractClientPlayer) null, ModAnimation.normalLayers, ModAnimation.AmLyingToRightLying, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package com.linearpast.sccore.mixin;
|
package com.linearpast.sccore.mixin;
|
||||||
|
|
||||||
import com.linearpast.sccore.SnowyCrescentCore;
|
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 net.minecraftforge.fml.ModList;
|
||||||
import org.objectweb.asm.tree.ClassNode;
|
import org.objectweb.asm.tree.ClassNode;
|
||||||
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
|
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
|
||||||
|
|
@ -27,7 +27,7 @@ public class SCCoreMixinPlugin implements IMixinConfigPlugin {
|
||||||
return "runData".equals(System.getProperty("gradle.task"));
|
return "runData".equals(System.getProperty("gradle.task"));
|
||||||
}
|
}
|
||||||
if (mixinClassName.startsWith("com\\.linearpast\\." + SnowyCrescentCore.MODID + "\\.mixin\\.animation")) {
|
if (mixinClassName.startsWith("com\\.linearpast\\." + SnowyCrescentCore.MODID + "\\.mixin\\.animation")) {
|
||||||
return ModList.get().isLoaded(AnimationHelper.AnimModId);
|
return ModList.get().isLoaded(AnimationService.AnimModId);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ package com.linearpast.sccore.mixin.animation;
|
||||||
import com.linearpast.sccore.animation.capability.AnimationDataCapability;
|
import com.linearpast.sccore.animation.capability.AnimationDataCapability;
|
||||||
import com.linearpast.sccore.animation.capability.inter.IAnimationCapability;
|
import com.linearpast.sccore.animation.capability.inter.IAnimationCapability;
|
||||||
import com.linearpast.sccore.animation.data.GenericAnimationData;
|
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 com.llamalad7.mixinextras.injector.ModifyReturnValue;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
|
|
@ -36,7 +36,7 @@ public abstract class MixinEntity {
|
||||||
if(data == null) return;
|
if(data == null) return;
|
||||||
Float camYModifier = null;
|
Float camYModifier = null;
|
||||||
for (ResourceLocation value : data.getAnimations().values()) {
|
for (ResourceLocation value : data.getAnimations().values()) {
|
||||||
GenericAnimationData animation = AnimationHelper.INSTANCE.getAnimation(value);
|
GenericAnimationData animation = AnimationService.INSTANCE.getAnimation(value);
|
||||||
if(animation == null) continue;
|
if(animation == null) continue;
|
||||||
float animationCamY = animation.getCamY();
|
float animationCamY = animation.getCamY();
|
||||||
if(camYModifier == null) camYModifier = animationCamY;
|
if(camYModifier == null) camYModifier = animationCamY;
|
||||||
|
|
@ -56,7 +56,7 @@ public abstract class MixinEntity {
|
||||||
private void redefinedBoundingBox(CallbackInfoReturnable<AABB> cir){
|
private void redefinedBoundingBox(CallbackInfoReturnable<AABB> cir){
|
||||||
Entity self = Entity.class.cast(this);
|
Entity self = Entity.class.cast(this);
|
||||||
if(self instanceof Player player){
|
if(self instanceof Player player){
|
||||||
float heightModifier = AnimationHelper.INSTANCE.getHeightModifier(player);
|
float heightModifier = AnimationService.INSTANCE.getHeightModifier(player);
|
||||||
if(heightModifier == 1.0f) return;
|
if(heightModifier == 1.0f) return;
|
||||||
double modifyHeight = 1.8f * heightModifier;
|
double modifyHeight = 1.8f * heightModifier;
|
||||||
cir.setReturnValue(this.bb.setMaxY(modifyHeight + this.bb.minY));
|
cir.setReturnValue(this.bb.setMaxY(modifyHeight + this.bb.minY));
|
||||||
|
|
@ -70,7 +70,7 @@ public abstract class MixinEntity {
|
||||||
private float redefinedBbHeight(float original){
|
private float redefinedBbHeight(float original){
|
||||||
Entity self = Entity.class.cast(this);
|
Entity self = Entity.class.cast(this);
|
||||||
if(self instanceof Player player){
|
if(self instanceof Player player){
|
||||||
float heightModifier = AnimationHelper.INSTANCE.getHeightModifier(player);
|
float heightModifier = AnimationService.INSTANCE.getHeightModifier(player);
|
||||||
if(heightModifier == 1.0f) return original;
|
if(heightModifier == 1.0f) return original;
|
||||||
return original * heightModifier;
|
return original * heightModifier;
|
||||||
}
|
}
|
||||||
|
|
@ -87,7 +87,7 @@ public abstract class MixinEntity {
|
||||||
private void redefinedPose(CallbackInfoReturnable<Pose> cir){
|
private void redefinedPose(CallbackInfoReturnable<Pose> cir){
|
||||||
Entity self = Entity.class.cast(this);
|
Entity self = Entity.class.cast(this);
|
||||||
if(self instanceof Player player){
|
if(self instanceof Player player){
|
||||||
float heightModifier = AnimationHelper.INSTANCE.getHeightModifier(player);
|
float heightModifier = AnimationService.INSTANCE.getHeightModifier(player);
|
||||||
if(heightModifier == 1.0f) return;
|
if(heightModifier == 1.0f) return;
|
||||||
setPose(Pose.STANDING);
|
setPose(Pose.STANDING);
|
||||||
cir.setReturnValue(Pose.STANDING);
|
cir.setReturnValue(Pose.STANDING);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package com.linearpast.sccore.mixin.animation.client;
|
package com.linearpast.sccore.mixin.animation.client;
|
||||||
|
|
||||||
import com.linearpast.sccore.animation.data.GenericAnimationData;
|
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.client.Minecraft;
|
||||||
import net.minecraft.util.Mth;
|
import net.minecraft.util.Mth;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
|
|
@ -36,7 +36,7 @@ public abstract class MixinEntity {
|
||||||
private void turnPosePlayer(double pYRot, double pXRot, CallbackInfo ci) {
|
private void turnPosePlayer(double pYRot, double pXRot, CallbackInfo ci) {
|
||||||
Entity self = Entity.class.cast(this);
|
Entity self = Entity.class.cast(this);
|
||||||
if(self instanceof Player player){
|
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()) {
|
if(lyingType != null && Minecraft.getInstance().options.getCameraType().isFirstPerson()) {
|
||||||
float f = (float)pXRot * 0.15F;
|
float f = (float)pXRot * 0.15F;
|
||||||
float f1 = (float)pYRot * 0.15F;
|
float f1 = (float)pYRot * 0.15F;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package com.linearpast.sccore.mixin.animation.client;
|
package com.linearpast.sccore.mixin.animation.client;
|
||||||
|
|
||||||
import com.linearpast.sccore.animation.data.GenericAnimationData;
|
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.AgeableListModel;
|
||||||
import net.minecraft.client.model.ArmedModel;
|
import net.minecraft.client.model.ArmedModel;
|
||||||
import net.minecraft.client.model.HeadedModel;
|
import net.minecraft.client.model.HeadedModel;
|
||||||
|
|
@ -26,7 +26,7 @@ public abstract class MixinHumanoidModel<T extends LivingEntity> extends Ageable
|
||||||
)
|
)
|
||||||
private void modifyHeadRot(T pEntity, float pLimbSwing, float pLimbSwingAmount, float pAgeInTicks, float pNetHeadYaw, float pHeadPitch, CallbackInfo ci){
|
private void modifyHeadRot(T pEntity, float pLimbSwing, float pLimbSwingAmount, float pAgeInTicks, float pNetHeadYaw, float pHeadPitch, CallbackInfo ci){
|
||||||
if(pEntity instanceof Player player){
|
if(pEntity instanceof Player player){
|
||||||
GenericAnimationData.LyingType lyingType = AnimationHelper.INSTANCE.getSideView(player);
|
GenericAnimationData.LyingType lyingType = AnimationService.INSTANCE.getSideView(player);
|
||||||
if(lyingType != null) {
|
if(lyingType != null) {
|
||||||
float pitch = pHeadPitch - 90.0f;
|
float pitch = pHeadPitch - 90.0f;
|
||||||
float yaw = pNetHeadYaw * -1.0f;
|
float yaw = pNetHeadYaw * -1.0f;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user