Jump to content

[Solved] Custom Entity - Entity undersized


Nero90

Recommended Posts

Hello everyone!

I'm trying to spawn a custom npc, but it's not working as expected.^^

 

Look at this:

463nib2xcxjp.png

This should be a normal player-sized entity. But for any reason its...well...undersized.  ???

 

Do somebody hava an idea why this happens?

 

Java Code:

 

Class RenderNpc

import net.minecraft.client.model.ModelBase;
import net.minecraft.client.renderer.entity.RenderLiving;
import net.minecraft.entity.Entity;
import net.minecraft.util.ResourceLocation;

public class RenderNpc extends RenderLiving{

private static final ResourceLocation Npc_Texture = new ResourceLocation("mymod:textures/entity/skin_smith.png");

    public RenderNpc(ModelBase par1ModelBase, float par2)
    {
        super(par1ModelBase, par2);
    }

    @Override
    protected ResourceLocation getEntityTexture(Entity par1Entity)
    {
        return Npc_Texture;
    }
}

 

Class ModelNpc (Copy&Paste from a tutorial)


import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;

public class ModelNpc extends ModelBase{

//fields
    ModelRenderer Legleft;
    ModelRenderer Legright;
    ModelRenderer Body;
    ModelRenderer Head;
  
  public ModelNpc(){
    textureWidth = 64;
    textureHeight = 32;
    
      Legleft = new ModelRenderer(this, 11, 21);
      Legleft.addBox(-1F, 0F, -1F, 2, 6, 2);
      Legleft.setRotationPoint(2F, 18F, 0F);
      Legleft.setTextureSize(64, 32);
      Legleft.mirror = true;
      setRotation(Legleft, 0F, 0F, 0F);
      Legright = new ModelRenderer(this, 29, 21);
      Legright.addBox(-1F, 0F, -1F, 2, 6, 2);
      Legright.setRotationPoint(-2F, 18F, 0F);
      Legright.setTextureSize(64, 32);
      Legright.mirror = true;
      setRotation(Legright, 0F, 0F, 0F);
      Body = new ModelRenderer(this, 14, 10);
      Body.addBox(-3.5F, -3F, -2F, 7, 6, 4);
      Body.setRotationPoint(0F, 15.16667F, 0F);
      Body.setTextureSize(64, 32);
      Body.mirror = true;
      setRotation(Body, 0F, 0F, 0F);
      Head = new ModelRenderer(this, 17, 3);
      Head.addBox(-1.5F, -3F, -1.5F, 3, 3, 3);
      Head.setRotationPoint(0F, 12F, 0F);
      Head.setTextureSize(64, 32);
      Head.mirror = true;
      setRotation(Head, 0F, 0F, 0F);
  }
  
  public void render(Entity par1Entity, float par2, float par3, float par4, float par5, float par6, float par7){
    super.render(par1Entity, par2, par3, par4, par5, par6, par7);
    setRotationAngles(par2, par3, par4, par5, par6, par7, par1Entity);
    Legleft.render(par7);
    Legright.render(par7);
    Body.render(par7);
    Head.render(par7);
  }
  
  private void setRotation(ModelRenderer model, float x, float y, float z){
    model.rotateAngleX = x;
    model.rotateAngleY = y;
    model.rotateAngleZ = z;
  }
  
  
  public void setRotationAngles(float par1, float par2, float par3, float par4, float par5, float par6, Entity par7Entity){
    super.setRotationAngles(par1, par2, par3, par4, par5, par6, par7Entity);
  }
}

 

Class ClientProxy

import com.npctowns.entity.EntityNpc;
import com.npctowns.entity.ModelNpc;
import com.npctowns.entity.RenderNpc;

import cpw.mods.fml.client.registry.RenderingRegistry;

public class ClientProxy extends NpcTownsProxy{

@Override
public void registerRenderers(){
	RenderingRegistry.registerEntityRenderingHandler(EntityNpc.class, new RenderNpc(new ModelNpc(), 0F));
}
}

 

 

Class Main - loadInit() function

    @EventHandler
    public void loadInit(FMLPreInitializationEvent event){
    	
    	MinecraftForge.EVENT_BUS.register(new ChatMessageHandler());
    	MinecraftForge.EVENT_BUS.register(new BasicEventHandler());
    	MinecraftForge.EVENT_BUS.register(new NpcEventHandler());
    	
    	int id=0;
    	EntityRegistry.registerModEntity(EntityNpc.class, "Basic Npc", id, this, 80, 1, true);
    	id++;
    	EntityRegistry.addSpawn(EntityNpc.class, 2, 0, 1, EnumCreatureType.creature, BiomeGenBase.plains);
    	proxy.registerRenderers();
    	
    }

 

Hopefully you can help me, thanks.

 

Oh before I forgot: One more Question! I tried to spawn an entity manually with a wooden hoe inside my eventHandler.

