combine button

This commit is contained in:
GlodBlock committed 2022-07-24 18:00:10 +08:00
1 parent 5747b4535b
commit 736a4b2051
19 files changed
+514 -108

No files matched your search

@@ -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 @@ public class GuiBaseFluidPatternTerminal extends GuiFCBaseMonitor {
{
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 class GuiBaseFluidPatternTerminal extends GuiFCBaseMonitor {
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 class GuiBaseFluidPatternTerminal extends GuiFCBaseMonitor {
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 );
}
@@ -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 @@ public class GuiBaseFluidPatternTerminalEx extends GuiFCBaseMonitor {
{
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 class GuiBaseFluidPatternTerminalEx extends GuiFCBaseMonitor {
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 class GuiBaseFluidPatternTerminalEx extends GuiFCBaseMonitor {
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 );
}
@@ -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<EnumPair, ButtonAppearance> 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;
}
}
@@ -11,7 +11,6 @@ import com.glodblock.github.common.item.ItemFluidPacket;
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;
@@ -28,6 +28,8 @@ import com.glodblock.github.inventory.InventoryHandler;
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 net.minecraft.world.World;
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 class ContainerFluidCraftConfirm extends AEBaseContainer {
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);
}
}
}
@@ -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 class FCBasePartContainer extends FCBaseMonitorContain implements IAEAppE
}
this.substitute = this.patternTerminal.isSubstitution();
this.combine = this.patternTerminal.shouldCombine();
}
}
@@ -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 @@ public class FCBasePartContainerEx extends FCBaseMonitorContain implements IAEAp
if( hasValue )
{
return list.toArray( new ItemStack[list.size()] );
return list.toArray(new ItemStack[0]);
}
return null;
@@ -280,6 +282,7 @@ public class FCBasePartContainerEx extends FCBaseMonitorContain implements IAEAp
if( Platform.isServer() )
{
this.substitute = this.patternTerminal.isSubstitution();
this.combine = this.patternTerminal.shouldCombine();
}
}
@@ -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 class PartFluidPatternTerminal extends FCBasePart {
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 class PartFluidPatternTerminal extends FCBasePart {
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 class PartFluidPatternTerminal extends FCBasePart {
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");
@@ -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 class PartFluidPatternTerminalEx extends FCBasePart {
{
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 class PartFluidPatternTerminalEx extends FCBasePart {
{
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 class PartFluidPatternTerminalEx extends FCBasePart {
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;
@@ -52,11 +52,13 @@ public class TileFluidInterface extends TileInterface implements IFluidHandler,
@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
@@ -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<OrderStack<?>> compress(List<OrderStack<?>> list) {
List<OrderStack<?>> 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<OrderStack<?>> clearNull(List<OrderStack<?>> list) {
List<OrderStack<?>> cleared = new LinkedList<>();
HashMap<Integer, Object> 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;
}
}
@@ -5,19 +5,15 @@ import codechicken.nei.recipe.IRecipeHandler;
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 class ForestryRecipeExtractor implements IRecipeExtractorLegacy {
public List<OrderStack<?>> getInputIngredients(List<PositionedStack> rawInputs, IRecipeHandler recipe, int index) {
TemplateRecipeHandler tRecipe = (TemplateRecipeHandler) recipe;
List<OrderStack<?>> tmp = new ArrayList<>();
List<PositionedStack> compressed = compress(rawInputs);
if (tRecipe.arecipes.get(index) instanceof RecipeHandlerBase.CachedBaseRecipe) {
tmp = getInputIngredients(compressed);
tmp = getInputIngredients(rawInputs);
List<PositionedFluidTank> 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 class ForestryRecipeExtractor implements IRecipeExtractorLegacy {
TemplateRecipeHandler tRecipe = (TemplateRecipeHandler) recipe;
removeGlass(rawOutputs);
List<OrderStack<?>> tmp = new ArrayList<>();
List<PositionedStack> compressed = compress(rawOutputs);
if (tRecipe.arecipes.get(index) instanceof RecipeHandlerBase.CachedBaseRecipe) {
tmp = getOutputIngredients(compressed);
tmp = getOutputIngredients(rawOutputs);
List<PositionedFluidTank> 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<PositionedStack> compress(List<PositionedStack> list) {
List<PositionedStack> 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<PositionedStack> list) {
if (handler instanceof NEIHandlerFabricator) {
list.remove(list.size() - 1);
@@ -12,8 +12,6 @@ import net.minecraftforge.fluids.FluidStack;
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 class GregTech5RecipeExtractor implements IRecipeExtractor {
@Override
public List<OrderStack<?>> getInputIngredients(List<PositionedStack> rawInputs) {
if (r) removeSpecial(rawInputs);
List<PositionedStack> compressed = compress(rawInputs);
List<OrderStack<?>> 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 class GregTech5RecipeExtractor implements IRecipeExtractor {
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 class GregTech5RecipeExtractor implements IRecipeExtractor {
@Override
public List<OrderStack<?>> getOutputIngredients(List<PositionedStack> rawOutputs) {
List<PositionedStack> compressed = compress(rawOutputs);
List<OrderStack<?>> 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 class GregTech5RecipeExtractor implements IRecipeExtractor {
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 @@ public class GregTech5RecipeExtractor implements IRecipeExtractor {
}
}
private List<PositionedStack> compress(List<PositionedStack> list) {
List<PositionedStack> 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());
}
}
@@ -10,8 +10,6 @@ import net.minecraftforge.fluids.FluidStack;
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 class GregTech6RecipeExtractor implements IRecipeExtractor {
@Override
public List<OrderStack<?>> getInputIngredients(List<PositionedStack> rawInputs) {
this.removeMachine(rawInputs);
List<PositionedStack> compressed = compress(rawInputs);
List<OrderStack<?>> 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 class GregTech6RecipeExtractor implements IRecipeExtractor {
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 class GregTech6RecipeExtractor implements IRecipeExtractor {
@Override
public List<OrderStack<?>> getOutputIngredients(List<PositionedStack> rawOutputs) {
List<PositionedStack> compressed = compress(rawOutputs);
List<OrderStack<?>> 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 class GregTech6RecipeExtractor implements IRecipeExtractor {
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 @@ public class GregTech6RecipeExtractor implements IRecipeExtractor {
}
}
private List<PositionedStack> compress(List<PositionedStack> list) {
List<PositionedStack> 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());
}
}
@@ -80,6 +80,9 @@ public class CPacketFluidPatternTermBtns implements IMessage {
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 class CPacketFluidPatternTermBtns implements IMessage {
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;
@@ -62,7 +62,6 @@ public class CPacketSwitchGuis implements IMessage {
InventoryHandler.openGui(player, player.worldObj, new BlockPos(te), Objects.requireNonNull(Util.from(context.getSide())), message.guiType);
return null;
}
}
}
@@ -3,6 +3,7 @@ package com.glodblock.github.network;
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 net.minecraftforge.fluids.FluidStack;
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 class CPacketTransferRecipe implements IMessage {
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 class CPacketTransferRecipe implements IMessage {
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 @@ public class CPacketTransferRecipe implements IMessage {
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 @@ public class CPacketTransferRecipe implements IMessage {
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();