mirror of
https://github.com/YouHaveTrouble/BlockEdit.git
synced 2026-06-29 13:36:19 +00:00
some random schematic work
This commit is contained in:
@@ -5,6 +5,7 @@ import net.querz.nbt.io.NBTInputStream;
|
|||||||
import net.querz.nbt.io.NamedTag;
|
import net.querz.nbt.io.NamedTag;
|
||||||
import net.querz.nbt.tag.CompoundTag;
|
import net.querz.nbt.tag.CompoundTag;
|
||||||
import net.querz.nbt.tag.Tag;
|
import net.querz.nbt.tag.Tag;
|
||||||
|
import org.bukkit.block.BlockState;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.zip.GZIPInputStream;
|
import java.util.zip.GZIPInputStream;
|
||||||
@@ -41,19 +42,7 @@ public class SchematicHandler {
|
|||||||
public Clipboard loadSchematic(String schematicName) {
|
public Clipboard loadSchematic(String schematicName) {
|
||||||
File schematicFile = new File(plugin.getDataFolder(), "schematics/" + schematicName + ".schematic");
|
File schematicFile = new File(plugin.getDataFolder(), "schematics/" + schematicName + ".schematic");
|
||||||
|
|
||||||
try (DataInputStream dis = new DataInputStream(new BufferedInputStream(new GZIPInputStream(new FileInputStream(schematicFile))))) {
|
|
||||||
NamedTag tag = new NBTInputStream(dis).readTag(Tag.DEFAULT_MAX_DEPTH);
|
|
||||||
|
|
||||||
if (tag == null) return null;
|
|
||||||
if (!(tag.getTag() instanceof CompoundTag compoundTag)) return null;
|
|
||||||
|
|
||||||
plugin.getLogger().info(compoundTag.get("Width").toString());
|
|
||||||
plugin.getLogger().info(compoundTag.get("Height").toString());
|
|
||||||
plugin.getLogger().info(compoundTag.get("Length").toString());
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package me.youhavetrouble.blockedit.exception;
|
||||||
|
|
||||||
|
public class SchematicLoadException extends RuntimeException {
|
||||||
|
|
||||||
|
public SchematicLoadException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package me.youhavetrouble.blockedit.util;
|
||||||
|
|
||||||
|
import me.youhavetrouble.blockedit.exception.SchematicLoadException;
|
||||||
|
import net.querz.nbt.io.NBTInputStream;
|
||||||
|
import net.querz.nbt.io.NamedTag;
|
||||||
|
import net.querz.nbt.tag.CompoundTag;
|
||||||
|
import net.querz.nbt.tag.Tag;
|
||||||
|
import org.bukkit.block.BlockState;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.zip.GZIPInputStream;
|
||||||
|
|
||||||
|
public class Schematic {
|
||||||
|
|
||||||
|
private final short width, height, length;
|
||||||
|
private final int[] palette;
|
||||||
|
private final int bitsPerBlock;
|
||||||
|
private final byte[] blocks;
|
||||||
|
|
||||||
|
private BlockState[] blockPalette = new BlockState[0];
|
||||||
|
|
||||||
|
public Schematic(File file) throws SchematicLoadException {
|
||||||
|
try (DataInputStream dis = new DataInputStream(new BufferedInputStream(new GZIPInputStream(new FileInputStream(file))))) {
|
||||||
|
NamedTag tag = new NBTInputStream(dis).readTag(Tag.DEFAULT_MAX_DEPTH);
|
||||||
|
|
||||||
|
if (tag == null) throw new SchematicLoadException("Could not load schematic. Invalid file format");
|
||||||
|
if (!(tag.getTag() instanceof CompoundTag compoundTag)) throw new SchematicLoadException("Could not load schematic. Invalid file format");
|
||||||
|
|
||||||
|
this.width = compoundTag.getShort("Width");
|
||||||
|
this.height = compoundTag.getShort("Height");
|
||||||
|
this.length = compoundTag.getShort("Length");
|
||||||
|
|
||||||
|
this.palette = compoundTag.getIntArray("Palette");
|
||||||
|
this.blocks = compoundTag.getByteArray("BlockData");
|
||||||
|
this.bitsPerBlock = blocks.length >> 6;
|
||||||
|
|
||||||
|
if (this.palette.length > 0) {
|
||||||
|
this.blockPalette = new BlockState[this.palette.length];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new SchematicLoadException("Could not load schematic due to I/O error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public short getWidth() {
|
||||||
|
return width;
|
||||||
|
}
|
||||||
|
|
||||||
|
public short getHeight() {
|
||||||
|
return height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public short getLength() {
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user