Search in sources :

Example 1 with CompoundTag

use of com.sk89q.jnbt.CompoundTag in project FastAsyncWorldEdit by IntellectualSites.

the class RegionCommands method nbtinfo.

@Command(name = "/nbtinfo", aliases = "/nbt", desc = "View nbt info for a block")
@CommandPermissions("worldedit.nbtinfo")
public void nbtinfo(Player player, EditSession editSession) {
    Location pos = player.getBlockTrace(128);
    if (pos == null) {
        player.print(Caption.of("fawe.navigation.no.block"));
        return;
    }
    CompoundTag nbt = editSession.getFullBlock(pos.toBlockPoint()).getNbtData();
    if (nbt != null) {
        player.print(TextComponent.of(nbt.getValue().toString()));
    } else {
        player.print(Caption.of("fawe.navigation.no.block"));
    }
}
Also used : CompoundTag(com.sk89q.jnbt.CompoundTag) Location(com.sk89q.worldedit.util.Location) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 2 with CompoundTag

use of com.sk89q.jnbt.CompoundTag in project FastAsyncWorldEdit by IntellectualSites.

the class FaweDelegateSchematicHandler method save.

public boolean save(CompoundTag tag, String path) {
    if (tag == null) {
        LOGGER.warn("Cannot save empty tag");
        return false;
    }
    try {
        File tmp = FileUtils.getFile(PlotSquared.platform().getDirectory(), path);
        tmp.getParentFile().mkdirs();
        if (tag instanceof CompressedCompoundTag) {
            CompressedCompoundTag cTag = (CompressedCompoundTag) tag;
            if (cTag instanceof CompressedSchematicTag) {
                Clipboard clipboard = (Clipboard) cTag.getSource();
                try (OutputStream stream = new FileOutputStream(tmp);
                    NBTOutputStream output = new NBTOutputStream(new BufferedOutputStream(new ParallelGZIPOutputStream(stream)))) {
                    new FastSchematicWriter(output).write(clipboard);
                }
            } else {
                try (OutputStream stream = new FileOutputStream(tmp);
                    BufferedOutputStream output = new BufferedOutputStream(new ParallelGZIPOutputStream(stream))) {
                    LZ4BlockInputStream is = cTag.adapt(cTag.getSource());
                    IOUtil.copy(is, output);
                }
            }
        } else {
            try (OutputStream stream = new FileOutputStream(tmp);
                NBTOutputStream output = new NBTOutputStream(new ParallelGZIPOutputStream(stream))) {
                Map<String, Tag> map = tag.getValue();
                output.writeNamedTag("Schematic", map.getOrDefault("Schematic", tag));
            }
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }
    return true;
}
Also used : FastSchematicWriter(com.fastasyncworldedit.core.extent.clipboard.io.FastSchematicWriter) CompressedSchematicTag(com.fastasyncworldedit.core.jnbt.CompressedSchematicTag) NBTOutputStream(com.sk89q.jnbt.NBTOutputStream) ParallelGZIPOutputStream(org.anarres.parallelgzip.ParallelGZIPOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) NBTOutputStream(com.sk89q.jnbt.NBTOutputStream) LZ4BlockInputStream(net.jpountz.lz4.LZ4BlockInputStream) CompressedCompoundTag(com.fastasyncworldedit.core.jnbt.CompressedCompoundTag) ParallelGZIPOutputStream(org.anarres.parallelgzip.ParallelGZIPOutputStream) FileOutputStream(java.io.FileOutputStream) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard) CompressedSchematicTag(com.fastasyncworldedit.core.jnbt.CompressedSchematicTag) CompressedCompoundTag(com.fastasyncworldedit.core.jnbt.CompressedCompoundTag) CompoundTag(com.sk89q.jnbt.CompoundTag) Tag(com.sk89q.jnbt.Tag) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Example 3 with CompoundTag

use of com.sk89q.jnbt.CompoundTag in project FastAsyncWorldEdit by IntellectualSites.

the class BlockTransformExtent method transformBaseBlockNBT.

