added a copy of Calclavia's Path Finder

For the moment its just added and not used. I will have to rewrite it in
a way that it doesn't care for TileEntities. This way i can use it for
the pump to make sure that water sources are connected to the pump.
This commit is contained in:
Rseifert 2013-03-01 11:50:10 -05:00
parent 601a6e591e
commit 76d9927483
9 changed files with 266 additions and 11 deletions

View file

@ -1 +1 @@
25
27

View file

@ -23,3 +23,5 @@ x Fluid-Mechanics_v0.2.7.21.jar hydraulic_v0.2.7.21_api.zip
@ Fluid-Mechanics_v0.2.8.23.jar hydraulic_v0.2.8.23_api.zip
* Fluid-Mechanics_v0.2.8.24.jar hydraulic_v0.2.8.24_api.zip
* Fluid-Mechanics_v0.2.8.25.jar hydraulic_v0.2.8.25_api.zip
* Fluid-Mechanics_v0.2.8.26.jar hydraulic_v0.2.8.26_api.zip
* Fluid-Mechanics_v0.2.8.27.jar hydraulic_v0.2.8.27_api.zip

View file

@ -0,0 +1,27 @@
package hydraulic.core.implement;
import net.minecraft.tileentity.TileEntity;
/**
* Applied to TileEntities.
*
* @author Calclavia
*
*/
public interface ILiquidConnectionProvider extends ILiquidConnector
{
/**
* Gets a list of all the connected TileEntities that this conductor is connected to. The
* array's length should be always the 6 adjacent wires.
*
* @return
*/
public TileEntity[] getAdjacentConnections();
/**
* Instantly refreshes all connected blocks around the conductor, recalculating the connected
* blocks.
*/
public void updateAdjacentConnections();
}

View file

@ -0,0 +1,18 @@
package hydraulic.core.implement;
import net.minecraftforge.common.ForgeDirection;
/**
* Applied to TileEntities that can connect to an electrical network.
*
* @author Calclavia
*
*/
public interface ILiquidConnector
{
/**
* @return If the connection is possible.
*/
public boolean canConnect(ForgeDirection direction);
}

View file

