Posted December 4, 20168 yr 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; }
December 5, 20168 yr 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.
December 5, 20168 yr Author After a bit more research, I found this page: https://gist.github.com/williewillus/c781d9824df3ae723bff ...which explains that onBlockActivated is indeed called when sneaking, but only if both hands are empty. That's why it was working for me before, and it actually still works that way now.
December 5, 20168 yr 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.