diff --git a/src/api/java/appeng/api/definitions/IParts.java b/src/api/java/appeng/api/definitions/IParts.java index a330b061b..5b46233f2 100644 --- a/src/api/java/appeng/api/definitions/IParts.java +++ b/src/api/java/appeng/api/definitions/IParts.java @@ -76,7 +76,7 @@ public interface IParts IItemDefinition p2PTunnelItems(); - //IItemDefinition p2PTunnelLiquids(); + IItemDefinition p2PTunnelFluids(); //IItemDefinition p2PTunnelEU(); diff --git a/src/main/java/appeng/core/api/definitions/ApiParts.java b/src/main/java/appeng/core/api/definitions/ApiParts.java index 628b767ce..995493870 100644 --- a/src/main/java/appeng/core/api/definitions/ApiParts.java +++ b/src/main/java/appeng/core/api/definitions/ApiParts.java @@ -61,8 +61,8 @@ public final class ApiParts implements IParts private final IItemDefinition p2PTunnelME; private final IItemDefinition p2PTunnelRedstone; private final IItemDefinition p2PTunnelItems; - //private final IItemDefinition p2PTunnelLiquids; - //private final IItemDefinition p2PTunnelEU; + private final IItemDefinition p2PTunnelFluids; + // private final IItemDefinition p2PTunnelEU; // private final IItemDefinition p2PTunnelRF; private final IItemDefinition p2PTunnelLight; // private final IItemDefinition p2PTunnelOpenComputers; @@ -112,8 +112,8 @@ public final class ApiParts implements IParts this.p2PTunnelME = new DamagedItemDefinition( "part.tunnel.me", itemPart.createPart( PartType.P2PTunnelME ) ); this.p2PTunnelRedstone = new DamagedItemDefinition( "part.tunnel.redstone", itemPart.createPart( PartType.P2PTunnelRedstone ) ); this.p2PTunnelItems = new DamagedItemDefinition( "part.tunnel.item", itemPart.createPart( PartType.P2PTunnelItems ) ); - //this.p2PTunnelLiquids = new DamagedItemDefinition( "part.tunnel.fluid", itemPart.createPart( PartType.P2PTunnelLiquids ) ); - //this.p2PTunnelEU = new DamagedItemDefinition( "part.tunnel.eu", itemPart.createPart( PartType.P2PTunnelEU ) ); + this.p2PTunnelFluids = new DamagedItemDefinition( "part.tunnel.fluid", itemPart.createPart( PartType.P2PTunnelFluids ) ); + // this.p2PTunnelEU = new DamagedItemDefinition( "part.tunnel.eu", itemPart.createPart( PartType.P2PTunnelEU ) ); // this.p2PTunnelRF = new DamagedItemDefinition( itemMultiPart.createPart( PartType.P2PTunnelRF ) ); this.p2PTunnelLight = new DamagedItemDefinition( "part.tunnel.light", itemPart.createPart( PartType.P2PTunnelLight ) ); // this.p2PTunnelOpenComputers = new DamagedItemDefinition( itemMultiPart.createPart( @@ -280,12 +280,12 @@ public final class ApiParts implements IParts return this.p2PTunnelItems; } -// @Override -// public IItemDefinition p2PTunnelLiquids() -// { -// return this.p2PTunnelLiquids; -// } -// + @Override + public IItemDefinition p2PTunnelFluids() + { + return this.p2PTunnelFluids; + } + // @Override // public IItemDefinition p2PTunnelEU() // { diff --git a/src/main/java/appeng/core/features/AEFeature.java b/src/main/java/appeng/core/features/AEFeature.java index b75f1161d..48d023fdf 100644 --- a/src/main/java/appeng/core/features/AEFeature.java +++ b/src/main/java/appeng/core/features/AEFeature.java @@ -118,7 +118,7 @@ public enum AEFeature P2P_TUNNEL_ITEMS( "P2PTunnelItems", Constants.CATEGORY_P2P_TUNNELS ), P2P_TUNNEL_REDSTONE( "P2PTunnelRedstone", Constants.CATEGORY_P2P_TUNNELS ), P2P_TUNNEL_EU( "P2PTunnelEU", Constants.CATEGORY_P2P_TUNNELS ), - P2P_TUNNEL_LIQUIDS( "P2PTunnelLiquids", Constants.CATEGORY_P2P_TUNNELS ), + P2P_TUNNEL_FLUIDS( "P2PTunnelFluids", Constants.CATEGORY_P2P_TUNNELS ), P2P_TUNNEL_LIGHT( "P2PTunnelLight", Constants.CATEGORY_P2P_TUNNELS ), P2P_TUNNEL_OPEN_COMPUTERS( "P2PTunnelOpenComputers", Constants.CATEGORY_P2P_TUNNELS ), P2P_TUNNEL_PRESSURE( "P2PTunnelPressure", Constants.CATEGORY_P2P_TUNNELS ), diff --git a/src/main/java/appeng/items/parts/PartType.java b/src/main/java/appeng/items/parts/PartType.java index 03fb76141..f78395d71 100644 --- a/src/main/java/appeng/items/parts/PartType.java +++ b/src/main/java/appeng/items/parts/PartType.java @@ -59,6 +59,8 @@ import appeng.parts.networking.PartCableGlass; import appeng.parts.networking.PartCableSmart; import appeng.parts.networking.PartDenseCable; import appeng.parts.networking.PartQuartzFiber; +import appeng.parts.p2p.PartP2PFluids; +//import appeng.parts.p2p.PartP2PIC2Power; import appeng.parts.p2p.PartP2PItems; import appeng.parts.p2p.PartP2PLight; import appeng.parts.p2p.PartP2PRedstone; @@ -224,15 +226,15 @@ public enum PartType } }, -// P2PTunnelLiquids( 463, "p2p_tunnel_liquids", EnumSet.of( AEFeature.P2P_TUNNEL, AEFeature.P2P_TUNNEL_LIQUIDS ), EnumSet -// .noneOf( IntegrationType.class ), PartP2PLiquids.class, GuiText.FluidTunnel ) -// { -// @Override -// String getUnlocalizedName() -// { -// return "P2PTunnel"; -// } -// }, + P2PTunnelFluids( 463, "p2p_tunnel_fluids", EnumSet.of( AEFeature.P2P_TUNNEL, AEFeature.P2P_TUNNEL_FLUIDS ), EnumSet + .noneOf( IntegrationType.class ), PartP2PFluids.class, GuiText.FluidTunnel ) + { + @Override + String getUnlocalizedName() + { + return "P2PTunnel"; + } + }, // // P2PTunnelEU( 465, "p2p_tunnel_ic2", EnumSet.of( AEFeature.P2P_TUNNEL, AEFeature.P2P_TUNNEL_EU ), EnumSet // .of( IntegrationType.IC2 ), PartP2PIC2Power.class, GuiText.EUTunnel ) diff --git a/src/main/java/appeng/parts/p2p/PartP2PFluids.java b/src/main/java/appeng/parts/p2p/PartP2PFluids.java new file mode 100644 index 000000000..ef1fbfb40 --- /dev/null +++ b/src/main/java/appeng/parts/p2p/PartP2PFluids.java @@ -0,0 +1,306 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.parts.p2p; + + +import java.util.Deque; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; + +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.capability.CapabilityFluidHandler; +import net.minecraftforge.fluids.capability.FluidTankProperties; +import net.minecraftforge.fluids.capability.IFluidHandler; +import net.minecraftforge.fluids.capability.IFluidTankProperties; + +import appeng.api.parts.IPartModel; +import appeng.items.parts.PartModels; +import appeng.me.GridAccessException; + + +public class PartP2PFluids extends PartP2PTunnel implements IFluidHandler +{ + + private static final P2PModels MODELS = new P2PModels( "part/p2p/p2p_tunnel_fluids" ); + + private static final ThreadLocal> DEPTH = new ThreadLocal<>(); + private static final FluidTankProperties[] ACTIVE_TANK = { new FluidTankProperties( null, 10000, true, false ) }; + private static final FluidTankProperties[] INACTIVE_TANK = { new FluidTankProperties( null, 0, false, false ) }; + + private IFluidHandler cachedTank; + private int tmpUsed; + + public PartP2PFluids( final ItemStack is ) + { + super( is ); + } + + @PartModels + public static List getModels() + { + return MODELS.getModels(); + } + + public float getPowerDrainPerTick() + { + return 2.0f; + } + + @Override + public void onTunnelNetworkChange() + { + this.cachedTank = null; + } + + @Override + public void onNeighborChanged() + { + this.cachedTank = null; + + if( this.isOutput() ) + { + final PartP2PFluids in = this.getInput(); + if( in != null ) + { + in.onTunnelNetworkChange(); + } + } + } + + @Override + public boolean hasCapability( Capability capabilityClass ) + { + if( capabilityClass == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY ) + { + return true; + } + + return super.hasCapability( capabilityClass ); + } + + @Override + public T getCapability( Capability capabilityClass ) + { + if( capabilityClass == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY ) + { + return (T) this; + } + + return super.getCapability( capabilityClass ); + } + + @Override + public IPartModel getStaticModels() + { + return MODELS.getModel( isPowered(), isActive() ); + } + + @Override + public IFluidTankProperties[] getTankProperties() + { + if( !this.isOutput() ) + { + final PartP2PFluids tun = this.getInput(); + if( tun != null ) + { + return ACTIVE_TANK; + } + } + + return INACTIVE_TANK; + } + + @Override + public int fill( FluidStack resource, boolean doFill ) + { + final Deque stack = this.getDepth(); + + for( final PartP2PFluids t : stack ) + { + if( t == this ) + { + return 0; + } + } + + stack.push( this ); + + final List list = this.getOutputs( resource.getFluid() ); + int requestTotal = 0; + + Iterator i = list.iterator(); + + while( i.hasNext() ) + { + final PartP2PFluids l = i.next(); + final IFluidHandler tank = l.getTarget(); + if( tank != null ) + { + l.tmpUsed = tank.fill( resource.copy(), false ); + } + else + { + l.tmpUsed = 0; + } + + if( l.tmpUsed <= 0 ) + { + i.remove(); + } + else + { + requestTotal += l.tmpUsed; + } + } + + if( requestTotal <= 0 ) + { + if( stack.pop() != this ) + { + throw new IllegalStateException( "Invalid Recursion detected." ); + } + + return 0; + } + + if( !doFill ) + { + if( stack.pop() != this ) + { + throw new IllegalStateException( "Invalid Recursion detected." ); + } + + return Math.min( resource.amount, requestTotal ); + } + + int available = resource.amount; + + i = list.iterator(); + int used = 0; + + while( i.hasNext() ) + { + final PartP2PFluids l = i.next(); + + final FluidStack insert = resource.copy(); + insert.amount = (int) Math.ceil( insert.amount * ( (double) l.tmpUsed / (double) requestTotal ) ); + if( insert.amount > available ) + { + insert.amount = available; + } + + final IFluidHandler tank = l.getTarget(); + if( tank != null ) + { + l.tmpUsed = tank.fill( insert.copy(), true ); + } + else + { + l.tmpUsed = 0; + } + + available -= insert.amount; + used += insert.amount; + } + + if( stack.pop() != this ) + { + throw new IllegalStateException( "Invalid Recursion detected." ); + } + + return used; + } + + @Override + public FluidStack drain( FluidStack resource, boolean doDrain ) + { + return null; + } + + @Override + public FluidStack drain( int maxDrain, boolean doDrain ) + { + return null; + } + + private Deque getDepth() + { + Deque s = DEPTH.get(); + + if( s == null ) + { + DEPTH.set( s = new LinkedList<>() ); + } + + return s; + } + + private List getOutputs( final Fluid input ) + { + final List outs = new LinkedList<>(); + + try + { + for( final PartP2PFluids l : this.getOutputs() ) + { + final IFluidHandler handler = l.getTarget(); + + if( handler != null ) + { + outs.add( l ); + } + } + } + catch( final GridAccessException e ) + { + // :P + } + + return outs; + } + + private IFluidHandler getTarget() + { + if( !this.getProxy().isActive() ) + { + return null; + } + + if( this.cachedTank != null ) + { + return this.cachedTank; + } + + final TileEntity te = this.getTile().getWorld().getTileEntity( this.getTile().getPos().offset( this.getSide().getFacing() ) ); + + if( te != null && te.hasCapability( CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, this.getSide().getFacing().getOpposite() ) ) + { + return this.cachedTank = te.getCapability( CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, + this.getSide().getFacing().getOpposite() ); + } + + return null; + } + +} \ No newline at end of file diff --git a/src/main/java/appeng/parts/p2p/PartP2PLiquids.java b/src/main/java/appeng/parts/p2p/PartP2PLiquids.java deleted file mode 100644 index ea625e4c6..000000000 --- a/src/main/java/appeng/parts/p2p/PartP2PLiquids.java +++ /dev/null @@ -1,312 +0,0 @@ -///* -// * This file is part of Applied Energistics 2. -// * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. -// * -// * Applied Energistics 2 is free software: you can redistribute it and/or modify -// * it under the terms of the GNU Lesser General Public License as published by -// * the Free Software Foundation, either version 3 of the License, or -// * (at your option) any later version. -// * -// * Applied Energistics 2 is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU Lesser General Public License for more details. -// * -// * You should have received a copy of the GNU Lesser General Public License -// * along with Applied Energistics 2. If not, see . -// */ -// -//package appeng.parts.p2p; -// -// -//import java.util.Iterator; -//import java.util.LinkedList; -//import java.util.List; -//import java.util.Stack; -// -//import net.minecraft.item.ItemStack; -//import net.minecraft.tileentity.TileEntity; -//import net.minecraft.util.EnumFacing; -//import net.minecraftforge.fluids.Fluid; -//import net.minecraftforge.fluids.FluidStack; -//import net.minecraftforge.fluids.FluidTankInfo; -//import net.minecraftforge.fluids.capability.IFluidHandler; -// -//import appeng.api.parts.IPartModel; -//import appeng.items.parts.PartModels; -//import appeng.me.GridAccessException; -// -// -//public class PartP2PLiquids extends PartP2PTunnel implements IFluidHandler -//{ -// -// private static final P2PModels MODELS = new P2PModels( "part/p2p/p2p_tunnel_liquids" ); -// -// @PartModels -// public static List getModels() -// { -// return MODELS.getModels(); -// } -// -// private static final ThreadLocal> DEPTH = new ThreadLocal>(); -// private static final FluidTankInfo[] ACTIVE_TANK = { new FluidTankInfo( null, 10000 ) }; -// private static final FluidTankInfo[] INACTIVE_TANK = { new FluidTankInfo( null, 0 ) }; -// private IFluidHandler cachedTank; -// private int tmpUsed; -// -// public PartP2PLiquids( final ItemStack is ) -// { -// super( is ); -// } -// -// public float getPowerDrainPerTick() -// { -// return 2.0f; -// } -// -// @Override -// public void onTunnelNetworkChange() -// { -// this.cachedTank = null; -// } -// -// @Override -// public void onNeighborChanged() -// { -// this.cachedTank = null; -// if( this.isOutput() ) -// { -// final PartP2PLiquids in = this.getInput(); -// if( in != null ) -// { -// in.onTunnelNetworkChange(); -// } -// } -// } -// -// @Override -// public int fill( final EnumFacing from, final FluidStack resource, final boolean doFill ) -// { -// final Stack stack = this.getDepth(); -// -// for( final PartP2PLiquids t : stack ) -// { -// if( t == this ) -// { -// return 0; -// } -// } -// -// stack.push( this ); -// -// final List list = this.getOutputs( resource.getFluid() ); -// int requestTotal = 0; -// -// Iterator i = list.iterator(); -// while( i.hasNext() ) -// { -// final PartP2PLiquids l = i.next(); -// final IFluidHandler tank = l.getTarget(); -// if( tank != null ) -// { -// l.tmpUsed = tank.fill( l.getSide().getFacing().getOpposite(), resource.copy(), false ); -// } -// else -// { -// l.tmpUsed = 0; -// } -// -// if( l.tmpUsed <= 0 ) -// { -// i.remove(); -// } -// else -// { -// requestTotal += l.tmpUsed; -// } -// } -// -// if( requestTotal <= 0 ) -// { -// if( stack.pop() != this ) -// { -// throw new IllegalStateException( "Invalid Recursion detected." ); -// } -// -// return 0; -// } -// -// if( !doFill ) -// { -// if( stack.pop() != this ) -// { -// throw new IllegalStateException( "Invalid Recursion detected." ); -// } -// -// return Math.min( resource.amount, requestTotal ); -// } -// -// int available = resource.amount; -// -// i = list.iterator(); -// int used = 0; -// while( i.hasNext() ) -// { -// final PartP2PLiquids l = i.next(); -// -// final FluidStack insert = resource.copy(); -// insert.amount = (int) Math.ceil( insert.amount * ( (double) l.tmpUsed / (double) requestTotal ) ); -// if( insert.amount > available ) -// { -// insert.amount = available; -// } -// -// final IFluidHandler tank = l.getTarget(); -// if( tank != null ) -// { -// l.tmpUsed = tank.fill( l.getSide().getFacing().getOpposite(), insert.copy(), true ); -// } -// else -// { -// l.tmpUsed = 0; -// } -// -// available -= insert.amount; -// used += insert.amount; -// } -// -// if( stack.pop() != this ) -// { -// throw new IllegalStateException( "Invalid Recursion detected." ); -// } -// -// return used; -// } -// -// private Stack getDepth() -// { -// Stack s = DEPTH.get(); -// -// if( s == null ) -// { -// DEPTH.set( s = new Stack() ); -// } -// -// return s; -// } -// -// private List getOutputs( final Fluid input ) -// { -// final List outs = new LinkedList(); -// -// try -// { -// for( final PartP2PLiquids l : this.getOutputs() ) -// { -// final IFluidHandler handler = l.getTarget(); -// if( handler != null ) -// { -// if( handler.canFill( l.getSide().getFacing().getOpposite(), input ) ) -// { -// outs.add( l ); -// } -// } -// } -// } -// catch( final GridAccessException e ) -// { -// // :P -// } -// -// return outs; -// } -// -// private IFluidHandler getTarget() -// { -// if( !this.getProxy().isActive() ) -// { -// return null; -// } -// -// if( this.cachedTank != null ) -// { -// return this.cachedTank; -// } -// -// final TileEntity te = this.getTile().getWorld().getTileEntity( this.getTile().getPos().offset( this.getSide().getFacing() ) ); -// if( te instanceof IFluidHandler ) -// { -// return this.cachedTank = (IFluidHandler) te; -// } -// -// return null; -// } -// -// @Override -// public FluidStack drain( final EnumFacing from, final FluidStack resource, final boolean doDrain ) -// { -// return null; -// } -// -// @Override -// public FluidStack drain( final EnumFacing from, final int maxDrain, final boolean doDrain ) -// { -// return null; -// } -// -// @Override -// public boolean canFill( final EnumFacing from, final Fluid fluid ) -// { -// return !this.isOutput() && from == this.getSide().getFacing() && !this.getOutputs( fluid ).isEmpty(); -// } -// -// @Override -// public boolean canDrain( final EnumFacing from, final Fluid fluid ) -// { -// return false; -// } -// -// @Override -// public FluidTankInfo[] getTankInfo( final EnumFacing from ) -// { -// if( from == this.getSide().getFacing() ) -// { -// return this.getTank(); -// } -// return new FluidTankInfo[0]; -// } -// -// private FluidTankInfo[] getTank() -// { -// if( this.isOutput() ) -// { -// final PartP2PLiquids tun = this.getInput(); -// if( tun != null ) -// { -// return ACTIVE_TANK; -// } -// } -// else -// { -// try -// { -// if( !this.getOutputs().isEmpty() ) -// { -// return ACTIVE_TANK; -// } -// } -// catch( final GridAccessException e ) -// { -// // :( -// } -// } -// return INACTIVE_TANK; -// } -// -// @Override -// public IPartModel getStaticModels() -// { -// return MODELS.getModel( isPowered(), isActive() ); -// } -// -//} \ No newline at end of file diff --git a/src/main/java/appeng/parts/p2p/PartP2PTunnel.java b/src/main/java/appeng/parts/p2p/PartP2PTunnel.java index 5dafcf9be..6b3ad5551 100644 --- a/src/main/java/appeng/parts/p2p/PartP2PTunnel.java +++ b/src/main/java/appeng/parts/p2p/PartP2PTunnel.java @@ -231,9 +231,9 @@ public abstract class PartP2PTunnel extends PartBasicSt * break; */ - //case FLUID: - // newType = parts.p2PTunnelLiquids().maybeStack( 1 ).orElse( ItemStack.EMPTY ); - // break; + case FLUID: + newType = parts.p2PTunnelFluids().maybeStack( 1 ).orElse( ItemStack.EMPTY ); + break; //case IC2_POWER: // newType = parts.p2PTunnelEU().maybeStack( 1 ).orElse( ItemStack.EMPTY ); diff --git a/src/main/java/appeng/tile/storage/TileChest.java b/src/main/java/appeng/tile/storage/TileChest.java index 2cbb0e16e..0adffb9d3 100644 --- a/src/main/java/appeng/tile/storage/TileChest.java +++ b/src/main/java/appeng/tile/storage/TileChest.java @@ -25,6 +25,7 @@ import java.util.List; import javax.annotation.Nullable; +import appeng.util.item.AEFluidStack; import io.netty.buffer.ByteBuf; import net.minecraft.entity.player.EntityPlayer; @@ -35,7 +36,11 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; import net.minecraft.util.ITickable; import net.minecraftforge.common.capabilities.Capability; - +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.capability.CapabilityFluidHandler; +import net.minecraftforge.fluids.capability.FluidTankProperties; +import net.minecraftforge.fluids.capability.IFluidHandler; +import net.minecraftforge.fluids.capability.IFluidTankProperties; import appeng.api.AEApi; import appeng.api.config.AccessRestriction; import appeng.api.config.Actionable; @@ -113,7 +118,8 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, ITerminal private ICellHandler cellHandler; private MEMonitorHandler itemCell; private MEMonitorHandler fluidCell; - private final Accessor accessor = new Accessor(); + private Accessor accessor; + private IFluidHandler fluidHandler; public TileChest() { @@ -198,6 +204,9 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, ITerminal this.itemCell = null; this.fluidCell = null; + this.accessor = null; + this.fluidHandler = null; + final ItemStack is = this.inv.getStackInSlot( 1 ); if( !is.isEmpty() ) { @@ -223,6 +232,17 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, ITerminal this.itemCell = this.wrap( itemCell ); this.fluidCell = this.wrap( fluidCell ); + + if( this.itemCell != null ) + { + + } + this.accessor = new Accessor(); + + if( this.fluidCell != null ) + { + this.fluidHandler = new FluidHandler(); + } } } } @@ -463,7 +483,8 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, ITerminal this.lastStateChange = this.world.getTotalWorldTime(); - return oldPaintedColor != this.paintedColor || ( this.state & 0xDB6DB6DB ) != ( oldState & 0xDB6DB6DB ) || !Platform.itemComparisons().isSameItem( oldType, this.storageType ); + return oldPaintedColor != this.paintedColor || ( this.state & 0xDB6DB6DB ) != ( oldState & 0xDB6DB6DB ) || !Platform.itemComparisons() + .isSameItem( oldType, this.storageType ); } @TileEvent( TileEventType.WORLD_NBT_READ ) @@ -571,7 +592,8 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, ITerminal try { final IMEInventory cell = this.getHandler( StorageChannel.ITEMS ); - final IAEItemStack returns = cell.injectItems( AEApi.instance().storage().createItemStack( this.inv.getStackInSlot( 0 ) ), Actionable.SIMULATE, this.mySrc ); + final IAEItemStack returns = cell.injectItems( AEApi.instance().storage().createItemStack( this.inv.getStackInSlot( 0 ) ), Actionable.SIMULATE, + this.mySrc ); return returns == null || returns.getStackSize() != insertingItem.getCount(); } catch( final ChestNoHandler ignored ) @@ -620,7 +642,8 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, ITerminal { final IMEInventory cell = this.getHandler( StorageChannel.ITEMS ); - final IAEItemStack returns = Platform.poweredInsert( this, cell, AEApi.instance().storage().createItemStack( this.inv.getStackInSlot( 0 ) ), this.mySrc ); + final IAEItemStack returns = Platform.poweredInsert( this, cell, AEApi.instance().storage().createItemStack( this.inv.getStackInSlot( 0 ) ), + this.mySrc ); if( returns == null ) { @@ -907,7 +930,11 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, ITerminal @Override public boolean hasCapability( Capability capability, EnumFacing facing ) { - if( capability == Capabilities.STORAGE_MONITORABLE_ACCESSOR && facing != getForward() ) + if( capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY && this.fluidHandler != null && facing != getForward() ) + { + return true; + } + if( capability == Capabilities.STORAGE_MONITORABLE_ACCESSOR && this.accessor != null && facing != getForward() ) { return true; } @@ -918,7 +945,11 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, ITerminal @Override public T getCapability( Capability capability, @Nullable EnumFacing facing ) { - if( capability == Capabilities.STORAGE_MONITORABLE_ACCESSOR && facing != getForward() ) + if( capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY && this.fluidHandler != null && facing != getForward() ) + { + return (T) this.fluidHandler; + } + if( capability == Capabilities.STORAGE_MONITORABLE_ACCESSOR && this.accessor != null && facing != getForward() ) { return (T) accessor; } @@ -939,11 +970,77 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, ITerminal } } - @Override - public boolean isEmpty() + + @Override + public boolean isEmpty() + { + // TODO Auto-generated method stub + return false; + } + + private class FluidHandler implements IFluidHandler { - // TODO Auto-generated method stub - return false; + + @Override + public int fill( final FluidStack resource, final boolean doFill ) + { + final double req = resource.amount / 500.0; + final double available = TileChest.this.extractAEPower( req, Actionable.SIMULATE, PowerMultiplier.CONFIG ); + if( available >= req - 0.01 ) + { + try + { + final IMEInventoryHandler h = TileChest.this.getHandler( StorageChannel.FLUIDS ); + + TileChest.this.extractAEPower( req, Actionable.MODULATE, PowerMultiplier.CONFIG ); + + final IAEStack results = h.injectItems( AEFluidStack.create( resource ), doFill ? Actionable.MODULATE : Actionable.SIMULATE, + TileChest.this.mySrc ); + + if( results == null ) + { + return resource.amount; + } + + return resource.amount - (int) results.getStackSize(); + } + catch( final ChestNoHandler ignored ) + { + } + } + return 0; + } + + @Override + public FluidStack drain( final FluidStack resource, final boolean doDrain ) + { + return null; + } + + @Override + public FluidStack drain( final int maxDrain, final boolean doDrain ) + { + return null; + } + + @Override + public IFluidTankProperties[] getTankProperties() + { + try + { + final IMEInventoryHandler h = TileChest.this.getHandler( StorageChannel.FLUIDS ); + + if( h.getChannel() == StorageChannel.FLUIDS ) + { + return new IFluidTankProperties[] { new FluidTankProperties( null, 1 ) }; // eh? + } + } + catch( final ChestNoHandler ignored ) + { + } + + return null; + } } } diff --git a/src/main/resources/assets/appliedenergistics2/models/item/part/p2p_tunnel_liquids.json b/src/main/resources/assets/appliedenergistics2/models/item/part/p2p_tunnel_fluids.json similarity index 100% rename from src/main/resources/assets/appliedenergistics2/models/item/part/p2p_tunnel_liquids.json rename to src/main/resources/assets/appliedenergistics2/models/item/part/p2p_tunnel_fluids.json diff --git a/src/main/resources/assets/appliedenergistics2/models/part/p2p/p2p_tunnel_liquids.json b/src/main/resources/assets/appliedenergistics2/models/part/p2p/p2p_tunnel_fluids.json similarity index 100% rename from src/main/resources/assets/appliedenergistics2/models/part/p2p/p2p_tunnel_liquids.json rename to src/main/resources/assets/appliedenergistics2/models/part/p2p/p2p_tunnel_fluids.json