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

In 1.8.9, I had a container that, when shift-right-clicked, would drop the item version of the block as if it had been broken and save the inventory. I achieved this by using the onBlockActivated method. In 1.10.2, this no longer works, as it seems onBlockActivated is no longer called when shift-right-clicking the block. What changed? How can I get this to behave like it used to?

 

Here's my onBlockActivated method, if it matters:

 

@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ)
{
	if (!world.isRemote)
	{
		if (player.isSneaking())
		{
			PrimalTileEntitySmall te = world.getTileEntity(pos) instanceof PrimalTileEntitySmall ? (PrimalTileEntitySmall) world.getTileEntity(pos) : null;
			dropContainerWithInventory(world, pos, state, player, te);
		} else
			player.openGui(Primalcraft.instance, PrimalGuiHandler.GUI_BASKET_SMALL, world, pos.getX(), pos.getY(), pos.getZ());
	}
	return true;
}

 

  • Author

The idea is that it's a small block that the player should just be able to "pick up" whenever they want, without "breaking" it. But I also want them to be able to break it, if they really want to destroy the block. It was definitely working before, but I remember now that I had to tweak some of the other methods as well. I wonder what changed. I guess I'll try PlayerIntractEvent.

  • Author

To get it to work even while holding something in the left hand, I had to use PlayerInteractEvent. It seems to be working smoothly now. In PlayerInteract, I check if the player is sneaking and if the target is an instance of my container. Then I do event.setUseBlock(Result.ALLOW) which calls onBlockActivated.

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.