Skip to content

Commit

Permalink
added basic engine screen overheat overlay rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
JR1811 committed Apr 13, 2024
1 parent 644a11e commit c27bbdc
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
37 changes: 34 additions & 3 deletions src/main/java/net/shirojr/boatism/screen/EngineControlScreen.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -9,7 +10,11 @@
import net.shirojr.boatism.screen.handler.EngineControlScreenHandler;

public class EngineControlScreen extends HandledScreen<EngineControlScreenHandler> {
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);
Expand All @@ -18,7 +23,6 @@ public EngineControlScreen(EngineControlScreenHandler handler, PlayerInventory i
@Override
protected void init() {
super.init();
// titleX = (backgroundWidth - textRenderer.getWidth(title)) / 2;
}

@Override
Expand All @@ -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) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit c27bbdc

Please sign in to comment.