The process itself seems to be working, but the entity is invisible. Code-snippet from my EventHandler-Class:

@Override
@SubscribeEvent
public void onUseHoe(UseHoeEvent event) {
	if(event.current.getItem().equals(Items.wooden_hoe)){
		System.out.println("[ToDev]: Spawning entity!");

		Entity entity;
		entity = new EntityNpc(event.world);
		entity.setPosition(event.x,event.y,event.z);

		event.world.spawnEntityInWorld(entity);
	}
}

Link to comment
Share on other sites

I found the solution for the "entity-spawn-bug".

I added a /mymod spawn command and it worked. Spawned at the players position.

So I thigured out, that the entity was spawned with the hoe, but stuck inside the

block I klicked on (the entity is still 1 block high -.-). So I set y-pos to event.y+1.

 

But now I get another bug: If I spawn an entity with the hoe, It spawned two.

I tried to cancel the event (event.setCanceled(true)) but it still spawn two entitys.

No problem with the spawn command anyway.

Link to comment
Share on other sites

I found the "entity undersized" error and solfed it by myself!

 

I had to change the

public class ModelMyEntity extends ModelBase

to

public class ModelMyEntity extends ModelBiped

and add the variables ModelRenderer Armleft, Armright and init them like the legs.

 

For everyone with the same problem, the corrected ModelMyEntity class:

 

import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelBiped;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;

public class ModelMyEntity extends ModelBiped{

//fields
    ModelRenderer Legleft;
    ModelRenderer Legright;
    ModelRenderer Armleft;
    ModelRenderer Armright;
    ModelRenderer Body;
    ModelRenderer Head;
  
  public ModelNpc(){
    textureWidth = 64;
    textureHeight = 32;
    
      //Legleft
      Legleft = new ModelRenderer(this, 11, 21);
      Legleft.addBox(-1F, 0F, -1F, 2, 6, 2);
      Legleft.setRotationPoint(2F, 18F, 0F);
      Legleft.setTextureSize(64, 32);
      Legleft.mirror = true;
      setRotation(Legleft, 0F, 0F, 0F);
      
      //Legright
      Legright = new ModelRenderer(this, 29, 21);
      Legright.addBox(-1F, 0F, -1F, 2, 6, 2);
      Legright.setRotationPoint(-2F, 18F, 0F);
      Legright.setTextureSize(64, 32);
      Legright.mirror = true;
      setRotation(Legright, 0F, 0F, 0F);
      
      //Armleft
      Armleft = new ModelRenderer(this, 11, 21);
      Armleft.addBox(-1F, 0F, -1F, 2, 6, 2);
      Armleft.setRotationPoint(2F, 18F, 0F);
      Armleft.setTextureSize(64, 32);
      Armleft.mirror = true;
      setRotation(Armleft, 0F, 0F, 0F);

      //Armright
      Armright = new ModelRenderer(this, 29, 21);
      Armright.addBox(-1F, 0F, -1F, 2, 6, 2);
      Armright.setRotationPoint(-2F, 18F, 0F);
      Armright.setTextureSize(64, 32);
      Armright.mirror = true;
      setRotation(Armright, 0F, 0F, 0F);
      
      
      //Body
      Body = new ModelRenderer(this, 14, 10);
      Body.addBox(-3.5F, -3F, -2F, 7, 6, 4);
      Body.setRotationPoint(0F, 15.16667F, 0F);
      Body.setTextureSize(64, 32);
      Body.mirror = true;
      setRotation(Body, 0F, 0F, 0F);
      
      //Head
      Head = new ModelRenderer(this, 17, 3);
      Head.addBox(-1.5F, -3F, -1.5F, 3, 3, 3);
      Head.setRotationPoint(0F, 12F, 0F);
      Head.setTextureSize(64, 32);
      Head.mirror = true;
      setRotation(Head, 0F, 0F, 0F);
  }
  
  @Override
  public void render(Entity par1Entity, float par2, float par3, float par4, float par5, float par6, float par7){
    super.render(par1Entity, par2, par3, par4, par5, par6, par7);
    setRotationAngles(par2, par3, par4, par5, par6, par7, par1Entity);
    Legleft.render(par7);
    Legright.render(par7);
    Armleft.render(par7);
    Armright.render(par7);
    Body.render(par7);
    Head.render(par7);
  }
  
  private void setRotation(ModelRenderer model, float x, float y, float z){
    model.rotateAngleX = x;
    model.rotateAngleY = y;
    model.rotateAngleZ = z;
  }
  
  @Override
  public void setRotationAngles(float par1, float par2, float par3, float par4, float par5, float par6, Entity par7Entity){
    super.setRotationAngles(par1, par2, par3, par4, par5, par6, par7Entity);
  }
}

 

Topic can be closed.

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.

Announcements



×
×
  • Create New...

Important Information

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