Skip to content

Commit

Permalink
double patterns cribs (#3461)
Browse files Browse the repository at this point in the history
Co-authored-by: Martin Robertz <dream-master@gmx.net>
Co-authored-by: Alexdoru <57050655+Alexdoru@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 21, 2024
1 parent 33e2ec6 commit 5e987a4
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/main/java/gregtech/api/gui/modularui/GTUITextures.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1054,4 +1067,31 @@ public List<ItemStack> 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();
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5e987a4

Please sign in to comment.