Skip to content

Commit

Permalink
优化部分内容
Browse files Browse the repository at this point in the history
- 修正模型详情界面 geckolib 动画不播放问题
- 修改模型详情界面女仆骑乘显示
- 添加 beg 和 chair 动画
- 添加部分 tlm 的 molang
  • Loading branch information
TartaricAcid committed Oct 28, 2023
1 parent 7bed5fd commit acb2da8
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,17 @@ public PlayState predicateUse(AnimationEvent<GeckoMaidEntity> event) {
return PlayState.STOP;
}

public PlayState predicateBeg(AnimationEvent<GeckoMaidEntity> event) {
EntityMaid maid = event.getAnimatable().getMaid();
if (maid == null) {
return PlayState.STOP;
}
if (maid.isBegging()) {
return playAnimation(event, "beg", ILoopType.EDefaultLoopTypes.LOOP);
}
return PlayState.STOP;
}

public PlayState predicateArmor(AnimationEvent<GeckoMaidEntity> event, EquipmentSlot slot) {
EntityMaid maid = event.getAnimatable().getMaid();
if (maid == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public static void registerAnimationState() {
register("swim", Priority.HIGHEST, (maid, event) -> maid.isSwimming());

register("boat", Priority.HIGH, (maid, event) -> maid.getVehicle() instanceof Boat);
register("sit", Priority.HIGH, (maid, event) -> maid.isPassenger() || maid.isInSittingPose());
register("sit", Priority.HIGH, (maid, event) -> maid.isInSittingPose());
register("chair", Priority.HIGH, (maid, event) -> maid.isPassenger());

register("swim_stand", Priority.NORMAL, (maid, event) -> maid.isInWater());
register("attacked", ILoopType.EDefaultLoopTypes.PLAY_ONCE, Priority.NORMAL, (maid, event) -> maid.hurtTime > 0);
Expand Down Expand Up @@ -90,7 +91,7 @@ public static void registerVariables() {
parser.register(new LazyVariable("query.modified_distance_moved", 0));
parser.register(new LazyVariable("query.moon_phase", 0));

parser.register(new LazyVariable("query.maid_level", 0));
parser.register(new LazyVariable("query.player_level", 0));
parser.register(new LazyVariable("query.time_of_day", 0));
parser.register(new LazyVariable("query.time_stamp", 0));
parser.register(new LazyVariable("query.vertical_speed", 0));
Expand Down Expand Up @@ -122,6 +123,11 @@ public static void registerVariables() {
parser.register(new LazyVariable("ysm.food_level", 20));

parser.register(new LazyVariable("ysm.first_person_mod_hide", MolangUtils.FALSE));

parser.register(new LazyVariable("tlm.is_begging", MolangUtils.FALSE));
parser.register(new LazyVariable("tlm.is_sitting", MolangUtils.FALSE));
parser.register(new LazyVariable("tlm.has_backpack", MolangUtils.FALSE));
parser.register(new LazyVariable("tlm.backpack_level", 0));
}

public static void setParserValue(AnimationEvent<GeckoMaidEntity> animationEvent, MolangParser parser, EntityModelData data, EntityMaid maid) {
Expand Down Expand Up @@ -169,7 +175,7 @@ public static void setParserValue(AnimationEvent<GeckoMaidEntity> animationEvent
parser.setValue("query.modified_distance_moved", () -> maid.walkDist);
parser.setValue("query.moon_phase", () -> mc.level.getMoonPhase());

parser.setValue("query.maid_level", () -> maid.getExperience() / 120);
parser.setValue("query.player_level", () -> maid.getExperience() / 120);
parser.setValue("query.time_of_day", () -> MolangUtils.normalizeTime(mc.level.getDayTime()));
parser.setValue("query.time_stamp", () -> mc.level.getDayTime());
parser.setValue("query.vertical_speed", () -> getVerticalSpeed(maid));
Expand All @@ -196,6 +202,11 @@ public static void setParserValue(AnimationEvent<GeckoMaidEntity> animationEvent

parser.setValue("ysm.armor_value", maid::getArmorValue);
parser.setValue("ysm.hurt_time", () -> maid.hurtTime);

parser.setValue("tlm.is_begging", () -> MolangUtils.booleanToFloat(maid.isBegging()));
parser.setValue("tlm.is_sitting", () -> MolangUtils.booleanToFloat(maid.isInSittingPose()));
parser.setValue("tlm.has_backpack", () -> MolangUtils.booleanToFloat(maid.hasBackpack()));
parser.setValue("tlm.backpack_level", maid::getBackpackLevel);
}

private static void register(String animationName, ILoopType loopType, int priority, BiPredicate<EntityMaid, AnimationEvent<GeckoMaidEntity>> predicate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.github.tartaricacid.touhoulittlemaid.geckolib3.resource.GeckoLibCache;
import com.github.tartaricacid.touhoulittlemaid.geckolib3.util.GeckoLibUtil;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EquipmentSlot;

public class GeckoMaidEntity implements IAnimatable {
private static final ResourceLocation GECKO_DEFAULT_ID = new ResourceLocation(TouhouLittleMaid.MOD_ID, "fox_miko");
Expand All @@ -27,15 +28,22 @@ public void registerControllers(AnimationData data) {
data.addAnimationController(new AnimationController<>(this, controllerName, 0, e -> manager.predicateParallel(e, animationName)));
}
data.addAnimationController(new AnimationController<>(this, "main", 2, manager::predicateMain));
data.addAnimationController(new AnimationController(this, "hold_offhand", 0, manager::predicateOffhandHold));
data.addAnimationController(new AnimationController(this, "hold_mainhand", 0, manager::predicateMainhandHold));
data.addAnimationController(new AnimationController(this, "swing", 2, manager::predicateSwing));
data.addAnimationController(new AnimationController(this, "use", 2, manager::predicateUse));
data.addAnimationController(new AnimationController<>(this, "hold_offhand", 0, manager::predicateOffhandHold));
data.addAnimationController(new AnimationController<>(this, "hold_mainhand", 0, manager::predicateMainhandHold));
data.addAnimationController(new AnimationController<>(this, "swing", 2, manager::predicateSwing));
data.addAnimationController(new AnimationController<>(this, "use", 2, manager::predicateUse));
data.addAnimationController(new AnimationController<>(this, "beg", 2, manager::predicateBeg));
for (int i = 0; i < 8; i++) {
String controllerName = String.format("parallel_%d_controller", i);
String animationName = String.format("parallel%d", i);
data.addAnimationController(new AnimationController<>(this, controllerName, 0, e -> manager.predicateParallel(e, animationName)));
}
for (EquipmentSlot slot : EquipmentSlot.values()) {
if (slot.getType() == EquipmentSlot.Type.ARMOR) {
String controllerName = String.format("%s_controller", slot.getName());
data.addAnimationController(new AnimationController<>(this, controllerName, 0, e -> manager.predicateArmor(e, slot)));
}
}
}

public ResourceLocation getModel() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ private void renderEntity(int middleWidth, int middleHeight) {
MultiBufferSource.BufferSource buffer = Minecraft.getInstance().renderBuffers().bufferSource();
RenderSystem.runAsFancy(() -> {
manager.render(guiEntity, 0, 0, 0, 0, 1, poseStack, buffer, 0xf000f0);
poseStack.translate(0, 0.5, 0);
if (showFloor) {
poseStack.translate(0, 0.5, 0);
this.floorModel.renderToBuffer(poseStack, buffer.getBuffer(this.floorModel.renderType(FLOOR_TEXTURE)), 0xf000f0, OverlayTexture.NO_OVERLAY, 1.0F, 1.0F, 1.0F, 1.0F);
}
this.renderExtraEntity(manager, poseStack, buffer);
Expand All @@ -244,6 +244,11 @@ private void renderEntity(int middleWidth, int middleHeight) {
Lighting.setupFor3DItems();
}

@Override
public boolean isPauseScreen() {
return false;
}

private void fillGradient(GuiGraphics graphics, Rectangle vec4d, int color) {
graphics.fillGradient((int) vec4d.x, (int) vec4d.y, (int) vec4d.w, (int) vec4d.h, color, color);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.github.tartaricacid.touhoulittlemaid.client.gui.entity.model.MaidModelGui;
import com.github.tartaricacid.touhoulittlemaid.client.gui.widget.button.ModelDetailsButton;
import com.github.tartaricacid.touhoulittlemaid.client.resource.pojo.MaidModelInfo;
import com.github.tartaricacid.touhoulittlemaid.entity.item.EntityChair;
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
import com.github.tartaricacid.touhoulittlemaid.init.InitEntities;
import com.mojang.blaze3d.vertex.PoseStack;
Expand All @@ -11,22 +12,29 @@
import net.minecraft.client.renderer.entity.EntityRenderDispatcher;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.vehicle.Minecart;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;

public class MaidModelDetailsGui extends AbstractModelDetailsGui<EntityMaid, MaidModelInfo> {
private static final ItemStack MAIN_HAND_SWORD = Items.DIAMOND_SWORD.getDefaultInstance();
private static final ItemStack OFF_HAND_SHIELD = Items.SHIELD.getDefaultInstance();
private static final ItemStack ARMOR_ITEM = Items.GOLDEN_HELMET.getDefaultInstance();
private Minecart minecart;
private EntityChair chair;
private volatile boolean isEnableWalk = false;

public MaidModelDetailsGui(EntityMaid sourceEntity, MaidModelInfo modelInfo) {
super(sourceEntity, InitEntities.MAID.get().create(sourceEntity.level()), modelInfo);
this.guiEntity.setModelId(modelInfo.getModelId().toString());
this.guiEntity.setOnGround(true);
this.initChair();
}

private void initChair() {
if (Minecraft.getInstance().level != null) {
this.minecart = EntityType.MINECART.create(Minecraft.getInstance().level);
this.chair = InitEntities.CHAIR.get().create(Minecraft.getInstance().level);
if (this.chair != null) {
this.chair.setModelId("touhou_little_maid:low_stool");
}
}
}

Expand Down Expand Up @@ -81,12 +89,14 @@ public void tick() {

@Override
protected void renderExtraEntity(EntityRenderDispatcher manager, PoseStack matrix, MultiBufferSource.BufferSource bufferIn) {

if (guiEntity.isPassenger() && chair != null) {
manager.render(chair, 0, -0.95, 0, 0, 1, matrix, bufferIn, 0xf000f0);
}
}

private void applyRideButtonLogic(boolean isStateTriggered) {
if (isStateTriggered && minecart != null) {
guiEntity.startRiding(minecart, true);
if (isStateTriggered && chair != null) {
guiEntity.startRiding(chair, true);
} else {
guiEntity.removeVehicle();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,15 @@
}
}
},
"beg": {
"loop": true,
"bones": {
"Head": {
"rotation": [0, 0, -10],
"position": [0, -0.5, 0]
}
}
},
"jump": {
"loop": true,
"animation_length": 0.75,
Expand Down Expand Up @@ -2119,6 +2128,80 @@
}
}
},
"chair": {
"animation_length": 0.375,
"bones": {
"Root": {
"rotation": [0, 0, 0],
"position": [0, -5, 0],
"scale": 1
},
"UpBody": {
"rotation": [15, 0, 0],
"position": [0, 0, 0]
},
"LeftArm": {
"rotation": [-68.659, 23.92746, -39.32269],
"position": [0, 0, 0]
},
"LeftForeArm": {
"rotation": [-60.94031, 19.61291, -8.71337],
"position": [0, 0, 0]
},
"RightArm": {
"rotation": [-87.59409, -11.75726, 65.47122],
"position": [0, 0, 0]
},
"RightForeArm": {
"rotation": [-47.5, 0, 0],
"position": [0, 0, 0]
},
"LeftLeg": {
"rotation": [-142.5, 0, 0],
"position": [0, 0, 0]
},
"LeftLowerLeg": {
"rotation": [105, 0, 0],
"position": [0, 0, 0]
},
"LeftFoot": {
"rotation": [37.5, 0, 0],
"position": [0, 0, 0]
},
"RightLeg": {
"rotation": [-127.5, 0, 0],
"position": [0, 0, 0]
},
"RightLowerLeg": {
"rotation": [75, 0, 0],
"position": [0, 0, 0]
},
"RightFoot": {
"rotation": [55, 0, 0],
"position": [0, 0, 0]
},
"AllBody": {
"rotation": [0, 0, 0],
"position": [0, -10.5, 0],
"scale": 1
},
"AllHead": {
"rotation": [0, 0, 0],
"position": [0, 0, 0]
},
"Head": {
"rotation": [-15, 0, 0],
"position": [0, 0, 0]
},
"LongHair": {
"rotation": [15, 0, 0]
},
"Skirt": {
"rotation": [-123.71393, -4.07256, -8.03263],
"position": [0.3, -3.45, 1.8]
}
}
},
"sleep": {
"animation_length": 0.375,
"bones": {
Expand Down

0 comments on commit acb2da8

Please sign in to comment.