version 0.1.7
This commit is contained in:
parent
e3146feff3
commit
2745b4fb42
|
|
@ -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.6
|
mod_version=1.20.1-0.1.7
|
||||||
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.
|
||||||
|
|
|
||||||
|
|
@ -3,6 +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.AnimationData;
|
import com.linearpast.sccore.animation.data.AnimationData;
|
||||||
|
import com.linearpast.sccore.animation.data.RawAnimationData;
|
||||||
import com.linearpast.sccore.animation.utils.AnimationUtils;
|
import com.linearpast.sccore.animation.utils.AnimationUtils;
|
||||||
import dev.kosmx.playerAnim.core.util.MathHelper;
|
import dev.kosmx.playerAnim.core.util.MathHelper;
|
||||||
import net.minecraft.client.Camera;
|
import net.minecraft.client.Camera;
|
||||||
|
|
@ -89,6 +90,10 @@ public class CameraModify {
|
||||||
targetOffset = Vec3.ZERO;
|
targetOffset = Vec3.ZERO;
|
||||||
if(animation != null) {
|
if(animation != null) {
|
||||||
Vec3 camPosOffset = animation.getCamPosOffset().multiply(1,0,1);
|
Vec3 camPosOffset = animation.getCamPosOffset().multiply(1,0,1);
|
||||||
|
AnimationData data = AnimationUtils.getEyeModifierAnimationData(player);
|
||||||
|
if(data instanceof RawAnimationData) {
|
||||||
|
camPosOffset = camPosOffset.add(0, data.getCamPosOffset().y, 0);
|
||||||
|
}
|
||||||
if(animation.isCamPosOffsetRelative()) {
|
if(animation.isCamPosOffsetRelative()) {
|
||||||
float yRot = player.yBodyRotO + (player.yBodyRot - player.yBodyRotO) * minecraft.getPartialTick();
|
float yRot = player.yBodyRotO + (player.yBodyRot - player.yBodyRotO) * minecraft.getPartialTick();
|
||||||
float bodyAngel = -(yRot + 90) * ((float)Math.PI / 180F);
|
float bodyAngel = -(yRot + 90) * ((float)Math.PI / 180F);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package com.linearpast.sccore.animation.network.toclient;
|
package com.linearpast.sccore.animation.network.toclient;
|
||||||
|
|
||||||
import com.linearpast.sccore.animation.register.AnimationRegistry;
|
import com.linearpast.sccore.animation.register.AnimationRegistry;
|
||||||
import dev.kosmx.playerAnim.minecraftApi.PlayerAnimationAccess;
|
import com.linearpast.sccore.animation.utils.AnimationUtils;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.player.LocalPlayer;
|
import net.minecraft.client.player.LocalPlayer;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
|
|
@ -31,9 +31,7 @@ public record AnimationClearPacket(@Nullable ResourceLocation layer) {
|
||||||
List<ResourceLocation> layers = new ArrayList<>();
|
List<ResourceLocation> layers = new ArrayList<>();
|
||||||
if(layer != null) layers.add(layer);
|
if(layer != null) layers.add(layer);
|
||||||
else layers.addAll(AnimationRegistry.getLayers().keySet());
|
else layers.addAll(AnimationRegistry.getLayers().keySet());
|
||||||
layers.forEach(layer -> PlayerAnimationAccess
|
layers.forEach(layer -> AnimationUtils.playAnimation(player, layer, null));
|
||||||
.getPlayerAssociatedData(player).set(layer, null)
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ public class AnimationChannels {
|
||||||
.encoder(AnimationClientStatusPacket::encode)
|
.encoder(AnimationClientStatusPacket::encode)
|
||||||
.consumerMainThread(AnimationClientStatusPacket::handle)
|
.consumerMainThread(AnimationClientStatusPacket::handle)
|
||||||
.add();
|
.add();
|
||||||
ModChannel.INSTANCE.messageBuilder(AnimationClearPacket.class, cid(), NetworkDirection.PLAY_TO_SERVER)
|
ModChannel.INSTANCE.messageBuilder(AnimationClearPacket.class, cid(), NetworkDirection.PLAY_TO_CLIENT)
|
||||||
.decoder(AnimationClearPacket::new)
|
.decoder(AnimationClearPacket::new)
|
||||||
.encoder(AnimationClearPacket::encode)
|
.encoder(AnimationClearPacket::encode)
|
||||||
.consumerMainThread(AnimationClearPacket::handle)
|
.consumerMainThread(AnimationClearPacket::handle)
|
||||||
|
|
|
||||||
|
|
@ -206,9 +206,9 @@ public class AnimationRegistry {
|
||||||
registerLayers(layersCache);
|
registerLayers(layersCache);
|
||||||
layersCache.forEach((key, value) -> PlayerAnimationFactory.ANIMATION_DATA_FACTORY.registerFactory(
|
layersCache.forEach((key, value) -> PlayerAnimationFactory.ANIMATION_DATA_FACTORY.registerFactory(
|
||||||
key, value, player -> {
|
key, value, player -> {
|
||||||
|
if(Minecraft.getInstance().player == null) return ClientCache.registerPlayerAnimation(player);
|
||||||
Map<ResourceLocation, IAnimation> animationMap = modifierLayers.getOrDefault(player.getUUID(), new HashMap<>());
|
Map<ResourceLocation, IAnimation> animationMap = modifierLayers.getOrDefault(player.getUUID(), new HashMap<>());
|
||||||
Optional<ResourceLocation> optional = animationMap.keySet().stream().filter(key::equals).findFirst();
|
if(animationMap.containsKey(key)) return animationMap.get(key);
|
||||||
if(optional.isPresent()) return animationMap.get(optional.get());
|
|
||||||
IAnimation iAnimation = ClientCache.registerPlayerAnimation(player);
|
IAnimation iAnimation = ClientCache.registerPlayerAnimation(player);
|
||||||
animationMap.put(key, iAnimation);
|
animationMap.put(key, iAnimation);
|
||||||
modifierLayers.put(player.getUUID(), animationMap);
|
modifierLayers.put(player.getUUID(), animationMap);
|
||||||
|
|
@ -235,11 +235,14 @@ 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> oldAnimationPair : oldArrayList) {
|
||||||
for (Pair<Integer, IAnimation> iAnimationPair : List.copyOf(newArrayList)) {
|
for (Pair<Integer, IAnimation> newAnimationPair : List.copyOf(newArrayList)) {
|
||||||
if(Objects.equals(iAnimationPair.getLeft(), integerIAnimationPair.getLeft())
|
if(Objects.equals(oldAnimationPair.getLeft(), newAnimationPair.getLeft())) {
|
||||||
&& Objects.equals(iAnimationPair.getRight(), integerIAnimationPair.getRight())) {
|
KeyframeAnimation oldData = Optional.ofNullable((KeyframeAnimationPlayer) ((ModifierLayer<?>) oldAnimationPair.getRight()).getAnimation())
|
||||||
newArrayList.remove(iAnimationPair);
|
.map(KeyframeAnimationPlayer::getData).orElse(null);
|
||||||
|
KeyframeAnimation newData = Optional.ofNullable((KeyframeAnimationPlayer) ((ModifierLayer<?>) newAnimationPair.getRight()).getAnimation())
|
||||||
|
.map(KeyframeAnimationPlayer::getData).orElse(null);
|
||||||
|
if(Objects.equals(oldData, newData)) oldArrayList.remove(oldAnimationPair);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -243,11 +243,37 @@ public class AnimationUtils {
|
||||||
if(data.getRiderAnimation() != null) resourceLocations.add(data.getRiderAnimation());
|
if(data.getRiderAnimation() != null) resourceLocations.add(data.getRiderAnimation());
|
||||||
for (ResourceLocation value : resourceLocations) {
|
for (ResourceLocation value : resourceLocations) {
|
||||||
AnimationData animation = AnimationApi.getDataHelper().getAnimationData(value);
|
AnimationData animation = AnimationApi.getDataHelper().getAnimationData(value);
|
||||||
if(animation == null) return null;
|
if(animation == null) continue;
|
||||||
if(!predicate.test(animation)) continue;
|
if(!predicate.test(animation)) continue;
|
||||||
animations = new AbstractMap.SimpleEntry<>(animation.getCamComputePriority(), animation);
|
if(animations == null || animations.getKey() < animation.getCamComputePriority()) {
|
||||||
|
animations = new AbstractMap.SimpleEntry<>(animation.getCamComputePriority(), animation);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return animations == null ? null : animations.getValue();
|
return animations == null ? null : animations.getValue();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public static AnimationData getEyeModifierAnimationData(Player player) {
|
||||||
|
IAnimationCapability data = AnimationDataCapability.getCapability(player).orElse(null);
|
||||||
|
RawAnimationDataCapability rawData = RawAnimationDataCapability.getCapability(player).orElse(null);
|
||||||
|
if(data == null) return null;
|
||||||
|
if(rawData == null) return null;
|
||||||
|
Map.Entry<AnimationData, Integer> entry = null;
|
||||||
|
List<ResourceLocation> values = new ArrayList<>();
|
||||||
|
if(data.getRiderAnimation() != null) values.add(data.getRiderAnimation());
|
||||||
|
values.addAll(data.getAnimations().values());
|
||||||
|
values.addAll(rawData.getAnimations().values());
|
||||||
|
for (ResourceLocation value : values) {
|
||||||
|
AnimationData animation = AnimationApi.getDataHelper().getAnimationData(value);
|
||||||
|
if(animation == null) continue;
|
||||||
|
float animationCamY = (float) animation.getCamPosOffset().y;
|
||||||
|
int priority = animation.getCamComputePriority();
|
||||||
|
if((entry == null && animationCamY != 0)
|
||||||
|
|| (entry != null && priority > entry.getValue())) {
|
||||||
|
entry = new HashMap.SimpleEntry<>(animation, priority);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return entry == null ? null : entry.getKey();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,10 @@
|
||||||
package com.linearpast.sccore.mixin.animation;
|
package com.linearpast.sccore.mixin.animation;
|
||||||
|
|
||||||
import com.linearpast.sccore.animation.capability.AnimationDataCapability;
|
import com.linearpast.sccore.animation.data.AnimationData;
|
||||||
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.service.AnimationService;
|
import com.linearpast.sccore.animation.service.AnimationService;
|
||||||
|
import com.linearpast.sccore.animation.utils.AnimationUtils;
|
||||||
import com.llamalad7.mixinextras.injector.ModifyReturnValue;
|
import com.llamalad7.mixinextras.injector.ModifyReturnValue;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.Pose;
|
import net.minecraft.world.entity.Pose;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
|
@ -16,11 +15,6 @@ import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Mixin(Entity.class)
|
@Mixin(Entity.class)
|
||||||
public abstract class MixinEntity {
|
public abstract class MixinEntity {
|
||||||
@Shadow private AABB bb;
|
@Shadow private AABB bb;
|
||||||
|
|
@ -34,23 +28,9 @@ public abstract class MixinEntity {
|
||||||
private float redefinedEyeHeight(float original){
|
private float redefinedEyeHeight(float original){
|
||||||
Entity self = Entity.class.cast(this);
|
Entity self = Entity.class.cast(this);
|
||||||
if(self instanceof Player player){
|
if(self instanceof Player player){
|
||||||
IAnimationCapability data = AnimationDataCapability.getCapability(player).orElse(null);
|
AnimationData data = AnimationUtils.getEyeModifierAnimationData(player);
|
||||||
if(data == null) return original;
|
if(data instanceof GenericAnimationData){
|
||||||
Map.Entry<Float, Integer> entry = null;
|
return player.getEyeHeight(Pose.STANDING) + (float) data.getCamPosOffset().y;
|
||||||
List<ResourceLocation> values = new ArrayList<>(data.getAnimations().values());
|
|
||||||
if(data.getRiderAnimation() != null) values.add(data.getRiderAnimation());
|
|
||||||
for (ResourceLocation value : values) {
|
|
||||||
GenericAnimationData animation = AnimationService.INSTANCE.getAnimation(value);
|
|
||||||
if(animation == null) continue;
|
|
||||||
float animationCamY = (float) animation.getCamPosOffset().y;
|
|
||||||
int priority = animation.getCamComputePriority();
|
|
||||||
if((entry == null && animationCamY != 0)
|
|
||||||
|| (entry != null && priority > entry.getValue())) {
|
|
||||||
entry = new HashMap.SimpleEntry<>(animationCamY, priority);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(entry != null){
|
|
||||||
return player.getEyeHeight(Pose.STANDING) + entry.getKey();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return original;
|
return original;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user