Jump to content

Trying to render weapon for custom mob


Greenman284

Recommended Posts

Hello all,

 

I recently got my custom mob working with model and texture, and now want it to hold a weapon.  I'm going to make a custom sword, but in the meantime I thought I would use a regular stone sword.  Unfortunately, for some reason, my mob holds out his hand, as if he was holding an item, but there is nothing in the hand.  Below will be the Entity****.java class:

 

 

package timescape.entity;

 

import net.minecraft.entity.Entity;

import net.minecraft.entity.EntityAgeable;

import net.minecraft.entity.EnumCreatureAttribute;

import net.minecraft.entity.ai.EntityAIAttackOnCollide;

import net.minecraft.entity.ai.EntityAIFollowParent;

import net.minecraft.entity.ai.EntityAIHurtByTarget;

import net.minecraft.entity.ai.EntityAILookIdle;

import net.minecraft.entity.ai.EntityAIMate;

import net.minecraft.entity.ai.EntityAINearestAttackableTarget;

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.monster.EntityMob;

import net.minecraft.entity.passive.EntityAnimal;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraft.world.World;

 

 

public class EntityNutcracker extends EntityMob

{

 

public EntityNutcracker(World world)

        {

                super(world);

                this.texture = "/mods/Nutcracker.png";

                this.getNavigator().setAvoidsWater(true);

                this.isImmuneToFire = false;

                this.moveSpeed = 0.25F;

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

                this.tasks.addTask(2, new EntityAIAttackOnCollide(this, EntityPlayer.class, this.moveSpeed, false));

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

                this.tasks.addTask(4, new EntityAIWander(this, this.moveSpeed));

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

                this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, false));

                this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, 16.0F, 0, true));

        }

 

        public boolean isAIEnabled()

        {

        return true;

        }

     

        public int getMaxHealth()

        {

                return 20;

        }

       

        protected void addRandomArmor()

        {

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

        }

           

        public EnumCreatureAttribute getCreatureAttribute()

        {

        return EnumCreatureAttribute.UNDEAD;

        }

        protected String getLivingSound()

        {

                return "mob.endermen.idle";

        }

       

        protected String getHurtSound()

        {

                return "mob.endermen.hit";

        }

       

        protected String getDeathSound()

        {

                return "mob.endermen.death";

        }

 

        protected void playStepSound(int par1, int par2, int par3, int par4)

        {

                this.worldObj.playSoundAtEntity(this, null, 0.15F,  1.0F);

        }

       

        protected int getDropItemId()

        {

                return Item.swordStone.itemID;

        }

       

        public EntityAgeable createChild1(EntityAgeable var1)

        {

                return null;

        }

        public ItemStack getHeldItem()

        {

                return defaultHeldItem;

        }

               

                static

        {

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

        }

               

        private static final ItemStack defaultHeldItem;

       

        @Override

protected boolean isValidLightLevel()

{

    return true;

}

}

 

 

Any help would be greatly appreciated.

 

Greenman

Link to comment
Share on other sites

Ah, my bad.  In that case, I haven't done anything to the render class, but here it is anyways:

 

 

package timescape.render;

 

import timescape.ModelNutcracker;

import timescape.entity.EntityNutcracker;

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

import net.minecraft.client.model.ModelBase;

import net.minecraft.client.model.ModelEnderman;

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

import net.minecraft.entity.Entity;

import net.minecraft.entity.EntityLiving;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

 

@SideOnly(Side.CLIENT)

public class RenderNutcracker extends RenderLiving

{

        public RenderNutcracker(ModelNutcracker ModelNutcracker_Test, float f)

        {

                super(new ModelNutcracker(), 0.5F);

        }

        public RenderNutcracker(ModelBase par1ModelBase, float par2)

        {

                super(par1ModelBase, par2);

        }

        public void RenderNutcracker(EntityNutcracker par1EntityNutcracker, double par2, double par4, double par6, float par8, float par9)

        {

                super.doRenderLiving(par1EntityNutcracker, par2, par4, par6, par8, par9);

        }

        public void doRenderLiving(EntityLiving par1EntityLiving, double par2, double par4, double par6, float par8, float par9)

        {

                this.RenderNutcracker((EntityNutcracker)par1EntityLiving, par2, par4, par6, par8, par9);

        }

