diff --git a/src/main/java/logisticspipes/gui/GuiCraftingPipe.java b/src/main/java/logisticspipes/gui/GuiCraftingPipe.java index 0cf5b8bd2..dce52800f 100644 --- a/src/main/java/logisticspipes/gui/GuiCraftingPipe.java +++ b/src/main/java/logisticspipes/gui/GuiCraftingPipe.java @@ -52,6 +52,8 @@ public class GuiCraftingPipe extends ModuleBaseGui { private GuiButton cleanupModeButton; + private FluidCraftingExtention fluidCraftingExtention = null; + public GuiCraftingPipe(EntityPlayer player, IInventory dummyInventory, ModuleCrafter module, boolean isAdvancedSat, int liquidCrafter, int[] amount, boolean hasByproductExtractor, boolean isFuzzy, int cleanupSize, boolean cleanupExclude) { @@ -139,10 +141,10 @@ public void initGui() { super.initGui(); extentionControllerLeft.clear(); buttonList.clear(); - FluidCraftingExtention extention = null; + fluidCraftingExtention = null; if (!isAdvancedSat) { if (liquidCrafter != 0) { - extention = new FluidCraftingExtention(0); + fluidCraftingExtention = new FluidCraftingExtention(0); } addButton( normalButtonArray[0] = new SmallGuiButton( @@ -193,7 +195,7 @@ public void initGui() { 10, "<")); if (liquidCrafter != 0) { - extention.registerButton( + fluidCraftingExtention.registerButton( extentionControllerLeft.registerControlledButton( addButton( normalButtonArray[6] = new SmallGuiButton( @@ -203,7 +205,7 @@ public void initGui() { 10, 10, ">")))); - extention.registerButton( + fluidCraftingExtention.registerButton( extentionControllerLeft.registerControlledButton( addButton( normalButtonArray[7] = new SmallGuiButton( @@ -268,7 +270,7 @@ public void initGui() { } for (int i = 0; i < liquidCrafter; i++) { if (isAdvancedSat) { - extention = new FluidCraftingExtention(i); + fluidCraftingExtention = new FluidCraftingExtention(i); } int liquidLeft = 0; if (isAdvancedSat) { @@ -277,7 +279,7 @@ public void initGui() { liquidLeft = guiLeft - (liquidCrafter * 40) + (i * 40); } liquidGuiParts[i] = new GuiButton[10]; - extention.registerButton( + fluidCraftingExtention.registerButton( extentionControllerLeft.registerControlledButton( addButton( liquidGuiParts[i][0] = new SmallGuiButton( @@ -287,7 +289,7 @@ public void initGui() { 10, 10, "+")))); - extention.registerButton( + fluidCraftingExtention.registerButton( extentionControllerLeft.registerControlledButton( addButton( liquidGuiParts[i][1] = new SmallGuiButton( @@ -297,7 +299,7 @@ public void initGui() { 10, 10, "+")))); - extention.registerButton( + fluidCraftingExtention.registerButton( extentionControllerLeft.registerControlledButton( addButton( liquidGuiParts[i][2] = new SmallGuiButton( @@ -307,7 +309,7 @@ public void initGui() { 10, 10, "+")))); - extention.registerButton( + fluidCraftingExtention.registerButton( extentionControllerLeft.registerControlledButton( addButton( liquidGuiParts[i][3] = new SmallGuiButton( @@ -317,7 +319,7 @@ public void initGui() { 10, 10, "+")))); - extention.registerButton( + fluidCraftingExtention.registerButton( extentionControllerLeft.registerControlledButton( addButton( liquidGuiParts[i][4] = new SmallGuiButton( @@ -327,7 +329,7 @@ public void initGui() { 10, 10, "-")))); - extention.registerButton( + fluidCraftingExtention.registerButton( extentionControllerLeft.registerControlledButton( addButton( liquidGuiParts[i][5] = new SmallGuiButton( @@ -337,7 +339,7 @@ public void initGui() { 10, 10, "-")))); - extention.registerButton( + fluidCraftingExtention.registerButton( extentionControllerLeft.registerControlledButton( addButton( liquidGuiParts[i][6] = new SmallGuiButton( @@ -347,7 +349,7 @@ public void initGui() { 10, 10, "-")))); - extention.registerButton( + fluidCraftingExtention.registerButton( extentionControllerLeft.registerControlledButton( addButton( liquidGuiParts[i][7] = new SmallGuiButton( @@ -358,7 +360,7 @@ public void initGui() { 10, "-")))); if (isAdvancedSat) { - extention.registerButton( + fluidCraftingExtention.registerButton( extentionControllerLeft.registerControlledButton( addButton( liquidGuiParts[i][8] = new SmallGuiButton( @@ -368,7 +370,7 @@ public void initGui() { 10, 10, "<")))); - extention.registerButton( + fluidCraftingExtention.registerButton( extentionControllerLeft.registerControlledButton( addButton( liquidGuiParts[i][9] = new SmallGuiButton( @@ -378,12 +380,12 @@ public void initGui() { 10, 10, ">")))); - extentionControllerLeft.addExtention(extention); + extentionControllerLeft.addExtention(fluidCraftingExtention); } - extention.registerSlot(fluidSlotIDs[i]); + fluidCraftingExtention.registerSlot(fluidSlotIDs[i]); } if (!isAdvancedSat && liquidCrafter != 0) { - extentionControllerLeft.addExtention(extention); + extentionControllerLeft.addExtention(fluidCraftingExtention); } if (hasByproductExtractor) { ByproductExtention byproductExtention = new ByproductExtention(); diff --git a/src/main/java/logisticspipes/gui/modules/ModuleBaseGui.java b/src/main/java/logisticspipes/gui/modules/ModuleBaseGui.java index ab5cb7be3..6ea9be0c2 100644 --- a/src/main/java/logisticspipes/gui/modules/ModuleBaseGui.java +++ b/src/main/java/logisticspipes/gui/modules/ModuleBaseGui.java @@ -22,12 +22,12 @@ public ModuleBaseGui(Container par1Container, LogisticsGuiModule module) { @Override protected void keyTyped(char c, int i) { - if (module == null) { - super.keyTyped(c, i); - return; - } + // Fix for NEI integration + super.keyTyped(c, i); + + if (module == null) return; + if (i == 1 || c == 'e') { - super.keyTyped(c, i); if (module.getSlot() == ModulePositionType.SLOT) { MainProxy.sendPacketToServer( PacketHandler.getPacket(GuiOpenChassie.class).setPosX(module.getX()).setPosY(module.getY()) diff --git a/src/main/java/logisticspipes/gui/popup/GuiRecipeImport.java b/src/main/java/logisticspipes/gui/popup/GuiRecipeImport.java index de79852e3..a8c8837c1 100644 --- a/src/main/java/logisticspipes/gui/popup/GuiRecipeImport.java +++ b/src/main/java/logisticspipes/gui/popup/GuiRecipeImport.java @@ -10,8 +10,11 @@ import net.minecraft.client.renderer.entity.RenderItem; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.fluids.FluidStack; import logisticspipes.network.PacketHandler; +import logisticspipes.network.abstractpackets.ModuleCoordinatesPacket; +import logisticspipes.network.packets.NEISetAdvancedCraftingRecipe; import logisticspipes.network.packets.NEISetCraftingRecipe; import logisticspipes.network.packets.pipe.FindMostLikelyRecipeComponents; import logisticspipes.proxy.MainProxy; @@ -38,13 +41,24 @@ public Canidates(Set set) { private final RenderItem itemRenderer = new RenderItem(); private final TileEntity tile; + private final ModuleCoordinatesPacket modulePacket; + private final List outputs; + private final List fluidInputs; private final Canidates[] grid = new Canidates[9]; private final List list; private Object[] tooltip = null; public GuiRecipeImport(TileEntity tile, ItemStack[][] stacks) { + this(tile, stacks, null, null, null); + } + + public GuiRecipeImport(TileEntity tile, ItemStack[][] stacks, ModuleCoordinatesPacket modulePacket, + List outputs, List fluidInputs) { super(150, 200, 0, 0); this.tile = tile; + this.modulePacket = modulePacket; + this.outputs = outputs; + this.fluidInputs = fluidInputs; list = new ArrayList<>(); for (int i = 0; i < 9; i++) { if (stacks[i] == null) { @@ -133,7 +147,7 @@ protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { itemStack, guiLeft + 45 + x * 18, guiTop + 20 + y * 18, - null); + itemStack.stackSize > 1 ? String.valueOf(itemStack.stackSize) : null); if (guiLeft + 45 + x * 18 < mouseX && mouseX < guiLeft + 45 + x * 18 + 16 && guiTop + 20 + y * 18 < mouseY @@ -234,13 +248,35 @@ protected void actionPerformed(GuiButton button) { } stack[i++] = canidate.order.get(canidate.pos).makeNormalStack(); } - NEISetCraftingRecipe packet = PacketHandler.getPacket(NEISetCraftingRecipe.class); - MainProxy.sendPacketToServer( - packet.setContent(stack).setPosX(tile.xCoord).setPosY(tile.yCoord).setPosZ(tile.zCoord)); + if (modulePacket instanceof NEISetAdvancedCraftingRecipe) { + List inputs = new ArrayList<>(); + for (ItemStack s : stack) { + if (s != null) { + inputs.add(s); + } + } + ((NEISetAdvancedCraftingRecipe) modulePacket).setInputs(inputs).setOutputs(outputs) + .setFluidInputs(fluidInputs); + MainProxy.sendPacketToServer(modulePacket); + } else { + NEISetCraftingRecipe packet = PacketHandler.getPacket(NEISetCraftingRecipe.class); + MainProxy.sendPacketToServer( + packet.setContent(stack).setPosX(tile.xCoord).setPosY(tile.yCoord).setPosZ(tile.zCoord)); + } exitGui(); } else if (id == 1) { - MainProxy.sendPacketToServer( - PacketHandler.getPacket(FindMostLikelyRecipeComponents.class).setContent(list).setTilePos(tile)); + FindMostLikelyRecipeComponents packet = PacketHandler.getPacket(FindMostLikelyRecipeComponents.class) + .setContent(list); + if (tile != null) { + packet.setTilePos(tile); + } else if (modulePacket != null) { + packet.setPosX(modulePacket.getPosX()); + packet.setPosY(modulePacket.getPosY()); + packet.setPosZ(modulePacket.getPosZ()); + } else { + return; + } + MainProxy.sendPacketToServer(packet); } else if (id >= 10 && id < 30) { int slot = id % 10; boolean up = id < 20; diff --git a/src/main/java/logisticspipes/modules/ModuleCrafter.java b/src/main/java/logisticspipes/modules/ModuleCrafter.java index df37bb55f..39d8ad36e 100644 --- a/src/main/java/logisticspipes/modules/ModuleCrafter.java +++ b/src/main/java/logisticspipes/modules/ModuleCrafter.java @@ -24,6 +24,7 @@ import net.minecraft.world.World; import net.minecraftforge.common.util.Constants; import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.FluidStack; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -968,6 +969,51 @@ public void setDummyInventorySlot(int slot, ItemStack itemstack) { _dummyInventory.setInventorySlotContents(slot, itemstack); } + public void handleNEIRecipePacket(ItemStack[] content, EntityPlayer player) { + _dummyInventory.clearGrid(); + for (int i = 0; i < content.length; i++) { + if (i < _dummyInventory.getSizeInventory()) { + _dummyInventory.setInventorySlotContents(i, content[i]); + } + } + if (player != null) { + MainProxy.sendPacketToPlayer(getCPipePacket(), player); + } + } + + public void handleAdvancedNEIRecipePacket(List inputs, List outputs, + List fluidInputs, EntityPlayer player) { + _dummyInventory.clearGrid(); + int itemSlot = 0; + for (int i = 0; i < inputs.size() && itemSlot < 9; i++) { + ItemStack stack = inputs.get(i); + _dummyInventory.setInventorySlotContents(itemSlot++, stack); + } + if (!outputs.isEmpty()) { + _dummyInventory.setInventorySlotContents(9, outputs.get(0)); + if (outputs.size() > 1) { + _dummyInventory.setInventorySlotContents(10, outputs.get(1)); + } + } + + // Populate liquids + _liquidInventory.clearGrid(); + for (int i = 0; i < amount.length; i++) { + amount[i] = 0; + } + + for (int i = 0; i < fluidInputs.size() && i < _liquidInventory.getSizeInventory(); i++) { + FluidStack fs = fluidInputs.get(i); + if (fs != null && fs.getFluid() != null) { + _liquidInventory.setInventorySlotContents(i, FluidIdentifier.get(fs).getItemIdentifier().makeStack(1)); + amount[i] = fs.amount; + } + } + if (player != null) { + MainProxy.sendPacketToPlayer(getCPipePacket(), player); + } + } + public void importFromCraftingTable(EntityPlayer player) { if (MainProxy.isClient(getWorld())) { // Send packet asking for import diff --git a/src/main/java/logisticspipes/nei/CraftingPipeOverlayHandler.java b/src/main/java/logisticspipes/nei/CraftingPipeOverlayHandler.java new file mode 100644 index 000000000..69787a6d6 --- /dev/null +++ b/src/main/java/logisticspipes/nei/CraftingPipeOverlayHandler.java @@ -0,0 +1,188 @@ +package logisticspipes.nei; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +import codechicken.nei.PositionedStack; +import codechicken.nei.api.IOverlayHandler; +import codechicken.nei.recipe.IRecipeHandler; +import codechicken.nei.recipe.StackInfo; +import logisticspipes.gui.GuiCraftingPipe; +import logisticspipes.gui.popup.GuiRecipeImport; +import logisticspipes.modules.ModuleCrafter; +import logisticspipes.network.PacketHandler; +import logisticspipes.network.packets.NEISetAdvancedCraftingRecipe; +import logisticspipes.utils.gui.SubGuiScreen; +import logisticspipes.utils.item.ItemIdentifier; + +public class CraftingPipeOverlayHandler implements IOverlayHandler { + + @Override + public void overlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean maxTransfer) { + + if (!(firstGui instanceof GuiCraftingPipe)) { + return; + } + + GuiCraftingPipe gui = (GuiCraftingPipe) firstGui; + ModuleCrafter module = gui.get_pipe(); + + List> inputOptions = new ArrayList<>(); + List outputs = new ArrayList<>(); + List fluidInputs = new ArrayList<>(); + + for (PositionedStack ps : recipe.getIngredientStacks(recipeIndex)) { + if (ps.items != null && ps.items.length > 0) { + FluidStack fluid = StackInfo.getFluid(ps.items[0]); + + if (fluid != null) { + fluidInputs.add(fluid); + } else { + List options = new ArrayList<>(Arrays.asList(ps.items)); + inputOptions.add(options); + } + + } else { + inputOptions.add(null); + } + } + + PositionedStack result = recipe.getResultStack(recipeIndex); + if (result != null && result.items != null && result.items.length > 0) { + outputs.add(result.items[0]); + } + + for (PositionedStack ps : recipe.getOtherStacks(recipeIndex)) { + if (ps.items != null && ps.items.length > 0) { + outputs.add(ps.items[0]); + } + } + + final List finalFluidInputs = collapseFluids(fluidInputs); + final List finalOutputs = collapseStacks(outputs); + + List> collapsedInputOptions = collapseInputOptions(inputOptions); + + // Special check if we don't have any substitutions + boolean allSingle = true; + for (List options : collapsedInputOptions) { + if (options != null && options.size() > 1) { + allSingle = false; + break; + } + } + + if (allSingle) { + NEISetAdvancedCraftingRecipe packet = PacketHandler.getPacket(NEISetAdvancedCraftingRecipe.class); + packet.setModulePos(module); + List inputs = new ArrayList<>(); + for (List options : collapsedInputOptions) { + if (options != null && !options.isEmpty()) { + inputs.add(options.get(0)); + } + } + packet.setInputs(inputs).setOutputs(finalOutputs).setFluidInputs(finalFluidInputs); + logisticspipes.proxy.MainProxy.sendPacketToServer(packet); + return; + } + + ItemStack[][] stacks = new ItemStack[9][]; + int i = 0; + for (List options : collapsedInputOptions) { + if (options != null) { + stacks[i] = options.toArray(new ItemStack[0]); + } + i++; + if (i >= 9) break; + } + + NEISetAdvancedCraftingRecipe packet = PacketHandler.getPacket(NEISetAdvancedCraftingRecipe.class); + packet.setModulePos(module); + + GuiRecipeImport subGui = new GuiRecipeImport(null, stacks, packet, finalOutputs, finalFluidInputs); + if (!gui.hasSubGui()) { + gui.setSubGui(subGui); + } else { + SubGuiScreen next = gui.getSubGui(); + while (next.hasSubGui()) { + next = next.getSubGui(); + } + next.setSubGui(subGui); + } + } + + private List collapseFluids(List fluids) { + List result = new ArrayList<>(); + for (FluidStack fluid : fluids) { + if (fluid == null || fluid.getFluid() == null) continue; + boolean found = false; + for (FluidStack existing : result) { + if (existing.isFluidEqual(fluid)) { + existing.amount += fluid.amount; + found = true; + break; + } + } + if (!found) { + result.add(fluid.copy()); + } + } + return result; + } + + private List> collapseInputOptions(List> inputOptions) { + List> result = new ArrayList<>(); + for (List options : inputOptions) { + if (options == null || options.isEmpty()) continue; + boolean found = false; + for (List existingOptions : result) { + if (optionsAreEqual(options, existingOptions)) { + for (int i = 0; i < existingOptions.size(); i++) { + existingOptions.get(i).stackSize += options.get(i).stackSize; + } + found = true; + break; + } + } + if (!found) { + List copy = new ArrayList<>(); + for (ItemStack stack : options) { + copy.add(stack.copy()); + } + result.add(copy); + } + } + return result; + } + + private boolean optionsAreEqual(List options1, List options2) { + if (options1.size() != options2.size()) return false; + for (int i = 0; i < options1.size(); i++) { + ItemStack stack1 = options1.get(i); + ItemStack stack2 = options2.get(i); + if (!ItemIdentifier.get(stack1).equals(ItemIdentifier.get(stack2))) return false; + } + return true; + } + + private List collapseStacks(List stacks) { + Map collapsed = new LinkedHashMap<>(); + for (ItemStack stack : stacks) { + if (stack == null) continue; + ItemIdentifier id = ItemIdentifier.get(stack); + collapsed.put(id, collapsed.getOrDefault(id, 0) + stack.stackSize); + } + List result = new ArrayList<>(); + for (Map.Entry entry : collapsed.entrySet()) { + result.add(entry.getKey().makeNormalStack(entry.getValue())); + } + return result; + } +} diff --git a/src/main/java/logisticspipes/nei/NEILogisticsPipesConfig.java b/src/main/java/logisticspipes/nei/NEILogisticsPipesConfig.java index 40cc1d1d9..b8b2d60a5 100644 --- a/src/main/java/logisticspipes/nei/NEILogisticsPipesConfig.java +++ b/src/main/java/logisticspipes/nei/NEILogisticsPipesConfig.java @@ -42,14 +42,50 @@ public void loadConfig() { API.registerRecipeHandler(new NEISolderingStationRecipeManager()); API.registerUsageHandler(new NEISolderingStationRecipeManager()); + API.registerGuiOverlay(GuiSolderingStation.class, "solderingstation"); + + API.registerGuiOverlay(GuiLogisticsCraftingTable.class, "crafting"); + API.registerGuiOverlayHandler( GuiLogisticsCraftingTable.class, new LogisticsCraftingOverlayHandler(), "crafting"); API.registerGuiOverlayHandler(GuiRequestTable.class, new LogisticsCraftingOverlayHandler(), "crafting"); + API.registerGuiOverlayHandler( + logisticspipes.gui.GuiCraftingPipe.class, + new CraftingPipeOverlayHandler(), + "crafting"); + API.registerGuiOverlayHandler( + logisticspipes.gui.GuiCraftingPipe.class, + new CraftingPipeOverlayHandler(), + "smelting"); + + API.registerGuiOverlayHandler(logisticspipes.gui.GuiCraftingPipe.class, new CraftingPipeOverlayHandler(), null); + if (LogisticsPipes.isGTNH) { + + for (gregtech.api.recipe.RecipeMap map : gregtech.api.recipe.RecipeMap.ALL_RECIPE_MAPS.values()) { + if (!map.unlocalizedName.isEmpty()) { + API.registerGuiOverlay(logisticspipes.gui.GuiCraftingPipe.class, map.unlocalizedName); + API.registerGuiOverlayHandler( + logisticspipes.gui.GuiCraftingPipe.class, + new CraftingPipeOverlayHandler(), + map.unlocalizedName); + API.registerGuiOverlay(GuiLogisticsCraftingTable.class, map.unlocalizedName); + API.registerGuiOverlayHandler( + GuiLogisticsCraftingTable.class, + new LogisticsCraftingOverlayHandler(), + map.unlocalizedName); + API.registerGuiOverlay(GuiRequestTable.class, map.unlocalizedName); + API.registerGuiOverlayHandler( + GuiRequestTable.class, + new LogisticsCraftingOverlayHandler(), + map.unlocalizedName); + } + } + // unused stuff API.hideItem(new ItemStack(LogisticsPipes.LogisticsPipeComponents, 1, OreDictionary.WILDCARD_VALUE)); API.hideItem(new ItemStack(LogisticsPipes.LogisticsSolidBlock, 1, 0)); diff --git a/src/main/java/logisticspipes/network/LPDataInputStream.java b/src/main/java/logisticspipes/network/LPDataInputStream.java index e12745709..df28144ae 100644 --- a/src/main/java/logisticspipes/network/LPDataInputStream.java +++ b/src/main/java/logisticspipes/network/LPDataInputStream.java @@ -9,12 +9,14 @@ import java.util.List; import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTSizeTracker; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.FluidStack; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufInputStream; @@ -171,6 +173,27 @@ public ItemIdentifierStack readItemIdentifierStack() throws IOException { return new ItemIdentifierStack(item, stacksize); } + public ItemStack readItemStack() throws IOException { + if (!readBoolean()) { + return null; + } + int itemID = readInt(); + int stackSize = readInt(); + int damage = readInt(); + NBTTagCompound tag = readNBTTagCompound(); + ItemStack stack = new ItemStack(Item.getItemById(itemID), stackSize, damage); + stack.setTagCompound(tag); + return stack; + } + + public FluidStack readFluidStack() throws IOException { + if (!readBoolean()) { + return null; + } + NBTTagCompound tag = readNBTTagCompound(); + return FluidStack.loadFluidStackFromNBT(tag); + } + public List readList(IReadListObject handler) throws IOException { int size = readInt(); List list = new ArrayList<>(size); diff --git a/src/main/java/logisticspipes/network/LPDataOutputStream.java b/src/main/java/logisticspipes/network/LPDataOutputStream.java index 8872d11a2..f7bf397ec 100644 --- a/src/main/java/logisticspipes/network/LPDataOutputStream.java +++ b/src/main/java/logisticspipes/network/LPDataOutputStream.java @@ -10,9 +10,11 @@ import java.util.List; import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.FluidStack; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufOutputStream; @@ -150,6 +152,27 @@ public void writeItemIdentifierStack(ItemIdentifierStack stack) throws IOExcepti writeInt(stack.getStackSize()); } + public void writeItemStack(ItemStack stack) throws IOException { + if (stack == null) { + writeBoolean(false); + } else { + writeBoolean(true); + writeInt(Item.getIdFromItem(stack.getItem())); + writeInt(stack.stackSize); + writeInt(stack.getItemDamage()); + writeNBTTagCompound(stack.getTagCompound()); + } + } + + public void writeFluidStack(FluidStack stack) throws IOException { + if (stack == null) { + writeBoolean(false); + } else { + writeBoolean(true); + writeNBTTagCompound(stack.writeToNBT(new NBTTagCompound())); + } + } + public void writeList(List list, IWriteListObject handler) throws IOException { writeInt(list.size()); for (T t : list) { diff --git a/src/main/java/logisticspipes/network/packets/NEISetAdvancedCraftingRecipe.java b/src/main/java/logisticspipes/network/packets/NEISetAdvancedCraftingRecipe.java new file mode 100644 index 000000000..fcdd08108 --- /dev/null +++ b/src/main/java/logisticspipes/network/packets/NEISetAdvancedCraftingRecipe.java @@ -0,0 +1,88 @@ +package logisticspipes.network.packets; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +import logisticspipes.modules.ModuleCrafter; +import logisticspipes.network.LPDataInputStream; +import logisticspipes.network.LPDataOutputStream; +import logisticspipes.network.abstractpackets.ModernPacket; +import logisticspipes.network.abstractpackets.ModuleCoordinatesPacket; +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.Accessors; + +@Accessors(chain = true) +public class NEISetAdvancedCraftingRecipe extends ModuleCoordinatesPacket { + + @Getter + @Setter + private List inputs = new ArrayList<>(); + + @Getter + @Setter + private List outputs = new ArrayList<>(); + + @Getter + @Setter + private List fluidInputs = new ArrayList<>(); + + public NEISetAdvancedCraftingRecipe(int id) { + super(id); + } + + @Override + public void processPacket(EntityPlayer player) { + ModuleCrafter module = getLogisticsModule(player, ModuleCrafter.class); + if (module != null) { + module.handleAdvancedNEIRecipePacket(inputs, outputs, fluidInputs, player); + } + } + + @Override + public ModernPacket template() { + return new NEISetAdvancedCraftingRecipe(getId()); + } + + @Override + public void writeData(LPDataOutputStream data) throws IOException { + super.writeData(data); + data.writeInt(inputs.size()); + for (ItemStack stack : inputs) { + data.writeItemStack(stack); + } + data.writeInt(outputs.size()); + for (ItemStack stack : outputs) { + data.writeItemStack(stack); + } + data.writeInt(fluidInputs.size()); + for (FluidStack stack : fluidInputs) { + data.writeFluidStack(stack); + } + } + + @Override + public void readData(LPDataInputStream data) throws IOException { + super.readData(data); + int inputSize = data.readInt(); + inputs = new ArrayList<>(inputSize); + for (int i = 0; i < inputSize; i++) { + inputs.add(data.readItemStack()); + } + int outputSize = data.readInt(); + outputs = new ArrayList<>(outputSize); + for (int i = 0; i < outputSize; i++) { + outputs.add(data.readItemStack()); + } + int fluidSize = data.readInt(); + fluidInputs = new ArrayList<>(fluidSize); + for (int i = 0; i < fluidSize; i++) { + fluidInputs.add(data.readFluidStack()); + } + } +} diff --git a/src/main/java/logisticspipes/network/packets/NEISetCraftingRecipe.java b/src/main/java/logisticspipes/network/packets/NEISetCraftingRecipe.java index 8d97b18d4..f75b04629 100644 --- a/src/main/java/logisticspipes/network/packets/NEISetCraftingRecipe.java +++ b/src/main/java/logisticspipes/network/packets/NEISetCraftingRecipe.java @@ -8,10 +8,11 @@ import net.minecraft.tileentity.TileEntity; import logisticspipes.blocks.crafting.LogisticsCraftingTableTileEntity; +import logisticspipes.modules.ModuleCrafter; import logisticspipes.network.LPDataInputStream; import logisticspipes.network.LPDataOutputStream; -import logisticspipes.network.abstractpackets.CoordinatesPacket; import logisticspipes.network.abstractpackets.ModernPacket; +import logisticspipes.network.abstractpackets.ModuleCoordinatesPacket; import logisticspipes.pipes.PipeBlockRequestTable; import logisticspipes.pipes.basic.LogisticsTileGenericPipe; import lombok.Getter; @@ -19,7 +20,7 @@ import lombok.experimental.Accessors; @Accessors(chain = true) -public class NEISetCraftingRecipe extends CoordinatesPacket { +public class NEISetCraftingRecipe extends ModuleCoordinatesPacket { @Getter @Setter @@ -38,6 +39,11 @@ public void processPacket(EntityPlayer player) { && ((LogisticsTileGenericPipe) tile).pipe instanceof PipeBlockRequestTable) { ((PipeBlockRequestTable) ((LogisticsTileGenericPipe) tile).pipe) .handleNEIRecipePacket(getContent()); + } else { + ModuleCrafter module = getLogisticsModule(player, ModuleCrafter.class); + if (module != null) { + module.handleNEIRecipePacket(getContent(), player); + } } } diff --git a/src/main/java/logisticspipes/proxy/side/ClientProxy.java b/src/main/java/logisticspipes/proxy/side/ClientProxy.java index 829cad23a..79d714857 100644 --- a/src/main/java/logisticspipes/proxy/side/ClientProxy.java +++ b/src/main/java/logisticspipes/proxy/side/ClientProxy.java @@ -443,6 +443,8 @@ public void processMostLikelyRecipeComponentsResponse(MostLikelyRecipeComponents gui = (GuiLogisticsCraftingTable) firstGui; } else if (firstGui instanceof GuiRequestTable) { gui = (GuiRequestTable) firstGui; + } else if (firstGui instanceof GuiCraftingPipe) { + gui = (GuiCraftingPipe) firstGui; } else { return; } diff --git a/src/main/java/logisticspipes/utils/string/StringUtils.java b/src/main/java/logisticspipes/utils/string/StringUtils.java index 57c643878..f7e12f3d8 100644 --- a/src/main/java/logisticspipes/utils/string/StringUtils.java +++ b/src/main/java/logisticspipes/utils/string/StringUtils.java @@ -121,16 +121,21 @@ private static void addExtraInfo(ItemStack stack, List list) { public static String getFormatedStackSize(long stackSize, boolean forceDisplayNumber) { String s; + if (stackSize == 1 && !forceDisplayNumber) { s = ""; + } else if (stackSize < 0) { + s = "Inf"; } else if (stackSize < 1000) { s = stackSize + ""; - } else if (stackSize < 100000) { - s = stackSize / 1000 + "K"; } else if (stackSize < 1000000) { - s = "0M" + stackSize / 100000; - } else { + s = stackSize / 1000 + "K"; + } else if (stackSize < 1000000000) { s = stackSize / 1000000 + "M"; + } else if (stackSize <= Integer.MAX_VALUE) { + s = stackSize / 1000000000 + "." + (stackSize / 100000000) % 10 + "G"; + } else { + s = "Inf"; } return s; }