private static BaseBlock transformBaseBlockNBT(BlockState transformed, CompoundTag tag, Transform transform) {
    if (tag != null) {
        if (tag.containsKey("Rot")) {
            int rot = tag.asInt("Rot");
            Direction direction = MCDirections.fromRotation(rot);
            if (direction != null) {
                Vector3 applyAbsolute = transform.apply(direction.toVector());
                Vector3 applyOrigin = transform.apply(Vector3.ZERO);
                applyAbsolute.mutX(applyAbsolute.getX() - applyOrigin.getX());
                applyAbsolute.mutY(applyAbsolute.getY() - applyOrigin.getY());
                applyAbsolute.mutZ(applyAbsolute.getZ() - applyOrigin.getZ());
                Direction newDirection = Direction.findClosest(applyAbsolute, Direction.Flag.CARDINAL | Direction.Flag.ORDINAL | Direction.Flag.SECONDARY_ORDINAL);
                if (newDirection != null) {
                    Map<String, Tag> values = new HashMap<>(tag.getValue());
                    values.put("Rot", new ByteTag((byte) MCDirections.toRotation(newDirection)));
                    tag = new CompoundTag(values);
                }
            }
        }
        return new BaseBlock(transformed, tag);
    }
    return transformed.toBaseBlock();
}
Also used : HashMap(java.util.HashMap) ByteTag(com.sk89q.jnbt.ByteTag) BlockVector3(com.sk89q.worldedit.math.BlockVector3) Vector3(com.sk89q.worldedit.math.Vector3) CompoundTag(com.sk89q.jnbt.CompoundTag) ByteTag(com.sk89q.jnbt.ByteTag) Tag(com.sk89q.jnbt.Tag) Direction(com.sk89q.worldedit.util.Direction) BaseBlock(com.sk89q.worldedit.world.block.BaseBlock) CompoundTag(com.sk89q.jnbt.CompoundTag)

Example 4 with CompoundTag

use of com.sk89q.jnbt.CompoundTag in project FastAsyncWorldEdit by IntellectualSites.

the class SpongeSchematicReader method readBiomes.

private void readBiomes(BlockArrayClipboard clipboard, Map<String, Tag> schematic) throws IOException {
    ByteArrayTag dataTag = requireTag(schematic, "BiomeData", ByteArrayTag.class);
    IntTag maxTag = requireTag(schematic, "BiomePaletteMax", IntTag.class);
    CompoundTag paletteTag = requireTag(schematic, "BiomePalette", CompoundTag.class);
    Map<Integer, BiomeType> palette = new HashMap<>();
    if (maxTag.getValue() != paletteTag.getValue().size()) {
        throw new IOException("Biome palette size does not match expected size.");
    }
    for (Entry<String, Tag> palettePart : paletteTag.getValue().entrySet()) {
        String key = palettePart.getKey();
        if (fixer != null) {
            key = fixer.fixUp(DataFixer.FixTypes.BIOME, key, dataVersion);
        }
        BiomeType biome = BiomeTypes.get(key);
        if (biome == null) {
            LOGGER.warn("Unknown biome type :" + key + " in palette. Are you missing a mod or using a schematic made in a newer version of Minecraft?");
        }
        Tag idTag = palettePart.getValue();
        if (!(idTag instanceof IntTag)) {
            throw new IOException("Biome mapped to non-Int tag.");
        }
        palette.put(((IntTag) idTag).getValue(), biome);
    }
    int width = clipboard.getDimensions().getX();
    byte[] biomes = dataTag.getValue();
    int biomeIndex = 0;
    int biomeJ = 0;
    int bVal;
    int varIntLength;
    BlockVector3 min = clipboard.getMinimumPoint();
    while (biomeJ < biomes.length) {
        bVal = 0;
        varIntLength = 0;
        while (true) {
            bVal |= (biomes[biomeJ] & 127) << (varIntLength++ * 7);
            if (varIntLength > 5) {
                throw new IOException("VarInt too big (probably corrupted data)");
            }
            if (((biomes[biomeJ] & 128) != 128)) {
                biomeJ++;
                break;
            }
            biomeJ++;
        }
        int z = biomeIndex / width;
        int x = biomeIndex % width;
        BiomeType type = palette.get(bVal);
        for (int y = 0; y < clipboard.getRegion().getHeight(); y++) {
            clipboard.setBiome(min.add(x, y, z), type);
        }
        biomeIndex++;
    }
}
Also used : HashMap(java.util.HashMap) IOException(java.io.IOException) BlockVector3(com.sk89q.worldedit.math.BlockVector3) BiomeType(com.sk89q.worldedit.world.biome.BiomeType) StringTag(com.sk89q.jnbt.StringTag) ShortTag(com.sk89q.jnbt.ShortTag) IntArrayTag(com.sk89q.jnbt.IntArrayTag) ListTag(com.sk89q.jnbt.ListTag) IntTag(com.sk89q.jnbt.IntTag) NamedTag(com.sk89q.jnbt.NamedTag) ByteArrayTag(com.sk89q.jnbt.ByteArrayTag) CompoundTag(com.sk89q.jnbt.CompoundTag) Tag(com.sk89q.jnbt.Tag) IntTag(com.sk89q.jnbt.IntTag) CompoundTag(com.sk89q.jnbt.CompoundTag) ByteArrayTag(com.sk89q.jnbt.ByteArrayTag)

