From 395b205484b6141e514b4b87238004eb514a2641 Mon Sep 17 00:00:00 2001 From: Felix Cravic Date: Sat, 1 Aug 2020 20:50:39 +0200 Subject: [PATCH] WIP PlayerHeadMeta & SpawnEggMeta --- .../net/minestom/server/item/ItemStack.java | 3 ++ .../server/item/metadata/PlayerHeadMeta.java | 38 +++++++++++++++ .../server/item/metadata/SpawnEggMeta.java | 48 +++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 src/main/java/net/minestom/server/item/metadata/PlayerHeadMeta.java create mode 100644 src/main/java/net/minestom/server/item/metadata/SpawnEggMeta.java diff --git a/src/main/java/net/minestom/server/item/ItemStack.java b/src/main/java/net/minestom/server/item/ItemStack.java index 9f65cfcad..b0d5d99bf 100644 --- a/src/main/java/net/minestom/server/item/ItemStack.java +++ b/src/main/java/net/minestom/server/item/ItemStack.java @@ -596,6 +596,9 @@ public class ItemStack implements DataContainer { if (material == Material.FIREWORK_ROCKET) return new FireworkMeta(); + if (material == Material.PLAYER_HEAD) + return new PlayerHeadMeta(); + if (material == Material.LEATHER_HELMET || material == Material.LEATHER_CHESTPLATE || material == Material.LEATHER_LEGGINGS || diff --git a/src/main/java/net/minestom/server/item/metadata/PlayerHeadMeta.java b/src/main/java/net/minestom/server/item/metadata/PlayerHeadMeta.java new file mode 100644 index 000000000..97a50b83c --- /dev/null +++ b/src/main/java/net/minestom/server/item/metadata/PlayerHeadMeta.java @@ -0,0 +1,38 @@ +package net.minestom.server.item.metadata; + +import net.minestom.server.entity.PlayerSkin; +import org.jglrxavpok.hephaistos.nbt.NBTCompound; + +public class PlayerHeadMeta implements ItemMeta { + + private String playerName; + private PlayerSkin playerSkin; + + @Override + public boolean hasNbt() { + return playerSkin != null; + } + + @Override + public boolean isSimilar(ItemMeta itemMeta) { + if (!(itemMeta instanceof PlayerHeadMeta)) + return false; + final PlayerHeadMeta playerHeadMeta = (PlayerHeadMeta) itemMeta; + return playerHeadMeta.playerSkin == playerSkin; + } + + @Override + public void read(NBTCompound compound) { + + } + + @Override + public void write(NBTCompound compound) { + + } + + @Override + public ItemMeta clone() { + return null; + } +} diff --git a/src/main/java/net/minestom/server/item/metadata/SpawnEggMeta.java b/src/main/java/net/minestom/server/item/metadata/SpawnEggMeta.java new file mode 100644 index 000000000..9fafb9cb5 --- /dev/null +++ b/src/main/java/net/minestom/server/item/metadata/SpawnEggMeta.java @@ -0,0 +1,48 @@ +package net.minestom.server.item.metadata; + +import net.minestom.server.entity.EntityType; +import org.jglrxavpok.hephaistos.nbt.NBTCompound; + +// TODO for which item +public class SpawnEggMeta implements ItemMeta { + + private EntityType entityType; + + @Override + public boolean hasNbt() { + return entityType != null; + } + + @Override + public boolean isSimilar(ItemMeta itemMeta) { + if (!(itemMeta instanceof SpawnEggMeta)) + return false; + final SpawnEggMeta spawnEggMeta = (SpawnEggMeta) itemMeta; + return spawnEggMeta.entityType == entityType; + } + + @Override + public void read(NBTCompound compound) { + if (compound.containsKey("EntityTag")) { + + } + } + + @Override + public void write(NBTCompound compound) { + if (!hasNbt()) + return; + NBTCompound entityCompound = new NBTCompound(); + if (entityType != null) { + entityCompound.setString("id", entityType.getNamespaceID()); + } + + } + + @Override + public ItemMeta clone() { + SpawnEggMeta spawnEggMeta = new SpawnEggMeta(); + spawnEggMeta.entityType = entityType; + return spawnEggMeta; + } +}