Jump to content

Set a new power layer to a new entity (like the field around charged creeper)


Recommended Posts


I was wondering how could I create a field around a new entity I called "Cubos" (it looks like a cube walking with two wooden legs. I know that the charged creeper (or "Wither" when it has only half his health points left) uses the file CreeperPowerLayer extending EnergySwirlLayer.

Here is the file I created "CubosPowerLayer" :

package fr.vat1n.vatmod.client.renderer.layers;

import fr.vat1n.vatmod.client.renderer.model.CubosModel;
import fr.vat1n.vatmod.entity.common.Cubos;
import net.minecraft.client.model.EntityModel;
import net.minecraft.client.model.geom.EntityModelSet;
import net.minecraft.client.model.geom.ModelLayers;
import net.minecraft.client.renderer.entity.RenderLayerParent;
import net.minecraft.client.renderer.entity.layers.EnergySwirlLayer;
import net.minecraft.resources.ResourceLocation;

public class CubosPowerLayer extends EnergySwirlLayer<Cubos, CubosModel<Cubos>> {
    private static final ResourceLocation POWER_LOCATION = new ResourceLocation("textures/entity/creeper/creeper_armor.png");
    private final CubosModel<Cubos> model;

    public CubosPowerLayer(RenderLayerParent<Cubos, CubosModel<Cubos>> renderLayerParent, EntityModelSet entityModelSet) {
        this.model = new CubosModel<>(entityModelSet.bakeLayer(ModelLayers.CREEPER_ARMOR));

    protected float xOffset(float xOffset) {
        return xOffset * 0.01F;

    protected ResourceLocation getTextureLocation() {
        return POWER_LOCATION;

    protected EntityModel<Cubos> model() {
        return this.model;

As you can see, in the constructor, I use the bakeLayer method for the CREEPER_ARMOR since I don't know how and where to create the same for the cubos.


And here is the CubosRenderer :

package fr.vat1n.vatmod.client.renderer;

import fr.vat1n.vatmod.VatMod;
import fr.vat1n.vatmod.client.renderer.layers.CubosPowerLayer;
import fr.vat1n.vatmod.client.renderer.model.CubosModel;
import fr.vat1n.vatmod.entity.common.Cubos;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.client.renderer.entity.MobRenderer;
import net.minecraft.resources.ResourceLocation;

public class CubosRenderer extends MobRenderer<Cubos, CubosModel<Cubos>> {
    private static final ResourceLocation TEXTURE = new ResourceLocation(VatMod.MOD_ID, "textures/entities/cubos.png");

    public CubosRenderer(EntityRendererProvider.Context context) {
        super(context, new CubosModel<>(context.bakeLayer(CubosModel.LAYER_LOCATION)), 0.5F);
        this.addLayer(new CubosPowerLayer(this, context.getModelSet()));

    public ResourceLocation getTextureLocation(Cubos pEntity) {
        return TEXTURE;

Finally, here is the CubosModel :

package fr.vat1n.vatmod.client.renderer.model;

import com.google.common.collect.ImmutableList;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import fr.vat1n.vatmod.VatMod;
import fr.vat1n.vatmod.entity.common.Cubos;
import net.minecraft.client.model.AgeableListModel;
import net.minecraft.client.model.geom.ModelLayerLocation;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.model.geom.PartPose;
import net.minecraft.client.model.geom.builders.*;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;

public class CubosModel<Type extends Cubos> extends AgeableListModel<Type> {
	public static final ModelLayerLocation LAYER_LOCATION = new ModelLayerLocation(new ResourceLocation(VatMod.MOD_ID, "cubos"), "main");
	private final ModelPart legL;
	private final ModelPart legR;
	private final ModelPart head;
	private final ModelPart root;

	public CubosModel(ModelPart root) {
		this.root = root;
		this.legL = root.getChild("legL");
		this.legR = root.getChild("legR");
		this.head = root.getChild("head");

	public static LayerDefinition createBodyLayer() {
		MeshDefinition meshdefinition = new MeshDefinition();
		PartDefinition partdefinition = meshdefinition.getRoot();
		partdefinition.addOrReplaceChild("head", CubeListBuilder.create().texOffs(0, 0).addBox(-6.0F, -6.0F, -6.0F, 12.0F, 12.0F, 12.0F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, 16.0F, 0.0F));
		partdefinition.addOrReplaceChild("legL", CubeListBuilder.create().texOffs(0, 24).addBox(6.0F, 0.0F, -1.0F, 2.0F, 9.0F, 2.0F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, 15.0F, 0.0F));
		partdefinition.addOrReplaceChild("legR", CubeListBuilder.create().texOffs(8, 24).addBox(-8.0F, 0.0F, -1.0F, 2.0F, 9.0F, 2.0F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, 15.0F, 0.0F));
		return LayerDefinition.create(meshdefinition, 64, 64);

	public void setupAnim(Type entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) {
		this.head.xRot = headPitch * ((float)Math.PI / 180F);
		this.legR.xRot = Mth.cos(limbSwing * 0.6662F) * 1.4F * limbSwingAmount;
		this.legL.xRot = Mth.cos(limbSwing * 0.6662F + (float)Math.PI) * 1.4F * limbSwingAmount;

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

	protected Iterable<ModelPart> headParts() {
		return ImmutableList.of(this.head);

	protected Iterable<ModelPart> bodyParts() {
		return null;

My problem is that the game can't find the "legL" part in the CubosModel : "Caused by: java.util.NoSuchElementException: Can't find part legL"

However, when I delete the line "this.addLayer(new CubosPowerLayer(this, context.getModelSet()));" in the CubosRenderer constructor, the problem disappears. Perhaps the issue comes from the fact I chose the CREEPER_ARMOR which isn't suitable.

I have checked the ModelLayers and LayerDefinitions which contain CREEPER_ARMOR but I can't solve the issue

Link to comment
Share on other sites


As you can see, in the constructor, I use the bakeLayer method for the CREEPER_ARMOR since I don't know how and where to create the same for the cubos.



Examples on github for other mods:



If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

By using this site, you agree to our Terms of Use.