diff --git a/electrical/src/main/scala/resonantinduction/electrical/itemrailing/GridRailing.java b/electrical/src/main/scala/resonantinduction/electrical/itemrailing/GridRailing.java index f3b4eea3e..674845b7e 100644 --- a/electrical/src/main/scala/resonantinduction/electrical/itemrailing/GridRailing.java +++ b/electrical/src/main/scala/resonantinduction/electrical/itemrailing/GridRailing.java @@ -1,10 +1,11 @@ package resonantinduction.electrical.itemrailing; import calclavia.lib.grid.NodeGrid; +import com.google.common.collect.Sets; import resonantinduction.electrical.itemrailing.interfaces.IItemRailing; import resonantinduction.electrical.itemrailing.interfaces.IItemRailingTransfer; -import java.util.Comparator; +import java.util.*; /** * @since 18/03/14 @@ -17,18 +18,29 @@ public class GridRailing extends NodeGrid super(type); } - public IItemRailing findTargetForIItemTransfer(IItemRailingTransfer itemRailingTransfer) + public IItemRailing findTargetForIItemTransfer(IItemRailingTransfer itemwrapper) { - + if (itemwrapper.getColor() == null) + { + return findNearestInventory(itemwrapper); + } + return findNearestColoredTarget(itemwrapper); } - public static class ComparatorRailing implements Comparator + public IItemRailing findNearestInventory(IItemRailingTransfer itemwrapper) { + IItemRailing endGoal = null; + IItemRailing[] arr = (IItemRailing[]) this.getNodes().toArray(); + Arrays.sort(); - @Override - public int compare(IItemRailing o1, IItemRailing o2) + for (NodeRailing node : this.getNodes()) { - return 0; + } } + + public IItemRailing findNearestColoredTarget(IItemRailingTransfer itemwrapper) + { + + } } diff --git a/electrical/src/main/scala/resonantinduction/electrical/itemrailing/NodeRailing.java b/electrical/src/main/scala/resonantinduction/electrical/itemrailing/NodeRailing.java index eb8922d2d..e99e3a4e9 100644 --- a/electrical/src/main/scala/resonantinduction/electrical/itemrailing/NodeRailing.java +++ b/electrical/src/main/scala/resonantinduction/electrical/itemrailing/NodeRailing.java @@ -1,14 +1,21 @@ package resonantinduction.electrical.itemrailing; -import calclavia.lib.grid.Grid; import calclavia.lib.grid.Node; +import net.minecraft.inventory.IInventory; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import net.minecraftforge.common.ForgeDirection; import resonantinduction.electrical.itemrailing.interfaces.IItemRailing; +import universalelectricity.api.vector.IVectorWorld; + +import java.util.ArrayList; +import java.util.List; /** * @since 18/03/14 * @author tgame14 */ -public class NodeRailing extends Node +public class NodeRailing extends Node implements IVectorWorld { public NodeRailing (PartRailing parent) { @@ -21,6 +28,63 @@ public class NodeRailing extends Node return new GridRailing(getClass()); } + /** + * + * @return possibly null, a IInventory to target + */ + public IInventory getInventoriesNearby() + { + List invList = new ArrayList(); + for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) + { + TileEntity te = parent.getWorldPos().translate(dir).getTileEntity(parent.getWorldPos().world()); + if (te != null && te instanceof IInventory) + { + invList.add((IInventory) te); + } + } + return invList.get(parent.getWorldPos().world().rand.nextInt(invList.size())); + } + + public boolean isLeaf() + { + int connectionsCount = 0; + for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) + { + if (parent.getWorldPos().translate(dir).getTileEntity(parent.getWorldPos().world()) instanceof IItemRailing) + { + connectionsCount++; + if (connectionsCount >= 2) + { + return false; + } + } + } + return true; + } + @Override + public double z() + { + return parent.getWorldPos().z(); + } + + @Override + public World world() + { + return parent.getWorldPos().world(); + } + + @Override + public double x() + { + return parent.getWorldPos().x(); + } + + @Override + public double y() + { + return parent.getWorldPos().y() + } } diff --git a/electrical/src/main/scala/resonantinduction/electrical/itemrailing/PartRailing.java b/electrical/src/main/scala/resonantinduction/electrical/itemrailing/PartRailing.java index 32f711de9..566a3d8db 100644 --- a/electrical/src/main/scala/resonantinduction/electrical/itemrailing/PartRailing.java +++ b/electrical/src/main/scala/resonantinduction/electrical/itemrailing/PartRailing.java @@ -97,7 +97,7 @@ public class PartRailing extends PartFramedConnection