Jump to content

Recommended Posts

Posted

I recently started working on a new mod, and right now I'm stuck with trying to get an entity to register. I've watched and read some tutorials to try and help me through, but I haven't been able to fully figure out how to get my entity in game, especially with a lack of 1.8.9 tutorials on mobs. As I've said, I've used tutorials from different people, so I apologize if my coding looks jumbled up and mismatched. Any help with this would be greatly appreciated

 

EntityImp.java

 

 

package com.TheGoldCrayon.Daemonology.entity.passive;

 

import com.ibm.icu.impl.duration.impl.Utils;

 

import net.minecraft.block.Block;

import net.minecraft.entity.EntityAgeable;

import net.minecraft.entity.EnumCreatureType;

import net.minecraft.entity.SharedMonsterAttributes;

import net.minecraft.entity.ai.EntityAIFollowParent;

import net.minecraft.entity.ai.EntityAILookIdle;

import net.minecraft.entity.ai.EntityAIMate;

import net.minecraft.entity.ai.EntityAIPanic;

import net.minecraft.entity.ai.EntityAISwimming;

import net.minecraft.entity.ai.EntityAITempt;

import net.minecraft.entity.ai.EntityAIWander;

import net.minecraft.entity.ai.EntityAIWatchClosest;

import net.minecraft.entity.passive.EntityAnimal;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.init.Items;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraft.pathfinding.PathNavigateGround;

import net.minecraft.util.BlockPos;

import net.minecraft.world.World;

import net.minecraft.world.biome.BiomeGenBase;

import net.minecraftforge.fml.common.registry.EntityRegistry;

 

public class EntityImp extends EntityAnimal

{

    public EntityImp(World worldIn)

    {

        super(worldIn);

        this.setSize(0.9F, 1.3F);

        ((PathNavigateGround)this.getNavigator()).setAvoidsWater(true);

        this.tasks.addTask(0, new EntityAISwimming(this));

        this.tasks.addTask(1, new EntityAIPanic(this, 2.0D));

        this.tasks.addTask(2, new EntityAIMate(this, 1.0D));

        this.tasks.addTask(3, new EntityAITempt(this, 1.25D, Items.wheat, false));

        this.tasks.addTask(4, new EntityAIFollowParent(this, 1.25D));

        this.tasks.addTask(5, new EntityAIWander(this, 1.0D));

        this.tasks.addTask(6, new EntityAIWatchClosest(this, EntityPlayer.class, 6.0F));

        this.tasks.addTask(7, new EntityAILookIdle(this));

    }

 

   

   

   

    protected void applyEntityAttributes()

    {

        super.applyEntityAttributes();

        this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(10.0D);

        this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.5D);

    }

 

    /**

    * Returns the sound this mob makes while it's alive.

    */

    protected String getLivingSound()

    {

        return "mob.cow.say";

    }

 

    /**

    * Returns the sound this mob makes when it is hurt.

    */

    protected String getHurtSound()

    {

        return "mob.cow.hurt";

    }

 

    /**

    * Returns the sound this mob makes on death.

    */

    protected String getDeathSound()

    {

        return "mob.cow.hurt";

    }

 

    protected void playStepSound(BlockPos pos, Block blockIn)

    {

        this.playSound("mob.cow.step", 0.15F, 1.0F);

    }

 

    /**

    * Returns the volume for the sounds this mob makes.

    */

    protected float getSoundVolume()

    {

        return 0.4F;

    }

 

    protected Item getDropItem()

    {

        return Items.leather;

    }

 

    /**

    * Drop 0-2 items of this living's type

    */

    protected void dropFewItems(boolean p_70628_1_, int p_70628_2_)

    {

        int i = this.rand.nextInt(3) + this.rand.nextInt(1 + p_70628_2_);

 

        for (int j = 0; j < i; ++j)

        {

            this.dropItem(Items.leather, 1);

        }

 

        i = this.rand.nextInt(3) + 1 + this.rand.nextInt(1 + p_70628_2_);

 

        for (int k = 0; k < i; ++k)

        {

            if (this.isBurning())

            {

                this.dropItem(Items.cooked_beef, 1);

            }

            else

            {

                this.dropItem(Items.beef, 1);

            }

        }

    }

 

    /**

    * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig.

    */

    public boolean interact(EntityPlayer player)

    {

            return super.interact(player);

    }

 

    public EntityImp createChild(EntityAgeable ageable)

    {

        return new EntityImp(this.worldObj);

    }

 

    public float getEyeHeight()

    {

        return this.height;

    }

   

    public boolean getCanSpawnHere()

    {

    return super.getCanSpawnHere();

    }

   

   

   

}

 

 

 

