How to create a Key.builder()?


[Google trad]
I would like to know if with Key.builder() one can create a key which stores in one block a BlockType of another block or a string like value?
I can not find an example to do it.
Thank you


j’aimerais savoir si avec Key.builder() on peut créer une clé qui stocke dans un bloc un BlockType d’un autre bloc ou une chaine de caractère comme valeur ?

Je ne trouve pas d'exemple pour le faire.



Here is a good example of how to make your own custom keys. Its by @pie_flavor


[Google trad]
I can have an example please, I really can not do it.

Je peux avoir un exemple SVP, je n’y arrive vraiment pas.


That was an example. This is the file with the keys.

[Google translate]
chapeau était un exemple. Ceci est le fichier avec les clés.


[Google translate]
I saw this file, but the key does not add:

J’ai vu ce fichier, mais la clé ne s’ajoute pas:

        BlockState bloc = player.getLocation().getBlock();
        Key<Value<String>> DATA = Key.builder()
                .name("Block Origin ID")
                .query(DataQuery.of('.', "block_origin_id"))
        bloc.with(DATA, "test");

        if(bloc.get(DATA).isPresent()) {
            Tool.getLogger().info("DATA => " + player.get(DATA).get());


Its sadly not that simple. You need a mutableDataManipulator and an ImmutableDataManipulator as well as a builder and you need to register the 3 as well as the key to get it to work.

This is the french version of the sponge docs on the page that tells you how it works.


Unfortunately, you can’t add custom data to a BlockState. You can only add custom data to ItemStack, Entity, and TileEntity.