Jump to content

[1.19] Armor model (Continuation)


Luckydel

Recommended Posts

 

The continuation

I get an exception:
Caused by: java.lang.NullPointerException: Cannot invoke "String.indexOf(int)" because "texture" is null


Model:
 

Spoiler
public class Balaclava_Model<T extends Entity> extends EntityModel<T> {
    public static final ModelLayerLocation LAYER_LOCATION = new ModelLayerLocation(new ResourceLocation(Main.MODID, "balaclava_model"), "main");
    public final ModelPart Head;

    public Balaclava_Model(ModelPart root) {
        this.Head = root.getChild("Head");
    }

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

        PartDefinition Head = partdefinition.addOrReplaceChild("Head", CubeListBuilder.create().texOffs(24, 0).addBox(-4.0F, -4.0F, -4.5F, 8.0F, 4.0F, 1.0F, new CubeDeformation(0.0F))
                .texOffs(24, 5).addBox(-4.0F, -8.0F, -4.5F, 8.0F, 2.0F, 1.0F, new CubeDeformation(0.0F))
                .texOffs(0, 3).addBox(3.0F, -6.0F, -4.5F, 1.0F, 2.0F, 1.0F, new CubeDeformation(0.0F))
                .texOffs(0, 0).addBox(-4.0F, -6.0F, -4.5F, 1.0F, 2.0F, 1.0F, new CubeDeformation(0.0F))
                .texOffs(31, 8).addBox(-4.0F, -8.0F, 3.1F, 8.0F, 8.0F, 1.0F, new CubeDeformation(0.0F))
                .texOffs(18, 18).addBox(-4.1F, -8.0F, -4.0F, 1.0F, 8.0F, 8.0F, new CubeDeformation(0.0F))
                .texOffs(0, 9).addBox(-4.0F, -8.1F, -4.0F, 8.0F, 1.0F, 8.0F, new CubeDeformation(0.0F))
                .texOffs(0, 0).addBox(-4.0F, -0.9F, -4.0F, 8.0F, 1.0F, 8.0F, new CubeDeformation(0.0F))
                .texOffs(0, 18).addBox(3.1F, -8.0F, -4.0F, 1.0F, 8.0F, 8.0F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, 0.0F, 0.0F));

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

    @Override
    public void setupAnim(T entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) {

    }

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

 

Armor item:
 

Spoiler
public class Balaclava extends ArmorItem{
    private static final ArmorMaterial  armorMaterial= new ArmorMaterial(){
        @Override
        public int getDurabilityForSlot(EquipmentSlot p_40410_) {
            return 25;
        }

        @Override
        public int getDefenseForSlot(EquipmentSlot p_40411_) {
            return 3;
        }

        @Override
        public int getEnchantmentValue() {
            return 0;
        }

        @Override
        public SoundEvent getEquipSound() {
            return null;
        }

        @Override
        public Ingredient getRepairIngredient() {
            return null;
        }

        @Override
        public String getName() {
            return null;
        }

        @Override
        public float getToughness() {
            return 0;
        }

        @Override
        public float getKnockbackResistance() {
            return 0;
        }
    };
    public Balaclava(EquipmentSlot slot, Item.Properties properties) {
        super(armorMaterial,slot,properties);
    }
    @Override
    public void initializeClient(java.util.function.Consumer<net.minecraftforge.client.extensions.common.IClientItemExtensions > consumer) {
        consumer.accept(new IClientItemExtensions() {
            public HumanoidModel getHumanoidArmorModel(LivingEntity living, ItemStack stack, EquipmentSlot slot, HumanoidModel defaultModel) {
                HumanoidModel armorModel = new HumanoidModel(new ModelPart(Collections.emptyList(),
                        Map.of("head",
                                new Balaclava_Model(Minecraft.getInstance().getEntityModels().bakeLayer(Balaclava_Model.LAYER_LOCATION)).Head,
                                "hat", new ModelPart(Collections.emptyList(), Collections.emptyMap()), "body",
                                new ModelPart(Collections.emptyList(), Collections.emptyMap()), "right_arm",
                                new ModelPart(Collections.emptyList(), Collections.emptyMap()), "left_arm",
                                new ModelPart(Collections.emptyList(), Collections.emptyMap()), "right_leg",
                                new ModelPart(Collections.emptyList(), Collections.emptyMap()), "left_leg",
                                new ModelPart(Collections.emptyList(), Collections.emptyMap()))));
                armorModel.crouching = living.isShiftKeyDown();
                armorModel.riding = defaultModel.riding;
                armorModel.young = living.isBaby();
                return armorModel;
            }
        });
    }

    public String getArmorTexture(ItemStack stack, Entity entity, EquipmentSlot slot, String type) {
        return "warmod_perekur:textures/entity/balaclava.png";
    }

}

 

Registry armor item:

Spoiler
public static final RegistryObject<Item> BALACLAVA = REGISTRY.register("balaclava",
            () -> new Balaclava(EquipmentSlot.HEAD,new Item.Properties().tab(CreativeModeTab.TAB_MISC).setNoRepair()));

 

Registry model armor:

Spoiler
public static void registerLayerDefinitions(EntityRenderersEvent.RegisterLayerDefinitions event) {
		event.registerLayerDefinition(Balaclava_Model.LAYER_LOCATION, Balaclava_Model::createBodyLayer);
	}

 

I did not create the rendering, should I do it?

Edited by Luckydel
Link to comment
Share on other sites

That is because you return null within your ArmorMaterial for `#getName`. This should be set to your material name with your modid appended (e.g. `examplemod:examplematerial`). As an additional heads up, none of the getters should return null, otherwise the game will most likely crash when executing the associated operation. You can use the vanilla enum class as a decent starting point on how to set it up properly.

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.

Guest
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.