Jump to content

[1.11.2] Overridden methods being called twice


ctbe

Recommended Posts

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 by ctbe
Language code syntax highlighter change
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.