Skip to content

Commit

Permalink
添加 chair Condition 动画
Browse files Browse the repository at this point in the history
- 修改图标
  • Loading branch information
TartaricAcid committed Oct 30, 2024
1 parent 26ec3a9 commit 058b0f3
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -281,6 +282,19 @@ public PlayState getVehicleAnimation(AnimationEvent<GeckoMaidEntity<?>> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class ConditionManager {
public static Map<ResourceLocation, ConditionArmor> ARMOR = Maps.newHashMap();
public static Map<ResourceLocation, ConditionalVehicle> VEHICLE = Maps.newHashMap();
public static Map<ResourceLocation, ConditionalPassenger> PASSENGER = Maps.newHashMap();
public static Map<ResourceLocation, ConditionalChair> CHAIR = Maps.newHashMap();

public static void addTest(ResourceLocation id, String name) {
SWING.computeIfAbsent(id, k -> new ConditionalSwing(InteractionHand.MAIN_HAND)).addTest(name);
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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<String> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 058b0f3

Please sign in to comment.