Skip to content

Commit

Permalink
Bat remodel
Browse files Browse the repository at this point in the history
  • Loading branch information
N1nn1 committed May 7, 2024
1 parent bf57faa commit 46be469
Show file tree
Hide file tree
Showing 11 changed files with 166 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/ninni/spawn/SpawnRPTweaks.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class SpawnRPTweaks {
public enum Tweaks {
PARROT_MODEL("parrot_remodel"),
RABBIT_REMODEL("rabbit_remodel"),
BAT_REMODEL("bat_remodel"),
TURTLE_ANIMATIONS("turtle_animations"),
TURTLE_BABY_HEAD_SCALE("turtle_baby_head_scale");

Expand Down
85 changes: 85 additions & 0 deletions src/main/java/com/ninni/spawn/client/model/BatRemodel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.ninni.spawn.client.model;

import net.minecraft.client.model.BatModel;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.model.geom.PartPose;
import net.minecraft.client.model.geom.builders.*;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.ambient.Bat;

public class BatRemodel extends BatModel {
private final ModelPart root;
private final ModelPart head;
private final ModelPart body;
private final ModelPart rightWing;
private final ModelPart leftWing;
private final ModelPart rightWingTip;
private final ModelPart leftWingTip;

public BatRemodel(ModelPart modelPart) {
super(modelPart);
this.root = modelPart;
this.head = modelPart.getChild("head");
this.body = modelPart.getChild("body");
this.rightWing = this.body.getChild("right_wing");
this.rightWingTip = this.rightWing.getChild("right_wing_tip");
this.leftWing = this.body.getChild("left_wing");
this.leftWingTip = this.leftWing.getChild("left_wing_tip");
}

@Override
public void setupAnim(Bat bat, float limbAngle, float limbDistance, float animationProgress, float headYaw, float headPitch) {
float pi = (float) Math.PI;

this.head.xRot = headPitch * (pi / 180);
this.head.yRot = headYaw * (pi / 180);

if (bat.isResting()) {
this.head.xRot = pi;
this.head.setPos(0.0f, 16.0f, 0.0f);
this.body.xRot = pi;
this.rightWing.xRot = -0.2f;
this.rightWing.yRot = -1.2f;
this.rightWingTip.yRot = -2f;
this.leftWing.xRot = this.rightWing.xRot;
this.leftWing.yRot = -this.rightWing.yRot;
this.leftWingTip.yRot = -this.rightWingTip.yRot;
} else {
this.body.xRot = Mth.sin(animationProgress * 0.3f) * -0.2f + 0.6f;
this.head.y = Mth.cos(animationProgress * 0.3f) * -0.2f + 16f;
this.rightWing.xRot = Mth.sin(animationProgress * 0.9f + pi) * 0.25f;
this.rightWing.yRot = Mth.cos(animationProgress * 0.9f + pi) * 1.25f;
this.rightWingTip.yRot = Mth.cos(animationProgress * 0.9f + pi) * 0.5f;
this.leftWing.xRot = Mth.sin(animationProgress * 0.9f) * 0.25f;
this.leftWing.yRot = Mth.cos(animationProgress * 0.9f) * 1.25f;
this.leftWingTip.yRot = Mth.cos(animationProgress * 0.9f) * 0.5f;
}
}

@Override
public ModelPart root() {
return this.root;
}

public static LayerDefinition createRemodel() {
MeshDefinition meshdefinition = new MeshDefinition();
PartDefinition partdefinition = meshdefinition.getRoot();

PartDefinition head = partdefinition.addOrReplaceChild("head", CubeListBuilder.create().texOffs(0, 0).addBox(-2.5F, -4.0F, -2.0F, 5.0F, 4.0F, 4.0F, new CubeDeformation(0.0F))
.texOffs(14, 0).addBox(1.5F, -6.0F, 0.0F, 2.0F, 3.0F, 1.0F, new CubeDeformation(0.0F))
.texOffs(14, 0).mirror().addBox(-3.5F, -6.0F, 0.0F, 2.0F, 3.0F, 1.0F, new CubeDeformation(0.0F)).mirror(false), PartPose.offset(0.0F, 16.0F, 0.0F));

PartDefinition body = partdefinition.addOrReplaceChild("body", CubeListBuilder.create().texOffs(0, 8).addBox(-2.0F, -0.5F, -1.0F, 4.0F, 5.0F, 2.0F, new CubeDeformation(0.0F))
.texOffs(12, 8).addBox(-1.5F, 4.5F, 0.0F, 3.0F, 3.0F, 0.0F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, 16.5F, 0.0F));

PartDefinition left_wing = body.addOrReplaceChild("left_wing", CubeListBuilder.create().texOffs(0, 15).addBox(0.0F, -3.0F, 0.0F, 5.0F, 7.0F, 0.0F, new CubeDeformation(0.0F)), PartPose.offset(2.0F, 0.5F, 0.5F));

PartDefinition left_wing_tip = left_wing.addOrReplaceChild("left_wing_tip", CubeListBuilder.create().texOffs(10, 15).addBox(0.0F, -2.0F, 0.0F, 5.0F, 7.0F, 0.0F, new CubeDeformation(0.0F)), PartPose.offset(5.0F, -1.0F, 0.0F));

PartDefinition right_wing = body.addOrReplaceChild("right_wing", CubeListBuilder.create().texOffs(0, 15).mirror().addBox(-5.0F, -3.0F, 0.0F, 5.0F, 7.0F, 0.0F, new CubeDeformation(0.0F)).mirror(false), PartPose.offset(-2.0F, 0.5F, 0.5F));

PartDefinition right_wing_tip = right_wing.addOrReplaceChild("right_wing_tip", CubeListBuilder.create().texOffs(10, 15).mirror().addBox(-5.0F, -2.0F, 0.0F, 5.0F, 7.0F, 0.0F, new CubeDeformation(0.0F)).mirror(false), PartPose.offset(-5.0F, -1.0F, 0.0F));

return LayerDefinition.create(meshdefinition, 32, 32);
}
}
48 changes: 48 additions & 0 deletions src/main/java/com/ninni/spawn/mixin/client/BatRendererMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.ninni.spawn.mixin.client;

import com.mojang.blaze3d.vertex.PoseStack;
import com.ninni.spawn.SpawnRPTweaks;
import com.ninni.spawn.client.model.BatRemodel;
import com.ninni.spawn.client.model.RabbitRemodel;
import com.ninni.spawn.registry.SpawnEntityModelLayers;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.model.BatModel;
import net.minecraft.client.model.RabbitModel;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.entity.BatRenderer;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.client.renderer.entity.MobRenderer;
import net.minecraft.client.renderer.entity.RabbitRenderer;
import net.minecraft.world.entity.ambient.Bat;
import net.minecraft.world.entity.animal.Rabbit;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(BatRenderer.class)
@Environment(value= EnvType.CLIENT)
public abstract class BatRendererMixin extends MobRenderer<Bat, BatModel> {
private BatRemodel remodel;

public BatRendererMixin(EntityRendererProvider.Context context, BatModel entityModel, float f) {
super(context, entityModel, f);
}

@Inject(method = "<init>", at = @At("TAIL"))
private void S$init(EntityRendererProvider.Context context, CallbackInfo ci) {
this.remodel = new BatRemodel(context.bakeLayer(SpawnEntityModelLayers.BAT_REMODEL));
}

@Inject(method = "scale(Lnet/minecraft/world/entity/ambient/Bat;Lcom/mojang/blaze3d/vertex/PoseStack;F)V", at = @At("HEAD"), cancellable = true)
private void S$scale(Bat bat, PoseStack poseStack, float f, CallbackInfo ci) {
if (SpawnRPTweaks.isPresent(SpawnRPTweaks.Tweaks.BAT_REMODEL)) ci.cancel();
}

@Override
public void render(Bat mob, float f, float g, PoseStack poseStack, MultiBufferSource multiBufferSource, int i) {
if (SpawnRPTweaks.isPresent(SpawnRPTweaks.Tweaks.BAT_REMODEL)) this.model = this.remodel;
super.render(mob, f, g, poseStack, multiBufferSource, i);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ public interface SpawnEntityModelLayers {
ModelLayerLocation OCTOPUS_LOCKING = main("octopus_locking", OctopusModel::createLockingBodyLayer);
ModelLayerLocation SEA_LION = main("sea_lion", SeaLionModel::createBodyLayer);
ModelLayerLocation SEA_LION_SWIMMING = main("sea_lion_swimming", SeaLionModel::createSwimmingBodyLayer);
ModelLayerLocation PARROT_REMODEL = main("parrot_remodel", ParrotRemodel::createRemodel);
ModelLayerLocation RABBIT_REMODEL = main("rabbit_remodel", RabbitRemodel::createRemodel);
ModelLayerLocation SUNFISH = main("sunfish", SunfishModel::createBodyLayer);
ModelLayerLocation SUNFISH_BABY = main("sunfish_baby", SunfishModel::createBabyBodyLayer);
ModelLayerLocation SUNFISH_NEWBORN = main("sunfish_newborn", SunfishModel::createNewbornBodyLayer);

ModelLayerLocation PARROT_REMODEL = main("parrot_remodel", ParrotRemodel::createRemodel);
ModelLayerLocation RABBIT_REMODEL = main("rabbit_remodel", RabbitRemodel::createRemodel);
ModelLayerLocation BAT_REMODEL = main("bat_remodel", BatRemodel::createRemodel);

private static ModelLayerLocation register(String id, String name, EntityModelLayerRegistry.TexturedModelDataProvider provider) {
ModelLayerLocation layer = new ModelLayerLocation(new ResourceLocation(MOD_ID, id), name);
EntityModelLayerRegistry.registerModelLayer(layer, provider);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@


* This tweak enables a new bat model with new animations and textures.



What is a Tweak?

Tweaks are client side modifications.
They are .txt files stored in the "minecraft/tweaks/" folder of resource packs,
each of them alters specific aspects of your game as long as Spawn is installed.
By including the desired tweaks in your resource pack, you can selectively activate features like model enhancements, animation freshen-ups and visual changes.
The "Animal Tweaks" resource pack, bundled with Spawn, automatically contains all available tweaks for you to choose from, go check the GitHub to see!

https://github.com/N1nn1/spawn/tree/update-2/src/main/resources/resourcepacks/animal_tweaks
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@
They are .txt files stored in the "minecraft/tweaks/" folder of resource packs,
each of them alters specific aspects of your game as long as Spawn is installed.
By including the desired tweaks in your resource pack, you can selectively activate features like model enhancements, animation freshen-ups and visual changes.
The "Animal Tweaks" resource pack, bundled with Spawn, automatically contains all available tweaks for you to choose from.
The "Animal Tweaks" resource pack, bundled with Spawn, automatically contains all available tweaks for you to choose from, go check the GitHub to see!

https://github.com/N1nn1/spawn/tree/update-2/src/main/resources/resourcepacks/animal_tweaks
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@
They are .txt files stored in the "minecraft/tweaks/" folder of resource packs,
each of them alters specific aspects of your game as long as Spawn is installed.
By including the desired tweaks in your resource pack, you can selectively activate features like model enhancements, animation freshen-ups and visual changes.
The "Animal Tweaks" resource pack, bundled with Spawn, automatically contains all available tweaks for you to choose from.
The "Animal Tweaks" resource pack, bundled with Spawn, automatically contains all available tweaks for you to choose from, go check the GitHub to see!

https://github.com/N1nn1/spawn/tree/update-2/src/main/resources/resourcepacks/animal_tweaks
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@
They are .txt files stored in the "minecraft/tweaks/" folder of resource packs,
each of them alters specific aspects of your game as long as Spawn is installed.
By including the desired tweaks in your resource pack, you can selectively activate features like model enhancements, animation freshen-ups and visual changes.
The "Animal Tweaks" resource pack, bundled with Spawn, automatically contains all available tweaks for you to choose from.
The "Animal Tweaks" resource pack, bundled with Spawn, automatically contains all available tweaks for you to choose from, go check the GitHub to see!

https://github.com/N1nn1/spawn/tree/update-2/src/main/resources/resourcepacks/animal_tweaks
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@
They are .txt files stored in the "minecraft/tweaks/" folder of resource packs,
each of them alters specific aspects of your game as long as Spawn is installed.
By including the desired tweaks in your resource pack, you can selectively activate features like model enhancements, animation freshen-ups and visual changes.
The "Animal Tweaks" resource pack, bundled with Spawn, automatically contains all available tweaks for you to choose from.
The "Animal Tweaks" resource pack, bundled with Spawn, automatically contains all available tweaks for you to choose from, go check the GitHub to see!

https://github.com/N1nn1/spawn/tree/update-2/src/main/resources/resourcepacks/animal_tweaks
1 change: 1 addition & 0 deletions src/main/resources/spawn.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"accessor.TropicalFishAccessor"
],
"client": [
"client.BatRendererMixin",
"client.BlockEntityWithoutLevelRendererMixin",
"client.ParrotOnShoulderLayerMixin",
"client.ParrotRendererMixin",
Expand Down

0 comments on commit 46be469

Please sign in to comment.