Merge remote-tracking branch 'origin/master'

# Conflicts:
#	src/main/java/com/linearpast/sccore/animation/network/toclient/AnimationClearPacket.java
This commit is contained in:
叁玖领域 2026-01-12 12:11:56 +08:00
commit 667a786c77
13 changed files with 147 additions and 57 deletions

View File

@ -173,6 +173,7 @@ tasks.named('jar', Jar).configure {
])
}
archiveFileName = "${mod_id}-${mod_version}-origin.jar"
finalizedBy 'reobfJar'
}
@ -251,8 +252,12 @@ publishing {
gradle.buildFinished {
def javadocJar = file("build/libs/${mod_id}-${mod_version}-javadoc.jar")
def sourcesJar = file("build/libs/${mod_id}-${mod_version}-sources.jar")
def allJarsJar = file("build/libs/${mod_id}-${mod_version}-all.jar")
if (javadocJar.exists()) ant.delete(file: javadocJar)
if (sourcesJar.exists()) ant.delete(file: sourcesJar)
if (allJarsJar.exists()) {
ant.move(file: allJarsJar, tofile: file("build/libs/${mod_id}-${mod_version}.jar"))
}
}
tasks.withType(JavaCompile).configureEach {

View File

@ -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.7.1
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.

View File

@ -66,22 +66,35 @@ public class AnimJson {
GenericAnimationData animation = GenericAnimationData.create(new ResourceLocation(json.get(Key).getAsString()));
if(json.has(Name)) animation.withName(json.get(Name).getAsString());
if(json.has(LyingType)) animation.withLyingType(AnimationData.LyingType.valueOf(json.get(LyingType).getAsString()));
JsonObject camOffset = json.get(CamPosOffset).getAsJsonObject();
animation.withHeightModifier(json.get(HeightModifier).getAsFloat())
.withCamComputePriority(json.get(Priority).getAsInt())
.setCamPosOffset(new Vec3(
camOffset.get("x").getAsDouble(),
camOffset.get("y").getAsDouble(),
camOffset.get("z").getAsDouble()
))
.withCamPosOffsetRelative(camOffset.get(Relative).getAsBoolean())
.withCamPitch(json.get(CamPitch).getAsFloat())
.withCamRoll(json.get(CamRoll).getAsFloat())
.withCamYaw(json.get(CamYaw).getAsFloat());
if(json.has(HeightModifier)) animation.withHeightModifier(json.get(HeightModifier).getAsFloat());
if(json.has(Priority)) animation.withCamComputePriority(json.get(Priority).getAsInt());
if(json.has(CamPitch)) animation.withCamPitch(json.get(CamPitch).getAsFloat());
if(json.has(CamRoll)) animation.withCamRoll(json.get(CamRoll).getAsFloat());
if(json.has(CamYaw)) animation.withCamYaw(json.get(CamYaw).getAsFloat());
if(json.has(CamPosOffset)) {
JsonObject camOffset = json.get(CamPosOffset).getAsJsonObject();
Vec3 vec3 = Vec3.ZERO;
if(camOffset.has("x")) vec3 = vec3.add(camOffset.get("x").getAsDouble(), 0, 0);
if(camOffset.has("y")) vec3 = vec3.add(0, camOffset.get("y").getAsDouble(), 0);
if(camOffset.has("z")) vec3 = vec3.add(0, 0, camOffset.get("z").getAsDouble());
if(!vec3.equals(Vec3.ZERO)) animation.setCamPosOffset(vec3);
if(camOffset.has(Relative)) animation.withCamPosOffsetRelative(camOffset.get(Relative).getAsBoolean());
}
if(json.has(WithRide)){
Ride ride = Ride.create();
JsonObject withRide = json.get(WithRide).getAsJsonObject();
JsonObject offsetJson = withRide.get(Offset).getAsJsonObject();
if(withRide.has(ExistTick)) ride.setExistTick(withRide.get(ExistTick).getAsInt());
if(withRide.has(XRot)) ride.setXRot(withRide.get(XRot).getAsFloat());
if(withRide.has(YRot)) ride.setYRot(withRide.get(YRot).getAsFloat());
if(withRide.has(Offset)) {
JsonObject offsetJson = withRide.get(Offset).getAsJsonObject();
Vec3 offset = new Vec3(
offsetJson.get("x").getAsDouble(),
offsetJson.get("y").getAsDouble(),
offsetJson.get("z").getAsDouble()
);
ride.withOffset(offset);
}
if(withRide.has(ComponentsAnimation)){
JsonArray elements = withRide.get(ComponentsAnimation).getAsJsonArray();
for (JsonElement element : elements) {
@ -90,14 +103,6 @@ public class AnimJson {
ride.addComponentAnimation(componentKey);
}
}
Vec3 offset = new Vec3(
offsetJson.get("x").getAsDouble(),
offsetJson.get("y").getAsDouble(),
offsetJson.get("z").getAsDouble()
);
ride.withOffset(offset).withExistTick(withRide.get(ExistTick).getAsInt())
.withXRot(withRide.get(XRot).getAsFloat())
.withYRot(withRide.get(YRot).getAsFloat());
animation.withRide(ride);
}
return animation;

View File

@ -59,21 +59,34 @@ public class RawAnimJson {
JsonObject json = originElement.getAsJsonObject();
RawAnimationData animation = RawAnimationData.create(new ResourceLocation(json.get(Key).getAsString()));
if(json.has(LyingType)) animation.withLyingType(AnimationData.LyingType.valueOf(json.get(LyingType).getAsString()));
JsonObject camOffset = json.get(CamPosOffset).getAsJsonObject();
animation.withCamComputePriority(json.get(Priority).getAsInt())
.setCamPosOffset(new Vec3(
camOffset.get("x").getAsDouble(),
camOffset.get("y").getAsDouble(),
camOffset.get("z").getAsDouble()
))
.withCamPosOffsetRelative(camOffset.get(Relative).getAsBoolean())
.withCamPitch(json.get(CamPitch).getAsFloat())
.withCamRoll(json.get(CamRoll).getAsFloat())
.withCamYaw(json.get(CamYaw).getAsFloat());
if(json.has(Priority)) animation.withCamComputePriority(json.get(Priority).getAsInt());
if(json.has(CamPitch)) animation.withCamPitch(json.get(CamPitch).getAsFloat());
if(json.has(CamRoll)) animation.withCamRoll(json.get(CamRoll).getAsFloat());
if(json.has(CamYaw)) animation.withCamYaw(json.get(CamYaw).getAsFloat());
if(json.has(CamPosOffset)) {
JsonObject camOffset = json.get(CamPosOffset).getAsJsonObject();
Vec3 vec3 = Vec3.ZERO;
if(camOffset.has("x")) vec3 = vec3.add(camOffset.get("x").getAsDouble(), 0, 0);
if(camOffset.has("y")) vec3 = vec3.add(0, camOffset.get("y").getAsDouble(), 0);
if(camOffset.has("z")) vec3 = vec3.add(0, 0, camOffset.get("z").getAsDouble());
if(!vec3.equals(Vec3.ZERO)) animation.setCamPosOffset(vec3);
if(camOffset.has(Relative)) animation.withCamPosOffsetRelative(camOffset.get(Relative).getAsBoolean());
}
if(json.has(WithRide)){
Ride ride = Ride.create();
JsonObject withRide = json.get(WithRide).getAsJsonObject();
JsonObject offsetJson = withRide.get(Offset).getAsJsonObject();
if(withRide.has(ExistTick)) ride.setExistTick(withRide.get(ExistTick).getAsInt());
if(withRide.has(XRot)) ride.setXRot(withRide.get(XRot).getAsFloat());
if(withRide.has(YRot)) ride.setYRot(withRide.get(YRot).getAsFloat());
if(withRide.has(Offset)) {
JsonObject offsetJson = withRide.get(Offset).getAsJsonObject();
Vec3 offset = new Vec3(
offsetJson.get("x").getAsDouble(),
offsetJson.get("y").getAsDouble(),
offsetJson.get("z").getAsDouble()
);
ride.withOffset(offset);
}
if(withRide.has(ComponentsAnimation)){
JsonArray elements = withRide.get(ComponentsAnimation).getAsJsonArray();
for (JsonElement element : elements) {
@ -82,14 +95,6 @@ public class RawAnimJson {
ride.addComponentAnimation(componentKey);
}
}
Vec3 offset = new Vec3(
offsetJson.get("x").getAsDouble(),
offsetJson.get("y").getAsDouble(),
offsetJson.get("z").getAsDouble()
);
ride.withOffset(offset).withExistTick(withRide.get(ExistTick).getAsInt())
.withXRot(withRide.get(XRot).getAsFloat())
.withYRot(withRide.get(YRot).getAsFloat());
animation.withRide(ride);
}
return animation;

View File

@ -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);

View File

@ -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();
}
}

View File

@ -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()) {

View File

@ -24,15 +24,17 @@ public record AnimationClearPacket(@Nullable ResourceLocation layer) {
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);
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> this::handleClient);
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> this::handle);
});
}
@OnlyIn(Dist.CLIENT)
public void handleClient() {
public void handle(){
LocalPlayer player = Minecraft.getInstance().player;
if(player == null) return;
List<ResourceLocation> layers = new ArrayList<>();

View File

@ -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<NetworkEvent.Context> supplier) {
NetworkEvent.Context context = supplier.get();
context.enqueueWork(() -> {
context.setPacketHandled(true);
ServerPlayer sender = context.getSender();
if(sender == null) return;
AnimationApi.getHelper(sender).removeAnimation(layer);
});
}
}

