Bloc non placé

Bonjour, j’essaye de placer un bloc de diamant pour le test(normalement une torche) et il est jamais placé. Est ce un bug ?

translate.google.fr:
Hello, I am trying to place a diamond block for the test (normally a torch) and it is never placed. Is this a bug?

    event.getCause().getContext().get(EventContextKeys.BLOCK_HIT).ifPresent(block_hit -> {
        if(block_hit.getLocation().isPresent()) {
            Location<World> loc = block_hit.getLocation().get();

            if(block_hit.getState().getType().equals(BlockTypes.GRAVEL)) {
                Location<World> newLoc = loc.add(0, 1, 0);
                Tool.getLogger().info(loc.getPosition().toInt().toString() + " " + block_hit.getState().getType().getId() + " - " + newLoc.getPosition().toInt().toString() + " " + newLoc.getBlock().getType().getId());

                if(newLoc.getBlock().getType().equals(BlockTypes.GRAVEL)) {
                    loc.setBlockType(BlockTypes.DIAMOND_BLOCK); // <= Jamais placé
                    Tool.getLogger().info("setBlock " + loc.getPosition().toInt().toString() + " getBlockType: " + loc.getBlockType().getId()); // log bloc

                    loc.add(0,0,1).setBlockType(BlockTypes.IRON_BLOCK); // test
                    loc.sub(0,0,1).setBlockType(BlockTypes.REDSTONE_BLOCK); // test
                    loc.sub(0,1,0).setBlockType(BlockTypes.GOLD_BLOCK); // test
                }
            }
        }
    });

log:

[14:03:02] [Server thread/INFO] [admintool]: (-70, 89, -28) minecraft:gravel - (-70, 90, -28) minecraft:gravel
[14:03:02] [Server thread/INFO] [admintool]: setBlock (-70, 89, -28)
[14:03:02] [Server thread/INFO] [admintool]: minecraft:diamond_block

up svp, comment je dois faire ?

Le bloc est jamais placé:

@Listener
public void ChangeBlockBreak2(ChangeBlockEvent.Break event) {
    if(event.getCause().first(Player.class).isPresent()) {
        Player player = event.getCause().first(Player.class).get();
        for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
            if(Blocks.isWood(transaction.getOriginal().getState().getType())) {
                Optional<BlockState> getSaplingOptional = Blocks.getSapling(transaction.getOriginal());

                getSaplingOptional.ifPresent(blockState -> {
                    transaction.getFinal().getLocation().ifPresent(location -> {
                        Tool.getLogger().info("setBlock: " + transaction.getOriginal().getState().getType().getId());
                        location.setBlock(blockState);
                        Tool.getLogger().info("location.getBlockType(): " + location.getBlockType().getId());
                    });
                });
            }
        }
    }
}

mais en log oui:
[12:13:53] [Server thread/INFO] [simpledestroyblock]: setBlock: minecraft:log2
[12:13:53] [Server thread/INFO] [simpledestroyblock]: location.getBlockType(): minecraft:sapling

Quand je mets ce code cela place le bloc:

                        Sponge.getScheduler().createTaskBuilder().execute(var -> {
                            location.setBlock(blockState);
                            var.cancel();
                        }).delayTicks(2).submit(Tool.getInstance());

Pourquoi ?

If I understood everything correctly, you can’t replace a broken block during ChangeBlockEvent.Break with some other? Try replacing the block by changing the transaction Transaction#setCustom(BlockSnapshot).

Test:
for(Transaction transaction: event.getTransactions()) {
transaction.setCustom(transaction.getOriginal());
Tool.getLogger().info("setCustom: " + transaction.getOriginal().toString());
Tool.getLogger().info("setCustom: " + transaction.getFinal().getState().getType().getId());
}

Log:
[09:49:07] [Server thread/INFO] [simpledestroyblock]: setCustom: SpongeBlockSnapshot{worldUniqueId=e6a02087-4c94-4c78-8832-e756c23c832b, position=(-68, 88, -38), blockState=minecraft:sand[variant=sand], extendedState=minecraft:sand[variant=sand]}
[09:49:07] [Server thread/INFO] [simpledestroyblock]: setCustom: minecraft:sand

Hmm, it seems that the Sponge core does not respond to a block change in a transaction, you need to create an issue on GitHub. There are always problems with this event… :unamused:

Avec ce code pas de bug:

translate.google.fr:
With this code no bug:

    for(Transaction<BlockSnapshot> transaction: event.getTransactions()) {
        Sponge.getScheduler().createTaskBuilder().execute(var -> {
            transaction.getFinal().getLocation().ifPresent(location -> {
                location.setBlock(BlockTypes.GLOWSTONE.getDefaultState());
            });
        }).delayTicks(0).submit(Tool.getInstance());
    }