Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.10.2] onBlockActivated while sneaking


Daeruin
 Share

Recommended Posts

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;
}

 

Link to comment
Share on other sites

onBlockActivated

hasn't been called when shift-rightclicking for a long time.

Shift-rightclick only activates the item you are holding, unless that specifies to pass it on to the block (the default is not to). If you want to detect it, use

PlayerInteractEvent.RightClickBlock

, but I don't see why you don't just use the normal block drops mechanics for this.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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
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.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.