Vswe's Summer Courses | You're not logged in. Sign up or log in | Server time: | Donate
One can now see other persons' badge hunts. Simply head over to their profiles to access them.

Go back to course page

The anatomy of a Minecraft model

How to work with and create models for Minecraft

Model doesn't spawn

  • 2014-03-02 23:38:32
    I'm stuck at lectures 1 - Models and Textures
    When I try to spawn my entity it's not appearing. I don't get any errors, just want show up.

    It might be a little syntax error some where or a tiny bit of code missing. I cant figure it out.

    Here is the classes;

    EntityDroid:
    package UU.Model;

    import net.minecraft.entity.Entity;
    import net.minecraft.nbt.NBTTagCompound;
    import net.minecraft.world.World;

        public class EntityDroid extends Entity
        {
            private double startY;
            private double targetY;
            
            public EntityDroid(World world)
            {
                super (world);
            }

        public EntityDroid(World world, double x, double y, double z)
        {
            this(world);
            
            posX = x;
            startY = posY = y;
            posZ = z;
            
        }
        
        @Override
        public void onUpdate() {
            super.onUpdate();
        
            if (!worldObj.isRemote){
                if (targetY == 0 || Math.abs(posY - targetY) < 0.25)
                    {
                            targetY = startY + worldObj.rand.nextDouble() * 5;
                    }
                
                if (posY < targetY)
                {
                    motionY = 0.05;
                }else{
                    motionY = -0.05;
                }
            }    
                setPosition(posX + motionX, posY + motionY, posZ + motionZ);
        }

        @Override
        protected void entityInit()
        {
        
        }

        @Override
        protected void readEntityFromNBT(NBTTagCompound nbttagcompound)
        {
            startY = nbttagcompound.getShort("Start");
            startY = nbttagcompound.getShort("Target");
        }

        @Override
        protected void writeEntityToNBT(NBTTagCompound nbttagcompound)
        {
            nbttagcompound.setShort("Start",(short)startY);
            nbttagcompound.setShort("Target",(short)targetY);
        }

    }

    Entities:

    package UU.Model;

    import cpw.mods.fml.common.registry.EntityRegistry;
    import UU.Technical.Main.UsefulUtilities;

    public class Entities
    {
        public static void init()
        {
            EntityRegistry.registerModEntity(EntityDroid.class, "EntityDroid", 2, UsefulUtilities.instance, 80, 3, true);
        }
        

    }

    RenderDroid:

    package UU.Model;

    import net.minecraft.client.renderer.entity.Render;
    import net.minecraft.entity.Entity;
    import net.minecraft.util.ResourceLocation;

    import org.lwjgl.opengl.GL11;


    public class RenderDroid extends Render
    {
        private ModelDroid model;
        
        public RenderDroid()
        {
            model = new ModelDroid();
            shadowSize = 0.5F;
        }
        
        private static final ResourceLocation texture = new ResourceLocation("exampel", "textures/models/droid.png");
        
        public void renderDroid(EntityDroid droid, double x, double y, double z,
                float yaw, float partialTickTime)
        {
            GL11.glPushMatrix();
            GL11.glTranslatef((float) x,(float) y,(float) z);
            GL11.glScalef(-1F, -1F, 1F);
            
            bindEntityTexture(droid);
            
            model.render(droid, 0F, 0F, 0F, 0F, 0F, 0.0625F);
            
            GL11.glPopMatrix();
        }
        
        @Override
        public void doRender(Entity entity, double x, double y, double z,
                float yaw, float partialTickTime)
        {
            renderDroid((EntityDroid) entity, x, y, z, yaw, partialTickTime);
        }

        @Override
        protected ResourceLocation getEntityTexture(Entity entity)
        {
            return texture;
        }
        
    }

    ItemDroid:

    package UU.Model;

    import net.minecraft.client.renderer.texture.IconRegister;
    import net.minecraft.client.settings.GameSettings;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.item.Item;
    import net.minecraft.item.ItemStack;
    import net.minecraft.world.GameRules;
    import net.minecraft.world.World;
    import UU.Items.TechnicalClass.ItemInfo;
    import UU.Technical.CreativeTab.UUCreativeTabs;
    import cpw.mods.fml.relauncher.Side;
    import cpw.mods.fml.relauncher.SideOnly;

        public class ItemDroid extends Item
        {
            public ItemDroid (int id)
            {
                super(id);
                setCreativeTab(UUCreativeTabs.UUItemsTab);
                setUnlocalizedName(ItemInfo.DroidUnlocalizedName);
            }
            
            @SideOnly(Side.CLIENT)
            public void registerIcons(IconRegister register)
            {
                itemIcon = register.registerIcon(ItemInfo.Texture_Loacation + ":" + ItemInfo.DroidTexture);
            }
            
            @Override
            public boolean onItemUseFirst(ItemStack stack, EntityPlayer player,
                    World world, int x, int y, int z,
                    int side, float hitX, float hitY, float hitZ)
            {
                if (!world.isRemote)
                {
                    world.spawnEntityInWorld(new EntityDroid(world, x + 0.5, y + 0.5, z + 0.5));
                    stack.stackSize--;
                    
                    return true;
                }else{
                    return false;
                }
            }
        }
  • 2014-03-03 11:04:38
    Are you registering the renderer, in the client proxy?
  • 2014-03-03 13:21:45
    Yes, the client proxy looks like this:

    package UU.Technical.Proxies;

    import UU.Model.EntityDroid;
    import UU.Model.RenderDroid;
    import cpw.mods.fml.client.registry.RenderingRegistry;

    public class ClientProxy extends CommonProxy
    {
        @Override
        public void initSounds()
        {
                //Sounds
        }

        @Override
        public void initRenders()
        {
                RenderingRegistry.registerEntityRenderingHandler(EntityDroid.class, new RenderDroid());
        }

    }


  • 2014-03-03 15:27:15
    I would recommend putting printLns in the entity and rendering , to check to see if the entity is created and to see if the entity is being rendered.

    Also are you calling the initRendering() in your mod base class?
  • 2014-03-03 18:30:48
    Also use the F3 in game debug screen to see if the entity is actually there and it is not rendered, or if it is never spawned
  • 2014-03-05 16:18:30
    I tried debugging this error a long while now, just going to clean up the workspace and try again. Thanks for the help anyway!
  • Log in or sign up to reply to this thread