diff --git a/src/main/java/com/glodblock/github/client/gui/GuiBaseFluidPatternTerminal.java b/src/main/java/com/glodblock/github/client/gui/GuiBaseFluidPatternTerminal.java index 74c8576c9..eb531e40d 100644 --- a/src/main/java/com/glodblock/github/client/gui/GuiBaseFluidPatternTerminal.java +++ b/src/main/java/com/glodblock/github/client/gui/GuiBaseFluidPatternTerminal.java @@ -40,6 +40,9 @@ public class GuiBaseFluidPatternTerminal extends GuiFCBaseMonitor { private GuiImgButton clearBtn; private GuiImgButton doubleBtn; + private GuiFCImgButton combineEnableBtn; + private GuiFCImgButton combineDisableBtn; + public GuiBaseFluidPatternTerminal(final InventoryPlayer inventoryPlayer, final ITerminalHost te ) { super( inventoryPlayer, te, new FCBasePartContainer( inventoryPlayer, te ) ); @@ -68,6 +71,10 @@ else if( this.substitutionsEnabledBtn == btn || this.substitutionsDisabledBtn == { FluidCraft.proxy.netHandler.sendToServer( new CPacketFluidPatternTermBtns( "PatternTerminal.Substitute", this.substitutionsEnabledBtn == btn ? SUBSITUTION_DISABLE : SUBSITUTION_ENABLE ) ); } + else if( this.combineDisableBtn == btn || this.combineEnableBtn == btn ) + { + FluidCraft.proxy.netHandler.sendToServer( new CPacketFluidPatternTermBtns( "PatternTerminal.Combine", this.combineDisableBtn == btn ? "1" : "0" ) ); + } else if (ModAndClassUtil.isDoubleButton && doubleBtn == btn) { FluidCraft.proxy.netHandler.sendToServer( new CPacketFluidPatternTermBtns( "PatternTerminal.Double", Keyboard.isKeyDown( Keyboard.KEY_LSHIFT ) ? "1": "0") ); @@ -100,11 +107,22 @@ public void initGui() this.encodeBtn = new GuiImgButton( this.guiLeft + 147, this.guiTop + this.ySize - 142, Settings.ACTIONS, ActionItems.ENCODE ); this.buttonList.add( this.encodeBtn ); + int combineLeft = 74; + if (ModAndClassUtil.isDoubleButton) { this.doubleBtn = new GuiImgButton( this.guiLeft + 74, this.guiTop + this.ySize - 153, Settings.ACTIONS, ActionItems.DOUBLE ); this.doubleBtn.setHalfSize( true ); this.buttonList.add( this.doubleBtn ); + combineLeft = 84; } + + this.combineEnableBtn = new GuiFCImgButton( this.guiLeft + combineLeft, this.guiTop + this.ySize - 153, "FORCE_COMBINE", "DO_COMBINE" ); + this.combineEnableBtn.setHalfSize( true ); + this.buttonList.add( this.combineEnableBtn ); + + this.combineDisableBtn = new GuiFCImgButton( this.guiLeft + combineLeft, this.guiTop + this.ySize - 153, "NOT_COMBINE", "DONT_COMBINE" ); + this.combineDisableBtn.setHalfSize( true ); + this.buttonList.add( this.combineDisableBtn ); } @Override @@ -136,6 +154,25 @@ public void drawFG( final int offsetX, final int offsetY, final int mouseX, fina this.substitutionsDisabledBtn.visible = true; } + if (!this.container.isCraftingMode()) + { + if ( this.container.combine ) + { + this.combineEnableBtn.visible = true; + this.combineDisableBtn.visible = false; + } + else + { + this.combineEnableBtn.visible = false; + this.combineDisableBtn.visible = true; + } + } + else + { + this.combineEnableBtn.visible = false; + this.combineDisableBtn.visible = false; + } + super.drawFG( offsetX, offsetY, mouseX, mouseY ); this.fontRendererObj.drawString(StatCollector.translateToLocal(NameConst.GUI_FLUID_PATTERN_TERMINAL), 8, this.ySize - 96 + 2 - getReservedSpace(), 4210752 ); } diff --git a/src/main/java/com/glodblock/github/client/gui/GuiBaseFluidPatternTerminalEx.java b/src/main/java/com/glodblock/github/client/gui/GuiBaseFluidPatternTerminalEx.java index e57b06e64..d0068f3f1 100644 --- a/src/main/java/com/glodblock/github/client/gui/GuiBaseFluidPatternTerminalEx.java +++ b/src/main/java/com/glodblock/github/client/gui/GuiBaseFluidPatternTerminalEx.java @@ -30,6 +30,9 @@ public class GuiBaseFluidPatternTerminalEx extends GuiFCBaseMonitor { private GuiImgButton clearBtn; private GuiImgButton doubleBtn; + private GuiFCImgButton combineEnableBtn; + private GuiFCImgButton combineDisableBtn; + public GuiBaseFluidPatternTerminalEx(final InventoryPlayer inventoryPlayer, final ITerminalHost te ) { super( inventoryPlayer, te, new FCBasePartContainerEx( inventoryPlayer, te ) ); @@ -54,6 +57,10 @@ else if( this.substitutionsEnabledBtn == btn || this.substitutionsDisabledBtn == { FluidCraft.proxy.netHandler.sendToServer( new CPacketFluidPatternTermBtns( "PatternTerminal.Substitute", this.substitutionsEnabledBtn == btn ? SUBSITUTION_DISABLE : SUBSITUTION_ENABLE ) ); } + else if( this.combineDisableBtn == btn || this.combineEnableBtn == btn ) + { + FluidCraft.proxy.netHandler.sendToServer( new CPacketFluidPatternTermBtns( "PatternTerminal.Combine", this.combineDisableBtn == btn ? "1" : "0" ) ); + } else if (ModAndClassUtil.isDoubleButton && doubleBtn == btn) { FluidCraft.proxy.netHandler.sendToServer( new CPacketFluidPatternTermBtns( "PatternTerminal.Double", Keyboard.isKeyDown( Keyboard.KEY_LSHIFT ) ? "1": "0") ); @@ -86,6 +93,14 @@ public void initGui() this.doubleBtn.setHalfSize( true ); this.buttonList.add( this.doubleBtn ); } + + this.combineEnableBtn = new GuiFCImgButton( this.guiLeft + 87, this.guiTop + this.ySize - 153, "FORCE_COMBINE", "DO_COMBINE" ); + this.combineEnableBtn.setHalfSize( true ); + this.buttonList.add( this.combineEnableBtn ); + + this.combineDisableBtn = new GuiFCImgButton( this.guiLeft + 87, this.guiTop + this.ySize - 153, "NOT_COMBINE", "DONT_COMBINE" ); + this.combineDisableBtn.setHalfSize( true ); + this.buttonList.add( this.combineDisableBtn ); } @Override @@ -105,6 +120,17 @@ public void drawFG( final int offsetX, final int offsetY, final int mouseX, fina this.substitutionsDisabledBtn.visible = true; } + if ( this.container.combine ) + { + this.combineEnableBtn.visible = true; + this.combineDisableBtn.visible = false; + } + else + { + this.combineEnableBtn.visible = false; + this.combineDisableBtn.visible = true; + } + super.drawFG( offsetX, offsetY, mouseX, mouseY ); this.fontRendererObj.drawString( StatCollector.translateToLocal(NameConst.GUI_FLUID_PATTERN_TERMINAL_EX), 8, this.ySize - 96 + 2 - getReservedSpace(), 4210752 ); } diff --git a/src/main/java/com/glodblock/github/client/gui/GuiFCImgButton.java b/src/main/java/com/glodblock/github/client/gui/GuiFCImgButton.java new file mode 100644 index 000000000..3b5b0c2e7 --- /dev/null +++ b/src/main/java/com/glodblock/github/client/gui/GuiFCImgButton.java @@ -0,0 +1,298 @@ +package com.glodblock.github.client.gui; + +import appeng.client.gui.widgets.ITooltip; +import com.glodblock.github.FluidCraft; +import com.glodblock.github.util.NameConst; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.util.StatCollector; +import org.lwjgl.opengl.GL11; + +import java.util.HashMap; +import java.util.Map; +import java.util.regex.Pattern; + +public class GuiFCImgButton extends GuiButton implements ITooltip { + + private static final Pattern COMPILE = Pattern.compile( "%s" ); + private static final Pattern PATTERN_NEW_LINE = Pattern.compile( "\\n", Pattern.LITERAL ); + private static Map appearances; + private final String buttonSetting; + private boolean halfSize = false; + private String fillVar; + private String currentValue; + private static final String prefix = NameConst.TT_KEY; + + public GuiFCImgButton( final int x, final int y, final String idx, final String val ) { + super(0, 0, 16, ""); + + this.buttonSetting = idx; + this.currentValue = val; + this.xPosition = x; + this.yPosition = y; + this.width = 16; + this.height = 16; + + if( appearances == null ) { + appearances = new HashMap<>(); + this.registerApp( 0, "NOT_COMBINE", "DONT_COMBINE", "not_combine" ); + this.registerApp( 1, "FORCE_COMBINE", "DO_COMBINE", "combine" ); + } + } + + private void registerApp(final int iconIndex, final String setting, final String val, final String title ) + { + final ButtonAppearance a = new ButtonAppearance(); + a.displayName = StatCollector.translateToLocal(prefix + title); + a.displayValue = StatCollector.translateToLocal(prefix + title + ".hint"); + a.index = iconIndex; + appearances.put( new EnumPair( setting, val ), a ); + } + + public void setVisibility( final boolean vis ) + { + this.visible = vis; + this.enabled = vis; + } + + private int getIconIndex() + { + if( this.buttonSetting != null && this.currentValue != null ) + { + final ButtonAppearance app = appearances.get(new EnumPair( this.buttonSetting, this.currentValue )); + if( app == null ) + { + return 8; + } + return app.index; + } + return 8; + } + + public String getSetting() + { + return this.buttonSetting; + } + + public String getCurrentValue() + { + return this.currentValue; + } + + public void set( final String e ) + { + if(!this.currentValue.equals(e)) + { + this.currentValue = e; + } + } + + public boolean isHalfSize() + { + return this.halfSize; + } + + public void setHalfSize( final boolean halfSize ) + { + this.halfSize = halfSize; + } + + public String getFillVar() + { + return this.fillVar; + } + + public void setFillVar( final String fillVar ) + { + this.fillVar = fillVar; + } + + @Override + public int xPos() + { + return this.xPosition; + } + + @Override + public int yPos() + { + return this.yPosition; + } + + @Override + public int getWidth() + { + return this.halfSize ? 8 : 16; + } + + @Override + public int getHeight() + { + return this.halfSize ? 8 : 16; + } + + @Override + public boolean isVisible() + { + return this.visible; + } + + @Override + public String getMessage() + { + String displayName = null; + String displayValue = null; + + if( this.buttonSetting != null && this.currentValue != null ) + { + final ButtonAppearance buttonAppearance = appearances.get( new EnumPair( this.buttonSetting, this.currentValue ) ); + if( buttonAppearance == null ) + { + return "No Such Message"; + } + displayName = buttonAppearance.displayName; + displayValue = buttonAppearance.displayValue; + } + + if( displayName != null ) + { + String name = StatCollector.translateToLocal( displayName ); + String value = StatCollector.translateToLocal( displayValue ); + + if( name == null || name.isEmpty() ) + { + name = displayName; + } + if( value == null || value.isEmpty() ) + { + value = displayValue; + } + + if( this.fillVar != null ) + { + value = COMPILE.matcher( value ).replaceFirst( this.fillVar ); + } + + value = PATTERN_NEW_LINE.matcher( value ).replaceAll( "\n" ); + final StringBuilder sb = new StringBuilder( value ); + + int i = sb.lastIndexOf( "\n" ); + if( i <= 0 ) + { + i = 0; + } + while( i + 30 < sb.length() && ( i = sb.lastIndexOf( " ", i + 30 ) ) != -1 ) + { + sb.replace( i, i + 1, "\n" ); + } + + return name + '\n' + sb; + } + return null; + } + + @Override + public void drawButton(final Minecraft par1Minecraft, final int par2, final int par3 ) + { + if( this.visible ) + { + final int iconIndex = this.getIconIndex(); + + if( this.halfSize ) + { + this.width = 8; + this.height = 8; + + GL11.glPushMatrix(); + GL11.glTranslatef( this.xPosition, this.yPosition, 0.0F ); + GL11.glScalef( 0.5f / 16 * 3, 0.5f / 16 * 3, 0.5f / 16 * 3 ); + + if( this.enabled ) + { + GL11.glColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); + } + else + { + GL11.glColor4f( 0.5f, 0.5f, 0.5f, 1.0f ); + } + + par1Minecraft.renderEngine.bindTexture( FluidCraft.resource("textures/gui/states.png") ); + this.field_146123_n = par2 >= this.xPosition && par3 >= this.yPosition && par2 < this.xPosition + this.width && par3 < this.yPosition + this.height; + + final int uv_y = (int) Math.floor( iconIndex / 3.0 ); + final int uv_x = iconIndex - uv_y * 3; + + this.drawTexturedModalRect( 0, 0, Math.round(32F * 16F / 3F), Math.round(32F * 16F / 3F), Math.round(16F * 16F / 3F), Math.round(16F * 16F / 3F) ); + this.drawTexturedModalRect( 0, 0, Math.round(uv_x * 16F * 16F / 3F), Math.round(uv_y * 16F * 16F / 3F), Math.round(16F * 16F / 3F), Math.round(16F * 16F / 3F) ); + this.mouseDragged( par1Minecraft, par2, par3 ); + + GL11.glPopMatrix(); + } + else + { + if( this.enabled ) + { + GL11.glColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); + } + else + { + GL11.glColor4f( 0.5f, 0.5f, 0.5f, 1.0f ); + } + + par1Minecraft.renderEngine.bindTexture( FluidCraft.resource("textures/gui/states.png") ); + this.field_146123_n = par2 >= this.xPosition && par3 >= this.yPosition && par2 < this.xPosition + this.width && par3 < this.yPosition + this.height; + + final int uv_y = (int) Math.floor( iconIndex / 3.0 ); + final int uv_x = iconIndex - uv_y * 3; + + this.drawTexturedModalRect( this.xPosition, this.yPosition, 32, 32, 16, 16 ); + this.drawTexturedModalRect( this.xPosition, this.yPosition, uv_x * 16, uv_y * 16, 16, 16 ); + this.mouseDragged( par1Minecraft, par2, par3 ); + } + } + GL11.glColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); + } + + private static final class EnumPair + { + + final String setting; + final String value; + + EnumPair( final String a, final String b ) + { + this.setting = a; + this.value = b; + } + + @Override + public int hashCode() + { + return this.setting.hashCode() ^ this.value.hashCode(); + } + + @Override + public boolean equals( final Object obj ) + { + if( obj == null ) + { + return false; + } + if( this.getClass() != obj.getClass() ) + { + return false; + } + final EnumPair other = (EnumPair) obj; + return other.setting.equals(this.setting) && other.value.equals(this.value); + } + } + + + private static class ButtonAppearance + { + public int index; + public String displayName; + public String displayValue; + } + +} 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 89a382717..9ece7e85a 100644 --- a/src/main/java/com/glodblock/github/client/gui/GuiFluidPatternTerminal.java +++ b/src/main/java/com/glodblock/github/client/gui/GuiFluidPatternTerminal.java @@ -11,7 +11,6 @@ import com.glodblock.github.inventory.InventoryHandler; import com.glodblock.github.inventory.gui.GuiType; import com.glodblock.github.inventory.slot.SlotSingleItem; -import com.glodblock.github.util.Ae2Reflect; import com.glodblock.github.util.Ae2ReflectClient; import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.InventoryPlayer; diff --git a/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidCraftConfirm.java b/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidCraftConfirm.java index 4dd40490b..42fd7edb5 100644 --- a/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidCraftConfirm.java +++ b/src/main/java/com/glodblock/github/client/gui/container/ContainerFluidCraftConfirm.java @@ -28,6 +28,8 @@ import com.glodblock.github.inventory.gui.GuiType; import com.glodblock.github.network.SPacketMEInventoryUpdate; import com.glodblock.github.util.Ae2Reflect; +import com.glodblock.github.util.BlockPos; +import com.glodblock.github.util.Util; import com.google.common.collect.ImmutableSet; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; @@ -39,6 +41,7 @@ import javax.annotation.Nonnull; import java.util.ArrayList; import java.util.Collections; +import java.util.Objects; import java.util.concurrent.Future; public class ContainerFluidCraftConfirm extends AEBaseContainer { @@ -312,7 +315,7 @@ public void startJob() this.setAutoStart( false ); if( g != null && originalGui != null && this.getOpenContext() != null ) { - InventoryHandler.switchGui(originalGui); + InventoryHandler.openGui(this.getInventoryPlayer().player, getWorld(), new BlockPos(this.getOpenContext().getTile()), Objects.requireNonNull(Util.from(this.getOpenContext().getSide())), originalGui); } } } diff --git a/src/main/java/com/glodblock/github/client/gui/container/FCBasePartContainer.java b/src/main/java/com/glodblock/github/client/gui/container/FCBasePartContainer.java index 490961d67..366882722 100644 --- a/src/main/java/com/glodblock/github/client/gui/container/FCBasePartContainer.java +++ b/src/main/java/com/glodblock/github/client/gui/container/FCBasePartContainer.java @@ -58,6 +58,8 @@ public class FCBasePartContainer extends FCBaseMonitorContain implements IAEAppE public boolean craftingMode = true; @GuiSync( 96 ) public boolean substitute = false; + @GuiSync( 95 ) + public boolean combine = false; public FCBasePartContainer(final InventoryPlayer ip, final ITerminalHost monitorable ) { @@ -457,6 +459,7 @@ public void detectAndSendChanges() } this.substitute = this.patternTerminal.isSubstitution(); + this.combine = this.patternTerminal.shouldCombine(); } } diff --git a/src/main/java/com/glodblock/github/client/gui/container/FCBasePartContainerEx.java b/src/main/java/com/glodblock/github/client/gui/container/FCBasePartContainerEx.java index 77f6b15a4..4378c5ad5 100644 --- a/src/main/java/com/glodblock/github/client/gui/container/FCBasePartContainerEx.java +++ b/src/main/java/com/glodblock/github/client/gui/container/FCBasePartContainerEx.java @@ -39,6 +39,8 @@ public class FCBasePartContainerEx extends FCBaseMonitorContain implements IAEAp protected final SlotRestrictedInput patternSlotOUT; @GuiSync( 96 ) public boolean substitute = false; + @GuiSync( 95 ) + public boolean combine = false; public FCBasePartContainerEx(final InventoryPlayer ip, final ITerminalHost monitorable ) { @@ -222,7 +224,7 @@ private ItemStack[] getOutputs() if( hasValue ) { - return list.toArray( new ItemStack[list.size()] ); + return list.toArray(new ItemStack[0]); } return null; @@ -280,6 +282,7 @@ public void detectAndSendChanges() if( Platform.isServer() ) { this.substitute = this.patternTerminal.isSubstitution(); + this.combine = this.patternTerminal.shouldCombine(); } } diff --git a/src/main/java/com/glodblock/github/common/parts/PartFluidPatternTerminal.java b/src/main/java/com/glodblock/github/common/parts/PartFluidPatternTerminal.java index 413518a4c..d9034af91 100644 --- a/src/main/java/com/glodblock/github/common/parts/PartFluidPatternTerminal.java +++ b/src/main/java/com/glodblock/github/common/parts/PartFluidPatternTerminal.java @@ -40,6 +40,7 @@ public class PartFluidPatternTerminal extends FCBasePart { private boolean craftingMode = true; private boolean substitute = false; + private boolean combine = false; public PartFluidPatternTerminal(ItemStack is) { super(is, true); @@ -81,6 +82,7 @@ public void readFromNBT( final NBTTagCompound data ) super.readFromNBT( data ); this.setCraftingRecipe( data.getBoolean( "craftingMode" ) ); this.setSubstitution( data.getBoolean( "substitute" ) ); + this.setCombineMode( data.getBoolean("combine") ); this.pattern.readFromNBT( data, "pattern" ); this.output.readFromNBT( data, "outputList" ); this.crafting.readFromNBT( data, "craftingGrid" ); @@ -92,6 +94,7 @@ public void writeToNBT( final NBTTagCompound data ) super.writeToNBT( data ); data.setBoolean( "craftingMode", this.craftingMode ); data.setBoolean( "substitute", this.substitute ); + data.setBoolean( "combine", this.combine ); this.pattern.writeToNBT( data, "pattern" ); this.output.writeToNBT( data, "outputList" ); this.crafting.writeToNBT( data, "craftingGrid" ); @@ -244,11 +247,21 @@ public boolean isSubstitution() return this.substitute; } + public boolean shouldCombine() + { + return this.combine; + } + public void setSubstitution( boolean canSubstitute ) { this.substitute = canSubstitute; } + public void setCombineMode(boolean shouldCombine) + { + this.combine = shouldCombine; + } + public void onChangeCrafting(IAEItemStack[] newCrafting, IAEItemStack[] newOutput) { IInventory crafting = this.getInventoryByName("crafting"); IInventory output = this.getInventoryByName("output"); diff --git a/src/main/java/com/glodblock/github/common/parts/PartFluidPatternTerminalEx.java b/src/main/java/com/glodblock/github/common/parts/PartFluidPatternTerminalEx.java index c6f573c14..fd449f987 100644 --- a/src/main/java/com/glodblock/github/common/parts/PartFluidPatternTerminalEx.java +++ b/src/main/java/com/glodblock/github/common/parts/PartFluidPatternTerminalEx.java @@ -39,6 +39,7 @@ public class PartFluidPatternTerminalEx extends FCBasePart { private final AppEngInternalInventory pattern = new AppEngInternalInventory( this, 2 ); private boolean substitute = false; + private boolean combine = false; public PartFluidPatternTerminalEx(ItemStack is) { super(is, true); @@ -79,6 +80,7 @@ public void readFromNBT( final NBTTagCompound data ) { super.readFromNBT( data ); this.setSubstitution( data.getBoolean( "substitute" ) ); + this.setCombineMode( data.getBoolean("combine") ); this.pattern.readFromNBT( data, "pattern" ); this.output.readFromNBT( data, "outputList" ); this.crafting.readFromNBT( data, "craftingGrid" ); @@ -89,6 +91,7 @@ public void writeToNBT( final NBTTagCompound data ) { super.writeToNBT( data ); data.setBoolean( "substitute", this.substitute ); + data.setBoolean( "combine", this.combine ); this.pattern.writeToNBT( data, "pattern" ); this.output.writeToNBT( data, "outputList" ); this.crafting.writeToNBT( data, "craftingGrid" ); @@ -204,6 +207,16 @@ public void onChangeInventory(final IInventory inv, final int slot, final InvOpe onChangeInventory0(inv, slot, mc, removedStack, newStack); } + public boolean shouldCombine() + { + return this.combine; + } + + public void setCombineMode(boolean shouldCombine) + { + this.combine = shouldCombine; + } + public boolean isSubstitution() { return this.substitute; diff --git a/src/main/java/com/glodblock/github/common/tile/TileFluidInterface.java b/src/main/java/com/glodblock/github/common/tile/TileFluidInterface.java index 8cb5268f7..ad0a3bb1a 100644 --- a/src/main/java/com/glodblock/github/common/tile/TileFluidInterface.java +++ b/src/main/java/com/glodblock/github/common/tile/TileFluidInterface.java @@ -52,11 +52,13 @@ public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) { @MENetworkEventSubscribe public void stateChange(final MENetworkChannelsChanged c) { fluidDuality.onChannelStateChange(c); + super.stateChange(c); } @MENetworkEventSubscribe public void stateChange(final MENetworkPowerStatusChange c) { fluidDuality.onPowerStateChange(c); + super.stateChange(c); } @Override diff --git a/src/main/java/com/glodblock/github/nei/NEIUtils.java b/src/main/java/com/glodblock/github/nei/NEIUtils.java new file mode 100644 index 000000000..8ce8931ca --- /dev/null +++ b/src/main/java/com/glodblock/github/nei/NEIUtils.java @@ -0,0 +1,62 @@ +package com.glodblock.github.nei; + +import com.glodblock.github.nei.object.OrderStack; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +public class NEIUtils { + + public static List> compress(List> list) { + List> comp = new LinkedList<>(); + for (OrderStack orderStack : list) { + if (orderStack == null) continue; + if (orderStack.getStack() instanceof FluidStack) { + comp.add(orderStack); + continue; + } + ItemStack currentStack = (ItemStack) orderStack.getStack(); + if (currentStack.stackSize == 0) continue; + boolean find = false; + for (OrderStack storedStack : comp) { + if (storedStack == null || !(orderStack.getStack() instanceof ItemStack)) continue; + ItemStack firstStack = (ItemStack) storedStack.getStack(); + boolean areItemStackEqual = firstStack.isItemEqual(currentStack) && ItemStack.areItemStackTagsEqual(firstStack, currentStack); + if (areItemStackEqual && (firstStack.stackSize + currentStack.stackSize) <= firstStack.getMaxStackSize()) { + find = true; + ((ItemStack) storedStack.getStack()).stackSize = firstStack.stackSize + currentStack.stackSize; + } + } + if (!find) { + comp.add(orderStack); + } + } + return comp.stream().filter(Objects::nonNull).collect(Collectors.toList()); + } + + public static List> clearNull(List> list) { + List> cleared = new LinkedList<>(); + HashMap map = new HashMap<>(); + int upper = 0; + for (OrderStack orderStack : list) { + if (orderStack != null && orderStack.getStack() != null) { + map.put(orderStack.getIndex(), orderStack.getStack()); + upper = Math.max(upper, orderStack.getIndex()); + } + } + int id = 0; + for (int i = 0; i <= upper; i ++) { + if (map.containsKey(i)) { + cleared.add(new OrderStack<>(map.get(i), id)); + id ++; + } + } + return cleared; + } + +} diff --git a/src/main/java/com/glodblock/github/nei/recipes/extractor/ForestryRecipeExtractor.java b/src/main/java/com/glodblock/github/nei/recipes/extractor/ForestryRecipeExtractor.java index d8f7d3c19..ac8ce26c9 100644 --- a/src/main/java/com/glodblock/github/nei/recipes/extractor/ForestryRecipeExtractor.java +++ b/src/main/java/com/glodblock/github/nei/recipes/extractor/ForestryRecipeExtractor.java @@ -5,19 +5,15 @@ import codechicken.nei.recipe.TemplateRecipeHandler; import com.glodblock.github.nei.object.IRecipeExtractorLegacy; import com.glodblock.github.nei.object.OrderStack; -import crazypants.enderio.nei.VatRecipeHandler; import forestry.core.recipes.nei.PositionedFluidTank; import forestry.core.recipes.nei.RecipeHandlerBase; import forestry.factory.recipes.nei.NEIHandlerFabricator; import forestry.factory.recipes.nei.NEIHandlerSqueezer; -import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; -import java.util.Objects; -import java.util.stream.Collectors; public class ForestryRecipeExtractor implements IRecipeExtractorLegacy { @@ -58,14 +54,13 @@ public List> getOutputIngredients(List rawOutputs public List> getInputIngredients(List rawInputs, IRecipeHandler recipe, int index) { TemplateRecipeHandler tRecipe = (TemplateRecipeHandler) recipe; List> tmp = new ArrayList<>(); - List compressed = compress(rawInputs); if (tRecipe.arecipes.get(index) instanceof RecipeHandlerBase.CachedBaseRecipe) { - tmp = getInputIngredients(compressed); + tmp = getInputIngredients(rawInputs); List tanks = ((RecipeHandlerBase.CachedBaseRecipe) tRecipe.arecipes.get(index)).getFluidTanks(); if (tanks.size() > 0 && !(handler instanceof NEIHandlerSqueezer)) { FluidStack fluid = tanks.get(0).tank.getFluid(); if (fluid != null) { - tmp.add(new OrderStack<>(fluid, compressed.size())); + tmp.add(new OrderStack<>(fluid, rawInputs.size())); } } } @@ -77,49 +72,25 @@ public List> getOutputIngredients(List rawOutputs TemplateRecipeHandler tRecipe = (TemplateRecipeHandler) recipe; removeGlass(rawOutputs); List> tmp = new ArrayList<>(); - List compressed = compress(rawOutputs); if (tRecipe.arecipes.get(index) instanceof RecipeHandlerBase.CachedBaseRecipe) { - tmp = getOutputIngredients(compressed); + tmp = getOutputIngredients(rawOutputs); List tanks = ((RecipeHandlerBase.CachedBaseRecipe) tRecipe.arecipes.get(index)).getFluidTanks(); if (tanks.size() > 0 && handler instanceof NEIHandlerSqueezer) { FluidStack fluid = tanks.get(0).tank.getFluid(); if (fluid != null) { - tmp.add(new OrderStack<>(fluid, compressed.size())); + tmp.add(new OrderStack<>(fluid, rawOutputs.size())); } } else if (tanks.size() > 1) { FluidStack fluid = tanks.get(1).tank.getFluid(); if (fluid != null) { - tmp.add(new OrderStack<>(fluid, compressed.size())); + tmp.add(new OrderStack<>(fluid, rawOutputs.size())); } } } return tmp; } - private List compress(List list) { - List comp = new LinkedList<>(); - for (PositionedStack positionedStack : list) { - if (positionedStack == null) continue; - ItemStack currentStack = positionedStack.items[0].copy(); - if (currentStack.stackSize == 0) continue; - boolean find = false; - for (PositionedStack storedStack : comp) { - if (storedStack == null) continue; - ItemStack firstStack = storedStack.items[0].copy(); - boolean areItemStackEqual = firstStack.isItemEqual(currentStack) && ItemStack.areItemStackTagsEqual(firstStack, currentStack); - if (areItemStackEqual && (firstStack.stackSize + currentStack.stackSize) <= firstStack.getMaxStackSize()) { - find = true; - storedStack.items[0].stackSize = firstStack.stackSize + currentStack.stackSize; - } - } - if (!find) { - comp.add(positionedStack.copy()); - } - } - return comp.stream().filter(Objects::nonNull).collect(Collectors.toList()); - } - private void removeGlass(List list) { if (handler instanceof NEIHandlerFabricator) { list.remove(list.size() - 1); diff --git a/src/main/java/com/glodblock/github/nei/recipes/extractor/GregTech5RecipeExtractor.java b/src/main/java/com/glodblock/github/nei/recipes/extractor/GregTech5RecipeExtractor.java index 5cfe7e168..06fb98997 100644 --- a/src/main/java/com/glodblock/github/nei/recipes/extractor/GregTech5RecipeExtractor.java +++ b/src/main/java/com/glodblock/github/nei/recipes/extractor/GregTech5RecipeExtractor.java @@ -12,8 +12,6 @@ import java.util.LinkedList; import java.util.List; -import java.util.Objects; -import java.util.stream.Collectors; public class GregTech5RecipeExtractor implements IRecipeExtractor { @@ -26,11 +24,10 @@ public GregTech5RecipeExtractor(boolean removeSpecial) { @Override public List> getInputIngredients(List rawInputs) { if (r) removeSpecial(rawInputs); - List compressed = compress(rawInputs); List> tmp = new LinkedList<>(); - for (int i = 0; i < compressed.size(); i ++) { - if (compressed.get(i) == null) continue; - ItemStack item = compressed.get(i).items[0]; + for (int i = 0; i < rawInputs.size(); i ++) { + if (rawInputs.get(i) == null) continue; + ItemStack item = rawInputs.get(i).items[0].copy(); OrderStack stack; if (item.getItem() instanceof GT_FluidDisplayItem) { NBTTagCompound aNBT = item.getTagCompound(); @@ -39,7 +36,7 @@ public List> getInputIngredients(List rawInputs) stack = new OrderStack<>(new FluidStack(FluidRegistry.getFluid(item.getItemDamage()), amt), i); tmp.add(stack); } else { - stack = OrderStack.pack(compressed.get(i), i); + stack = OrderStack.pack(rawInputs.get(i), i); if (stack != null) tmp.add(stack); } } @@ -48,11 +45,10 @@ public List> getInputIngredients(List rawInputs) @Override public List> getOutputIngredients(List rawOutputs) { - List compressed = compress(rawOutputs); List> tmp = new LinkedList<>(); - for (int i = 0; i < compressed.size(); i ++) { - if (compressed.get(i) == null) continue; - ItemStack item = compressed.get(i).items[0]; + for (int i = 0; i < rawOutputs.size(); i ++) { + if (rawOutputs.get(i) == null) continue; + ItemStack item = rawOutputs.get(i).items[0].copy(); OrderStack stack; if (item.getItem() instanceof GT_FluidDisplayItem) { NBTTagCompound aNBT = item.getTagCompound(); @@ -61,7 +57,7 @@ public List> getOutputIngredients(List rawOutputs stack = new OrderStack<>(new FluidStack(FluidRegistry.getFluid(item.getItemDamage()), amt), i); tmp.add(stack); } else { - stack = OrderStack.pack(compressed.get(i), i); + stack = OrderStack.pack(rawOutputs.get(i), i); if (stack != null) tmp.add(stack); } } @@ -79,27 +75,4 @@ private void removeSpecial(List list) { } } - private List compress(List list) { - List comp = new LinkedList<>(); - for (PositionedStack positionedStack : list) { - if (positionedStack == null) continue; - ItemStack currentStack = positionedStack.items[0].copy(); - if (currentStack.stackSize == 0) continue; - boolean find = false; - for (PositionedStack storedStack : comp) { - if (storedStack == null) continue; - ItemStack firstStack = storedStack.items[0].copy(); - boolean areItemStackEqual = firstStack.isItemEqual(currentStack) && ItemStack.areItemStackTagsEqual(firstStack, currentStack); - if (areItemStackEqual && (firstStack.stackSize + currentStack.stackSize) <= firstStack.getMaxStackSize()) { - find = true; - storedStack.items[0].stackSize = firstStack.stackSize + currentStack.stackSize; - } - } - if (!find) { - comp.add(positionedStack.copy()); - } - } - return comp.stream().filter(Objects::nonNull).collect(Collectors.toList()); - } - } diff --git a/src/main/java/com/glodblock/github/nei/recipes/extractor/GregTech6RecipeExtractor.java b/src/main/java/com/glodblock/github/nei/recipes/extractor/GregTech6RecipeExtractor.java index 90afa1655..5ffa5956e 100644 --- a/src/main/java/com/glodblock/github/nei/recipes/extractor/GregTech6RecipeExtractor.java +++ b/src/main/java/com/glodblock/github/nei/recipes/extractor/GregTech6RecipeExtractor.java @@ -10,8 +10,6 @@ import java.util.LinkedList; import java.util.List; -import java.util.Objects; -import java.util.stream.Collectors; public class GregTech6RecipeExtractor implements IRecipeExtractor { @@ -24,11 +22,10 @@ public GregTech6RecipeExtractor(Recipe.RecipeMap aMap) { @Override public List> getInputIngredients(List rawInputs) { this.removeMachine(rawInputs); - List compressed = compress(rawInputs); List> tmp = new LinkedList<>(); - for (int i = 0; i < compressed.size(); i ++) { - if (compressed.get(i) == null) continue; - ItemStack item = compressed.get(i).items[0]; + for (int i = 0; i < rawInputs.size(); i ++) { + if (rawInputs.get(i) == null) continue; + ItemStack item = rawInputs.get(i).items[0].copy(); OrderStack stack; if (item.getItem() instanceof ItemFluidDisplay) { FluidStack fluid = ((ItemFluidDisplay) item.getItem()).getFluid(item); @@ -36,7 +33,7 @@ public List> getInputIngredients(List rawInputs) stack = new OrderStack<>(fluid, i); tmp.add(stack); } else { - stack = OrderStack.pack(compressed.get(i), i); + stack = OrderStack.pack(rawInputs.get(i), i); if (stack != null) tmp.add(stack); } } @@ -45,11 +42,10 @@ public List> getInputIngredients(List rawInputs) @Override public List> getOutputIngredients(List rawOutputs) { - List compressed = compress(rawOutputs); List> tmp = new LinkedList<>(); - for (int i = 0; i < compressed.size(); i ++) { - if (compressed.get(i) == null) continue; - ItemStack item = compressed.get(i).items[0]; + for (int i = 0; i < rawOutputs.size(); i ++) { + if (rawOutputs.get(i) == null) continue; + ItemStack item = rawOutputs.get(i).items[0].copy(); OrderStack stack; if (item.getItem() instanceof ItemFluidDisplay) { FluidStack fluid = ((ItemFluidDisplay) item.getItem()).getFluid(item); @@ -57,7 +53,7 @@ public List> getOutputIngredients(List rawOutputs stack = new OrderStack<>(fluid, i); tmp.add(stack); } else { - stack = OrderStack.pack(compressed.get(i), i); + stack = OrderStack.pack(rawOutputs.get(i), i); if (stack != null) tmp.add(stack); } } @@ -78,27 +74,4 @@ private void removeMachine(List list) { } } - private List compress(List list) { - List comp = new LinkedList<>(); - for (PositionedStack positionedStack : list) { - if (positionedStack == null) continue; - ItemStack currentStack = positionedStack.items[0].copy(); - if (currentStack.stackSize == 0) continue; - boolean find = false; - for (PositionedStack storedStack : comp) { - if (storedStack == null) continue; - ItemStack firstStack = storedStack.items[0].copy(); - boolean areItemStackEqual = firstStack.isItemEqual(currentStack) && ItemStack.areItemStackTagsEqual(firstStack, currentStack); - if (areItemStackEqual && (firstStack.stackSize + currentStack.stackSize) <= firstStack.getMaxStackSize()) { - find = true; - storedStack.items[0].stackSize = firstStack.stackSize + currentStack.stackSize; - } - } - if (!find) { - comp.add(positionedStack.copy()); - } - } - return comp.stream().filter(Objects::nonNull).collect(Collectors.toList()); - } - } diff --git a/src/main/java/com/glodblock/github/network/CPacketFluidPatternTermBtns.java b/src/main/java/com/glodblock/github/network/CPacketFluidPatternTermBtns.java index 76a7622a1..c88b681c9 100644 --- a/src/main/java/com/glodblock/github/network/CPacketFluidPatternTermBtns.java +++ b/src/main/java/com/glodblock/github/network/CPacketFluidPatternTermBtns.java @@ -80,6 +80,9 @@ public IMessage onMessage(CPacketFluidPatternTermBtns message, MessageContext ct case "PatternTerminal.Double": cpt.doubleStacks(Value.equals("1")); break; + case "PatternTerminal.Combine": + cpt.getPatternTerminal().setCombineMode(Value.equals("1")); + break; } } else if( Name.startsWith( "PatternTerminal." ) && (c instanceof ContainerFluidPatternTerminalEx)) { @@ -100,6 +103,9 @@ public IMessage onMessage(CPacketFluidPatternTermBtns message, MessageContext ct case "PatternTerminal.Double": cpt.doubleStacks(Value.equals("1")); break; + case "PatternTerminal.Combine": + cpt.getPatternTerminal().setCombineMode(Value.equals("1")); + break; } } else if(Name.equals( "Terminal.Cpu" ) && c instanceof ContainerFluidCraftConfirm) { final ContainerFluidCraftConfirm qk = (ContainerFluidCraftConfirm) c; diff --git a/src/main/java/com/glodblock/github/network/CPacketSwitchGuis.java b/src/main/java/com/glodblock/github/network/CPacketSwitchGuis.java index 7c7ce1c25..c2b37e125 100644 --- a/src/main/java/com/glodblock/github/network/CPacketSwitchGuis.java +++ b/src/main/java/com/glodblock/github/network/CPacketSwitchGuis.java @@ -62,7 +62,6 @@ public IMessage onMessage(CPacketSwitchGuis message, MessageContext ctx) { InventoryHandler.openGui(player, player.worldObj, new BlockPos(te), Objects.requireNonNull(Util.from(context.getSide())), message.guiType); 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 1f522434d..0c2f35bcc 100644 --- a/src/main/java/com/glodblock/github/network/CPacketTransferRecipe.java +++ b/src/main/java/com/glodblock/github/network/CPacketTransferRecipe.java @@ -3,6 +3,7 @@ import com.glodblock.github.client.gui.container.ContainerFluidPatternTerminal; import com.glodblock.github.client.gui.container.ContainerFluidPatternTerminalEx; import com.glodblock.github.common.item.ItemFluidPacket; +import com.glodblock.github.nei.NEIUtils; import com.glodblock.github.nei.object.OrderStack; import cpw.mods.fml.common.network.ByteBufUtils; import cpw.mods.fml.common.network.simpleimpl.IMessage; @@ -18,6 +19,8 @@ import javax.annotation.Nullable; import java.util.LinkedList; import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; public class CPacketTransferRecipe implements IMessage { @@ -80,6 +83,7 @@ public IMessage onMessage(CPacketTransferRecipe message, MessageContext ctx) { Container c = ctx.getServerHandler().playerEntity.openContainer; if (c instanceof ContainerFluidPatternTerminal) { ContainerFluidPatternTerminal cf = (ContainerFluidPatternTerminal) c; + boolean combine = cf.combine; cf.getPatternTerminal().setCraftingRecipe(message.isCraft); IInventory inputSlot = cf.getInventoryByName("crafting"); IInventory outputSlot = cf.getInventoryByName("output"); @@ -89,6 +93,14 @@ public IMessage onMessage(CPacketTransferRecipe message, MessageContext ctx) { for (int i = 0; i < outputSlot.getSizeInventory(); i ++) { outputSlot.setInventorySlotContents(i, null); } + + if (combine) { + message.inputs = NEIUtils.compress(message.inputs); + message.outputs = NEIUtils.compress(message.outputs); + } + message.inputs = NEIUtils.clearNull(message.inputs); + message.outputs = NEIUtils.clearNull(message.outputs); + for (OrderStack stack : message.inputs) { if (stack != null) { int index = stack.getIndex(); @@ -123,6 +135,7 @@ else if (stack.getStack() instanceof FluidStack) { c.onCraftMatrixChanged(outputSlot); } else if (c instanceof ContainerFluidPatternTerminalEx) { ContainerFluidPatternTerminalEx cf = (ContainerFluidPatternTerminalEx) c; + boolean combine = cf.combine; IInventory inputSlot = cf.getInventoryByName("crafting"); IInventory outputSlot = cf.getInventoryByName("output"); for (int i = 0; i < inputSlot.getSizeInventory(); i ++) { @@ -131,6 +144,14 @@ else if (stack.getStack() instanceof FluidStack) { for (int i = 0; i < outputSlot.getSizeInventory(); i ++) { outputSlot.setInventorySlotContents(i, null); } + + if (combine) { + message.inputs = NEIUtils.compress(message.inputs); + message.outputs = NEIUtils.compress(message.outputs); + } + message.inputs = NEIUtils.clearNull(message.inputs); + message.outputs = NEIUtils.clearNull(message.outputs); + for (OrderStack stack : message.inputs) { if (stack != null) { int index = stack.getIndex(); diff --git a/src/main/resources/assets/ae2fc/lang/en_US.lang b/src/main/resources/assets/ae2fc/lang/en_US.lang index edae99ab7..c750f6b43 100644 --- a/src/main/resources/assets/ae2fc/lang/en_US.lang +++ b/src/main/resources/assets/ae2fc/lang/en_US.lang @@ -35,6 +35,10 @@ ae2fc.tooltip.fluid_packet=Use a Fluid Packet Decoder to\nconvert this back into ae2fc.tooltip.empty=Empty ae2fc.tooltip.dump_tank=Dump Tank Contents ae2fc.tooltip.switch_fluid_interface=Switch ME Dual Interface GUI +ae2fc.tooltip.not_combine=Merge the same items +ae2fc.tooltip.not_combine.hint=Disabled +ae2fc.tooltip.combine=Merge the same items +ae2fc.tooltip.combine.hint=Enabled ae2fc.gui.part_fluid_pattern_terminal=Fluid Pattern Terminal ae2fc.gui.part_fluid_pattern_terminal_ex=Fluid Processing Pattern Terminal diff --git a/src/main/resources/assets/ae2fc/textures/gui/states.png b/src/main/resources/assets/ae2fc/textures/gui/states.png new file mode 100644 index 000000000..ce994c2e4 Binary files /dev/null and b/src/main/resources/assets/ae2fc/textures/gui/states.png differ