Skip to content

Commit

Permalink
Merge branch 'master' into apatite-chembalance
Browse files Browse the repository at this point in the history
  • Loading branch information
Dream-Master authored Jan 16, 2025
2 parents 2b79d7a + 07c8aa4 commit 12b4a88
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
import static java.lang.Math.min;
import static kekztech.util.Util.toPercentageFrom;
import static kekztech.util.Util.toStandardForm;
import static net.minecraft.util.StatCollector.translateToLocal;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
Expand Down Expand Up @@ -57,13 +59,16 @@
import com.gtnewhorizons.modularui.api.drawable.IDrawable;
import com.gtnewhorizons.modularui.api.drawable.UITexture;
import com.gtnewhorizons.modularui.api.math.Alignment;
import com.gtnewhorizons.modularui.api.math.Color;
import com.gtnewhorizons.modularui.api.math.Size;
import com.gtnewhorizons.modularui.api.screen.ModularWindow;
import com.gtnewhorizons.modularui.api.screen.UIBuildContext;
import com.gtnewhorizons.modularui.common.widget.ButtonWidget;
import com.gtnewhorizons.modularui.common.widget.DynamicPositionedColumn;
import com.gtnewhorizons.modularui.common.widget.FakeSyncWidget;
import com.gtnewhorizons.modularui.common.widget.SlotWidget;
import com.gtnewhorizons.modularui.common.widget.TextWidget;
import com.gtnewhorizons.modularui.common.widget.textfield.NumericWidget;

