Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x2 button funtional for fluid pattern terminals. And varions fixes. #252

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 {

Expand Down Expand Up @@ -144,6 +147,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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 {

Expand Down Expand Up @@ -179,7 +181,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();
Expand Down
152 changes: 152 additions & 0 deletions src/main/java/com/glodblock/github/client/gui/GuiPatternMulti.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -537,15 +539,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) {
Expand Down Expand Up @@ -595,6 +592,7 @@ static void multiplyOrDivideStacksInternal(SlotFake[] slots, int mult) {
ItemFluidPacket.setFluidAmount(st, ItemFluidPacket.getFluidAmount(st) * mult);
} else {
st.stackSize *= mult;
s.putStack(st);
}
}
}
Expand All @@ -607,12 +605,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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading