How can I get TileEntity from block location in sponge 8.0?

In sponge 7.0 I can get TileEntity from block location by using this code.

Location loc;
TileEntity tile = loc.getTileEntity().get();

but In sponge 8.0 I couldn’t find the TileEntity class and getTileEntity method.

How can I get TileEntity from block location in sponge 8.0 ?

I want to get TileEntity then cast to SignData class. then set sign line.

Please help me.

TileEntity is no longer called Tile entity (as it changed in the mappings)

Its now called BlockEntity

You can use location.blockEntity() to get it now

Thank for you care!

How can I get Sign from BlockEntity ? and How can I set text line in the Sign ?

Two ways again.

Key: Keys.SIGN_LINES

Or sign

Sign sign;
sign.lines().set(lines);
sign.lines().add(line);

As for the getting a sign from a block entity

BlockEntity blockEntity;
if(!(blockEntity instanceof Sign)){
  //Not sign
  return;
}
Sign sign = (Sign)blockEntity;

Or as your getting it right from location

Optional<Sign> opSign = loc
.blockEntity()
.flatMap(blockEntity -> blockEntity instanceof Sign ? Optional.of((Sign) blockEntity) : Optional.empty());
1 Like

Thank for you care!