From 85ca955e34376e203d1013ab90226cfe7f15c395 Mon Sep 17 00:00:00 2001 From: Kyle Gunger Date: Mon, 19 Oct 2020 00:46:16 -0400 Subject: Package change + Abstract implementation for INode ~ Changed requirements for nodes ~ Changed package signatures --- src/main/java/net/corechg/mc/transit/Transit.java | 13 + .../mc/transit/basic/AbstractAcceptorNode.java | 51 ++++ .../net/corechg/mc/transit/basic/AbstractNode.java | 45 ++++ .../mc/transit/basic/AbstractProviderNode.java | 47 ++++ .../mc/transit/basic/AbstractTwoWayNode.java | 47 ++++ .../mc/transit/basic/system/AbstractSystem.java | 13 + .../transit/basic/system/AbstractSystemNode.java | 12 + .../mc/transit/network/packet/IStaticPacket.java | 23 ++ .../mc/transit/network/packet/MetaPacket.java | 35 +++ .../mc/transit/network/packet/StaticPacket.java | 36 +++ .../network/packet/dynamic/DynamicPacket.java | 43 ++++ .../network/packet/dynamic/IDynamicPacket.java | 16 ++ .../network/packet/dynamic/MetaDynamicPacket.java | 44 ++++ .../mc/transit/network/system/Connection.java | 49 ++++ .../corechg/mc/transit/network/system/INode.java | 53 ++++ .../corechg/mc/transit/network/system/ISystem.java | 15 ++ .../transit/network/system/swap/IAcceptorNode.java | 37 +++ .../transit/network/system/swap/IProviderNode.java | 27 +++ .../java/net/corechg/mc/transit/type/TFluid.java | 33 +++ .../java/net/corechg/mc/transit/type/TMana.java | 31 +++ .../java/net/corechg/mc/transit/type/Type.java | 66 +++++ .../mc/transit/type/group/GroupRegistry.java | 56 +++++ .../corechg/mc/transit/type/group/TypeGroup.java | 267 +++++++++++++++++++++ .../mc/transit/type/group/simple/SimpleGroups.java | 32 +++ .../mc/transit/type/simple/SimpleTypes.java | 22 ++ src/main/java/net/corechg/transit/Transit.java | 13 - .../transit/network/packet/IStaticPacket.java | 23 -- .../corechg/transit/network/packet/MetaPacket.java | 35 --- .../transit/network/packet/StaticPacket.java | 36 --- .../network/packet/dynamic/DynamicPacket.java | 43 ---- .../network/packet/dynamic/IDynamicPacket.java | 16 -- .../network/packet/dynamic/MetaDynamicPacket.java | 44 ---- .../net/corechg/transit/network/system/INode.java | 53 ---- .../corechg/transit/network/system/ISystem.java | 15 -- .../transit/network/system/swap/IAcceptorNode.java | 43 ---- .../transit/network/system/swap/IProviderNode.java | 33 --- src/main/java/net/corechg/transit/type/TFluid.java | 33 --- src/main/java/net/corechg/transit/type/TMana.java | 31 --- src/main/java/net/corechg/transit/type/Type.java | 67 ------ .../corechg/transit/type/group/GroupRegistry.java | 56 ----- .../net/corechg/transit/type/group/TypeGroup.java | 267 --------------------- .../transit/type/group/simple/SimpleGroups.java | 33 --- .../corechg/transit/type/simple/SimpleTypes.java | 22 -- 43 files changed, 1113 insertions(+), 863 deletions(-) create mode 100644 src/main/java/net/corechg/mc/transit/Transit.java create mode 100644 src/main/java/net/corechg/mc/transit/basic/AbstractAcceptorNode.java create mode 100644 src/main/java/net/corechg/mc/transit/basic/AbstractNode.java create mode 100644 src/main/java/net/corechg/mc/transit/basic/AbstractProviderNode.java create mode 100644 src/main/java/net/corechg/mc/transit/basic/AbstractTwoWayNode.java create mode 100644 src/main/java/net/corechg/mc/transit/basic/system/AbstractSystem.java create mode 100644 src/main/java/net/corechg/mc/transit/basic/system/AbstractSystemNode.java create mode 100644 src/main/java/net/corechg/mc/transit/network/packet/IStaticPacket.java create mode 100644 src/main/java/net/corechg/mc/transit/network/packet/MetaPacket.java create mode 100644 src/main/java/net/corechg/mc/transit/network/packet/StaticPacket.java create mode 100644 src/main/java/net/corechg/mc/transit/network/packet/dynamic/DynamicPacket.java create mode 100644 src/main/java/net/corechg/mc/transit/network/packet/dynamic/IDynamicPacket.java create mode 100644 src/main/java/net/corechg/mc/transit/network/packet/dynamic/MetaDynamicPacket.java create mode 100644 src/main/java/net/corechg/mc/transit/network/system/Connection.java create mode 100644 src/main/java/net/corechg/mc/transit/network/system/INode.java create mode 100644 src/main/java/net/corechg/mc/transit/network/system/ISystem.java create mode 100644 src/main/java/net/corechg/mc/transit/network/system/swap/IAcceptorNode.java create mode 100644 src/main/java/net/corechg/mc/transit/network/system/swap/IProviderNode.java create mode 100644 src/main/java/net/corechg/mc/transit/type/TFluid.java create mode 100644 src/main/java/net/corechg/mc/transit/type/TMana.java create mode 100644 src/main/java/net/corechg/mc/transit/type/Type.java create mode 100644 src/main/java/net/corechg/mc/transit/type/group/GroupRegistry.java create mode 100644 src/main/java/net/corechg/mc/transit/type/group/TypeGroup.java create mode 100644 src/main/java/net/corechg/mc/transit/type/group/simple/SimpleGroups.java create mode 100644 src/main/java/net/corechg/mc/transit/type/simple/SimpleTypes.java delete mode 100644 src/main/java/net/corechg/transit/Transit.java delete mode 100644 src/main/java/net/corechg/transit/network/packet/IStaticPacket.java delete mode 100644 src/main/java/net/corechg/transit/network/packet/MetaPacket.java delete mode 100644 src/main/java/net/corechg/transit/network/packet/StaticPacket.java delete mode 100644 src/main/java/net/corechg/transit/network/packet/dynamic/DynamicPacket.java delete mode 100644 src/main/java/net/corechg/transit/network/packet/dynamic/IDynamicPacket.java delete mode 100644 src/main/java/net/corechg/transit/network/packet/dynamic/MetaDynamicPacket.java delete mode 100644 src/main/java/net/corechg/transit/network/system/INode.java delete mode 100644 src/main/java/net/corechg/transit/network/system/ISystem.java delete mode 100644 src/main/java/net/corechg/transit/network/system/swap/IAcceptorNode.java delete mode 100644 src/main/java/net/corechg/transit/network/system/swap/IProviderNode.java delete mode 100644 src/main/java/net/corechg/transit/type/TFluid.java delete mode 100644 src/main/java/net/corechg/transit/type/TMana.java delete mode 100644 src/main/java/net/corechg/transit/type/Type.java delete mode 100644 src/main/java/net/corechg/transit/type/group/GroupRegistry.java delete mode 100644 src/main/java/net/corechg/transit/type/group/TypeGroup.java delete mode 100644 src/main/java/net/corechg/transit/type/group/simple/SimpleGroups.java delete mode 100644 src/main/java/net/corechg/transit/type/simple/SimpleTypes.java (limited to 'src/main/java/net') diff --git a/src/main/java/net/corechg/mc/transit/Transit.java b/src/main/java/net/corechg/mc/transit/Transit.java new file mode 100644 index 0000000..36b60bf --- /dev/null +++ b/src/main/java/net/corechg/mc/transit/Transit.java @@ -0,0 +1,13 @@ +package net.corechg.mc.transit; + +import net.fabricmc.api.ModInitializer; +import net.corechg.mc.transit.type.group.simple.SimpleGroups; + +public class Transit implements ModInitializer { + + @Override + public void onInitialize() { + SimpleGroups.init(); + } + +} diff --git a/src/main/java/net/corechg/mc/transit/basic/AbstractAcceptorNode.java b/src/main/java/net/corechg/mc/transit/basic/AbstractAcceptorNode.java new file mode 100644 index 0000000..d569557 --- /dev/null +++ b/src/main/java/net/corechg/mc/transit/basic/AbstractAcceptorNode.java @@ -0,0 +1,51 @@ +package net.corechg.mc.transit.basic; + +import net.corechg.mc.transit.network.packet.IStaticPacket; +import net.corechg.mc.transit.network.system.Connection; +import net.corechg.mc.transit.network.system.swap.*; +import net.minecraft.block.entity.BlockEntityType; + +public abstract class AbstractAcceptorNode extends AbstractNode implements IAcceptorNode { + + public AbstractAcceptorNode(BlockEntityType type) { + super(type); + } + + @Override + public abstract boolean accept(IStaticPacket packet, String group); + + @Override + public boolean linkProvider(IProviderNode requestor, String group) { + if(this.hasGroup(group)) + { + for (Connection c : connections) { + if(c.getNode() == requestor) + return false; + } + + connections.add(new Connection(requestor, (short) 2)); + + return true; + } + + return false; + } + + @Override + public boolean unlinkProvider(IProviderNode requestor) { + for (Connection c : connections) { + if(c.getNode() == requestor) + { + if(c.isAccepting()) + c.setProviding(false); + else + connections.remove(c); + + return true; + } + } + + return false; + } + +} \ No newline at end of file diff --git a/src/main/java/net/corechg/mc/transit/basic/AbstractNode.java b/src/main/java/net/corechg/mc/transit/basic/AbstractNode.java new file mode 100644 index 0000000..01c537c --- /dev/null +++ b/src/main/java/net/corechg/mc/transit/basic/AbstractNode.java @@ -0,0 +1,45 @@ +package net.corechg.mc.transit.basic; + +import java.util.*; + +import net.corechg.mc.transit.network.system.*; +import net.minecraft.block.entity.*; + +public abstract class AbstractNode extends BlockEntity implements INode { + + public AbstractNode(BlockEntityType type) { + super(type); + } + + HashMap data = new HashMap(); + ArrayList connections = new ArrayList(0); + + @Override + public abstract boolean hasGroup(String groupID); + + @Override + public ISystem getSystem() { + return null; + } + + @Override + public Object getData(String groupID) { + return data.get(groupID); + } + + @Override + public void setData(Object dat, String groupID) { + data.put(groupID, dat); + } + + @Override + public Connection[] getConnections() { + return (Connection[]) connections.toArray(); + } + + @Override + public int connectionCount() { + return connections.size(); + } + +} \ No newline at end of file diff --git a/src/main/java/net/corechg/mc/transit/basic/AbstractProviderNode.java b/src/main/java/net/corechg/mc/transit/basic/AbstractProviderNode.java new file mode 100644 index 0000000..7ddc41b --- /dev/null +++ b/src/main/java/net/corechg/mc/transit/basic/AbstractProviderNode.java @@ -0,0 +1,47 @@ +package net.corechg.mc.transit.basic; + +import net.corechg.mc.transit.network.system.Connection; +import net.corechg.mc.transit.network.system.swap.*; +import net.minecraft.block.entity.BlockEntityType; + +public abstract class AbstractProviderNode extends AbstractNode implements IProviderNode { + + public AbstractProviderNode(BlockEntityType type) { + super(type); + } + + @Override + public boolean linkAcceptor(IAcceptorNode requestor, String group) { + if(this.hasGroup(group)) + { + for (Connection c : connections) { + if(c.getNode() == requestor) + return false; + } + + connections.add(new Connection(requestor, (short) 1)); + + return true; + } + + return false; + } + + @Override + public boolean unlinkAcceptor(IAcceptorNode requestor) { + for (Connection c : connections) { + if(c.getNode() == requestor) + { + if(c.isProviding()) + c.setAccepting(false); + else + connections.remove(c); + + return true; + } + } + + return false; + } + +} \ No newline at end of file diff --git a/src/main/java/net/corechg/mc/transit/basic/AbstractTwoWayNode.java b/src/main/java/net/corechg/mc/transit/basic/AbstractTwoWayNode.java new file mode 100644 index 0000000..1d37245 --- /dev/null +++ b/src/main/java/net/corechg/mc/transit/basic/AbstractTwoWayNode.java @@ -0,0 +1,47 @@ +package net.corechg.mc.transit.basic; + +import net.corechg.mc.transit.network.system.Connection; +import net.corechg.mc.transit.network.system.swap.*; +import net.minecraft.block.entity.BlockEntityType; + +public abstract class AbstractTwoWayNode extends AbstractAcceptorNode implements IProviderNode { + + public AbstractTwoWayNode(BlockEntityType type) { + super(type); + } + + @Override + public boolean linkAcceptor(IAcceptorNode requestor, String group) { + if(this.hasGroup(group)) + { + for (Connection c : connections) { + if(c.getNode() == requestor) + return false; + } + + connections.add(new Connection(requestor, (short) 1)); + + return true; + } + + return false; + } + + @Override + public boolean unlinkAcceptor(IAcceptorNode requestor) { + for (Connection c : connections) { + if(c.getNode() == requestor) + { + if(c.isProviding()) + c.setAccepting(false); + else + connections.remove(c); + + return true; + } + } + + return false; + } + +} \ No newline at end of file diff --git a/src/main/java/net/corechg/mc/transit/basic/system/AbstractSystem.java b/src/main/java/net/corechg/mc/transit/basic/system/AbstractSystem.java new file mode 100644 index 0000000..637a072 --- /dev/null +++ b/src/main/java/net/corechg/mc/transit/basic/system/AbstractSystem.java @@ -0,0 +1,13 @@ +package net.corechg.mc.transit.basic.system; + +import net.corechg.mc.transit.network.system.*; + +public abstract class AbstractSystem implements ISystem { + + @Override + public INode[] getNodes() { + // TODO Auto-generated method stub + return null; + } + +} \ No newline at end of file diff --git a/src/main/java/net/corechg/mc/transit/basic/system/AbstractSystemNode.java b/src/main/java/net/corechg/mc/transit/basic/system/AbstractSystemNode.java new file mode 100644 index 0000000..c65c6a2 --- /dev/null +++ b/src/main/java/net/corechg/mc/transit/basic/system/AbstractSystemNode.java @@ -0,0 +1,12 @@ +package net.corechg.mc.transit.basic.system; + +import net.corechg.mc.transit.basic.*; +import net.minecraft.block.entity.BlockEntityType; + +public abstract class AbstractSystemNode extends AbstractNode { + + public AbstractSystemNode(BlockEntityType type) { + super(type); + } + +} \ No newline at end of file diff --git a/src/main/java/net/corechg/mc/transit/network/packet/IStaticPacket.java b/src/main/java/net/corechg/mc/transit/network/packet/IStaticPacket.java new file mode 100644 index 0000000..27dd3fb --- /dev/null +++ b/src/main/java/net/corechg/mc/transit/network/packet/IStaticPacket.java @@ -0,0 +1,23 @@ +package net.corechg.mc.transit.network.packet; + +import net.corechg.mc.transit.type.Type; + +/** Interface describing an unchanging packet. + * @author Kyle Gunger + * + * @param The data type (Object) that the packet transfers. + */ +public interface IStaticPacket +{ + /**Get the packet's data. + * + * @return The packet's data + */ + public D getData(); + + /**Get the packet's type. + * + * @return IType<> The type of the packet + */ + public Type getType(); +} \ No newline at end of file diff --git a/src/main/java/net/corechg/mc/transit/network/packet/MetaPacket.java b/src/main/java/net/corechg/mc/transit/network/packet/MetaPacket.java new file mode 100644 index 0000000..3195198 --- /dev/null +++ b/src/main/java/net/corechg/mc/transit/network/packet/MetaPacket.java @@ -0,0 +1,35 @@ +package net.corechg.mc.transit.network.packet; + +import net.corechg.mc.transit.type.Type; + +/** Static packet with extra data attached. + * @author Kyle Gunger + * + * @param The data type (Object) that the packet transfers + * @param The type of metadata +*/ +public class MetaPacket extends StaticPacket +{ + private M metaData; + + /** Constructor + * + * @param dat The data to store + * @param t The Type of the data + * @param meta The metadata to store + */ + public MetaPacket(D dat, Type t, M meta) + { + super(dat, t); + metaData = meta; + } + + /** Get the metadata of the packet. + * + * @return The packet's metadata + */ + public M getMetaData() + { + return metaData; + } +} diff --git a/src/main/java/net/corechg/mc/transit/network/packet/StaticPacket.java b/src/main/java/net/corechg/mc/transit/network/packet/StaticPacket.java new file mode 100644 index 0000000..cf37b02 --- /dev/null +++ b/src/main/java/net/corechg/mc/transit/network/packet/StaticPacket.java @@ -0,0 +1,36 @@ +package net.corechg.mc.transit.network.packet; + +import net.corechg.mc.transit.type.Type; + +/** Simple packet which stores an unchanging value. + * @author Kyle Gunger + * + * @param The data type (Object) that the packet transfers. + */ +public class StaticPacket implements IStaticPacket +{ + private D data; + private Type type; + + /** Constructor. Stores the given data and uses the given type. + * + * @param dat The packet's data + * @param t The packet's type + */ + public StaticPacket(D dat, Type t) + { + data = dat; + type = t; + } + + @Override + public D getData() + { + return data; + } + + @Override + public Type getType() { + return type; + } +} \ No newline at end of file diff --git a/src/main/java/net/corechg/mc/transit/network/packet/dynamic/DynamicPacket.java b/src/main/java/net/corechg/mc/transit/network/packet/dynamic/DynamicPacket.java new file mode 100644 index 0000000..e59a762 --- /dev/null +++ b/src/main/java/net/corechg/mc/transit/network/packet/dynamic/DynamicPacket.java @@ -0,0 +1,43 @@ +package net.corechg.mc.transit.network.packet.dynamic; + +import net.corechg.mc.transit.type.Type; + +/** + * Simple packet which stores a fluid value. + * + * @author Kyle Gunger + * + * @param The data type (Object) that the packet transfers + */ +public class DynamicPacket implements IDynamicPacket { + private D data; + private Type type; + + /** Constructor. Stores the given data and uses the given type. + * + * @param dat The packet's data + * @param t The packet's type + */ + public DynamicPacket(D dat, Type t) + { + data = dat; + type = t; + } + + @Override + public D getData() + { + return data; + } + + @Override + public void setData(D dat) + { + data = dat; + } + + @Override + public Type getType() { + return type; + } +} \ No newline at end of file diff --git a/src/main/java/net/corechg/mc/transit/network/packet/dynamic/IDynamicPacket.java b/src/main/java/net/corechg/mc/transit/network/packet/dynamic/IDynamicPacket.java new file mode 100644 index 0000000..096d289 --- /dev/null +++ b/src/main/java/net/corechg/mc/transit/network/packet/dynamic/IDynamicPacket.java @@ -0,0 +1,16 @@ +package net.corechg.mc.transit.network.packet.dynamic; + +import net.corechg.mc.transit.network.packet.IStaticPacket; + +/** Interface describing a fluid packet. + * @author Kyle Gunger + * + * @param The data type (Object) that the packet transfers + */ +public interface IDynamicPacket extends IStaticPacket{ + /**Set the packet's data. + * + * @return The packet's data + */ + public void setData(D dat); +} \ No newline at end of file diff --git a/src/main/java/net/corechg/mc/transit/network/packet/dynamic/MetaDynamicPacket.java b/src/main/java/net/corechg/mc/transit/network/packet/dynamic/MetaDynamicPacket.java new file mode 100644 index 0000000..fd4c24d --- /dev/null +++ b/src/main/java/net/corechg/mc/transit/network/packet/dynamic/MetaDynamicPacket.java @@ -0,0 +1,44 @@ +package net.corechg.mc.transit.network.packet.dynamic; + +import net.corechg.mc.transit.type.Type; + +/** Static packet with extra data attached. + * @author Kyle Gunger + * + * @param The data type (Object) that the packet transfers + * @param The type of metadata +*/ +public class MetaDynamicPacket extends DynamicPacket +{ + private M metaData; + + /** Constructor + * + * @param dat The data to store + * @param t The Type of the data + * @param meta The metadata to store + */ + public MetaDynamicPacket(D dat, Type t, M meta) + { + super(dat, t); + metaData = meta; + } + + /** Get the metadata of the packet. + * + * @return The packet's metadata + */ + public M getMetaData() + { + return metaData; + } + + /** Set the metadata of the packet. + * + * @param meta The packet's new metadata + */ + public void setMetaData(M meta) + { + metaData = meta; + } +} diff --git a/src/main/java/net/corechg/mc/transit/network/system/Connection.java b/src/main/java/net/corechg/mc/transit/network/system/Connection.java new file mode 100644 index 0000000..bb53f93 --- /dev/null +++ b/src/main/java/net/corechg/mc/transit/network/system/Connection.java @@ -0,0 +1,49 @@ +package net.corechg.mc.transit.network.system; + +public class Connection { + INode node; + short mask; + + public Connection(INode n) + { + node = n; + mask = 0; + } + + public Connection(INode n, short m) + { + node = n; + mask = m; + } + + public INode getNode() + { + return node; + } + + public boolean isAccepting() + { + return (mask & 1) == 1; + } + + public void setAccepting(boolean value) + { + if(isAccepting() && value == false) + mask -= 1; + else if(!isAccepting() && value == true) + mask += 1; + } + + public boolean isProviding() + { + return (mask & 2) == 2; + } + + public void setProviding(boolean value) + { + if(isProviding() && value == false) + mask -= 2; + else if(!isProviding() && value == true) + mask += 2; + } +} \ No newline at end of file diff --git a/src/main/java/net/corechg/mc/transit/network/system/INode.java b/src/main/java/net/corechg/mc/transit/network/system/INode.java new file mode 100644 index 0000000..71733e6 --- /dev/null +++ b/src/main/java/net/corechg/mc/transit/network/system/INode.java @@ -0,0 +1,53 @@ +package net.corechg.mc.transit.network.system; + +/** + * @author Kyle Gunger + * @apiNote A node inside or outside a system. + */ +public interface INode +{ + + /**Returns true if the group given is used by the node + * + * @param groupID the group to querry + * @return bool + */ + public boolean hasGroup(String groupID); + + + /**Get the system managing the node or {@code null} if there isn't one + * + * @return System + */ + public ISystem getSystem(); + + + /** Get the data of one of the TypeGroups the Node supports + * + * @param groupID + * @return + */ + public Object getData(String groupID); + + + /** Set the group data for the node + * + * @param dat + * @param groupID + */ + public void setData(Object dat, String groupID); + + + /** Get the nodes that this node is connected to + * + * @return Node[] + */ + public Connection[] 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/mc/transit/network/system/ISystem.java b/src/main/java/net/corechg/mc/transit/network/system/ISystem.java new file mode 100644 index 0000000..0ebb656 --- /dev/null +++ b/src/main/java/net/corechg/mc/transit/network/system/ISystem.java @@ -0,0 +1,15 @@ +package net.corechg.mc.transit.network.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 +{ + /**The nodes stored by the system + * + * @return INode[] + */ + public INode[] getNodes(); +} diff --git a/src/main/java/net/corechg/mc/transit/network/system/swap/IAcceptorNode.java b/src/main/java/net/corechg/mc/transit/network/system/swap/IAcceptorNode.java new file mode 100644 index 0000000..61f6022 --- /dev/null +++ b/src/main/java/net/corechg/mc/transit/network/system/swap/IAcceptorNode.java @@ -0,0 +1,37 @@ +package net.corechg.mc.transit.network.system.swap; + +import net.corechg.mc.transit.network.packet.IStaticPacket; +import net.corechg.mc.transit.network.system.INode; + +/** + * @author Kyle Gunger + * @apiNote A node which can accept packets of specific types + */ +public interface IAcceptorNode extends INode +{ + + /** Link another node as a provider + * + * @param requester The object to be a provider + * @param group + * @return + */ + public boolean linkProvider(IProviderNode requestor, String group); + + + /** Unlink a provider from the acceptor + * + * @param requestor + * @return + */ + public boolean unlinkProvider(IProviderNode requestor); + + + /** Accept a packet from a provider + * + * @param packet + * @param group + * @return + */ + public boolean accept(IStaticPacket packet, String group); +} diff --git a/src/main/java/net/corechg/mc/transit/network/system/swap/IProviderNode.java b/src/main/java/net/corechg/mc/transit/network/system/swap/IProviderNode.java new file mode 100644 index 0000000..62a45b7 --- /dev/null +++ b/src/main/java/net/corechg/mc/transit/network/system/swap/IProviderNode.java @@ -0,0 +1,27 @@ +package net.corechg.mc.transit.network.system.swap; + +import net.corechg.mc.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 + * + * @param requester The object requesting the Acceptor + * @param group + * @return boolean + */ + public boolean linkAcceptor(IAcceptorNode requestor, String group); + + + /** Unlink a provider from the acceptor + * + * @param requestor + * @return + */ + public boolean unlinkAcceptor(IAcceptorNode requestor); + +} diff --git a/src/main/java/net/corechg/mc/transit/type/TFluid.java b/src/main/java/net/corechg/mc/transit/type/TFluid.java new file mode 100644 index 0000000..9f00a9b --- /dev/null +++ b/src/main/java/net/corechg/mc/transit/type/TFluid.java @@ -0,0 +1,33 @@ +package net.corechg.mc.transit.type; + +import net.minecraft.fluid.Fluid; + +/** Units of fluid. + * @author Kyle Gunger + */ +public class TFluid { + private Fluid fluid; + private Number millibuckets; + + /** Constructor + * + * @param f Fluid stored (Water/Lava/etc.) + * @param mb Count of fluid (mB) + */ + public TFluid(Fluid f, Number mb) { + fluid = f; + millibuckets = mb; + } + + /** Get the fluid stored. + */ + public Fluid getFluid() { + return fluid; + } + + /** Get the millibuckets stored. + */ + public Number getMilliBuckets() { + return millibuckets; + } +} \ No newline at end of file diff --git a/src/main/java/net/corechg/mc/transit/type/TMana.java b/src/main/java/net/corechg/mc/transit/type/TMana.java new file mode 100644 index 0000000..16983b7 --- /dev/null +++ b/src/main/java/net/corechg/mc/transit/type/TMana.java @@ -0,0 +1,31 @@ +package net.corechg.mc.transit.type; + +/** Units of mana. + * @author Kyle Gunger + */ +public class TMana { + private String type; + private Number count; + + /** Constructor + * + * @param t Type of mana (Fire/Water/Dark/Light/etc.) leave empty string for an untyped mana system. + * @param ct Count of mana + */ + public TMana(String t, Number ct) { + type = t; + count = ct; + } + + /** Get the mana type. + */ + public String getType() { + return type; + } + + /** Get the mana stored. + */ + public Number getCount() { + return count; + } +} diff --git a/src/main/java/net/corechg/mc/transit/type/Type.java b/src/main/java/net/corechg/mc/transit/type/Type.java new file mode 100644 index 0000000..7ac670e --- /dev/null +++ b/src/main/java/net/corechg/mc/transit/type/Type.java @@ -0,0 +1,66 @@ +package net.corechg.mc.transit.type; + +import net.corechg.mc.transit.network.packet.*; + +/**@author Kyle Gunger + * + * @param T The type of object transfered by packets of this type + */ +public class Type +{ + protected final String typeID; + protected final String groupID; + + public Type(String tID, String gID) + { + typeID = tID; + groupID = gID; + } + + /** Return the packet's data formatted in the group's base type. + * If creating a new type, extend this class and override this function. + * + * @param packet The packet (of this type) + * @param group The group asking for the conversion + * @return The packet's data in the default type + */ + public T toBase(IStaticPacket packet, String group) + { + return packet.getData(); + } + + /** Create a packet which has the current type from the data in the base type. + * If creating a new type, extend this class and override this function. + * + * @param base The base data + * @param group The group that the data comes from + * @return IStaticPacket The packet + */ + public IStaticPacket fromBase(T base, String group) + { + return new StaticPacket(base, this); + } + + /** The type identifier. Gives the normal type identity of the type. + * + * @return String + */ + public final String getType() + { + return typeID; + } + + /** The group identifier. Gives the normal group identity of the type. + * + * @return String + */ + public final String getGroup() + { + return groupID; + } + + @Override + public final String toString() { + return groupID + ":" + typeID; + } +} diff --git a/src/main/java/net/corechg/mc/transit/type/group/GroupRegistry.java b/src/main/java/net/corechg/mc/transit/type/group/GroupRegistry.java new file mode 100644 index 0000000..2d0d17f --- /dev/null +++ b/src/main/java/net/corechg/mc/transit/type/group/GroupRegistry.java @@ -0,0 +1,56 @@ +package net.corechg.mc.transit.type.group; + +import java.util.ArrayList; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import net.corechg.mc.transit.type.Type; + +public final class GroupRegistry { + private static final ArrayList> GROUPS = new ArrayList>(0); + + private static final Logger LOG = LogManager.getFormatterLogger("Transit|GroupRegistry"); + + private GroupRegistry() {} + + public static final boolean addGroup(TypeGroup group) + { + for(TypeGroup g : GROUPS) + { + if(g.getGroup().equals(group.getGroup())) + { + 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 + " to the registry."); + return true; + } + + @SuppressWarnings("unchecked") + public static final TypeGroup groupByID(String groupID) + { + for(TypeGroup g : GROUPS) + { + if(g.getGroup().equals(groupID)){ + try{ + return (TypeGroup) g; + }catch(ClassCastException e) { + return null; + } + } + } + + return null; + + } + + public static final Type typeByIdentity(String groupID, String typeID) + { + return GroupRegistry.groupByID(groupID).getType(typeID); + } + +} diff --git a/src/main/java/net/corechg/mc/transit/type/group/TypeGroup.java b/src/main/java/net/corechg/mc/transit/type/group/TypeGroup.java new file mode 100644 index 0000000..4717119 --- /dev/null +++ b/src/main/java/net/corechg/mc/transit/type/group/TypeGroup.java @@ -0,0 +1,267 @@ +package net.corechg.mc.transit.type.group; + +import java.util.ArrayList; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import net.corechg.mc.transit.network.packet.*; +import net.corechg.mc.transit.type.Type; + +/** + * @author Kyle Gunger + * @param The base object which all grouped Types should convert between. + */ +public class TypeGroup +{ + // The base Type (provides the group's identifier) + private Type baseType; + + // The list of types. + private final ArrayList> TYPES = new ArrayList>(0); + + // Logger for events in the TypeGroup. + private static final Logger LOG = LogManager.getFormatterLogger("Transit|Group"); + + + public TypeGroup(Type base) + { + baseType = base; + addType(base); + } + + + // Type management + + /** Add a Type to the TypeGroup. + * The Type must have a group-type combo not already found in this TypeGroup. + * Returns {@code true} if the group was added. + * + * @param type The Type to add + * @return + */ + public boolean addType(Type type) + { + if(!isInGroup(type)) + { + TYPES.add(type); + LOG.info("Added type " + type + " to group " + getGroup()); + return true; + } + + LOG.info("Failed to add type " + type + " to group " + getGroup() + ". Was the type already added?"); + return false; + } + + /** Remove a Type from the TypeGroup. + * + * @param type The Type to remove + * @return + */ + public boolean removeType(Type type) + { + if(type.equals(baseType)) { + 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)) + " from group " + getGroup()); + return true; + } + + 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; + } + + /** Remove a type from the group based on it's group-type identifier. + * + * @param type + * @return + */ + 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.toString() == groupID + ":" + typeID) + { + LOG.info("Removed type " + TYPES.remove(TYPES.indexOf(type)) + " from group " + getGroup()); + return true; + } + } + + LOG.warn("[WARN] Failed to remove type " + groupID + ":" + typeID + " from group " + getGroup() + ". Are we sure that the type was added to the group first?"); + return false; + } + + /** Remove a type from the group based on it's group-type identifier. + * + * @param type + * @return + */ + public boolean removeType(String typeID) + { + return removeType(getGroup(), typeID); + } + + + // Check if a type is in the group + + /**Check if the type is in the group + * + * @param type + * @return boolean + */ + public boolean isInGroup(Type type) + { + for(Type t : TYPES) + { + if(t.equals(type)) return true; + } + return false; + } + + /**Check if the type is in the group + * + * @param groupID + * @param typeID + * @return boolean + */ + public boolean isInGroup(String groupID, String typeID) + { + for(Type t : TYPES) + { + if(t.toString() == groupID + ":" + typeID) return true; + } + return false; + } + + /**Check if the type is in the group + * + * @param typeID + * @return boolean + */ + public boolean isInGroup(String typeID) + { + return isInGroup(getGroup(), typeID); + } + + // Get a type in the group + + /**Get the type from the group + * + * @param groupID The ID of the group the type is originally from + * @param typeID The ID of the type + * @return Type + */ + public Type getType(String groupID, String typeID) + { + for(Type t : TYPES) + { + if(t.toString() == groupID + ":" + typeID) return t; + } + + return null; + } + + /**Get the type from the group + * + * @param typeID The ID of the type + * @return Type + */ + public Type getType(String typeID) + { + return getType(getGroup(), typeID); + } + + + // Type conversion + + /** Actually convert the packet + * + * @param packet + * @param type + * @return + */ + protected IStaticPacket convertPacketRaw(IStaticPacket packet, Type type) + { + return type.fromBase(packet.getType().toBase(packet, getGroup()), getGroup()); + } + + /**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 + * @return Packet + */ + public IStaticPacket convertPacket(IStaticPacket packet, Type type) + { + if(isInGroup(packet.getType()) && isInGroup(type)) + { + return convertPacketRaw(packet, type); + } + + return null; + } + + /**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 + * @param typeID The typeID of the Type to convert to + * @return Packet + */ + public IStaticPacket convertPacket(IStaticPacket packet, String groupID, String typeID) + { + Type toType = getType(groupID, typeID); + if(toType != null) + { + return convertPacketRaw(packet, toType); + } + + return null; + } + + /**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 + * @return Packet + */ + public IStaticPacket convertPacket(IStaticPacket packet, String typeID) + { + Type toType = getType(typeID); + if(toType != null) + { + return convertPacketRaw(packet, toType); + } + + return null; + } + + /** The group identifier. Given by the Base Group + * @return String + */ + public final String getGroup() + { + return baseType.getGroup(); + } + + /** The base group type + * @return Type + */ + public final Type getBase() { + return baseType; + } + + @Override + public final String toString() { + return this.getGroup(); + } +} diff --git a/src/main/java/net/corechg/mc/transit/type/group/simple/SimpleGroups.java b/src/main/java/net/corechg/mc/transit/type/group/simple/SimpleGroups.java new file mode 100644 index 0000000..73e0df7 --- /dev/null +++ b/src/main/java/net/corechg/mc/transit/type/group/simple/SimpleGroups.java @@ -0,0 +1,32 @@ +package net.corechg.mc.transit.type.group.simple; + +import net.minecraft.item.ItemStack; +import net.corechg.mc.transit.type.group.*; +import net.corechg.mc.transit.type.simple.SimpleTypes; +import net.corechg.mc.transit.type.*; + +public final class SimpleGroups { + /** Transfers energy. Basic unit is TJoule (Transit Joule). + */ + public static final TypeGroup ENERGY_GROUP = new TypeGroup(SimpleTypes.TransitJoule); + + /** Transfers mana. Basic unit is TMana (Transit Mana). + */ + public static final TypeGroup MANA_GROUP = new TypeGroup(SimpleTypes.TransitMana); + + /** Transfers items. Basic type is ItemStack. + */ + public static final TypeGroup ITEM_GROUP = new TypeGroup(SimpleTypes.Item); + + /** Transfers fluids. Basic unit is TFluid. + */ + public static final TypeGroup FLUID_GROUP = new TypeGroup(SimpleTypes.Fluid); + + public static final void init() + { + GroupRegistry.addGroup(ENERGY_GROUP); + GroupRegistry.addGroup(MANA_GROUP); + GroupRegistry.addGroup(ITEM_GROUP); + GroupRegistry.addGroup(FLUID_GROUP); + } +} diff --git a/src/main/java/net/corechg/mc/transit/type/simple/SimpleTypes.java b/src/main/java/net/corechg/mc/transit/type/simple/SimpleTypes.java new file mode 100644 index 0000000..79ee9a8 --- /dev/null +++ b/src/main/java/net/corechg/mc/transit/type/simple/SimpleTypes.java @@ -0,0 +1,22 @@ +package net.corechg.mc.transit.type.simple; + +import net.minecraft.item.ItemStack; +import net.corechg.mc.transit.type.*; + +public final class SimpleTypes { + /** Transfers energy. Energy is stored as a numeric, base value is TJoule (TransitJoule) + */ + public static final Type TransitJoule = new Type("TJoule", "ENERGY"); + + /** Transfers mana. TMana stores mana count and type. + */ + public static final Type TransitMana = new Type("TMana", "MANA"); + + /** Transfers items in a itemstack. + */ + public static final Type Item = new Type("Item", "ITEM"); + + /** Transfers fluid. TFluid stores fluid and mB. + */ + public static final Type Fluid = new Type("Fluid", "FLUID"); +} diff --git a/src/main/java/net/corechg/transit/Transit.java b/src/main/java/net/corechg/transit/Transit.java deleted file mode 100644 index 3cf4917..0000000 --- a/src/main/java/net/corechg/transit/Transit.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 Transit implements ModInitializer { - - @Override - public void onInitialize() { - SimpleGroups.init(); - } - -} diff --git a/src/main/java/net/corechg/transit/network/packet/IStaticPacket.java b/src/main/java/net/corechg/transit/network/packet/IStaticPacket.java deleted file mode 100644 index 74d5110..0000000 --- a/src/main/java/net/corechg/transit/network/packet/IStaticPacket.java +++ /dev/null @@ -1,23 +0,0 @@ -package net.corechg.transit.network.packet; - -import net.corechg.transit.type.Type; - -/** Interface describing an unchanging packet. - * @author Kyle Gunger - * - * @param The data type (Object) that the packet transfers. - */ -public interface IStaticPacket -{ - /**Get the packet's data. - * - * @return The packet's data - */ - public D getData(); - - /**Get the packet's type. - * - * @return IType<> The type of the packet - */ - public Type getType(); -} \ No newline at end of file diff --git a/src/main/java/net/corechg/transit/network/packet/MetaPacket.java b/src/main/java/net/corechg/transit/network/packet/MetaPacket.java deleted file mode 100644 index e043aa1..0000000 --- a/src/main/java/net/corechg/transit/network/packet/MetaPacket.java +++ /dev/null @@ -1,35 +0,0 @@ -package net.corechg.transit.network.packet; - -import net.corechg.transit.type.Type; - -/** Static packet with extra data attached. - * @author Kyle Gunger - * - * @param The data type (Object) that the packet transfers - * @param The type of metadata -*/ -public class MetaPacket extends StaticPacket -{ - private M metaData; - - /** Constructor - * - * @param dat The data to store - * @param t The Type of the data - * @param meta The metadata to store - */ - public MetaPacket(D dat, Type t, M meta) - { - super(dat, t); - metaData = meta; - } - - /** Get the metadata of the packet. - * - * @return The packet's metadata - */ - public M getMetaData() - { - return metaData; - } -} diff --git a/src/main/java/net/corechg/transit/network/packet/StaticPacket.java b/src/main/java/net/corechg/transit/network/packet/StaticPacket.java deleted file mode 100644 index 2596a8f..0000000 --- a/src/main/java/net/corechg/transit/network/packet/StaticPacket.java +++ /dev/null @@ -1,36 +0,0 @@ -package net.corechg.transit.network.packet; - -import net.corechg.transit.type.Type; - -/** Simple packet which stores an unchanging value. - * @author Kyle Gunger - * - * @param The data type (Object) that the packet transfers. - */ -public class StaticPacket implements IStaticPacket -{ - private D data; - private Type type; - - /** Constructor. Stores the given data and uses the given type. - * - * @param dat The packet's data - * @param t The packet's type - */ - public StaticPacket(D dat, Type t) - { - data = dat; - type = t; - } - - @Override - public D getData() - { - return data; - } - - @Override - public Type getType() { - return type; - } -} \ No newline at end of file diff --git a/src/main/java/net/corechg/transit/network/packet/dynamic/DynamicPacket.java b/src/main/java/net/corechg/transit/network/packet/dynamic/DynamicPacket.java deleted file mode 100644 index 73f3669..0000000 --- a/src/main/java/net/corechg/transit/network/packet/dynamic/DynamicPacket.java +++ /dev/null @@ -1,43 +0,0 @@ -package net.corechg.transit.network.packet.dynamic; - -import net.corechg.transit.type.Type; - -/** - * Simple packet which stores a fluid value. - * - * @author Kyle Gunger - * - * @param The data type (Object) that the packet transfers - */ -public class DynamicPacket implements IDynamicPacket { - private D data; - private Type type; - - /** Constructor. Stores the given data and uses the given type. - * - * @param dat The packet's data - * @param t The packet's type - */ - public DynamicPacket(D dat, Type t) - { - data = dat; - type = t; - } - - @Override - public D getData() - { - return data; - } - - @Override - public void setData(D dat) - { - data = dat; - } - - @Override - public Type getType() { - return type; - } -} \ No newline at end of file diff --git a/src/main/java/net/corechg/transit/network/packet/dynamic/IDynamicPacket.java b/src/main/java/net/corechg/transit/network/packet/dynamic/IDynamicPacket.java deleted file mode 100644 index 6cf3018..0000000 --- a/src/main/java/net/corechg/transit/network/packet/dynamic/IDynamicPacket.java +++ /dev/null @@ -1,16 +0,0 @@ -package net.corechg.transit.network.packet.dynamic; - -import net.corechg.transit.network.packet.IStaticPacket; - -/** Interface describing a fluid packet. - * @author Kyle Gunger - * - * @param The data type (Object) that the packet transfers - */ -public interface IDynamicPacket extends IStaticPacket{ - /**Set the packet's data. - * - * @return The packet's data - */ - public void setData(D dat); -} \ No newline at end of file diff --git a/src/main/java/net/corechg/transit/network/packet/dynamic/MetaDynamicPacket.java b/src/main/java/net/corechg/transit/network/packet/dynamic/MetaDynamicPacket.java deleted file mode 100644 index 50418b9..0000000 --- a/src/main/java/net/corechg/transit/network/packet/dynamic/MetaDynamicPacket.java +++ /dev/null @@ -1,44 +0,0 @@ -package net.corechg.transit.network.packet.dynamic; - -import net.corechg.transit.type.Type; - -/** Static packet with extra data attached. - * @author Kyle Gunger - * - * @param The data type (Object) that the packet transfers - * @param The type of metadata -*/ -public class MetaDynamicPacket extends DynamicPacket -{ - private M metaData; - - /** Constructor - * - * @param dat The data to store - * @param t The Type of the data - * @param meta The metadata to store - */ - public MetaDynamicPacket(D dat, Type t, M meta) - { - super(dat, t); - metaData = meta; - } - - /** Get the metadata of the packet. - * - * @return The packet's metadata - */ - public M getMetaData() - { - return metaData; - } - - /** Set the metadata of the packet. - * - * @param meta The packet's new metadata - */ - public void setMetaData(M meta) - { - metaData = meta; - } -} diff --git a/src/main/java/net/corechg/transit/network/system/INode.java b/src/main/java/net/corechg/transit/network/system/INode.java deleted file mode 100644 index 94ec308..0000000 --- a/src/main/java/net/corechg/transit/network/system/INode.java +++ /dev/null @@ -1,53 +0,0 @@ -package net.corechg.transit.network.system; - -/** - * @author Kyle Gunger - * @apiNote A node inside or outside a system. - */ -public interface INode -{ - - /**Returns true if the group given is used by the node - * - * @param groupID the group to querry - * @return bool - */ - public boolean hasGroup(String groupID); - - - /**Get the system managing the node or {@code null} if there isn't one - * - * @return System - */ - public ISystem getSystem(); - - - /** Get the data of one of the TypeGroups the Node supports - * - * @param groupID - * @return - */ - public Object getData(String groupID); - - - /** Set the group data for the node - * - * @param dat - * @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 deleted file mode 100644 index 693a3ed..0000000 --- a/src/main/java/net/corechg/transit/network/system/ISystem.java +++ /dev/null @@ -1,15 +0,0 @@ -package net.corechg.transit.network.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 -{ - /**The nodes stored by the system - * - * @return INode[] - */ - public INode[] getNodes(); -} 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 deleted file mode 100644 index 84765ac..0000000 --- a/src/main/java/net/corechg/transit/network/system/swap/IAcceptorNode.java +++ /dev/null @@ -1,43 +0,0 @@ -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 -{ - - /** Link another node as a provider - * - * @param requester The object to be a provider - * @param group - * @return - */ - public boolean linkProvider(INode requester, String group); - - - /** Unlink a provider from the acceptor - * - * @param toUnlink - * @return - */ - public boolean unlinkProvider(INode toUnlink); - - - /** - * @return Node[] - */ - public IProviderNode[] getProviders(); - - - /** Accept a packet from a provider - * - * @param packet - * @param group - * @return - */ - public boolean accept(IStaticPacket packet, String group); -} 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 deleted file mode 100644 index 5fd9908..0000000 --- a/src/main/java/net/corechg/transit/network/system/swap/IProviderNode.java +++ /dev/null @@ -1,33 +0,0 @@ -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 - * - * @param requester The object requesting the Acceptor - * @param group - * @return boolean - */ - public boolean linkAcceptor(INode requester, String group); - - - /** Unlink a provider from the acceptor - * - * @param toUnlink - * @return - */ - public boolean unlinkAcceptor(INode toUnlink); - - - /** - * @return Node[] - */ - public IAcceptorNode[] getAcceptors(); - -} diff --git a/src/main/java/net/corechg/transit/type/TFluid.java b/src/main/java/net/corechg/transit/type/TFluid.java deleted file mode 100644 index 6886ab2..0000000 --- a/src/main/java/net/corechg/transit/type/TFluid.java +++ /dev/null @@ -1,33 +0,0 @@ -package net.corechg.transit.type; - -import net.minecraft.fluid.Fluid; - -/** Units of fluid. - * @author Kyle Gunger - */ -public class TFluid { - private Fluid fluid; - private Number millibuckets; - - /** Constructor - * - * @param f Fluid stored (Water/Lava/etc.) - * @param mb Count of fluid (mB) - */ - public TFluid(Fluid f, Number mb) { - fluid = f; - millibuckets = mb; - } - - /** Get the fluid stored. - */ - public Fluid getFluid() { - return fluid; - } - - /** Get the millibuckets stored. - */ - public Number getMilliBuckets() { - return millibuckets; - } -} \ No newline at end of file diff --git a/src/main/java/net/corechg/transit/type/TMana.java b/src/main/java/net/corechg/transit/type/TMana.java deleted file mode 100644 index 1a176fc..0000000 --- a/src/main/java/net/corechg/transit/type/TMana.java +++ /dev/null @@ -1,31 +0,0 @@ -package net.corechg.transit.type; - -/** Units of mana. - * @author Kyle Gunger - */ -public class TMana { - private String type; - private Number count; - - /** Constructor - * - * @param t Type of mana (Fire/Water/Dark/Light/etc.) - * @param ct Count of mana - */ - public TMana(String t, Number ct) { - type = t; - count = ct; - } - - /** Get the mana type. - */ - public String getType() { - return type; - } - - /** Get the mana stored. - */ - public Number getCount() { - return count; - } -} diff --git a/src/main/java/net/corechg/transit/type/Type.java b/src/main/java/net/corechg/transit/type/Type.java deleted file mode 100644 index 3940f3f..0000000 --- a/src/main/java/net/corechg/transit/type/Type.java +++ /dev/null @@ -1,67 +0,0 @@ -package net.corechg.transit.type; - -import net.corechg.transit.network.packet.IStaticPacket; -import net.corechg.transit.network.packet.StaticPacket; - -/**@author Kyle Gunger - * - * @param T The type of object transfered by packets of this type - */ -public class Type -{ - protected final String typeID; - protected final String groupID; - - public Type(String tID, String gID) - { - typeID = tID; - groupID = gID; - } - - /** Return the packet's data formatted in the group's base type. - * If creating a new type, extend this class and override this function. - * - * @param packet The packet (of this type) - * @param group The group asking for the conversion - * @return The packet's data in the default type - */ - public T toBase(IStaticPacket packet, String group) - { - return packet.getData(); - } - - /** Create a packet which has the current type from the data in the base type. - * If creating a new type, extend this class and override this function. - * - * @param base The base data - * @param group The group that the data comes from - * @return IStaticPacket The packet - */ - public IStaticPacket fromBase(T base, String group) - { - return new StaticPacket(base, this); - } - - /** The type identifier. Gives the normal type identity of the type. - * - * @return String - */ - public final String getType() - { - return typeID; - } - - /** The group identifier. Gives the normal group identity of the type. - * - * @return String - */ - public final String getGroup() - { - 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 deleted file mode 100644 index 0b04913..0000000 --- a/src/main/java/net/corechg/transit/type/group/GroupRegistry.java +++ /dev/null @@ -1,56 +0,0 @@ -package net.corechg.transit.type.group; - -import java.util.ArrayList; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import net.corechg.transit.type.Type; - -public class GroupRegistry { - private static final ArrayList> GROUPS = new ArrayList>(0); - - private static final Logger LOG = LogManager.getFormatterLogger("Transit|GroupRegistry"); - - private GroupRegistry() {} - - public static final boolean addGroup(TypeGroup group) - { - for(TypeGroup g : GROUPS) - { - if(g.getGroup().equals(group.getGroup())) - { - 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 + " to the registry."); - return true; - } - - @SuppressWarnings("unchecked") - public static final TypeGroup groupByID(String groupID) - { - for(TypeGroup g : GROUPS) - { - if(g.getGroup().equals(groupID)){ - try{ - return (TypeGroup) g; - }catch(ClassCastException e) { - return null; - } - } - } - - return null; - - } - - public static final Type typeByIdentity(String groupID, String typeID) - { - return GroupRegistry.groupByID(groupID).getType(typeID); - } - -} diff --git a/src/main/java/net/corechg/transit/type/group/TypeGroup.java b/src/main/java/net/corechg/transit/type/group/TypeGroup.java deleted file mode 100644 index eecf6d4..0000000 --- a/src/main/java/net/corechg/transit/type/group/TypeGroup.java +++ /dev/null @@ -1,267 +0,0 @@ -package net.corechg.transit.type.group; - -import java.util.ArrayList; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import net.corechg.transit.network.packet.*; -import net.corechg.transit.type.Type; - -/** - * @author Kyle Gunger - * @param The base object which all grouped Types should convert between. - */ -public class TypeGroup -{ - // The base Type (provides the group's identifier) - private Type baseType; - - // The list of types. - private final ArrayList> TYPES = new ArrayList>(0); - - // Logger for events in the TypeGroup. - private static final Logger LOG = LogManager.getFormatterLogger("Transit|Group"); - - - public TypeGroup(Type base) - { - baseType = base; - addType(base); - } - - - // Type management - - /** Add a Type to the TypeGroup. - * The Type must have a group-type combo not already found in this TypeGroup. - * Returns {@code true} if the group was added. - * - * @param type The Type to add - * @return - */ - public boolean addType(Type type) - { - if(!isInGroup(type)) - { - TYPES.add(type); - LOG.info("Added type " + type + " to group " + getGroup()); - return true; - } - - LOG.info("Failed to add type " + type + " to group " + getGroup() + ". Was the type already added?"); - return false; - } - - /** Remove a Type from the TypeGroup. - * - * @param type The Type to remove - * @return - */ - public boolean removeType(Type type) - { - if(type.equals(baseType)) { - 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)) + " from group " + getGroup()); - return true; - } - - 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; - } - - /** Remove a type from the group based on it's group-type identifier. - * - * @param type - * @return - */ - 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.toString() == groupID + ":" + typeID) - { - LOG.info("Removed type " + TYPES.remove(TYPES.indexOf(type)) + " from group " + getGroup()); - return true; - } - } - - LOG.warn("[WARN] Failed to remove type " + groupID + ":" + typeID + " from group " + getGroup() + ". Are we sure that the type was added to the group first?"); - return false; - } - - /** Remove a type from the group based on it's group-type identifier. - * - * @param type - * @return - */ - public boolean removeType(String typeID) - { - return removeType(getGroup(), typeID); - } - - - // Check if a type is in the group - - /**Check if the type is in the group - * - * @param type - * @return boolean - */ - public boolean isInGroup(Type type) - { - for(Type t : TYPES) - { - if(t.equals(type)) return true; - } - return false; - } - - /**Check if the type is in the group - * - * @param groupID - * @param typeID - * @return boolean - */ - public boolean isInGroup(String groupID, String typeID) - { - for(Type t : TYPES) - { - if(t.toString() == groupID + ":" + typeID) return true; - } - return false; - } - - /**Check if the type is in the group - * - * @param typeID - * @return boolean - */ - public boolean isInGroup(String typeID) - { - return isInGroup(getGroup(), typeID); - } - - // Get a type in the group - - /**Get the type from the group - * - * @param groupID The ID of the group the type is originally from - * @param typeID The ID of the type - * @return Type - */ - public Type getType(String groupID, String typeID) - { - for(Type t : TYPES) - { - if(t.toString() == groupID + ":" + typeID) return t; - } - - return null; - } - - /**Get the type from the group - * - * @param typeID The ID of the type - * @return Type - */ - public Type getType(String typeID) - { - return getType(getGroup(), typeID); - } - - - // Type conversion - - /** Actually convert the packet - * - * @param packet - * @param type - * @return - */ - protected IStaticPacket convertPacketRaw(IStaticPacket packet, Type type) - { - return type.fromBase(packet.getType().toBase(packet, getGroup()), getGroup()); - } - - /**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 - * @return Packet - */ - public IStaticPacket convertPacket(IStaticPacket packet, Type type) - { - if(isInGroup(packet.getType()) && isInGroup(type)) - { - return convertPacketRaw(packet, type); - } - - return null; - } - - /**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 - * @param typeID The typeID of the Type to convert to - * @return Packet - */ - public IStaticPacket convertPacket(IStaticPacket packet, String groupID, String typeID) - { - Type toType = getType(groupID, typeID); - if(toType != null) - { - return convertPacketRaw(packet, toType); - } - - return null; - } - - /**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 - * @return Packet - */ - public IStaticPacket convertPacket(IStaticPacket packet, String typeID) - { - Type toType = getType(typeID); - if(toType != null) - { - return convertPacketRaw(packet, toType); - } - - return null; - } - - /** The group identifier. Given by the Base Group - * @return String - */ - public final String getGroup() - { - return baseType.getGroup(); - } - - /** The base group type - * @return Type - */ - public final Type getBase() { - return baseType; - } - - @Override - public final String toString() { - return this.getGroup(); - } -} diff --git a/src/main/java/net/corechg/transit/type/group/simple/SimpleGroups.java b/src/main/java/net/corechg/transit/type/group/simple/SimpleGroups.java deleted file mode 100644 index ce39fc1..0000000 --- a/src/main/java/net/corechg/transit/type/group/simple/SimpleGroups.java +++ /dev/null @@ -1,33 +0,0 @@ -package net.corechg.transit.type.group.simple; - -import net.minecraft.item.ItemStack; -import net.corechg.transit.type.group.GroupRegistry; -import net.corechg.transit.type.group.TypeGroup; -import net.corechg.transit.type.simple.SimpleTypes; -import net.corechg.transit.type.*; - -public final class SimpleGroups { - /** Transfers energy. Basic unit is TJoule (Transit Joule). - */ - public static final TypeGroup ENERGY_GROUP = new TypeGroup(SimpleTypes.TransitJoule); - - /** Transfers mana. Basic unit is TMana (Transit Mana). - */ - public static final TypeGroup MANA_GROUP = new TypeGroup(SimpleTypes.TransitMana); - - /** Transfers items. Basic type is ItemStack. - */ - public static final TypeGroup ITEM_GROUP = new TypeGroup(SimpleTypes.Item); - - /** Transfers fluids. Basic unit is TFluid. - */ - public static final TypeGroup FLUID_GROUP = new TypeGroup(SimpleTypes.Fluid); - - public static final void init() - { - GroupRegistry.addGroup(ENERGY_GROUP); - GroupRegistry.addGroup(MANA_GROUP); - GroupRegistry.addGroup(ITEM_GROUP); - GroupRegistry.addGroup(FLUID_GROUP); - } -} diff --git a/src/main/java/net/corechg/transit/type/simple/SimpleTypes.java b/src/main/java/net/corechg/transit/type/simple/SimpleTypes.java deleted file mode 100644 index f608bdd..0000000 --- a/src/main/java/net/corechg/transit/type/simple/SimpleTypes.java +++ /dev/null @@ -1,22 +0,0 @@ -package net.corechg.transit.type.simple; - -import net.minecraft.item.ItemStack; -import net.corechg.transit.type.*; - -public final class SimpleTypes { - /** Transfers energy. Energy is stored as a numeric, base value is TJoule (TransitJoule) - */ - public static final Type TransitJoule = new Type("TJoule", "ENERGY"); - - /** Transfers mana. TMana stores mana count and type. - */ - public static final Type TransitMana = new Type("TMana", "MANA"); - - /** Transfers items in a itemstack. - */ - public static final Type Item = new Type("Item", "ITEM"); - - /** Transfers fluid. TFluid stores fluid and mB. - */ - public static final Type Fluid = new Type("Fluid", "FLUID"); -} -- cgit v1.2.3