From c78cd153e6087627fd817d3a16cedeae9cf87b0e Mon Sep 17 00:00:00 2001 From: tgame14 Date: Thu, 17 Apr 2014 13:41:53 +0300 Subject: [PATCH] Adding logic to choose next ItemRailing for IItemRailingTransfer to go to next --- .../electrical/itemrailing/GridRailing.java | 7 +++++++ .../electrical/itemrailing/NodeRailing.java | 11 ++++++++++- .../itemrailing/RailingDistanceComparator.java | 2 +- .../itemrailing/interfaces/IItemRailing.java | 7 ++++++- .../itemrailing/interfaces/IItemRailingTransfer.java | 3 +++ 5 files changed, 27 insertions(+), 3 deletions(-) diff --git a/electrical/src/main/scala/resonantinduction/electrical/itemrailing/GridRailing.java b/electrical/src/main/scala/resonantinduction/electrical/itemrailing/GridRailing.java index e1c3db089..f223e2c0c 100644 --- a/electrical/src/main/scala/resonantinduction/electrical/itemrailing/GridRailing.java +++ b/electrical/src/main/scala/resonantinduction/electrical/itemrailing/GridRailing.java @@ -39,4 +39,11 @@ public class GridRailing extends NodeGrid Arrays.sort(arr, new RailingDistanceComparator.RailingColoredDistanceComparator(itemwrapper.getRailing(), itemwrapper.getColor())); return arr[0]; } + + public IItemRailing chooseNextGoal(IItemRailingTransfer itemwrapper) + { + IItemRailing[] arr = (IItemRailing[]) itemwrapper.getRailing().getConnectionMap().entrySet().toArray(); + Arrays.sort(arr, new RailingDistanceComparator(itemwrapper.getEndGoal())); + return arr[0]; + } } diff --git a/electrical/src/main/scala/resonantinduction/electrical/itemrailing/NodeRailing.java b/electrical/src/main/scala/resonantinduction/electrical/itemrailing/NodeRailing.java index cf7d1005e..4e16bfbe4 100644 --- a/electrical/src/main/scala/resonantinduction/electrical/itemrailing/NodeRailing.java +++ b/electrical/src/main/scala/resonantinduction/electrical/itemrailing/NodeRailing.java @@ -14,13 +14,14 @@ import universalelectricity.api.vector.VectorWorld; import java.util.ArrayList; import java.util.HashSet; +import java.util.Map; import java.util.Set; /** * @author tgame14 * @since 18/03/14 */ -public class NodeRailing extends Node implements IVectorWorld, IItemRailing +public class NodeRailing extends Node implements IVectorWorld, IItemRailing { private EnumColor color; private Set itemNodeSet; @@ -93,6 +94,12 @@ public class NodeRailing extends Node imp return parent.getWorldPos(); } + @Override + public Map getConnectionMap() + { + return this.getConnections(); + } + @Override public IInventory[] getInventoriesNearby() { @@ -112,4 +119,6 @@ public class NodeRailing extends Node imp { return parent.getConnections().length < 2; } + + } diff --git a/electrical/src/main/scala/resonantinduction/electrical/itemrailing/RailingDistanceComparator.java b/electrical/src/main/scala/resonantinduction/electrical/itemrailing/RailingDistanceComparator.java index d7a5a7975..73f04e39a 100644 --- a/electrical/src/main/scala/resonantinduction/electrical/itemrailing/RailingDistanceComparator.java +++ b/electrical/src/main/scala/resonantinduction/electrical/itemrailing/RailingDistanceComparator.java @@ -9,7 +9,7 @@ import java.util.Comparator; * @author tgame14 * @since 16/04/14 */ -public abstract class RailingDistanceComparator implements Comparator +public class RailingDistanceComparator implements Comparator { private IItemRailing source; diff --git a/electrical/src/main/scala/resonantinduction/electrical/itemrailing/interfaces/IItemRailing.java b/electrical/src/main/scala/resonantinduction/electrical/itemrailing/interfaces/IItemRailing.java index cb6f31c1c..935888065 100644 --- a/electrical/src/main/scala/resonantinduction/electrical/itemrailing/interfaces/IItemRailing.java +++ b/electrical/src/main/scala/resonantinduction/electrical/itemrailing/interfaces/IItemRailing.java @@ -1,17 +1,20 @@ package resonantinduction.electrical.itemrailing.interfaces; +import calclavia.lib.grid.INode; import calclavia.lib.render.EnumColor; import net.minecraft.inventory.IInventory; import net.minecraftforge.common.ForgeDirection; import universalelectricity.api.vector.VectorWorld; +import java.util.Map; + /** * implement on Part Railings. * * @since 16/03/14 * @author tgame14 */ -public interface IItemRailing +public interface IItemRailing extends INode { public boolean canItemEnter (IItemRailingTransfer item); @@ -23,6 +26,8 @@ public interface IItemRailing public VectorWorld getWorldPos(); + public Map getConnectionMap(); + public IInventory[] getInventoriesNearby(); public boolean isLeaf(); diff --git a/electrical/src/main/scala/resonantinduction/electrical/itemrailing/interfaces/IItemRailingTransfer.java b/electrical/src/main/scala/resonantinduction/electrical/itemrailing/interfaces/IItemRailingTransfer.java index 4468e75a0..a09597345 100644 --- a/electrical/src/main/scala/resonantinduction/electrical/itemrailing/interfaces/IItemRailingTransfer.java +++ b/electrical/src/main/scala/resonantinduction/electrical/itemrailing/interfaces/IItemRailingTransfer.java @@ -1,9 +1,12 @@ package resonantinduction.electrical.itemrailing.interfaces; import net.minecraft.item.ItemStack; +import net.minecraftforge.common.ForgeDirection; import resonantinduction.electrical.itemrailing.PartRailing; import calclavia.lib.render.EnumColor; +import java.util.Map; + /** * the object that functions as a Wrapper for items and handles the items that flow through Railings *