Skip to content

Commit

Permalink
Compat with immersive_melodies (#625)
Browse files Browse the repository at this point in the history
* compat with immersive_melodies

* fix head pitch

* non fix...back

* 修正部分内容

---------

Co-authored-by: tartaric_acid <baka943@qq.com>
  • Loading branch information
Azumic and TartaricAcid authored Dec 23, 2024
1 parent 325e70e commit 0083c7e
Show file tree
Hide file tree
Showing 9 changed files with 373 additions and 11 deletions.
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ repositories {
maven {
url = "https://api.modrinth.com/maven"
}
maven {
url = "https://maven.conczin.net/Artifacts"
}
}

dependencies {
Expand Down Expand Up @@ -149,6 +152,8 @@ dependencies {

implementation fg.deobf("curse.maven:iron-chests-228756:${iron_chests_id}")

implementation fg.deobf("net.conczin:immersive_melodies:${immersive_melodies_version}")

runtimeOnly fg.deobf("curse.maven:carry-on-274259:${carry_on_id}")

runtimeOnly "curse.maven:kotlin-for-forge-351264:${kotlin_id}"
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ top_id=4629624
cloth_config_forge=11.1.106
citadel_id=4576429
domestication_innovation_id=4911955
immersive_melodies_version=0.3.0+1.20.1+forge
iron_chests_id=4614852
carry_on_id=4882500
kotlin_id=4983659
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.github.tartaricacid.touhoulittlemaid.api.entity.IMaid;
import com.github.tartaricacid.touhoulittlemaid.client.animation.gecko.AnimationManager;
import com.github.tartaricacid.touhoulittlemaid.client.resource.pojo.MaidModelInfo;
import com.github.tartaricacid.touhoulittlemaid.compat.immersivemelodies.ImmersiveMelodiesCompat;
import com.github.tartaricacid.touhoulittlemaid.geckolib3.core.AnimatableEntity;
import com.github.tartaricacid.touhoulittlemaid.geckolib3.core.controller.AnimationController;
import com.github.tartaricacid.touhoulittlemaid.geckolib3.core.event.predicate.AnimationEvent;
Expand All @@ -28,12 +29,11 @@ public class GeckoMaidEntity<T extends Mob> extends AnimatableEntity<T> {
private static final int FPS = 60;

private final IMaid maid;
private MaidModelInfo maidInfo;
private final Vector2f headRot = new Vector2f();

private final MaidState<T> state;
private MaidModelInfo maidInfo;
private float currentTick = -1;
private boolean modelDirty = false;
private final MaidState<T> state;

public GeckoMaidEntity(T mob, IMaid maid) {
super(mob, FPS);
Expand Down Expand Up @@ -75,16 +75,18 @@ public boolean setCustomAnimations(AnimationContext context, @NotNull AnimationE
List extraData = animationEvent.getExtraData();
MolangParser parser = GeckoLibCache.getInstance().parser;
if (!Minecraft.getInstance().isPaused() && extraData.size() == 1 && extraData.get(0) instanceof EntityModelData data) {
//AnimationRegister.setParserValue(animationEvent, parser, data, this.maid);
var update = super.setCustomAnimations(context, animationEvent);
AnimatedGeoModel currentModel = this.getCurrentModel();
if (currentModel != null && currentModel.head() != null) {
IBone head = currentModel.head();
if (update) {
this.headRot.set(head.getRotationX(), head.getRotationY());
if (currentModel != null) {
if (currentModel.head() != null) {
IBone head = currentModel.head();
if (update) {
this.headRot.set(head.getRotationX(), head.getRotationY());
}
head.setRotationX(this.headRot.x + (float) Math.toRadians(data.headPitch));
head.setRotationY(this.headRot.y + (float) Math.toRadians(data.netHeadYaw));
}
head.setRotationX(this.headRot.x + (float) Math.toRadians(data.headPitch));
head.setRotationY(this.headRot.y + (float) Math.toRadians(data.netHeadYaw));
ImmersiveMelodiesCompat.setGeckoAngles(maid, currentModel.head(), currentModel.hat(), currentModel.leftArm(), currentModel.rightArm());
}
return update;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.github.tartaricacid.touhoulittlemaid.client.event.ShowOptifineScreen;
import com.github.tartaricacid.touhoulittlemaid.client.overlay.BroomTipsOverlay;
import com.github.tartaricacid.touhoulittlemaid.client.overlay.MaidTipsOverlay;
import com.github.tartaricacid.touhoulittlemaid.compat.immersivemelodies.ImmersiveMelodiesCompat;
import com.github.tartaricacid.touhoulittlemaid.compat.simplehats.SimpleHatsCompat;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.RegisterGuiOverlaysEvent;
Expand All @@ -24,6 +25,7 @@ public static void onClientSetup(FMLClientSetupEvent event) {

// 客户端兼容
SimpleHatsCompat.init();
ImmersiveMelodiesCompat.init();
}

@SubscribeEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.github.tartaricacid.touhoulittlemaid.client.model.BedrockVersion;
import com.github.tartaricacid.touhoulittlemaid.client.model.pojo.*;
import com.github.tartaricacid.touhoulittlemaid.client.resource.CustomPackLoader;
import com.github.tartaricacid.touhoulittlemaid.compat.immersivemelodies.ImmersiveMelodiesCompat;
import com.github.tartaricacid.touhoulittlemaid.entity.item.EntityChair;
import com.google.common.collect.Lists;
import com.mojang.blaze3d.vertex.PoseStack;
Expand Down Expand Up @@ -256,8 +257,12 @@ public void setupAnim(T entityIn, float limbSwing, float limbSwingAmount, float
Invocable invocable = (Invocable) CustomJsAnimationManger.NASHORN;
if (entityIn instanceof Mob mob) {
IMaid maid = IMaid.convert(mob);
if (maid != null)
if (maid != null) {
setupMaidAnim(maid, limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, invocable);
ImmersiveMelodiesCompat.setAngles(maid, this.hasHead() ? this.getHead() : null, this.getHat(),
this.hasLeftArm() ? this.getArm(HumanoidArm.LEFT) : null,
this.hasRightArm() ? this.getArm(HumanoidArm.RIGHT) : null);
}
return;
}
if (entityIn instanceof EntityChair) {
Expand Down Expand Up @@ -346,6 +351,15 @@ public BedrockPart getHead() {
return modelMap.get("head").getModelRenderer();
}

@Nullable
public BedrockPart getHat() {
ModelRendererWrapper hat = modelMap.get("hat");
if (hat != null) {
return hat.getModelRenderer();
}
return null;
}

public boolean hasLeftArm() {
return modelMap.containsKey("armLeft");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
package com.github.tartaricacid.touhoulittlemaid.compat.immersivemelodies;

import com.github.tartaricacid.touhoulittlemaid.geckolib3.geo.animated.AnimatedGeoBone;
import immersive_melodies.client.animation.EntityModelAnimator;
import immersive_melodies.client.animation.accessors.ModelAccessor;
import net.minecraft.world.entity.Mob;

import javax.annotation.Nullable;
import java.util.Optional;

public class GeckoMaidArmsAndHeadAccessor implements ModelAccessor<Mob> {
private final Mob maid;
private final @Nullable AnimatedGeoBone head;
private final @Nullable AnimatedGeoBone hat;
private final @Nullable AnimatedGeoBone leftArm;
private final @Nullable AnimatedGeoBone rightArm;

private GeckoMaidArmsAndHeadAccessor(Mob maid, @Nullable AnimatedGeoBone head, @Nullable AnimatedGeoBone hat,
@Nullable AnimatedGeoBone leftArm, @Nullable AnimatedGeoBone rightArm) {
this.maid = maid;
this.head = head;
this.hat = hat;
this.leftArm = leftArm;
this.rightArm = rightArm;
}

static void setAngles(Mob maid, @Nullable AnimatedGeoBone head, @Nullable AnimatedGeoBone hat,
@Nullable AnimatedGeoBone leftArm, @Nullable AnimatedGeoBone rightArm) {
EntityModelAnimator.setAngles(new GeckoMaidArmsAndHeadAccessor(maid, head, hat, leftArm, rightArm));
}

@Override
public Mob getEntity() {
return this.maid;
}

@Override
public float headYaw() {
return getMaidHead().map(AnimatedGeoBone::getRotationY).orElse(0.0f);
}

@Override
public void headYaw(float yaw) {
getMaidHead().ifPresent(bone -> bone.setRotationY(flipHands() ? yaw : -yaw));
getMaidHat().ifPresent(bone -> bone.setRotationY(flipHands() ? yaw : -yaw));
}

@Override
public float headPitch() {
return getMaidHat().map(AnimatedGeoBone::getRotationX).orElse(0.0f);
}

@Override
public void headPitch(float pitch) {
getMaidHead().ifPresent(bone -> bone.setRotationX(-pitch));
getMaidHat().ifPresent(bone -> bone.setRotationX(-pitch));
}

@Override
public float leftArmYaw() {
return getMaidFlippedLeftArm().map(AnimatedGeoBone::getRotationY).orElse(0.0f);
}

@Override
public void leftArmYaw(float yaw) {
getMaidFlippedLeftArm().ifPresent(bone -> bone.setRotationY(flipHands() ? yaw : -yaw));
}

@Override
public float leftArmPitch() {
return getMaidFlippedLeftArm().map(AnimatedGeoBone::getRotationX).orElse(0.0f);
}

@Override
public void leftArmPitch(float pitch) {
// GeckoLib 的模型和和默认的的模型是数值是相反的
getMaidFlippedLeftArm().ifPresent(bone -> bone.setRotationX(-pitch));
}

@Override
public float leftArmRoll() {
return getMaidFlippedLeftArm().map(AnimatedGeoBone::getRotationZ).orElse(0.0f);
}

@Override
public void leftArmRoll(float roll) {
getMaidFlippedLeftArm().ifPresent(bone -> bone.setRotationZ(flipHands() ? roll : -roll));
}

@Override
public float rightArmYaw() {
return getMaidFlippedRightArm().map(AnimatedGeoBone::getRotationY).orElse(0.0f);
}

@Override
public void rightArmYaw(float yaw) {
getMaidFlippedRightArm().ifPresent(bone -> bone.setRotationY(flipHands() ? yaw : -yaw));
}

@Override
public float rightArmPitch() {
return getMaidFlippedRightArm().map(AnimatedGeoBone::getRotationX).orElse(0.0f);
}

@Override
public void rightArmPitch(float pitch) {
// GeckoLib 的模型和和默认的的模型是数值是相反的
getMaidFlippedRightArm().ifPresent(bone -> bone.setRotationX(-pitch));
}

@Override
public float rightArmRoll() {
return getMaidFlippedRightArm().map(AnimatedGeoBone::getRotationZ).orElse(0.0f);
}

@Override
public void rightArmRoll(float roll) {
getMaidFlippedRightArm().ifPresent(bone -> bone.setRotationY(flipHands() ? -roll : roll));
}

private Optional<AnimatedGeoBone> getMaidHead() {
return Optional.ofNullable(head);
}

private Optional<AnimatedGeoBone> getMaidHat() {
return Optional.ofNullable(hat);
}

private Optional<AnimatedGeoBone> getMaidFlippedLeftArm() {
return flipHands() ? getMaidRightArm() : getMaidLeftArm();
}

private Optional<AnimatedGeoBone> getMaidFlippedRightArm() {
return flipHands() ? getMaidLeftArm() : getMaidRightArm();
}

private Optional<AnimatedGeoBone> getMaidLeftArm() {
return Optional.ofNullable(leftArm);
}

private Optional<AnimatedGeoBone> getMaidRightArm() {
return Optional.ofNullable(rightArm);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.github.tartaricacid.touhoulittlemaid.compat.immersivemelodies;

import com.github.tartaricacid.touhoulittlemaid.api.entity.IMaid;
import com.github.tartaricacid.touhoulittlemaid.client.model.bedrock.BedrockPart;
import com.github.tartaricacid.touhoulittlemaid.geckolib3.geo.animated.AnimatedGeoBone;
import net.minecraftforge.fml.ModList;

import javax.annotation.Nullable;

public class ImmersiveMelodiesCompat {
private static final String IMMERSIVE_MELODIES = "immersive_melodies";
private static boolean IS_LOADED = false;

public static void init() {
IS_LOADED = ModList.get().isLoaded(IMMERSIVE_MELODIES);
}

public static void setAngles(IMaid maid, BedrockPart head, BedrockPart hat, BedrockPart leftArm, BedrockPart rightArm) {
if (IS_LOADED) {
MaidArmsAndHeadAccessor.setAngles(maid.asEntity(), head, hat, leftArm, rightArm);
}
}

public static void setGeckoAngles(IMaid maid, @Nullable AnimatedGeoBone head, @Nullable AnimatedGeoBone hat, @Nullable AnimatedGeoBone leftArm, @Nullable AnimatedGeoBone rightArm) {
if (IS_LOADED) {
GeckoMaidArmsAndHeadAccessor.setAngles(maid.asEntity(), head, hat, leftArm, rightArm);
}
}
}
Loading

0 comments on commit 0083c7e

Please sign in to comment.