View File

@ -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() {

View File

@ -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<D extends AnimationData, C extends ICapabilit
default ApiBack removeAnimation(@Nullable AbstractClientPlayer player, ResourceLocation layer) {
return ANIMATION_RUNNER.testLoadedAndCall(() -> {
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<D extends AnimationData, C extends ICapabilit
return ApiBack.SUCCESS;
});
}
default ApiBack playAnimationWithRide(@NotNull ServerPlayer player, ResourceLocation layer, AnimationData animation, boolean force) {
default ApiBack playAnimationWithRide(@NotNull ServerPlayer player, ResourceLocation layer, AnimationData animation, boolean force, Vec3 pos) {
return ANIMATION_RUNNER.testLoadedAndCall(() -> {
ResourceLocation key = animation.getKey();
if(!isAnimationLayerPresent(layer) || !isAnimationPresent(key))
@ -292,10 +299,13 @@ public interface IAnimationService<D extends AnimationData, C extends ICapabilit
boolean flag = player.getVehicle() != null;
if(flag && force) player.stopRiding();
else if(flag) return ApiBack.UNSUPPORTED;
boolean result = AnimationRideEntity.create(player, layer, animation, force) != null;
boolean result = AnimationRideEntity.create(player, layer, animation, force, pos) != null;
return result ? ApiBack.SUCCESS : ApiBack.FAIL;
});
};
}
default ApiBack playAnimationWithRide(@NotNull ServerPlayer player, ResourceLocation layer, AnimationData animation, boolean force) {
return playAnimationWithRide(player, layer, animation, force, player.position());
}
/**
* <pre>

View File

@ -81,16 +81,18 @@ public class AnimationUtils {
Set<ResourceLocation> resourceLocations = new HashSet<>();
if(layer == null) resourceLocations.addAll(AnimationRegistry.getLayers().keySet());
else resourceLocations.add(layer);
boolean isNoneAnimation = true;
for (ResourceLocation location : resourceLocations) {
ModifierLayer<IAnimation> animationModifierLayer = (ModifierLayer<IAnimation>) 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;
});

View File

@ -2,7 +2,8 @@ package com.linearpast.sccore.mixin;
import com.linearpast.sccore.SnowyCrescentCore;
import com.linearpast.sccore.animation.service.AnimationService;
import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.loading.LoadingModList;
import net.minecraftforge.fml.loading.moddiscovery.ModInfo;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
@ -23,11 +24,13 @@ public class SCCoreMixinPlugin implements IMixinConfigPlugin {
@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
if (targetClassName.startsWith("runData\\.")) {
if (targetClassName.startsWith("runData.")) {
return "runData".equals(System.getProperty("gradle.task"));
}
if (mixinClassName.startsWith("com\\.linearpast\\." + SnowyCrescentCore.MODID + "\\.mixin\\.animation")) {
return ModList.get().isLoaded(AnimationService.AnimModId);
if (mixinClassName.startsWith("com.linearpast." + SnowyCrescentCore.MODID + ".mixin.animation.")) {
return LoadingModList.get().getMods().stream().map(ModInfo::getModId).anyMatch(
s -> s.equals(AnimationService.AnimModId)
);
}
return true;
}