From 4372fdc319d8e3d1494db5e8e47e0cb9d85005e0 Mon Sep 17 00:00:00 2001 From: d1gress <55198830+d1gress@users.noreply.github.com> Date: Thu, 5 Dec 2019 00:56:51 +0800 Subject: [PATCH] Make NBT Command (#223) --- .../kami/command/commands/NBTCommand.java | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/main/java/me/zeroeightsix/kami/command/commands/NBTCommand.java diff --git a/src/main/java/me/zeroeightsix/kami/command/commands/NBTCommand.java b/src/main/java/me/zeroeightsix/kami/command/commands/NBTCommand.java new file mode 100644 index 000000000..ed833d233 --- /dev/null +++ b/src/main/java/me/zeroeightsix/kami/command/commands/NBTCommand.java @@ -0,0 +1,54 @@ +package me.zeroeightsix.kami.command.commands; + +import me.zeroeightsix.kami.command.Command; +import me.zeroeightsix.kami.command.syntax.ChunkBuilder; +import me.zeroeightsix.kami.command.syntax.parsers.EnumParser; +import net.minecraft.client.Minecraft; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +import java.awt.*; +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.StringSelection; + +/** + * @author d1gress/Qther + * Created by d1gress/Qther on 4/12/2019. + */ +public class NBTCommand extends Command { + + public NBTCommand() { + super("nbt", new ChunkBuilder() + .append("action", true, new EnumParser(new String[]{"get", "copy", "wipe"})) + .build()); + setDescription("Does NBT related stuff (get, copy, set)"); + } + + Minecraft mc = Minecraft.getMinecraft(); + private final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); + StringSelection nbt; + + @Override + public void call(String[] args) { + if(args[0].isEmpty()) { + sendErrorMessage("Invalid Syntax!"); + return; + } + ItemStack item = mc.player.inventory.getCurrentItem(); + + if (args[0].equalsIgnoreCase("get")) { + if (item.getTagCompound() != null) { + sendChatMessage("&6&lNBT:\n" + item.getTagCompound() + ""); + } else sendErrorMessage("No NBT on " + item.getDisplayName()); + } else if (args[0].equalsIgnoreCase("copy")) { + if (item.getTagCompound() != null) { + nbt = new StringSelection(item.getTagCompound() + ""); + clipboard.setContents(nbt, nbt); + sendChatMessage("&6Copied\n&f" + (item.getTagCompound() + "\n") + "&6to clipboard."); + } else sendErrorMessage("No NBT on " + item.getDisplayName()); + } else if (args[0].equalsIgnoreCase("wipe")) { + sendChatMessage("&6Wiped\n&f" + (item.getTagCompound() + "\n") + "&6from " + item.getDisplayName() + "."); + item.setTagCompound(new NBTTagCompound()); + } + } +}