summaryrefslogtreecommitdiff
path: root/src/main/java/net/cshift/transit
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2021-01-22 12:38:53 -0500
committerKyle Gunger <kgunger12@gmail.com>2021-01-22 12:38:53 -0500
commitd45be1d289816e0262e0872d4b06b09208e82153 (patch)
treeca7b06b83f9ad3f9fafd7df75effb7b6a5487cf4 /src/main/java/net/cshift/transit
parent01c32f91ac7d6088cb11d5ca85430d65010c640b (diff)
[RC1] Type updates and such
Diffstat (limited to 'src/main/java/net/cshift/transit')
-rw-r--r--src/main/java/net/cshift/transit/type/TFluid.java15
-rw-r--r--src/main/java/net/cshift/transit/type/TItem.java34
-rw-r--r--src/main/java/net/cshift/transit/type/Type.java199
-rw-r--r--src/main/java/net/cshift/transit/type/group/TypeGroup.java6
-rw-r--r--src/main/java/net/cshift/transit/type/group/simple/SimpleGroups.java5
-rw-r--r--src/main/java/net/cshift/transit/type/simple/SimpleTypes.java3
6 files changed, 236 insertions, 26 deletions
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<T>
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<T> packet, String group)
+ public final T toBase(IStaticPacket<T> 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<T> 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<T> packetFromBase(T data, String group)
+ {
+ return new StaticPacket<T>(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<T> fromBase(T base, String group)
+ public final IStaticPacket<T> packetFromBase(T data)
{
- return new StaticPacket<T>(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<T> 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<T> 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<T> convertFrom(IStaticPacket<T> packet, String group) {
+ return new StaticPacket<T>(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<T> convertFrom(IStaticPacket<T> 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<T> 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<T> 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<T> convertTo(Type<T> to, IStaticPacket<T> 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<T> convertTo(Type<T> to, IStaticPacket<T> 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<B>
* @param type
* @return
*/
+ @Deprecated
protected IStaticPacket<B> convertPacketRaw(IStaticPacket<B> packet, Type<B> 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<B>
* @param type The type to convert to
* @return Packet
*/
+ @Deprecated
public IStaticPacket<B> convertPacket(IStaticPacket<B> packet, Type<B> type)
{
if(isInGroup(packet.getType()) && isInGroup(type))
@@ -217,6 +219,7 @@ public class TypeGroup<B>
* @param typeID The typeID of the Type to convert to
* @return Packet
*/
+ @Deprecated
public IStaticPacket<B> convertPacket(IStaticPacket<B> packet, String groupID, String typeID)
{
Type<B> toType = getType(groupID, typeID);
@@ -234,6 +237,7 @@ public class TypeGroup<B>
* @param typeID The typeID of the Type to convert to
* @return Packet
*/
+ @Deprecated
public IStaticPacket<B> convertPacket(IStaticPacket<B> packet, String typeID)
{
Type<B> 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<ItemStack> ITEM_GROUP = new TypeGroup<ItemStack>(SimpleTypes.Item);
+ public static final TypeGroup<TItem> ITEM_GROUP = new TypeGroup<TItem>(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<ItemStack> Item = new Type<ItemStack>("Item", "ITEM");
+ public static final Type<TItem> Item = new Type<TItem>("Item", "ITEM");
/** Transfers fluid. TFluid stores fluid and mB.
*/