From df044930bca4252ff6e4814c654a612c6aee2136 Mon Sep 17 00:00:00 2001 From: Kyle Gunger Date: Wed, 20 Nov 2019 12:45:16 -0500 Subject: [0.1.7 REWRITE] Codebase overhaul. ~ Codebase split into two sub-packages ~ net.transit.network for transfering between objects ~ net.transit.type for type registering and conversion + Added new interfaces (INode and ISystem) + More documentation + (Kinda) Working build - Removed unnessairy interfaces (IGenerator and IConsumer) - Removed base types ~ Restructured type system --- src/main/java/net/transit/InitTransit.java | 15 +++ src/main/java/net/transit/impl/IAcceptor.java | 13 -- src/main/java/net/transit/impl/IConsumer.java | 8 -- src/main/java/net/transit/impl/IGenerator.java | 8 -- src/main/java/net/transit/impl/IProvider.java | 17 --- .../net/transit/network/packet/ArrayPacket.java | 45 +++++++ .../java/net/transit/network/packet/IPacket.java | 23 ++++ .../net/transit/network/packet/MetaPacket.java | 33 +++++ .../net/transit/network/packet/StaticPacket.java | 25 ++++ .../java/net/transit/network/swap/IAcceptor.java | 31 +++++ .../java/net/transit/network/swap/IProvider.java | 37 ++++++ .../java/net/transit/network/system/INode.java | 50 ++++++++ .../java/net/transit/network/system/ISystem.java | 17 +++ src/main/java/net/transit/packet/ArrayPacket.java | 37 ------ src/main/java/net/transit/packet/IPacket.java | 6 - src/main/java/net/transit/packet/StaticPacket.java | 16 --- src/main/java/net/transit/type/BaseType.java | 14 --- src/main/java/net/transit/type/Type.java | 51 +++++--- .../java/net/transit/type/group/GroupRegistry.java | 51 ++++++++ .../java/net/transit/type/group/TypeGroup.java | 137 +++++++++++++++++++++ .../net/transit/type/group/simple/EnergyGroup.java | 10 ++ .../net/transit/type/group/simple/FluidGroup.java | 11 ++ .../net/transit/type/group/simple/ItemGroup.java | 11 ++ .../net/transit/type/group/simple/ManaGroup.java | 10 ++ .../transit/type/group/simple/SimpleGroups.java | 26 ++++ .../java/net/transit/type/simple/EnergyType.java | 11 ++ .../java/net/transit/type/simple/FluidType.java | 11 ++ .../java/net/transit/type/simple/ItemType.java | 11 ++ .../java/net/transit/type/simple/ManaType.java | 10 ++ .../java/net/transit/type/simple/SimpleTypes.java | 27 ++++ .../java/net/transit/type/typebase/MetaBase.java | 28 ----- .../java/net/transit/type/typebase/NumberBase.java | 20 --- .../java/net/transit/type/typebase/StringBase.java | 20 --- .../java/net/transit/type/typegroup/TypeGroup.java | 53 -------- .../net/transit/type/typegroup/TypeRegister.java | 44 ------- src/main/resources/fabric.mod.json | 6 +- 36 files changed, 644 insertions(+), 299 deletions(-) create mode 100644 src/main/java/net/transit/InitTransit.java delete mode 100644 src/main/java/net/transit/impl/IAcceptor.java delete mode 100644 src/main/java/net/transit/impl/IConsumer.java delete mode 100644 src/main/java/net/transit/impl/IGenerator.java delete mode 100644 src/main/java/net/transit/impl/IProvider.java create mode 100644 src/main/java/net/transit/network/packet/ArrayPacket.java create mode 100644 src/main/java/net/transit/network/packet/IPacket.java create mode 100644 src/main/java/net/transit/network/packet/MetaPacket.java create mode 100644 src/main/java/net/transit/network/packet/StaticPacket.java create mode 100644 src/main/java/net/transit/network/swap/IAcceptor.java create mode 100644 src/main/java/net/transit/network/swap/IProvider.java create mode 100644 src/main/java/net/transit/network/system/INode.java create mode 100644 src/main/java/net/transit/network/system/ISystem.java delete mode 100644 src/main/java/net/transit/packet/ArrayPacket.java delete mode 100644 src/main/java/net/transit/packet/IPacket.java delete mode 100644 src/main/java/net/transit/packet/StaticPacket.java delete mode 100644 src/main/java/net/transit/type/BaseType.java create mode 100644 src/main/java/net/transit/type/group/GroupRegistry.java create mode 100644 src/main/java/net/transit/type/group/TypeGroup.java create mode 100644 src/main/java/net/transit/type/group/simple/EnergyGroup.java create mode 100644 src/main/java/net/transit/type/group/simple/FluidGroup.java create mode 100644 src/main/java/net/transit/type/group/simple/ItemGroup.java create mode 100644 src/main/java/net/transit/type/group/simple/ManaGroup.java create mode 100644 src/main/java/net/transit/type/group/simple/SimpleGroups.java create mode 100644 src/main/java/net/transit/type/simple/EnergyType.java create mode 100644 src/main/java/net/transit/type/simple/FluidType.java create mode 100644 src/main/java/net/transit/type/simple/ItemType.java create mode 100644 src/main/java/net/transit/type/simple/ManaType.java create mode 100644 src/main/java/net/transit/type/simple/SimpleTypes.java delete mode 100644 src/main/java/net/transit/type/typebase/MetaBase.java delete mode 100644 src/main/java/net/transit/type/typebase/NumberBase.java delete mode 100644 src/main/java/net/transit/type/typebase/StringBase.java delete mode 100644 src/main/java/net/transit/type/typegroup/TypeGroup.java delete mode 100644 src/main/java/net/transit/type/typegroup/TypeRegister.java (limited to 'src') diff --git a/src/main/java/net/transit/InitTransit.java b/src/main/java/net/transit/InitTransit.java new file mode 100644 index 0000000..1d4941e --- /dev/null +++ b/src/main/java/net/transit/InitTransit.java @@ -0,0 +1,15 @@ +package net.transit; + +import net.fabricmc.api.ModInitializer; +import net.transit.type.group.simple.SimpleGroups; +import net.transit.type.simple.SimpleTypes; + +public class InitTransit implements ModInitializer { + + @Override + public void onInitialize() { + SimpleGroups.initGroups(); + SimpleTypes.initTypes(); + } + +} diff --git a/src/main/java/net/transit/impl/IAcceptor.java b/src/main/java/net/transit/impl/IAcceptor.java deleted file mode 100644 index 7fe06aa..0000000 --- a/src/main/java/net/transit/impl/IAcceptor.java +++ /dev/null @@ -1,13 +0,0 @@ -package net.transit.impl; - -import net.transit.packet.IPacket; -import net.minecraft.util.math.Direction; - -public interface IAcceptor -{ - // Direction given if acceptor is a block - public boolean canAccept(Direction d); - - // Accept (or not) a provided T (should trigger ITransferEvent) - public boolean accept(IPacket provided); -} \ No newline at end of file diff --git a/src/main/java/net/transit/impl/IConsumer.java b/src/main/java/net/transit/impl/IConsumer.java deleted file mode 100644 index 7b3b070..0000000 --- a/src/main/java/net/transit/impl/IConsumer.java +++ /dev/null @@ -1,8 +0,0 @@ -package net.transit.impl; - -public interface IConsumer extends IAcceptor -{ - public boolean canConsume(); - - -} \ No newline at end of file diff --git a/src/main/java/net/transit/impl/IGenerator.java b/src/main/java/net/transit/impl/IGenerator.java deleted file mode 100644 index f69de2f..0000000 --- a/src/main/java/net/transit/impl/IGenerator.java +++ /dev/null @@ -1,8 +0,0 @@ -package net.transit.impl; - -public interface IGenerator extends IProvider -{ - public boolean canGenerate(); - - -} \ No newline at end of file diff --git a/src/main/java/net/transit/impl/IProvider.java b/src/main/java/net/transit/impl/IProvider.java deleted file mode 100644 index 94e903f..0000000 --- a/src/main/java/net/transit/impl/IProvider.java +++ /dev/null @@ -1,17 +0,0 @@ -package net.transit.impl; - -import net.transit.packet.IPacket; -import net.minecraft.util.math.Direction; - -public interface IProvider -{ - - // Direction given if provider is a block - public boolean canProvide(Direction d); - - // Provide the next T (should trigger ITransferEvent) - public IPacket provide(); - - // Retain the rejected T if the acceptor did not accept it (should trigger ITransferEvent) - public void retain(IPacket rejected); -} \ No newline at end of file diff --git a/src/main/java/net/transit/network/packet/ArrayPacket.java b/src/main/java/net/transit/network/packet/ArrayPacket.java new file mode 100644 index 0000000..9cbd300 --- /dev/null +++ b/src/main/java/net/transit/network/packet/ArrayPacket.java @@ -0,0 +1,45 @@ +package net.transit.network.packet; + +import java.util.ArrayList; + +import net.transit.type.Type; + +public class ArrayPacket implements IPacket +{ + private ArrayList arrayData; + private Type type; + + public ArrayPacket(D startValue, Type t) + { + arrayData = new ArrayList(0); + arrayData.add(startValue); + } + + public D getData() + { + if(arrayData.size() > 0) return arrayData.get(0); + return null; + } + + public void addData(D data) + { + arrayData.add(data); + } + + public D popAndShift() + { + D temp = null; + + if(arrayData.size() > 0) + { + temp = arrayData.remove(0); + } + + return temp; + } + + @Override + public Type getType() { + return type; + } +} \ No newline at end of file diff --git a/src/main/java/net/transit/network/packet/IPacket.java b/src/main/java/net/transit/network/packet/IPacket.java new file mode 100644 index 0000000..deafdf8 --- /dev/null +++ b/src/main/java/net/transit/network/packet/IPacket.java @@ -0,0 +1,23 @@ +package net.transit.network.packet; + +import net.transit.type.Type; + +/** + * @author Kyle Gunger + * + * @param The data type (Object) that the packet transfers. + */ +public interface IPacket +{ + /**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/transit/network/packet/MetaPacket.java b/src/main/java/net/transit/network/packet/MetaPacket.java new file mode 100644 index 0000000..e4cffdf --- /dev/null +++ b/src/main/java/net/transit/network/packet/MetaPacket.java @@ -0,0 +1,33 @@ +package net.transit.network.packet; + +import net.transit.type.Type; + +public class MetaPacket implements IPacket +{ + + private D data; + private M metaData; + private Type type; + + public MetaPacket(D dat, Type t, M meta) + { + data = dat; + type = t; + metaData = meta; + } + + public D getData() + { + return data; + } + + public M getMetaData() + { + return metaData; + } + + @Override + public Type getType() { + return type; + } +} diff --git a/src/main/java/net/transit/network/packet/StaticPacket.java b/src/main/java/net/transit/network/packet/StaticPacket.java new file mode 100644 index 0000000..8399041 --- /dev/null +++ b/src/main/java/net/transit/network/packet/StaticPacket.java @@ -0,0 +1,25 @@ +package net.transit.network.packet; + +import net.transit.type.Type; + +public class StaticPacket implements IPacket +{ + private D data; + private Type type; + + public StaticPacket(D dat, Type t) + { + data = dat; + type = t; + } + + public D getData() + { + return data; + } + + @Override + public Type getType() { + return type; + } +} \ No newline at end of file diff --git a/src/main/java/net/transit/network/swap/IAcceptor.java b/src/main/java/net/transit/network/swap/IAcceptor.java new file mode 100644 index 0000000..6966b9a --- /dev/null +++ b/src/main/java/net/transit/network/swap/IAcceptor.java @@ -0,0 +1,31 @@ +package net.transit.network.swap; + +import net.transit.network.packet.IPacket; + +/** + * @author Kyle Gunger + * + * @param The type of data accepted (in IPacket<> form) + */ +public interface IAcceptor +{ + /** + * @return True if the acceptor can accept packets. + */ + public boolean canAccept(); + + /** + * @param provided The packet provided. + * @return True if the acceptor accepted the packet. + */ + public boolean accept(IPacket provided); + + /** + * @return True if the acceptor has a provider assigned to it. + */ + public boolean hasProvider(); + + /**Set the provider of the acceptor. The acceptor can decide if it wants to adopt the provider. + */ + public void setProvider(IProvider provider); +} \ No newline at end of file diff --git a/src/main/java/net/transit/network/swap/IProvider.java b/src/main/java/net/transit/network/swap/IProvider.java new file mode 100644 index 0000000..03c9ca9 --- /dev/null +++ b/src/main/java/net/transit/network/swap/IProvider.java @@ -0,0 +1,37 @@ +package net.transit.network.swap; + +import net.transit.network.packet.IPacket; + +/** + * @author Kyle Gunger + * + * @param The type of data provided (in IPacket<> form) + */ +public interface IProvider +{ + /** + * @return True if the provider can provide a packet. + */ + public boolean canProvide(); + + /**Get the next packet from the provider + * + * @return IPacket<> + */ + public IPacket provide(); + + /**Retain the packet if the acceptor did not accept the packet. + * + * @param rejected The rejected packet + */ + public void retain(IPacket rejected); + + /** + * @return True if the acceptor has a provider assigned to it + */ + public boolean hasAcceptor(); + + /**Set the acceptor of the provider. The provider can decide if it wants to adopt the acceptor. + */ + public void setAcceptor(); +} \ No newline at end of file diff --git a/src/main/java/net/transit/network/system/INode.java b/src/main/java/net/transit/network/system/INode.java new file mode 100644 index 0000000..2dc3686 --- /dev/null +++ b/src/main/java/net/transit/network/system/INode.java @@ -0,0 +1,50 @@ +package net.transit.network.system; + +import net.transit.network.swap.IAcceptor; +import net.transit.network.swap.IProvider; + +/** + * @author Kyle Gunger + * @apiNote A node inside or outside a system. Provides acceptors and providers to other nodes. + */ +public interface INode +{ + /**Returns the groupIDs of groups the node provide + * + * @return String[] + */ + public String[] groupsProvided(); + + /**Get the system managing the node or {@code null} if there isn't one + * + * @return ISystem + */ + public ISystem getSystem(); + + /**Returns {@code true} if the node provides IAcceptors + * + * @return boolean + */ + public boolean isAcceptor(); + + /**Returns an IAcceptor or {@code null} depending on the requester and group + * + * @param requester The object requesting the IAcceptor + * @param group + * @return IAcceptor + */ + public IAcceptor requestAcceptor(Object requester, String group); + + /**Returns {@code true} if the node provides IProviders + * + */ + public boolean isProvider(); + + /**Returns an IProvider or {@code null} depending on the requester and group + * + * @param requester The object requesting the IProvider + * @param group + * @return IProvider + */ + public IProvider requestProvider(Object requestor, String group); +} diff --git a/src/main/java/net/transit/network/system/ISystem.java b/src/main/java/net/transit/network/system/ISystem.java new file mode 100644 index 0000000..fd2fa51 --- /dev/null +++ b/src/main/java/net/transit/network/system/ISystem.java @@ -0,0 +1,17 @@ +package net.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. + */ +public interface ISystem +{ + /**The nodes stored by the system + * + * @return INode[] + */ + public INode[] getNodes(); +} diff --git a/src/main/java/net/transit/packet/ArrayPacket.java b/src/main/java/net/transit/packet/ArrayPacket.java deleted file mode 100644 index 09ef5f1..0000000 --- a/src/main/java/net/transit/packet/ArrayPacket.java +++ /dev/null @@ -1,37 +0,0 @@ -package net.transit.packet; - -import java.util.ArrayList; - -public class ArrayPacket implements IPacket -{ - private ArrayList arrayData; - - public ArrayPacket(D startValue) - { - arrayData = new ArrayList(0); - arrayData.add(startValue); - } - - public D getData() - { - if(arrayData.size() > 0) return arrayData.get(0); - return null; - } - - public void addData(D data) - { - arrayData.add(data); - } - - public D popAndShift() - { - D temp = null; - - if(arrayData.size() > 0) - { - temp = arrayData.remove(0); - } - - return temp; - } -} \ No newline at end of file diff --git a/src/main/java/net/transit/packet/IPacket.java b/src/main/java/net/transit/packet/IPacket.java deleted file mode 100644 index 2b1753b..0000000 --- a/src/main/java/net/transit/packet/IPacket.java +++ /dev/null @@ -1,6 +0,0 @@ -package net.transit.packet; - -public interface IPacket -{ - public D getData(); -} \ No newline at end of file diff --git a/src/main/java/net/transit/packet/StaticPacket.java b/src/main/java/net/transit/packet/StaticPacket.java deleted file mode 100644 index fb11dd7..0000000 --- a/src/main/java/net/transit/packet/StaticPacket.java +++ /dev/null @@ -1,16 +0,0 @@ -package net.transit.packet; - -public class StaticPacket implements IPacket -{ - private D data; - - public StaticPacket(D dat) - { - data = dat; - } - - public D getData() - { - return data; - } -} \ No newline at end of file diff --git a/src/main/java/net/transit/type/BaseType.java b/src/main/java/net/transit/type/BaseType.java deleted file mode 100644 index 1202f95..0000000 --- a/src/main/java/net/transit/type/BaseType.java +++ /dev/null @@ -1,14 +0,0 @@ -package net.transit.type; - -public abstract class BaseType -{ - - public static final String TYPE_NAME = "BASE"; - - private T data; - - public T getData() - { - return data; - } -} \ No newline at end of file diff --git a/src/main/java/net/transit/type/Type.java b/src/main/java/net/transit/type/Type.java index 0c6fc91..7c7f839 100644 --- a/src/main/java/net/transit/type/Type.java +++ b/src/main/java/net/transit/type/Type.java @@ -1,18 +1,41 @@ package net.transit.type; -import net.transit.packet.IPacket; +import net.transit.network.packet.IPacket; +import net.transit.network.packet.StaticPacket; -public abstract class Type extends BaseType +/**@author Kyle Gunger + * + * @param The type of object transfered by packets of this type + */ +public abstract class Type { - public static final String TYPE_NAME = "TYPE"; - - public B convertToBase() - { - return null; - } - - public IPacket convertFromBase(B base) - { - return null; - } -} \ No newline at end of file + + /**Return the packet's data formatted in the group's base type. + * + * @param packet The packet (of this type) + * @return The packet's data in the default type + */ + public T toBase(IPacket packet) + { + return packet.getData(); + } + + /**Create a packet which has the current type from the data in the base type. + * + * @param base The base data + * @return IPacket<> The packet + */ + public IPacket fromBase(T base) + { + return new StaticPacket(base, this); + } + + /** The type identifier. Must be overridden for any class implementing IType + * + * @return String + */ + public String getType() + { + return "ITYPE"; + } +} diff --git a/src/main/java/net/transit/type/group/GroupRegistry.java b/src/main/java/net/transit/type/group/GroupRegistry.java new file mode 100644 index 0000000..47ee4db --- /dev/null +++ b/src/main/java/net/transit/type/group/GroupRegistry.java @@ -0,0 +1,51 @@ +package net.transit.type.group; + +import java.util.ArrayList; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +public abstract class GroupRegistry { + private static final ArrayList> GROUPS = new ArrayList>(0); + private static final ArrayList GROUPIDS = new ArrayList(0); + + private static final Logger LOG = LogManager.getFormatterLogger("Transit|GroupRegistry"); + + public static final boolean addGroup(TypeGroup group, String groupID) + { + for(String s : GROUPIDS) + { + if(s.equals(groupID)) + { + LOG.warn("Failed to add group " + group.getGroup() + " to the registry. Did another mod add a group with the same name?"); + return false; + } + } + + for(TypeGroup g : GROUPS) + { + if(g.equals(group)) + { + LOG.warn("Failed to add group " + group.getGroup() + " to the registry. Was the group alreay added?"); + return false; + } + } + + GROUPS.add(group); + GROUPIDS.add(groupID); + LOG.info("Successfully added group " + group.getGroup() + " to the registry."); + return true; + } + + public static final TypeGroup groupByID(String groupID) + { + for(String s : GROUPIDS) + { + if(s.equals(groupID)) return GROUPS.get(GROUPIDS.indexOf(s)); + } + + return null; + + } + +} diff --git a/src/main/java/net/transit/type/group/TypeGroup.java b/src/main/java/net/transit/type/group/TypeGroup.java new file mode 100644 index 0000000..2602641 --- /dev/null +++ b/src/main/java/net/transit/type/group/TypeGroup.java @@ -0,0 +1,137 @@ +package net.transit.type.group; + +import java.util.ArrayList; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import net.transit.network.packet.IPacket; +import net.transit.type.Type; + +/** + * @author Kyle Gunger + * @param The base object which all grouped Types should convert between. + */ +public class TypeGroup +{ + /** The list of types. */ + private final ArrayList> TYPES = new ArrayList>(0); + private final ArrayList TYPEIDS = new ArrayList(0); + + /** Logger for events in the group. Should not be overridden.*/ + private static final Logger LOG = LogManager.getFormatterLogger("Transit|Group"); + + /**Check if the type is in the group + * + * @param type + * @return boolean + */ + public boolean isInGroup(Type type) + { + return TYPES.contains(type); + } + + /**Check if the type is in the group + * + * @param type + * @return boolean + */ + public boolean isInGroup(String type) + { + return TYPEIDS.contains(type); + } + + /**Get the type from the group + * + * @param type + * @return IType<> + */ + public Type getType(String type) + { + if(isInGroup(type)) + { + return (Type) TYPES.get(TYPEIDS.indexOf(type)); + } + + return null; + } + + // Type conversion + /**Convert a packet to a new type + * + * @param packet The packet to convert + * @param type The type to convert to + * @return IPacket<> + */ + public IPacket convertPacket(IPacket packet, Type type) + { + if(isInGroup(packet.getType()) && isInGroup(type)) + { + return type.fromBase(packet.getType().toBase(packet)); + } + + return null; + } + + public IPacket convertPacket(IPacket packet, String type) + { + if(isInGroup(packet.getType()) && isInGroup(type)) + { + return getType(type).fromBase(packet.getType().toBase(packet)); + } + + return null; + } + + // Type management + + public boolean addType(Type type, String typeID) + { + if(!isInGroup(type.getType()) && !isInGroup(typeID)) + { + TYPES.add(type); + TYPEIDS.add(typeID); + LOG.info("Added type " + typeID + " to group " + this.getGroup()); + return true; + } + + return false; + } + + + public boolean removeType(Type type) + { + + if(isInGroup(type) && TYPES.indexOf(type) != -1) + { + String id = TYPEIDS.remove(TYPES.indexOf(type)); + TYPES.remove(type); + LOG.info("Removed type " + id + " from group " + this.getGroup()); + return true; + } + LOG.warn("Failed to remove type " + type.getType() + " from group " + this.getGroup() + ". Are we sure that the type was added to the group first?"); + return false; + } + + public boolean removeType(String typeID) + { + if(isInGroup(typeID) && TYPEIDS.indexOf(typeID) != -1) + { + TYPES.remove(TYPEIDS.indexOf(typeID)); + TYPEIDS.remove(typeID); + LOG.info("Removed type " + typeID + " from group " + this.getGroup()); + return true; + } + + LOG.warn("Failed to remove type " + typeID + " from group " + this.getGroup() + ". Are we sure that the type was added to the group first?"); + return false; + } + + /** The group identifier. Must be overridden for any class implementing ITypeGroup + * @return String + */ + public String getGroup() + { + return "ITYPEGROUP"; + } +} diff --git a/src/main/java/net/transit/type/group/simple/EnergyGroup.java b/src/main/java/net/transit/type/group/simple/EnergyGroup.java new file mode 100644 index 0000000..2d1eadc --- /dev/null +++ b/src/main/java/net/transit/type/group/simple/EnergyGroup.java @@ -0,0 +1,10 @@ +package net.transit.type.group.simple; + +import net.transit.type.group.TypeGroup; + +public class EnergyGroup extends TypeGroup{ + public String getGroup() + { + return "ENERGY"; + } +} diff --git a/src/main/java/net/transit/type/group/simple/FluidGroup.java b/src/main/java/net/transit/type/group/simple/FluidGroup.java new file mode 100644 index 0000000..3272c94 --- /dev/null +++ b/src/main/java/net/transit/type/group/simple/FluidGroup.java @@ -0,0 +1,11 @@ +package net.transit.type.group.simple; + +import net.minecraft.block.FluidBlock; +import net.transit.type.group.TypeGroup; + +public class FluidGroup extends TypeGroup{ + public String getGroup() + { + return "FLUID"; + } +} diff --git a/src/main/java/net/transit/type/group/simple/ItemGroup.java b/src/main/java/net/transit/type/group/simple/ItemGroup.java new file mode 100644 index 0000000..b7df90b --- /dev/null +++ b/src/main/java/net/transit/type/group/simple/ItemGroup.java @@ -0,0 +1,11 @@ +package net.transit.type.group.simple; + +import net.minecraft.item.Item; +import net.transit.type.group.TypeGroup; + +public class ItemGroup extends TypeGroup{ + public String getGroup() + { + return "ITEM"; + } +} diff --git a/src/main/java/net/transit/type/group/simple/ManaGroup.java b/src/main/java/net/transit/type/group/simple/ManaGroup.java new file mode 100644 index 0000000..6ed6ff1 --- /dev/null +++ b/src/main/java/net/transit/type/group/simple/ManaGroup.java @@ -0,0 +1,10 @@ +package net.transit.type.group.simple; + +import net.transit.type.group.TypeGroup; + +public class ManaGroup extends TypeGroup{ + public String getGroup() + { + return "MANA"; + } +} diff --git a/src/main/java/net/transit/type/group/simple/SimpleGroups.java b/src/main/java/net/transit/type/group/simple/SimpleGroups.java new file mode 100644 index 0000000..57ab2e9 --- /dev/null +++ b/src/main/java/net/transit/type/group/simple/SimpleGroups.java @@ -0,0 +1,26 @@ +package net.transit.type.group.simple; + +import net.minecraft.block.FluidBlock; +import net.minecraft.item.Item; +import net.transit.type.group.GroupRegistry; +import net.transit.type.group.TypeGroup; + +/** + * @author Kyle Gunger + * + * @apiNote Basic default groups which all mods are welcome to add themselves to. + */ +public class SimpleGroups +{ + public static final TypeGroup ENERGY_GROUP = new EnergyGroup(); + public static final TypeGroup MANA_GROUP = new ManaGroup(); + public static final TypeGroup ITEM_GROUP = new ItemGroup(); + public static final TypeGroup FLUID_GROUP = new FluidGroup(); + public static void initGroups() + { + GroupRegistry.addGroup(ENERGY_GROUP, "ENERGY"); + GroupRegistry.addGroup(MANA_GROUP, "MANA"); + GroupRegistry.addGroup(ITEM_GROUP, "ITEM"); + GroupRegistry.addGroup(FLUID_GROUP, "FLUID"); + } +} diff --git a/src/main/java/net/transit/type/simple/EnergyType.java b/src/main/java/net/transit/type/simple/EnergyType.java new file mode 100644 index 0000000..113b881 --- /dev/null +++ b/src/main/java/net/transit/type/simple/EnergyType.java @@ -0,0 +1,11 @@ +package net.transit.type.simple; + +import net.transit.type.Type; + +public class EnergyType extends Type +{ + public String getType() { + return "ENERGY_TYPE"; + } + +} diff --git a/src/main/java/net/transit/type/simple/FluidType.java b/src/main/java/net/transit/type/simple/FluidType.java new file mode 100644 index 0000000..86a3fb0 --- /dev/null +++ b/src/main/java/net/transit/type/simple/FluidType.java @@ -0,0 +1,11 @@ +package net.transit.type.simple; + +import net.minecraft.block.FluidBlock; +import net.transit.type.Type; + +public class FluidType extends Type +{ + public String getType() { + return "FLUID_TYPE"; + } +} diff --git a/src/main/java/net/transit/type/simple/ItemType.java b/src/main/java/net/transit/type/simple/ItemType.java new file mode 100644 index 0000000..6e860fc --- /dev/null +++ b/src/main/java/net/transit/type/simple/ItemType.java @@ -0,0 +1,11 @@ +package net.transit.type.simple; + +import net.minecraft.item.Item; +import net.transit.type.Type; + +public class ItemType extends Type +{ + public String getType() { + return "ITEM_TYPE"; + } +} diff --git a/src/main/java/net/transit/type/simple/ManaType.java b/src/main/java/net/transit/type/simple/ManaType.java new file mode 100644 index 0000000..6959216 --- /dev/null +++ b/src/main/java/net/transit/type/simple/ManaType.java @@ -0,0 +1,10 @@ +package net.transit.type.simple; + +import net.transit.type.Type; + +public class ManaType extends Type +{ + public String getType() { + return "MANA_TYPE"; + } +} diff --git a/src/main/java/net/transit/type/simple/SimpleTypes.java b/src/main/java/net/transit/type/simple/SimpleTypes.java new file mode 100644 index 0000000..e01af77 --- /dev/null +++ b/src/main/java/net/transit/type/simple/SimpleTypes.java @@ -0,0 +1,27 @@ +package net.transit.type.simple; + +import net.minecraft.block.FluidBlock; +import net.minecraft.item.Item; +import net.transit.type.Type; +import net.transit.type.group.simple.SimpleGroups; + +/** + * @author Kyle Gunger + * + * @apiNote Simple types which work as the base types for the simple groups. + */ +public class SimpleTypes +{ + public static final Type ENERGY_TYPE = new EnergyType(); + public static final Type MANA_TYPE = new ManaType(); + public static final Type ITEM_TYPE = new ItemType(); + public static final Type FLUID_TYPE = new FluidType(); + public static void initTypes() + { + SimpleGroups.ENERGY_GROUP.addType(ENERGY_TYPE, "ENERGY"); + SimpleGroups.MANA_GROUP.addType(MANA_TYPE, "MANA"); + SimpleGroups.ITEM_GROUP.addType(ITEM_TYPE, "ITEM"); + SimpleGroups.FLUID_GROUP.addType(FLUID_TYPE, "FLUID"); + System.out.println(SimpleGroups.ENERGY_GROUP.isInGroup("ENERGY")); + } +} diff --git a/src/main/java/net/transit/type/typebase/MetaBase.java b/src/main/java/net/transit/type/typebase/MetaBase.java deleted file mode 100644 index e1e6f5c..0000000 --- a/src/main/java/net/transit/type/typebase/MetaBase.java +++ /dev/null @@ -1,28 +0,0 @@ -package net.transit.type.typebase; - -import net.transit.type.BaseType; - -public class MetaBase> extends BaseType -{ - private T data; - private String metaData; - - public static final String TYPE_NAME = "BASE_META"; - - public MetaBase(T dat, String meta) - { - data = dat; - metaData = meta; - } - - public T getData() - { - return data; - } - - public String getMetaData() - { - return metaData; - } - -} \ No newline at end of file diff --git a/src/main/java/net/transit/type/typebase/NumberBase.java b/src/main/java/net/transit/type/typebase/NumberBase.java deleted file mode 100644 index a8d5ca3..0000000 --- a/src/main/java/net/transit/type/typebase/NumberBase.java +++ /dev/null @@ -1,20 +0,0 @@ -package net.transit.type.typebase; - -import net.transit.type.BaseType; - -public class NumberBase extends BaseType -{ - private Number data; - - public static final String TYPE_NAME = "BASE_NUMBER"; - - public NumberBase(Number dat) - { - data = dat; - } - - public Number getData() - { - return data; - } -} \ No newline at end of file diff --git a/src/main/java/net/transit/type/typebase/StringBase.java b/src/main/java/net/transit/type/typebase/StringBase.java deleted file mode 100644 index 8138b8d..0000000 --- a/src/main/java/net/transit/type/typebase/StringBase.java +++ /dev/null @@ -1,20 +0,0 @@ -package net.transit.type.typebase; - -import net.transit.type.BaseType; - -public class StringBase extends BaseType -{ - private String data; - - public static final String TYPE_NAME = "BASE_STRING"; - - public StringBase(String dat) - { - data = dat; - } - - public String getData() - { - return data; - } -} \ No newline at end of file diff --git a/src/main/java/net/transit/type/typegroup/TypeGroup.java b/src/main/java/net/transit/type/typegroup/TypeGroup.java deleted file mode 100644 index 4349df6..0000000 --- a/src/main/java/net/transit/type/typegroup/TypeGroup.java +++ /dev/null @@ -1,53 +0,0 @@ -package net.transit.type.typegroup; - -import java.util.ArrayList; - -import net.transit.type.Type; -import net.transit.type.BaseType; - -public class TypeGroup -{ - private BaseType baseType; - - private String groupName; - - private ArrayList> types; - - /**Create a new TypeGroup - * - * @param base The base type of the group. - * @param name The identifier of the group. Should be in all caps. - */ - public TypeGroup(BaseType base, String name) - { - baseType = base; - types = new ArrayList>(0); - groupName = name; - } - - // Return the base type - public BaseType getBaseType() - { - return baseType; - } - - // Returns if the type is supported by the group - public boolean hasType(Type t) - { - - for(Type gtype : types) - { - - if(t.TYPE_NAME == gtype.TYPE_NAME) return true; - } - - return false; - } - - // Group name/identifier - public String getGroupName() - { - - return groupName; - } -} \ No newline at end of file diff --git a/src/main/java/net/transit/type/typegroup/TypeRegister.java b/src/main/java/net/transit/type/typegroup/TypeRegister.java deleted file mode 100644 index d226cbe..0000000 --- a/src/main/java/net/transit/type/typegroup/TypeRegister.java +++ /dev/null @@ -1,44 +0,0 @@ -package net.transit.type.typegroup; - -import java.util.ArrayList; - -import net.transit.type.Type; - -public final class TypeRegister -{ - private TypeRegister(){} - - // Hold all the groups - private static ArrayList> groups = new ArrayList>(0); - - private static ArrayList caster = new ArrayList(0); - - // Add a group - public static void addTypeGroup(TypeGroup g) - { - if(getTypeGroup(g.getGroupName()) != null) return; - - groups.add(g); - } - - // Get a group by it's identifier - public static TypeGroup getTypeGroup(String name) - { - for(TypeGroup g : groups) - { - if(g.getGroupName().toUpperCase() == name.toUpperCase()) return g; - } - - return null; - } - - public static String groupOf(Type t) - { - for(TypeGroup g : groups) - { - if(g.hasType(t)) return g.getGroupName(); - } - - return null; - } -} \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 9bfe73f..918da54 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -15,7 +15,11 @@ "icon": "assets/transit-api/transit.png", "environment": "*", - + + "entrypoints" : { + "main": ["net.transit.InitTransit"] + }, + "depends": { "fabricloader": ">=0.4.0", "fabric": "*" -- cgit v1.2.3