Example 5 with CompoundTag

use of com.sk89q.jnbt.CompoundTag in project FastAsyncWorldEdit by IntellectualSites.

the class SpongeSchematicReader method getDataVersion.

@Override
public OptionalInt getDataVersion() {
    try {
        CompoundTag schematicTag = getBaseTag();
        Map<String, Tag> schematic = schematicTag.getValue();
        if (schematicVersion == 1) {
            return OptionalInt.of(Constants.DATA_VERSION_MC_1_13_2);
        } else if (schematicVersion == 2) {
            int dataVersion = requireTag(schematic, "DataVersion", IntTag.class).getValue();
            if (dataVersion < 0) {
                return OptionalInt.empty();
            }
            return OptionalInt.of(dataVersion);
        }
        return OptionalInt.empty();
    } catch (IOException e) {
        return OptionalInt.empty();
    }
}
Also used : StringTag(com.sk89q.jnbt.StringTag) ShortTag(com.sk89q.jnbt.ShortTag) IntArrayTag(com.sk89q.jnbt.IntArrayTag) ListTag(com.sk89q.jnbt.ListTag) IntTag(com.sk89q.jnbt.IntTag) NamedTag(com.sk89q.jnbt.NamedTag) ByteArrayTag(com.sk89q.jnbt.ByteArrayTag) CompoundTag(com.sk89q.jnbt.CompoundTag) Tag(com.sk89q.jnbt.Tag) IOException(java.io.IOException) CompoundTag(com.sk89q.jnbt.CompoundTag)

Aggregations

CompoundTag (com.sk89q.jnbt.CompoundTag)63 Tag (com.sk89q.jnbt.Tag)33 StringTag (com.sk89q.jnbt.StringTag)22 HashMap (java.util.HashMap)20 IntTag (com.sk89q.jnbt.IntTag)19 ListTag (com.sk89q.jnbt.ListTag)17 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)13 ShortTag (com.sk89q.jnbt.ShortTag)12 IOException (java.io.IOException)12 ByteArrayTag (com.sk89q.jnbt.ByteArrayTag)10 IntArrayTag (com.sk89q.jnbt.IntArrayTag)10 Map (java.util.Map)10 NamedTag (com.sk89q.jnbt.NamedTag)9 Location (com.sk89q.worldedit.util.Location)9 BaseBlock (com.sk89q.worldedit.world.block.BaseBlock)9 BlockState (com.sk89q.worldedit.world.block.BlockState)9 BaseEntity (com.sk89q.worldedit.entity.BaseEntity)8 BlockArrayClipboard (com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard)5 Region (com.sk89q.worldedit.regions.Region)5 UUID (java.util.UUID)5