tutorial:entity
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
tutorial:entity [2021/07/15 18:41] – [Registering Entity Renderer] Updating the page for recent versions. logdawg970 | tutorial:entity [2021/08/17 15:24] – fix parameters for render method idontcare | ||
---|---|---|---|
Line 151: | Line 151: | ||
return new CubeEntityRenderer(context); | return new CubeEntityRenderer(context); | ||
}); | }); | ||
+ | EntityModelLayerRegistry.registerModelLayer(MODEL_CUBE_LAYER, | ||
} | } | ||
} | } | ||
Line 161: | Line 162: | ||
Standard models define " | Standard models define " | ||
- | initialize them in the constructor, | + | initialize them in the constructor, obtain data in the '' |
Note that '' | Note that '' | ||
- | |||
- | '' | ||
- | * the current model instance | ||
- | * textureOffsetU as an '' | ||
- | * textureOffsetV as an '' | ||
- | |||
- | Texture offsets provide the location of the model' | ||
- | Our entity is a single cube, so the base '' | ||
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
Line 177: | Line 170: | ||
private final ModelPart base; | private final ModelPart base; | ||
- | public CubeEntityModel() { | + | public CubeEntityModel(ModelPart modelPart) { |
- | base = new ModelPart(this, 0, 0); | + | |
} | } | ||
| | ||
Line 185: | Line 178: | ||
</ | </ | ||
- | After creating a part, we need to add a shape to it. | + | After creating a part, we need to add a shape to it. |
+ | To do so, we must add a child to the root. The texture location for the new part is located in '' | ||
+ | the offset for it is located in the first 3 numbers of '' | ||
Note that the origin of a model starts at the corner, so you will need to offset the part to center it: | Note that the origin of a model starts at the corner, so you will need to offset the part to center it: | ||
Line 194: | Line 189: | ||
public CubeEntityModel() { | public CubeEntityModel() { | ||
- | | + | |
- | base.addCuboid(-6, | + | |
} | } | ||
| | ||
- | | + | |
- | } | + | ModelData modelData = new ModelData(); |
+ | ModelPartData modelPartData = modelData.getRoot(); | ||
+ | modelPartData.addChild(EntityModelPartNames.CUBE, | ||
+ | } | ||
</ | </ | ||
Line 213: | Line 210: | ||
| | ||
public CubeEntityModel() [...] | public CubeEntityModel() [...] | ||
+ | | ||
+ | public static TexturedModelData getTexturedModelData() [...] | ||
@Override | @Override | ||
public void setAngles(CubeEntity entity, float limbAngle, float limbDistance, | public void setAngles(CubeEntity entity, float limbAngle, float limbDistance, | ||
- | |||
} | } | ||
@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) { | ||
- | | + | |
- | matrices.translate(0, 1.125, 0); | + | |
- | + | }); | |
- | // render cube | + | |
- | base.render(matrices, | + | |
} | } | ||
} | } | ||
Line 231: | Line 227: | ||
To complete our model, we need to add a texture file. The default texture size is 64 wide and 32 tall; | To complete our model, we need to add a texture file. The default texture size is 64 wide and 32 tall; | ||
- | you can change this by changing '' | + | you can change this by adding a return of your texturedModelData |
We will set it to 64x64 for our texture: | We will set it to 64x64 for our texture: | ||
Line 241: | Line 237: | ||
private final ModelPart base; | private final ModelPart base; | ||
- | public | + | |
- | this.textureHeight = 64; | + | |
- | this.textureWidth = 64; | + | |
- | + | ||
[...] | [...] | ||
+ | return TexturedModelData.of(modelData, | ||
} | } | ||
Line 254: | Line 250: | ||
===== Spawning your Entity ===== | ===== Spawning your Entity ===== | ||
+ | Be sure to add your client entrypoint to fabric.mod.json. | ||
+ | You can do this like so: | ||
+ | <code json> | ||
+ | |||
+ | " | ||
+ | " | ||
+ | " | ||
+ | ], | ||
+ | " | ||
+ | " | ||
+ | ] | ||
+ | }, | ||
+ | </ | ||
You can spawn your entity by typing ''/ | You can spawn your entity by typing ''/ | ||
{{https:// | {{https:// |
tutorial/entity.txt · Last modified: 2024/04/30 20:42 by ryhon