Jump to content

[1.6.4] [SOLVED] How to get mobs to hold items???


adusut

Recommended Posts

Hello, I have recently created a mob and now I want it to hold an item, e.g sword. I have looked on the internet and in the PigZombie class. I have found this and added it to my code but it doesn't seem to be working:

 

protected void addRandomArmor()

    {

        super.addRandomArmor();

        this.setCurrentItemOrArmor(0, new ItemStack(Item.swordgold));

 

I then found this:

 

private static final ItemStack defaultHeldItem;

   

    public ItemStack getHeldItem()

    {

    return defaultHeldItem;

    }

    static

    {

    defaultHeldItem=new ItemStack(Item.swordGold, 1);

    }

 

This also doesn't work. Any help would be appreciated, thanks.

Link to comment
Share on other sites

I just looked in the RenderBiped class and found this:

 

protected void func_130005_c(EntityLiving par1EntityLiving, float par2)

    {

        float f1 = 1.0F;

        GL11.glColor3f(f1, f1, f1);

        super.renderEquippedItems(par1EntityLiving, par2);

        ItemStack itemstack = par1EntityLiving.getHeldItem();

        ItemStack itemstack1 = par1EntityLiving.func_130225_q(3);

        float f2;

 

        if (itemstack1 != null)

        {

            GL11.glPushMatrix();

            this.modelBipedMain.bipedHead.postRender(0.0625F);

 

            IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer(itemstack1, EQUIPPED);

            boolean is3D = (customRenderer != null && customRenderer.shouldUseRenderHelper(EQUIPPED, itemstack1, BLOCK_3D));

 

            if (itemstack1.getItem() instanceof ItemBlock)

            {

                if (is3D || RenderBlocks.renderItemIn3d(Block.blocksList[itemstack1.itemID].getRenderType()))

                {

                    f2 = 0.625F;

                    GL11.glTranslatef(0.0F, -0.25F, 0.0F);

                    GL11.glRotatef(90.0F, 0.0F, 1.0F, 0.0F);

                    GL11.glScalef(f2, -f2, -f2);

                }

 

                this.renderManager.itemRenderer.renderItem(par1EntityLiving, itemstack1, 0);

            }

            else if (itemstack1.getItem().itemID == Item.skull.itemID)

            {

                f2 = 1.0625F;

                GL11.glScalef(f2, -f2, -f2);

                String s = "";

 

                if (itemstack1.hasTagCompound() && itemstack1.getTagCompound().hasKey("SkullOwner"))

                {

                    s = itemstack1.getTagCompound().getString("SkullOwner");

                }

 

                TileEntitySkullRenderer.skullRenderer.func_82393_a(-0.5F, 0.0F, -0.5F, 1, 180.0F, itemstack1.getItemDamage(), s);

            }

 

            GL11.glPopMatrix();

        }

 

        if (itemstack != null)

        {

            GL11.glPushMatrix();

 

            if (this.mainModel.isChild)

            {

                f2 = 0.5F;

                GL11.glTranslatef(0.0F, 0.625F, 0.0F);

                GL11.glRotatef(-20.0F, -1.0F, 0.0F, 0.0F);

                GL11.glScalef(f2, f2, f2);

            }

 

            this.modelBipedMain.bipedRightArm.postRender(0.0625F);

            GL11.glTranslatef(-0.0625F, 0.4375F, 0.0625F);

 

            IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer(itemstack, EQUIPPED);

            boolean is3D = (customRenderer != null && customRenderer.shouldUseRenderHelper(EQUIPPED, itemstack, BLOCK_3D));

 

            if (itemstack.getItem() instanceof ItemBlock && (is3D || RenderBlocks.renderItemIn3d(Block.blocksList[itemstack.itemID].getRenderType())))

            {

                f2 = 0.5F;

                GL11.glTranslatef(0.0F, 0.1875F, -0.3125F);

                f2 *= 0.75F;

                GL11.glRotatef(20.0F, 1.0F, 0.0F, 0.0F);

                GL11.glRotatef(45.0F, 0.0F, 1.0F, 0.0F);

                GL11.glScalef(-f2, -f2, f2);

            }

            else if (itemstack.itemID == Item.bow.itemID)

            {

                f2 = 0.625F;

                GL11.glTranslatef(0.0F, 0.125F, 0.3125F);

                GL11.glRotatef(-20.0F, 0.0F, 1.0F, 0.0F);

                GL11.glScalef(f2, -f2, f2);

                GL11.glRotatef(-100.0F, 1.0F, 0.0F, 0.0F);

                GL11.glRotatef(45.0F, 0.0F, 1.0F, 0.0F);

            }

            else if (Item.itemsList[itemstack.itemID].isFull3D())

            {

                f2 = 0.625F;

 

                if (Item.itemsList[itemstack.itemID].shouldRotateAroundWhenRendering())

                {

                    GL11.glRotatef(180.0F, 0.0F, 0.0F, 1.0F);

                    GL11.glTranslatef(0.0F, -0.125F, 0.0F);

                }

 

                this.func_82422_c();

                GL11.glScalef(f2, -f2, f2);

                GL11.glRotatef(-100.0F, 1.0F, 0.0F, 0.0F);

                GL11.glRotatef(45.0F, 0.0F, 1.0F, 0.0F);

            }

            else

            {

                f2 = 0.375F;

                GL11.glTranslatef(0.25F, 0.1875F, -0.1875F);

                GL11.glScalef(f2, f2, f2);

                GL11.glRotatef(60.0F, 0.0F, 0.0F, 1.0F);

                GL11.glRotatef(-90.0F, 1.0F, 0.0F, 0.0F);

                GL11.glRotatef(20.0F, 0.0F, 0.0F, 1.0F);

            }

 

            this.renderManager.itemRenderer.renderItem(par1EntityLiving, itemstack, 0);

 

            if (itemstack.getItem().requiresMultipleRenderPasses())

            {

                for (int x = 1; x < itemstack.getItem().getRenderPasses(itemstack.getItemDamage()); x++)

                {

                    this.renderManager.itemRenderer.renderItem(par1EntityLiving, itemstack, x);

                }

            }

 

            GL11.glPopMatrix();

        }

    }

 

    protected void func_82422_c()

    {

        GL11.glTranslatef(0.0F, 0.1875F, 0.0F);

    }

 

Does this have anything to do with it? And if so, how would I use it to render the item?

Link to comment
Share on other sites

This is what I use for my custom-mob that doesn't extend EntitySkeleton lel:

 

//pre-class stuff

private static final ItemStack defaultHeldItem = new ItemStack(Items.bow, 1);

//entity stuff

@Override
public ItemStack getHeldItem() {
     return defaultHeldItem;
}

Very similiar, although, I don't use the static.

Link to comment
Share on other sites

Hi, thanks for reply. I just tried that out in my enitymob class but its still not showing up. Do you have anything special in your render class related to this? I'm not sure why it isn't working for me, thanks.

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.