Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions develop/entities/custom-entities.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: Custom Entities
description: Learn how to do custom entities.
authors:
- JaaiDead
- Earthcomputer
---

# Custom Entities {#custom-entities}
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
package com.example.docs;

import com.example.docs.entity.CustomEntityModel;
import com.example.docs.entity.FabricDocsReferanceCustomEntity;
import com.example.docs.entity.CustomEntityRender;

import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.rendering.v1.EntityModelLayerRegistry;
import net.fabricmc.fabric.api.client.rendering.v1.EntityRendererRegistry;

import com.example.docs.entity.ModEntityTypes;
import com.example.docs.entity.model.ModEntityModelLayers;
import com.example.docs.entity.renderer.MiniGolemEntityRenderer;

public class FabricDocsCustomEntityClient implements ClientModInitializer {

@Override
public void onInitializeClient() {

EntityModelLayerRegistry.registerModelLayer(CustomEntityModel.CustomEntity, CustomEntityModel::getTexturedModelData);
EntityRendererRegistry.register(FabricDocsReferanceCustomEntity.CustomEntity, CustomEntityRender);
//TODO: Temp Need Help & Review
ModEntityModelLayers.registerModelLayers();
EntityRendererRegistry.register(ModEntityTypes.MINI_GOLEM, MiniGolemEntityRenderer::new);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.fabricmc.fabric.api.datagen.v1.provider.FabricLanguageProvider;

import com.example.docs.block.ModBlocks;
import com.example.docs.entity.ModEntityTypes;
import com.example.docs.item.ModItems;

// :::datagen-translations:provider
Expand Down Expand Up @@ -47,6 +48,8 @@ public void generateTranslations(RegistryWrapper.WrapperLookup wrapperLookup, Tr
translationBuilder.add("itemGroup.fabric_docs_reference", "Fabric Docs Reference");
translationBuilder.add("enchantment.fabric-docs-reference.thundering", "Thundering");

translationBuilder.add(ModEntityTypes.MINI_GOLEM, "Mini Golem");

translationBuilder.add(ModBlocks.CONDENSED_DIRT, "Condensed Dirt");
translationBuilder.add(ModBlocks.CONDENSED_OAK_LOG, "Condensed Oak Log");
translationBuilder.add(ModBlocks.COUNTER_BLOCK, "Counter Block");
Expand All @@ -58,6 +61,8 @@ public void generateTranslations(RegistryWrapper.WrapperLookup wrapperLookup, Tr
translationBuilder.add(ModBlocks.PRISMARINE_LAMP.asItem(), "Prismarine Lamp");
translationBuilder.add(ModBlocks.ENGINE_BLOCK.asItem(), "Engine Block");

translationBuilder.add(ModItems.MINI_GOLEM_SPAWN_EGG, "Mini Golem Spawn Egg");

translationBuilder.add(ModBlocks.STEEL_BLOCK, "Steel Block");
translationBuilder.add(ModBlocks.PIPE_BLOCK, "Pipe Block");
translationBuilder.add(ModBlocks.RUBY_BLOCK, "Ruby Block");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.example.docs.FabricDocsReference;
import com.example.docs.block.ModBlocks;
import com.example.docs.block.custom.VerticalSlabBlock;
import com.example.docs.item.ModItems;

// :::datagen-model:provider
public class FabricDocsReferenceModelProvider extends FabricModelProvider {
Expand Down Expand Up @@ -89,6 +90,8 @@ public void generateItemModels(ItemModelGenerator itemModelGenerator) {
//TODO Since I have little experience with generating item models, I will leave this to someone more experienced (Fellteros)

// :::datagen-model:provider

itemModelGenerator.registerSpawnEgg(ModItems.MINI_GOLEM_SPAWN_EGG, 0x00FF00, 0xFA4F4F);
}

// :::datagen-model:provider
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.example.docs.entity.animation;

import net.minecraft.client.render.entity.animation.Animation;
import net.minecraft.client.render.entity.animation.AnimationHelper;
import net.minecraft.client.render.entity.animation.Keyframe;
import net.minecraft.client.render.entity.animation.Transformation;
import net.minecraft.client.render.entity.model.EntityModelPartNames;

public class MiniGolemAnimations {
public static final Animation DANCING = Animation.Builder.create(1)
.looping()
.addBoneAnimation(EntityModelPartNames.HEAD, new Transformation(
Transformation.Targets.ROTATE,
new Keyframe(0, AnimationHelper.createRotationalVector(0, 0, 0), Transformation.Interpolations.LINEAR),
new Keyframe(0.2f, AnimationHelper.createRotationalVector(0, 0, 45), Transformation.Interpolations.LINEAR),
new Keyframe(0.4f, AnimationHelper.createRotationalVector(0, 0, 0), Transformation.Interpolations.LINEAR),
new Keyframe(0.6f, AnimationHelper.createRotationalVector(0, 0, 0), Transformation.Interpolations.LINEAR),
new Keyframe(0.8f, AnimationHelper.createRotationalVector(0, 0, -45), Transformation.Interpolations.LINEAR),
new Keyframe(1, AnimationHelper.createRotationalVector(0, 0, 0), Transformation.Interpolations.LINEAR)
))
.addBoneAnimation(EntityModelPartNames.LEFT_LEG, new Transformation(
Transformation.Targets.ROTATE,
new Keyframe(0, AnimationHelper.createRotationalVector(0, 0, 0), Transformation.Interpolations.LINEAR),
new Keyframe(0.2f, AnimationHelper.createRotationalVector(0, 0, 45), Transformation.Interpolations.LINEAR),
new Keyframe(0.4f, AnimationHelper.createRotationalVector(0, 0, 0), Transformation.Interpolations.LINEAR)
))
.addBoneAnimation(EntityModelPartNames.RIGHT_LEG, new Transformation(
Transformation.Targets.ROTATE,
new Keyframe(0.5f, AnimationHelper.createRotationalVector(0, 0, 0), Transformation.Interpolations.LINEAR),
new Keyframe(0.7f, AnimationHelper.createRotationalVector(0, 0, -45), Transformation.Interpolations.LINEAR),
new Keyframe(0.9f, AnimationHelper.createRotationalVector(0, 0, 0), Transformation.Interpolations.LINEAR)
))
.build();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.example.docs.entity.model;

import net.minecraft.client.model.ModelData;
import net.minecraft.client.model.ModelPart;
import net.minecraft.client.model.ModelPartBuilder;
import net.minecraft.client.model.ModelPartData;
import net.minecraft.client.model.ModelTransform;
import net.minecraft.client.model.TexturedModelData;
import net.minecraft.client.render.entity.model.EntityModel;
import net.minecraft.client.render.entity.model.EntityModelPartNames;
import net.minecraft.util.math.MathHelper;

import com.example.docs.entity.animation.MiniGolemAnimations;
import com.example.docs.entity.state.MiniGolemEntityRenderState;

public class MiniGolemEntityModel extends EntityModel<MiniGolemEntityRenderState> {
private final ModelPart head;
private final ModelPart leftLeg;
private final ModelPart rightLeg;

public MiniGolemEntityModel(ModelPart root) {
super(root);
head = root.getChild(EntityModelPartNames.HEAD);
leftLeg = root.getChild(EntityModelPartNames.LEFT_LEG);
rightLeg = root.getChild(EntityModelPartNames.RIGHT_LEG);
}

public static TexturedModelData getTexturedModelData() {
ModelData modelData = new ModelData();
ModelPartData root = modelData.getRoot();
root.addChild(
EntityModelPartNames.BODY,
ModelPartBuilder.create().cuboid(-6, -6, -6, 12, 12, 12),
ModelTransform.pivot(0, 8, 0)
);
root.addChild(
EntityModelPartNames.HEAD,
ModelPartBuilder.create().uv(36, 0).cuboid(-3, -6, -3, 6, 6, 6),
ModelTransform.pivot(0, 2, 0)
);
root.addChild(
EntityModelPartNames.LEFT_LEG,
ModelPartBuilder.create().uv(48, 12).cuboid(-2, 0, -2, 4, 10, 4),
ModelTransform.pivot(-2.5f, 14, 0)
);
root.addChild(
EntityModelPartNames.RIGHT_LEG,
ModelPartBuilder.create().uv(48, 12).cuboid(-2, 0, -2, 4, 10, 4),
ModelTransform.pivot(2.5f, 14, 0)
);
return TexturedModelData.of(modelData, 64, 32);
}

@Override
public void setAngles(MiniGolemEntityRenderState state) {
super.setAngles(state);

if (state.dancingAnimationState.isRunning()) {
this.animate(state.dancingAnimationState, MiniGolemAnimations.DANCING, state.age);
} else {
head.pitch = state.pitch * MathHelper.RADIANS_PER_DEGREE;
head.yaw = state.yawDegrees * MathHelper.RADIANS_PER_DEGREE;
float limbSwingAmplitude = state.limbAmplitudeMultiplier;
float limbSwingAnimationProgress = state.limbFrequency;
leftLeg.pitch = MathHelper.cos(limbSwingAnimationProgress * 0.2f + MathHelper.PI) * 1.4f * limbSwingAmplitude;
rightLeg.pitch = MathHelper.cos(limbSwingAnimationProgress * 0.2f) * 1.4f * limbSwingAmplitude;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.example.docs.entity.model;

import net.minecraft.client.render.entity.model.EntityModelLayer;
import net.minecraft.util.Identifier;

import net.fabricmc.fabric.api.client.rendering.v1.EntityModelLayerRegistry;

import com.example.docs.FabricDocsReference;

public class ModEntityModelLayers {
public static final EntityModelLayer MINI_GOLEM = createMain("mini_golem");

private static EntityModelLayer createMain(String name) {
return new EntityModelLayer(Identifier.of(FabricDocsReference.MOD_ID, name), "main");
}

public static void registerModelLayers() {
EntityModelLayerRegistry.registerModelLayer(ModEntityModelLayers.MINI_GOLEM, MiniGolemEntityModel::getTexturedModelData);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.example.docs.entity.renderer;

import net.minecraft.client.render.entity.EntityRendererFactory;
import net.minecraft.client.render.entity.MobEntityRenderer;
import net.minecraft.util.Identifier;

import com.example.docs.FabricDocsReference;
import com.example.docs.entity.MiniGolemEntity;
import com.example.docs.entity.model.MiniGolemEntityModel;
import com.example.docs.entity.model.ModEntityModelLayers;
import com.example.docs.entity.state.MiniGolemEntityRenderState;

public class MiniGolemEntityRenderer extends MobEntityRenderer<MiniGolemEntity, MiniGolemEntityRenderState, MiniGolemEntityModel> {
private static final Identifier TEXTURE = Identifier.of(FabricDocsReference.MOD_ID, "textures/entity/mini_golem.png");

public MiniGolemEntityRenderer(EntityRendererFactory.Context context) {
super(context, new MiniGolemEntityModel(context.getPart(ModEntityModelLayers.MINI_GOLEM)), 0.375f);
}

@Override
public MiniGolemEntityRenderState createRenderState() {
return new MiniGolemEntityRenderState();
}

@Override
public void updateRenderState(MiniGolemEntity entity, MiniGolemEntityRenderState state, float tickProgress) {
super.updateRenderState(entity, state, tickProgress);
state.dancingAnimationState.copyFrom(entity.dancingAnimationState);
}

@Override
public Identifier getTexture(MiniGolemEntityRenderState state) {
return TEXTURE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.docs.entity.state;

import net.minecraft.client.render.entity.state.LivingEntityRenderState;
import net.minecraft.entity.AnimationState;

public class MiniGolemEntityRenderState extends LivingEntityRenderState {
public final AnimationState dancingAnimationState = new AnimationState();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"model": {
"type": "minecraft:model",
"model": "minecraft:item/template_spawn_egg",
"tints": [
{
"type": "minecraft:constant",
"value": -16711936
},
{
"type": "minecraft:constant",
"value": -372913
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"death.attack.tater": "%1$s died from Tater damage!",
"effect.fabric-docs-reference.tater": "Tater",
"enchantment.fabric-docs-reference.thundering": "Thundering",
"entity.fabric-docs-reference.mini_golem": "Mini Golem",
"item.fabric-docs-reference.condensed_dirt": "Condensed Dirt",
"item.fabric-docs-reference.condensed_oak_log": "Condensed Oak Log",
"item.fabric-docs-reference.counter": "Counter",
Expand All @@ -28,6 +29,7 @@
"item.fabric-docs-reference.guidite_leggings": "Guidite Leggings",
"item.fabric-docs-reference.guidite_sword": "Guidite Sword",
"item.fabric-docs-reference.lightning_stick": "Lightning Stick",
"item.fabric-docs-reference.mini_golem_spawn_egg": "Mini Golem Spawn Egg",
"item.fabric-docs-reference.poisonous_apple": "Poisonous Apple",
"item.fabric-docs-reference.prismarine_lamp": "Prismarine Lamp",
"item.fabric-docs-reference.suspicious_substance": "Suspicious Substance",
Expand Down

This file was deleted.

Loading