diff --git a/gradle.properties b/gradle.properties index b58616d..5278a98 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ minecraft_version=1.20 loader_version=0.15.6 # Mod Properties -mod_version=2.0 +mod_version=2.0.1 maven_group=net.scenariopla mod_id=nbtexporter mod_name=NBT Exporter diff --git a/src/main/java/net/scenariopla/nbtexporter/NBTExporter.java b/src/main/java/net/scenariopla/nbtexporter/NBTExporter.java index 878fa27..4bbde17 100644 --- a/src/main/java/net/scenariopla/nbtexporter/NBTExporter.java +++ b/src/main/java/net/scenariopla/nbtexporter/NBTExporter.java @@ -10,7 +10,10 @@ import net.fabricmc.loader.api.FabricLoader; import net.scenariopla.nbtexporter.command.ExportItemStackCommand; +import net.scenariopla.nbtexporter.command.ExportItemStackGiveCommand; import net.scenariopla.nbtexporter.command.ExportItemStackNBTCommand; +import net.scenariopla.nbtexporter.command.ExportStringifiedItemStackCommand; +import net.scenariopla.nbtexporter.command.ExportStringifiedItemStackNBTCommand; import net.scenariopla.nbtexporter.command.ICommand; import net.scenariopla.nbtexporter.init.DirectoryInit; @@ -18,13 +21,16 @@ public class NBTExporter implements ClientModInitializer { public class Reference { public static final String MOD_ID = "nbtexporter"; public static final String NAME = "NBT Exporter"; - public static final String VERSION = "2.0"; + public static final String VERSION = "2.0.1"; public static final String MOD_DIRECTORY = MOD_ID; public static final ICommand[] MOD_CLIENT_COMMANDS = { + new ExportItemStackCommand(), new ExportItemStackNBTCommand(), - new ExportItemStackCommand() + new ExportStringifiedItemStackCommand(), + new ExportStringifiedItemStackNBTCommand(), + new ExportItemStackGiveCommand() }; public static final FabricLoader MINECRAFT = FabricLoader.getInstance(); diff --git a/src/main/java/net/scenariopla/nbtexporter/command/ExportStringifiedItemStackCommand.java b/src/main/java/net/scenariopla/nbtexporter/command/ExportStringifiedItemStackCommand.java index 147611d..429cdb9 100644 --- a/src/main/java/net/scenariopla/nbtexporter/command/ExportStringifiedItemStackCommand.java +++ b/src/main/java/net/scenariopla/nbtexporter/command/ExportStringifiedItemStackCommand.java @@ -46,7 +46,7 @@ public String getMessageKey() { } public void register(CommandDispatcher dispatcher) { - dispatcher.register(literal("exportnbtstr") + dispatcher.register(literal("exportstackstr") .executes(context -> { return execute(context, getFilename()); }) diff --git a/src/main/java/net/scenariopla/nbtexporter/command/NBTExporterCommand.java b/src/main/java/net/scenariopla/nbtexporter/command/NBTExporterCommand.java index cdf988a..5c241dd 100644 --- a/src/main/java/net/scenariopla/nbtexporter/command/NBTExporterCommand.java +++ b/src/main/java/net/scenariopla/nbtexporter/command/NBTExporterCommand.java @@ -17,6 +17,7 @@ import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtIo; import net.minecraft.network.chat.ClickEvent; import net.minecraft.network.chat.Component; import net.minecraft.world.entity.player.Player; @@ -24,7 +25,6 @@ import net.scenariopla.nbtexporter.NBTExporter; import net.scenariopla.nbtexporter.NBTExporter.Reference; -import net.scenariopla.nbtexporter.util.NBTFileWriter; import static net.scenariopla.nbtexporter.command.NBTExporterCommandExceptions.ExceptionCollection; import static net.scenariopla.nbtexporter.command.NBTExporterCommandExceptions.exception; @@ -134,7 +134,7 @@ protected static File writeToFile(File file, ByteArrayOutputStream byteArrayOutputStream = null; try { byteArrayOutputStream = new ByteArrayOutputStream(); - NBTFileWriter.writeCompoundGZIP(tag, byteArrayOutputStream); + NbtIo.writeCompressed(tag, byteArrayOutputStream); return writeToFile(file, byteArrayOutputStream.toByteArray()); } catch (IOException e) { e.printStackTrace(); diff --git a/src/main/java/net/scenariopla/nbtexporter/util/NBTFileWriter.java b/src/main/java/net/scenariopla/nbtexporter/util/NBTFileWriter.java deleted file mode 100644 index 761293a..0000000 --- a/src/main/java/net/scenariopla/nbtexporter/util/NBTFileWriter.java +++ /dev/null @@ -1,73 +0,0 @@ -package net.scenariopla.nbtexporter.util; - -import java.io.BufferedOutputStream; -import java.io.DataOutput; -import java.io.DataOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.util.zip.GZIPOutputStream; - -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.Tag; - -public class NBTFileWriter { - private static void writeSingle(final Tag tag, - final DataOutput output) - throws IOException { - final byte id = tag.getId(); - output.writeByte(id); - if (id != 0) { - output.writeUTF(""); - tag.write(output); - } - } - - public static void writeCompound(final CompoundTag compound, - final DataOutput output) - throws IOException { - writeSingle(compound, output); - } - - public static void writeCompound(final CompoundTag compound, - final File file) - throws IOException { - DataOutputStream dataOutputStream = null; - try { - dataOutputStream = new DataOutputStream( - new FileOutputStream(file)); - writeCompound(compound, dataOutputStream); - } finally { - dataOutputStream.close(); - } - } - - public static void writeCompoundGZIP(final CompoundTag compound, - final File file) - throws IOException { - FileOutputStream fileOutputStream = null; - try { - fileOutputStream = new FileOutputStream(file); - writeCompoundGZIP(compound, new FileOutputStream(file)); - } catch (Exception e) { - throw e; - } finally { - fileOutputStream.close(); - } - } - - public static void writeCompoundGZIP(final CompoundTag compound, - final OutputStream outputStream) - throws IOException { - DataOutputStream dataOutputStream = null; - try { - dataOutputStream = new DataOutputStream( - new BufferedOutputStream( - new GZIPOutputStream(outputStream))); - writeCompound(compound, dataOutputStream); - } finally { - dataOutputStream.close(); - } - } -}