        public void doRender(Entity par1Entity, double par2, double par4, double par6, float par8, float par9)

        {

                this.RenderNutcracker((EntityNutcracker)par1Entity, par2, par4, par6, par8, par9);

        }

}

 

Link to comment
Share on other sites

Alright, so I found another tut to try working off of, and I got the entity*** to this:

 

 

package timescape.entity;

 

import net.minecraft.entity.Entity;

import net.minecraft.entity.EntityAgeable;

import net.minecraft.entity.EnumCreatureAttribute;

import net.minecraft.entity.ai.EntityAIAttackOnCollide;

import net.minecraft.entity.ai.EntityAIFollowParent;

import net.minecraft.entity.ai.EntityAIHurtByTarget;

import net.minecraft.entity.ai.EntityAILookIdle;

import net.minecraft.entity.ai.EntityAIMate;

import net.minecraft.entity.ai.EntityAINearestAttackableTarget;

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.monster.EntityMob;

import net.minecraft.entity.passive.EntityAnimal;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraft.world.World;

 

public class EntityNutcracker extends EntityMob

{

 

public EntityNutcracker(World world)

        {

                super(world);

                this.texture = "/mods/Nutcracker.png";

                this.getNavigator().setAvoidsWater(true);

                this.isImmuneToFire = false;

                this.moveSpeed = 0.25F;

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

                this.tasks.addTask(2, new EntityAIAttackOnCollide(this, EntityPlayer.class, this.moveSpeed, false));

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

                this.tasks.addTask(4, new EntityAIWander(this, this.moveSpeed));

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

                this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, false));

                this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, 16.0F, 0, true));

        }

 

        public boolean isAIEnabled()

        {

        return true;

        }

     

        public int getMaxHealth()

        {

                return 20;

        }

       

        protected void addRandomArmor()

        {

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

        }

           

        public EnumCreatureAttribute getCreatureAttribute()

        {

        return EnumCreatureAttribute.UNDEAD;

        }

        protected String getLivingSound()

        {

                return "mob.endermen.idle";

        }

       

        protected String getHurtSound()

        {

                return "mob.endermen.hit";

        }

       

        protected String getDeathSound()

        {

                return "mob.endermen.death";

        }

 

        protected void playStepSound(int par1, int par2, int par3, int par4)

        {

                this.worldObj.playSoundAtEntity(this, null, 0.15F,  1.0F);

        }

       

        protected int getDropItemId()

        {

                return Item.swordStone.itemID;

        }

       

        public EntityAgeable createChild1(EntityAgeable var1)

        {

                return null;

        }

        public ItemStack getHeldItem()

        {

        return heldItem;

        }

       

        private static ItemStack heldItem = new ItemStack(Item.swordStone);

        @Override

      protected boolean isValidLightLevel()

{

    return true;

}

}

 

 

