From 5cf67526600deb0db677d7b3db0f86c034090fa5 Mon Sep 17 00:00:00 2001 From: Kyle Gunger Date: Tue, 21 Apr 2020 18:50:51 -0400 Subject: [Update] Version 0.11.1 ~ Changed the init file name ~ Edits to the requirements of nodes --- src/main/java/net/corechg/transit/InitTransit.java | 13 -------- src/main/java/net/corechg/transit/Transit.java | 13 ++++++++ .../net/corechg/transit/network/system/INode.java | 20 ++++++++---- .../corechg/transit/network/system/ISystem.java | 8 ++--- .../transit/network/system/swap/IAcceptorNode.java | 6 +++- .../transit/network/system/swap/IProviderNode.java | 6 +++- src/main/java/net/corechg/transit/type/Type.java | 15 ++++++--- .../corechg/transit/type/group/GroupRegistry.java | 4 +-- .../net/corechg/transit/type/group/TypeGroup.java | 37 ++++++++++++++-------- src/main/resources/fabric.mod.json | 4 +-- 10 files changed, 77 insertions(+), 49 deletions(-) delete mode 100644 src/main/java/net/corechg/transit/InitTransit.java create mode 100644 src/main/java/net/corechg/transit/Transit.java (limited to 'src/main') diff --git a/src/main/java/net/corechg/transit/InitTransit.java b/src/main/java/net/corechg/transit/InitTransit.java deleted file mode 100644 index 622d4ea..0000000 --- a/src/main/java/net/corechg/transit/InitTransit.java +++ /dev/null @@ -1,13 +0,0 @@ -package net.corechg.transit; - -import net.fabricmc.api.ModInitializer; -import net.corechg.transit.type.group.simple.SimpleGroups; - -public class InitTransit implements ModInitializer { - - @Override - public void onInitialize() { - SimpleGroups.init(); - } - -} diff --git a/src/main/java/net/corechg/transit/Transit.java b/src/main/java/net/corechg/transit/Transit.java new file mode 100644 index 0000000..3cf4917 --- /dev/null +++ b/src/main/java/net/corechg/transit/Transit.java @@ -0,0 +1,13 @@ +package net.corechg.transit; + +import net.fabricmc.api.ModInitializer; +import net.corechg.transit.type.group.simple.SimpleGroups; + +public class Transit implements ModInitializer { + + @Override + public void onInitialize() { + SimpleGroups.init(); + } + +} 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 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 { - 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 * * @param packet The packet (of this type) * @param group The group asking for the conversion - * @return The packet's data in the default type + * @return The packet's data in the default type */ public T toBase(IStaticPacket packet, String group) { @@ -35,7 +35,7 @@ public class Type * * @param base The base data * @param group The group that the data comes from - * @return IPacket<> The packet + * @return IStaticPacket The packet */ public IStaticPacket fromBase(T base, String group) { @@ -59,4 +59,9 @@ public class Type { 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 */ public boolean addType(Type 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 public boolean removeType(Type 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 */ 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 { for(Type 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 { for(Type 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 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 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 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 public final Type 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" ] }, -- cgit v1.2.3