Jump to content

Recommended Posts

Posted

So I have this code on my custom sword

 

    public boolean hitEntity(ItemStack par1ItemStack, EntityLiving par2EntityLiving, EntityLiving par3EntityLiving)
    {
    	Random rand = new Random();
   	int chance = (1 + rand.nextInt(100));
   	World world = par3EntityLiving.worldObj;
   	if(chance <= {
   		par1ItemStack.damageItem(100, par3EntityLiving);
       	par2EntityLiving.addPotionEffect(new PotionEffect(Potion.wither.getId(), 100, 7));
       	par2EntityLiving.entityDropItem(new ItemStack(mod_MainClass.BlinShard, 1),  1.0f);
        	
    }else{
    	par1ItemStack.damageItem(1, par3EntityLiving);
    }
        return true;
    }

 

And sometimes it'll spawn an extra item that can't be picked up. I thought it would use world.isRemote but this specific method doesn't use world in it. So I am at a loss at what could be causing a ghost item to appear.

 

EDIT:

I just derped. I realised I did declare a world variable and changed my code to this

    public boolean hitEntity(ItemStack par1ItemStack, EntityLiving par2EntityLiving, EntityLiving par3EntityLiving)
    {
   	World world = par3EntityLiving.worldObj;
    	if (world.isRemote)
    	{
    		return true;
    	}else{
    	Random rand = new Random();
	   	int chance = (1 + rand.nextInt(100));
	   	if(chance <= {
	   		par1ItemStack.damageItem(100, par3EntityLiving);
	       	par2EntityLiving.addPotionEffect(new PotionEffect(Potion.wither.getId(), 100, 7));
	       	par2EntityLiving.entityDropItem(new ItemStack(mod_MainClass.BlinShard, 1),  1.0f);
	        	
	    }else{
	    	par1ItemStack.damageItem(1, par3EntityLiving);
	    }
        return true;
    }
    }

Bumper Cars!

Posted

you need to use world.isRemote so you only spawn entity's on the server side :)

 

It's true that you don't get served a world Object inn the parameters, but ya know what?

You do gets Entity's which live inside the world, so you can check what world they are inn and use that world object to do the check :)

If you guys dont get it.. then well ya.. try harder...

Posted

hehe good good <3

Then you can mark this as solved by putting [solved] inn your title and lock the thread.

This makes it easier for people using the search function to find solutions to the same problem :)

thanks :)

If you guys dont get it.. then well ya.. try harder...

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.