And I understand that I need to render getHeldItem, but I can`t for the life of me figure out what exact line of code I would put in.

 

EDIT: So I think I found something that MAY render it, but the this.func_82428_a has an error.

 

RenderNutcracker.java

 

package timescape.render;

 

import java.awt.geom.Arc2D.Float;

 

import timescape.ModelNutcracker;

import timescape.entity.EntityNutcracker;

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

import net.minecraft.client.model.ModelBase;

import net.minecraft.client.model.ModelEnderman;

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

import net.minecraft.entity.Entity;

import net.minecraft.entity.EntityLiving;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

 

@SideOnly(Side.CLIENT)

public class RenderNutcracker extends RenderLiving

{

        public RenderNutcracker(ModelNutcracker ModelNutcracker_Test, float f)

        {

                super(new ModelNutcracker(), 0.5F);

        }

        public RenderNutcracker(ModelBase par1ModelBase, float par2)

        {

                super(par1ModelBase, par2);

        }

        public void RenderNutcracker(EntityNutcracker par1EntityNutcracker, double par2, double par4, double par6, float par8, float par9)

        {

                super.doRenderLiving(par1EntityNutcracker, par2, par4, par6, par8, par9);

        }

        public void doRenderLiving(EntityLiving par1EntityLiving, double par2, double par4, double par6, float par8, float par9)

        {

                this.RenderNutcracker((EntityNutcracker)par1EntityLiving, par2, par4, par6, par8, par9);

        }

        public void doRender(Entity par1Entity, double par2, double par4, double par6, float par8, float par9)

        {

                this.RenderNutcracker((EntityNutcracker)par1Entity, par2, par4, par6, par8, par9);

        }

        protected void renderEquippedItems(EntityLiving par1EntityLiving, float par2)

        {

        this.func_82428_a((EntityNutcracker)par1EntityLiving, par2);

        }

}

 

Link to comment
Share on other sites

So, my friend, if you are talking about HOLDING an ItemStack, you must add, at least, two methods, the EqquipedTems stuff, and the RenderCarrying. You can see they at the EnderMan renderer

 

Look, about that function stuff, you will substitute it to your RenderCarrying, thats the thing, got it?

 

Link to comment
Share on other sites

I took those two things (EquippedItems and RenderCarrying) and I input them into the render***.java class.  This is what it look like:

 

 

package timescape.render;

 

import java.awt.geom.Arc2D.Float;

 

import timescape.ModelNutcracker;

import timescape.entity.EntityNutcracker;

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

import net.minecraft.client.model.ModelBase;

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

import net.minecraft.entity.Entity;

import net.minecraft.entity.EntityLiving;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

 

@SideOnly(Side.CLIENT)

public class RenderNutcracker extends RenderLiving

{

        public RenderNutcracker(ModelNutcracker ModelNutcracker_Test, float f)

        {

                super(new ModelNutcracker(), 0.5F);

        }

        public RenderNutcracker(ModelBase par1ModelBase, float par2)

        {

                super(par1ModelBase, par2);

        }

        public void RenderNutcracker(EntityNutcracker par1EntityNutcracker, double par2, double par4, double par6, float par8, float par9)

        {

                super.doRenderLiving(par1EntityNutcracker, par2, par4, par6, par8, par9);

        }

        public void doRenderLiving(EntityLiving par1EntityLiving, double par2, double par4, double par6, float par8, float par9)

        {

                this.RenderNutcracker((EntityNutcracker)par1EntityLiving, par2, par4, par6, par8, par9);

        }

        public void doRender(Entity par1Entity, double par2, double par4, double par6, float par8, float par9)

        {

                this.RenderNutcracker((EntityNutcracker)par1Entity, par2, par4, par6, par8, par9);

        }

        protected void renderCarrying(EntityNutcracker par1EntityNutcracker, float par2)

        {

            super.renderEquippedItems(par1EntityNutcracker, par2);

}

}

 

 

However, the sword still doesn't render with the mob.

Link to comment
Share on other sites

Heey, now i see that you mean a sword hehe, i will try to explain it

 

 

Well, i dont like messing up with these func12346969 i really dont like them.

But the only thing that i can tell you, is that in the Zombie, when you add that func stuff in the EquipedItems, you add a void method about it also. Example:

 

public void func123 (stuff par1stuff....)

.

.

.

renderEquiperItems(stuff)

func123(blabla)

Link to comment
Share on other sites

I didn't really understand that, so let me clarify exactly what I want to do.

 

I want a custom mob (with custom model) to render(already done), but I want to render a weapon for it at the same time (eg: sword)

 

However, as I don't understand functions either, I would prefer to stay away from them.  There must be another way, like what Newt was talking about.  Could either of you explain what YOU would personally use to render a weapon for a mob?

 

Thanks again for all the help I'm getting.

Link to comment
Share on other sites

Still can't figure it out for the life of me :P

 

If anyone has any ideas about this, please hit me with everything you've got.  ;)

*throws several thermonuclear bombs and a can of Coke at Greenman*

 

I assure you, that would solve your problem, and in fact ensure that you don't have any problems anymore. ;D

BEWARE OF GOD

---

Co-author of Pentachoron Labs' SBFP Tech.

Link to comment
Share on other sites

Still can't figure it out for the life of me :P

 

If anyone has any ideas about this, please hit me with everything you've got.  ;)

*throws several thermonuclear bombs and a can of Coke at Greenman*

 

I assure you, that would solve your problem, and in fact ensure that you don't have any problems anymore. ;D

 

wha...well played Newt, well played.

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.