version 0.1.6
This commit is contained in:
parent
64319a48df
commit
e3146feff3
|
|
@ -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.5.1
|
||||
mod_version=1.20.1-0.1.6
|
||||
mod_group_id=com.linearpast
|
||||
mod_authors=LostInLinearPast
|
||||
mod_description=A lib about capability and player animator.
|
||||
|
|
|
|||
|
|
@ -8,9 +8,11 @@ import com.linearpast.sccore.animation.command.exception.ApiBackException;
|
|||
import com.linearpast.sccore.animation.data.AnimationData;
|
||||
import com.linearpast.sccore.animation.helper.AnimationHelper;
|
||||
import com.linearpast.sccore.animation.helper.AnimationServiceGetterHelper;
|
||||
import com.linearpast.sccore.animation.network.toclient.AnimationClearPacket;
|
||||
import com.linearpast.sccore.animation.service.IAnimationService;
|
||||
import com.linearpast.sccore.animation.service.RawAnimationService;
|
||||
import com.linearpast.sccore.animation.utils.ApiBack;
|
||||
import com.linearpast.sccore.core.ModChannel;
|
||||
import com.linearpast.sccore.core.datagen.ModLang;
|
||||
import com.mojang.brigadier.arguments.BoolArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
|
|
@ -228,6 +230,7 @@ public class PlayCommand {
|
|||
AnimationHelper helper = AnimationApi.getHelper(player);
|
||||
helper.clearAnimation();
|
||||
helper.detachAnimation();
|
||||
ModChannel.sendToPlayer(new AnimationClearPacket((ResourceLocation) null), player);
|
||||
});
|
||||
source.sendSuccess(() -> Component.translatable(
|
||||
ModLang.TranslatableMessage.CLEAR_ANIMATIONS.getKey()
|
||||
|
|
|
|||
|
|
@ -2,17 +2,23 @@ package com.linearpast.sccore.animation.command.client;
|
|||
|
||||
import com.linearpast.sccore.SnowyCrescentCore;
|
||||
import com.linearpast.sccore.animation.AnimationApi;
|
||||
import com.linearpast.sccore.animation.register.AnimationRegistry;
|
||||
import com.linearpast.sccore.core.datagen.ModLang;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import dev.kosmx.playerAnim.api.layered.IAnimation;
|
||||
import dev.kosmx.playerAnim.minecraftApi.PlayerAnimationAccess;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static net.minecraft.commands.Commands.literal;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
|
|
@ -28,6 +34,15 @@ public class RefreshCommand {
|
|||
LocalPlayer player = instance.player;
|
||||
if(player == null) throw new RuntimeException();
|
||||
AnimationApi.getHelper(player).refreshAnimation();
|
||||
|
||||
for (ResourceLocation layer : Set.copyOf(AnimationRegistry.getLayers().keySet())) {
|
||||
PlayerAnimationAccess.PlayerAssociatedAnimationData playerAssociatedData = PlayerAnimationAccess.getPlayerAssociatedData(player);
|
||||
IAnimation iAnimation = playerAssociatedData.get(layer);
|
||||
if(iAnimation == null) continue;
|
||||
ResourceLocation playing = AnimationApi.getHelper(player).getAnimationPlaying(layer);
|
||||
if(playing == null) playerAssociatedData.set(layer, null);
|
||||
}
|
||||
|
||||
source.sendSuccess(() -> Component.translatable(
|
||||
ModLang.TranslatableMessage.REFRESH_ANIMATIONS.getKey()
|
||||
).withStyle(ChatFormatting.GREEN), true);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
package com.linearpast.sccore.animation.network.toclient;
|
||||
|
||||
import com.linearpast.sccore.animation.register.AnimationRegistry;
|
||||
import dev.kosmx.playerAnim.minecraftApi.PlayerAnimationAccess;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public record AnimationClearPacket(@Nullable ResourceLocation layer) {
|
||||
public AnimationClearPacket(FriendlyByteBuf buf) {
|
||||
this(buf.readNullable(FriendlyByteBuf::readResourceLocation));
|
||||
}
|
||||
|
||||
public void encode(FriendlyByteBuf buf) {
|
||||
buf.writeNullable(layer, FriendlyByteBuf::writeResourceLocation);
|
||||
}
|
||||
|
||||
public void handle(Supplier<NetworkEvent.Context> supplier) {
|
||||
NetworkEvent.Context context = supplier.get();
|
||||
context.enqueueWork(() -> {
|
||||
context.setPacketHandled(true);
|
||||
LocalPlayer player = Minecraft.getInstance().player;
|
||||
if(player == null) return;
|
||||
List<ResourceLocation> layers = new ArrayList<>();
|
||||
if(layer != null) layers.add(layer);
|
||||
else layers.addAll(AnimationRegistry.getLayers().keySet());
|
||||
layers.forEach(layer -> PlayerAnimationAccess
|
||||
.getPlayerAssociatedData(player).set(layer, null)
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package com.linearpast.sccore.animation.register;
|
||||
|
||||
import com.linearpast.sccore.animation.network.toclient.AnimationClearPacket;
|
||||
import com.linearpast.sccore.animation.network.toclient.AnimationClientStatusPacket;
|
||||
import com.linearpast.sccore.animation.network.toclient.AnimationJsonPacket;
|
||||
import com.linearpast.sccore.animation.network.toclient.SyncAnimationPacket;
|
||||
|
|
@ -24,6 +25,11 @@ public class AnimationChannels {
|
|||
.encoder(AnimationClientStatusPacket::encode)
|
||||
.consumerMainThread(AnimationClientStatusPacket::handle)
|
||||
.add();
|
||||
ModChannel.INSTANCE.messageBuilder(AnimationClearPacket.class, cid(), NetworkDirection.PLAY_TO_SERVER)
|
||||
.decoder(AnimationClearPacket::new)
|
||||
.encoder(AnimationClearPacket::encode)
|
||||
.consumerMainThread(AnimationClearPacket::handle)
|
||||
.add();
|
||||
|
||||
//To server
|
||||
ModChannel.INSTANCE.messageBuilder(PlayAnimationPacket.class, cid(), NetworkDirection.PLAY_TO_SERVER)
|
||||
|
|
|
|||
|
|
@ -240,7 +240,7 @@ public class AnimationUtils {
|
|||
ArrayList<ResourceLocation> resourceLocations = new ArrayList<>();
|
||||
resourceLocations.addAll(data.getAnimations().values());
|
||||
resourceLocations.addAll(rawData.getAnimations().values());
|
||||
resourceLocations.add(data.getRiderAnimation());
|
||||
if(data.getRiderAnimation() != null) resourceLocations.add(data.getRiderAnimation());
|
||||
for (ResourceLocation value : resourceLocations) {
|
||||
AnimationData animation = AnimationApi.getDataHelper().getAnimationData(value);
|
||||
if(animation == null) return null;
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ public abstract class MixinEntity {
|
|||
if(data == null) return original;
|
||||
Map.Entry<Float, Integer> entry = null;
|
||||
List<ResourceLocation> values = new ArrayList<>(data.getAnimations().values());
|
||||
values.add(data.getRiderAnimation());
|
||||
if(data.getRiderAnimation() != null) values.add(data.getRiderAnimation());
|
||||
for (ResourceLocation value : values) {
|
||||
GenericAnimationData animation = AnimationService.INSTANCE.getAnimation(value);
|
||||
if(animation == null) continue;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user