ModelImp.java

 

 

package com.TheGoldCrayon.Daemonology.client.model;

 

import net.minecraft.client.model.ModelBase;

import net.minecraft.client.model.ModelBiped;

import net.minecraft.client.model.ModelRenderer;

import net.minecraft.client.renderer.GlStateManager;

import net.minecraft.entity.Entity;

import net.minecraft.util.MathHelper;

 

public class ModelImp extends ModelBiped

{

public ModelRenderer head = new ModelRenderer(this, 0, 0);

public ModelRenderer body;

public ModelRenderer rightleg;

public ModelRenderer leftleg;

public ModelRenderer rightarm;

public ModelRenderer leftarm;

public ModelRenderer righthorn;

public ModelRenderer lefthorn;

public ModelRenderer rightwing;

public ModelRenderer leftwing;

public ModelRenderer tail;

 

public ModelImp()

{

textureWidth = 64;

textureHeight = 64;

 

this.head = new ModelRenderer(this, 10, 0);

this.head.addBox(-2.5F, -4F, -1.5F, 5, 4, 3);

    this.head.setRotationPoint(0F, 12F, 0F);

   

    this.body = new ModelRenderer(this, 0, 13);

    this.body.addBox(-3F, 0F, -2F, 6, 9, 4);

    this.body.setRotationPoint(0F, 12F, 0F);

   

    this.rightarm = new ModelRenderer(this, 21, 8);

    this.rightarm.addBox(-1F, -1F, -1F, 2, 6, 2);

    this.rightarm.setRotationPoint(-4F, 13F, 0F);

   

    this.leftarm = new ModelRenderer(this, 21, 8);

    this.leftarm.addBox(-1F, -1F, -1F, 2, 6, 2);

    this.leftarm.setRotationPoint(4F, 13F, 0F);

   

    this.rightleg = new ModelRenderer(this, 0, 7);

    this.rightleg.addBox(-1F, 0F, -1F, 2, 3, 2);

    this.rightleg.setRotationPoint(-2F, 21F, 0F);

 

    this.leftleg = new ModelRenderer(this, 0, 7);

    this.leftleg.addBox(-1F, 0F, -1F, 2, 3, 2);

    this.leftleg.setRotationPoint(2F, 21F, 0F);

   

    this.tail = new ModelRenderer(this, 5, 0);

    this.tail.addBox(-0.5F, -5F, 0F, 1, 5, 1);

    this.tail.setRotationPoint(0F, 20F, 1F);

   

    this.righthorn = new ModelRenderer(this, 0, 0);

    this.righthorn.addBox(-0.5F, 0F, 0F, 1, 1, 1);

    this.righthorn.setRotationPoint(-1F, 8F, -0.7F);

   

    this.lefthorn = new ModelRenderer(this, 0, 0);

    this.lefthorn.addBox(-0.5F, 0F, 0F, 1, 1, 1);

    this.lefthorn.setRotationPoint(1F, 8F, -0.7F);

   

    this.rightwing = new ModelRenderer(this, 0, 27);

    this.rightwing.addBox(-10F, 0F, 0F, 10, 4, 1);

    this.rightwing.setRotationPoint(0F, 13F, 2F);

   

    this.leftwing = new ModelRenderer(this, 0, 33);

    this.leftwing.addBox(0F, 0F, 0F, 10, 4, 1);

    this.leftwing.setRotationPoint(0F, 13F, 2F);

}

 

public void render(Entity entity, float time, float limbSwingDistance, float p_78088_4_, float headYRot, float headXRot, float Ytrans)

{

this.setRotationAngles(time, limbSwingDistance, p_78088_4_, headYRot, headXRot, Ytrans, entity);

 

if(this.isChild)

{

float div = 2.0F;

GlStateManager.pushMatrix();

GlStateManager.scale(1.0F / div, 1.0F / div, 1.0F / div);

GlStateManager.translate(0.0F, 24.0F * Ytrans, 0.0F);

this.head.render(Ytrans);

this.body.render(Ytrans);

this.tail.render(Ytrans);

this.rightleg.render(Ytrans);

this.leftleg.render(Ytrans);

this.rightarm.render(Ytrans);

this.leftarm.render(Ytrans);

this.righthorn.render(Ytrans);

this.lefthorn.render(Ytrans);

this.rightwing.render(Ytrans);

this.leftwing.render(Ytrans);

GlStateManager.popMatrix();

}

 

else

{

this.head.render(Ytrans);

this.body.render(Ytrans);

this.tail.render(Ytrans);

this.rightleg.render(Ytrans);

this.leftleg.render(Ytrans);

this.rightarm.render(Ytrans);

this.leftarm.render(Ytrans);

this.righthorn.render(Ytrans);

this.lefthorn.render(Ytrans);

this.rightwing.render(Ytrans);

this.leftwing.render(Ytrans);

}

}

 

public void setRotationAngles(float time, float limbSwingDistance, float p_78087_3_, float headYrot, float headXRot, float p_78087_6_, Entity entity)

