public class BoxScreen extends HandledScreen { private static final Identifier TEXTURE = new Identifier("minecraft", "textures/gui/container/dispenser.png"); public BoxScreen(ScreenHandler handler, PlayerInventory inventory, Text title) { super(handler, inventory, getPositionText(handler).orElse(title)); //We try to get the block position to use it as our title, if that fails for some reason we will use the default title } //This method will try to get the Position from the ScreenHandler, as ScreenRendering only happens on the client we //get the ScreenHandler instance here which has the correct BlockPos in it! private static Optional getPositionText(ScreenHandler handler) { if (handler instanceof BoxScreenHandler) { BlockPos pos = ((BoxScreenHandler) handler).getPos(); // for versions 1.18.2 and below, use `new LiteralText` return pos != null ? Optional.of(Text.literal("(" + pos.toShortString() + ")")) : Optional.empty(); } else { return Optional.empty(); } } @Override protected void drawBackground(MatrixStack matrices, float delta, int mouseX, int mouseY) { [...] } @Override public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { [...] } @Override protected void init() { [...] } }