Skip to content

Commit

Permalink
tweak rendering code
Browse files Browse the repository at this point in the history
Signed-off-by: unilock <[email protected]>
  • Loading branch information
unilock committed Feb 3, 2025
1 parent 97af8db commit ea30dbd
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void onInitializeClient() {
BuiltinItemRendererRegistry.INSTANCE.register(ModItems.RAT_MASTER_MASK, inventoryItemRenderer);
ModelLoadingPlugin.register(pluginContext -> {
pluginContext.addModels(new ModelIdentifier(itemId, "inventory"));
pluginContext.addModels(new ModelIdentifier(new Identifier(itemId.getNamespace(), itemId.getPath() + "_worn"), "inventory"));
pluginContext.addModels(new ModelIdentifier(itemId.withSuffixedPath("_worn"), "inventory"));
});

// model predicates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ public Identifier getAnimationResource(RatEntity rat) {
public void setCustomAnimations(RatEntity ratEntity, long instanceId, AnimationState<RatEntity> animationState) {
super.setCustomAnimations(ratEntity, instanceId, animationState);

CoreGeoBone head = this.getAnimationProcessor().getBone("head");
CoreGeoBone leftEar = this.getAnimationProcessor().getBone("leftear");
CoreGeoBone rightEar = this.getAnimationProcessor().getBone("rightear");
if (!(ratEntity.isSniffing() || ratEntity.isEating() || ratEntity.isFlying())) {
CoreGeoBone head = this.getAnimationProcessor().getBone("head");
CoreGeoBone leftEar = this.getAnimationProcessor().getBone("leftear");
CoreGeoBone rightEar = this.getAnimationProcessor().getBone("rightear");

if (head != null && !ratEntity.isSniffing() && !ratEntity.isEating() && !ratEntity.isFlying()) {
head.setRotX(MathHelper.clamp(-ratEntity.getPitch(), 0, 90) * ((float) Math.PI / 180F));
leftEar.setRotX(MathHelper.clamp(ratEntity.getPitch(), -90, 0) * 1.4f * ((float) Math.PI / 180F));
rightEar.setRotX(MathHelper.clamp(ratEntity.getPitch(), -90, 0) * 1.4f * ((float) Math.PI / 180F));
Expand All @@ -52,14 +52,5 @@ public void setCustomAnimations(RatEntity ratEntity, long instanceId, AnimationS
tail.setRotX((float) (-45 * Math.PI / 180));
tailend.setRotX((float) (-30 * Math.PI / 180));
}

if (ratEntity.isBaby()) {
CoreGeoBone root = this.getAnimationProcessor().getBone("root");
if (root != null) {
root.setScaleX(0.5f);
root.setScaleY(0.5f);
root.setScaleZ(0.5f);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DyeColor;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RotationAxis;
import net.minecraft.util.math.Vec3d;
Expand All @@ -22,11 +21,6 @@
import software.bernie.geckolib.renderer.GeoEntityRenderer;

public class RatEntityRenderer extends GeoEntityRenderer<RatEntity> {
// variables needed for later
private ItemStack itemStack;
private VertexConsumerProvider vertexConsumerProvider;
private Identifier ratTexture;

public RatEntityRenderer(EntityRendererFactory.Context context) {
super(context, new RatEntityModel());
this.shadowRadius = 0.35f;
Expand All @@ -53,31 +47,30 @@ public void render(RatEntity ratEntity, float entityYaw, float partialTick, Matr
}

@Override
public void preRender(MatrixStack poseStack, RatEntity ratEntity, BakedGeoModel model, VertexConsumerProvider vertexConsumerProvider, VertexConsumer buffer, boolean isReRender, float partialTick, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) {
this.itemStack = ratEntity.isSitting() || ratEntity.isSneaking() ? ItemStack.EMPTY : ratEntity.getEquippedStack(EquipmentSlot.MAINHAND);
this.vertexConsumerProvider = vertexConsumerProvider;
this.ratTexture = this.getTexture(ratEntity);

super.preRender(poseStack, ratEntity, model, vertexConsumerProvider, buffer, isReRender, partialTick, packedLight, packedOverlay, red, green, blue, alpha);
}

@Override
public void renderRecursively(MatrixStack stack, RatEntity animatable, GeoBone bone, RenderLayer renderType, VertexConsumerProvider bufferSourceIn, VertexConsumer bufferIn, boolean isReRender, float partialTick, int packedLightIn, int packedOverlayIn, float red, float green, float blue, float alpha) {
if (bone.getName().equals("bodybone")) {
stack.push();
stack.multiply(RotationAxis.POSITIVE_X.rotationDegrees(-90));
stack.translate(bone.getPosX(), bone.getPosZ(), bone.getPosY() - 0.05);
stack.scale(0.7f, 0.7f, 0.7f);
stack.multiply(new Quaternionf(bone.getRotX(), bone.getRotZ(), bone.getRotY(), 1.0F));
public void renderRecursively(MatrixStack poseStack, RatEntity animatable, GeoBone bone, RenderLayer renderType, VertexConsumerProvider bufferSource, VertexConsumer buffer, boolean isReRender, float partialTick, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) {
if (bone.getName().equals("bodybone") && !(animatable.isSitting() || animatable.isSneaking())) {
ItemStack itemStack = animatable.getEquippedStack(EquipmentSlot.MAINHAND);
if (!itemStack.isEmpty()) {
poseStack.push();
poseStack.multiply(RotationAxis.POSITIVE_X.rotationDegrees(-90));
poseStack.translate(bone.getPosX(), bone.getPosZ(), bone.getPosY() - 0.05);
poseStack.scale(0.7f, 0.7f, 0.7f);
poseStack.multiply(new Quaternionf(bone.getRotX(), bone.getRotZ(), bone.getRotY(), 1.0F));

MinecraftClient.getInstance().getItemRenderer().renderItem(this.itemStack, ModelTransformationMode.THIRD_PERSON_RIGHT_HAND, packedLightIn, packedOverlayIn, stack, this.vertexConsumerProvider, animatable.getWorld(), 0);
stack.pop();
MinecraftClient.getInstance().getItemRenderer().renderItem(itemStack, ModelTransformationMode.THIRD_PERSON_RIGHT_HAND, packedLight, packedOverlay, poseStack, bufferSource, animatable.getWorld(), 0);
poseStack.pop();

// restore the render buffer - GeckoLib expects this state otherwise you'll have weird texture issues
bufferIn = this.vertexConsumerProvider.getBuffer(RenderLayer.getEntityCutout(this.ratTexture));
// restore the render buffer - GeckoLib expects this state otherwise you'll have weird texture issues
buffer = bufferSource.getBuffer(RenderLayer.getEntityCutout(this.getTexture(animatable)));
}
}

super.renderRecursively(stack, animatable, bone, renderType, bufferSourceIn, bufferIn, isReRender, partialTick, packedLightIn, packedOverlayIn, red, green, blue, alpha);
super.renderRecursively(poseStack, animatable, bone, renderType, bufferSource, buffer, isReRender, partialTick, packedLight, packedOverlay, red, green, blue, alpha);
}

@Override
public void scaleModelForRender(float widthScale, float heightScale, MatrixStack poseStack, RatEntity animatable, BakedGeoModel model, boolean isReRender, float partialTick, int packedLight, int packedOverlay) {
super.scaleModelForRender(animatable.isBaby() ? widthScale / 2 : widthScale, animatable.isBaby() ? heightScale / 2 : heightScale, poseStack, animatable, model, isReRender, partialTick, packedLight, packedOverlay);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public CompletableFuture<Void> reload(Synchronizer synchronizer, ResourceManager
final MinecraftClient client = MinecraftClient.getInstance();
this.itemRenderer = client.getItemRenderer();
this.inventoryModel = client.getBakedModelManager().getModel(new ModelIdentifier(this.itemId, "inventory"));
this.wornModel = client.getBakedModelManager().getModel(new ModelIdentifier(new Identifier(this.itemId.getNamespace(), this.itemId.getPath() + "_worn"), "inventory"));
this.wornModel = client.getBakedModelManager().getModel(new ModelIdentifier(this.itemId.withSuffixedPath("_worn"), "inventory"));
applyProfiler.pop();
applyProfiler.endTick();
}, applyExecutor);
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "RAT's Mischief",
"description": "Adds rats to Minecraft: smart, versatile and adorable pets!",
"authors": [
"doctor4t"
"doctor4t (Author)"
],
"contributors": [
"AmyMialee (Programmer)",
Expand Down

0 comments on commit ea30dbd

Please sign in to comment.