    {

this.head.rotateAngleX = headXRot / (180F / (float)Math.PI);

this.head.rotateAngleY = headXRot / (180F / (float)Math.PI);

 

this.body.rotateAngleX = ((float)Math.PI / 2.0F);

 

this.rightleg.rotateAngleX = MathHelper.cos(time * 0.6662F) * 1.4F * limbSwingDistance;

this.leftleg.rotateAngleX = MathHelper.cos(time * .6662F + (float)Math.PI) * 1.4F * limbSwingDistance;

this.leftarm.rotateAngleX = MathHelper.cos(time * 0.6662F) * 1.4F * limbSwingDistance;

this.rightarm.rotateAngleX = MathHelper.cos(time * .6662F + (float)Math.PI) * 1.4F * limbSwingDistance;

 

    }

 

}

 

 

 

 

RenderImp.java

 

 

package com.TheGoldCrayon.Daemonology.client.renderer.entity;

 

import net.minecraft.client.renderer.entity.RenderLiving;

import net.minecraft.client.renderer.entity.RenderManager;

import net.minecraft.client.Minecraft;

import net.minecraft.client.model.ModelBase;

import net.minecraft.entity.Entity;

 

import com.TheGoldCrayon.Daemonology.client.model.ModelImp;

import com.TheGoldCrayon.Daemonology.entity.passive.EntityImp;

import net.minecraft.util.ResourceLocation;

import net.minecraftforge.fml.client.registry.RenderingRegistry;

 

public class RenderImp extends RenderLiving

{

private static final ResourceLocation impTextures = new ResourceLocation("dm:textures/entity/Imp.png");

 

public RenderImp(RenderManager rendermanager, ModelBase model, float shadowsize)

{

super(rendermanager, model, shadowsize);

}

 

protected ResourceLocation func_180572_a(EntityImp entity)

{

return impTextures;

}

 

protected ResourceLocation getEntityTexture(Entity entity)

{

return this.func_180572_a((EntityImp)entity);

}

 

}

 

 

 

 

ClientProxy.java

 

 

package com.TheGoldCrayon.Daemonology.proxy;

 

import com.TheGoldCrayon.Daemonology.client.model.ModelImp;

import com.TheGoldCrayon.Daemonology.client.renderer.entity.RenderImp;

import com.TheGoldCrayon.Daemonology.entity.passive.EntityImp;

import com.TheGoldCrayon.Daemonology.init.DaemonologyBlocks;

