Get Dataquery from block


#1

i try to put dataquery to block with place event smth like

BlockSnapshot block = event.getTransactions().get(0).getFinal();
block.toContainer().set(DataQuery.of(“UnsafeData”,“reg”), “reg”);
event.getTransactions().get(0).setCustom(block);

and check on break event but seem not work
anyone have good way to detect ?

: i try to do auto regenerate block but i don’t know how to point block that need to regenerate


#2

BlockSnapshot is immutable i.e. you cannot change an existing one.
You need to create a new BlockSnapshot with the new data, like this:

BlockSnapshot block = event.getTransactions().get(0).getFinal();
BlockSnapshot newBlock = block.withContainer(block.toContainer().set(DataQuery.of("UnsafeData","reg"), "reg"));
event.getTransactions().get(0).setCustom(newBlock);

#3

Thx for help
but now i try to figure out how to detect with breakblock event
i try

player.sendMessage(Text.of(event.getTransactions().get(0).getOriginal().toContainer().get(DataQuery.of(“UnsafeData”, “reg”)).get().toString()));

but seem not work
ERROR log : https://pastebin.com/qPDdMf3c

**i try to check present but it not present how can i get dataquery from block


#4

What block type are you trying this with?
Custom data containers only work on tile entities due to tile entities having NBT, whereas non-TE blocks don’t store any NBT.


#5

Thx for reply that what i thought cus NBT seem store in tile thing
i will find different way