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

I override the method onItemUse() for my own item. This is what it looks like:  

@Override
	/**
     * Called when a Block is right-clicked with this Item
     */
    public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
    {
		if (imageName != null && colorMatrix != null) {
				for (int i = 0; i < colorMatrix.length; i++) {
					// build each line of the blockMatrix
					for (int j = 0; j < colorMatrix[0].length; j++) {
					
						if (colorMatrix[i][j] != null)
							worldIn.setBlockState(new BlockPos(pos.getX() + j, pos.getY() + 1, pos.getZ() + i), Blocks.WOOL.getDefaultState().withProperty(COLOR, colorMatrix[i][j]));
						else
							worldIn.setBlockState(new BlockPos(pos.getX() + j, pos.getY() + 1, pos.getZ() + i), Blocks.TNT.getDefaultState());
					}
				}
                    		System.out.println("TEST TEST TEST");
				player.sendMessage(new TextComponentString("Image build successfully!"));
		} else {
			player.sendMessage(new TextComponentString("There was an error building your image. Image name: " + imageName + "; colorMatrix: " + colorMatrix));
		}
			
		return EnumActionResult.PASS;
    }

Whenever I right click with my Item, some blocks are placed after which the message "Image build successfully" is displayed twice in the in game chat.  

If there is an error, the error message is also displayed twice.  

The console output looks like this:  

[16:53:44] [main/INFO] [STDOUT]: [me.opkekz.imagespawner.item.ImageSpawnerItem:onItemUse:91]: TEST TEST TEST
[16:53:44] [main/INFO] [minecraft/GuiNewChat]: [CHAT] Image build successfully!
[16:53:44] [Server thread/INFO] [STDOUT]: [me.opkekz.imagespawner.item.ImageSpawnerItem:onItemUse:91]: TEST TEST TEST
[16:53:44] [main/INFO] [minecraft/GuiNewChat]: [CHAT] Image build successfully!

This means that the onItemUse() method is being called twice. What could cause this?  

If you need any more information please let me know.

 

Thanks in advance.

The method is called twice indeed, once on the server, once on the client as you can see from your console output.

 

Also:

39 minutes ago, Kekz said:

if (imageName != null && colorMatrix != null) {

If these are fields stored in your items then you can't do that since items are singletons. 

  • Author
4 minutes ago, V0idWa1k3r said:

The method is called twice indeed, once on the server, once on the client as you can see from your console output.

How can I prevent that? The method spawns a lot of blocks and having that done twice would be very costly. Or does it have to be called twice?

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.