diff --git a/src/main/java/com/github/tartaricacid/touhoulittlemaid/client/animation/gecko/AnimationManager.java b/src/main/java/com/github/tartaricacid/touhoulittlemaid/client/animation/gecko/AnimationManager.java index f16ca1dd9..8bd4c5083 100644 --- a/src/main/java/com/github/tartaricacid/touhoulittlemaid/client/animation/gecko/AnimationManager.java +++ b/src/main/java/com/github/tartaricacid/touhoulittlemaid/client/animation/gecko/AnimationManager.java @@ -4,6 +4,7 @@ import com.github.tartaricacid.touhoulittlemaid.client.animation.gecko.condition.*; import com.github.tartaricacid.touhoulittlemaid.client.entity.GeckoMaidEntity; import com.github.tartaricacid.touhoulittlemaid.compat.tacz.TacCompat; +import com.github.tartaricacid.touhoulittlemaid.entity.item.EntityChair; import com.github.tartaricacid.touhoulittlemaid.geckolib3.core.PlayState; import com.github.tartaricacid.touhoulittlemaid.geckolib3.core.builder.AnimationBuilder; import com.github.tartaricacid.touhoulittlemaid.geckolib3.core.builder.ILoopType; @@ -281,6 +282,19 @@ public PlayState getVehicleAnimation(AnimationEvent> event) { return null; } ResourceLocation id = event.getAnimatableEntity().getAnimationFileLocation(); + + // 如果是坐垫 + if (vehicle instanceof EntityChair) { + ConditionalChair conditionalChair = ConditionManager.getChair(id); + if (conditionalChair != null) { + String name = conditionalChair.doTest(mob); + if (StringUtils.isNoneBlank(name)) { + return playAnimation(event, name, ILoopType.EDefaultLoopTypes.LOOP); + } + } + } + + // 其他情况 ConditionalVehicle vehicleCondition = ConditionManager.getVehicle(id); if (vehicleCondition != null) { String name = vehicleCondition.doTest(mob); diff --git a/src/main/java/com/github/tartaricacid/touhoulittlemaid/client/animation/gecko/AnimationRegister.java b/src/main/java/com/github/tartaricacid/touhoulittlemaid/client/animation/gecko/AnimationRegister.java index 069f5e0b6..62f2ded8e 100644 --- a/src/main/java/com/github/tartaricacid/touhoulittlemaid/client/animation/gecko/AnimationRegister.java +++ b/src/main/java/com/github/tartaricacid/touhoulittlemaid/client/animation/gecko/AnimationRegister.java @@ -16,7 +16,6 @@ public class AnimationRegister { public static void registerAnimationState() { register("death", ILoopType.EDefaultLoopTypes.PLAY_ONCE, Priority.HIGHEST, (maid, event) -> maid.asEntity().isDeadOrDying()); register("sleep", Priority.HIGHEST, (maid, event) -> maid.asEntity().getPose() == Pose.SLEEPING); - register("swim", Priority.HIGHEST, (maid, event) -> maid.asEntity().isSwimming()); register("gomoku", Priority.HIGH, (maid, event) -> sitInJoy(maid, Type.GOMOKU)); register("bookshelf", Priority.HIGH, (maid, event) -> sitInJoy(maid, Type.BOOKSHELF)); diff --git a/src/main/java/com/github/tartaricacid/touhoulittlemaid/client/animation/gecko/condition/ConditionManager.java b/src/main/java/com/github/tartaricacid/touhoulittlemaid/client/animation/gecko/condition/ConditionManager.java index c7e4e5030..a1ae2874b 100644 --- a/src/main/java/com/github/tartaricacid/touhoulittlemaid/client/animation/gecko/condition/ConditionManager.java +++ b/src/main/java/com/github/tartaricacid/touhoulittlemaid/client/animation/gecko/condition/ConditionManager.java @@ -17,6 +17,7 @@ public class ConditionManager { public static Map ARMOR = Maps.newHashMap(); public static Map VEHICLE = Maps.newHashMap(); public static Map PASSENGER = Maps.newHashMap(); + public static Map CHAIR = Maps.newHashMap(); public static void addTest(ResourceLocation id, String name) { SWING.computeIfAbsent(id, k -> new ConditionalSwing(InteractionHand.MAIN_HAND)).addTest(name); @@ -29,15 +30,21 @@ public static void addTest(ResourceLocation id, String name) { ARMOR.computeIfAbsent(id, k -> new ConditionArmor()).addTest(name); VEHICLE.computeIfAbsent(id, k -> new ConditionalVehicle()).addTest(name); PASSENGER.computeIfAbsent(id, k -> new ConditionalPassenger()).addTest(name); + CHAIR.computeIfAbsent(id, k -> new ConditionalChair()).addTest(name); } public static void clear() { SWING.clear(); + SWING_OFFHAND.clear(); USE_MAINHAND.clear(); USE_OFFHAND.clear(); HOLD_MAINHAND.clear(); HOLD_OFFHAND.clear(); + TAC.clear(); ARMOR.clear(); + VEHICLE.clear(); + PASSENGER.clear(); + CHAIR.clear(); } public static ConditionalSwing getSwingMainhand(ResourceLocation id) { @@ -79,4 +86,8 @@ public static ConditionalVehicle getVehicle(ResourceLocation id) { public static ConditionalPassenger getPassenger(ResourceLocation id) { return PASSENGER.get(id); } + + public static ConditionalChair getChair(ResourceLocation id) { + return CHAIR.get(id); + } } diff --git a/src/main/java/com/github/tartaricacid/touhoulittlemaid/client/animation/gecko/condition/ConditionalChair.java b/src/main/java/com/github/tartaricacid/touhoulittlemaid/client/animation/gecko/condition/ConditionalChair.java new file mode 100644 index 000000000..8c45e5f70 --- /dev/null +++ b/src/main/java/com/github/tartaricacid/touhoulittlemaid/client/animation/gecko/condition/ConditionalChair.java @@ -0,0 +1,49 @@ +package com.github.tartaricacid.touhoulittlemaid.client.animation.gecko.condition; + +import com.github.tartaricacid.touhoulittlemaid.entity.item.EntityChair; +import com.google.common.collect.Lists; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.Mob; + +import java.util.List; + +public class ConditionalChair { + private static final String EMPTY = ""; + private final List idTest = Lists.newArrayList(); + private final String idPre; + + public ConditionalChair() { + this.idPre = "chair$"; + } + + public void addTest(String name) { + int preSize = this.idPre.length(); + if (name.length() <= preSize) { + return; + } + String substring = name.substring(preSize); + if (name.startsWith(idPre) && ResourceLocation.isValidResourceLocation(substring)) { + idTest.add(substring); + } + } + + public String doTest(Mob maid) { + Entity vehicle = maid.getVehicle(); + if (!(vehicle instanceof EntityChair chair)) { + return EMPTY; + } + return doIdTest(chair); + } + + private String doIdTest(EntityChair chair) { + if (idTest.isEmpty()) { + return EMPTY; + } + String modelId = chair.getModelId(); + if (idTest.contains(modelId)) { + return idPre + modelId; + } + return EMPTY; + } +} diff --git a/src/main/java/com/github/tartaricacid/touhoulittlemaid/client/resource/CustomPackLoader.java b/src/main/java/com/github/tartaricacid/touhoulittlemaid/client/resource/CustomPackLoader.java index 383228118..caf239279 100644 --- a/src/main/java/com/github/tartaricacid/touhoulittlemaid/client/resource/CustomPackLoader.java +++ b/src/main/java/com/github/tartaricacid/touhoulittlemaid/client/resource/CustomPackLoader.java @@ -2,6 +2,7 @@ import com.github.tartaricacid.touhoulittlemaid.TouhouLittleMaid; import com.github.tartaricacid.touhoulittlemaid.client.animation.CustomJsAnimationManger; +import com.github.tartaricacid.touhoulittlemaid.client.animation.gecko.condition.ConditionManager; import com.github.tartaricacid.touhoulittlemaid.client.gui.entity.cache.CacheIconManager; import com.github.tartaricacid.touhoulittlemaid.client.model.BedrockVersion; import com.github.tartaricacid.touhoulittlemaid.client.model.bedrock.BedrockModel; @@ -73,6 +74,7 @@ public class CustomPackLoader { public static void reloadPacks() { // 清除 CustomJsAnimationManger.clearAll(); + ConditionManager.clear(); MAID_MODELS.clearAll(); CHAIR_MODELS.clearAll(); TMP_REGISTER_TEXTURE.clear(); diff --git a/src/main/resources/assets/touhou_little_maid/textures/gui/maid_gui_side.png b/src/main/resources/assets/touhou_little_maid/textures/gui/maid_gui_side.png index 369b1b81e..dc0f3b44d 100644 Binary files a/src/main/resources/assets/touhou_little_maid/textures/gui/maid_gui_side.png and b/src/main/resources/assets/touhou_little_maid/textures/gui/maid_gui_side.png differ