From c27bbdcbcd0cf3dc30eba00fc1a443643f4e509c Mon Sep 17 00:00:00 2001 From: JR1811 Date: Sat, 13 Apr 2024 13:39:03 +0200 Subject: [PATCH] added basic engine screen overheat overlay rendering --- .../boatism/screen/EngineControlScreen.java | 37 +++++++++++++++++-- .../handler/EngineControlScreenHandler.java | 8 ++-- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/shirojr/boatism/screen/EngineControlScreen.java b/src/main/java/net/shirojr/boatism/screen/EngineControlScreen.java index 7d9415d..26de2ba 100644 --- a/src/main/java/net/shirojr/boatism/screen/EngineControlScreen.java +++ b/src/main/java/net/shirojr/boatism/screen/EngineControlScreen.java @@ -1,5 +1,6 @@ package net.shirojr.boatism.screen; +import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.ingame.HandledScreen; import net.minecraft.entity.player.PlayerInventory; @@ -9,7 +10,11 @@ import net.shirojr.boatism.screen.handler.EngineControlScreenHandler; public class EngineControlScreen extends HandledScreen { - private static final Identifier TEXTURE = new Identifier(Boatism.MODID, "textures/gui/engine_control.png"); + public static final Identifier TEXTURE = new Identifier(Boatism.MODID, "textures/gui/engine_control.png"); + public static final EnginePartTexture TOP = new EnginePartTexture(206, 1, 29, 15); + public static final EnginePartTexture MID = new EnginePartTexture(206, 17, 10, 8); + public static final EnginePartTexture BOTTOM = new EnginePartTexture(206, 26, 6, 18); + public static final EnginePartTexture TURBINE = new EnginePartTexture(206, 45, 14, 9); public EngineControlScreen(EngineControlScreenHandler handler, PlayerInventory inventory, Text title) { super(handler, inventory, title); @@ -18,7 +23,6 @@ public EngineControlScreen(EngineControlScreenHandler handler, PlayerInventory i @Override protected void init() { super.init(); - // titleX = (backgroundWidth - textRenderer.getWidth(title)) / 2; } @Override @@ -27,16 +31,43 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) { this.drawMouseoverTooltip(context, mouseX, mouseY); } + @Override + protected void drawForeground(DrawContext context, int mouseX, int mouseY) { + super.drawForeground(context, mouseX, mouseY); + } + @Override protected void drawBackground(DrawContext context, float delta, int mouseX, int mouseY) { int x = (width - backgroundWidth) / 2; int y = (height - backgroundHeight) / 2; context.drawTexture(TEXTURE, x, y, 0, 0, this.backgroundWidth, this.backgroundHeight); - context.drawGuiTexture(TEXTURE, 100, 100, 0, 0, 50, 50, 1, 1); + + renderEngineOverlay(context, x + 16, y + 41, TURBINE); + renderEngineOverlay(context, x + 17, y + 33, BOTTOM); + renderEngineOverlay(context, x + 16, y + 29, MID); + renderEngineOverlay(context, x + 19, y + 18, TOP); + } + + public void renderEngineOverlay(DrawContext context, int x, int y, EnginePartTexture enginePart) { + // TODO: implement maxHeat with delegates from handler to normalize heat + float heat = this.handler.getOverheat(); + + RenderSystem.disableDepthTest(); + RenderSystem.depthMask(false); + RenderSystem.enableBlend(); + context.setShaderColor(1.0f, 1.0f, 1.0f, 0.0f); + context.drawTexture(TEXTURE, x, y, enginePart.u, enginePart.v, enginePart.width, enginePart.height); + RenderSystem.depthMask(true); + RenderSystem.enableDepthTest(); + RenderSystem.disableBlend(); + context.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f); } @Override public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) { return super.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount); } + + private record EnginePartTexture(int u, int v, int width, int height) { + } } diff --git a/src/main/java/net/shirojr/boatism/screen/handler/EngineControlScreenHandler.java b/src/main/java/net/shirojr/boatism/screen/handler/EngineControlScreenHandler.java index 2e29e41..df41069 100644 --- a/src/main/java/net/shirojr/boatism/screen/handler/EngineControlScreenHandler.java +++ b/src/main/java/net/shirojr/boatism/screen/handler/EngineControlScreenHandler.java @@ -9,14 +9,10 @@ import net.minecraft.screen.ArrayPropertyDelegate; import net.minecraft.screen.PropertyDelegate; import net.minecraft.screen.ScreenHandler; -import net.minecraft.screen.ScreenHandlerContext; import net.minecraft.screen.slot.Slot; import net.minecraft.screen.slot.SlotActionType; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.server.world.ServerWorld; import net.shirojr.boatism.api.BoatEngineComponent; import net.shirojr.boatism.entity.custom.BoatEngineEntity; -import net.shirojr.boatism.util.handler.EntityHandler; public class EngineControlScreenHandler extends ScreenHandler { private final Inventory engineInventory; @@ -83,7 +79,9 @@ public ItemStack quickMove(PlayerEntity player, int slotIndex) { @Override public void onSlotClick(int slotIndex, int button, SlotActionType actionType, PlayerEntity player) { - if (this.boatEngine != null) this.boatEngine.syncComponentListToTrackingClients(); + if (this.boatEngine != null && player.getWorld().isClient()) { + this.boatEngine.syncComponentListToTrackingClients(); + } super.onSlotClick(slotIndex, button, actionType, player); }