summaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/net/corechg/transit/Transit.java (renamed from src/main/java/net/corechg/transit/InitTransit.java)2
-rw-r--r--src/main/java/net/corechg/transit/network/system/INode.java20
-rw-r--r--src/main/java/net/corechg/transit/network/system/ISystem.java8
-rw-r--r--src/main/java/net/corechg/transit/network/system/swap/IAcceptorNode.java6
-rw-r--r--src/main/java/net/corechg/transit/network/system/swap/IProviderNode.java6
-rw-r--r--src/main/java/net/corechg/transit/type/Type.java15
-rw-r--r--src/main/java/net/corechg/transit/type/group/GroupRegistry.java4
-rw-r--r--src/main/java/net/corechg/transit/type/group/TypeGroup.java37
-rw-r--r--src/main/resources/fabric.mod.json4
9 files changed, 65 insertions, 37 deletions
diff --git a/src/main/java/net/corechg/transit/InitTransit.java b/src/main/java/net/corechg/transit/Transit.java
index 622d4ea..3cf4917 100644
--- a/src/main/java/net/corechg/transit/InitTransit.java
+++ b/src/main/java/net/corechg/transit/Transit.java
@@ -3,7 +3,7 @@ package net.corechg.transit;
import net.fabricmc.api.ModInitializer;
import net.corechg.transit.type.group.simple.SimpleGroups;
-public class InitTransit implements ModInitializer {
+public class Transit implements ModInitializer {
@Override
public void onInitialize() {
diff --git a/src/main/java/net/corechg/transit/network/system/INode.java b/src/main/java/net/corechg/transit/network/system/INode.java
index dbea402..94ec308 100644
--- a/src/main/java/net/corechg/transit/network/system/INode.java
+++ b/src/main/java/net/corechg/transit/network/system/INode.java
@@ -2,16 +2,17 @@ package net.corechg.transit.network.system;
/**
* @author Kyle Gunger
- * @apiNote A node inside or outside a system. Provides acceptors and providers to other nodes.
+ * @apiNote A node inside or outside a system.
*/
public interface INode
{
- /**Returns the groupIDs of groups the node interacts with
+ /**Returns true if the group given is used by the node
*
- * @return String[]
+ * @param groupID the group to querry
+ * @return bool
*/
- public String[] groupsProvided();
+ public boolean hasGroup(String groupID);
/**Get the system managing the node or {@code null} if there isn't one
@@ -35,11 +36,18 @@ public interface INode
* @param groupID
*/
public void setData(Object dat, String groupID);
-
-
+
+
/** Get the nodes that this node is connected to
*
* @return Node[]
*/
public INode[] getConnections();
+
+
+ /** Get the number of nodes that this node is connected to
+ *
+ * @return int
+ */
+ public int connectionCount();
}
diff --git a/src/main/java/net/corechg/transit/network/system/ISystem.java b/src/main/java/net/corechg/transit/network/system/ISystem.java
index 1c0b122..693a3ed 100644
--- a/src/main/java/net/corechg/transit/network/system/ISystem.java
+++ b/src/main/java/net/corechg/transit/network/system/ISystem.java
@@ -1,11 +1,9 @@
package net.corechg.transit.network.system;
-/**ISystem - a group of nodes optimized for performance
- *
- * A node can exist without a system, but a system can not exist without at least one root node.
- *
- * @param T The object type stored in the system.
+/**
+ * @author Kyle Gunger
+ * @apiNote An ISystem represents a system of nodes which has been optimized for performance. A node can exist on its own, but an ISystem can't exist without a node.
*/
public interface ISystem
{
diff --git a/src/main/java/net/corechg/transit/network/system/swap/IAcceptorNode.java b/src/main/java/net/corechg/transit/network/system/swap/IAcceptorNode.java
index 40cd430..84765ac 100644
--- a/src/main/java/net/corechg/transit/network/system/swap/IAcceptorNode.java
+++ b/src/main/java/net/corechg/transit/network/system/swap/IAcceptorNode.java
@@ -3,6 +3,10 @@ package net.corechg.transit.network.system.swap;
import net.corechg.transit.network.packet.IStaticPacket;
import net.corechg.transit.network.system.INode;
+/**
+ * @author Kyle Gunger
+ * @apiNote A node which can accept packets of specific types
+ */
public interface IAcceptorNode extends INode
{
@@ -26,7 +30,7 @@ public interface IAcceptorNode extends INode
/**
* @return Node[]
*/
- public INode[] getProviders();
+ public IProviderNode[] getProviders();
/** Accept a packet from a provider
diff --git a/src/main/java/net/corechg/transit/network/system/swap/IProviderNode.java b/src/main/java/net/corechg/transit/network/system/swap/IProviderNode.java
index 84a8f62..5fd9908 100644
--- a/src/main/java/net/corechg/transit/network/system/swap/IProviderNode.java
+++ b/src/main/java/net/corechg/transit/network/system/swap/IProviderNode.java
@@ -2,6 +2,10 @@ package net.corechg.transit.network.system.swap;
import net.corechg.transit.network.system.INode;
+/**
+ * @author Kyle Gunger
+ * @apiNote A node which can provide packets of specific types
+ */
public interface IProviderNode extends INode{
/** Link another node as an acceptor
@@ -24,6 +28,6 @@ public interface IProviderNode extends INode{
/**
* @return Node[]
*/
- public INode[] getAcceptors();
+ public IAcceptorNode[] getAcceptors();
}
diff --git a/src/main/java/net/corechg/transit/type/Type.java b/src/main/java/net/corechg/transit/type/Type.java
index 2c4d6ac..3940f3f 100644
--- a/src/main/java/net/corechg/transit/type/Type.java
+++ b/src/main/java/net/corechg/transit/type/Type.java
@@ -5,12 +5,12 @@ import net.corechg.transit.network.packet.StaticPacket;
/**@author Kyle Gunger
*
- * @param <T> The type of object transfered by packets of this type
+ * @param T The type of object transfered by packets of this type
*/
public class Type<T>
{
- protected String typeID;
- protected String groupID;
+ protected final String typeID;
+ protected final String groupID;
public Type(String tID, String gID)
{
@@ -23,7 +23,7 @@ public class Type<T>
*
* @param packet The packet (of this type)
* @param group The group asking for the conversion
- * @return <T> The packet's data in the default type
+ * @return The packet's data in the default type
*/
public T toBase(IStaticPacket<T> packet, String group)
{
@@ -35,7 +35,7 @@ public class Type<T>
*
* @param base The base data
* @param group The group that the data comes from
- * @return IPacket<<T>> The packet
+ * @return IStaticPacket The packet
*/
public IStaticPacket<T> fromBase(T base, String group)
{
@@ -59,4 +59,9 @@ public class Type<T>
{
return groupID;
}
+
+ @Override
+ public final String toString() {
+ return groupID + ":" + typeID;
+ }
}
diff --git a/src/main/java/net/corechg/transit/type/group/GroupRegistry.java b/src/main/java/net/corechg/transit/type/group/GroupRegistry.java
index c6c0186..3929973 100644
--- a/src/main/java/net/corechg/transit/type/group/GroupRegistry.java
+++ b/src/main/java/net/corechg/transit/type/group/GroupRegistry.java
@@ -20,13 +20,13 @@ public class GroupRegistry {
{
if(g.getGroup().equals(group.getGroup()))
{
- LOG.warn("Failed to add group " + group.getGroup() + " to the registry. Did another mod add a group with the same name?");
+ LOG.warn("Failed to add group " + group + " to the registry. Did another mod add a group with the same name?");
return false;
}
}
GROUPS.add(group);
- LOG.info("Successfully added group " + group.getGroup() + " to the registry.");
+ LOG.info("Successfully added group " + group + " to the registry.");
return true;
}
diff --git a/src/main/java/net/corechg/transit/type/group/TypeGroup.java b/src/main/java/net/corechg/transit/type/group/TypeGroup.java
index e04df8c..eecf6d4 100644
--- a/src/main/java/net/corechg/transit/type/group/TypeGroup.java
+++ b/src/main/java/net/corechg/transit/type/group/TypeGroup.java
@@ -42,14 +42,14 @@ public class TypeGroup<B>
*/
public boolean addType(Type<B> type)
{
- if(!isInGroup(type.getGroup(), type.getType()))
+ if(!isInGroup(type))
{
TYPES.add(type);
- LOG.info("Added type " + type.getType() + ":" + type.getGroup() + " to group " + getGroup());
+ LOG.info("Added type " + type + " to group " + getGroup());
return true;
}
- LOG.info("Failed to add type " + type.getType() + ":" + type.getGroup() + " to group " + getGroup() + ". Was the type already added?");
+ LOG.info("Failed to add type " + type + " to group " + getGroup() + ". Was the type already added?");
return false;
}
@@ -61,17 +61,17 @@ public class TypeGroup<B>
public boolean removeType(Type<B> type)
{
if(type.equals(baseType)) {
- LOG.warn("[WARN] Failed to remove type " + type.getGroup() + ":" + type.getType() + " from group " + getGroup() + ". This is the base type and can not be removed.");
+ LOG.warn("[WARN] Failed to remove type " + type + " from group " + getGroup() + ". This is the base type and can not be removed.");
return false;
}
if(TYPES.indexOf(type) != -1)
{
- LOG.info("Removed type " + TYPES.remove(TYPES.indexOf(type)).getType() + " from group " + getGroup());
+ LOG.info("Removed type " + TYPES.remove(TYPES.indexOf(type)) + " from group " + getGroup());
return true;
}
- LOG.warn("[WARN] Failed to remove type " + type.getGroup() + ":" + type.getType() + " from group " + getGroup() + ". Are we sure that the type was added to the group first?");
+ LOG.warn("[WARN] Failed to remove type " + type + " from group " + getGroup() + ". Are we sure that the type was added to the group first?");
return false;
}
@@ -82,12 +82,16 @@ public class TypeGroup<B>
*/
public boolean removeType(String groupID, String typeID)
{
-
+ if(baseType.toString() == groupID + ":" + typeID) {
+ LOG.warn("[WARN] Failed to remove type " + baseType + " from group " + getGroup() + ". This is the base type and can not be removed.");
+ return false;
+ }
+
for(Type<?> type : TYPES)
{
- if(type.getGroup().equals(groupID) && type.getType().equals(typeID))
+ if(type.toString() == groupID + ":" + typeID)
{
- LOG.info("Removed type " + TYPES.remove(TYPES.indexOf(type)).getType() + " from group " + getGroup());
+ LOG.info("Removed type " + TYPES.remove(TYPES.indexOf(type)) + " from group " + getGroup());
return true;
}
}
@@ -133,7 +137,7 @@ public class TypeGroup<B>
{
for(Type<B> t : TYPES)
{
- if(t.getGroup().equals(groupID) && t.getType().equals(typeID)) return true;
+ if(t.toString() == groupID + ":" + typeID) return true;
}
return false;
}
@@ -160,7 +164,7 @@ public class TypeGroup<B>
{
for(Type<B> t : TYPES)
{
- if(t.getGroup().equals(groupID) && t.getType().equals(typeID)) return t;
+ if(t.toString() == groupID + ":" + typeID) return t;
}
return null;
@@ -190,7 +194,7 @@ public class TypeGroup<B>
return type.fromBase(packet.getType().toBase(packet, getGroup()), getGroup());
}
- /**Convert a packet to a new type
+ /**Convert a packet to a new type Returns null if the type isn't in the group.
*
* @param packet The packet to convert
* @param type The type to convert to
@@ -206,7 +210,7 @@ public class TypeGroup<B>
return null;
}
- /**Convert a packet to a new type
+ /**Convert a packet to a new type Returns null if the type isn't found.
*
* @param packet The packet to convert
* @param groupID The groupID of the Type to convert to
@@ -224,7 +228,7 @@ public class TypeGroup<B>
return null;
}
- /**Convert a packet to a new type
+ /**Convert a packet to a new type. Returns null if the type isn't found.
*
* @param packet The packet to convert
* @param typeID The typeID of the Type to convert to
@@ -255,4 +259,9 @@ public class TypeGroup<B>
public final Type<B> getBase() {
return baseType;
}
+
+ @Override
+ public final String toString() {
+ return this.getGroup();
+ }
}
diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json
index 2c556ef..b43e25f 100644
--- a/src/main/resources/fabric.mod.json
+++ b/src/main/resources/fabric.mod.json
@@ -1,7 +1,7 @@
{
"schemaVersion": 1,
"id": "transit-api",
- "version": "0.10.3",
+ "version": "0.11.1",
"name": "Transit API",
"description": "Move about!",
@@ -19,7 +19,7 @@
"environment": "*",
"entrypoints": {
"main": [
- "net.corechg.transit.InitTransit"
+ "net.corechg.transit.Transit"
]
},