From deda6a2e7571a88c917b319fff190ac03e560c85 Mon Sep 17 00:00:00 2001 From: LostInLinearPast <1283411677@qq.com> Date: Thu, 8 Jan 2026 04:50:00 +0800 Subject: [PATCH] version 0.1.9 --- gradle.properties | 2 +- .../animation/entity/AnimationRideEntity.java | 14 +++++++-- .../event/client/ClientPlayerEvent.java | 4 +-- .../animation/helper/AnimationHelper.java | 13 ++++++++ .../network/toserver/StopAnimationPacket.java | 30 +++++++++++++++++++ .../animation/register/AnimationChannels.java | 5 ++++ .../animation/service/IAnimationService.java | 16 ++++++++-- .../animation/utils/AnimationUtils.java | 6 ++-- 8 files changed, 80 insertions(+), 10 deletions(-) create mode 100644 src/main/java/com/linearpast/sccore/animation/network/toserver/StopAnimationPacket.java diff --git a/gradle.properties b/gradle.properties index 1d5ad81..a54dbb9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,7 @@ mapping_version=2023.09.03-1.20.1 mod_id=sccore mod_name=SnowyCrescentCore mod_license=GNU AGPL 3.0 -mod_version=1.20.1-0.1.8 +mod_version=1.20.1-0.1.9 mod_group_id=com.linearpast mod_authors=LostInLinearPast mod_description=A lib about capability and player animator. diff --git a/src/main/java/com/linearpast/sccore/animation/entity/AnimationRideEntity.java b/src/main/java/com/linearpast/sccore/animation/entity/AnimationRideEntity.java index 67073c2..7068a7a 100644 --- a/src/main/java/com/linearpast/sccore/animation/entity/AnimationRideEntity.java +++ b/src/main/java/com/linearpast/sccore/animation/entity/AnimationRideEntity.java @@ -6,6 +6,7 @@ import com.linearpast.sccore.animation.data.AnimationData; import com.linearpast.sccore.animation.data.Ride; import com.linearpast.sccore.animation.register.AnimationEntities; import com.linearpast.sccore.animation.service.AnimationService; +import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.ClientGamePacketListener; @@ -103,7 +104,7 @@ public class AnimationRideEntity extends Entity { } @Nullable - public static AnimationRideEntity create(ServerPlayer pPlayer, ResourceLocation layer, AnimationData anim, boolean force) { + public static AnimationRideEntity create(ServerPlayer pPlayer, ResourceLocation layer, AnimationData anim, boolean force, Vec3 pos) { if(anim == null) return null; if(anim.getRide() == null) return null; IAnimationCapability data = AnimationDataCapability.getCapability(pPlayer).orElse(null); @@ -114,7 +115,6 @@ public class AnimationRideEntity extends Entity { float yRot = anim.getRide().getYRot(); if(xRot == 0 && yRot == 0) seat.setRot(pPlayer.getXRot(), pPlayer.getYRot()); else seat.setRot(yRot, xRot); - Vec3 pos = pPlayer.position(); pos.add(anim.getRide().getOffset()); seat.setPos(pos.x, pos.y + 0.35f, pos.z); pPlayer.level().addFreshEntity(seat); @@ -122,6 +122,16 @@ public class AnimationRideEntity extends Entity { return seat; } + @Nullable + public static AnimationRideEntity create(ServerPlayer pPlayer, ResourceLocation layer, AnimationData anim, boolean force) { + return create(pPlayer, layer, anim, force, pPlayer.position()); + } + + @Nullable + public static AnimationRideEntity create(ServerPlayer pPlayer, ResourceLocation layer, AnimationData anim, boolean force, BlockPos pos) { + return create(pPlayer, layer, anim, force, pos.getCenter()); + } + @Override protected void positionRider(@NotNull Entity pPassenger, @NotNull MoveFunction pCallback) { super.positionRider(pPassenger, pCallback); diff --git a/src/main/java/com/linearpast/sccore/animation/event/client/ClientPlayerEvent.java b/src/main/java/com/linearpast/sccore/animation/event/client/ClientPlayerEvent.java index 38341b0..3aaeff8 100644 --- a/src/main/java/com/linearpast/sccore/animation/event/client/ClientPlayerEvent.java +++ b/src/main/java/com/linearpast/sccore/animation/event/client/ClientPlayerEvent.java @@ -1,6 +1,6 @@ package com.linearpast.sccore.animation.event.client; -import com.linearpast.sccore.animation.service.AnimationService; +import com.linearpast.sccore.animation.AnimationApi; import net.minecraft.client.player.AbstractClientPlayer; import net.minecraft.world.entity.player.Player; import net.minecraftforge.api.distmarker.Dist; @@ -19,7 +19,7 @@ public class ClientPlayerEvent { Player player = event.player; if(player.tickCount % 10 != 0) return; if (!(player instanceof AbstractClientPlayer clientPlayer)) return; - AnimationService.INSTANCE.refreshAnimation(clientPlayer); + AnimationApi.getHelper(clientPlayer).refreshAnimation(); } } diff --git a/src/main/java/com/linearpast/sccore/animation/helper/AnimationHelper.java b/src/main/java/com/linearpast/sccore/animation/helper/AnimationHelper.java index 581ecba..8737066 100644 --- a/src/main/java/com/linearpast/sccore/animation/helper/AnimationHelper.java +++ b/src/main/java/com/linearpast/sccore/animation/helper/AnimationHelper.java @@ -8,9 +8,11 @@ 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.core.BlockPos; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.phys.Vec3; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import org.jetbrains.annotations.Nullable; @@ -51,6 +53,17 @@ public class AnimationHelper { () -> service.playAnimationWithRide(lazyRun.getClientPlayer(), layer, animation.getKey(), isForce) ); } + public ApiBack playAnimationWithRide(ResourceLocation layer, AnimationData animation, boolean isForce, Vec3 pos) { + IAnimationService service = AnimationApi.getServiceGetterHelper(animation.getKey()).getService(); + if(service == null) return ApiBack.FAIL; + return lazyRun.testLoadedAndCall( + () -> service.playAnimationWithRide(lazyRun.getServerPlayer(), layer, animation, isForce, pos), + () -> ApiBack.UNSUPPORTED + ); + } + public ApiBack playAnimationWithRide(ResourceLocation layer, AnimationData animation, boolean isForce, BlockPos pos) { + return playAnimationWithRide(layer, animation, isForce, pos.getCenter()); + } public void clearAnimation() { for (IAnimationService service : AnimationApi.getServiceGetterHelper().getAllServices()) { diff --git a/src/main/java/com/linearpast/sccore/animation/network/toserver/StopAnimationPacket.java b/src/main/java/com/linearpast/sccore/animation/network/toserver/StopAnimationPacket.java new file mode 100644 index 0000000..335116e --- /dev/null +++ b/src/main/java/com/linearpast/sccore/animation/network/toserver/StopAnimationPacket.java @@ -0,0 +1,30 @@ +package com.linearpast.sccore.animation.network.toserver; + +import com.linearpast.sccore.animation.AnimationApi; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerPlayer; +import net.minecraftforge.network.NetworkEvent; + +import java.util.function.Supplier; + +public record StopAnimationPacket(ResourceLocation layer) { + public StopAnimationPacket(FriendlyByteBuf buf) { + this(buf.readResourceLocation()); + } + + public void encode(FriendlyByteBuf buf) { + buf.writeResourceLocation(layer); + } + + public void handle(Supplier supplier) { + NetworkEvent.Context context = supplier.get(); + context.enqueueWork(() -> { + context.setPacketHandled(true); + ServerPlayer sender = context.getSender(); + if(sender == null) return; + AnimationApi.getHelper(sender).removeAnimation(layer); + }); + } + +} diff --git a/src/main/java/com/linearpast/sccore/animation/register/AnimationChannels.java b/src/main/java/com/linearpast/sccore/animation/register/AnimationChannels.java index c0c6186..5f8c979 100644 --- a/src/main/java/com/linearpast/sccore/animation/register/AnimationChannels.java +++ b/src/main/java/com/linearpast/sccore/animation/register/AnimationChannels.java @@ -57,6 +57,11 @@ public class AnimationChannels { .encoder(RequestAnimationPacket::encode) .consumerMainThread(RequestAnimationPacket::handle) .add(); + ModChannel.INSTANCE.messageBuilder(StopAnimationPacket.class, cid(), NetworkDirection.PLAY_TO_SERVER) + .decoder(StopAnimationPacket::new) + .encoder(StopAnimationPacket::encode) + .consumerMainThread(StopAnimationPacket::handle) + .add(); } private static int cid() { diff --git a/src/main/java/com/linearpast/sccore/animation/service/IAnimationService.java b/src/main/java/com/linearpast/sccore/animation/service/IAnimationService.java index c609004..ee58632 100644 --- a/src/main/java/com/linearpast/sccore/animation/service/IAnimationService.java +++ b/src/main/java/com/linearpast/sccore/animation/service/IAnimationService.java @@ -21,12 +21,15 @@ import com.linearpast.sccore.core.ModCompatRun; import com.linearpast.sccore.core.configs.ModConfigs; import dev.kosmx.playerAnim.core.data.KeyframeAnimation; import dev.kosmx.playerAnim.minecraftApi.PlayerAnimationRegistry; +import net.minecraft.client.Minecraft; import net.minecraft.client.player.AbstractClientPlayer; +import net.minecraft.client.player.LocalPlayer; import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.phys.Vec3; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.common.MinecraftForge; @@ -251,6 +254,10 @@ public interface IAnimationService { AnimationUtils.removeAnimation(player, layer); + LocalPlayer self = Minecraft.getInstance().player; + if(self != null && player != null && Objects.equals(self.getUUID(), player.getUUID())) { + ModChannel.INSTANCE.sendToServer(new StopAnimationPacket(layer)); + } return ApiBack.SUCCESS; }); } @@ -280,7 +287,7 @@ public interface IAnimationService { ResourceLocation key = animation.getKey(); if(!isAnimationLayerPresent(layer) || !isAnimationPresent(key)) @@ -292,10 +299,13 @@ public interface IAnimationService diff --git a/src/main/java/com/linearpast/sccore/animation/utils/AnimationUtils.java b/src/main/java/com/linearpast/sccore/animation/utils/AnimationUtils.java index 749f0d7..8ee7f33 100644 --- a/src/main/java/com/linearpast/sccore/animation/utils/AnimationUtils.java +++ b/src/main/java/com/linearpast/sccore/animation/utils/AnimationUtils.java @@ -81,16 +81,18 @@ public class AnimationUtils { Set resourceLocations = new HashSet<>(); if(layer == null) resourceLocations.addAll(AnimationRegistry.getLayers().keySet()); else resourceLocations.add(layer); + boolean isNoneAnimation = true; for (ResourceLocation location : resourceLocations) { ModifierLayer animationModifierLayer = (ModifierLayer) PlayerAnimationAccess .getPlayerAssociatedData(player).get(location); if(animationModifierLayer == null) continue; KeyframeAnimationPlayer animation = (KeyframeAnimationPlayer) animationModifierLayer.getAnimation(); - if(animation == null) return false; + if(animation == null) continue; int currentTick = animation.getCurrentTick(); int stopTick = animation.getStopTick(); - return currentTick > stopTick; + if(currentTick < stopTick) isNoneAnimation = false; } + return isNoneAnimation; } catch (Exception ignored) {} return true; });