mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-19 19:59:58 +00:00
Added filter for Ender Fluid Conduits.
This commit is contained in:
1 parent
2d61560f42
commit
2f247084fb
16 files changed
+513
-20
No files matched your search
@@ -36,6 +36,7 @@ import crazypants.enderio.conduit.geom.ConduitConnectorType;
|
||||
import crazypants.enderio.conduit.gui.ExternalConnectionContainer;
|
||||
import crazypants.enderio.conduit.gui.GuiExternalConnection;
|
||||
import crazypants.enderio.conduit.gui.GuiExternalConnectionSelector;
|
||||
import crazypants.enderio.conduit.gui.PacketFluidFilter;
|
||||
import crazypants.enderio.conduit.gui.PacketOpenConduitUI;
|
||||
import crazypants.enderio.conduit.gui.item.PacketExistingItemFilterSnapshot;
|
||||
import crazypants.enderio.conduit.liquid.PacketFluidLevel;
|
||||
@@ -63,6 +64,7 @@ public class BlockConduitBundle extends BlockEio implements IGuiHandler {
|
||||
PacketHandler.INSTANCE.registerMessage(PacketConnectionMode.class, PacketConnectionMode.class, PacketHandler.nextID(), Side.SERVER);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketItemConduitFilter.class, PacketItemConduitFilter.class, PacketHandler.nextID(), Side.SERVER);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketExistingItemFilterSnapshot.class, PacketExistingItemFilterSnapshot.class, PacketHandler.nextID(), Side.SERVER);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketFluidFilter.class, PacketFluidFilter.class, PacketHandler.nextID(), Side.SERVER);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketRedstoneConduitSignalColor.class, PacketRedstoneConduitSignalColor.class, PacketHandler.nextID(), Side.SERVER);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketOpenConduitUI.class, PacketOpenConduitUI.class, PacketHandler.nextID(), Side.SERVER);
|
||||
|
||||
|
||||
+5
-3
@@ -1,4 +1,4 @@
|
||||
package crazypants.enderio.conduit.gui.item;
|
||||
package crazypants.enderio.conduit.gui;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
@@ -10,8 +10,6 @@ import org.lwjgl.opengl.GL11;
|
||||
|
||||
import crazypants.enderio.conduit.ConnectionMode;
|
||||
import crazypants.enderio.conduit.IConduit;
|
||||
import crazypants.enderio.conduit.gui.GuiExternalConnection;
|
||||
import crazypants.enderio.conduit.gui.ISettingsPanel;
|
||||
import crazypants.enderio.conduit.packet.PacketConnectionMode;
|
||||
import crazypants.enderio.gui.IconButtonEIO;
|
||||
import crazypants.enderio.gui.IconEIO;
|
||||
@@ -89,6 +87,10 @@ public class BaseSettingsPanel implements ISettingsPanel {
|
||||
@Override
|
||||
public void deactivate() {
|
||||
}
|
||||
|
||||
public void mouseClicked(int x, int y, int par3) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public IconEIO getIcon() {
|
||||
@@ -138,6 +138,7 @@ public class GuiExternalConnection extends GuiContainerBase {
|
||||
return;
|
||||
}
|
||||
}
|
||||
tabs.get(activeTab).mouseClicked(x,y,par3);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -15,4 +15,6 @@ public interface ISettingsPanel {
|
||||
|
||||
void actionPerformed(GuiButton guiButton);
|
||||
|
||||
void mouseClicked(int x, int y, int par3);
|
||||
|
||||
}
|
||||
@@ -1,11 +1,23 @@
|
||||
package crazypants.enderio.conduit.gui;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Rectangle;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.conduit.ConnectionMode;
|
||||
import crazypants.enderio.conduit.IConduit;
|
||||
import crazypants.enderio.conduit.gui.item.BaseSettingsPanel;
|
||||
import crazypants.enderio.conduit.liquid.EnderLiquidConduit;
|
||||
import crazypants.enderio.conduit.liquid.FluidFilter;
|
||||
import crazypants.enderio.conduit.liquid.ILiquidConduit;
|
||||
import crazypants.enderio.conduit.packet.PacketExtractMode;
|
||||
import crazypants.enderio.gui.ColorButton;
|
||||
@@ -14,7 +26,9 @@ import crazypants.enderio.gui.RedstoneModeButton;
|
||||
import crazypants.enderio.machine.IRedstoneModeControlable;
|
||||
import crazypants.enderio.machine.RedstoneControlMode;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
import crazypants.gui.GuiToolTip;
|
||||
import crazypants.render.ColorUtil;
|
||||
import crazypants.render.RenderUtil;
|
||||
import crazypants.util.DyeColor;
|
||||
import crazypants.util.Lang;
|
||||
|
||||
@@ -29,13 +43,32 @@ public class LiquidSettings extends BaseSettingsPanel {
|
||||
private ColorButton colorB;
|
||||
|
||||
private String autoExtractStr = Lang.localize("gui.conduit.fluid.autoExtract");
|
||||
private String filterStr = Lang.localize("gui.conduit.fluid.filter");
|
||||
|
||||
private ILiquidConduit conduit;
|
||||
|
||||
private EnderLiquidConduit eConduit;
|
||||
private boolean isEnder;
|
||||
private int filterX = 59;
|
||||
private int filterY = 59;
|
||||
private Rectangle filterBounds = new Rectangle(filterX, filterY, 90, 18);
|
||||
private GuiToolTip[] filterToolTips;
|
||||
|
||||
protected LiquidSettings(final GuiExternalConnection gui, IConduit con) {
|
||||
super(IconEIO.WRENCH_OVERLAY_FLUID, Lang.localize("itemLiquidConduit.name"), gui, con);
|
||||
|
||||
conduit = (ILiquidConduit) con;
|
||||
if(con instanceof EnderLiquidConduit) {
|
||||
eConduit = (EnderLiquidConduit) con;
|
||||
isEnder = true;
|
||||
if(isFilterVisible()) {
|
||||
gui.getContainer().setInventorySlotsVisible(true);
|
||||
}
|
||||
addFilterTooltips();
|
||||
} else {
|
||||
isEnder = false;
|
||||
gui.getContainer().setInventorySlotsVisible(false);
|
||||
}
|
||||
|
||||
int x = gap + gui.getFontRenderer().getStringWidth(autoExtractStr) + gap * 2;
|
||||
int y = customTop;
|
||||
@@ -64,6 +97,15 @@ public class LiquidSettings extends BaseSettingsPanel {
|
||||
colorB.setColorIndex(conduit.getExtractionSignalColor(gui.getDir()).ordinal());
|
||||
}
|
||||
|
||||
private void addFilterTooltips() {
|
||||
filterToolTips = new GuiToolTip[5];
|
||||
for(int i=0;i<5;i++) {
|
||||
Rectangle bound = new Rectangle(filterX + (i*18), filterY, 18, 18);
|
||||
filterToolTips[i] = new FilterToolTip(bound, i);
|
||||
gui.addToolTip(filterToolTips[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(GuiButton guiButton) {
|
||||
super.actionPerformed(guiButton);
|
||||
@@ -84,6 +126,35 @@ public class LiquidSettings extends BaseSettingsPanel {
|
||||
gui.removeButton(colorB);
|
||||
}
|
||||
|
||||
if(isEnder && isFilterVisible()) {
|
||||
gui.getContainer().setInventorySlotsVisible(true);
|
||||
} else {
|
||||
gui.getContainer().setInventorySlotsVisible(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int x, int y, int par3) {
|
||||
|
||||
if(!isFilterVisible()) {
|
||||
return;
|
||||
}
|
||||
ItemStack st = Minecraft.getMinecraft().thePlayer.inventory.getItemStack();
|
||||
FluidFilter filter = eConduit.getFilter(gui.getDir(), isInput());
|
||||
if(filter == null && st == null) {
|
||||
return;
|
||||
}
|
||||
if(filter == null) {
|
||||
filter = new FluidFilter();
|
||||
}
|
||||
if(filterBounds.contains(x, y)) {
|
||||
int slot = (x - filterX) / 18;
|
||||
filter.setFluid(slot, st);
|
||||
}
|
||||
eConduit.setFilter(gui.getDir(), filter, isInput());
|
||||
EnderIO.packetPipeline.INSTANCE.sendToServer(new PacketFluidFilter(eConduit, gui.getDir(), filter, isInput()));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -91,15 +162,98 @@ public class LiquidSettings extends BaseSettingsPanel {
|
||||
super.deactivate();
|
||||
rsB.setToolTip((String[]) null);
|
||||
colorB.setToolTip((String[]) null);
|
||||
if(isEnder) {
|
||||
gui.getContainer().setInventorySlotsVisible(false);
|
||||
for(GuiToolTip tt : filterToolTips) {
|
||||
if(tt != null) {
|
||||
gui.removeToolTip(tt);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderCustomOptions(int top, float par1, int par2, int par3) {
|
||||
if(conduit.getConectionMode(gui.getDir()) == ConnectionMode.INPUT) {
|
||||
boolean isInput = isInput();
|
||||
if(isInput) {
|
||||
int x = gui.getGuiLeft() + gap + gui.getFontRenderer().getStringWidth(autoExtractStr) + gap + 2;
|
||||
int y = customTop;
|
||||
gui.getFontRenderer().drawString(autoExtractStr, left, top, ColorUtil.getRGB(Color.DARK_GRAY));
|
||||
}
|
||||
if(isEnder && isFilterVisible()) {
|
||||
|
||||
GL11.glColor3f(1, 1, 1);
|
||||
RenderUtil.bindTexture("enderio:textures/gui/itemFilter.png");
|
||||
gui.drawTexturedModalRect(gui.getGuiLeft(), gui.getGuiTop() + 55, 0, 55, gui.getXSize(), 145);
|
||||
|
||||
FontRenderer fr = gui.getFontRenderer();
|
||||
int sw = fr.getStringWidth(filterStr);
|
||||
int x = (gui.width / 2) - sw / 2;
|
||||
int y = top + 20;
|
||||
fr.drawString(filterStr, x, y, ColorUtil.getRGB(Color.DARK_GRAY));
|
||||
|
||||
x = gui.getGuiLeft() + filterX;
|
||||
y = customTop + filterY;
|
||||
GL11.glColor3f(1, 1, 1);
|
||||
RenderUtil.bindTexture("enderio:textures/gui/externalConduitConnection.png");
|
||||
gui.drawTexturedModalRect(x, y, 24, 238, 90, 18);
|
||||
|
||||
FluidFilter filter = eConduit.getFilter(gui.getDir(), isInput);
|
||||
if(filter != null && !filter.isEmpty()) {
|
||||
for (int i = 0; i < filter.size(); i++) {
|
||||
Fluid f = filter.getFluidAt(i);
|
||||
if(f != null) {
|
||||
renderFluid(f, x + (i * 18), y);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void renderFluid(Fluid f, int x, int y) {
|
||||
IIcon icon = f.getIcon();
|
||||
if(icon != null) {
|
||||
RenderUtil.bindBlockTexture();
|
||||
gui.drawTexturedModelRectFromIcon(x + 1, y + 1, icon, 16, 16);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean isInput() {
|
||||
return conduit.getConectionMode(gui.getDir()) == ConnectionMode.INPUT;
|
||||
}
|
||||
|
||||
private boolean isFilterVisible() {
|
||||
ConnectionMode mode = conduit.getConectionMode(gui.getDir());
|
||||
return mode == ConnectionMode.INPUT || mode == ConnectionMode.OUTPUT;
|
||||
}
|
||||
|
||||
private class FilterToolTip extends GuiToolTip {
|
||||
|
||||
int index;
|
||||
|
||||
public FilterToolTip(Rectangle bounds, int index) {
|
||||
super(bounds, (String[])null);
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getToolTipText() {
|
||||
if(!isFilterVisible()) {
|
||||
return null;
|
||||
}
|
||||
FluidFilter filter = eConduit.getFilter(gui.getDir(), isInput());
|
||||
if(filter == null) {
|
||||
return null;
|
||||
}
|
||||
if(filter.getFluidAt(index) == null) {
|
||||
return null;
|
||||
}
|
||||
return Collections.singletonList(filter.getFluidAt(index).getLocalizedName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package crazypants.enderio.conduit.gui;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import cpw.mods.fml.common.network.ByteBufUtils;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import crazypants.enderio.conduit.item.IItemConduit;
|
||||
import crazypants.enderio.conduit.liquid.EnderLiquidConduit;
|
||||
import crazypants.enderio.conduit.liquid.FluidFilter;
|
||||
import crazypants.enderio.conduit.liquid.ILiquidConduit;
|
||||
import crazypants.enderio.conduit.packet.AbstractConduitPacket;
|
||||
import crazypants.enderio.conduit.packet.ConTypeEnum;
|
||||
import crazypants.enderio.conduit.packet.PacketExtractMode;
|
||||
|
||||
public class PacketFluidFilter extends AbstractConduitPacket<ILiquidConduit> implements IMessageHandler<PacketFluidFilter, IMessage>{
|
||||
|
||||
private ForgeDirection dir;
|
||||
private boolean isInput;
|
||||
private FluidFilter filter;
|
||||
|
||||
public PacketFluidFilter() {
|
||||
}
|
||||
|
||||
public PacketFluidFilter(EnderLiquidConduit eConduit, ForgeDirection dir, FluidFilter filter, boolean isInput) {
|
||||
super(eConduit.getBundle().getEntity(), ConTypeEnum.FLUID);
|
||||
this.dir = dir;
|
||||
this.filter = filter;
|
||||
this.isInput = isInput;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
super.toBytes(buf);
|
||||
buf.writeShort(dir.ordinal());
|
||||
buf.writeBoolean(isInput);
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
filter.writeToNBT(tag);
|
||||
ByteBufUtils.writeTag(buf, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
super.fromBytes(buf);
|
||||
dir = ForgeDirection.values()[buf.readShort()];
|
||||
isInput = buf.readBoolean();
|
||||
NBTTagCompound tag = ByteBufUtils.readTag(buf);
|
||||
filter = new FluidFilter();
|
||||
filter.readFromNBT(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketFluidFilter message, MessageContext ctx) {
|
||||
ILiquidConduit conduit = message.getTileCasted(ctx);
|
||||
if(! (conduit instanceof EnderLiquidConduit)) {
|
||||
return null;
|
||||
}
|
||||
EnderLiquidConduit eCon = (EnderLiquidConduit)conduit;
|
||||
eCon.setFilter(message.dir, message.filter, message.isInput);
|
||||
message.getWorld(ctx).markBlockForUpdate(message.x, message.y, message.z);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package crazypants.enderio.conduit.gui;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import crazypants.enderio.conduit.IConduit;
|
||||
import crazypants.enderio.conduit.gui.item.BaseSettingsPanel;
|
||||
import crazypants.enderio.conduit.packet.PacketExtractMode;
|
||||
import crazypants.enderio.conduit.power.IPowerConduit;
|
||||
import crazypants.enderio.gui.ColorButton;
|
||||
|
||||
@@ -4,7 +4,6 @@ import java.awt.Color;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import crazypants.enderio.conduit.IConduit;
|
||||
import crazypants.enderio.conduit.gui.item.BaseSettingsPanel;
|
||||
import crazypants.enderio.conduit.packet.PacketRedstoneConduitSignalColor;
|
||||
import crazypants.enderio.conduit.redstone.IInsulatedRedstoneConduit;
|
||||
import crazypants.enderio.gui.ColorButton;
|
||||
|
||||
@@ -10,6 +10,7 @@ import org.lwjgl.opengl.GL11;
|
||||
|
||||
import crazypants.enderio.conduit.ConnectionMode;
|
||||
import crazypants.enderio.conduit.IConduit;
|
||||
import crazypants.enderio.conduit.gui.BaseSettingsPanel;
|
||||
import crazypants.enderio.conduit.gui.FilterChangeListener;
|
||||
import crazypants.enderio.conduit.gui.GuiExternalConnection;
|
||||
import crazypants.enderio.conduit.item.IItemConduit;
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
package crazypants.enderio.conduit.liquid;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
@@ -23,6 +26,8 @@ import crazypants.enderio.conduit.ConnectionMode;
|
||||
import crazypants.enderio.conduit.IConduit;
|
||||
import crazypants.enderio.conduit.RaytraceResult;
|
||||
import crazypants.enderio.conduit.geom.CollidableComponent;
|
||||
import crazypants.enderio.conduit.item.FilterRegister;
|
||||
import crazypants.enderio.conduit.item.filter.IItemFilter;
|
||||
import crazypants.render.IconUtil;
|
||||
import crazypants.util.BlockCoord;
|
||||
|
||||
@@ -58,6 +63,9 @@ public class EnderLiquidConduit extends AbstractLiquidConduit {
|
||||
private EnderLiquidConduitNetwork network;
|
||||
private int ticksSinceFailedExtract;
|
||||
|
||||
private final EnumMap<ForgeDirection, FluidFilter> outputFilters = new EnumMap<ForgeDirection, FluidFilter>(ForgeDirection.class);
|
||||
private final EnumMap<ForgeDirection, FluidFilter> inputFilters = new EnumMap<ForgeDirection, FluidFilter>(ForgeDirection.class);
|
||||
|
||||
@Override
|
||||
public ItemStack createItem() {
|
||||
return new ItemStack(EnderIO.itemLiquidConduit, 1, 2);
|
||||
@@ -113,6 +121,21 @@ public class EnderLiquidConduit extends AbstractLiquidConduit {
|
||||
return network;
|
||||
}
|
||||
|
||||
public FluidFilter getFilter(ForgeDirection dir, boolean isInput) {
|
||||
if(isInput) {
|
||||
return inputFilters.get(dir);
|
||||
}
|
||||
return outputFilters.get(dir);
|
||||
}
|
||||
|
||||
public void setFilter(ForgeDirection dir, FluidFilter filter, boolean isInput) {
|
||||
if(isInput) {
|
||||
inputFilters.put(dir, filter);
|
||||
} else {
|
||||
outputFilters.put(dir, filter);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setNetwork(AbstractConduitNetwork<?, ?> network) {
|
||||
if(network == null) {
|
||||
@@ -123,10 +146,10 @@ public class EnderLiquidConduit extends AbstractLiquidConduit {
|
||||
return false;
|
||||
}
|
||||
this.network = (EnderLiquidConduitNetwork) network;
|
||||
for(ForgeDirection dir : externalConnections) {
|
||||
for (ForgeDirection dir : externalConnections) {
|
||||
this.network.connectionChanged(this, dir);
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -169,7 +192,7 @@ public class EnderLiquidConduit extends AbstractLiquidConduit {
|
||||
}
|
||||
|
||||
private void refreshConnections(ForgeDirection dir) {
|
||||
if(network == null) {
|
||||
if(network == null) {
|
||||
return;
|
||||
}
|
||||
network.connectionChanged(this, dir);
|
||||
@@ -263,4 +286,57 @@ public class EnderLiquidConduit extends AbstractLiquidConduit {
|
||||
return network.getTankInfo(this, from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbtRoot) {
|
||||
super.writeToNBT(nbtRoot);
|
||||
for (Entry<ForgeDirection, FluidFilter> entry : inputFilters.entrySet()) {
|
||||
if(entry.getValue() != null) {
|
||||
FluidFilter f = entry.getValue();
|
||||
if(f != null && !f.isEmpty()) {
|
||||
NBTTagCompound itemRoot = new NBTTagCompound();
|
||||
f.writeToNBT(itemRoot);
|
||||
nbtRoot.setTag("inFilts." + entry.getKey().name(), itemRoot);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Entry<ForgeDirection, FluidFilter> entry : outputFilters.entrySet()) {
|
||||
if(entry.getValue() != null) {
|
||||
FluidFilter f = entry.getValue();
|
||||
if(f != null && !f.isEmpty()) {
|
||||
NBTTagCompound itemRoot = new NBTTagCompound();
|
||||
f.writeToNBT(itemRoot);
|
||||
nbtRoot.setTag("outFilts." + entry.getKey().name(), itemRoot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbtRoot, short nbtVersion) {
|
||||
super.readFromNBT(nbtRoot, nbtVersion);
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
String key = "inFilts." + dir.name();
|
||||
if(nbtRoot.hasKey(key)) {
|
||||
NBTTagCompound filterTag = (NBTTagCompound) nbtRoot.getTag(key);
|
||||
FluidFilter f = new FluidFilter();
|
||||
f.readFromNBT(filterTag);
|
||||
if(!f.isEmpty()) {
|
||||
inputFilters.put(dir, f);
|
||||
}
|
||||
}
|
||||
|
||||
key = "outFilts." + dir.name();
|
||||
if(nbtRoot.hasKey(key)) {
|
||||
NBTTagCompound filterTag = (NBTTagCompound) nbtRoot.getTag(key);
|
||||
FluidFilter f = new FluidFilter();
|
||||
f.readFromNBT(filterTag);
|
||||
if(!f.isEmpty()) {
|
||||
outputFilters.put(dir, f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,7 +24,8 @@ public class EnderLiquidConduitNetwork extends AbstractConduitNetwork<ILiquidCon
|
||||
public static final int MAX_IO_PER_TICK = Config.enderFluidConduitMaxIoRate;
|
||||
|
||||
List<NetworkTank> tanks = new ArrayList<NetworkTank>();
|
||||
|
||||
Map<NetworkTankKey, NetworkTank> tankMap = new HashMap<NetworkTankKey, NetworkTank>();
|
||||
|
||||
Map<NetworkTank, RoundRobinIterator<NetworkTank>> iterators;
|
||||
|
||||
public EnderLiquidConduitNetwork() {
|
||||
@@ -36,19 +37,22 @@ public class EnderLiquidConduitNetwork extends AbstractConduitNetwork<ILiquidCon
|
||||
return ILiquidConduit.class;
|
||||
}
|
||||
|
||||
public void connectionChanged(EnderLiquidConduit con, ForgeDirection conDir) {
|
||||
public void connectionChanged(EnderLiquidConduit con, ForgeDirection conDir) {
|
||||
NetworkTankKey key = new NetworkTankKey(con, conDir);
|
||||
NetworkTank tank = new NetworkTank(con, conDir);
|
||||
tanks.remove(tank); // remove old tank, NB: =/hash is only calced on location and dir
|
||||
tankMap.remove(key);
|
||||
tanks.add(tank);
|
||||
tankMap.put(key, tank);
|
||||
}
|
||||
|
||||
public boolean extractFrom(EnderLiquidConduit con, ForgeDirection conDir) {
|
||||
NetworkTank tank = new NetworkTank(con, conDir);
|
||||
if(!tank.isValid()) {
|
||||
NetworkTank tank = getTank(con, conDir);
|
||||
if(tank == null || !tank.isValid()) {
|
||||
return false;
|
||||
}
|
||||
FluidStack drained = tank.externalTank.drain(conDir.getOpposite(), MAX_EXTRACT_PER_TICK, false);
|
||||
if(drained == null || drained.amount <= 0) {
|
||||
if(drained == null || drained.amount <= 0 || !matchedFilter(drained, con, conDir, true)) {
|
||||
return false;
|
||||
}
|
||||
int amountAccepted = fillFrom(tank, drained, false);
|
||||
@@ -66,12 +70,16 @@ public class EnderLiquidConduitNetwork extends AbstractConduitNetwork<ILiquidCon
|
||||
return true;
|
||||
}
|
||||
|
||||
private NetworkTank getTank(EnderLiquidConduit con, ForgeDirection conDir) {
|
||||
return tankMap.get(new NetworkTankKey(con, conDir));
|
||||
}
|
||||
|
||||
public int fillFrom(EnderLiquidConduit con, ForgeDirection conDir, FluidStack resource, boolean doFill) {
|
||||
return fillFrom(new NetworkTank(con, conDir), resource, doFill);
|
||||
return fillFrom(getTank(con, conDir), resource, doFill);
|
||||
}
|
||||
|
||||
public int fillFrom(NetworkTank tank, FluidStack resource, boolean doFill) {
|
||||
if(resource == null) {
|
||||
if(resource == null || tank == null || !matchedFilter(resource, tank.con, tank.conDir, true)) {
|
||||
return 0;
|
||||
}
|
||||
resource = resource.copy();
|
||||
@@ -79,7 +87,7 @@ public class EnderLiquidConduitNetwork extends AbstractConduitNetwork<ILiquidCon
|
||||
int filled = 0;
|
||||
int remaining = resource.amount;
|
||||
for (NetworkTank target : getIteratorForTank(tank)) {
|
||||
if(!target.equals(tank) && target.acceptsOuput && target.isValid()) {
|
||||
if(!target.equals(tank) && target.acceptsOuput && target.isValid() && matchedFilter(resource, target.con, target.conDir, false)) {
|
||||
int vol = target.externalTank.fill(target.tankDir, resource.copy(), doFill);
|
||||
remaining -= vol;
|
||||
filled += vol;
|
||||
@@ -92,6 +100,17 @@ public class EnderLiquidConduitNetwork extends AbstractConduitNetwork<ILiquidCon
|
||||
return filled;
|
||||
}
|
||||
|
||||
private boolean matchedFilter(FluidStack drained, EnderLiquidConduit con, ForgeDirection conDir, boolean isInput) {
|
||||
if(drained == null || con == null || conDir == null) {
|
||||
return false;
|
||||
}
|
||||
FluidFilter filter = con.getFilter(conDir, isInput);
|
||||
if(filter == null || filter.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
return filter.matchesFilter(drained);
|
||||
}
|
||||
|
||||
private Iterable<NetworkTank> getIteratorForTank(NetworkTank tank) {
|
||||
if(iterators == null) {
|
||||
iterators = new HashMap<NetworkTank, RoundRobinIterator<NetworkTank>>();
|
||||
@@ -106,11 +125,11 @@ public class EnderLiquidConduitNetwork extends AbstractConduitNetwork<ILiquidCon
|
||||
|
||||
public FluidTankInfo[] getTankInfo(EnderLiquidConduit con, ForgeDirection conDir) {
|
||||
List<FluidTankInfo> res = new ArrayList<FluidTankInfo>(tanks.size());
|
||||
NetworkTank tank = new NetworkTank(con, conDir);
|
||||
NetworkTank tank = getTank(con, conDir);
|
||||
for (NetworkTank target : tanks) {
|
||||
if(!target.equals(tank) && target.isValid()) {
|
||||
FluidTankInfo[] tTanks = target.externalTank.getTankInfo(target.tankDir);
|
||||
for(FluidTankInfo info: tTanks) {
|
||||
for (FluidTankInfo info : tTanks) {
|
||||
res.add(info);
|
||||
}
|
||||
}
|
||||
@@ -118,6 +137,50 @@ public class EnderLiquidConduitNetwork extends AbstractConduitNetwork<ILiquidCon
|
||||
return res.toArray(new FluidTankInfo[res.size()]);
|
||||
}
|
||||
|
||||
static class NetworkTankKey {
|
||||
|
||||
ForgeDirection conDir;
|
||||
BlockCoord conduitLoc;
|
||||
|
||||
public NetworkTankKey(EnderLiquidConduit con, ForgeDirection conDir) {
|
||||
this(con.getLocation(), conDir);
|
||||
}
|
||||
|
||||
public NetworkTankKey(BlockCoord conduitLoc, ForgeDirection conDir) {
|
||||
this.conDir = conDir;
|
||||
this.conduitLoc = conduitLoc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((conDir == null) ? 0 : conDir.hashCode());
|
||||
result = prime * result + ((conduitLoc == null) ? 0 : conduitLoc.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(this == obj)
|
||||
return true;
|
||||
if(obj == null)
|
||||
return false;
|
||||
if(getClass() != obj.getClass())
|
||||
return false;
|
||||
NetworkTankKey other = (NetworkTankKey) obj;
|
||||
if(conDir != other.conDir)
|
||||
return false;
|
||||
if(conduitLoc == null) {
|
||||
if(other.conduitLoc != null)
|
||||
return false;
|
||||
} else if(!conduitLoc.equals(other.conduitLoc))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class NetworkTank {
|
||||
|
||||
EnderLiquidConduit con;
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
package crazypants.enderio.conduit.liquid;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import crazypants.util.FluidUtil;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.nbt.NBTTagString;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
public class FluidFilter {
|
||||
|
||||
private final Fluid[] fluids = new Fluid[5];
|
||||
|
||||
public boolean isEmpty() {
|
||||
for (Fluid f : fluids) {
|
||||
if(f != null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return fluids.length;
|
||||
}
|
||||
|
||||
public Fluid getFluidAt(int index) {
|
||||
return fluids[index];
|
||||
}
|
||||
|
||||
public boolean setFluid(int index, Fluid fluid) {
|
||||
fluids[index] = fluid;
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean setFluid(int index, FluidStack fluid) {
|
||||
return setFluid(index, fluid.getFluid());
|
||||
}
|
||||
|
||||
public boolean setFluid(int index, ItemStack stack) {
|
||||
if(stack == null) {
|
||||
return setFluid(index, (Fluid) null);
|
||||
}
|
||||
FluidStack f = FluidUtil.getFluidFromItem(stack);
|
||||
if(f == null || f.getFluid() == null) {
|
||||
return false;
|
||||
}
|
||||
return setFluid(index, f);
|
||||
}
|
||||
|
||||
public boolean removeFluid(int index) {
|
||||
if(index < 0 || index >= fluids.length) {
|
||||
return false;
|
||||
}
|
||||
fluids[index] = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void setFluid(int index, String fluidName) {
|
||||
Fluid f = FluidRegistry.getFluid(fluidName);
|
||||
fluids[index] = f;
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound root) {
|
||||
if(isEmpty()) {
|
||||
root.removeTag("fluidFilter");
|
||||
return;
|
||||
}
|
||||
|
||||
NBTTagList fluidList = new NBTTagList();
|
||||
int index = 0;
|
||||
for (Fluid f : fluids) {
|
||||
if(f != null) {
|
||||
NBTTagCompound fRoot = new NBTTagCompound();
|
||||
fRoot.setInteger("index", index);
|
||||
fRoot.setString("fluidName", f.getName());
|
||||
fluidList.appendTag(fRoot);
|
||||
}
|
||||
index++;
|
||||
}
|
||||
root.setTag("fluidFilter", fluidList);
|
||||
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound root) {
|
||||
if(!root.hasKey("fluidFilter")) {
|
||||
clear();
|
||||
return;
|
||||
}
|
||||
NBTTagList fluidList = (NBTTagList) root.getTag("fluidFilter");
|
||||
for (int i = 0; i < fluidList.tagCount(); i++) {
|
||||
NBTTagCompound fRoot = fluidList.getCompoundTagAt(i);
|
||||
setFluid(fRoot.getInteger("index"), fRoot.getString("fluidName"));
|
||||
}
|
||||
}
|
||||
|
||||
private void clear() {
|
||||
for(int i=0;i<fluids.length;i++) {
|
||||
fluids[i] = null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean matchesFilter(FluidStack drained) {
|
||||
if(drained == null || drained.getFluid() == null) {
|
||||
return false;
|
||||
}
|
||||
if(isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
for (Fluid f : fluids) {
|
||||
if(f != null && f.getID() == drained.getFluid().getID()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -43,6 +43,9 @@ public class ToolTipManager {
|
||||
|
||||
protected void drawTooltip(GuiToolTip toolTip, int mouseX, int mouseY, ToolTipRenderer renderer) {
|
||||
List<String> list = toolTip.getToolTipText();
|
||||
if(list == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> formatted = new ArrayList<String>(list.size());
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
|
||||
Reference in new issue
Block a user