@ -4,6 +4,7 @@ import hydraulic.core.helpers.connectionHelper;
import hydraulic.core.implement.ColorCode;
import hydraulic.core.implement.IFluidPipe;
import hydraulic.core.implement.IPsiCreator;
import hydraulic.core.implement.IPsiMachine;
import hydraulic.core.implement.IPsiReciever;
import java.util.ArrayList;
@ -22,11 +23,7 @@ public class HydraulicNetwork
public final List<IFluidPipe> conductors = new ArrayList<IFluidPipe>();
/* MACHINES THAT USE THE FORGE LIQUID API TO RECEIVE LIQUID ** */
public final List<ITankContainer> fluidReceivers = new ArrayList<ITankContainer>();
/* MACHINES THAT DEAL WITH PRESSURE ** */
public final List<IPsiCreator> pressureProducers = new ArrayList<IPsiCreator>();
public final List<IPsiReciever> pressureReceivers = new ArrayList<IPsiReciever>();
public final List<TileEntity> receivers = new ArrayList<TileEntity>();
public ColorCode color = ColorCode.NONE;
@ -63,10 +60,11 @@ public class HydraulicNetwork
boolean found = false;
for (ITankContainer tank : fluidReceivers)
for (TileEntity ent : receivers)
{
if (tank instanceof TileEntity)
if (ent instanceof ITankContainer)
{
ITankContainer tank = (ITankContainer) ent;
TileEntity[] surroundings = connectionHelper.getSurroundingTileEntities((TileEntity) tank);
for (int i = 0; i < 6; i++)
{
@ -153,9 +151,20 @@ public class HydraulicNetwork
*/
public void removeEntity(TileEntity ent)
{
fluidReceivers.remove(ent);
pressureProducers.remove(ent);
pressureReceivers.remove(ent);
if (receivers.contains(ent))
{
receivers.remove(ent);
}
}
/**
* Adds a tileEntity to the list if its valid
*/
public void addEntity(TileEntity ent)
{
if(!receivers.contains(ent) && (ent instanceof ITankContainer || ent instanceof IPsiMachine || ent instanceof IPsiCreator))
{
receivers.add(ent);
}
}
public void addConductor(IFluidPipe newConductor)

View file

@ -197,9 +197,13 @@ public class LiquidHandler
if (stack.stackSize == 1)
{
if (stack.getItem().hasContainerItem())
{
return stack.getItem().getContainerItemStack(stack);
}
else
{
return null;
}
}
else
{

View file

@ -0,0 +1,108 @@
package hydraulic.core.path;
import hydraulic.core.implement.ILiquidConnectionProvider;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
/**
* A class that allows flexible path finding in Minecraft Blocks.
*
* @author Calclavia
*
*/
public class Pathfinder
{
public interface IPathCallBack
{
/**
* Is this a valid node to search for?
*
* @return
*/
public boolean isValidNode(Pathfinder finder, ForgeDirection direction, ILiquidConnectionProvider provider, ILiquidConnectionProvider node);
/**
* Called when looping through nodes.
*
* @param finder
* @param provider
* @return True to stop the path finding operation.
*/
public boolean onSearch(Pathfinder finder, ILiquidConnectionProvider provider);
}
/**
* A pathfinding call back interface used to call back on paths.
*/
public IPathCallBack callBackCheck;
/**
* A list of nodes that the pathfinder went through.
*/
public List<ILiquidConnectionProvider> iteratedNodes;
/**
* The results and findings found by the pathfinder.
*/
public List results;
public Pathfinder(IPathCallBack callBack)
{
this.callBackCheck = callBack;
this.clear();
}
public boolean findNodes(ILiquidConnectionProvider provider)
{
TileEntity[] connectedBlocks = provider.getAdjacentConnections();
this.iteratedNodes.add(provider);
if (this.callBackCheck.onSearch(this, provider))
{
return false;
}
for (int i = 0; i < connectedBlocks.length; i++)
{
TileEntity connectedBlock = connectedBlocks[i];
if (connectedBlock instanceof ILiquidConnectionProvider)
{
if (!iteratedNodes.contains(connectedBlock))
{
if (this.callBackCheck.isValidNode(this, ForgeDirection.getOrientation(i), provider, (ILiquidConnectionProvider) connectedBlock))
{
if (!this.findNodes((ILiquidConnectionProvider) connectedBlock))
{
return false;
}
}
}
}
}
return true;
}
/**
* Called to execute the pathfinding operation.
*/
public Pathfinder init(ILiquidConnectionProvider provider)
{
this.findNodes(provider);
return this;
}
public Pathfinder clear()
{
this.iteratedNodes = new ArrayList<ILiquidConnectionProvider>();
this.results = new ArrayList();
return this;
}
}

View file

@ -0,0 +1,48 @@
package hydraulic.core.path;
import hydraulic.core.implement.ILiquidConnectionProvider;
import hydraulic.core.implement.ILiquidConnector;
import java.util.Arrays;
import net.minecraftforge.common.ForgeDirection;
/**
* Check if a conductor connects with another.
*
* @author Calclavia
*
*/
public class PathfinderChecker extends Pathfinder
{
public PathfinderChecker(final ILiquidConnectionProvider targetConnector, final ILiquidConnectionProvider... ignoreConnector)
{
super(new IPathCallBack()
{
@Override
public boolean isValidNode(Pathfinder finder, ForgeDirection direction, ILiquidConnectionProvider provider, ILiquidConnectionProvider connectedBlock)
{
if (connectedBlock instanceof ILiquidConnector && !Arrays.asList(ignoreConnector).contains(connectedBlock))
{
if (((ILiquidConnector) connectedBlock).canConnect(direction.getOpposite()))
{
return true;
}
}
return false;
}
@Override
public boolean onSearch(Pathfinder finder, ILiquidConnectionProvider provider)
{
if (provider == targetConnector)
{
finder.results.add(provider);
return true;
}
return false;
}
});
}
}

View file

@ -0,0 +1,39 @@
package hydraulic.core.path;
import hydraulic.core.implement.ILiquidConnectionProvider;
import hydraulic.core.implement.ILiquidConnector;
import net.minecraftforge.common.ForgeDirection;
/**
* Finds all the possible conductors.
*
* @author Calclavia
*
*/
public class PathfinderConductor extends Pathfinder
{
public PathfinderConductor()
{
super(new IPathCallBack()
{
@Override
public boolean isValidNode(Pathfinder finder, ForgeDirection direction, ILiquidConnectionProvider provider, ILiquidConnectionProvider connectedBlock)
{
if (connectedBlock instanceof ILiquidConnector)
{
if (((ILiquidConnector) connectedBlock).canConnect(direction.getOpposite()))
{
return true;
}
}
return false;
}
@Override
public boolean onSearch(Pathfinder finder, ILiquidConnectionProvider provider)
{
return false;
}
});
}
}