import com.TheGoldCrayon.Daemonology.init.DaemonologyItems;

 

import net.minecraft.client.Minecraft;

import net.minecraftforge.fml.client.registry.RenderingRegistry;

import net.minecraftforge.fml.common.event.FMLInitializationEvent;

import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;

 

public class ClientProxy extends CommonProxy

{

@Override

public void registerRenders()

{

DaemonologyItems.registerRenders();

DaemonologyBlocks.registerRenders();

}

 

 

 

public void preInit(FMLPreInitializationEvent e)

{

RenderingRegistry.registerEntityRenderingHandler(EntityImp.class, new RenderImp(Minecraft.getMinecraft().getRenderManager(), new ModelImp(), 0.5F));

 

}

 

}

 

 

 

 

DaemonologyMod.java (My main mod file)

 

 

package com.TheGoldCrayon.Daemonology;

 

import com.TheGoldCrayon.Daemonology.client.renderer.entity.RenderImp;

import com.TheGoldCrayon.Daemonology.entity.passive.EntityImp;

import com.TheGoldCrayon.Daemonology.init.DaemonologyBlocks;

import com.TheGoldCrayon.Daemonology.init.DaemonologyItems;

import com.TheGoldCrayon.Daemonology.proxy.CommonProxy;

 

import net.minecraft.entity.EnumCreatureType;

import net.minecraft.world.biome.BiomeGenBase;

import net.minecraftforge.fml.common.Mod;

import net.minecraftforge.fml.common.Mod.EventHandler;

import net.minecraftforge.fml.common.SidedProxy;

import net.minecraftforge.fml.common.event.FMLInitializationEvent;

import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;

import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;

import net.minecraftforge.fml.common.registry.EntityRegistry;

 

@Mod(modid = Reference.MOD_ID, name = Reference.MOD_NAME, version = Reference.VERSION)

public class DaemonologyMod {

 

@SidedProxy(clientSide = Reference.CLIENT_PROXY_CLASS, serverSide = Reference.SERVER_PROXY_CLASS)

public static CommonProxy proxy;

 

public static final DaemonologyTab tabDaemonology = new DaemonologyTab("tabDaemonology");

 

@EventHandler

public void preInit(FMLPreInitializationEvent event)

{

DaemonologyItems.init();

DaemonologyItems.register();

 

DaemonologyBlocks.init();

DaemonologyBlocks.register();

 

Recipes.init();

 

 

}

 

@EventHandler

public void init(FMLInitializationEvent event)

{

proxy.registerRenders();

proxy.registerWorldGenerators();

EntityRegistry.registerModEntity(EntityImp.class, "Imp", 1, 1, 80, 3, true, 0, 0);

    EntityRegistry.addSpawn(EntityImp.class, 80, 1, 3, EnumCreatureType.CREATURE, BiomeGenBase.birchForest);

    EntityRegistry.addSpawn(EntityImp.class, 80, 1, 3, EnumCreatureType.CREATURE, BiomeGenBase.plains);

    EntityRegistry.addSpawn(EntityImp.class, 80, 1, 3, EnumCreatureType.CREATURE, BiomeGenBase.forest);

    EntityRegistry.addSpawn(EntityImp.class, 80, 1, 3, EnumCreatureType.CREATURE, BiomeGenBase.desert);

    EntityRegistry.addSpawn(EntityImp.class, 80, 1, 3, EnumCreatureType.CREATURE, BiomeGenBase.savanna);

}

 

@EventHandler

public void postInit(FMLPostInitializationEvent event)

{

 

}

}

 

 

 

"War doesn't determine who is right. Only who is left." -Bertrand Russell

Posted

Pretty sure EntityRegistry#registerModEntity still requires an instance of your mod, even in 1.8.9:

int entity_id = 0;
int tracking_range = 80; // used by most mobs and animals; most projectiles use 64
int update_frequency = 3; // used by most mobs and animals; most projectiles use 10, except arrows
EntityRegistry.registerModEntity(YourEntity.class, "registry_name", entity_id++, YourMod.instance, tracking_range, update_frequency, true, egg_color_1, egg_color_2);

