Jump to content

Recommended Posts

Posted

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);
	}
}

Posted

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.

Posted

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.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Start by following the docs to get a workspace setup: https://docs.minecraftforge.net/en/latest/gettingstarted/ Then poke around some of the tutorials, https://www.mcjty.eu/docs/1.20/ used to be the goto, but not sure if there are any updates for regular forge or not, but if you've brushed up on Java, it will be enough to get you started. Poke around the Minecraft and Forge sources to see how things are done. Read the FAQ for information on how to post code/logs when you run into issues. Share as much info on issues you have as possible. Use github to host projects, chances of someone helping are higher when they can actually see all your code and/or build it themselves. And finally, keep it on the forums, don't direct message people with questions, most people do not provide personal support like that. Also keep in mind forums posts are not always immediately answered, if you're looking for a quicker response, you can always try the Minecraft Forge discord server.
    • Hello, I have a Forge Minecraft sever (I host it at g-portal.com) which has always worked fine and I had no problems, but today it doesn't wanna work anymore. Today I started the server and the status said online, but after a few seconds it said this: "Start failed". And then out of nowhere it restarted itself and the same thing happened again and again and now it's in an infinite loop where it just keeps failing and then restarts. Here's the download link for the server logs: https://www.mediafire.com/file/sq30dgoonjevib1/2025-07-06-1.log/file Does anyone know how to fix this? If yes I would really appreciate help. Best wishes, Gabs1107
    • I'm experiencing a critical issue on a dedicated Arch Linux server running the latest Forge for Minecraft 1.20.1. When a player exits a Nether portal (not enters, and not via /tp) or teleports into the End via portal, the server completely freezes for 1–10 minutes. During this time, all commands are unresponsive, and the game world essentially locks up. This is with watchdog disabled. Environment: OS: Arch Linux (latest packages) Java: OpenJDK 17 (up to date) Forge Version: Latest 1.20.1 (tested multiple versions from the past ~3 months) Mods: None (issue occurs on a clean install) Server Type: Proxmox VM with: 4 virtual cores 64 GB RAM (63 GB allocated via -Xmx and -Xms flags) Observed Behavior: Observed Behavior: The server freezes for 1–10 minutes when: Exiting a Nether portal (entering does not trigger the issue) Entering or exiting the End using a portal Teleporting using commands (e.g., /tp) works only for the Nether; teleporting to the End via command also causes a freeze The issue occurs anywhere in the world, not tied to specific coordinates or builds During the freeze: The server becomes completely unresponsive to all commands and player actions No crash reports, no errors, and no warnings are logged CPU usage remains under 50%, and RAM usage stays around 6–14 GB After 1–10 minutes, the server recovers automatically and resumes normal operation
    • Hey man, I just found this section in your code.  Try to do this: { "parent": "minecraft:item/generated", "textures": { "layer0": "testmod:item/alexandrite" } } This means your png should be named alexandrite.png. Hope it helps  
  • Topics

×
×
  • Create New...

Important Information

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