Model Custom_model

Started by JerichoSwain00 on Mon, 12/28/2020 - 11:26

Topic category: Help with modding (Java Edition)

Last seen on 17:54, 31. Jan 2021
Joined Dec 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Model Custom_model
Mon, 12/28/2020 - 11:26

Hello. I need help. I designed a mod. I want to add a mob. I made a mob from Blockbench. Everything is over but I am getting an error. I leave it as a supplement. I solved it from different places as much as I could but I got stuck here.

 

package net.ahmetefefirat.cevhermodu.entity;

import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.common.registry.EntityRegistry;
import net.minecraftforge.fml.common.registry.EntityEntryBuilder;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraftforge.common.DungeonHooks;

import net.minecraft.world.biome.Biome;
import net.minecraft.world.World;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.DamageSource;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Item;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAIPanic;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
import net.minecraft.entity.ai.EntityAIAttackMelee;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.entity.EnumCreatureAttribute;
import net.minecraft.entity.Entity;
import net.minecraft.client.renderer.entity.RenderLiving;
import net.minecraft.client.model.ModelRenderer;

import net.ahmetefefirat.cevhermodu.block.BlockCevherblogu;
import net.ahmetefefirat.cevhermodu.ElementsCevherMod;

import java.util.Iterator;
import java.util.ArrayList;

@ElementsCevherMod.ModElement.Tag
public class EntityCevherGardiyani extends ElementsCevherMod.ModElement {
    public final int ENTITYID = 11;
    public final int ENTITYID_RANGED = 12;
    public EntityCevherGardiyani(ElementsCevherMod instance) {
        super(instance, 60);
    }

    @Override
    public void initElements() {
        elements.entities
                .add(() -> EntityEntryBuilder.create().entity(EntityCustom.class).id(new ResourceLocation("cevher", "cevher_gardiyani"), ENTITYID)
                        .name("cevher_gardiyani").tracker(64, 3, true).egg(-9623443, -7039852).build());
    }

    @Override
    public void init(FMLInitializationEvent event) {
        Biome[] spawnBiomes = allbiomes(Biome.REGISTRY);
        EntityRegistry.addSpawn(EntityCustom.class, 35, 2, 6, EnumCreatureType.MONSTER, spawnBiomes);
        DungeonHooks.addDungeonMob(new ResourceLocation("cevher:cevher_gardiyani"), 180);
    }

    private Biome[] allbiomes(net.minecraft.util.registry.RegistryNamespaced<ResourceLocation, Biome> in) {
        Iterator<Biome> itr = in.iterator();
        ArrayList<Biome> ls = new ArrayList<Biome>();
        while (itr.hasNext())
            ls.add(itr.next());
        return ls.toArray(new Biome[ls.size()]);
    }

    @SideOnly(Side.CLIENT)
    @Override
    public void preInit(FMLPreInitializationEvent event) {
        RenderingRegistry.registerEntityRenderingHandler(EntityCustom.class, renderManager -> {
            return new RenderLiving(renderManager, new Modelcustom_model(), 0.5f) {
                protected ResourceLocation getEntityTexture(Entity entity) {
                    return new ResourceLocation("cevher:textures/cevher.png");
                }
            };
        });
    }
    public class EntityCustom extends EntityMob {
        public EntityCustom(World world) {
            super(world);
            setSize(0.6f, 1.8f);
            experienceValue = 25;
            this.isImmuneToFire = true;
            setNoAI(!true);
        }

        @Override
        protected void initEntityAI() {
            super.initEntityAI();
            this.tasks.addTask(1, new EntityAIAttackMelee(this, 1.2, false));
            this.tasks.addTask(2, new EntityAIWander(this, 1));
            this.targetTasks.addTask(3, new EntityAIHurtByTarget(this, false));
            this.tasks.addTask(4, new EntityAILookIdle(this));
            this.tasks.addTask(5, new EntityAISwimming(this));
            this.tasks.addTask(6, new EntityAIPanic(this, 18));
        }

