How to change the text of a sign?


I am working on the migration of my bukkit plugin to Sponge and I am trying to modify the text of a sign.

I tried various solutions and read a lot of things in the forum but could not get the way to achieve this. The documentation is not up-to-date.

I think I must create a SignData with the new text and then update the BlockState using BlockState.with(SignData sign), and then update the location, but BlockState.with() does not accept a SignData.

Thanks for your help.

My variant:

public boolean setLines(TileEntity entity, Text line0, Text line1, Text line2, Text line3) {
        SignData sign = entity.get(SignData.class).get();
        if (line0!=null) sign = sign.set(sign.getValue(Keys.SIGN_LINES).get().set(0, line0));
        if (line1!=null) sign = sign.set(sign.getValue(Keys.SIGN_LINES).get().set(1, line1));
        if (line2!=null) sign = sign.set(sign.getValue(Keys.SIGN_LINES).get().set(2, line2));
        if (line3!=null) sign = sign.set(sign.getValue(Keys.SIGN_LINES).get().set(3, line3));
        return true;

Thanks ! I did not undestand that TileEntity was the solution.

Another question : To read a sign, what is the preferable way to do : get an ImmutableSignData through BlockState, or a SignData through TileEntity ?

Use the TileEntity. BlockStates have a finite set of possible values and does not store that sort of information.