diff --git a/src/main/java/com/glodblock/github/client/gui/GuiFluidPatternTerminal.java b/src/main/java/com/glodblock/github/client/gui/GuiFluidPatternTerminal.java index af7410955..8febe5a15 100644 --- a/src/main/java/com/glodblock/github/client/gui/GuiFluidPatternTerminal.java +++ b/src/main/java/com/glodblock/github/client/gui/GuiFluidPatternTerminal.java @@ -6,10 +6,12 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.StatCollector; +import com.glodblock.github.FluidCraft; import com.glodblock.github.client.gui.base.FCGuiEncodeTerminal; import com.glodblock.github.client.gui.container.ContainerFluidPatternTerminal; import com.glodblock.github.client.gui.container.ContainerFluidPatternWireless; import com.glodblock.github.inventory.item.IWirelessTerminal; +import com.glodblock.github.network.CPacketInventoryAction; import com.glodblock.github.util.ModAndClassUtil; import com.glodblock.github.util.NameConst; @@ -24,6 +26,7 @@ import appeng.container.slot.SlotFakeCraftingMatrix; import appeng.container.slot.SlotPatternTerm; import appeng.core.localization.GuiText; +import appeng.helpers.InventoryAction; public class GuiFluidPatternTerminal extends FCGuiEncodeTerminal { @@ -143,6 +146,18 @@ public void drawFG(final int offsetX, final int offsetY, final int mouseX, final 4210752); } + @Override + protected void mouseClicked(final int xCoord, final int yCoord, final int btn) { + + if (btn == 2 && doubleBtn.mousePressed(this.mc, xCoord, yCoord)) { // + InventoryAction action = InventoryAction.SET_PATTERN_MULTI; + + final CPacketInventoryAction p = new CPacketInventoryAction(action, 0, 0); + FluidCraft.proxy.netHandler.sendToServer(p); + } else super.mouseClicked(xCoord, yCoord, btn); + + } + @Override protected void handleMouseClick(final Slot slot, final int slotIdx, final int ctrlDown, final int mouseButton) { if (mouseButton == 3) { diff --git a/src/main/java/com/glodblock/github/client/gui/GuiFluidPatternTerminalEx.java b/src/main/java/com/glodblock/github/client/gui/GuiFluidPatternTerminalEx.java index 4c4bcbcef..5cd0d1e8b 100644 --- a/src/main/java/com/glodblock/github/client/gui/GuiFluidPatternTerminalEx.java +++ b/src/main/java/com/glodblock/github/client/gui/GuiFluidPatternTerminalEx.java @@ -11,6 +11,7 @@ import com.glodblock.github.client.gui.container.ContainerFluidPatternTerminalEx; import com.glodblock.github.inventory.item.IWirelessTerminal; import com.glodblock.github.network.CPacketFluidPatternTermBtns; +import com.glodblock.github.network.CPacketInventoryAction; import com.glodblock.github.util.ModAndClassUtil; import com.glodblock.github.util.NameConst; @@ -21,6 +22,7 @@ import appeng.api.config.Settings; import appeng.api.storage.ITerminalHost; import appeng.client.gui.widgets.GuiImgButton; +import appeng.helpers.InventoryAction; public class GuiFluidPatternTerminalEx extends FCGuiEncodeTerminal { @@ -178,7 +180,12 @@ public void drawScreen(final int mouseX, final int mouseY, final float btn) { protected void mouseClicked(final int xCoord, final int yCoord, final int btn) { final int currentScroll = this.processingScrollBar.getCurrentScroll(); this.processingScrollBar.click(this, xCoord - this.guiLeft, yCoord - this.guiTop); - super.mouseClicked(xCoord, yCoord, btn); + if (btn == 2 && doubleBtn.mousePressed(this.mc, xCoord, yCoord)) { // + InventoryAction action = InventoryAction.SET_PATTERN_MULTI; + + final CPacketInventoryAction p = new CPacketInventoryAction(action, 0, 0); + FluidCraft.proxy.netHandler.sendToServer(p); + } else super.mouseClicked(xCoord, yCoord, btn); if (currentScroll != this.processingScrollBar.getCurrentScroll()) { changeActivePage(); diff --git a/src/main/java/com/glodblock/github/client/gui/GuiPatternMulti.java b/src/main/java/com/glodblock/github/client/gui/GuiPatternMulti.java new file mode 100644 index 000000000..7b500aab8 --- /dev/null +++ b/src/main/java/com/glodblock/github/client/gui/GuiPatternMulti.java @@ -0,0 +1,152 @@ +package com.glodblock.github.client.gui; + +import net.minecraft.client.gui.GuiButton; +import net.minecraft.entity.player.InventoryPlayer; + +import com.glodblock.github.FluidCraft; +import com.glodblock.github.common.item.ItemWirelessUltraTerminal; +import com.glodblock.github.common.parts.PartFluidPatternTerminal; +import com.glodblock.github.common.parts.PartFluidPatternTerminalEx; +import com.glodblock.github.common.parts.PartFluidTerminal; +import com.glodblock.github.common.parts.PartLevelTerminal; +import com.glodblock.github.inventory.gui.GuiType; +import com.glodblock.github.inventory.item.IWirelessTerminal; +import com.glodblock.github.inventory.item.WirelessLevelTerminalInventory; +import com.glodblock.github.inventory.item.WirelessPatternTerminalInventory; +import com.glodblock.github.loader.ItemAndBlockHolder; +import com.glodblock.github.network.CPacketPatternMultiSet; + +import appeng.api.config.ActionItems; +import appeng.api.config.Settings; +import appeng.api.storage.ITerminalHost; +import appeng.client.gui.implementations.GuiAmount; +import appeng.client.gui.widgets.GuiImgButton; +import appeng.container.implementations.ContainerPatternMulti; +import appeng.core.localization.GuiColors; +import appeng.core.localization.GuiText; +import appeng.helpers.Reflected; +import appeng.util.calculators.ArithHelper; +import appeng.util.calculators.Calculator; + +public class GuiPatternMulti extends GuiAmount { + + private static final int DEFAULT_VALUE = 0; + private GuiImgButton symbolSwitch; + protected GuiType originalGui; + + @Reflected + public GuiPatternMulti(final InventoryPlayer inventoryPlayer, final ITerminalHost te) { + super(new ContainerPatternMulti(inventoryPlayer, te)); + } + + @Override + public void initGui() { + super.initGui(); + + this.buttonList.add( + this.symbolSwitch = new GuiImgButton( + this.guiLeft + 22, + this.guiTop + 53, + Settings.ACTIONS, + ActionItems.MULTIPLY)); + + this.amountTextField.xPosition = this.guiLeft + 50; + this.amountTextField.setText(String.valueOf(DEFAULT_VALUE)); + this.amountTextField.setSelectionPos(0); + } + + @Override + public void drawFG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) { + this.fontRendererObj + .drawString(GuiText.SelectAmount.getLocal(), 8, 6, GuiColors.CraftAmountSelectAmount.getColor()); + } + + @Override + public void drawBG(final int offsetX, final int offsetY, final int mouseX, final int mouseY) { + super.drawBG(offsetX, offsetY, mouseX, mouseY); + this.nextBtn.displayString = GuiText.Set.getLocal(); + + try { + int resultI = getAmount(); + + this.symbolSwitch.set(resultI >= 0 ? ActionItems.MULTIPLY : ActionItems.DIVIDE); + this.nextBtn.enabled = resultI < -1 || resultI > 1; + } catch (final NumberFormatException e) { + this.nextBtn.enabled = false; + } + + this.amountTextField.drawTextBox(); + } + + @Override + protected void actionPerformed(final GuiButton btn) { + super.actionPerformed(btn); + + try { + + if (btn == this.nextBtn && btn.enabled) { + int resultI = getAmount(); + if (resultI > 1 || resultI < -1) + FluidCraft.proxy.netHandler.sendToServer(new CPacketPatternMultiSet(this.originalGui, resultI)); + } + } catch (final NumberFormatException e) { + // nope.. + this.amountTextField.setText(String.valueOf(DEFAULT_VALUE)); + } + + if (btn == this.symbolSwitch) { + int resultI = -getAmount(); + this.amountTextField.setText(Integer.toString(resultI)); + } + + } + + @Override + protected int getAmount() { + String out = this.amountTextField.getText(); + + double resultD = Calculator.conversion(out); + + if (Double.isNaN(resultD)) { + return DEFAULT_VALUE; + } else { + return (int) ArithHelper.round(resultD, 0); + } + } + + @Override + protected int addOrderAmount(final int i) { + return i + getAmount(); + } + + @Override + protected String getBackground() { + return "guis/patternMulti.png"; + } + + @Override + protected void setOriginGUI(Object target) { + if (target instanceof PartFluidPatternTerminal) { + this.myIcon = ItemAndBlockHolder.FLUID_TERMINAL.stack(); + this.originalGui = GuiType.FLUID_PATTERN_TERMINAL; + } else if (target instanceof PartFluidPatternTerminalEx) { + this.myIcon = ItemAndBlockHolder.FLUID_TERMINAL_EX.stack(); + this.originalGui = GuiType.FLUID_PATTERN_TERMINAL_EX; + } else if (target instanceof PartFluidTerminal) { + this.myIcon = ItemAndBlockHolder.FLUID_TERM.stack(); + this.originalGui = GuiType.FLUID_TERMINAL; + } else if (target instanceof PartLevelTerminal) { + myIcon = ItemAndBlockHolder.LEVEL_TERMINAL.stack(); + originalGui = GuiType.LEVEL_TERMINAL; + } else if (target instanceof IWirelessTerminal terminal && terminal.isUniversal(target)) { + this.myIcon = ItemAndBlockHolder.WIRELESS_ULTRA_TERM.stack(); + this.originalGui = ItemWirelessUltraTerminal.readMode(terminal.getItemStack()); + } else if (target instanceof WirelessPatternTerminalInventory) { + this.myIcon = ItemAndBlockHolder.WIRELESS_PATTERN_TERM.stack(); + this.originalGui = GuiType.FLUID_TERMINAL; + } else if (target instanceof WirelessLevelTerminalInventory) { + myIcon = ItemAndBlockHolder.LEVEL_TERMINAL.stack(); + originalGui = GuiType.WIRELESS_LEVEL_TERMINAL; + } + } +} diff --git a/src/main/java/com/glodblock/github/client/gui/base/FCGuiEncodeTerminal.java b/src/main/java/com/glodblock/github/client/gui/base/FCGuiEncodeTerminal.java index 5bce694ed..f6d294eb1 100644 --- a/src/main/java/com/glodblock/github/client/gui/base/FCGuiEncodeTerminal.java +++ b/src/main/java/com/glodblock/github/client/gui/base/FCGuiEncodeTerminal.java @@ -117,11 +117,10 @@ protected void actionPerformed(final GuiButton btn) { "PatternTerminal.Combine", this.combineDisableBtn == btn ? "1" : "0")); } else if (ModAndClassUtil.isDoubleButton && doubleBtn == btn) { - final int eventButton = Mouse.getEventButton(); - FluidCraft.proxy.netHandler.sendToServer( - new CPacketFluidPatternTermBtns( - "PatternTerminal.Double", - (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) ? "1" : "0") + (eventButton == 1 ? "1" : "0"))); + int val = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) ? 1 : 0; + if (Mouse.isButtonDown(1)) val |= 0b10; + FluidCraft.proxy.netHandler + .sendToServer(new CPacketFluidPatternTermBtns("PatternTerminal.Double", String.valueOf(val))); } else if (ModAndClassUtil.isBeSubstitutionsButton && beSubstitutionsDisabledBtn == btn) { FluidCraft.proxy.netHandler .sendToServer(new CPacketFluidPatternTermBtns("PatternTerminal.beSubstitute", "1")); diff --git a/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidPatternTerminal.java b/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidPatternTerminal.java index 798624d28..6988496e8 100644 --- a/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidPatternTerminal.java +++ b/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidPatternTerminal.java @@ -153,9 +153,9 @@ private void setCraftingMode(final boolean craftingMode) { } @Override - public void doubleStacks(boolean isShift, boolean divide) { + public void doubleStacks(int val) { if (!isCraftingMode()) { - super.doubleStacks(isShift, divide); + super.doubleStacks(val); } } } diff --git a/src/main/java/com/glodblock/github/client/gui/container/ContainerPatternMulti.java b/src/main/java/com/glodblock/github/client/gui/container/ContainerPatternMulti.java new file mode 100644 index 000000000..6199ec44e --- /dev/null +++ b/src/main/java/com/glodblock/github/client/gui/container/ContainerPatternMulti.java @@ -0,0 +1,38 @@ +package com.glodblock.github.client.gui.container; + +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.world.World; + +import appeng.api.config.SecurityPermissions; +import appeng.api.networking.IGrid; +import appeng.api.networking.security.BaseActionSource; +import appeng.api.networking.security.IActionHost; +import appeng.api.networking.security.PlayerSource; +import appeng.api.storage.ITerminalHost; +import appeng.container.AEBaseContainer; + +public class ContainerPatternMulti extends AEBaseContainer { + + public ContainerPatternMulti(final InventoryPlayer ip, final ITerminalHost te) { + super(ip, te); + } + + @Override + public void detectAndSendChanges() { + super.detectAndSendChanges(); + this.verifyPermissions(SecurityPermissions.CRAFT, false); + } + + public IGrid getGrid() { + final IActionHost h = ((IActionHost) this.getTarget()); + return h.getActionableNode().getGrid(); + } + + public World getWorld() { + return this.getPlayerInv().player.worldObj; + } + + public BaseActionSource getActionSrc() { + return new PlayerSource(this.getPlayerInv().player, (IActionHost) this.getTarget()); + } +} diff --git a/src/main/java/com/glodblock/github/client/gui/container/base/FCContainerEncodeTerminal.java b/src/main/java/com/glodblock/github/client/gui/container/base/FCContainerEncodeTerminal.java index bf6b8cc3c..51e5dadb9 100644 --- a/src/main/java/com/glodblock/github/client/gui/container/base/FCContainerEncodeTerminal.java +++ b/src/main/java/com/glodblock/github/client/gui/container/base/FCContainerEncodeTerminal.java @@ -53,6 +53,8 @@ public abstract class FCContainerEncodeTerminal extends ContainerItemMonitor implements IAEAppEngInventory, IOptionalSlotHost, IContainerCraftingPacket, IPatternConsumer { + public static final int MULTIPLE_OF_BUTTON_CLICK = 2; + public static final int MULTIPLE_OF_BUTTON_CLICK_ON_SHIFT = 8; protected final IItemPatternTerminal patternTerminal; protected final AppEngInternalInventory cOut = new AppEngInternalInventory(null, 1); protected final IInventory crafting; @@ -538,15 +540,10 @@ public boolean useRealItems() { return false; } - public void doubleStacks(boolean isShift, boolean divide) { - if (!isCraftingMode()) { - final int mult = (isShift ? 8 : 2) * (divide ? -1 : 1); - if (canMultiplyOrDivide(this.craftingSlots, mult) && canMultiplyOrDivide(this.outputSlots, mult)) { - multiplyOrDivideStacksInternal(this.craftingSlots, mult); - multiplyOrDivideStacksInternal(this.outputSlots, mult); - } - this.detectAndSendChanges(); - } + public void doubleStacks(int val) { + multiplyOrDivideStacks( + ((val & 1) != 0 ? MULTIPLE_OF_BUTTON_CLICK_ON_SHIFT : MULTIPLE_OF_BUTTON_CLICK) + * ((val & 2) != 0 ? -1 : 1)); } static boolean canMultiplyOrDivide(SlotFake[] slots, int mult) { @@ -596,6 +593,7 @@ static void multiplyOrDivideStacksInternal(SlotFake[] slots, int mult) { ItemFluidPacket.setFluidAmount(st, ItemFluidPacket.getFluidAmount(st) * mult); } else { st.stackSize *= mult; + s.putStack(st); } } } @@ -608,12 +606,28 @@ static void multiplyOrDivideStacksInternal(SlotFake[] slots, int mult) { ItemFluidPacket.setFluidAmount(st, ItemFluidPacket.getFluidAmount(st) / mult); } else { st.stackSize /= mult; + s.putStack(st); } } } } } + /** + * Multiply or divide a number + * + * @param multi Positive numbers are multiplied and negative numbers are divided + */ + public void multiplyOrDivideStacks(int multi) { + if (!isCraftingMode()) { + if (canMultiplyOrDivide(this.craftingSlots, multi) && canMultiplyOrDivide(this.outputSlots, multi)) { + multiplyOrDivideStacksInternal(this.craftingSlots, multi); + multiplyOrDivideStacksInternal(this.outputSlots, multi); + } + this.detectAndSendChanges(); + } + } + @Override public void acceptPattern(IAEItemStack[] inputs, IAEItemStack[] outputs) { if (this.patternTerminal != null) { diff --git a/src/main/java/com/glodblock/github/inventory/ItemBiggerAppEngInventory.java b/src/main/java/com/glodblock/github/inventory/ItemBiggerAppEngInventory.java index 08a070b18..0ae64beac 100644 --- a/src/main/java/com/glodblock/github/inventory/ItemBiggerAppEngInventory.java +++ b/src/main/java/com/glodblock/github/inventory/ItemBiggerAppEngInventory.java @@ -32,7 +32,9 @@ public void markDirty() { boolean isCraft = Platform.openNbtData(is).getBoolean("craftingMode"); boolean isCraftingTerm = Platform.openNbtData(is).getString("mode_main") .equals(GuiType.WIRELESS_CRAFTING_TERMINAL.toString()); - if (!isCraftingTerm && isCraft) { + boolean isExPattern = Platform.openNbtData(is).getString("mode_main") + .equals(GuiType.WIRELESS_FLUID_PATTERN_TERMINAL_EX.toString()); + if (!isCraftingTerm && !isExPattern && isCraft) { for (int x = 0; x < this.getSizeInventory(); x++) { final ItemStack is = this.getStackInSlot(x); if (is != null) { diff --git a/src/main/java/com/glodblock/github/inventory/gui/GuiType.java b/src/main/java/com/glodblock/github/inventory/gui/GuiType.java index 824aaaeda..49e5890f8 100644 --- a/src/main/java/com/glodblock/github/inventory/gui/GuiType.java +++ b/src/main/java/com/glodblock/github/inventory/gui/GuiType.java @@ -34,6 +34,7 @@ import com.glodblock.github.client.gui.GuiLevelTerminal; import com.glodblock.github.client.gui.GuiLevelWireless; import com.glodblock.github.client.gui.GuiOCPatternEditor; +import com.glodblock.github.client.gui.GuiPatternMulti; import com.glodblock.github.client.gui.GuiPatternValueAmount; import com.glodblock.github.client.gui.GuiRenamer; import com.glodblock.github.client.gui.container.ContainerCraftingWireless; @@ -61,6 +62,7 @@ import com.glodblock.github.client.gui.container.ContainerLevelTerminal; import com.glodblock.github.client.gui.container.ContainerLevelWireless; import com.glodblock.github.client.gui.container.ContainerOCPatternEditor; +import com.glodblock.github.client.gui.container.ContainerPatternMulti; import com.glodblock.github.client.gui.container.ContainerPatternValueAmount; import com.glodblock.github.client.gui.container.ContainerRenamer; import com.glodblock.github.common.parts.PartFluidLevelEmitter; @@ -512,6 +514,19 @@ protected Object createServerGui(EntityPlayer player, ITerminalHost inv) { protected Object createClientGui(EntityPlayer player, ITerminalHost inv) { return new GuiPatternValueAmount(player.inventory, inv); } + }), + + GUI_PATTERN_MULTI(new PartOrItemGuiFactory<>(ITerminalHost.class) { + + @Override + protected Object createServerGui(EntityPlayer player, ITerminalHost inv) { + return new ContainerPatternMulti(player.inventory, inv); + } + + @Override + protected Object createClientGui(EntityPlayer player, ITerminalHost inv) { + return new GuiPatternMulti(player.inventory, inv); + } }); public static final List VALUES = ImmutableList.copyOf(values()); diff --git a/src/main/java/com/glodblock/github/loader/ChannelLoader.java b/src/main/java/com/glodblock/github/loader/ChannelLoader.java index bd5244f6e..1bccece49 100644 --- a/src/main/java/com/glodblock/github/loader/ChannelLoader.java +++ b/src/main/java/com/glodblock/github/loader/ChannelLoader.java @@ -13,6 +13,7 @@ import com.glodblock.github.network.CPacketInventoryAction; import com.glodblock.github.network.CPacketLevelMaintainer; import com.glodblock.github.network.CPacketLevelTerminalCommands; +import com.glodblock.github.network.CPacketPatternMultiSet; import com.glodblock.github.network.CPacketPatternValueSet; import com.glodblock.github.network.CPacketRenamer; import com.glodblock.github.network.CPacketSwitchGuis; @@ -78,6 +79,8 @@ public void run() { CPacketLevelTerminalCommands.class, id++, Side.SERVER); + netHandler + .registerMessage(new CPacketPatternMultiSet.Handler(), CPacketPatternMultiSet.class, id++, Side.SERVER); } public static void sendPacketToAllPlayers(Packet packet, World world) { diff --git a/src/main/java/com/glodblock/github/network/CPacketFluidPatternTermBtns.java b/src/main/java/com/glodblock/github/network/CPacketFluidPatternTermBtns.java index 8af7d79d1..44e0e4233 100644 --- a/src/main/java/com/glodblock/github/network/CPacketFluidPatternTermBtns.java +++ b/src/main/java/com/glodblock/github/network/CPacketFluidPatternTermBtns.java @@ -77,7 +77,7 @@ public IMessage onMessage(CPacketFluidPatternTermBtns message, MessageContext ct case "PatternTerminal.Clear" -> cpt.clear(); case "PatternTerminal.Substitute" -> cpt.getPatternTerminal().setSubstitution(Value.equals("1")); case "PatternTerminal.Invert" -> cpt.getPatternTerminal().setInverted(Value.equals("1")); - case "PatternTerminal.Double" -> cpt.doubleStacks(Value.charAt(0) == '1', Value.charAt(1) == '1'); + case "PatternTerminal.Double" -> cpt.doubleStacks(Integer.parseInt(message.Value)); case "PatternTerminal.Combine" -> cpt.getPatternTerminal().setCombineMode(Value.equals("1")); case "PatternTerminal.beSubstitute" -> cpt.getPatternTerminal().setBeSubstitute(Value.equals("1")); case "PatternTerminal.ActivePage" -> diff --git a/src/main/java/com/glodblock/github/network/CPacketInventoryAction.java b/src/main/java/com/glodblock/github/network/CPacketInventoryAction.java index c20fc7c98..b4b960839 100644 --- a/src/main/java/com/glodblock/github/network/CPacketInventoryAction.java +++ b/src/main/java/com/glodblock/github/network/CPacketInventoryAction.java @@ -11,6 +11,7 @@ import net.minecraftforge.fluids.FluidStack; import com.glodblock.github.FluidCraft; +import com.glodblock.github.client.gui.container.ContainerPatternMulti; import com.glodblock.github.client.gui.container.ContainerPatternValueAmount; import com.glodblock.github.common.item.ItemFluidPacket; import com.glodblock.github.inventory.InventoryHandler; @@ -105,12 +106,12 @@ public IMessage onMessage(CPacketInventoryAction message, MessageContext ctx) { new BlockPos(te), Objects.requireNonNull(baseContainer.getOpenContext().getSide()), GuiType.FLUID_CRAFTING_AMOUNT); - } else if (target instanceof IWirelessTerminal) { + } else if (target instanceof IWirelessTerminal wt) { InventoryHandler.openGui( sender, sender.worldObj, new BlockPos( - ((IWirelessTerminal) target).getInventorySlot(), + wt.getInventorySlot(), Util.GuiHelper.encodeType(0, Util.GuiHelper.GuiType.ITEM), 0), ForgeDirection.UNKNOWN, @@ -135,12 +136,12 @@ public IMessage onMessage(CPacketInventoryAction message, MessageContext ctx) { new BlockPos(te), Objects.requireNonNull(baseContainer.getOpenContext().getSide()), GuiType.PATTERN_VALUE_SET); - } else if (target instanceof IWirelessTerminal) { + } else if (target instanceof IWirelessTerminal wt) { InventoryHandler.openGui( sender, sender.worldObj, new BlockPos( - ((IWirelessTerminal) target).getInventorySlot(), + wt.getInventorySlot(), Util.GuiHelper.encodeType(0, Util.GuiHelper.GuiType.ITEM), 0), ForgeDirection.UNKNOWN, @@ -160,6 +161,32 @@ public IMessage onMessage(CPacketInventoryAction message, MessageContext ctx) { cpv.detectAndSendChanges(); } } + } else if (message.action == InventoryAction.SET_PATTERN_MULTI) { + final ContainerOpenContext context = baseContainer.getOpenContext(); + if (context != null) { + final TileEntity te = context.getTile(); + if (te != null) { + InventoryHandler.openGui( + sender, + te.getWorldObj(), + new BlockPos(te), + Objects.requireNonNull(baseContainer.getOpenContext().getSide()), + GuiType.GUI_PATTERN_MULTI); + } else if (target instanceof IWirelessTerminal wt) { + InventoryHandler.openGui( + sender, + sender.worldObj, + new BlockPos( + wt.getInventorySlot(), + Util.GuiHelper.encodeType(0, Util.GuiHelper.GuiType.ITEM), + 0), + ForgeDirection.UNKNOWN, + GuiType.GUI_PATTERN_MULTI); + } + if (sender.openContainer instanceof ContainerPatternMulti cpm) { + cpm.detectAndSendChanges(); + } + } } else { baseContainer.doAction(sender, message.action, message.slot, message.id); } diff --git a/src/main/java/com/glodblock/github/network/CPacketPatternMultiSet.java b/src/main/java/com/glodblock/github/network/CPacketPatternMultiSet.java new file mode 100644 index 000000000..e3656d2bb --- /dev/null +++ b/src/main/java/com/glodblock/github/network/CPacketPatternMultiSet.java @@ -0,0 +1,89 @@ +package com.glodblock.github.network; + +import java.util.Objects; + +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; + +import com.glodblock.github.client.gui.container.ContainerPatternMulti; +import com.glodblock.github.client.gui.container.base.FCContainerEncodeTerminal; +import com.glodblock.github.inventory.InventoryHandler; +import com.glodblock.github.inventory.gui.GuiType; +import com.glodblock.github.inventory.item.IWirelessTerminal; +import com.glodblock.github.util.BlockPos; +import com.glodblock.github.util.Util; + +import appeng.api.networking.IGridHost; +import appeng.container.ContainerOpenContext; +import cpw.mods.fml.common.network.simpleimpl.IMessage; +import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; +import cpw.mods.fml.common.network.simpleimpl.MessageContext; +import io.netty.buffer.ByteBuf; + +public class CPacketPatternMultiSet implements IMessage { + + private static GuiType guiType; + private static int multi; + + public CPacketPatternMultiSet(GuiType guiType, int multi) { + CPacketPatternMultiSet.guiType = guiType; + CPacketPatternMultiSet.multi = multi; + } + + public CPacketPatternMultiSet() { + // NO-OP + } + + @Override + public void fromBytes(ByteBuf byteBuf) { + guiType = GuiType.getByOrdinal(byteBuf.readByte()); + multi = byteBuf.readInt(); + } + + @Override + public void toBytes(ByteBuf byteBuf) { + byteBuf.writeByte(guiType != null ? guiType.ordinal() : 0); + byteBuf.writeInt(multi); + } + + public static class Handler implements IMessageHandler { + + @Override + public IMessage onMessage(CPacketPatternMultiSet message, MessageContext ctx) { + EntityPlayerMP player = ctx.getServerHandler().playerEntity; + if (player.openContainer instanceof ContainerPatternMulti cpv) { + final Object target = cpv.getTarget(); + if (target instanceof IGridHost) { + final ContainerOpenContext context = cpv.getOpenContext(); + if (context != null) { + final TileEntity te = context.getTile(); + if (te != null) { + InventoryHandler.openGui( + player, + te.getWorldObj(), + new BlockPos(te), + Objects.requireNonNull(cpv.getOpenContext().getSide()), + guiType); + } else if (target instanceof IWirelessTerminal wt) { + InventoryHandler.openGui( + player, + player.worldObj, + new BlockPos( + wt.getInventorySlot(), + Util.GuiHelper.encodeType(0, Util.GuiHelper.GuiType.ITEM), + 0), + ForgeDirection.UNKNOWN, + guiType); + } + if (player.openContainer instanceof FCContainerEncodeTerminal cpt) { + cpt.multiplyOrDivideStacks(multi); + } + } + } + } + return null; + } + } + +} diff --git a/src/main/java/com/glodblock/github/network/CPacketTransferRecipe.java b/src/main/java/com/glodblock/github/network/CPacketTransferRecipe.java index 8d8931319..77917c8fa 100644 --- a/src/main/java/com/glodblock/github/network/CPacketTransferRecipe.java +++ b/src/main/java/com/glodblock/github/network/CPacketTransferRecipe.java @@ -32,7 +32,8 @@ public class CPacketTransferRecipe implements IMessage { private List> inputs; private List> outputs; private boolean isCraft; - private static final int MAX_INDEX = 32; + private static final int MAX_INDEX = 81; + private static final int MAX_SLOTS_INDEX = 32; private boolean shift; public CPacketTransferRecipe() {} @@ -79,11 +80,11 @@ public void fromBytes(ByteBuf buf) { NBTTagCompound nbt_o = nbt_m.getCompoundTag("o"); for (int i = 0; i < MAX_INDEX; i++) { OrderStack tmp = OrderStack.readFromNBT(nbt_i, null, i); - if (tmp != null) inputs.add(tmp); + if (tmp != null && inputs.size() < MAX_SLOTS_INDEX) inputs.add(tmp); } for (int i = 0; i < MAX_INDEX; i++) { OrderStack tmp = OrderStack.readFromNBT(nbt_o, null, i); - if (tmp != null) outputs.add(tmp); + if (tmp != null && inputs.size() < MAX_SLOTS_INDEX) outputs.add(tmp); } } diff --git a/src/main/resources/assets/ae2fc/textures/gui/patternMulti.png b/src/main/resources/assets/ae2fc/textures/gui/patternMulti.png new file mode 100644 index 000000000..74874d2e0 Binary files /dev/null and b/src/main/resources/assets/ae2fc/textures/gui/patternMulti.png differ