Skip to content

Commit

Permalink
fix piranha & add tortoise (no anim yet)
Browse files Browse the repository at this point in the history
  • Loading branch information
Uraneptus committed Sep 26, 2024
1 parent a8da1fd commit aa90335
Show file tree
Hide file tree
Showing 8 changed files with 419 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class PiranhaAnimation {
new Keyframe(0.25F, KeyframeAnimations.posVec(0.1F, 0.0F, 0.0F), AnimationChannel.Interpolations.CATMULLROM),
new Keyframe(0.5F, KeyframeAnimations.posVec(-0.1F, 0.0F, 0.0F), AnimationChannel.Interpolations.CATMULLROM)
))

.addAnimation("tail_fin", new AnimationChannel(AnimationChannel.Targets.ROTATION,
new Keyframe(0.0F, KeyframeAnimations.degreeVec(0.0F, -10.0F, 0.0F), AnimationChannel.Interpolations.CATMULLROM),
new Keyframe(0.25F, KeyframeAnimations.degreeVec(0.0F, 10.0F, 0.0F), AnimationChannel.Interpolations.CATMULLROM),
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.uraneptus.sullysmod.SullysMod;
import com.uraneptus.sullysmod.client.animations.AnimUtil;
import com.uraneptus.sullysmod.client.animations.BoulderingZombieAnimation;
import com.uraneptus.sullysmod.client.animations.PiranhaAnimation;
import com.uraneptus.sullysmod.common.entities.Piranha;
import net.minecraft.client.model.EntityModel;
Expand Down Expand Up @@ -50,18 +51,14 @@ public static LayerDefinition createBodyLayer() {

@Override
public void setupAnim(E pEntity, float pLimbSwing, float pLimbSwingAmount, float pAgeInTicks, float pNetHeadYaw, float pHeadPitch) {
this.root().getAllParts().forEach(ModelPart::resetPose);
float f = 1.0F;
if (!pEntity.isInWater()) {
f = 1.5F;
}

if (pEntity.isInWater()) {
if (pEntity.getRemainingPersistentAngerTime() > 0 || pEntity.hasBoatTarget()) {
AnimUtil.animateWalk(this, PiranhaAnimation.SWIM_ANGRY, pLimbSwing, pLimbSwingAmount, 1.0F, 0.0F);
} else {
AnimUtil.animateWalk(this, PiranhaAnimation.SWIM, pLimbSwing, pLimbSwingAmount, 1.0F, 0.0F);
}
}
AnimUtil.animate(this, pEntity.swimState, PiranhaAnimation.SWIM, pAgeInTicks);
AnimUtil.animate(this, pEntity.angrySwimState, PiranhaAnimation.SWIM_ANGRY, pAgeInTicks);

this.tail_fin.yRot = -f * 0.45F * Mth.sin(0.6F * pAgeInTicks);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,83 @@
package com.uraneptus.sullysmod.client.model;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.uraneptus.sullysmod.SullysMod;
import com.uraneptus.sullysmod.common.entities.Tortoise;
import net.minecraft.resources.ResourceLocation;
import software.bernie.geckolib.core.animatable.model.CoreGeoBone;
import software.bernie.geckolib.core.animation.AnimationState;
import software.bernie.geckolib.model.DefaultedEntityGeoModel;

public class TortoiseModel <T extends Tortoise> extends DefaultedEntityGeoModel<T> {
public TortoiseModel() {
super(SullysMod.modPrefix("tortoise"), true);
import net.minecraft.client.model.EntityModel;
import net.minecraft.client.model.geom.ModelLayerLocation;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.model.geom.PartPose;
import net.minecraft.client.model.geom.builders.*;

public class TortoiseModel<E extends Tortoise> extends EntityModel<E> implements RootModel {
public static final ModelLayerLocation LAYER_LOCATION = new ModelLayerLocation(SullysMod.modPrefix("tortoise"), "main");

private final ModelPart root;
private final ModelPart body;
private final ModelPart left_back_leg;
private final ModelPart right_back_leg;
private final ModelPart right_front_leg;
private final ModelPart left_front_leg;
private final ModelPart shell;
private final ModelPart workstation_saddle;
private final ModelPart head;
private final ModelPart tail;

public TortoiseModel(ModelPart pRoot) {
this.root = pRoot;
this.body = root.getChild("body");
this.left_back_leg = body.getChild("left_back_leg");
this.right_back_leg = body.getChild("right_back_leg");
this.right_front_leg = body.getChild("right_front_leg");
this.left_front_leg = body.getChild("left_front_leg");
this.shell = body.getChild("shell");
this.workstation_saddle = shell.getChild("workstation_saddle");
this.head = shell.getChild("head");
this.tail = shell.getChild("tail");
}

@Override
public ResourceLocation getModelResource(T object) {
return SullysMod.modPrefix("geo/tortoise.geo.json");
public static LayerDefinition createBodyLayer() {
MeshDefinition meshdefinition = new MeshDefinition();
PartDefinition partdefinition = meshdefinition.getRoot();

PartDefinition body = partdefinition.addOrReplaceChild("body", CubeListBuilder.create(), PartPose.offset(0.0F, 24.0F, 0.0F));

body.addOrReplaceChild("left_back_leg", CubeListBuilder.create().texOffs(50, 39).addBox(-2.0F, -1.0F, -3.0F, 5.0F, 6.0F, 5.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(7.0F, -5.0F, 9.0F, 0.0F, -1.1345F, 0.0F));
body.addOrReplaceChild("right_back_leg", CubeListBuilder.create().texOffs(50, 39).mirror().addBox(-3.0F, -1.0F, -3.0F, 5.0F, 6.0F, 5.0F, new CubeDeformation(0.0F)).mirror(false), PartPose.offsetAndRotation(-7.0F, -5.0F, 9.0F, 0.0F, 1.1345F, 0.0F));
body.addOrReplaceChild("right_front_leg", CubeListBuilder.create().texOffs(50, 39).mirror().addBox(-3.0F, -1.0F, -2.0F, 5.0F, 6.0F, 5.0F, new CubeDeformation(0.0F)).mirror(false), PartPose.offsetAndRotation(-7.0F, -5.0F, -9.0F, 0.0F, 0.3927F, 0.0F));
body.addOrReplaceChild("left_front_leg", CubeListBuilder.create().texOffs(50, 39).addBox(-2.0F, -1.0F, -2.0F, 5.0F, 6.0F, 5.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(7.0F, -5.0F, -9.0F, 0.0F, -0.3927F, 0.0F));

PartDefinition shell = body.addOrReplaceChild("shell", CubeListBuilder.create().texOffs(0, 0).addBox(-8.0F, -17.0F, -8.0F, 16.0F, 14.0F, 18.0F, new CubeDeformation(0.0F))
.texOffs(0, 32).addBox(-8.0F, -17.0F, -8.0F, 16.0F, 14.0F, 18.0F, new CubeDeformation(0.5F)), PartPose.offset(0.0F, 0.0F, -0.5F));

shell.addOrReplaceChild("workstation_saddle", CubeListBuilder.create().texOffs(0, 64).addBox(-8.0F, -18.0F, -7.0F, 16.0F, 16.0F, 16.0F, new CubeDeformation(0.01F)), PartPose.offset(0.0F, -3.0F, 0.0F));

PartDefinition head = shell.addOrReplaceChild("head", CubeListBuilder.create().texOffs(50, 0).addBox(-3.0F, -2.0F, -9.0F, 6.0F, 6.0F, 9.0F, new CubeDeformation(0.0F))
.texOffs(80, 0).addBox(-3.0F, -2.5F, -9.0F, 6.0F, 6.0F, 9.0F, new CubeDeformation(0.5F)), PartPose.offset(0.0F, -5.5F, -6.0F));

PartDefinition tail = shell.addOrReplaceChild("tail", CubeListBuilder.create(), PartPose.offset(0.0F, -3.0F, 9.0F));

//PartDefinition cube_r1 = tail.addOrReplaceChild("cube_r1", CubeListBuilder.create().texOffs(0, 10).addBox(-1.0F, -1.5F, -1.0F, 2.0F, 2.0F, 6.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(0.0F, 1.0F, 1.0F, -0.2182F, 0.0F, 0.0F));

return LayerDefinition.create(meshdefinition, 128, 128);
}

@Override
public ResourceLocation getTextureResource(T object) {
return object.isCraftingTable() ? SullysMod.modPrefix("textures/entity/tortoise/tortoise_crafting.png") : SullysMod.modPrefix("textures/entity/tortoise/tortoise_jukebox.png");
public void setupAnim(E pEntity, float pLimbSwing, float pLimbSwingAmount, float pAgeInTicks, float pNetHeadYaw, float pHeadPitch) {
if (!pEntity.hasAppliedWorkstation()) {
this.workstation_saddle.visible = false;
}
//TODO do all the animations
}

@Override
public ResourceLocation getAnimationResource(T animatable) {
return SullysMod.modPrefix("animations/tortoise.animation.json");
public void renderToBuffer(PoseStack pPoseStack, VertexConsumer pBuffer, int pPackedLight, int pPackedOverlay, float pRed, float pGreen, float pBlue, float pAlpha) {
this.root().render(pPoseStack, pBuffer, pPackedLight, pPackedOverlay);
}

@Override
public void setCustomAnimations(T animatable, long instanceId, AnimationState<T> animationState) {
super.setCustomAnimations(animatable, instanceId, animationState);
CoreGeoBone saddle = getAnimationProcessor().getBone("WorkstationSaddle");

saddle.setHidden(!animatable.hasAppliedWorkstation());
public ModelPart root() {
return this.root;
}
}
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
package com.uraneptus.sullysmod.client.renderer.entities;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.uraneptus.sullysmod.SullysMod;
import com.uraneptus.sullysmod.client.model.TortoiseModel;
import com.uraneptus.sullysmod.common.entities.Tortoise;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import software.bernie.geckolib.cache.object.BakedGeoModel;
import software.bernie.geckolib.renderer.GeoEntityRenderer;
import net.minecraft.client.renderer.entity.MobRenderer;
import net.minecraft.resources.ResourceLocation;

public class TortoiseRenderer <E extends Tortoise> extends GeoEntityRenderer<E> {
public TortoiseRenderer(EntityRendererProvider.Context renderManager) {
super(renderManager, new TortoiseModel<>());
this.shadowRadius = 0.75F;
}
public class TortoiseRenderer<E extends Tortoise> extends MobRenderer<E, TortoiseModel<E>> {
private static final ResourceLocation TEXTURE_CRAFTING = SullysMod.modPrefix("textures/entity/tortoise/tortoise_crafting.png");
private static final ResourceLocation TEXTURE_JUKEBOX = SullysMod.modPrefix("textures/entity/tortoise/tortoise_jukebox.png");

//Reduced motionThreshold to detect entities that are moving slowly e.g. Tortoise
@Override
public float getMotionAnimThreshold(E animatable) {
return 0.005F;
public TortoiseRenderer(EntityRendererProvider.Context pContext) {
super(pContext, new TortoiseModel<>(pContext.bakeLayer(TortoiseModel.LAYER_LOCATION)), 0.75F);
}

@Override
public void preRender(PoseStack poseStack, E animatable, BakedGeoModel model, MultiBufferSource bufferSource, VertexConsumer buffer, boolean isReRender, float partialTick, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) {
super.preRender(poseStack, animatable, model, bufferSource, buffer, isReRender, partialTick, packedLight, packedOverlay, red, green, blue, alpha);
public void render(E pEntity, float pEntityYaw, float pPartialTicks, PoseStack pPoseStack, MultiBufferSource pBuffer, int pPackedLight) {
super.render(pEntity, pEntityYaw, pPartialTicks, pPoseStack, pBuffer, pPackedLight);

if (animatable.isBaby()) {
poseStack.scale(0.15F, 0.15F, 0.15F);
if (pEntity.isBaby()) {
pPoseStack.scale(0.15F, 0.15F, 0.15F);
this.shadowRadius *= 0.15F;
}
}

@Override
public ResourceLocation getTextureLocation(E pEntity) {
return pEntity.isCraftingTable() ? TEXTURE_CRAFTING : TEXTURE_JUKEBOX;
}
}
33 changes: 6 additions & 27 deletions src/main/java/com/uraneptus/sullysmod/common/entities/Piranha.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,15 @@
import java.util.UUID;

public class Piranha extends AbstractSchoolingFish implements NeutralMob {
protected static final RawAnimation SWIMMING_ANIM = RawAnimation.begin().thenLoop("animation.piranha.swim");
protected static final RawAnimation SWIMMING_ANGRY_ANIM = RawAnimation.begin().thenLoop("animation.piranha.swim_angry");
protected static final RawAnimation JUMPING_ANIM = RawAnimation.begin().thenPlay("animation.piranha.in_air");
private static final EntityDataAccessor<Integer> DATA_REMAINING_ANGER_TIME = SynchedEntityData.defineId(Piranha.class, EntityDataSerializers.INT);
private static final UniformInt PERSISTENT_ANGER_TIME = TimeUtil.rangeOfSeconds(5, 10);
private static final EntityDataAccessor<Boolean> HAS_BOAT_TARGET = SynchedEntityData.defineId(Piranha.class, EntityDataSerializers.BOOLEAN);
@Nullable
private UUID persistentAngerTarget;
@Nullable
private Boat boatTarget;
public final AnimationState swimState = new AnimationState();
public final AnimationState angrySwimState = new AnimationState();

public Piranha(EntityType<? extends AbstractSchoolingFish> pEntityType, Level pLevel) {
super(pEntityType, pLevel);
Expand Down Expand Up @@ -127,19 +126,11 @@ public void readAdditionalSaveData(CompoundTag pCompound) {

public void tick() {
super.tick();
/*
System.out.println("Regular Target: " + this.getTarget());
System.out.println(hasBoatTarget());
if (boatTarget != null) {
System.out.println(this.boatTarget.getDamage());
System.out.println("Boat Target: " + this.boatTarget);
if (level().isClientSide()) {
boolean angryFlag = this.getRemainingPersistentAngerTime() > 0 || this.hasBoatTarget();
this.swimState.animateWhen(this.isInWater() && !angryFlag, this.tickCount);
this.angrySwimState.animateWhen(this.isInWater() && angryFlag, this.tickCount);
}
*/
System.out.println(this.getRemainingPersistentAngerTime());
System.out.println(this.hasBoatTarget());

}

@Override
Expand Down Expand Up @@ -173,18 +164,6 @@ public ItemStack getBucketItemStack() {
return new ItemStack(SMItems.PIRANHA_BUCKET.get());
}

/*
public <E extends GeoAnimatable> PlayState setAnimation(final AnimationState<E> event) {
if ((event.isMoving() && this.getRemainingPersistentAngerTime() > 0) || this.hasBoatTarget()) {
return event.setAndContinue(SWIMMING_ANGRY_ANIM);
} else if (event.isMoving()) {
return event.setAndContinue(SWIMMING_ANIM);
}
return PlayState.STOP;
}
*/

public int getRemainingPersistentAngerTime() {
return this.entityData.get(DATA_REMAINING_ANGER_TIME);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@

import java.util.List;

public class Tortoise extends Animal implements GeoEntity, WorkstationAttachable {
public class Tortoise extends Animal implements WorkstationAttachable {
public static final EntityDataAccessor<Integer> HIDE_TIMER = SynchedEntityData.defineId(Tortoise.class, EntityDataSerializers.INT);
private static final EntityDataAccessor<Boolean> HAS_EGG = SynchedEntityData.defineId(Tortoise.class, EntityDataSerializers.BOOLEAN);
private static final EntityDataAccessor<Boolean> LAYING_EGG = SynchedEntityData.defineId(Tortoise.class, EntityDataSerializers.BOOLEAN);
Expand All @@ -68,7 +68,6 @@ public class Tortoise extends Animal implements GeoEntity, WorkstationAttachable
protected static final RawAnimation WALKING_ANIM = RawAnimation.begin().thenLoop("animation.tortoise.walking");
protected static final RawAnimation HIDING_ANIM = RawAnimation.begin().thenPlayAndHold("animation.tortoise.hide").thenLoop("animation.tortoise.hiding");
protected static final RawAnimation REVEAL_ANIM = RawAnimation.begin().thenPlayAndHold("animation.tortoise.reveal");
private final AnimatableInstanceCache instanceCache = GeckoLibUtil.createInstanceCache(this);
int layEggCounter;
FollowJukeboxEntitySoundInstance soundInstance;
long recordTickCount;
Expand Down Expand Up @@ -272,16 +271,7 @@ public LivingEntity getControllingPassenger() {
return null;
}

@Override
public void registerControllers(AnimatableManager.ControllerRegistrar controllerRegistrar) {
controllerRegistrar.add(new AnimationController<>(this, "Animations", 3, this::setAnimation));
}

@Override
public AnimatableInstanceCache getAnimatableInstanceCache() {
return instanceCache;
}

/*
public <E extends GeoAnimatable> PlayState setAnimation(final AnimationState<E> event) {
if (event.isMoving() && getHideTimerDuration() == 0 && onGround()) {
return event.setAndContinue(WALKING_ANIM);
Expand All @@ -293,6 +283,8 @@ public <E extends GeoAnimatable> PlayState setAnimation(final AnimationState<E>
return PlayState.STOP;
}
*/

@Override
public boolean hurt(@NotNull DamageSource source, float amount) {
Level level = this.level();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public static void registerLayerLocation(EntityRenderersEvent.RegisterLayerDefin
event.registerLayerDefinition(LanternfishModel.LAYER_LOCATION, LanternfishModel::createBodyLayer);
event.registerLayerDefinition(JadeShieldModel.LAYER_LOCATION, JadeShieldModel::createLayer);
event.registerLayerDefinition(TortoiseShellModel.LAYER_LOCATION, TortoiseShellModel::createBodyLayer);
event.registerLayerDefinition(TortoiseModel.LAYER_LOCATION, TortoiseModel::createBodyLayer);
event.registerLayerDefinition(JungleSpiderModel.LAYER_LOCATION, JungleSpiderModel::createBodyLayer);
event.registerLayerDefinition(BoulderingZombieModel.LAYER_LOCATION, BoulderingZombieModel::createBodyLayer);
event.registerLayerDefinition(PiranhaModel.LAYER_LOCATION, PiranhaModel::createBodyLayer);
Expand Down

0 comments on commit aa90335

Please sign in to comment.