diff options
Diffstat (limited to 'src/main')
26 files changed, 528 insertions, 390 deletions
diff --git a/src/main/java/net/cshift/api/transit/Transit.java b/src/main/java/net/cshift/api/transit/Transit.java new file mode 100644 index 0000000..adc9f25 --- /dev/null +++ b/src/main/java/net/cshift/api/transit/Transit.java @@ -0,0 +1,48 @@ +/* + MIT License + + Copyright (c) 2023 Kyle Gunger + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +package net.cshift.api.transit; + +import net.fabricmc.api.ModInitializer; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.cshift.api.transit.type.group.SimpleGroups; + +/** + * @author Kyle Gunger + * @apiNote This is the main entry point for Transit. The api is mostly intended for use on server-side connections. + */ +public class Transit implements ModInitializer { + + private static final Logger LOGGER = LoggerFactory.getLogger("Transit API"); + + @Override + public void onInitialize() { + LOGGER.info("Transit API: Providing a thin wrapper over reality!"); + SimpleGroups.init(); + } + +} diff --git a/src/main/java/net/cshift/transit/network/Channel.java b/src/main/java/net/cshift/api/transit/network/Channel.java index e5c64da..bd4cdf2 100644 --- a/src/main/java/net/cshift/transit/network/Channel.java +++ b/src/main/java/net/cshift/api/transit/network/Channel.java @@ -1,6 +1,30 @@ -package net.cshift.transit.network; - -import net.cshift.transit.network.packet.IStaticPacket; +/* + MIT License + + Copyright (c) 2023 Kyle Gunger + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +package net.cshift.api.transit.network; + +import net.cshift.api.transit.network.packet.IStaticPacket; /** * @author Kyle Gunger diff --git a/src/main/java/net/cshift/transit/network/INode.java b/src/main/java/net/cshift/api/transit/network/INode.java index 7cbb1cc..54701e7 100644 --- a/src/main/java/net/cshift/transit/network/INode.java +++ b/src/main/java/net/cshift/api/transit/network/INode.java @@ -1,6 +1,6 @@ -package net.cshift.transit.network; +package net.cshift.api.transit.network; -import net.cshift.transit.network.packet.*; +import net.cshift.api.transit.network.packet.*; /** * @author Kyle Gunger diff --git a/src/main/java/net/cshift/transit/network/ISystem.java b/src/main/java/net/cshift/api/transit/network/ISystem.java index 8d41c1d..b7ab9bf 100644 --- a/src/main/java/net/cshift/transit/network/ISystem.java +++ b/src/main/java/net/cshift/api/transit/network/ISystem.java @@ -1,4 +1,4 @@ -package net.cshift.transit.network; +package net.cshift.api.transit.network; /** diff --git a/src/main/java/net/cshift/transit/network/PoolManifest.java b/src/main/java/net/cshift/api/transit/network/PoolManifest.java index e23d47f..26cbece 100644 --- a/src/main/java/net/cshift/transit/network/PoolManifest.java +++ b/src/main/java/net/cshift/api/transit/network/PoolManifest.java @@ -1,4 +1,4 @@ -package net.cshift.transit.network; +package net.cshift.api.transit.network; /** * @author Kyle Gunger diff --git a/src/main/java/net/cshift/transit/network/packet/DynamicPacket.java b/src/main/java/net/cshift/api/transit/network/packet/DynamicPacket.java index 60ad177..f3a6c47 100644 --- a/src/main/java/net/cshift/transit/network/packet/DynamicPacket.java +++ b/src/main/java/net/cshift/api/transit/network/packet/DynamicPacket.java @@ -1,6 +1,6 @@ -package net.cshift.transit.network.packet; +package net.cshift.api.transit.network.packet; -import net.cshift.transit.type.Type; +import net.cshift.api.transit.type.Type; /** * Simple packet which stores a fluid value. diff --git a/src/main/java/net/cshift/transit/network/packet/IDynamicPacket.java b/src/main/java/net/cshift/api/transit/network/packet/IDynamicPacket.java index 8b7c330..334d5f6 100644 --- a/src/main/java/net/cshift/transit/network/packet/IDynamicPacket.java +++ b/src/main/java/net/cshift/api/transit/network/packet/IDynamicPacket.java @@ -1,4 +1,4 @@ -package net.cshift.transit.network.packet; +package net.cshift.api.transit.network.packet; /** Interface describing a fluid packet. * @author Kyle Gunger diff --git a/src/main/java/net/cshift/transit/network/packet/IStaticPacket.java b/src/main/java/net/cshift/api/transit/network/packet/IStaticPacket.java index bac8745..ba1b17f 100644 --- a/src/main/java/net/cshift/transit/network/packet/IStaticPacket.java +++ b/src/main/java/net/cshift/api/transit/network/packet/IStaticPacket.java @@ -1,6 +1,6 @@ -package net.cshift.transit.network.packet; +package net.cshift.api.transit.network.packet; -import net.cshift.transit.type.*; +import net.cshift.api.transit.type.*; /** Interface describing an unchanging packet. * @author Kyle Gunger diff --git a/src/main/java/net/cshift/transit/network/packet/MetaDynamicPacket.java b/src/main/java/net/cshift/api/transit/network/packet/MetaDynamicPacket.java index b87c2ed..d382645 100644 --- a/src/main/java/net/cshift/transit/network/packet/MetaDynamicPacket.java +++ b/src/main/java/net/cshift/api/transit/network/packet/MetaDynamicPacket.java @@ -1,6 +1,6 @@ -package net.cshift.transit.network.packet; +package net.cshift.api.transit.network.packet; -import net.cshift.transit.type.Type; +import net.cshift.api.transit.type.Type; /** Static packet with extra data attached. * @author Kyle Gunger diff --git a/src/main/java/net/cshift/transit/network/packet/MetaPacket.java b/src/main/java/net/cshift/api/transit/network/packet/MetaPacket.java index 99be83c..aea1b83 100644 --- a/src/main/java/net/cshift/transit/network/packet/MetaPacket.java +++ b/src/main/java/net/cshift/api/transit/network/packet/MetaPacket.java @@ -1,6 +1,6 @@ -package net.cshift.transit.network.packet; +package net.cshift.api.transit.network.packet; -import net.cshift.transit.type.*; +import net.cshift.api.transit.type.*; /** Static packet with extra data attached. * @author Kyle Gunger diff --git a/src/main/java/net/cshift/transit/network/packet/StaticPacket.java b/src/main/java/net/cshift/api/transit/network/packet/StaticPacket.java index 7c95108..2c6a16a 100644 --- a/src/main/java/net/cshift/transit/network/packet/StaticPacket.java +++ b/src/main/java/net/cshift/api/transit/network/packet/StaticPacket.java @@ -1,6 +1,6 @@ -package net.cshift.transit.network.packet; +package net.cshift.api.transit.network.packet; -import net.cshift.transit.type.*; +import net.cshift.api.transit.type.*; /** Simple packet which stores an unchanging value. * @author Kyle Gunger diff --git a/src/main/java/net/cshift/api/transit/type/SimpleTypes.java b/src/main/java/net/cshift/api/transit/type/SimpleTypes.java new file mode 100644 index 0000000..54106c7 --- /dev/null +++ b/src/main/java/net/cshift/api/transit/type/SimpleTypes.java @@ -0,0 +1,43 @@ +/* + MIT License + + Copyright (c) 2023 Kyle Gunger + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +package net.cshift.api.transit.type; + +public final class SimpleTypes { + /** Transfers energy. Energy is stored as a numeric. + */ + public static final Type<Long> TransitJoule = new Type<Long>("Joule", "ENERGY"); + + /** Transfers mana. TMana stores mana count and type. + */ + public static final Type<TMana> TransitMana = new Type<TMana>("TMana", "MANA"); + + /** Transfers items. TItem stores an item and an item count. + */ + public static final Type<TItem> TransitItem = new Type<TItem>("TItem", "ITEM"); + + /** Transfers fluid. TFluid stores fluid and mB. + */ + public static final Type<TFluid> TransitFluid = new Type<TFluid>("TFluid", "FLUID"); +} diff --git a/src/main/java/net/cshift/transit/type/TFluid.java b/src/main/java/net/cshift/api/transit/type/TFluid.java index 4b980bd..522d75c 100644 --- a/src/main/java/net/cshift/transit/type/TFluid.java +++ b/src/main/java/net/cshift/api/transit/type/TFluid.java @@ -1,4 +1,4 @@ -package net.cshift.transit.type; +package net.cshift.api.transit.type; import net.minecraft.fluid.*; @@ -13,7 +13,7 @@ public class TFluid { * Since a bucket of fluid is the same as a block of a fluid, mb can be called millibuckets or milliblocks. * * @param f Fluid stored (Water/Lava/etc.) - * @param mB Count of fluid (mB) + * @param mB Count of fluid (droplets) */ public TFluid(Fluid f, Number mB) { fluid = f; diff --git a/src/main/java/net/cshift/api/transit/type/TItem.java b/src/main/java/net/cshift/api/transit/type/TItem.java new file mode 100644 index 0000000..54a3d23 --- /dev/null +++ b/src/main/java/net/cshift/api/transit/type/TItem.java @@ -0,0 +1,57 @@ +/* + MIT License + + Copyright (c) 2023 Kyle Gunger + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +package net.cshift.api.transit.type; + +import net.minecraft.item.*; + +/** Item storage + * @author Kyle Gunger + */ +public class TItem { + private Item item; + private Number count; + + /** Constructor. + * + * @param i Item stored + * @param c Item count + */ + public TItem(Item i, Number c) { + item = i; + count = c; + } + + /** Get the item stored. + */ + public Item getItem() { + return item; + } + + /** Get the item count. + */ + public Number getCount() { + return count; + } +} diff --git a/src/main/java/net/cshift/transit/type/TMana.java b/src/main/java/net/cshift/api/transit/type/TMana.java index 468b04f..a73e47c 100644 --- a/src/main/java/net/cshift/transit/type/TMana.java +++ b/src/main/java/net/cshift/api/transit/type/TMana.java @@ -1,4 +1,4 @@ -package net.cshift.transit.type; +package net.cshift.api.transit.type; /** Units of mana. * @author Kyle Gunger diff --git a/src/main/java/net/cshift/transit/type/Type.java b/src/main/java/net/cshift/api/transit/type/Type.java index 9049135..d47cd08 100644 --- a/src/main/java/net/cshift/transit/type/Type.java +++ b/src/main/java/net/cshift/api/transit/type/Type.java @@ -1,6 +1,6 @@ -package net.cshift.transit.type; +package net.cshift.api.transit.type; -import net.cshift.transit.network.packet.*; +import net.cshift.api.transit.network.packet.*; /**@author Kyle Gunger * diff --git a/src/main/java/net/cshift/api/transit/type/group/GroupRegistry.java b/src/main/java/net/cshift/api/transit/type/group/GroupRegistry.java new file mode 100644 index 0000000..5e09e71 --- /dev/null +++ b/src/main/java/net/cshift/api/transit/type/group/GroupRegistry.java @@ -0,0 +1,50 @@ +package net.cshift.api.transit.type.group; + +import java.security.InvalidKeyException; +import java.util.HashMap; + +import org.slf4j.*; + +import net.cshift.api.transit.type.Type; + +public final class GroupRegistry { + private static final HashMap<String, TypeGroup<?>> GROUPS = new HashMap<String, TypeGroup<?>>(); + + private static final Logger LOGGER = LoggerFactory.getLogger("Transit API/Group Registry"); + + private GroupRegistry() {} + + public static final boolean addGroup(TypeGroup<?> group) + { + if (GROUPS.containsKey(group.getGroup())) { + LOGGER.warn("Failed to add group " + group + " to the registry. Did another mod add a group with the same name?"); + return false; + } + + GROUPS.put(group.getGroup(), group); + LOGGER.info("Successfully added group " + group + " to the registry."); + + return true; + } + + public static final <T> TypeGroup<T> groupByID(String groupID) + { + if (GROUPS.containsKey(groupID)) { + TypeGroup<?> g = GROUPS.get(groupID); + return (TypeGroup<T>) g; + } + + return null; + } + + public static final <T> Type<T> typeByIdentity(String groupID, String typeID) throws InvalidKeyException + { + TypeGroup<T> group = GroupRegistry.<T>groupByID(groupID); + + if(group != null) + return group.getType(typeID); + + return null; + } + +} diff --git a/src/main/java/net/cshift/api/transit/type/group/SimpleGroups.java b/src/main/java/net/cshift/api/transit/type/group/SimpleGroups.java new file mode 100644 index 0000000..66d0121 --- /dev/null +++ b/src/main/java/net/cshift/api/transit/type/group/SimpleGroups.java @@ -0,0 +1,58 @@ +/* + MIT License + + Copyright (c) 2023 Kyle Gunger + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +package net.cshift.api.transit.type.group; + +import org.slf4j.*; + +import net.cshift.api.transit.type.*; + +public final class SimpleGroups { + /** Transfers energy. Basic unit is TJoule (Transit Joule). + */ + public static final TypeGroup<Long> ENERGY = new TypeGroup<Long>(SimpleTypes.TransitJoule); + + /** Transfers mana. Basic unit is TMana (Transit Mana). + */ + public static final TypeGroup<TMana> MANA = new TypeGroup<TMana>(SimpleTypes.TransitMana); + + /** Transfers items. Basic unit is TItem. + */ + public static final TypeGroup<TItem> ITEM = new TypeGroup<TItem>(SimpleTypes.TransitItem); + + /** Transfers fluids. Basic unit is TFluid. + */ + public static final TypeGroup<TFluid> FLUID = new TypeGroup<TFluid>(SimpleTypes.TransitFluid); + + private static final Logger LOGGER = LoggerFactory.getLogger("Transit API/Simple Groups"); + + public static final void init() + { + LOGGER.info("Initializing simple groups"); + GroupRegistry.addGroup(ENERGY); + GroupRegistry.addGroup(MANA); + GroupRegistry.addGroup(ITEM); + GroupRegistry.addGroup(FLUID); + } +} diff --git a/src/main/java/net/cshift/api/transit/type/group/TypeGroup.java b/src/main/java/net/cshift/api/transit/type/group/TypeGroup.java new file mode 100644 index 0000000..fcbb3ef --- /dev/null +++ b/src/main/java/net/cshift/api/transit/type/group/TypeGroup.java @@ -0,0 +1,220 @@ +/* + MIT License + + Copyright (c) 2023 Kyle Gunger + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +package net.cshift.api.transit.type.group; + +import java.security.InvalidKeyException; +import java.sql.Types; +import java.util.HashMap; + +import org.slf4j.*; + +import net.cshift.api.transit.type.Type; + +/** + * @author Kyle Gunger + * @param <B> The base object which all grouped Types should convert between. + */ +public final class TypeGroup<B> +{ + // The base Type (provides the group's identifier) + private Type<B> baseType; + + // The list of types. + private final HashMap<String, Type<B>> TYPES; + + // Logger for events in the TypeGroup. + private static final Logger LOGGER = LoggerFactory.getLogger("Transit API/Type Group"); + + + public TypeGroup(Type<B> base) + { + TYPES = new HashMap<String, Type<B>>(); + 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<B> type) + { + if(TYPES.containsKey(type.getType())) + { + LOGGER.info("Failed to add type " + type + " to group " + getGroup() + ". Was the type already added?"); + return false; + } + + TYPES.put(type.toString(), type); + LOGGER.info("Added type " + type + " to group " + getGroup()); + return true; + + } + + /** Remove a Type from the TypeGroup. + * + * @param type The Type to remove + * @return + */ + public boolean removeType(Type<B> type) + { + if(type.toString().equals(baseType.toString())) { + LOGGER.warn("Failed to remove type " + type + " from group " + getGroup() + ". This is the base type and can not be removed."); + return false; + } + + if(TYPES.containsKey(type.toString())) + { + LOGGER.info("Removed type " + TYPES.remove(type.toString()) + " from group " + getGroup()); + return true; + } + + LOGGER.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) + { + String typeString = groupID + ":" + typeID; + + if(baseType.toString().equals(typeString)) { + LOGGER.warn("Failed to remove type " + baseType + " from group " + getGroup() + ". This is the base type and can not be removed."); + return false; + } + + if(TYPES.containsKey(typeString)) + { + LOGGER.info("Removed type " + TYPES.remove(typeString) + " from group " + getGroup()); + return true; + } + + LOGGER.warn("Failed to remove type " + typeString + " 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<B> type) + { + return TYPES.containsKey(type.toString()) && TYPES.get(type.toString()) == type; + } + + /**Check if the type is in the group + * + * @param groupID + * @param typeID + * @return boolean + */ + public boolean isInGroup(String groupID, String typeID) + { + return TYPES.containsKey(groupID + ":" + typeID); + } + + /**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<B> getType(String groupID, String typeID) throws InvalidKeyException + { + String typeString = groupID + ":" + typeID; + if (!TYPES.containsKey(typeString)) + throw new InvalidKeyException("Invalid key in getType (" + typeString + "is not in group" + getGroup() + ")"); + return TYPES.get(typeString); + } + + /**Get the type from the group + * + * @param typeID The ID of the type + * @return Type + */ + public Type<B> getType(String typeID) throws InvalidKeyException + { + return getType(getGroup(), typeID); + } + + + // DO ALL TYPE CONVERSION USING TYPES. + + /** 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<B> getBase() { + return baseType; + } + + @Override + public final String toString() { + return this.getGroup(); + } +} diff --git a/src/main/java/net/cshift/transit/Transit.java b/src/main/java/net/cshift/transit/Transit.java deleted file mode 100644 index 71d3fea..0000000 --- a/src/main/java/net/cshift/transit/Transit.java +++ /dev/null @@ -1,17 +0,0 @@ -package net.cshift.transit; - -import net.fabricmc.api.ModInitializer; -import net.cshift.transit.type.group.SimpleGroups; - -/** - * @author Kyle Gunger - * @apiNote This is the main entry point for Transit. The api is mostly intended for use on server-side connections. - */ -public class Transit implements ModInitializer { - - @Override - public void onInitialize() { - SimpleGroups.init(); - } - -} diff --git a/src/main/java/net/cshift/transit/type/SimpleTypes.java b/src/main/java/net/cshift/transit/type/SimpleTypes.java deleted file mode 100644 index ee8dd01..0000000 --- a/src/main/java/net/cshift/transit/type/SimpleTypes.java +++ /dev/null @@ -1,19 +0,0 @@ -package net.cshift.transit.type; - -public final class SimpleTypes { - /** Transfers energy. Energy is stored as a numeric. - */ - public static final Type<Number> TransitJoule = new Type<Number>("TJoule", "ENERGY"); - - /** Transfers mana. TMana stores mana count and type. - */ - public static final Type<TMana> TransitMana = new Type<TMana>("TMana", "MANA"); - - /** Transfers items. TItem stores an item and an item count. - */ - public static final Type<TItem> TransitItem = new Type<TItem>("TItem", "ITEM"); - - /** Transfers fluid. TFluid stores fluid and mB. - */ - public static final Type<TFluid> TransitFluid = new Type<TFluid>("TFluid", "FLUID"); -} diff --git a/src/main/java/net/cshift/transit/type/TItem.java b/src/main/java/net/cshift/transit/type/TItem.java deleted file mode 100644 index b3cc160..0000000 --- a/src/main/java/net/cshift/transit/type/TItem.java +++ /dev/null @@ -1,33 +0,0 @@ -package net.cshift.transit.type; - -import net.minecraft.item.*; - -/** Item storage - * @author Kyle Gunger - */ -public class TItem { - private Item item; - private Number count; - - /** Constructor. - * - * @param i Item stored - * @param c Item count - */ - public TItem(Item i, Number c) { - item = i; - count = c; - } - - /** Get the item stored. - */ - public Item getItem() { - return item; - } - - /** Get the item count. - */ - public Number getCount() { - return count; - } -} diff --git a/src/main/java/net/cshift/transit/type/group/GroupRegistry.java b/src/main/java/net/cshift/transit/type/group/GroupRegistry.java deleted file mode 100644 index cfebb03..0000000 --- a/src/main/java/net/cshift/transit/type/group/GroupRegistry.java +++ /dev/null @@ -1,60 +0,0 @@ -package net.cshift.transit.type.group; - -import java.util.ArrayList; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import net.cshift.transit.type.Type; - -public final class GroupRegistry { - private static final ArrayList<TypeGroup<?>> GROUPS = new ArrayList<TypeGroup<?>>(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; - } - - public static final <T> TypeGroup<T> groupByID(String groupID) - { - for(TypeGroup<?> g : GROUPS) - { - if(g.getGroup().equals(groupID)){ - try{ - return (TypeGroup<T>) g; - }catch(ClassCastException e) { - return null; - } - } - } - - return null; - - } - - public static final <T> Type<T> typeByIdentity(String groupID, String typeID) - { - TypeGroup<T> group = GroupRegistry.<T>groupByID(groupID); - - if(group != null) - return group.getType(typeID); - - return null; - } - -} diff --git a/src/main/java/net/cshift/transit/type/group/SimpleGroups.java b/src/main/java/net/cshift/transit/type/group/SimpleGroups.java deleted file mode 100644 index d68c5a5..0000000 --- a/src/main/java/net/cshift/transit/type/group/SimpleGroups.java +++ /dev/null @@ -1,29 +0,0 @@ -package net.cshift.transit.type.group; - -import net.cshift.transit.type.*; - -public final class SimpleGroups { - /** Transfers energy. Basic unit is TJoule (Transit Joule). - */ - public static final TypeGroup<Number> ENERGY = new TypeGroup<Number>(SimpleTypes.TransitJoule); - - /** Transfers mana. Basic unit is TMana (Transit Mana). - */ - public static final TypeGroup<TMana> MANA = new TypeGroup<TMana>(SimpleTypes.TransitMana); - - /** Transfers items. Basic unit is TItem. - */ - public static final TypeGroup<TItem> ITEM = new TypeGroup<TItem>(SimpleTypes.TransitItem); - - /** Transfers fluids. Basic unit is TFluid. - */ - public static final TypeGroup<TFluid> FLUID = new TypeGroup<TFluid>(SimpleTypes.TransitFluid); - - public static final void init() - { - GroupRegistry.addGroup(ENERGY); - GroupRegistry.addGroup(MANA); - GroupRegistry.addGroup(ITEM); - GroupRegistry.addGroup(FLUID); - } -} diff --git a/src/main/java/net/cshift/transit/type/group/TypeGroup.java b/src/main/java/net/cshift/transit/type/group/TypeGroup.java deleted file mode 100644 index 214f28c..0000000 --- a/src/main/java/net/cshift/transit/type/group/TypeGroup.java +++ /dev/null @@ -1,204 +0,0 @@ -package net.cshift.transit.type.group; - -import java.util.ArrayList; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import net.cshift.transit.type.Type; - -/** - * @author Kyle Gunger - * @param <B> The base object which all grouped Types should convert between. - */ -public final class TypeGroup<B> -{ - // The base Type (provides the group's identifier) - private Type<B> baseType; - - // The list of types. - private final ArrayList<Type<B>> TYPES = new ArrayList<Type<B>>(0); - - // Logger for events in the TypeGroup. - private static final Logger LOG = LogManager.getFormatterLogger("Transit|Group"); - - - public TypeGroup(Type<B> 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<B> 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<B> 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<B> type) - { - for(Type<B> 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<B> 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<B> getType(String groupID, String typeID) - { - for(Type<B> 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<B> getType(String typeID) - { - return getType(getGroup(), typeID); - } - - - // DO ALL TYPE CONVERSION USING TYPES. - - /** 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<B> getBase() { - return baseType; - } - - @Override - public final String toString() { - return this.getGroup(); - } -} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 9768c22..6f2fbd5 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -1,7 +1,7 @@ { "schemaVersion": 1, "id": "transit-api", - "version": "2.0.0", + "version": "3.0.0-alpha", "name": "Transit API", "description": "Move things about!", @@ -9,7 +9,7 @@ "CSKyle" ], "contact": { - "homepage": "https://cshift.net/", + "homepage": "https://cshift.net/TransitAPI", "sources": "https://github.com/CircleShift/TransitAPI", "issues": "https://github.com/CircleShift/TransitAPI/issues" }, @@ -20,12 +20,12 @@ "environment": "*", "entrypoints": { "main": [ - "net.cshift.transit.Transit" + "net.cshift.api.transit.Transit" ] }, "depends": { - "fabricloader": ">=0.7.4", - "minecraft": "1.17.x" + "fabricloader": ">=0.14.0", + "minecraft": "1.20.x" } } |