Posted March 27, 201312 yr 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!
March 27, 201312 yr 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...
March 27, 201312 yr Author ya I made an edit before I saw your post 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 Bumper Cars!
March 27, 201312 yr 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.