        @Override
        public EnumCreatureAttribute getCreatureAttribute() {
            return EnumCreatureAttribute.UNDEFINED;
        }

        @Override
        protected Item getDropItem() {
            return new ItemStack(BlockCevherblogu.block, (int) (1)).getItem();
        }

        @Override
        public net.minecraft.util.SoundEvent getAmbientSound() {
            return (net.minecraft.util.SoundEvent) net.minecraft.util.SoundEvent.REGISTRY.getObject(new ResourceLocation("cevher:yuruyus"));
        }

        @Override
        public net.minecraft.util.SoundEvent getHurtSound(DamageSource ds) {
            return (net.minecraft.util.SoundEvent) net.minecraft.util.SoundEvent.REGISTRY.getObject(new ResourceLocation("cevher:dmg"));
        }

        @Override
        public net.minecraft.util.SoundEvent getDeathSound() {
            return (net.minecraft.util.SoundEvent) net.minecraft.util.SoundEvent.REGISTRY.getObject(new ResourceLocation("cevher:olum"));
        }

        @Override
        protected float getSoundVolume() {
            return 1.0F;
        }

        @Override
        protected void applyEntityAttributes() {
            super.applyEntityAttributes();
            if (this.getEntityAttribute(SharedMonsterAttributes.ARMOR) != null)
                this.getEntityAttribute(SharedMonsterAttributes.ARMOR).setBaseValue(3.5D);
            if (this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED) != null)
                this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.4D);
            if (this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH) != null)
                this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(15D);
            if (this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE) != null)
                this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(5D);
        }

        @Override
        public boolean canBeCollidedWith() {
            return false;
        }
    }

    // Made with Blockbench 3.7.4
    // Exported for Minecraft version 1.15
    // Paste this class into your mod and generate all required imports
    public class Modelcustom_model extends EntityModel<Entity> {
        private final ModelRenderer sagbacak;
        private final ModelRenderer solbacak;
        private final ModelRenderer govde;
        private final ModelRenderer solkol;
        private final ModelRenderer sagkol;
        public Modelcustom_model() {
            textureWidth = 64;
            textureHeight = 64;
            sagbacak = new ModelRenderer(this);
            sagbacak.setRotationPoint(0.0F, 24.0F, 0.0F);
            sagbacak.setTextureOffset(4, 28).addBox(-5.0F, -7.0F, 3.0F, 1.0F, 5.0F, 1.0F, 0.0F, false);
            sagbacak.setTextureOffset(0, 28).addBox(-5.0F, -7.0F, -3.0F, 1.0F, 5.0F, 1.0F, 0.0F, false);
            sagbacak.setTextureOffset(20, 25).addBox(-4.0F, -7.0F, 2.0F, 1.0F, 7.0F, 1.0F, 0.0F, false);
            sagbacak.setTextureOffset(12, 25).addBox(-4.0F, -7.0F, -2.0F, 1.0F, 7.0F, 1.0F, 0.0F, false);
            sagbacak.setTextureOffset(21, 21).addBox(-6.0F, -5.0F, -4.0F, 3.0F, 1.0F, 3.0F, 0.0F, false);
            sagbacak.setTextureOffset(20, 4).addBox(-6.0F, -5.0F, 2.0F, 3.0F, 1.0F, 3.0F, 0.0F, false);
            solbacak = new ModelRenderer(this);
            solbacak.setRotationPoint(0.0F, 24.0F, 0.0F);
            solbacak.setTextureOffset(24, 25).addBox(2.0F, -7.0F, -2.0F, 1.0F, 7.0F, 1.0F, 0.0F, false);
            solbacak.setTextureOffset(16, 25).addBox(2.0F, -7.0F, 2.0F, 1.0F, 7.0F, 1.0F, 0.0F, false);
            solbacak.setTextureOffset(28, 28).addBox(3.0F, -7.0F, -3.0F, 1.0F, 5.0F, 1.0F, 0.0F, false);
            solbacak.setTextureOffset(28, 11).addBox(3.0F, -7.0F, 3.0F, 1.0F, 5.0F, 1.0F, 0.0F, false);
            solbacak.setTextureOffset(9, 21).addBox(2.0F, -5.0F, -4.0F, 3.0F, 1.0F, 3.0F, 0.0F, false);
            solbacak.setTextureOffset(0, 20).addBox(2.0F, -5.0F, 2.0F, 3.0F, 1.0F, 3.0F, 0.0F, false);
            govde = new ModelRenderer(this);
            govde.setRotationPoint(0.0F, 24.0F, 0.0F);
            govde.setTextureOffset(0, 24).addBox(-2.0F, -13.0F, 0.0F, 3.0F, 3.0F, 1.0F, 0.0F, false);
            govde.setTextureOffset(18, 21).addBox(-1.0F, -12.0F, 0.0F, 1.0F, 1.0F, 2.0F, 0.0F, false);
            govde.setTextureOffset(0, 0).addBox(-3.0F, -10.0F, -2.0F, 5.0F, 6.0F, 5.0F, 0.0F, false);
            govde.setTextureOffset(0, 11).addBox(-3.0F, -9.0F, -3.0F, 5.0F, 8.0F, 1.0F, 0.0F, false);
            solkol = new ModelRenderer(this);
            solkol.setRotationPoint(-3.0F, 17.0F, 0.0F);
            setRotationAngle(solkol, -0.5236F, 0.0F, 0.0F);
            solkol.setTextureOffset(15, 0).addBox(-2.0F, -7.0F, -1.0F, 3.0F, 1.0F, 3.0F, 0.0F, false);
            solkol.setTextureOffset(24, 12).addBox(-1.0F, -7.0F, 0.0F, 1.0F, 7.0F, 1.0F, 0.0F, false);
            sagkol = new ModelRenderer(this);
            sagkol.setRotationPoint(3.0F, 17.0F, 0.0F);
            setRotationAngle(sagkol, -0.5236F, 0.0F, 0.0F);
            sagkol.setTextureOffset(8, 25).addBox(-1.0F, -7.0F, 0.0F, 1.0F, 7.0F, 1.0F, 0.0F, false);
            sagkol.setTextureOffset(17, 8).addBox(-2.0F, -7.0F, -1.0F, 3.0F, 1.0F, 3.0F, 0.0F, false);
        }

        @Override
        public void render(MatrixStack matrixStack, IVertexBuilder buffer, int packedLight, int packedOverlay, float red, float green, float blue,
                float alpha) {
            sagbacak.render(matrixStack, buffer, packedLight, packedOverlay);
            solbacak.render(matrixStack, buffer, packedLight, packedOverlay);
            govde.render(matrixStack, buffer, packedLight, packedOverlay);
            solkol.render(matrixStack, buffer, packedLight, packedOverlay);
            sagkol.render(matrixStack, buffer, packedLight, packedOverlay);
        }

        public void setRotationAngle(ModelRenderer modelRenderer, float x, float y, float z) {
            modelRenderer.rotateAngleX = x;
            modelRenderer.rotateAngleY = y;
            modelRenderer.rotateAngleZ = z;
        }

        public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5, Entity e) {
            super.setRotationAngles(f, f1, f2, f3, f4, f5, e);
            this.govde.rotateAngleY = f3 / (180F / (float) Math.PI);
            this.govde.rotateAngleX = f4 / (180F / (float) Math.PI);
            this.solkol.rotateAngleX = MathHelper.cos(f * 0.6662F) * f1;
            this.solbacak.rotateAngleX = MathHelper.cos(f * 1.0F) * -1.0F * f1;
            this.sagkol.rotateAngleX = MathHelper.cos(f * 0.6662F + (float) Math.PI) * f1;
            this.sagbacak.rotateAngleX = MathHelper.cos(f * 1.0F) * 1.0F * f1;
        }
    }
}