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

Forging a Minecraft mod

Basic Minecraft modding with Minecraft Forge

check for which entity

  • 2013-07-16 14:16:08
    so i tried to make the wand kill a zombie when klicked on it. the only problem is how i check that my target is actually a zombie? i got this code so far:
    public boolean hitEntity(ItemStack itemstack, EntityLivingBase player, EntityLivingBase target){
            if(!target.worldObj.isRemote){
                if(target.isEntityEqual(//zombie)){
    //fun stuff
    }
            }        
            return false;    
         }
  • 2013-07-16 14:27:07
    if (target instanceof EntityZombie) {

    }
  • 2013-07-16 14:37:47
    thanks
  • 2013-07-16 14:41:17
    only one problem, it doesn't work when i click did i call the worng method? (its in the item's class)

    public boolean hitEntity(ItemStack itemstack, EntityLivingBase player, EntityLivingBase target){
            if(!target.worldObj.isRemote){
                if (target instanceof EntityZombie) {
                    target.isDead = true;
                }

            }    
            return false;    
            }
  • 2013-07-16 14:58:40
    solved it, now using this method:
    public boolean onLeftClickEntity(ItemStack stack, EntityPlayer player, Entity target){
            if(!target.worldObj.isRemote){
                if (target instanceof EntityZombie) {
                    target.isDead = true;
                }            
            }        
    return false;
    }
  • 2013-07-16 19:53:06
    Have a look at the this thread: http://courses.vswe.se/?course=3&lecture=24&thread=65

    Basically, you can also use hitEntity, but the parameters target and player are reversed there.
  • 2013-07-17 09:22:54
    remember to use @Override so that you will know if you have override the method or not.
  • Log in or sign up to reply to this thread