How to create a Key.builder()?


#1

[Google trad]
Hello,
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

Bonjour,

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.

Merci


#2

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

https://github.com/pie-flavor/ExampleDataPlugin?files=1


#3

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

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


#4

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.


#5

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

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

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

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

#6

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.

https://docs.spongepowered.org/stable/fr/plugin/data/custom/index.html


#7

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