Jump to content

BlockEvent.BreakEvent problem: Block not replaceable


Alekseyev

Recommended Posts

I have the following code, to check if the player destroyed a stone block while wearing a certain tool (a fire sword), and if that is the case, replace the block in question by lava.

 

@SubscribeEvent
	public void breakBlock(BlockEvent.BreakEvent event)
	{
		System.out.println("Event active: breakBlock");
		if (event.getPlayer().inventory.getCurrentItem().getItem() == ItemInit.SWORD_FIRE)
		{
			System.out.println("Fire Sword found");
			if (event.getState().getBlock() == Blocks.STONE)
			{
				System.out.println("Stone Block found");
				event.getWorld().setBlockState((new BlockPos(event.getPos().getX() + 1, event.getPos().getY(), event.getPos().getZ())), Blocks.LAVA.getDefaultState());
			}
		}
	}

 

However, there is a problem: The code will replace any block, anywhere, just fine, except for the position of the destroyed block. So in the code above, I made it adjust the X position by +1, and it works. If I however do not do that, and use the actual broken block's positon, the lava will simply not be placed.

(I know that the position can be accessed/set much better, but for testing reasons I split up all the coordinates.)

Edited by Alekseyev
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.