diff --git a/src/main/java/net/minestom/server/item/metadata/ItemMeta.java b/src/main/java/net/minestom/server/item/metadata/ItemMeta.java index 27ed14884..5fb7f1305 100644 --- a/src/main/java/net/minestom/server/item/metadata/ItemMeta.java +++ b/src/main/java/net/minestom/server/item/metadata/ItemMeta.java @@ -1,11 +1,54 @@ package net.minestom.server.item.metadata; -public abstract class ItemMeta { +import net.minestom.server.item.ItemStack; +import org.jglrxavpok.hephaistos.nbt.NBTCompound; - public abstract boolean hasNbt(); +/** + * Represent nbt data only available for a type of item + */ +public interface ItemMeta { - public abstract boolean isSimilar(ItemMeta itemMeta); + /** + * Get if this meta object contains any useful data to send to the client + * + * @return true if this item has nbt data, false otherwise + */ + boolean hasNbt(); - public abstract ItemMeta clone(); + /** + * Get if the two ItemMeta are similar + *
+ * It is used by {@link ItemStack#isSimilar(ItemStack)} + * + * @param itemMeta the second item meta to check + * @return true if the two meta are similar, false otherwise + */ + boolean isSimilar(ItemMeta itemMeta); + + /** + * Read nbt data from a compound + *
+ * WARNING: it is possible that it contains no useful data, + * it has to be checked before getting anything + * + * @param compound the compound containing the data + */ + void read(NBTCompound compound); + + /** + * Write nbt data to a compound + * + * @param compound the compound receiving the item meta data + */ + void write(NBTCompound compound); + + /** + * Clone this item meta + *
+ * Used by {@link ItemStack#clone()}
+ *
+ * @return the cloned item meta
+ */
+ ItemMeta clone();
}
diff --git a/src/main/java/net/minestom/server/item/metadata/MapMeta.java b/src/main/java/net/minestom/server/item/metadata/MapMeta.java
index 47b165052..5ce6298bc 100644
--- a/src/main/java/net/minestom/server/item/metadata/MapMeta.java
+++ b/src/main/java/net/minestom/server/item/metadata/MapMeta.java
@@ -1,6 +1,8 @@
package net.minestom.server.item.metadata;
-public class MapMeta extends ItemMeta {
+import org.jglrxavpok.hephaistos.nbt.NBTCompound;
+
+public class MapMeta implements ItemMeta {
private int mapId;
@@ -22,6 +24,20 @@ public class MapMeta extends ItemMeta {
return itemMeta instanceof MapMeta && ((MapMeta) itemMeta).getMapId() == mapId;
}
+ @Override
+ public void read(NBTCompound compound) {
+ if (compound.containsKey("map")) {
+ this.mapId = compound.getInt("map");
+ }
+ }
+
+ @Override
+ public void write(NBTCompound compound) {
+ if (mapId != 0) {
+ compound.setInt("map", mapId);
+ }
+ }
+
@Override
public ItemMeta clone() {
MapMeta mapMeta = new MapMeta();
diff --git a/src/main/java/net/minestom/server/item/metadata/PotionMeta.java b/src/main/java/net/minestom/server/item/metadata/PotionMeta.java
index 20f88a2d5..87dad3954 100644
--- a/src/main/java/net/minestom/server/item/metadata/PotionMeta.java
+++ b/src/main/java/net/minestom/server/item/metadata/PotionMeta.java
@@ -1,12 +1,14 @@
package net.minestom.server.item.metadata;
import net.minestom.server.potion.PotionType;
+import net.minestom.server.registry.Registries;
+import org.jglrxavpok.hephaistos.nbt.NBTCompound;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
-public class PotionMeta extends ItemMeta {
+public class PotionMeta implements ItemMeta {
private Set