From 5e987a416817e06a7535e9defc748effb7de87d5 Mon Sep 17 00:00:00 2001 From: lordIcocain <62835225+lordIcocain@users.noreply.github.com> Date: Sat, 21 Dec 2024 20:49:01 +0200 Subject: [PATCH] double patterns cribs (#3461) Co-authored-by: Martin Robertz Co-authored-by: Alexdoru <57050655+Alexdoru@users.noreply.github.com> --- .../api/gui/modularui/GTUITextures.java | 1 + .../machines/MTEHatchCraftingInputME.java | 42 +++++++++++++++++- .../textures/gui/overlay_button/x2.png | Bin 0 -> 189 bytes 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/assets/gregtech/textures/gui/overlay_button/x2.png diff --git a/src/main/java/gregtech/api/gui/modularui/GTUITextures.java b/src/main/java/gregtech/api/gui/modularui/GTUITextures.java index 499f043af18..4ea333c5011 100644 --- a/src/main/java/gregtech/api/gui/modularui/GTUITextures.java +++ b/src/main/java/gregtech/api/gui/modularui/GTUITextures.java @@ -409,6 +409,7 @@ public static FallbackableUITexture fallbackableProgressbar(String name, UITextu .fullImage(GregTech.ID, "gui/overlay_button/hourglass"); public static final UITexture OVERLAY_BUTTON_PATTERN_OPTIMIZE = UITexture .fullImage(GregTech.ID, "gui/overlay_button/pattern_optimize"); + public static final UITexture OVERLAY_BUTTON_X2 = UITexture.fullImage(GregTech.ID, "gui/overlay_button/x2"); public static final UITexture OVERLAY_BUTTON_LIQUIDMODE = UITexture .fullImage(GregTech.ID, "gui/overlay_button/LiquidMode"); diff --git a/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java b/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java index b6a8cacc8e3..cb57fb85db6 100644 --- a/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java +++ b/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java @@ -30,6 +30,7 @@ import net.minecraft.util.ChatComponentText; import net.minecraft.util.ChatComponentTranslation; import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.StatCollector; import net.minecraft.world.World; import net.minecraftforge.common.util.Constants; import net.minecraftforge.common.util.ForgeDirection; @@ -75,9 +76,11 @@ import appeng.items.misc.ItemEncodedPattern; import appeng.items.tools.quartz.ToolQuartzCuttingKnife; import appeng.me.GridAccessException; +import appeng.me.cache.CraftingGridCache; import appeng.me.helpers.AENetworkProxy; import appeng.me.helpers.IGridProxyable; import appeng.util.IWideReadableNumberConverter; +import appeng.util.PatternMultiplierHelper; import appeng.util.Platform; import appeng.util.ReadableNumberConverter; import gregtech.GTMod; @@ -745,7 +748,17 @@ protected ItemStack getItemStackForRendering(Slot slotIn) { .addTooltip(0, "Pattern Optimization:\n§7Allowed") .addTooltip(1, "Pattern Optimization:\n§7Disabled") .setPos(170, 10) - .setSize(16, 16)); + .setSize(16, 16)) + .widget(new ButtonWidget().setOnClick((clickData, widget) -> { + int val = clickData.shift ? 1 : 0; + if (clickData.mouseButton == 1) val |= 0b10; + doublePatterns(val); + }) + .setPlayClickSound(true) + .setBackground(GTUITextures.BUTTON_STANDARD, GTUITextures.OVERLAY_BUTTON_X2) + .addTooltip(StatCollector.translateToLocal("gui.tooltips.appliedenergistics2.DoublePatterns")) + .setSize(16, 16) + .setPos(194, 10));; } @Override @@ -1054,4 +1067,31 @@ public List getItemsForHoloGlasses() { } return list; } + + public void doublePatterns(int val) { + boolean fast = (val & 1) != 0; + boolean backwards = (val & 2) != 0; + CraftingGridCache.pauseRebuilds(); + try { + IInventory patterns = this.getPatterns(); + TileEntity te = this.getTileEntity(); + for (int i = 0; i < patterns.getSizeInventory(); i++) { + ItemStack stack = patterns.getStackInSlot(i); + if (stack != null && stack.getItem() instanceof ICraftingPatternItem cpi) { + ICraftingPatternDetails details = cpi.getPatternForItem(stack, te.getWorldObj()); + if (details != null && !details.isCraftable()) { + int max = backwards ? PatternMultiplierHelper.getMaxBitDivider(details) + : PatternMultiplierHelper.getMaxBitMultiplier(details); + if (max > 0) { + ItemStack copy = stack.copy(); + PatternMultiplierHelper + .applyModification(copy, (fast ? Math.min(3, max) : 1) * (backwards ? -1 : 1)); + patterns.setInventorySlotContents(i, copy); + } + } + } + } + } catch (Throwable ignored) {} + CraftingGridCache.unpauseRebuilds(); + } } diff --git a/src/main/resources/assets/gregtech/textures/gui/overlay_button/x2.png b/src/main/resources/assets/gregtech/textures/gui/overlay_button/x2.png new file mode 100644 index 0000000000000000000000000000000000000000..12c9665254894e08f8080fed3d92158656eb9f58 GIT binary patch literal 189 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85qP=L734qNaX`iFv!!zF~q_@S%P&6vztaQ|DX0tFBqKlcR9sK zIWnx4VHY^8@*$IrafgkWeuK)yqlJ=fSAXAM_$6P1m#HO&nf(P