import bartworks.API.BorosilicateGlass;
import gregtech.api.enums.Dyes;
Expand Down Expand Up @@ -111,6 +116,7 @@ private enum TopState {
private boolean wireless_mode = false;
private int counter = 1;
private boolean balanced = false;
private boolean warningReceived = false;

private final LongRunningAverage energyInputValues1h = new LongRunningAverage(3600 * 20);
private final LongRunningAverage energyOutputValues1h = new LongRunningAverage(3600 * 20);
Expand Down Expand Up @@ -183,6 +189,8 @@ public static int getIndexFromGlassTier(int glassTier) {
private static final int CASING_TEXTURE_ID = (42 << 7) | 127;

private static final int DURATION_AVERAGE_TICKS = 100;
private static final int DEBUG_POWER_WINDOW_ID = 10;
private static final int WIRELESS_WARNING_WINDOW_ID = 11;

// height channel for height.
// glass channel for glass
Expand Down Expand Up @@ -477,7 +485,15 @@ protected MultiblockTooltipBuilder createTooltip() {
+ EnumChatFormatting.GRAY
+ ") EU in the LSC")
.addInfo("it will withdraw from the network and add to the LSC.")
.addInfo("If there is more it will add the EU to the network and remove it from the LSC.")
.addInfo(
"If there is more it will add " + EnumChatFormatting.DARK_RED
+ EnumChatFormatting.BOLD
+ EnumChatFormatting.UNDERLINE
+ "all excess"
+ EnumChatFormatting.RESET
+ EnumChatFormatting.GRAY
+ " EU to the network, removing it from the LSC.")
.addInfo("This can potentially brick your base, be careful.")
.addInfo(
"The threshold increases " + EnumChatFormatting.DARK_RED
+ "100"
Expand Down Expand Up @@ -1217,6 +1233,7 @@ public void saveNBTData(NBTTagCompound nbt) {
nbt.setByteArray("stored", stored.toByteArray());
nbt.setBoolean("wireless_mode", wireless_mode);
nbt.setInteger("wireless_mode_cooldown", counter);
nbt.setBoolean("warningReceived", warningReceived);

super.saveNBTData(nbt);
}
Expand All @@ -1229,6 +1246,7 @@ public void loadNBTData(NBTTagCompound nbt) {
stored = new BigInteger(nbt.getByteArray("stored"));
wireless_mode = nbt.getBoolean("wireless_mode");
counter = nbt.getInteger("wireless_mode_cooldown");
warningReceived = nbt.getBoolean("warningReceived");

super.loadNBTData(nbt);
}
Expand Down Expand Up @@ -1324,13 +1342,22 @@ public void onScrewdriverRightClick(ForgeDirection side, EntityPlayer aPlayer, f
@Override
public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) {
super.addUIWidgets(builder, buildContext);
buildContext.addSyncedWindow(DEBUG_POWER_WINDOW_ID, this::createPowerWindow);
buildContext.addSyncedWindow(WIRELESS_WARNING_WINDOW_ID, this::createWarningWindow);
builder.widget(new ButtonWidget().setOnClick((clickData, widget) -> {
if (!widget.isClient()) {
canUseWireless = canUseWireless();
}
if (canUseWireless) {
wireless_mode = !wireless_mode;
if (!warningReceived) {
warningReceived = true;
widget.getContext()
.openSyncedWindow(WIRELESS_WARNING_WINDOW_ID);
} else {
wireless_mode = !wireless_mode;
}
}

})
.setPlayClickSound(true)
.setBackground(() -> {
Expand All @@ -1353,6 +1380,7 @@ public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildCont
.setTooltipShowUpDelay(TOOLTIP_DELAY))
.widget(new FakeSyncWidget.BooleanSyncer(() -> wireless_mode, val -> wireless_mode = val))
.widget(new FakeSyncWidget.BooleanSyncer(this::canUseWireless, val -> canUseWireless = val))
.widget(new FakeSyncWidget.BooleanSyncer(() -> warningReceived, val -> warningReceived = val))
.widget(new ButtonWidget().setOnClick((clickData, widget) -> {
if (mMachine && wireless_mode && canUseWireless && !balanced) {
counter = rebalance();
Expand All @@ -1370,6 +1398,99 @@ public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildCont
.setEnabled((widget) -> wireless_mode && canUseWireless && !balanced)
.addTooltip(StatCollector.translateToLocal("gui.kekztech_lapotronicenergyunit.wireless_rebalance"))
.setTooltipShowUpDelay(TOOLTIP_DELAY));

builder.widget(new ButtonWidget().setOnClick((clickData, widget) -> {
if (!widget.isClient()) {
widget.getContext()
.openSyncedWindow(DEBUG_POWER_WINDOW_ID);
}
})
.setPlayClickSound(true)
.setBackground(() -> {
List<UITexture> ret = new ArrayList<>();
ret.add(GTUITextures.BUTTON_STANDARD);
ret.add(GTUITextures.OVERLAY_BUTTON_EMIT_ENERGY);
return ret.toArray(new IDrawable[0]);
})
.addTooltip(translateToLocal("GT5U.multiblock.energy"))
.setTooltipShowUpDelay(TOOLTIP_DELAY)
.setEnabled($ -> buildContext.getPlayer().capabilities.isCreativeMode)
.setPos(174, 112)
.setSize(16, 16));
}

protected ModularWindow createPowerWindow(final EntityPlayer player) {
final int WIDTH = 158;
final int HEIGHT = 52;
final int PARENT_WIDTH = getGUIWidth();
final int PARENT_HEIGHT = getGUIHeight();
ModularWindow.Builder builder = ModularWindow.builder(WIDTH, HEIGHT);
builder.setBackground(GTUITextures.BACKGROUND_SINGLEBLOCK_DEFAULT);
builder.setGuiTint(getGUIColorization());
builder.setDraggable(true);
builder.setPos(
(size, window) -> Alignment.Center.getAlignedPos(size, new Size(PARENT_WIDTH, PARENT_HEIGHT))
.add(
Alignment.BottomRight.getAlignedPos(new Size(PARENT_WIDTH, PARENT_HEIGHT), new Size(WIDTH, HEIGHT))
.add(WIDTH - 3, 0)
.subtract(0, 10)));
builder.widget(
TextWidget.localised("GT5U.multiblock.energy")
.setPos(3, 4)
.setSize(150, 20))
.widget(
new NumericWidget().setSetter(
val -> stored = BigDecimal.valueOf(val)
.toBigInteger())
.setGetter(() -> stored.doubleValue())
.setIntegerOnly(false)
.setBounds(0, capacity.doubleValue())
.setDefaultValue(stored.doubleValue())
.setTextAlignment(Alignment.Center)
.setTextColor(Color.WHITE.normal)
.setSize(150, 18)
.setPos(4, 25)
.setBackground(GTUITextures.BACKGROUND_TEXT_FIELD)
.attachSyncer(
new FakeSyncWidget.DoubleSyncer(
() -> capacity.doubleValue(),
(val) -> capacity = BigDecimal.valueOf(val)
.toBigInteger()),
builder)
.attachSyncer(
new FakeSyncWidget.DoubleSyncer(
() -> stored.doubleValue(),
(val) -> stored = BigDecimal.valueOf(val)
.toBigInteger()),
builder));
return builder.build();
}

protected ModularWindow createWarningWindow(final EntityPlayer player) {
final int WIDTH = 180;
final int HEIGHT = 75;
ModularWindow.Builder builder = ModularWindow.builder(WIDTH, HEIGHT);
builder.setBackground(GTUITextures.BACKGROUND_SINGLEBLOCK_DEFAULT);
builder.setGuiTint(getGUIColorization());
builder.setDraggable(true);
builder
.widget(
new TextWidget(
EnumChatFormatting.BOLD + translateToLocal("gui.kekztech_lapotronicenergyunit.warning.header"))
.setDefaultColor(0xff0000)
.setScale(1.2f)
.setTextAlignment(Alignment.Center)
.setPos(0, 7)
.setSize(180, 15))
.widget(
TextWidget.localised("gui.kekztech_lapotronicenergyunit.warning.text")
.setTextAlignment(Alignment.CenterLeft)
.setPos(5, 20)
.setSize(170, 50));
builder.widget(
ButtonWidget.closeWindowButton(true)
.setPos(164, 4));
return builder.build();
}

private enum LSCHatchElement implements IHatchElement<MTELapotronicSuperCapacitor> {
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/kekztech/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,5 @@ achievement.tile.kekztech_lapotronicenergyunit_block.10=Mega Ultimate Capacitor
# -------- GUI
gui.kekztech_lapotronicenergyunit.wireless=Wireless mode
gui.kekztech_lapotronicenergyunit.wireless_rebalance=Rebalance Wireless (One Time Use)
gui.kekztech_lapotronicenergyunit.warning.header=Warning!
gui.kekztech_lapotronicenergyunit.warning.text=Make sure to carefully read and understand the tooltip before activating wireless mode, it can potentially brick your base. This warning won't appear again.

0 comments on commit 12b4a88

Please sign in to comment.