version 0.1.2

This commit is contained in:
LostInLinearPast 2025-12-04 19:44:07 +08:00
parent c855f39bf0
commit 6a14c7e768
4 changed files with 46 additions and 32 deletions

View File

@ -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.1.4 mod_version=1.20.1-0.1.2
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.

View File

@ -224,6 +224,7 @@ public class AnimationRegistry {
public static boolean isAnimationRegistered = false; public static boolean isAnimationRegistered = false;
private static final Map<ResourceLocation, GenericAnimationData> animationsCache = new HashMap<>(); private static final Map<ResourceLocation, GenericAnimationData> animationsCache = new HashMap<>();
private static final Map<ResourceLocation, Integer> layersCache = new HashMap<>(); private static final Map<ResourceLocation, Integer> layersCache = new HashMap<>();
private static final Map<ResourceLocation, IAnimation> modifierLayers = new HashMap<>();
public static void cacheAddAnimation(ResourceLocation location, GenericAnimationData animation) { public static void cacheAddAnimation(ResourceLocation location, GenericAnimationData animation) {
animationsCache.put(location, animation); animationsCache.put(location, animation);
@ -249,10 +250,14 @@ public class AnimationRegistry {
} }
case LAYER_REGISTER -> { case LAYER_REGISTER -> {
registerLayers(layersCache); registerLayers(layersCache);
layersCache.forEach((key, value) -> layersCache.forEach((key, value) -> PlayerAnimationFactory.ANIMATION_DATA_FACTORY.registerFactory(
PlayerAnimationFactory.ANIMATION_DATA_FACTORY.registerFactory( key, value, player -> {
key, value, ClientCache::registerPlayerAnimation Optional<ResourceLocation> optional = modifierLayers.keySet().stream().filter(key::equals).findFirst();
) if(optional.isPresent()) return modifierLayers.get(optional.get());
IAnimation iAnimation = ClientCache.registerPlayerAnimation(player);
modifierLayers.put(key, iAnimation);
return iAnimation;
})
); );
ClientLevel level = Minecraft.getInstance().level; ClientLevel level = Minecraft.getInstance().level;
if(level == null) { if(level == null) {
@ -279,8 +284,17 @@ public class AnimationRegistry {
ArrayList<Pair<Integer, IAnimation>> oldArrayList = (ArrayList<Pair<Integer, IAnimation>>) layersField.get(oldAnimationStack); ArrayList<Pair<Integer, IAnimation>> oldArrayList = (ArrayList<Pair<Integer, IAnimation>>) layersField.get(oldAnimationStack);
ArrayList<Pair<Integer, IAnimation>> newArrayList = (ArrayList<Pair<Integer, IAnimation>>) layersField.get(newAnimationStack); ArrayList<Pair<Integer, IAnimation>> newArrayList = (ArrayList<Pair<Integer, IAnimation>>) layersField.get(newAnimationStack);
ArrayList<Pair<Integer, IAnimation>> result = new ArrayList<>(); ArrayList<Pair<Integer, IAnimation>> result = new ArrayList<>();
for (Pair<Integer, IAnimation> integerIAnimationPair : oldArrayList) {
for (Pair<Integer, IAnimation> iAnimationPair : List.copyOf(newArrayList)) {
if(Objects.equals(iAnimationPair.getLeft(), integerIAnimationPair.getLeft())
&& Objects.equals(iAnimationPair.getRight(), integerIAnimationPair.getRight())) {
newArrayList.remove(iAnimationPair);
}
}
}
result.addAll(oldArrayList); result.addAll(oldArrayList);
result.addAll(newArrayList); result.addAll(newArrayList);
layersField.set(newAnimationStack, result); layersField.set(newAnimationStack, result);
animationStackField.set(player, newAnimationStack); animationStackField.set(player, newAnimationStack);
Field animationApplierField = playerClass.getDeclaredField("animationApplier"); Field animationApplierField = playerClass.getDeclaredField("animationApplier");

View File

@ -42,7 +42,7 @@ public class RawAnimationService implements IAnimationService<RawAnimationData,
if(FMLEnvironment.dist == Dist.CLIENT) { if(FMLEnvironment.dist == Dist.CLIENT) {
return RawAnimationRegistry.getAnimations().getOrDefault(location, null); return RawAnimationRegistry.getAnimations().getOrDefault(location, null);
} else { } else {
return null; return RawAnimationData.create(location);
} }
} }

View File

@ -1,7 +1,7 @@
package com.linearpast.sccore.example.animation; package com.linearpast.sccore.example.animation;
import com.linearpast.sccore.SnowyCrescentCore; import com.linearpast.sccore.SnowyCrescentCore;
import com.linearpast.sccore.animation.data.RawAnimationData; import com.linearpast.sccore.animation.data.GenericAnimationData;
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.service.AnimationService; import com.linearpast.sccore.animation.service.AnimationService;
@ -47,38 +47,38 @@ public class ModAnimation {
*/ */
public static void onAnimationRegister(AnimationRegisterEvent.Animation event) { public static void onAnimationRegister(AnimationRegisterEvent.Animation event) {
//You must define corresponding Animation to invite //You must define corresponding Animation to invite
// Animation amLTRL = Animation.create(AmLyingToRightLying) GenericAnimationData amLTRL = GenericAnimationData.create(AmLyingToRightLying)
// .withLyingType(Animation.LyingType.RIGHT) .withLyingType(GenericAnimationData.LyingType.RIGHT)
// .withName("Lying-to-Right-Lying"); .withName("Lying-to-Right-Lying");
// Animation amSTL = Animation.create(AmStandToLying) GenericAnimationData amSTL = GenericAnimationData.create(AmStandToLying)
// .withName("Stand-to-Lying") .withName("Stand-to-Lying")
// .withLyingType(Animation.LyingType.FRONT); .withLyingType(GenericAnimationData.LyingType.FRONT);
// Animation waltzGentleman = Animation.create(WaltzGentleman) GenericAnimationData waltzGentleman = GenericAnimationData.create(WaltzGentleman)
// .withName("Waltz-Gentleman") .withName("Waltz-Gentleman")
// .withRide(Ride.create().addComponentAnimation(WaltzLady)); .withRide(Ride.create().addComponentAnimation(WaltzLady));
// Animation waltzLady = Animation.create(WaltzLady) GenericAnimationData waltzLady = GenericAnimationData.create(WaltzLady)
// .withName("Waltz-Lady") .withName("Waltz-Lady")
// .withCamYaw(180) .withCamYaw(180)
// .withRide(Ride.create().addComponentAnimation(WaltzGentleman)); .withRide(Ride.create().addComponentAnimation(WaltzGentleman));
//
// //You can use it to invite an Animation
// event.registerAnimation(AmLyingToRightLying, amLTRL);
// event.registerAnimation(AmStandToLying, amSTL);
// event.registerAnimation(WaltzGentleman, waltzGentleman);
// event.registerAnimation(WaltzLady, waltzLady);
}
public static void onRawAnimationRegister(AnimationRegisterEvent.RawAnimation event) { //You can use it to invite an Animation
RawAnimationData amSTL = RawAnimationData.create(AmStandToLying).withRide(Ride.create().withExistTick(100));
RawAnimationData amLTRL = RawAnimationData.create(AmLyingToRightLying).withRide(Ride.create().withExistTick(100));
RawAnimationData waltzGentleman = RawAnimationData.create(WaltzGentleman).withRide(Ride.create().withExistTick(100).addComponentAnimation(WaltzLady));
RawAnimationData waltzLady = RawAnimationData.create(WaltzLady).withRide(Ride.create().withExistTick(100).addComponentAnimation(WaltzGentleman));
event.registerAnimation(AmLyingToRightLying, amLTRL); event.registerAnimation(AmLyingToRightLying, amLTRL);
event.registerAnimation(AmStandToLying, amSTL); event.registerAnimation(AmStandToLying, amSTL);
event.registerAnimation(WaltzGentleman, waltzGentleman); event.registerAnimation(WaltzGentleman, waltzGentleman);
event.registerAnimation(WaltzLady, waltzLady); event.registerAnimation(WaltzLady, waltzLady);
} }
public static void onRawAnimationRegister(AnimationRegisterEvent.RawAnimation event) {
// RawAnimationData amSTL = RawAnimationData.create(AmStandToLying).withRide(Ride.create().withExistTick(100));
// RawAnimationData amLTRL = RawAnimationData.create(AmLyingToRightLying).withRide(Ride.create().withExistTick(100));
// RawAnimationData waltzGentleman = RawAnimationData.create(WaltzGentleman).withRide(Ride.create().withExistTick(100).addComponentAnimation(WaltzLady));
// RawAnimationData waltzLady = RawAnimationData.create(WaltzLady).withRide(Ride.create().withExistTick(100).addComponentAnimation(WaltzGentleman));
// event.registerAnimation(AmLyingToRightLying, amLTRL);
// event.registerAnimation(AmStandToLying, amSTL);
// event.registerAnimation(WaltzGentleman, waltzGentleman);
// event.registerAnimation(WaltzLady, waltzLady);
}
public static void register(IEventBus forgeBus, IEventBus modBus) { public static void register(IEventBus forgeBus, IEventBus modBus) {
//Register by event //Register by event
//Or use AnimationUtils.registerAnimationLayer(ResourceLocation layer, int priority); //Or use AnimationUtils.registerAnimationLayer(ResourceLocation layer, int priority);