Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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!

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...

  • Author

ya I made an edit before I saw your post :P I figured it out. I already had a world variable declared so I just moved around my code to create the world.isRemote if statement :P

Bumper Cars!

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...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.