aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api
diff options
context:
space:
mode:
authorquerns <33518699+querns@users.noreply.github.com>2023-10-09 09:55:31 -0500
committerGitHub <noreply@github.com>2023-10-09 16:55:31 +0200
commitdff250c6d32156270b9a39137346a2b3767cb4a2 (patch)
treec3ad948b6aa9e5b9edefde7e4517e9b78be7d2fe /src/main/java/gregtech/api
parent45566b43ee5d8b8f75170916530fd884e0ff74db (diff)
downloadGT5-Unofficial-dff250c6d32156270b9a39137346a2b3767cb4a2.tar.gz
GT5-Unofficial-dff250c6d32156270b9a39137346a2b3767cb4a2.tar.bz2
GT5-Unofficial-dff250c6d32156270b9a39137346a2b3767cb4a2.zip
Allows covers to be configured to tick more slowly (#2307)
* Right clicking covers with a jackhammer will now make them tick more slowly * Interim commit, switching tasks * Finishes tick rate button in cover UIs * Change tick rate multiplier to a tick rate addition * Missed one number in the multiplier -> addition conversion * Hold Ctrl to adjust tick rate by 5 steps per click, move button closer to corner of cover GUI * Adjust how holding Ctrl computes tick rate change, remove gray formatting option for tick rate formatter * Cover tick rate addition can now be prevented per-cover-behavior, minor code tweaks
Diffstat (limited to 'src/main/java/gregtech/api')
-rw-r--r--src/main/java/gregtech/api/GregTech_API.java3
-rw-r--r--src/main/java/gregtech/api/gui/modularui/GT_UITextures.java3
-rw-r--r--src/main/java/gregtech/api/gui/widgets/GT_CoverTickRateButton.java82
-rw-r--r--src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java26
-rw-r--r--src/main/java/gregtech/api/util/GT_CoverBehaviorBase.java15
5 files changed, 128 insertions, 1 deletions
diff --git a/src/main/java/gregtech/api/GregTech_API.java b/src/main/java/gregtech/api/GregTech_API.java
index de295e2aa6..763c4210c9 100644
--- a/src/main/java/gregtech/api/GregTech_API.java
+++ b/src/main/java/gregtech/api/GregTech_API.java
@@ -183,7 +183,8 @@ public class GregTech_API {
public static final GT_HashSet<GT_ItemStack> sToolList = new GT_HashSet<>(), sCrowbarList = new GT_HashSet<>(),
sScrewdriverList = new GT_HashSet<>(), sWrenchList = new GT_HashSet<>(), sSoftHammerList = new GT_HashSet<>(),
sHardHammerList = new GT_HashSet<>(), sWireCutterList = new GT_HashSet<>(),
- sSolderingToolList = new GT_HashSet<>(), sSolderingMetalList = new GT_HashSet<>();
+ sSolderingToolList = new GT_HashSet<>(), sSolderingMetalList = new GT_HashSet<>(),
+ sJackhammerList = new GT_HashSet<>();
/**
* The List of Hazmat Armors
*/
diff --git a/src/main/java/gregtech/api/gui/modularui/GT_UITextures.java b/src/main/java/gregtech/api/gui/modularui/GT_UITextures.java
index 19bf3ca3f4..ffeec40561 100644
--- a/src/main/java/gregtech/api/gui/modularui/GT_UITextures.java
+++ b/src/main/java/gregtech/api/gui/modularui/GT_UITextures.java
@@ -380,6 +380,9 @@ public class GT_UITextures {
public static final UITexture OVERLAY_RETRACT_PIPE = UITexture
.fullImage(GregTech.ID, "gui/overlay_button/retract_pipes");
+ public static final UITexture OVERLAY_BUTTON_HOURGLASS = UITexture
+ .fullImage(GregTech.ID, "gui/overlay_button/hourglass");
+
/**
* Can adjust size as needed.
*/
diff --git a/src/main/java/gregtech/api/gui/widgets/GT_CoverTickRateButton.java b/src/main/java/gregtech/api/gui/widgets/GT_CoverTickRateButton.java
new file mode 100644
index 0000000000..883ffb4079
--- /dev/null
+++ b/src/main/java/gregtech/api/gui/widgets/GT_CoverTickRateButton.java
@@ -0,0 +1,82 @@
+package gregtech.api.gui.widgets;
+
+import static gregtech.api.gui.modularui.GT_UITextures.OVERLAY_BUTTON_HOURGLASS;
+import static gregtech.common.covers.CoverInfo.MAX_TICK_RATE_ADDITION;
+
+import java.util.List;
+
+import net.minecraft.util.StatCollector;
+
+import org.jetbrains.annotations.NotNull;
+
+import com.google.common.collect.ImmutableList;
+import com.gtnewhorizons.modularui.api.drawable.UITexture;
+import com.gtnewhorizons.modularui.api.widget.IWidgetBuilder;
+import com.gtnewhorizons.modularui.api.widget.Widget;
+import com.gtnewhorizons.modularui.common.widget.ButtonWidget;
+import com.gtnewhorizons.modularui.common.widget.FakeSyncWidget;
+
+import gregtech.api.gui.modularui.GT_UITextures;
+import gregtech.common.covers.CoverInfo;
+
+public class GT_CoverTickRateButton extends ButtonWidget {
+
+ private static final UITexture BACKGROUND = GT_UITextures.BUTTON_COVER_NORMAL.getSubArea(0, 0, 1, 0.5f);
+
+ private final CoverInfo coverInfo;
+ private int clientTickRate;
+ private int tickRateAddition;
+
+ public GT_CoverTickRateButton(@NotNull CoverInfo coverInfo, @NotNull IWidgetBuilder<?> builder) {
+ this.coverInfo = coverInfo;
+ this.clientTickRate = coverInfo.getTickRate();
+ this.tickRateAddition = coverInfo.getTickRateAddition();
+
+ super.setBackground(BACKGROUND, OVERLAY_BUTTON_HOURGLASS);
+ super.setOnClick(this::onClick);
+ super.dynamicTooltip(this::dynamicTooltip);
+ super.attachSyncer(
+ new FakeSyncWidget.IntegerSyncer(this.coverInfo::getTickRate, integer -> clientTickRate = integer),
+ builder,
+ (widget, aInt) -> notifyTooltipChange())
+ .attachSyncer(
+ new FakeSyncWidget.IntegerSyncer(
+ this.coverInfo::getTickRateAddition,
+ integer -> tickRateAddition = integer),
+ builder);
+
+ }
+
+ private void onClick(@NotNull ClickData clickData, @NotNull Widget widget) {
+ final int iterations = clickData.ctrl ? 5 : 1;
+ final boolean isDecreasing = clickData.mouseButton == 1;
+
+ // Do five operations at once if Ctrl is held down. Since the actual increase granted by each invocation can be
+ // different on each call, just call the method several times rather than trying to do a bunch of weird math.
+ for (int i = 0; i < iterations; i++) {
+ coverInfo.adjustTickRateMultiplier(isDecreasing);
+ }
+ }
+
+ private List<String> dynamicTooltip() {
+ final String boundsNotification;
+
+ if (tickRateAddition == 0) {
+ boundsNotification = StatCollector.translateToLocal("gt.cover.info.button.bounds_notification.minimum");
+ } else if (tickRateAddition >= MAX_TICK_RATE_ADDITION - 1) {
+ // Clamping can make tickRateAddition approach but never actually equal MAX_ADDITION, so we need this
+ // adjustment.
+ boundsNotification = StatCollector.translateToLocal("gt.cover.info.button.bounds_notification.maximum");
+ } else {
+ boundsNotification = "";
+ }
+
+ return ImmutableList.of(
+ StatCollector.translateToLocalFormatted(
+ "gt.cover.info.button.tick_rate.1",
+ new CoverInfo.ClientTickRateFormatter(clientTickRate),
+ boundsNotification),
+ StatCollector.translateToLocal("gt.cover.info.button.tick_rate.2"),
+ StatCollector.translateToLocal("gt.cover.info.button.tick_rate.3"));
+ }
+}
diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java
index 57a55fc17e..a7236e164d 100644
--- a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java
+++ b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java
@@ -27,6 +27,7 @@ import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.EnumChatFormatting;
+import net.minecraft.util.StatCollector;
import net.minecraft.world.EnumSkyBlock;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;
@@ -1696,6 +1697,31 @@ public class BaseMetaTileEntity extends CommonMetaTileEntity
dropCover(coverSide, side, false);
}
return true;
+ } else if (GT_Utility.isStackInList(tCurrentItem, GregTech_API.sJackhammerList)) {
+ // Configuration of delicate electronics calls for a tool with precision and subtlety.
+ if (GT_ModHandler.damageOrDechargeItem(tCurrentItem, 1, 1000, aPlayer)) {
+ final CoverInfo info = getCoverInfoAtSide(coverSide);
+ if (info != CoverInfo.EMPTY_INFO) {
+ final GT_CoverBehaviorBase<?> behavior = info.getCoverBehavior();
+ if (behavior.allowsTickRateAddition()) {
+ info.onCoverJackhammer(aPlayer);
+ GT_Utility.sendSoundToPlayers(
+ worldObj,
+ SoundResource.IC2_TOOLS_DRILL_DRILL_SOFT,
+ 1.0F,
+ 1,
+ xCoord,
+ yCoord,
+ zCoord);
+
+ } else {
+ GT_Utility.sendChatToPlayer(
+ aPlayer,
+ StatCollector.translateToLocal("gt.cover.info.chat.tick_rate_not_allowed"));
+ }
+ return true;
+ }
+ }
}
}
// End item != null
diff --git a/src/main/java/gregtech/api/util/GT_CoverBehaviorBase.java b/src/main/java/gregtech/api/util/GT_CoverBehaviorBase.java
index 3300ab43d6..97f02821c1 100644
--- a/src/main/java/gregtech/api/util/GT_CoverBehaviorBase.java
+++ b/src/main/java/gregtech/api/util/GT_CoverBehaviorBase.java
@@ -31,10 +31,12 @@ import gregtech.api.enums.GT_Values;
import gregtech.api.gui.GT_GUIColorOverride;
import gregtech.api.gui.modularui.GT_CoverUIBuildContext;
import gregtech.api.gui.modularui.GT_UIInfos;
+import gregtech.api.gui.widgets.GT_CoverTickRateButton;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.tileentity.ICoverable;
import gregtech.api.net.GT_Packet_TileEntityCoverGUI;
import gregtech.api.objects.GT_ItemStack;
+import gregtech.common.covers.CoverInfo;
/**
* For Covers with a special behavior.
@@ -447,6 +449,15 @@ public abstract class GT_CoverBehaviorBase<T extends ISerializableObject> {
ButtonWidget.closeWindowButton(true)
.setPos(getGUIWidth() - 15, 3));
}
+
+ final CoverInfo coverInfo = uiBuildContext.getTile()
+ .getCoverInfoAtSide(uiBuildContext.getCoverSide());
+ final GT_CoverBehaviorBase<?> behavior = coverInfo.getCoverBehavior();
+ if (coverInfo.getMinimumTickRate() > 0 && behavior.allowsTickRateAddition()) {
+ builder.widget(
+ new GT_CoverTickRateButton(coverInfo, builder).setPos(getGUIWidth() - 24, getGUIHeight() - 24));
+ }
+
return builder.build();
}
@@ -837,6 +848,10 @@ public abstract class GT_CoverBehaviorBase<T extends ISerializableObject> {
return true;
}
+ public boolean allowsTickRateAddition() {
+ return true;
+ }
+
@NotNull
public final List<String> getAdditionalTooltip(ISerializableObject coverData) {
return getAdditionalTooltipImpl(forceCast(coverData));