Spongeapi: Phase incompatibility detected, on changing blocks inside events

Created on 30 Nov 2017  路  6Comments  路  Source: SpongePowered/SpongeAPI

Hello, i am trying to update a block type inside on the ChangeBlockEvent.Place, the block place correctly but it throw some errors in the console

My code:

    @Listener
    public void onBlockPlace(ChangeBlockEvent.Place e){
        Optional<Player> player = Helper.playerCause(e.getCause());
        if(player.isPresent()){
            BlockSnapshot block = e.getTransactions().get(0).getFinal();
            block.getLocation().get().copy().sub(5, 5, 5).setBlockType(BlockTypes.BEDROCK, Cause.source(SpongyPS.getInstance().getPluginContainer()).build());
        }
    }

The error:

https://pastebin.com/1tqnBq6m

Version:

  • Minecraft: 1.11.2
  • SpongeAPI: 6.1.0-SNAPSHOT-d1eb7e2b
  • SpongeVanilla: 1.11.2-6.1.0-BETA-22

Thanks ;)

6 (u)

Most helpful comment

*correction

I should have been paying more attention, this is definitely a bug in my eyes.

I didn't notice that you were adjusting a different block then what was being set in the event.

I'm not sure it's possible to add additional blocks to the transaction, so we definitely should at least be doing something about this.

All 6 comments

you should modify the transactions or add it to a task

~@Liach is correct, the whole point of the transaction is to be able to get the original, and swap out the result. setting the blocktype using the API will just throw another event.~

~Adding it as a task should really only be used as a last resort, as it will still set the original final from the place event, and then fire an event again that you will be listening to.~

~I'm leaving this open for input on whether this should be closed, or moved to SpongeCommon as a bug that it allowed the block to be set, whilst throwing an error.~

*correction

I should have been paying more attention, this is definitely a bug in my eyes.

I didn't notice that you were adjusting a different block then what was being set in the event.

I'm not sure it's possible to add additional blocks to the transaction, so we definitely should at least be doing something about this.

I'm not sure it's possible to add additional blocks to the transaction, so we definitely should at least be doing something about this.

I thought we could add more transaction in this case. Using Sponge.getScheduler().createTaskBuiler() and make a task for the next tick may be a temporary workaround.

This should be in implementation to be honest, as it's a SpongeCommon bug, not an API bug. Re-open there please.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Lergin picture Lergin  路  5Comments

Cybermaxke picture Cybermaxke  路  6Comments

Eufranio picture Eufranio  路  5Comments

BrainStone picture BrainStone  路  5Comments

gabizou picture gabizou  路  6Comments