From 39ee2eeafec3475e59f2942f0285acc47fdd6193 Mon Sep 17 00:00:00 2001 From: Flowsqy <47575244+Flowsqy@users.noreply.github.com> Date: Thu, 23 Feb 2023 22:57:11 +0100 Subject: [PATCH] Add base structure for Component in nms implementation --- .../component/ComponentExtractor.java | 7 +++++++ .../v1_19_R2/component/ItemTagExtractor.java | 14 +++++++++++++ .../TranslatableItemNameExtractor.java | 14 +++++++++++++ .../nms/v1_19_R2/item/NMSItemStack.java | 20 +++++++++++++++++++ 4 files changed, 55 insertions(+) create mode 100644 nms/v1_19_R2/src/main/java/de/epiceric/shopchest/nms/v1_19_R2/component/ComponentExtractor.java create mode 100644 nms/v1_19_R2/src/main/java/de/epiceric/shopchest/nms/v1_19_R2/component/ItemTagExtractor.java create mode 100644 nms/v1_19_R2/src/main/java/de/epiceric/shopchest/nms/v1_19_R2/component/TranslatableItemNameExtractor.java create mode 100644 nms/v1_19_R2/src/main/java/de/epiceric/shopchest/nms/v1_19_R2/item/NMSItemStack.java diff --git a/nms/v1_19_R2/src/main/java/de/epiceric/shopchest/nms/v1_19_R2/component/ComponentExtractor.java b/nms/v1_19_R2/src/main/java/de/epiceric/shopchest/nms/v1_19_R2/component/ComponentExtractor.java new file mode 100644 index 0000000..6a72fcf --- /dev/null +++ b/nms/v1_19_R2/src/main/java/de/epiceric/shopchest/nms/v1_19_R2/component/ComponentExtractor.java @@ -0,0 +1,7 @@ +package de.epiceric.shopchest.nms.v1_19_R2.component; + +public class ComponentExtractor { + + + +} diff --git a/nms/v1_19_R2/src/main/java/de/epiceric/shopchest/nms/v1_19_R2/component/ItemTagExtractor.java b/nms/v1_19_R2/src/main/java/de/epiceric/shopchest/nms/v1_19_R2/component/ItemTagExtractor.java new file mode 100644 index 0000000..3377ce2 --- /dev/null +++ b/nms/v1_19_R2/src/main/java/de/epiceric/shopchest/nms/v1_19_R2/component/ItemTagExtractor.java @@ -0,0 +1,14 @@ +package de.epiceric.shopchest.nms.v1_19_R2.component; + +import de.epiceric.shopchest.nms.v1_19_R2.item.NMSItemStack; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.Tag; + +public class ItemTagExtractor { + + public String extractItemTag(NMSItemStack itemStack) { + final Tag tag = itemStack.getNmsItemStack().save(new CompoundTag()).get("tag"); + return tag == null ? null : tag.getAsString(); + } + +} diff --git a/nms/v1_19_R2/src/main/java/de/epiceric/shopchest/nms/v1_19_R2/component/TranslatableItemNameExtractor.java b/nms/v1_19_R2/src/main/java/de/epiceric/shopchest/nms/v1_19_R2/component/TranslatableItemNameExtractor.java new file mode 100644 index 0000000..b094b76 --- /dev/null +++ b/nms/v1_19_R2/src/main/java/de/epiceric/shopchest/nms/v1_19_R2/component/TranslatableItemNameExtractor.java @@ -0,0 +1,14 @@ +package de.epiceric.shopchest.nms.v1_19_R2.component; + +import de.epiceric.shopchest.nms.v1_19_R2.item.NMSItemStack; +import net.minecraft.network.chat.Component; + +public class TranslatableItemNameExtractor { + + public String extractTranslatableItemName(NMSItemStack nmsItemStack) { + final net.minecraft.world.item.ItemStack nStack = nmsItemStack.getNmsItemStack(); + final Component component = nStack.getItem().getName(nStack); + return Component.Serializer.toJson(component); + } + +} diff --git a/nms/v1_19_R2/src/main/java/de/epiceric/shopchest/nms/v1_19_R2/item/NMSItemStack.java b/nms/v1_19_R2/src/main/java/de/epiceric/shopchest/nms/v1_19_R2/item/NMSItemStack.java new file mode 100644 index 0000000..107cb6f --- /dev/null +++ b/nms/v1_19_R2/src/main/java/de/epiceric/shopchest/nms/v1_19_R2/item/NMSItemStack.java @@ -0,0 +1,20 @@ +package de.epiceric.shopchest.nms.v1_19_R2.item; + +import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftItemStack; +import org.bukkit.inventory.ItemStack; + +public class NMSItemStack { + + private final ItemStack bukkitItemStack; + private final net.minecraft.world.item.ItemStack nmsItemStack; + + public NMSItemStack(ItemStack bukkitItemStack) { + this.bukkitItemStack = bukkitItemStack; + nmsItemStack = CraftItemStack.asNMSCopy(bukkitItemStack); + } + + public net.minecraft.world.item.ItemStack getNmsItemStack() { + return nmsItemStack; + } + +}