From 2a606b1ed1dc04e140a5ae78a2235a350c9a1f60 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Mon, 28 Oct 2019 19:47:38 -0700 Subject: [PATCH] Our own basic NBT types --- .../com/gmail/nossr50/core/nbt/NBTBase.java | 11 ++++++ .../com/gmail/nossr50/core/nbt/NBTByte.java | 28 +++++++++++++++ .../gmail/nossr50/core/nbt/NBTByteArray.java | 32 +++++++++++++++++ .../com/gmail/nossr50/core/nbt/NBTDouble.java | 28 +++++++++++++++ .../com/gmail/nossr50/core/nbt/NBTFloat.java | 28 +++++++++++++++ .../gmail/nossr50/core/nbt/NBTIntArray.java | 32 +++++++++++++++++ .../gmail/nossr50/core/nbt/NBTInteger.java | 28 +++++++++++++++ .../com/gmail/nossr50/core/nbt/NBTList.java | 35 +++++++++++++++++++ .../com/gmail/nossr50/core/nbt/NBTLong.java | 28 +++++++++++++++ .../gmail/nossr50/core/nbt/NBTLongArray.java | 32 +++++++++++++++++ .../com/gmail/nossr50/core/nbt/NBTShort.java | 28 +++++++++++++++ .../com/gmail/nossr50/core/nbt/NBTString.java | 28 +++++++++++++++ .../nossr50/core/nbt/NBTTagCompound.java | 18 ++++++++++ .../com/gmail/nossr50/core/nbt/NBTType.java | 22 ++++++++++++ 14 files changed, 378 insertions(+) create mode 100644 mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTBase.java create mode 100644 mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTByte.java create mode 100644 mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTByteArray.java create mode 100644 mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTDouble.java create mode 100644 mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTFloat.java create mode 100644 mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTIntArray.java create mode 100644 mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTInteger.java create mode 100644 mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTList.java create mode 100644 mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTLong.java create mode 100644 mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTLongArray.java create mode 100644 mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTShort.java create mode 100644 mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTString.java create mode 100644 mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTTagCompound.java create mode 100644 mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTType.java diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTBase.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTBase.java new file mode 100644 index 000000000..620100b85 --- /dev/null +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTBase.java @@ -0,0 +1,11 @@ +package com.gmail.nossr50.core.nbt; + +public interface NBTBase { + + /** + * Get the NBTType for this NBTBase + * @return this NBTType + */ + NBTType getNBTType(); + +} diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTByte.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTByte.java new file mode 100644 index 000000000..ca1635243 --- /dev/null +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTByte.java @@ -0,0 +1,28 @@ +package com.gmail.nossr50.core.nbt; + +public class NBTByte implements NBTBase { + + private String key; + private Byte value; + + @Override + public NBTType getNBTType() { + return NBTType.BYTE; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public Byte getValue() { + return value; + } + + public void setValue(Byte value) { + this.value = value; + } +} diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTByteArray.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTByteArray.java new file mode 100644 index 000000000..312837442 --- /dev/null +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTByteArray.java @@ -0,0 +1,32 @@ +package com.gmail.nossr50.core.nbt; + +public class NBTByteArray implements NBTBase { + + private String key; + private byte[] values; + + @Override + public NBTType getNBTType() { + return NBTType.BYTE_ARRAY; + } + + public int getLength() { + return values.length; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public byte[] getValues() { + return values; + } + + public void setValues(byte[] values) { + this.values = values; + } +} diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTDouble.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTDouble.java new file mode 100644 index 000000000..4b3ed06be --- /dev/null +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTDouble.java @@ -0,0 +1,28 @@ +package com.gmail.nossr50.core.nbt; + +public class NBTDouble implements NBTBase { + + private String key; + private double value; + + @Override + public NBTType getNBTType() { + return NBTType.DOUBLE; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public double getValue() { + return value; + } + + public void setValue(double value) { + this.value = value; + } +} diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTFloat.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTFloat.java new file mode 100644 index 000000000..5bbb9a36f --- /dev/null +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTFloat.java @@ -0,0 +1,28 @@ +package com.gmail.nossr50.core.nbt; + +public class NBTFloat implements NBTBase { + + private String key; + private float value; + + @Override + public NBTType getNBTType() { + return NBTType.FLOAT; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public float getValue() { + return value; + } + + public void setValue(float value) { + this.value = value; + } +} diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTIntArray.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTIntArray.java new file mode 100644 index 000000000..fce90d9c8 --- /dev/null +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTIntArray.java @@ -0,0 +1,32 @@ +package com.gmail.nossr50.core.nbt; + +public class NBTIntArray implements NBTBase { + + private String key; + private int[] values; + + @Override + public NBTType getNBTType() { + return NBTType.INT_ARRAY; + } + + public int getLength() { + return values.length; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public int[] getValues() { + return values; + } + + public void setValues(int[] values) { + this.values = values; + } +} diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTInteger.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTInteger.java new file mode 100644 index 000000000..2591bba3b --- /dev/null +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTInteger.java @@ -0,0 +1,28 @@ +package com.gmail.nossr50.core.nbt; + +public class NBTInteger implements NBTBase { + + private String key; + private int value; + + @Override + public NBTType getNBTType() { + return NBTType.INT; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public int getValue() { + return value; + } + + public void setValue(int value) { + this.value = value; + } +} diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTList.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTList.java new file mode 100644 index 000000000..f98653560 --- /dev/null +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTList.java @@ -0,0 +1,35 @@ +package com.gmail.nossr50.core.nbt; + +import java.util.List; + +public class NBTList implements NBTBase { + + private int length; + private String key; + private List values; + + @Override + public NBTType getNBTType() { + return NBTType.LIST; + } + + public int getLength() { + return length; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public List getValues() { + return values; + } + + public void setValues(List values) { + this.values = values; + } +} diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTLong.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTLong.java new file mode 100644 index 000000000..630f748fa --- /dev/null +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTLong.java @@ -0,0 +1,28 @@ +package com.gmail.nossr50.core.nbt; + +public class NBTLong implements NBTBase { + + public String key; + public long value; + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public long getValue() { + return value; + } + + public void setValue(long value) { + this.value = value; + } + + @Override + public NBTType getNBTType() { + return NBTType.LONG; + } +} diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTLongArray.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTLongArray.java new file mode 100644 index 000000000..feb7aee26 --- /dev/null +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTLongArray.java @@ -0,0 +1,32 @@ +package com.gmail.nossr50.core.nbt; + +public class NBTLongArray implements NBTBase { + + private String key; + private long[] values; + + @Override + public NBTType getNBTType() { + return NBTType.LONG_ARRAY; + } + + public int getLength() { + return values.length; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public long[] getValues() { + return values; + } + + public void setValues(long[] values) { + this.values = values; + } +} diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTShort.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTShort.java new file mode 100644 index 000000000..db64f624d --- /dev/null +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTShort.java @@ -0,0 +1,28 @@ +package com.gmail.nossr50.core.nbt; + +public class NBTShort implements NBTBase { + + private String key; + private short value; + + @Override + public NBTType getNBTType() { + return NBTType.SHORT; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public short getValue() { + return value; + } + + public void setValue(short value) { + this.value = value; + } +} diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTString.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTString.java new file mode 100644 index 000000000..123e82665 --- /dev/null +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTString.java @@ -0,0 +1,28 @@ +package com.gmail.nossr50.core.nbt; + +public class NBTString implements NBTBase { + + private String key; + private String value; + + @Override + public NBTType getNBTType() { + return NBTType.STRING; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTTagCompound.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTTagCompound.java new file mode 100644 index 000000000..26dbbc7d4 --- /dev/null +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTTagCompound.java @@ -0,0 +1,18 @@ +package com.gmail.nossr50.core.nbt; + +import java.util.Map; + +public class NBTTagCompound implements NBTBase { + + private Map tagMap; + + @Override + public NBTType getNBTType() { + return NBTType.COMPOUND; + } + + public NBTBase getTag(String key) { + return tagMap.get(key); + } + +} diff --git a/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTType.java b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTType.java new file mode 100644 index 000000000..40d162dbf --- /dev/null +++ b/mcmmo-core/src/main/java/com/gmail/nossr50/core/nbt/NBTType.java @@ -0,0 +1,22 @@ +package com.gmail.nossr50.core.nbt; + +/** + * Represents the NBT Type + * Based on NBT Structure in 1.14.4 + */ +public enum NBTType { + ////String[] a = new String[]{"END", "BYTE", "SHORT", "INT", "LONG", "FLOAT", "DOUBLE", "BYTE[]", "STRING", "LIST", "COMPOUND", "INT[]", "LONG[]"}; + END, + BYTE, + SHORT, + INT, + LONG, + FLOAT, + DOUBLE, + BYTE_ARRAY, + STRING, + LIST, + COMPOUND, + INT_ARRAY, + LONG_ARRAY +}