Skip to content

Commit

Permalink
Hamster progress
Browse files Browse the repository at this point in the history
  • Loading branch information
crispytwig committed Oct 24, 2024
1 parent 2f5f363 commit 05e1cf1
Show file tree
Hide file tree
Showing 18 changed files with 792 additions and 72 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
package com.starfish_studios.hamsters;

import com.starfish_studios.hamsters.block.CagePanelBlock;
import com.starfish_studios.hamsters.client.model.shoulder.LeftSittingHamsterModel;
import com.starfish_studios.hamsters.client.renderer.*;
import com.starfish_studios.hamsters.registry.HamstersBlocks;
import com.starfish_studios.hamsters.registry.HamstersEntityType;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.fabricmc.fabric.api.client.rendering.v1.EntityModelLayerRegistry;
import net.fabricmc.fabric.api.client.rendering.v1.EntityRendererRegistry;
import net.minecraft.client.model.geom.ModelLayerLocation;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;

import java.util.function.Supplier;

public class HamstersVanillaIntegration {
public static final ModelLayerLocation HAMSTER_LAYER = new ModelLayerLocation(new ResourceLocation(Hamsters.MOD_ID, "sitting_hamster"), "main");


public static void serverInit() {
Expand All @@ -38,6 +42,8 @@ private static void registerModelLayers() {
EntityRendererRegistry.register(HamstersEntityType.HAMSTER, HamsterRenderer::new);
EntityRendererRegistry.register(HamstersEntityType.HAMSTER_NEW, HamsterNewRenderer::new);
EntityRendererRegistry.register(HamstersEntityType.HAMSTER_BALL, HamsterBallRenderer::new);

EntityModelLayerRegistry.registerModelLayer(HAMSTER_LAYER, LeftSittingHamsterModel::createBodyLayer);
}

private static void registerBlockRenderLayers() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
package com.starfish_studios.hamsters.client.model;

import com.google.common.collect.Maps;
import com.starfish_studios.hamsters.Hamsters;
import com.starfish_studios.hamsters.block.entity.HamsterWheelBlockEntity;
import com.starfish_studios.hamsters.entity.Hamster;
import net.minecraft.Util;
import com.starfish_studios.hamsters.entity.HamsterNew;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.resources.ResourceLocation;
import org.apache.logging.log4j.core.appender.ScriptAppenderSelector;
import software.bernie.geckolib.core.animatable.model.CoreGeoBone;
import software.bernie.geckolib.core.animation.AnimationState;
import software.bernie.geckolib.model.DefaultedEntityGeoModel;

import java.util.Map;

import static com.starfish_studios.hamsters.Hamsters.MOD_ID;

public class HamsterModel extends DefaultedEntityGeoModel<Hamster> {
Expand All @@ -24,23 +18,63 @@ public HamsterModel() {

@Override
public ResourceLocation getModelResource(Hamster animatable) {
return animatable.isBaby() ? new ResourceLocation(MOD_ID, "geo/entity/pinkie.geo.json") : new ResourceLocation(MOD_ID, "geo/entity/hamster.geo.json");
// return animatable.isBaby() ? new ResourceLocation(MOD_ID, "geo/entity/pinkie.geo.json") : new ResourceLocation(MOD_ID, "geo/entity/hamster.geo.json");
return new ResourceLocation(MOD_ID, "geo/entity/hamster.geo.json");
}

public static ResourceLocation getVariantTexture2(HamsterNew.Variant variant) {
ResourceLocation resourceLocation;
switch (variant) {
case WHITE -> resourceLocation = new ResourceLocation(MOD_ID, "textures/entity/hamster/white.png");
case CREAM -> resourceLocation = new ResourceLocation(MOD_ID, "textures/entity/hamster/cream.png");
case CHAMPAGNE -> resourceLocation = new ResourceLocation(MOD_ID, "textures/entity/hamster/champagne.png");
case SILVER_DOVE -> resourceLocation = new ResourceLocation(MOD_ID, "textures/entity/hamster/silver_dove.png");
case DOVE -> resourceLocation = new ResourceLocation(MOD_ID, "textures/entity/hamster/dove.png");
case CHOCOLATE -> resourceLocation = new ResourceLocation(MOD_ID, "textures/entity/hamster/chocolate.png");
case BLACK -> resourceLocation = new ResourceLocation(MOD_ID, "textures/entity/hamster/black.png");
case WILD -> resourceLocation = new ResourceLocation(MOD_ID, "textures/entity/hamster/wild.png");
default -> throw new IllegalStateException("Unexpected value: " + variant);
}
return resourceLocation;
}

public static ResourceLocation getVariantTexture(HamsterNew.Variant variant, HamsterNew.Marking marking) {
ResourceLocation resourceLocation;
switch (variant) {
case WHITE -> resourceLocation = new ResourceLocation(MOD_ID, "textures/entity/hamster/white.png");
case CREAM -> resourceLocation = new ResourceLocation(MOD_ID, "textures/entity/hamster/cream.png");
case CHAMPAGNE -> resourceLocation = new ResourceLocation(MOD_ID, "textures/entity/hamster/champagne.png");
case SILVER_DOVE -> resourceLocation = new ResourceLocation(MOD_ID, "textures/entity/hamster/silver_dove.png");
case DOVE -> resourceLocation = new ResourceLocation(MOD_ID, "textures/entity/hamster/dove.png");
case CHOCOLATE -> resourceLocation = new ResourceLocation(MOD_ID, "textures/entity/hamster/chocolate.png");
case BLACK -> resourceLocation = new ResourceLocation(MOD_ID, "textures/entity/hamster/black.png");
case WILD -> resourceLocation = new ResourceLocation(MOD_ID, "textures/entity/hamster/wild.png");
default -> throw new IllegalStateException("Unexpected value: " + variant);
}
switch (marking) {
case BLANK -> resourceLocation = new ResourceLocation(MOD_ID, "textures/entity/hamster/blank.png");
case BANDED -> resourceLocation = new ResourceLocation(MOD_ID, "textures/entity/hamster/banded.png");
case DOMINANT_SPOTS -> resourceLocation = new ResourceLocation(MOD_ID, "textures/entity/hamster/dominant_spots.png");
case ROAN -> resourceLocation = new ResourceLocation(MOD_ID, "textures/entity/hamster/roan.png");
case BELLY -> resourceLocation = new ResourceLocation(MOD_ID, "textures/entity/hamster/belly.png");
}
return resourceLocation;
}

@Override
public ResourceLocation getTextureResource(Hamster animatable) {
if (animatable.isBaby()) {
return new ResourceLocation(MOD_ID, "textures/entity/hamster/pinkie.png");
}
return switch (animatable.getVariant()) {
case 0 -> new ResourceLocation(MOD_ID, "textures/entity/hamster/white.png");
case 1 -> new ResourceLocation(MOD_ID, "textures/entity/hamster/cream.png");
case 2 -> new ResourceLocation(MOD_ID, "textures/entity/hamster/champagne.png");
case 3 -> new ResourceLocation(MOD_ID, "textures/entity/hamster/silver_dove.png");
case 4 -> new ResourceLocation(MOD_ID, "textures/entity/hamster/dove.png");
case 5 -> new ResourceLocation(MOD_ID, "textures/entity/hamster/chocolate.png");
case 6 -> new ResourceLocation(MOD_ID, "textures/entity/hamster/black.png");
default -> throw new IllegalStateException("Unexpected value: " + animatable.getVariant());
return switch (HamsterNew.Variant.getTypeById(animatable.getVariant())) {
case WHITE -> new ResourceLocation(MOD_ID, "textures/entity/hamster/white.png");
case CREAM -> new ResourceLocation(MOD_ID, "textures/entity/hamster/cream.png");
case CHAMPAGNE -> new ResourceLocation(MOD_ID, "textures/entity/hamster/champagne.png");
case SILVER_DOVE -> new ResourceLocation(MOD_ID, "textures/entity/hamster/silver_dove.png");
case DOVE -> new ResourceLocation(MOD_ID, "textures/entity/hamster/dove.png");
case CHOCOLATE -> new ResourceLocation(MOD_ID, "textures/entity/hamster/chocolate.png");
case BLACK -> new ResourceLocation(MOD_ID, "textures/entity/hamster/black.png");
default -> new ResourceLocation(MOD_ID, "textures/entity/hamster/wild.png");
};
}

Expand All @@ -51,7 +85,7 @@ public ResourceLocation getAnimationResource(Hamster animatable) {

@Override
public RenderType getRenderType(Hamster animatable, ResourceLocation texture) {
return RenderType.entitySolid(texture);
return RenderType.entityCutoutNoCull(texture);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.starfish_studios.hamsters.entity.HamsterNew;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.resources.ResourceLocation;
import org.apache.logging.log4j.core.appender.ScriptAppenderSelector;
import software.bernie.geckolib.core.animatable.model.CoreGeoBone;
import software.bernie.geckolib.core.animation.AnimationState;
import software.bernie.geckolib.model.DefaultedEntityGeoModel;
Expand All @@ -17,14 +18,15 @@ public HamsterNewModel() {

@Override
public ResourceLocation getModelResource(HamsterNew animatable) {
return animatable.isBaby() ? new ResourceLocation(MOD_ID, "geo/entity/pinkie.geo.json") : new ResourceLocation(MOD_ID, "geo/entity/hamster.geo.json");
// return animatable.isBaby() ? new ResourceLocation(MOD_ID, "geo/entity/pinkie.geo.json") : new ResourceLocation(MOD_ID, "geo/entity/hamster.geo.json");
return new ResourceLocation(MOD_ID, "geo/entity/hamster.geo.json");
}

@Override
public ResourceLocation getTextureResource(HamsterNew animatable) {
if (animatable.isBaby()) {
return new ResourceLocation(MOD_ID, "textures/entity/hamster/pinkie.png");
}
// if (animatable.isBaby()) {
// return new ResourceLocation(MOD_ID, "textures/entity/hamster/pinkie.png");
// }
return switch (animatable.getVariant()) {
case 0 -> new ResourceLocation(MOD_ID, "textures/entity/hamster/white.png");
case 1 -> new ResourceLocation(MOD_ID, "textures/entity/hamster/cream.png");
Expand All @@ -33,6 +35,7 @@ public ResourceLocation getTextureResource(HamsterNew animatable) {
case 4 -> new ResourceLocation(MOD_ID, "textures/entity/hamster/dove.png");
case 5 -> new ResourceLocation(MOD_ID, "textures/entity/hamster/chocolate.png");
case 6 -> new ResourceLocation(MOD_ID, "textures/entity/hamster/black.png");
case 7 -> new ResourceLocation(MOD_ID, "textures/entity/hamster/wild.png");
default -> throw new IllegalStateException("Unexpected value: " + animatable.getVariant());
};
}
Expand All @@ -44,20 +47,38 @@ public ResourceLocation getAnimationResource(HamsterNew animatable) {

@Override
public RenderType getRenderType(HamsterNew animatable, ResourceLocation texture) {
return RenderType.entitySolid(texture);
return RenderType.entityCutoutNoCull(texture);
}

@Override
public void setCustomAnimations(HamsterNew animatable, long instanceId, AnimationState<HamsterNew> animationState) {
super.setCustomAnimations(animatable, instanceId, animationState);

if (animationState == null) return;
CoreGeoBone root = this.getAnimationProcessor().getBone("root");
CoreGeoBone head = this.getAnimationProcessor().getBone("head");
CoreGeoBone sleep = this.getAnimationProcessor().getBone("sleep");
CoreGeoBone cheeks = this.getAnimationProcessor().getBone("cheeks");
CoreGeoBone leftCheek = this.getAnimationProcessor().getBone("leftCheek");
CoreGeoBone rightCheek = this.getAnimationProcessor().getBone("rightCheek");

cheeks.setHidden(animatable.getMainHandItem().isEmpty());

if (animatable.getCheekLevel() > 0) {
cheeks.setHidden(false);
leftCheek.setScaleX(1.0F + (animatable.getCheekLevel() * 0.2F)); leftCheek.setScaleY(1.0F + (animatable.getCheekLevel() * 0.2F)); leftCheek.setScaleZ(1.0F + (animatable.getCheekLevel() * 0.2F));
rightCheek.setScaleX(1.0F + (animatable.getCheekLevel() * 0.2F)); rightCheek.setScaleY(1.0F + (animatable.getCheekLevel() * 0.2F)); rightCheek.setScaleZ(1.0F + (animatable.getCheekLevel() * 0.2F));
} else {
cheeks.setScaleX(1.0F);
cheeks.setScaleY(1.0F);
cheeks.setScaleZ(1.0F);
}

if (animatable.getCheekLevel() > 1) {
root.setRotZ((float) Math.sin(System.currentTimeMillis() * 0.05) * 0.1F * (animatable.getCheekLevel() * 0.05F));

}


// Ensures there are no strange eye glitches when the hamster is sleeping or awake.
if (animatable.isSleeping() && !animatable.isBaby()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package com.starfish_studios.hamsters.client.model.shoulder;


import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.starfish_studios.hamsters.entity.HamsterNew;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.model.EntityModel;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.model.geom.PartPose;
import net.minecraft.client.model.geom.builders.*;

public class LeftSittingHamsterModel<T extends HamsterNew> extends EntityModel<T> {
private final ModelPart root;
private final ModelPart body;
private final ModelPart headRot;
private final ModelPart head;
private final ModelPart armorBipedHead;
private final ModelPart rightEar;
private final ModelPart leftEar;
private final ModelPart cheeks;
private final ModelPart sleep;
private final ModelPart tail;
private final ModelPart rightHand;
private final ModelPart leftHand;
private final ModelPart legs;
private final ModelPart leftFoot;
private final ModelPart rightFoot;

public LeftSittingHamsterModel(ModelPart modelPart) {
this.root = modelPart;
this.body = modelPart.getChild("body");
this.headRot = this.body.getChild("headRot");
this.head = this.headRot.getChild("head");
this.armorBipedHead = this.head.getChild("armorBipedHead");
this.rightEar = this.head.getChild("rightEar");
this.leftEar = this.head.getChild("leftEar");
this.cheeks = this.head.getChild("cheeks");
this.sleep = this.head.getChild("sleep");
this.tail = this.body.getChild("tail");
this.rightHand = this.body.getChild("rightHand");
this.leftHand = this.body.getChild("leftHand");
this.legs = modelPart.getChild("legs");
this.leftFoot = this.legs.getChild("leftFoot");
this.rightFoot = this.legs.getChild("rightFoot");
}

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

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

PartDefinition body = root.addOrReplaceChild("body", CubeListBuilder.create().texOffs(0, 0).addBox(-3.0F, -3.0F, -5.0F, 6.0F, 4.0F, 6.0F, new CubeDeformation(0.01F)), PartPose.offsetAndRotation(0.0F, -0.5F, 3.0F, -0.9599F, 0.0F, 0.0F));

PartDefinition headRot = body.addOrReplaceChild("headRot", CubeListBuilder.create(), PartPose.offsetAndRotation(-0.5F, -2.0F, -4.5F, 0.9599F, 0.0F, 0.0F));

PartDefinition head = headRot.addOrReplaceChild("head", CubeListBuilder.create(), PartPose.offset(0.0F, 0.0F, 0.0F));

PartDefinition armorBipedHead = head.addOrReplaceChild("armorBipedHead", CubeListBuilder.create().texOffs(1, 11).addBox(-2.5F, -4.0F, -2.0F, 5.0F, 4.0F, 4.0F, new CubeDeformation(0.0F)), PartPose.offset(0.5F, 1.5F, -2.0F));

PartDefinition rightEar = head.addOrReplaceChild("rightEar", CubeListBuilder.create().texOffs(0, 11).mirror().addBox(-2.0F, -2.0F, 0.0F, 2.0F, 2.0F, 0.0F, new CubeDeformation(0.01F)).mirror(false), PartPose.offset(-1.0F, -1.5F, -2.0F));

PartDefinition leftEar = head.addOrReplaceChild("leftEar", CubeListBuilder.create().texOffs(0, 11).addBox(0.0F, -2.0F, 0.0F, 2.0F, 2.0F, 0.0F, new CubeDeformation(0.01F)), PartPose.offset(2.0F, -1.5F, -2.0F));

PartDefinition cheeks = head.addOrReplaceChild("cheeks", CubeListBuilder.create().texOffs(20, 13).addBox(7.0F, -1.5F, -2.0F, 2.0F, 3.0F, 3.0F, new CubeDeformation(0.0F))
.texOffs(20, 13).mirror().addBox(0.0F, -1.5F, -2.0F, 2.0F, 3.0F, 3.0F, new CubeDeformation(0.0F)).mirror(false), PartPose.offset(-4.0F, 0.0F, -2.0F));

PartDefinition sleep = head.addOrReplaceChild("sleep", CubeListBuilder.create(), PartPose.offset(0.5F, 2.5F, 0.0F));

PartDefinition tail = body.addOrReplaceChild("tail", CubeListBuilder.create().texOffs(19, 0).addBox(-1.0F, 0.0F, 0.0F, 2.0F, 1.0F, 1.0F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, -3.0F, 1.0F));

PartDefinition rightHand = body.addOrReplaceChild("rightHand", CubeListBuilder.create().texOffs(24, 2).mirror().addBox(-1.0F, 0.0F, -1.0F, 2.0F, 1.0F, 2.0F, new CubeDeformation(0.0F)).mirror(false), PartPose.offsetAndRotation(-1.5F, 1.5F, -3.5F, 2.3126F, 0.2618F, 0.0565F));

PartDefinition leftHand = body.addOrReplaceChild("leftHand", CubeListBuilder.create().texOffs(24, 2).addBox(-1.0F, 0.0F, -1.0F, 2.0F, 1.0F, 2.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(1.5F, 1.5F, -3.5F, 2.3126F, -0.2618F, -0.0698F));

PartDefinition legs = root.addOrReplaceChild("legs", CubeListBuilder.create(), PartPose.offset(1.5F, -1.0F, -1.0F));

PartDefinition leftFoot = legs.addOrReplaceChild("leftFoot", CubeListBuilder.create().texOffs(24, 2).addBox(-1.0F, 0.0F, -1.0F, 2.0F, 1.0F, 2.0F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, 0.0F, 3.0F));

PartDefinition rightFoot = legs.addOrReplaceChild("rightFoot", CubeListBuilder.create().texOffs(24, 2).mirror().addBox(-1.0F, 0.0F, -1.0F, 2.0F, 1.0F, 2.0F, new CubeDeformation(0.0F)).mirror(false), PartPose.offset(-3.0F, 0.0F, 3.0F));

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

public void renderOnShoulder(PoseStack poseStack, VertexConsumer vertexConsumer, int i, int j, float f, float g, float h, float k, int l) {
this.setupAnim(State.ON_SHOULDER, l, f, g, 0.0F, h, k);
this.root.render(poseStack, vertexConsumer, i, j);
}

private void setupAnim(State state, int i, float f, float g, float h, float j, float k) {
this.head.xRot = k * 0.017453292F;
this.head.yRot = j * 0.017453292F;
}

@Override
public void renderToBuffer(PoseStack poseStack, VertexConsumer vertexConsumer, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) {
root.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha);
}

@Override
public void setupAnim(T entity, float f, float g, float h, float i, float j) {
this.setupAnim(State.ON_SHOULDER, entity.tickCount, f, g, h, i, j);
}

@Environment(EnvType.CLIENT)
public enum State {
ON_SHOULDER;
}
}
Loading

0 comments on commit 05e1cf1

Please sign in to comment.