Add base structure for Component in nms implementation

This commit is contained in:
Flowsqy 2023-02-23 22:57:11 +01:00
parent 365034c08c
commit 39ee2eeafe
4 changed files with 55 additions and 0 deletions

View File

@ -0,0 +1,7 @@
package de.epiceric.shopchest.nms.v1_19_R2.component;
public class ComponentExtractor {
}

View File

@ -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();
}
}

View File

@ -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);
}
}

View File

@ -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;
}
}