Getting a blocks block entity

Started by pottassination on

Topic category: Help with Minecraft modding (Java Edition)

Joined May 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Getting a blocks block entity
Mon, 03/02/2026 - 04:03 (edited)

I'm trying to read an nbt tag of a block in a "block destroyed by player" function, but it seems the function is triggered after the block is removed and there isn't a code block that can get the nbt data of a block entity without getting the block entity through a given position. I dug a little and found the passed blockstate dependency can give the block itself, but it seems the 'Block' and 'BlockEntity' classes are completely separate and I can't find anything that links the two.

I feel like maybe I can re-place the block because the block is getting replaced based on the read data anyway, though I don't know if the block entity data will persist.

Editing the code for the blocks "block destroyed by player" function to just execute my function could also work, but I don't want to have to do this for every block.

Any help would be appreciated.

Edited by pottassination on Mon, 03/02/2026 - 04:03
Joined Feb 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Maybe try canceling the…
Mon, 03/02/2026 - 18:44

Maybe try canceling the trigger, read the nbt tag, and then break the block 

Joined May 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
It does work to just go to…
Tue, 03/03/2026 - 16:46

It does work to just go to the code for the block and comment out the "super.onDestroyedByPlayer(blockstate, world, pos, entity, willHarvest, fluid)" function call, but I feel like it would be more convenient to try to keep it in my function rather than editing every blocks code.

If you are talking about the "set cancelation of event (bool)" code block, that gave me an error when I tried to use it.


If you are not talking about that code block or editing the blocks code, I'd appreciate more details.