From d45be1d289816e0262e0872d4b06b09208e82153 Mon Sep 17 00:00:00 2001 From: Kyle Gunger Date: Fri, 22 Jan 2021 12:38:53 -0500 Subject: [RC1] Type updates and such --- src/main/java/net/cshift/transit/type/TFluid.java | 15 +- src/main/java/net/cshift/transit/type/TItem.java | 34 ++++ src/main/java/net/cshift/transit/type/Type.java | 199 +++++++++++++++++++-- .../net/cshift/transit/type/group/TypeGroup.java | 6 +- .../transit/type/group/simple/SimpleGroups.java | 5 +- .../cshift/transit/type/simple/SimpleTypes.java | 3 +- src/main/resources/fabric.mod.json | 2 +- 7 files changed, 237 insertions(+), 27 deletions(-) create mode 100644 src/main/java/net/cshift/transit/type/TItem.java (limited to 'src/main') diff --git a/src/main/java/net/cshift/transit/type/TFluid.java b/src/main/java/net/cshift/transit/type/TFluid.java index 4f6b70f..4b980bd 100644 --- a/src/main/java/net/cshift/transit/type/TFluid.java +++ b/src/main/java/net/cshift/transit/type/TFluid.java @@ -1,22 +1,23 @@ package net.cshift.transit.type; -import net.minecraft.fluid.Fluid; +import net.minecraft.fluid.*; /** Units of fluid. * @author Kyle Gunger */ public class TFluid { private Fluid fluid; - private Number millibuckets; + private Number mb; - /** Constructor + /** Constructor. + * 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 (mB) */ - public TFluid(Fluid f, Number mb) { + public TFluid(Fluid f, Number mB) { fluid = f; - millibuckets = mb; + mb = mB; } /** Get the fluid stored. @@ -28,6 +29,6 @@ public class TFluid { /** Get the millibuckets stored. */ public Number getMilliBuckets() { - return millibuckets; + return mb; } } diff --git a/src/main/java/net/cshift/transit/type/TItem.java b/src/main/java/net/cshift/transit/type/TItem.java new file mode 100644 index 0000000..966267d --- /dev/null +++ b/src/main/java/net/cshift/transit/type/TItem.java @@ -0,0 +1,34 @@ +package net.cshift.transit.type; + +import net.minecraft.item.*; + +/** Units of fluid. + * @author Kyle Gunger + */ +public class TItem { + private Item item; + private Number count; + + /** Constructor. + * Since a bucket of fluid is the same as a block of a fluid, mb can be called millibuckets or milliblocks. + * + * @param i Fluid stored (Water/Lava/etc.) + * @param c Item countie + */ + public TItem(Item i, Number c) { + item = i; + count = c; + } + + /** Get the fluid stored. + */ + public Item getItem() { + return item; + } + + /** Get the millibuckets stored. + */ + public Number getCount() { + return count; + } +} diff --git a/src/main/java/net/cshift/transit/type/Type.java b/src/main/java/net/cshift/transit/type/Type.java index 46e2ace..586a891 100644 --- a/src/main/java/net/cshift/transit/type/Type.java +++ b/src/main/java/net/cshift/transit/type/Type.java @@ -17,29 +17,202 @@ public class Type 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. + + + // ########################################## + // # Converting from this type to base type # + // ########################################## + + /** Return the data formatted in the given group's base type. + * If creating a new type, override this function if required. + * + * @param data The data (of this type) + * @param group The group asking for the conversion + * @return The data in the group's base type + */ + public T toBase(T data, String group) + { + return data; + } + + /** Return the data formatted in the default group's base type. + * + * @param data The data (of this type) + * @return The data in the group's base type + */ + public final T toBase(T data) + { + return this.toBase(data, this.groupID); + } + + /** Return the packet's data formatted in the given group's base type. * * @param packet The packet (of this type) * @param group The group asking for the conversion - * @return The packet's data in the default type + * @return The packet's data in the group's base type */ - public T toBase(IStaticPacket packet, String group) + public final T toBase(IStaticPacket packet, String group) { - return packet.getData(); + return this.toBase(packet.getData(), group); } - - /** 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. + + /** Return the packet's data formatted in the default group's base type. + * + * @param packet The packet (of this type) + * @return The packet's data in the group's base type + */ + public final T toBase(IStaticPacket packet) + { + return this.toBase(packet, this.groupID); + } + + + + // ########################################## + // # Converting from base type to this type # + // ########################################## + + /** Convert data from the given group's base type to this type. + * If creating a new type, override this function if required. + * + * @param data The base data + * @param group The group asking for the conversion + * @return The packet's data in the group's base type + */ + public T fromBase(T data, String group) + { + return data; + } + + /** Convert data from the default group's base type to this type. + * + * @param data The base data + * @return The packet's data in the group's base type + */ + public final T fromBase(T data) + { + return fromBase(data, this.groupID); + } + + /** Create a packet from data formatted in the given group's base type. + * + * @param data The base data + * @param group The group asking for the conversion + * @return The packet's data in the group's base type + */ + public final IStaticPacket packetFromBase(T data, String group) + { + return new StaticPacket(this.fromBase(data, group), this); + } + + /** Create a packet from data formatted in the default group's base type. * - * @param base The base data - * @param group The group that the data comes from - * @return IStaticPacket The packet + * @param data The base data + * @return The packet's data in the group's base type */ - public IStaticPacket fromBase(T base, String group) + public final IStaticPacket packetFromBase(T data) { - return new StaticPacket(base, this); + return packetFromBase(data, this.groupID); } + + + + // ########################################### + // # Converting from other type to this type # + // ########################################### + + /** Convert data from another type to this type in the given group. + * If creating a new type, override this function if required. + * + * @param from The type to convert from + * @param group The group we are converting within + * @param data The data to convert + * @return The data formatted in this type + */ + public T convertFrom(Type from, String group, T data) { + return this.fromBase(from.toBase(data, group), group); + } + + /** Convert data from another type to this type in the default group. + * + * @param from The type to convert from + * @param data The data to convert + * @return The data formatted in this type + */ + public final T convertFrom(Type from, T data) { + return convertFrom(from, from.groupID, data); + } + + /** Convert a packet using another type to a packet using this type within the given group. + * + * @param packet The packet to convert + * @param group The group to convert within + * @return The new packet formatted in this type + */ + public final IStaticPacket convertFrom(IStaticPacket packet, String group) { + return new StaticPacket(convertFrom(packet.getType(), group, packet.getData()), this); + } + + /** Convert a packet using another type to a packet using this type within the default group. + * + * @param packet The packet to convert + * @return The new packet formatted in this type + */ + public final IStaticPacket convertFrom(IStaticPacket packet) { + return this.convertFrom(packet, packet.getType().groupID); + } + + + + // ########################################### + // # Converting from other type to this type # + // ########################################### + + /** Convert data from this type to another type in the given group. + * + * @param from The type to convert from + * @param group The group we are converting within + * @param data The data to convert + * @return The data formatted in this type + */ + public final T convertTo(Type to, String group, T data) { + return to.convertFrom(this, group, data); + } + + /** Convert data from this type to another type in the default group. + * + * @param from The type to convert from + * @param data The data to convert + * @return The data formatted in this type + */ + public final T convertTo(Type to, T data) { + return to.convertFrom(this, groupID, data); + } + + /** Convert a packet using this type to a packet using another type within the given group. + * + * @param packet The packet to convert + * @param group The group to convert within + * @return The new packet formatted in this type + */ + public final IStaticPacket convertTo(Type to, IStaticPacket packet, String group) { + return to.convertFrom(packet, group); + } + + /** Convert a packet using this type to a packet using another type within the default group. + * + * @param packet The packet to convert + * @return The new packet formatted in this type + */ + public final IStaticPacket convertTo(Type to, IStaticPacket packet) { + return to.convertFrom(packet, groupID); + } + + + + // ############################## + // # Utility and info functions # + // ############################## /** The type identifier. Gives the normal type identity of the type. * diff --git a/src/main/java/net/cshift/transit/type/group/TypeGroup.java b/src/main/java/net/cshift/transit/type/group/TypeGroup.java index 5b8f061..596a511 100644 --- a/src/main/java/net/cshift/transit/type/group/TypeGroup.java +++ b/src/main/java/net/cshift/transit/type/group/TypeGroup.java @@ -189,9 +189,10 @@ public class TypeGroup * @param type * @return */ + @Deprecated protected IStaticPacket convertPacketRaw(IStaticPacket packet, Type type) { - return type.fromBase(packet.getType().toBase(packet, getGroup()), getGroup()); + return type.packetFromBase(packet.getType().toBase(packet.getData())); } /**Convert a packet to a new type Returns null if the type isn't in the group. @@ -200,6 +201,7 @@ public class TypeGroup * @param type The type to convert to * @return Packet */ + @Deprecated public IStaticPacket convertPacket(IStaticPacket packet, Type type) { if(isInGroup(packet.getType()) && isInGroup(type)) @@ -217,6 +219,7 @@ public class TypeGroup * @param typeID The typeID of the Type to convert to * @return Packet */ + @Deprecated public IStaticPacket convertPacket(IStaticPacket packet, String groupID, String typeID) { Type toType = getType(groupID, typeID); @@ -234,6 +237,7 @@ public class TypeGroup * @param typeID The typeID of the Type to convert to * @return Packet */ + @Deprecated public IStaticPacket convertPacket(IStaticPacket packet, String typeID) { Type toType = getType(typeID); diff --git a/src/main/java/net/cshift/transit/type/group/simple/SimpleGroups.java b/src/main/java/net/cshift/transit/type/group/simple/SimpleGroups.java index 24868e1..95b151a 100644 --- a/src/main/java/net/cshift/transit/type/group/simple/SimpleGroups.java +++ b/src/main/java/net/cshift/transit/type/group/simple/SimpleGroups.java @@ -1,8 +1,7 @@ package net.cshift.transit.type.group.simple; -import net.minecraft.item.ItemStack; import net.cshift.transit.type.group.*; -import net.cshift.transit.type.simple.SimpleTypes; +import net.cshift.transit.type.simple.*; import net.cshift.transit.type.*; public final class SimpleGroups { @@ -16,7 +15,7 @@ public final class SimpleGroups { /** Transfers items. Basic type is ItemStack. */ - public static final TypeGroup ITEM_GROUP = new TypeGroup(SimpleTypes.Item); + public static final TypeGroup ITEM_GROUP = new TypeGroup(SimpleTypes.Item); /** Transfers fluids. Basic unit is TFluid. */ diff --git a/src/main/java/net/cshift/transit/type/simple/SimpleTypes.java b/src/main/java/net/cshift/transit/type/simple/SimpleTypes.java index 4b231f3..26171b1 100644 --- a/src/main/java/net/cshift/transit/type/simple/SimpleTypes.java +++ b/src/main/java/net/cshift/transit/type/simple/SimpleTypes.java @@ -1,6 +1,5 @@ package net.cshift.transit.type.simple; -import net.minecraft.item.ItemStack; import net.cshift.transit.type.*; public final class SimpleTypes { @@ -14,7 +13,7 @@ public final class SimpleTypes { /** Transfers items in a itemstack. */ - public static final Type Item = new Type("Item", "ITEM"); + public static final Type Item = new Type("Item", "ITEM"); /** Transfers fluid. TFluid stores fluid and mB. */ diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index dca6073..44afcd7 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -1,7 +1,7 @@ { "schemaVersion": 1, "id": "transit-api", - "version": "0.15.0", + "version": "1.0.0-rc.1", "name": "Transit API", "description": "Move things about!", -- cgit v1.2.3