diff options
| author | Foghrye4 <foghrye4@gmail.com> | 2016-04-11 19:44:54 +0300 |
|---|---|---|
| committer | Foghrye4 <foghrye4@gmail.com> | 2016-04-11 19:44:54 +0300 |
| commit | 05c78126859231a68e199dc34613689bd0978e2f (patch) | |
| tree | 050bea104a18c72905095d29f31bec2935a27a24 /ihl/datanet/DataNet.java | |
Initial commit
Diffstat (limited to 'ihl/datanet/DataNet.java')
| -rw-r--r-- | ihl/datanet/DataNet.java | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/ihl/datanet/DataNet.java b/ihl/datanet/DataNet.java new file mode 100644 index 0000000..3f88c55 --- /dev/null +++ b/ihl/datanet/DataNet.java @@ -0,0 +1,127 @@ +package ihl.datanet;
+
+import ihl.IHLMod;
+import ihl.flexible_cable.NodeEntity;
+import ihl.interfaces.IDataNode;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import net.minecraft.nbt.NBTTagCompound;
+
+public class DataNet {
+
+ public Map<Integer, DataGrid> grids = new HashMap();
+ private int griduid=0;
+
+ public DataNet()
+ {
+ }
+
+ public int getNewUniqueGridID()
+ {
+ for(int i=0;i<Integer.MAX_VALUE;i++)
+ {
+ if(grids.get(++griduid)==null)
+ {
+ return griduid;
+ }
+ }
+ return -1;
+ }
+
+ public int mergeGrids(int gridID, int gridID2)
+ {
+ if(gridID==-1 && gridID2!=-1)
+ {
+ return gridID2;
+ }
+ else if(gridID!=-1 && gridID2==-1)
+ {
+ return gridID;
+ }
+ else if(gridID==-1 && gridID2==-1)
+ {
+ int newGridID=this.getNewUniqueGridID();
+ DataGrid cgrid;
+ cgrid=new DataGrid();
+ grids.put(newGridID, cgrid);
+ return newGridID;
+ }
+ else if(gridID!=gridID2)
+ {
+ Iterator<IDataNode> tei = grids.get(gridID2).telist.iterator();
+ while(tei.hasNext())
+ {
+ IDataNode te = tei.next();
+ te.setDataGrid(gridID);
+ }
+ grids.remove(gridID2);
+ return gridID;
+ }
+ return gridID2;
+ }
+
+
+ public DataGrid getGrid(int gridID)
+ {
+ if(this.grids.get(gridID)==null)
+ {
+ DataGrid cgrid;
+ cgrid=new DataGrid();
+ grids.put(gridID, cgrid);
+ return cgrid;
+ }
+ else
+ {
+ return this.grids.get(gridID);
+ }
+ }
+
+ public void splitGrids(int gridID)
+ {
+ DataGrid grid1 = this.grids.get(gridID);
+ Set<IDataNode> excludedNodes = grid1.getListOfExcludedNodes();
+ if(!excludedNodes.isEmpty())
+ {
+ if(grid1.telist.size()==1)
+ {
+ IDataNode singleNode = grid1.telist.iterator().next();
+ singleNode.setDataGrid(-1);
+ grid1.telist.remove(singleNode);
+ }
+ if(excludedNodes.size()==1)
+ {
+ IDataNode singleNode = excludedNodes.iterator().next();
+ singleNode.setDataGrid(-1);
+ }
+ else //Form a new grid
+ {
+ int newGridId = this.getNewUniqueGridID();
+ Iterator<IDataNode> excludedNodesI = excludedNodes.iterator();
+ while(excludedNodesI.hasNext())
+ {
+ excludedNodesI.next().setDataGrid(newGridId);
+ }
+ }
+ }
+ }
+
+ public void removeCableEntities(NBTTagCompound cable)
+ {
+ int uid = cable.getInteger("chainUID");
+ Set<NodeEntity> cs = IHLMod.proxy.nodeEntityRegistry.get(uid);
+ if(cs!=null)
+ {
+ for(NodeEntity ne:cs)
+ {
+ if(ne!=null)
+ {
+ ne.setDead();
+ }
+ }
+ }
+ }
+}
|
