How to create PlayerRelativeBlockHardness to allow for the block "owner" to be able to break the block easily

Started by communistkarl on

Topic category: Help with modding (Java Edition)

Last seen on 01:53, 4. Apr 2020
Joined Apr 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How to create PlayerRelativeBlockHardness to allow for the block "owner" to be able to break the block easily

How to create PlayerRelativeBlockHardness to allow for the block "owner" to be able to break the block easily while the public hardness is very high.

 

Player A places block. RelativeBlockHardness is set on place event -> Block is easy to break for Player A

Last seen on 23:11, 16. Jul 2023
Joined Sep 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Get the display name of…
Sun, 08/23/2020 - 14:52

Get the display name of whoever placed the block, then make the block unbreakable and put in "when player starts to destroy" if the display name is the same, destroy the block and spawn gem

Last seen on 18:54, 23. Aug 2023
Joined Jun 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
To expand on Dansamy's…
Sun, 08/23/2020 - 19:26

To expand on Dansamy's response as it was a little short, what you could do is store an NBT tag on the block when it's placed by the player, that NBT tag being a string called something like "playerName" which stores the name of the player who placed it. Then when a player tries to break the block, check if the "playerName" NBT tag is equal to the player destroying it. If it is, allow them to break it. If not, either make the block unbreakable, or allow them to break the block, but respawn the block right after being broken and not drop the item.