public class BoxScreen extends HandledScreen { // GUI 纹理的路径,本例中使用发射器中的纹理 private static final Identifier TEXTURE = Identifier.ofVanilla("minecraft", "textures/gui/container/dispenser.png"); public BoxScreen(ScreenHandler handler, PlayerInventory inventory, Text title) { super(handler, inventory, title); } @Override protected void drawBackground(DrawContext context, float delta, int mouseX, int mouseY) { RenderSystem.setShader(GameRenderer::getPositionTexProgram); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.setShaderTexture(0, TEXTURE); int x = (width - backgroundWidth) / 2; int y = (height - backgroundHeight) / 2; context.drawTexture(TEXTURE, x, y, 0, 0, backgroundWidth, backgroundHeight); } @Override public void render(DrawContext context, int mouseX, int mouseY, float delta) { renderBackground(context, mouseX, mouseY, delta); super.render(context, mouseX, mouseY, delta); drawMouseoverTooltip(context, mouseX, mouseY); } @Override protected void init() { super.init(); // 将标题居中 titleX = (backgroundWidth - textRenderer.getWidth(title)) / 2; } }