Skip to content

Commit

Permalink
fix: fix leg animation of flesh animals
Browse files Browse the repository at this point in the history
  • Loading branch information
Elenterius committed Aug 9, 2024
1 parent 125acef commit ff74136
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import com.github.elenterius.biomancy.BiomancyMod;
import com.github.elenterius.biomancy.entity.mob.FleshChicken;
import net.minecraft.client.Minecraft;
import net.minecraft.util.Mth;
import software.bernie.geckolib.core.animatable.model.CoreGeoBone;
import software.bernie.geckolib.core.animation.AnimationState;
import software.bernie.geckolib.core.molang.MolangParser;
import software.bernie.geckolib.model.DefaultedEntityGeoModel;

public class FleshChickenModel<T extends FleshChicken> extends DefaultedEntityGeoModel<T> {
Expand Down Expand Up @@ -32,4 +34,37 @@ protected float getWingRotation(T chicken, float partialTicks) {
return (Mth.sin(flapProgress) + 1f) * flapSpeed;
}

@Override
public void applyMolangQueries(T animatable, double animTime) {
super.applyMolangQueries(animatable, animTime);

MolangParser parser = MolangParser.INSTANCE;

parser.setMemoizedValue("custom_query.limb_swing", () -> {
boolean shouldSit = animatable.isPassenger() && (animatable.getVehicle() != null && animatable.getVehicle().shouldRiderSit());

float limbSwing = 0;

if (!shouldSit && animatable.isAlive()) {
limbSwing = animatable.walkAnimation.position(Minecraft.getInstance().getPartialTick());
if (animatable.isBaby()) limbSwing *= 3f;
}

return limbSwing;
});

parser.setMemoizedValue("custom_query.limb_swing_amount", () -> {
boolean shouldSit = animatable.isPassenger() && (animatable.getVehicle() != null && animatable.getVehicle().shouldRiderSit());

float limbSwingAmount = 0;

if (!shouldSit && animatable.isAlive()) {
limbSwingAmount = animatable.walkAnimation.speed(Minecraft.getInstance().getPartialTick());
if (limbSwingAmount > 1f) limbSwingAmount = 1f;
}

return limbSwingAmount;
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.github.elenterius.biomancy.BiomancyMod;
import com.github.elenterius.biomancy.entity.mob.FleshCow;
import net.minecraft.client.Minecraft;
import software.bernie.geckolib.core.molang.MolangParser;
import software.bernie.geckolib.model.DefaultedEntityGeoModel;

public class FleshCowModel<T extends FleshCow> extends DefaultedEntityGeoModel<T> {
Expand All @@ -10,4 +12,37 @@ public FleshCowModel() {
super(BiomancyMod.createRL("mob/flesh_cow"), true);
}

@Override
public void applyMolangQueries(T animatable, double animTime) {
super.applyMolangQueries(animatable, animTime);

MolangParser parser = MolangParser.INSTANCE;

parser.setMemoizedValue("custom_query.limb_swing", () -> {
boolean shouldSit = animatable.isPassenger() && (animatable.getVehicle() != null && animatable.getVehicle().shouldRiderSit());

float limbSwing = 0;

if (!shouldSit && animatable.isAlive()) {
limbSwing = animatable.walkAnimation.position(Minecraft.getInstance().getPartialTick());
if (animatable.isBaby()) limbSwing *= 3f;
}

return limbSwing;
});

parser.setMemoizedValue("custom_query.limb_swing_amount", () -> {
boolean shouldSit = animatable.isPassenger() && (animatable.getVehicle() != null && animatable.getVehicle().shouldRiderSit());

float limbSwingAmount = 0;

if (!shouldSit && animatable.isAlive()) {
limbSwingAmount = animatable.walkAnimation.speed(Minecraft.getInstance().getPartialTick());
if (limbSwingAmount > 1f) limbSwingAmount = 1f;
}

return limbSwingAmount;
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.github.elenterius.biomancy.BiomancyMod;
import com.github.elenterius.biomancy.entity.mob.FleshPig;
import net.minecraft.client.Minecraft;
import software.bernie.geckolib.core.molang.MolangParser;
import software.bernie.geckolib.model.DefaultedEntityGeoModel;

public class FleshPigModel<T extends FleshPig> extends DefaultedEntityGeoModel<T> {
Expand All @@ -10,4 +12,37 @@ public FleshPigModel() {
super(BiomancyMod.createRL("mob/flesh_pig"), true);
}

@Override
public void applyMolangQueries(T animatable, double animTime) {
super.applyMolangQueries(animatable, animTime);

MolangParser parser = MolangParser.INSTANCE;

parser.setMemoizedValue("custom_query.limb_swing", () -> {
boolean shouldSit = animatable.isPassenger() && (animatable.getVehicle() != null && animatable.getVehicle().shouldRiderSit());

float limbSwing = 0;

if (!shouldSit && animatable.isAlive()) {
limbSwing = animatable.walkAnimation.position(Minecraft.getInstance().getPartialTick());
if (animatable.isBaby()) limbSwing *= 3f;
}

return limbSwing;
});

parser.setMemoizedValue("custom_query.limb_swing_amount", () -> {
boolean shouldSit = animatable.isPassenger() && (animatable.getVehicle() != null && animatable.getVehicle().shouldRiderSit());

float limbSwingAmount = 0;

if (!shouldSit && animatable.isAlive()) {
limbSwingAmount = animatable.walkAnimation.speed(Minecraft.getInstance().getPartialTick());
if (limbSwingAmount > 1f) limbSwingAmount = 1f;
}

return limbSwingAmount;
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import com.github.elenterius.biomancy.BiomancyMod;
import com.github.elenterius.biomancy.entity.mob.FleshSheep;
import net.minecraft.client.Minecraft;
import net.minecraft.util.Mth;
import software.bernie.geckolib.constant.DataTickets;
import software.bernie.geckolib.core.animatable.model.CoreGeoBone;
import software.bernie.geckolib.core.animation.AnimationState;
import software.bernie.geckolib.core.molang.MolangParser;
import software.bernie.geckolib.model.DefaultedEntityGeoModel;
import software.bernie.geckolib.model.data.EntityModelData;

Expand All @@ -30,4 +32,37 @@ public void setCustomAnimations(T animatable, long instanceId, AnimationState<T>
head.setRotY(entityData.netHeadYaw() * Mth.DEG_TO_RAD);
}

@Override
public void applyMolangQueries(T animatable, double animTime) {
super.applyMolangQueries(animatable, animTime);

MolangParser parser = MolangParser.INSTANCE;

parser.setMemoizedValue("custom_query.limb_swing", () -> {
boolean shouldSit = animatable.isPassenger() && (animatable.getVehicle() != null && animatable.getVehicle().shouldRiderSit());

float limbSwing = 0;

if (!shouldSit && animatable.isAlive()) {
limbSwing = animatable.walkAnimation.position(Minecraft.getInstance().getPartialTick());
if (animatable.isBaby()) limbSwing *= 3f;
}

return limbSwing;
});

parser.setMemoizedValue("custom_query.limb_swing_amount", () -> {
boolean shouldSit = animatable.isPassenger() && (animatable.getVehicle() != null && animatable.getVehicle().shouldRiderSit());

float limbSwingAmount = 0;

if (!shouldSit && animatable.isAlive()) {
limbSwingAmount = animatable.walkAnimation.speed(Minecraft.getInstance().getPartialTick());
if (limbSwingAmount > 1f) limbSwingAmount = 1f;
}

return limbSwingAmount;
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
"bones": {
"leg0": {
"rotation": {
"vector": [ "math.cos(query.anim_time * 360) * 80.0", 0, 0 ]
"vector": [ "math.cos(custom_query.limb_swing * 38.1704) * 80.0 * custom_query.limb_swing_amount", 0, 0 ]
}
},
"leg1": {
"rotation": {
"vector": [ "math.cos(query.anim_time * 360) * -80.0", 0, 0 ]
"vector": [ "math.cos(custom_query.limb_swing * 38.1704) * -80.0 * custom_query.limb_swing_amount", 0, 0 ]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@
"bones": {
"leg0": {
"rotation": {
"vector": [ "math.cos(query.anim_time * 360) * 80.0", 0, 0 ]
"vector": [ "math.cos(custom_query.limb_swing * 38.1704) * 80.0 * custom_query.limb_swing_amount", 0, 0 ]
}
},
"leg1": {
"rotation": {
"vector": [ "math.cos(query.anim_time * 360) * -80.0", 0, 0 ]
"vector": [ "math.cos(custom_query.limb_swing * 38.1704) * -80.0 * custom_query.limb_swing_amount", 0, 0 ]
}
},
"leg2": {
"rotation": {
"vector": [ "math.cos(query.anim_time * 360) * -80.0", 0, 0 ]
"vector": [ "math.cos(custom_query.limb_swing * 38.1704) * -80.0 * custom_query.limb_swing_amount", 0, 0 ]
}
},
"leg3": {
"rotation": {
"vector": [ "math.cos(query.anim_time * 360) * 80.0", 0, 0 ]
"vector": [ "math.cos(custom_query.limb_swing * 38.1704) * 80.0 * custom_query.limb_swing_amount", 0, 0 ]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@
"bones": {
"leg0": {
"rotation": {
"vector": [ "math.cos(query.anim_time * 360) * 80.0", 0, 0 ]
"vector": [ "math.cos(custom_query.limb_swing * 38.1704) * 80.0 * custom_query.limb_swing_amount", 0, 0 ]
}
},
"leg1": {
"rotation": {
"vector": [ "math.cos(query.anim_time * 360) * -80.0", 0, 0 ]
"vector": [ "math.cos(custom_query.limb_swing * 38.1704) * -80.0 * custom_query.limb_swing_amount", 0, 0 ]
}
},
"leg2": {
"rotation": {
"vector": [ "math.cos(query.anim_time * 360) * -80.0", 0, 0 ]
"vector": [ "math.cos(custom_query.limb_swing * 38.1704) * -80.0 * custom_query.limb_swing_amount", 0, 0 ]
}
},
"leg3": {
"rotation": {
"vector": [ "math.cos(query.anim_time * 360) * 80.0", 0, 0 ]
"vector": [ "math.cos(custom_query.limb_swing * 38.1704) * 80.0 * custom_query.limb_swing_amount", 0, 0 ]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,22 @@
"bones": {
"leg0": {
"rotation": {
"vector": [ "math.cos(query.anim_time * 360) * 80.0", 0, 0 ]
"vector": [ "math.cos(custom_query.limb_swing * 38.1704) * 80.0 * custom_query.limb_swing_amount", 0, 0 ]
}
},
"leg1": {
"rotation": {
"vector": [ "math.cos(query.anim_time * 360) * -80.0", 0, 0 ]
"vector": [ "math.cos(custom_query.limb_swing * 38.1704) * -80.0 * custom_query.limb_swing_amount", 0, 0 ]
}
},
"leg2": {
"rotation": {
"vector": [ "math.cos(query.anim_time * 360) * -80.0", 0, 0 ]
"vector": [ "math.cos(custom_query.limb_swing * 38.1704) * -80.0 * custom_query.limb_swing_amount", 0, 0 ]
}
},
"leg3": {
"rotation": {
"vector": [ "math.cos(query.anim_time * 360) * 80.0", 0, 0 ]
"vector": [ "math.cos(custom_query.limb_swing * 38.1704) * 80.0 * custom_query.limb_swing_amount", 0, 0 ]
}
}
}
Expand Down

0 comments on commit ff74136

Please sign in to comment.