Posted April 1, 20178 yr I have an item tool that extends ItemPickaxe. Every method I override gets called twice. No matter which method it is. For example override def onBlockDestroyed (stack: ItemStack, worldIn: World, state: IBlockState, pos: BlockPos, entityLiving: EntityLivingBase): Boolean = { System.out.println ("Block destroyed") return true; } It doesn't matter if I return true or false. Neither it matters if I call super. It always gets called twice. This is Scala, but it also happens if I use Java. I take it the language doesn't matter. If I do override def onItemUse(player: EntityPlayer, worldIn: World, pos: BlockPos, hand: EnumHand, facing: EnumFacing, hitX: Float, hitY: Float, hitZ: Float): EnumActionResult = { System.out.println ("Item used") return EnumActionResult.SUCCESS } It also happens. Regardless of returning EnumActionResult.SUCCESS or EnumActionResult.FAIL or calling super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ). I get double code execution. All overridden methods are called twice. Is there any fix for this? Edited April 1, 20178 yr by ctbe Language code syntax highlighter change
April 1, 20178 yr Author Thanks. I still don't know how to use it though. A little help would be appreciated.
April 1, 20178 yr Author Thanks. If I do override def onBlockDestroyed(stack: ItemStack, worldIn: World, state: IBlockState, pos: BlockPos, entityLiving: EntityLivingBase): Boolean = { if (worldIn.isRemote) { System.out.println("Block destroyed") return true } return false } Then it gets executed only once. Fixing my original problem. But now I have another doubt. Does this means that if someone installs my mod on a server, that println in this specific code or whatever is inside will not execute? I ask because according to https://mcforge.readthedocs.io/en/latest/concepts/sides/ Quote It follows that the physical server will always contain false in this field... And the definition of physical server is Quote Often known as the dedicated server, the physical server is the entire program that runs whenever you launch any sort of minecraft_server.jar that does not bring up a playable GUI. I'm not sure if I should post a new thread for this other question that arose connected to my original problem since my original problem is solved.
April 1, 20178 yr Quote /** * True if the world is a 'slave' client; changes will not be saved or propagated from this world. For example, * server worlds have this set to false, client worlds have this set to true. */ the javadoc for isRemote if you want it on the server side you need to do it like so if (!worldIn.isRemote)
April 1, 20178 yr Author I understand. Thanks for your help. Edited April 1, 20178 yr by ctbe Fixed typo in *your
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.