Give them legs and they can breath underwater now

This commit is contained in:
Sollace 2024-04-20 17:20:18 +01:00
parent 2749bab863
commit 22d6874102
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
4 changed files with 62 additions and 19 deletions

File diff suppressed because one or more lines are too long

View file

@ -1,6 +1,9 @@
// Made with Blockbench 4.9.4 // Made with Blockbench 4.9.4
// Exported for Minecraft version 1.17+ for Yarn // Exported for Minecraft version 1.17+ for Yarn
// Paste this class into your mod and generate all required imports // Paste this class into your mod and generate all required imports
package com.example.mod;
public class mimic extends EntityModel<Entity> { public class mimic extends EntityModel<Entity> {
private final ModelPart lid; private final ModelPart lid;
private final ModelPart tongue_r1; private final ModelPart tongue_r1;
@ -8,9 +11,13 @@ public class mimic extends EntityModel<Entity> {
private final ModelPart cube_r1; private final ModelPart cube_r1;
private final ModelPart lower_teeth; private final ModelPart lower_teeth;
private final ModelPart cube_r2; private final ModelPart cube_r2;
private final ModelPart right_leg;
private final ModelPart left_leg;
public mimic(ModelPart root) { public mimic(ModelPart root) {
this.lid = root.getChild("lid"); this.lid = root.getChild("lid");
this.lower_teeth = root.getChild("lower_teeth"); this.lower_teeth = root.getChild("lower_teeth");
this.right_leg = root.getChild("right_leg");
this.left_leg = root.getChild("left_leg");
} }
public static TexturedModelData getTexturedModelData() { public static TexturedModelData getTexturedModelData() {
ModelData modelData = new ModelData(); ModelData modelData = new ModelData();
@ -40,6 +47,10 @@ public class mimic extends EntityModel<Entity> {
.uv(0, 0).cuboid(-6.0F, -1.0F, 5.0F, 2.0F, 4.0F, 1.0F, new Dilation(0.0F)) .uv(0, 0).cuboid(-6.0F, -1.0F, 5.0F, 2.0F, 4.0F, 1.0F, new Dilation(0.0F))
.uv(0, 0).cuboid(-9.0F, -1.0F, 5.0F, 2.0F, 4.0F, 1.0F, new Dilation(0.0F)) .uv(0, 0).cuboid(-9.0F, -1.0F, 5.0F, 2.0F, 4.0F, 1.0F, new Dilation(0.0F))
.uv(0, 0).cuboid(-12.0F, -1.0F, 5.0F, 2.0F, 4.0F, 1.0F, new Dilation(0.0F)), ModelTransform.of(0.0F, 0.0F, 0.0F, 0.0F, 1.5708F, 0.0F)); .uv(0, 0).cuboid(-12.0F, -1.0F, 5.0F, 2.0F, 4.0F, 1.0F, new Dilation(0.0F)), ModelTransform.of(0.0F, 0.0F, 0.0F, 0.0F, 1.5708F, 0.0F));
ModelPartData right_leg = modelPartData.addChild("right_leg", ModelPartBuilder.create().uv(7, 30).cuboid(-2.5F, -1.5F, -3.0F, 5.0F, 7.0F, 6.0F, new Dilation(0.0F)), ModelTransform.pivot(3.5F, 25.5F, 1.0F));
ModelPartData left_leg = modelPartData.addChild("left_leg", ModelPartBuilder.create().uv(7, 30).mirrored().cuboid(-9.5F, -1.5F, -3.0F, 5.0F, 7.0F, 6.0F, new Dilation(0.0F)).mirrored(false), ModelTransform.pivot(3.5F, 25.5F, 1.0F));
return TexturedModelData.of(modelData, 64, 64); return TexturedModelData.of(modelData, 64, 64);
} }
@Override @Override
@ -49,5 +60,7 @@ public class mimic extends EntityModel<Entity> {
public void render(MatrixStack matrices, VertexConsumer vertexConsumer, int light, int overlay, float red, float green, float blue, float alpha) { public void render(MatrixStack matrices, VertexConsumer vertexConsumer, int light, int overlay, float red, float green, float blue, float alpha) {
lid.render(matrices, vertexConsumer, light, overlay, red, green, blue, alpha); lid.render(matrices, vertexConsumer, light, overlay, red, green, blue, alpha);
lower_teeth.render(matrices, vertexConsumer, light, overlay, red, green, blue, alpha); lower_teeth.render(matrices, vertexConsumer, light, overlay, red, green, blue, alpha);
right_leg.render(matrices, vertexConsumer, light, overlay, red, green, blue, alpha);
left_leg.render(matrices, vertexConsumer, light, overlay, red, green, blue, alpha);
} }
} }

View file

@ -34,6 +34,8 @@ public class MimicEntityRenderer extends MobEntityRenderer<MimicEntity, MimicEnt
@Override @Override
public void render(MimicEntity entity, float yaw, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertices, int light) { public void render(MimicEntity entity, float yaw, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertices, int light) {
matrices.push();
matrices.translate(0, 0.3F * entity.getPeekAmount(), 0);
super.render(entity, yaw, tickDelta, matrices, super.render(entity, yaw, tickDelta, matrices,
FloatingArtefactEntityRenderer.getDestructionOverlayProvider( FloatingArtefactEntityRenderer.getDestructionOverlayProvider(
matrices, matrices,
@ -41,6 +43,7 @@ public class MimicEntityRenderer extends MobEntityRenderer<MimicEntity, MimicEnt
1, 1,
FloatingArtefactEntityRenderer.getDestructionStage(entity) FloatingArtefactEntityRenderer.getDestructionStage(entity)
), light); ), light);
matrices.pop();
} }
@Override @Override
@ -76,29 +79,34 @@ public class MimicEntityRenderer extends MobEntityRenderer<MimicEntity, MimicEnt
static class MimicModel extends EntityModel<MimicEntity> { static class MimicModel extends EntityModel<MimicEntity> {
private ModelPart part; private ModelPart part;
private ModelPart lid; private ModelPart lid;
private ModelPart leftLeg;
private ModelPart rightLeg;
public MimicModel(ModelPart part) { public MimicModel(ModelPart part) {
this.part = part; this.part = part;
this.lid = part.getChild("lid"); this.lid = part.getChild("lid");
this.leftLeg = part.getChild("left_leg");
this.rightLeg = part.getChild("right_leg");
} }
public static TexturedModelData getTexturedModelData() { public static TexturedModelData getTexturedModelData() {
ModelData data = new ModelData(); ModelData data = new ModelData();
ModelPartData root = data.getRoot(); ModelPartData root = data.getRoot();
ModelPartData lid = root.addChild("lid", ModelPartBuilder.create(), ModelTransform.of(0, 17, -7, -0.829F, 0, -3.1416F)); ModelPartData lid = root.addChild("lid", ModelPartBuilder.create(), ModelTransform.of(0, 15, -7, 0, 0, -3.1416F));
lid.addChild("tongue", ModelPartBuilder.create() lid.addChild("tongue", ModelPartBuilder.create()
.uv(11, 34).cuboid(-3, -11, 1, 6, 1, 8, Dilation.NONE), ModelTransform.of(0, 6, 9, 0.8F, 0, 0)); .uv(11, 34).cuboid(-3, -11, 1, 6, 1, 8, Dilation.NONE), ModelTransform.of(0, 6, 9, 0.8F, 0, 0));
lid.addChild("upper_teeth", ModelPartBuilder.create() lid.addChild("upper_teeth", ModelPartBuilder.create()
.uv(0, 0).cuboid(-1, -8, 5, 2, 4, 1, Dilation.NONE) //.uv(0, 0).cuboid(-7, 0, 0, 14, 5, 14, Dilation.NONE)
.uv(0, 0).cuboid(-4, -8, 5, 2, 4, 1, Dilation.NONE) .uv(0, 0).cuboid(-1, -2, 12, 2, 4, 1, Dilation.NONE)
.uv(0, 0).cuboid(2, -8, 5, 2, 4, 1, Dilation.NONE), ModelTransform.pivot(0, 6, 9)) .uv(0, 0).cuboid(-4, -2, 12, 2, 4, 1, Dilation.NONE)
.uv(0, 0).cuboid(2, -2, 12, 2, 4, 1, Dilation.NONE), ModelTransform.NONE)
.addChild("cube_r1", ModelPartBuilder.create() .addChild("cube_r1", ModelPartBuilder.create()
.uv(0, 0).cuboid(-6, -1, -6, 2, 4, 1, Dilation.NONE) .uv(0, 0).cuboid(-5, -2, -6, 2, 4, 1, Dilation.NONE)
.uv(0, 0).cuboid(-9, -1, -6, 2, 4, 1, Dilation.NONE) .uv(0, 0).cuboid(-8, -2, -6, 2, 4, 1, Dilation.NONE)
.uv(0, 0).cuboid(-12, -1, -6, 2, 4, 1, Dilation.NONE) .uv(0, 0).cuboid(-11, -2, -6, 2, 4, 1, Dilation.NONE)
.uv(0, 0).cuboid(-6, -1, 5, 2, 4, 1, Dilation.NONE) .uv(0, 0).cuboid(-5, -2, 5, 2, 4, 1, Dilation.NONE)
.uv(0, 0).cuboid(-9, -1, 5, 2, 4, 1, Dilation.NONE) .uv(0, 0).cuboid(-8, -2, 5, 2, 4, 1, Dilation.NONE)
.uv(0, 0).cuboid(-12, -1, 5, 2, 4, 1, Dilation.NONE), ModelTransform.of(0, -7, -7, 0, 1.5708F, 0)); .uv(0, 0).cuboid(-11, -2, 5, 2, 4, 1, Dilation.NONE), ModelTransform.of(0, 0, 0, 0, 1.5708F, 0));
root.addChild("lower_teeth", ModelPartBuilder.create() root.addChild("lower_teeth", ModelPartBuilder.create()
.uv(0, 0).cuboid(-1, -1, 12, 2, 4, 1, Dilation.NONE) .uv(0, 0).cuboid(-1, -1, 12, 2, 4, 1, Dilation.NONE)
.uv(0, 0).cuboid(-4, -1, 12, 2, 4, 1, Dilation.NONE) .uv(0, 0).cuboid(-4, -1, 12, 2, 4, 1, Dilation.NONE)
@ -110,14 +118,15 @@ public class MimicEntityRenderer extends MobEntityRenderer<MimicEntity, MimicEnt
.uv(0, 0).cuboid(-6, -1, 5, 2, 4, 1, Dilation.NONE) .uv(0, 0).cuboid(-6, -1, 5, 2, 4, 1, Dilation.NONE)
.uv(0, 0).cuboid(-9, -1, 5, 2, 4, 1, Dilation.NONE) .uv(0, 0).cuboid(-9, -1, 5, 2, 4, 1, Dilation.NONE)
.uv(0, 0).cuboid(-12, -1, 5, 2, 4, 1, Dilation.NONE), ModelTransform.of(0, 0, 0, 0, 1.5708F, 0)); .uv(0, 0).cuboid(-12, -1, 5, 2, 4, 1, Dilation.NONE), ModelTransform.of(0, 0, 0, 0, 1.5708F, 0));
root.addChild("right_leg", ModelPartBuilder.create()
.uv(7, 30).cuboid(-2.5F, -1.5F, -3.5F, 5, 7, 6, Dilation.NONE), ModelTransform.pivot(3.5F, 23.5F, 0));
root.addChild("left_leg", ModelPartBuilder.create()
.uv(7, 30).mirrored().cuboid(-9.5F, -1.5F, -3.5F, 5, 7, 6, Dilation.NONE), ModelTransform.pivot(3.5F, 23.5F, 0));
return TexturedModelData.of(data, 64, 64); return TexturedModelData.of(data, 64, 64);
} }
@Override @Override
public void animateModel(MimicEntity entity, float limbAngle, float limbDistance, float tickDelta) { public void animateModel(MimicEntity entity, float limbAngle, float limbDistance, float tickDelta) {
var data = getTexturedModelData();
part = data.createModel();
lid = part.getChild("lid");
ChestBlockEntity tileData = entity.getChestData(); ChestBlockEntity tileData = entity.getChestData();
if (tileData != null) { if (tileData != null) {
var properties = CloudChestBlockEntityRenderer.getProperties(tileData.getCachedState(), tileData); var properties = CloudChestBlockEntityRenderer.getProperties(tileData.getCachedState(), tileData);
@ -129,15 +138,24 @@ public class MimicEntityRenderer extends MobEntityRenderer<MimicEntity, MimicEnt
part.yaw = MathHelper.RADIANS_PER_DEGREE * 180; part.yaw = MathHelper.RADIANS_PER_DEGREE * 180;
part.pitch = -entity.getPitch(tickDelta) * MathHelper.RADIANS_PER_DEGREE; part.pitch = -entity.getPitch(tickDelta) * MathHelper.RADIANS_PER_DEGREE;
} }
@Override @Override
public void setAngles(MimicEntity entity, float limbAngle, float limbDistance, float animationProgress, float headYaw, float headPitch) { public void setAngles(MimicEntity entity, float limbAngle, float limbDistance, float animationProgress, float headYaw, float headPitch) {
rightLeg.resetTransform();
leftLeg.resetTransform();
rightLeg.pitch = MathHelper.cos(limbAngle * 0.6662F) * 1.4F * limbDistance;
leftLeg.pitch = MathHelper.cos(limbAngle * 0.6662F + (float) Math.PI) * 1.4F * limbDistance;
float revealPercentage = entity.getPeekAmount();
float velocy = (1 - revealPercentage) * -10F;
rightLeg.pivotY += velocy;
leftLeg.pivotY += velocy;
rightLeg.visible = revealPercentage > 0.2F;
leftLeg.visible = revealPercentage > 0.2F;
} }
@Override @Override
public void render(MatrixStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green, float blue, float alpha) { public void render(MatrixStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green, float blue, float alpha) {
if (lid.pitch != 0) {
part.render(matrices, vertices, light, overlay); part.render(matrices, vertices, light, overlay);
} }
} }
}
} }

View file

@ -68,7 +68,7 @@ public class MimicEntity extends PathAwareEntity {
} }
float spawnChance = (difficulty / 3F) * 0.25F; float spawnChance = (difficulty / 3F) * 0.25F;
float roll = world.random.nextFloat(); float roll = world.random.nextFloat();
System.out.println("Roll mimic: " + roll + " < " + spawnChance);
if (roll >= spawnChance) { if (roll >= spawnChance) {
return TypedActionResult.pass(null); return TypedActionResult.pass(null);
} }
@ -112,6 +112,11 @@ public class MimicEntity extends PathAwareEntity {
return isAlive(); return isAlive();
} }
@Override
public boolean canBreatheInWater() {
return true;
}
@Nullable @Nullable
@Override @Override
public ItemStack getPickBlockStack() { public ItemStack getPickBlockStack() {
@ -121,7 +126,7 @@ public class MimicEntity extends PathAwareEntity {
@Override @Override
protected void initGoals() { protected void initGoals() {
goalSelector.add(2, new AttackGoal(this, 1.0, false)); goalSelector.add(2, new AttackGoal(this, 0.6F, false));
} }
public void setChest(ChestBlock chest) { public void setChest(ChestBlock chest) {
@ -168,6 +173,10 @@ public class MimicEntity extends PathAwareEntity {
setMouthOpen(true); setMouthOpen(true);
} }
public float getPeekAmount() {
return MathHelper.clamp((float)getVelocity().lengthSquared() * 50F, 0, 1);
}
@Override @Override
public void tick() { public void tick() {
super.tick(); super.tick();
@ -183,6 +192,9 @@ public class MimicEntity extends PathAwareEntity {
setBodyYaw(MathHelper.floor(getBodyYaw() / 90) * 90); setBodyYaw(MathHelper.floor(getBodyYaw() / 90) * 90);
setYaw(MathHelper.floor(getYaw() / 90) * 90); setYaw(MathHelper.floor(getYaw() / 90) * 90);
setHeadYaw(MathHelper.floor(getHeadYaw() / 90) * 90); setHeadYaw(MathHelper.floor(getHeadYaw() / 90) * 90);
if (getHealth() < getMaxHealth() && getWorld().random.nextInt(20) == 0) {
heal(1);
}
} }
} }