CatalogType vers BlockState


Bonjour, ce code fonctionne pas, il ne place pas le bloc, une solution ?

[google trad]
Hello, this code does not work, it does not place the block, a solution?

    Player player = (Player) sender;
    CatalogType bloc = args.<CatalogType>getOne("bloc").get();
    String blocId = bloc.getId();


    if(getGame().getRegistry().getType(BlockState.class, blocId).isPresent()) {
        Sponge.getLogger().debug("Bloc placé");
        BlockState b = Sponge.getGame().getRegistry().getType(BlockState.class, blocId).get();

        Location<World> location = new Location<World>(player.getWorld(), player.getPosition().sub(0, 0, 1));
    } else {


You can request a specific argument of BlockState instead of CatalogType, that way you have tab completion for the player to use to get the desired block state.

So in code:

Player player = (Player) sender;
BlockState state = args.<BlockState>getOne("bloc").get();

Can’t remember if Location specifically. has methods like that, but that should work in theory.


Avec ceci ?

.arguments(GenericArguments.onlyOne(GenericArguments.catalogedElement(Text.of(“bloc”), CatalogTypes.BLOCK_TYPE)))


Yep, that will work.

Oui, ça va marcher.


Cela ne fonctionne pas:

BlockState state = args.<BlockState>getOne(“bloc”).get();

.arguments(GenericArguments.onlyOne(GenericArguments.catalogedElement(Text.of(“bloc”), CatalogTypes.BLOCK_TYPE)))

Error occurred while executing command ‘test3 minecraft:stone’ for source EntityPlayerMP[‘SimonBHB’/353, l=‘monde’, x=-109,97, y=67,00, z=293,01]: net.minecraft.block.BlockStone cannot be cast to org.spongepowered.api.block.BlockState
java.lang.ClassCastException: net.minecraft.block.BlockStone cannot be cast to org.spongepowered.api.block.BlockState


Remplace CatalogTypes.BLOCK_TYPE par BlockState.class


Ca fonctionne, mais quand j’appuie sur la touche tab ça écrit tout seul: /test3 minecraft: et le jeu crash.