Separate screen, add power gauge draw
This commit is contained in:
parent
fb727a55bb
commit
8cec0e3724
@ -32,9 +32,14 @@ public class BigDecimalDataContainer implements ContainerData {
|
||||
|
||||
byte[] build = new byte[_build[0] & 0xFF];
|
||||
|
||||
System.arraycopy(_build, 1, build, 0, build.length);
|
||||
if (_build[0] != 0) {
|
||||
System.arraycopy(_build, 1, build, 0, build.length);
|
||||
|
||||
value = new BigDecimal(new BigInteger(build), buffer[0]);
|
||||
value = new BigDecimal(new BigInteger(build), buffer[0]);
|
||||
return value;
|
||||
}
|
||||
|
||||
value = new BigDecimal(0);
|
||||
return value;
|
||||
}
|
||||
|
||||
|
@ -7,59 +7,23 @@ import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import ru.dbotthepony.mc.otm.OverdriveThatMatters;
|
||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability;
|
||||
import ru.dbotthepony.mc.otm.menu.AndroidStationMenu;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class AndroidStationScreen extends AbstractContainerScreen<AndroidStationMenu> {
|
||||
public class AndroidStationScreen extends PoweredMachineScreen<AndroidStationMenu> {
|
||||
private static final ResourceLocation CONTAINER_BACKGROUND = new ResourceLocation(OverdriveThatMatters.MOD_ID, "textures/gui/android_station.png");
|
||||
private final AndroidStationMenu station;
|
||||
|
||||
@Override
|
||||
protected ResourceLocation CONTAINER_BACKGROUND() {
|
||||
return CONTAINER_BACKGROUND;
|
||||
}
|
||||
|
||||
public AndroidStationScreen(AndroidStationMenu p_97741_, Inventory p_97742_, Component p_97743_) {
|
||||
super(p_97741_, p_97742_, p_97743_);
|
||||
station = p_97741_;
|
||||
|
||||
imageWidth = 176;
|
||||
imageHeight = 178;
|
||||
titleLabelY = 4;
|
||||
|
||||
inventoryLabelY = imageHeight - 92;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(PoseStack p_98418_, int p_98419_, int p_98420_, float p_98421_) {
|
||||
this.renderBackground(p_98418_);
|
||||
super.render(p_98418_, p_98419_, p_98420_, p_98421_);
|
||||
this.renderTooltip(p_98418_, p_98419_, p_98420_);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderBg(PoseStack pose, float p_97788_, int p_97789_, int p_97790_) {
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
RenderSystem.setShaderTexture(0, CONTAINER_BACKGROUND);
|
||||
int i = (width - imageWidth) / 2;
|
||||
int j = (height - imageHeight) / 2;
|
||||
// PoseStack, x, y, image_start_x, image_start_y, rect_size_x, rect_size_y
|
||||
this.blit(pose, i, j, 0, 0, this.imageWidth, this.imageHeight);
|
||||
|
||||
BigDecimal energy = station.energy.getDecimal();
|
||||
BigDecimal max_energy = station.max_energy.getDecimal();
|
||||
|
||||
double level;
|
||||
|
||||
if (max_energy.equals(BigDecimal.ZERO)) {
|
||||
level = 0d;
|
||||
} else {
|
||||
level = energy.divide(max_energy, MatteryCapability.ROUND_RULES).doubleValue();
|
||||
|
||||
if (level >= 0.98)
|
||||
level = 1d;
|
||||
}
|
||||
|
||||
if (level > 0.01)
|
||||
this.blit(pose, i + 13, j + 15 + 46 - (int) (level * 45d), 176, 0, 7, (int) (level * 46d));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,125 @@
|
||||
package ru.dbotthepony.mc.otm.screen;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.FormattedText;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import ru.dbotthepony.mc.otm.OverdriveThatMatters;
|
||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability;
|
||||
import ru.dbotthepony.mc.otm.menu.PoweredMachineMenu;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
public class PoweredMachineScreen<T extends PoweredMachineMenu> extends AbstractContainerScreen<T> {
|
||||
private static ResourceLocation CONTAINER_BACKGROUND = new ResourceLocation(OverdriveThatMatters.MOD_ID, "textures/gui/mattery_machine_base.png");
|
||||
|
||||
protected boolean auto_draw_gauge = true;
|
||||
protected int power_gauge_x = 13;
|
||||
protected int power_gauge_y = 15;
|
||||
|
||||
protected ResourceLocation CONTAINER_BACKGROUND() {
|
||||
return CONTAINER_BACKGROUND;
|
||||
}
|
||||
|
||||
public PoweredMachineScreen(T p_97741_, Inventory p_97742_, Component p_97743_) {
|
||||
super(p_97741_, p_97742_, p_97743_);
|
||||
|
||||
imageWidth = 176;
|
||||
imageHeight = 178;
|
||||
titleLabelY = 4;
|
||||
|
||||
inventoryLabelY = imageHeight - 92;
|
||||
}
|
||||
|
||||
protected List<FormattedText> getFormattedPowerLevel() {
|
||||
BigDecimal energy = menu.energy.getDecimal();
|
||||
BigDecimal max_energy = menu.max_energy.getDecimal();
|
||||
|
||||
double level;
|
||||
|
||||
if (max_energy.equals(BigDecimal.ZERO)) {
|
||||
level = 0d;
|
||||
} else {
|
||||
level = energy.divide(max_energy, MatteryCapability.ROUND_RULES).doubleValue();
|
||||
|
||||
if (level >= 0.98)
|
||||
level = 1d;
|
||||
}
|
||||
|
||||
return List.of(
|
||||
new TextComponent(String.format("Energy level: %.2f%%", level * 100d)),
|
||||
new TextComponent(String.format("%s / %s Mattery Energy", energy.toString(), max_energy.toString()))
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderTooltip(PoseStack p_97791_, int mouseX, int mouseY) {
|
||||
super.renderTooltip(p_97791_, mouseX, mouseY);
|
||||
|
||||
if (this.hoveredSlot == null && menu.getCarried().isEmpty() && hovering_power_gauge) {
|
||||
this.renderComponentToolTip(p_97791_, getFormattedPowerLevel(), mouseX, mouseY, font);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(PoseStack p_98418_, int mouseX, int mouseY, float p_98421_) {
|
||||
this.renderBackground(p_98418_);
|
||||
super.render(p_98418_, mouseX, mouseY, p_98421_);
|
||||
this.renderTooltip(p_98418_, mouseX, mouseY);
|
||||
}
|
||||
|
||||
protected boolean hovering_power_gauge = false;
|
||||
|
||||
protected void renderPowerGauge(PoseStack pose, int x, int y, int mouseX, int mouseY) {
|
||||
BigDecimal energy = menu.energy.getDecimal();
|
||||
BigDecimal max_energy = menu.max_energy.getDecimal();
|
||||
|
||||
int i = (width - imageWidth) / 2;
|
||||
int j = (height - imageHeight) / 2;
|
||||
|
||||
double level;
|
||||
|
||||
if (max_energy.equals(BigDecimal.ZERO)) {
|
||||
level = 0d;
|
||||
} else {
|
||||
level = energy.divide(max_energy, MatteryCapability.ROUND_RULES).doubleValue();
|
||||
|
||||
if (level >= 0.98)
|
||||
level = 1d;
|
||||
}
|
||||
|
||||
if (level > 0.01) {
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
RenderSystem.setShaderTexture(0, CONTAINER_BACKGROUND);
|
||||
|
||||
int intHeight = (int) Math.floor(level * 46d + 0.5d);
|
||||
|
||||
this.blit(pose, i + 13, j + 15 + 46 - intHeight, 176, 0, 7, intHeight);
|
||||
}
|
||||
|
||||
x += leftPos;
|
||||
y += topPos;
|
||||
hovering_power_gauge = x <= mouseX && x + 7 >= mouseX && y <= mouseY && y + 46 >= mouseY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderBg(PoseStack pose, float p_97788_, int mouseX, int mouseY) {
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
RenderSystem.setShaderTexture(0, CONTAINER_BACKGROUND());
|
||||
int i = (width - imageWidth) / 2;
|
||||
int j = (height - imageHeight) / 2;
|
||||
// PoseStack, x, y, image_start_x, image_start_y, rect_size_x, rect_size_y
|
||||
this.blit(pose, i, j, 0, 0, this.imageWidth, this.imageHeight);
|
||||
|
||||
if (auto_draw_gauge)
|
||||
renderPowerGauge(pose, power_gauge_x, power_gauge_y, mouseX, mouseY);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user