Take a look at the vanilla EntityList class for the tracking range and update frequencies used for vanilla entities - that will help you decide what to use for each of your particular entities.

Posted

Pretty sure EntityRegistry#registerModEntity still requires an instance of your mod, even in 1.8.9:

int entity_id = 0;
int tracking_range = 80; // used by most mobs and animals; most projectiles use 64
int update_frequency = 3; // used by most mobs and animals; most projectiles use 10, except arrows
EntityRegistry.registerModEntity(YourEntity.class, "registry_name", entity_id++, YourMod.instance, tracking_range, update_frequency, true, egg_color_1, egg_color_2);

Take a look at the vanilla EntityList class for the tracking range and update frequencies used for vanilla entities - that will help you decide what to use for each of your particular entities.

 

I do have that under my DaemonologyMod.java file.

EntityRegistry.registerModEntity(EntityImp.class, "Imp", 1, 1, 80, 3, true, 0, 0);

 

Leaving my code the way it is, when I run the client, it crashes. I looked in the console and the only code that it mentioned form my mod was this exact line.

 

EDIT: I looked at the code again and then another video and saw that I was missing the instance. I hadn't seen it in use before so I didn't know that I needed it. Thank you very  much. I ran the client and my entity showed up. Except for the fact that it's now a white box. Do you have any idea what I did wrong this time?

"War doesn't determine who is right. Only who is left." -Bertrand Russell

Posted

You're passing the

Integer

1 as the

mod

argument of

EntityRegistry.registerModEntity

. This compiles because every reference type extends

Object

and every primitive type can be boxed to a reference type. This fails at runtime because 1 isn't a

String

mod ID or an instance of a mod class, it's just an integer.

 

When asking for help with a crash, always post the FML log or crash report.

 

In future, please use Gist or Pastebin to post logs/crash reports (if applicable) and code with syntax highlighting. To get syntax highlighting on Gist, give each file the appropriate extension (.java for Java code). To get syntax highlighting on Pastebin, select the language from the dropdown at the bottom of the page.

 

It's much easier to read code with proper formatting and syntax highlighting.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

You're passing the

Integer

1 as the

mod

argument of

EntityRegistry.registerModEntity

. This compiles because every reference type extends

Object

and every primitive type can be boxed to a reference type. This fails at runtime because 1 isn't a

String

mod ID or an instance of a mod class, it's just an integer.

 

When asking for help with a crash, always post the FML log or crash report.

 

In future, please use Gist or Pastebin to post logs/crash reports (if applicable) and code with syntax highlighting. To get syntax highlighting on Gist, give each file the appropriate extension (.java for Java code). To get syntax highlighting on Pastebin, select the language from the dropdown at the bottom of the page.

 

It's much easier to read code with proper formatting and syntax highlighting.

 

Okay, I will do that in the future. I ended up fixing that piece of code, and my entity registers in game now. But when I see it in game, it's just a white box. Do you have any idea what I did wrong to make this happen?

 

"War doesn't determine who is right. Only who is left." -Bertrand Russell

Posted

It looks like you're never calling the

ClientProxy#preInit

method. Add a method with the same signature (name + arguments) to

CommonProxy

, add the

@Override

annotation to the

ClientProxy

method and then call this method from

DaemonologyMod#preInit

.

 

The overload of

RenderingRegistry.registerEntityRenderingHandler

you're using is deprecated and will be removed at some point in the future. Use the overload with an

IRenderFactory

argument instead.

 

To implement

IRenderFactory

, either use an anonymous class (if you're targeting Java 6/7) or a constructor method reference (if you're targeting Java 8).

 

As the documentation of this method says, it should be called in the preInit phase.

 

Edit: The


smiley is really annoying when talking about Java 8 or Minecraft 1.8.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

I did end up getting it. Now I'm just finishing up on the rotation angles as a couple body parts weren't rotated how I want them.

"War doesn't determine who is right. Only who is left." -Bertrand Russell

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.

Announcements



×
×
  • Create New...

Important Information

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