Search in sources :

Example 11 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)

Example 12 with CompoundTag

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

the class SpongeSchematicWriter method writeBiomes.

private void writeBiomes(Clipboard clipboard, Map<String, Tag> schematic) {
    BlockVector3 min = clipboard.getMinimumPoint();
    int width = clipboard.getRegion().getWidth();
    int length = clipboard.getRegion().getLength();
    ByteArrayOutputStream buffer = new ByteArrayOutputStream(width * length);
    int paletteMax = 0;
    Map<String, Integer> palette = new HashMap<>();
    for (int z = 0; z < length; z++) {
        int z0 = min.getBlockZ() + z;
        for (int x = 0; x < width; x++) {
            int x0 = min.getBlockX() + x;
            BlockVector3 pt = BlockVector3.at(x0, min.getBlockY(), z0);
            BiomeType biome = clipboard.getBiome(pt);
            String biomeKey = biome.getId();
            int biomeId;
            if (palette.containsKey(biomeKey)) {
                biomeId = palette.get(biomeKey);
            } else {
                biomeId = paletteMax;
                palette.put(biomeKey, biomeId);
                paletteMax++;
            }
            while ((biomeId & -128) != 0) {
                buffer.write(biomeId & 127 | 128);
                biomeId >>>= 7;
            }
            buffer.write(biomeId);
        }
    }
    schematic.put("BiomePaletteMax", new IntTag(paletteMax));
    Map<String, Tag> paletteTag = new HashMap<>();
    palette.forEach((key, value) -> paletteTag.put(key, new IntTag(value)));
    schematic.put("BiomePalette", new CompoundTag(paletteTag));
    schematic.put("BiomeData", new ByteArrayTag(buffer.toByteArray()));
}
Also used : HashMap(java.util.HashMap) ByteArrayOutputStream(java.io.ByteArrayOutputStream) 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) 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 13 with CompoundTag

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

the class BannerBlockCompatibilityHandler method updateNBT.

@Override
public <B extends BlockStateHolder<B>> BlockStateHolder<?> updateNBT(B block, Map<String, Tag> values) {
    Tag typeTag = values.get("Base");
    if (typeTag instanceof IntTag) {
        boolean isWall = block.getBlockType() == BlockTypes.WHITE_WALL_BANNER;
        String bannerType = convertBannerType(((IntTag) typeTag).getValue(), isWall);
        if (bannerType != null) {
            BlockType type = BlockTypes.get("minecraft:" + bannerType);
            if (type != null) {
                BlockState state = type.getDefaultState();
                if (isWall) {
                    Property<Direction> facingProp = type.getProperty("facing");
                    state = state.with(facingProp, block.getState(FacingProperty));
                } else {
                    Property<Integer> rotationProp = type.getProperty("rotation");
                    state = state.with(rotationProp, block.getState(RotationProperty));
                }
                values.remove("Base");
                Tag patternsTag = values.get("Patterns");
                if (patternsTag instanceof ListTag) {
                    List<Tag> tempList = new ArrayList<>();
                    for (Tag pattern : ((ListTag) patternsTag).getValue()) {
                        if (pattern instanceof CompoundTag) {
                            Map<String, Tag> patternMap = ((CompoundTag) pattern).getValue();
                            Tag colorTag = patternMap.get("Color");
                            CompoundTagBuilder builder = CompoundTagBuilder.create();
                            builder.putAll(patternMap);
                            if (colorTag instanceof IntTag) {
                                builder.putInt("Color", 15 - ((IntTag) colorTag).getValue());
                            }
                            tempList.add(builder.build());
                        } else {
                            tempList.add(pattern);
                        }
                    }
                    values.put("Patterns", new ListTag(((ListTag) patternsTag).getType(), tempList));
                }
                return state;
            }
        }
    }
    return block;
}
Also used : ArrayList(java.util.ArrayList) Direction(com.sk89q.worldedit.util.Direction) ListTag(com.sk89q.jnbt.ListTag) CompoundTagBuilder(com.sk89q.jnbt.CompoundTagBuilder) BlockState(com.sk89q.worldedit.world.block.BlockState) BlockType(com.sk89q.worldedit.world.block.BlockType) ListTag(com.sk89q.jnbt.ListTag) IntTag(com.sk89q.jnbt.IntTag) CompoundTag(com.sk89q.jnbt.CompoundTag) Tag(com.sk89q.jnbt.Tag) IntTag(com.sk89q.jnbt.IntTag) CompoundTag(com.sk89q.jnbt.CompoundTag)

Example 14 with CompoundTag

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

the class MobSpawnerBlock method setNbtData.

@Override
public void setNbtData(CompoundTag rootTag) {
    if (rootTag == null) {
        return;
    }
    Map<String, Tag> values = rootTag.getValue();
    Tag t = values.get("id");
    if (!(t instanceof StringTag) || !((StringTag) t).getValue().equals(getNbtId())) {
        throw new RuntimeException(String.format("'%s' tile entity expected", getNbtId()));
    }
    CompoundTag spawnDataTag;
    String mobType;
    ShortTag delayTag;
    try {
        spawnDataTag = NBTUtils.getChildTag(values, "SpawnData", CompoundTag.class);
        mobType = spawnDataTag.getString("id");
        if (mobType.equals("")) {
            throw new InvalidFormatException("No spawn id.");
        }
        this.mobType = mobType;
        this.spawnData = spawnDataTag;
    } catch (InvalidFormatException ignored) {
        throw new RuntimeException("Invalid mob spawner data: no SpawnData and/or no Delay");
    }
    try {
        delayTag = NBTUtils.getChildTag(values, "Delay", ShortTag.class);
        this.delay = delayTag.getValue();
    } catch (InvalidFormatException ignored) {
        this.delay = -1;
    }
    ShortTag spawnCountTag = null;
    ShortTag spawnRangeTag = null;
    ShortTag minSpawnDelayTag = null;
    ShortTag maxSpawnDelayTag = null;
    ShortTag maxNearbyEntitiesTag = null;
    ShortTag requiredPlayerRangeTag = null;
    ListTag spawnPotentialsTag = null;
    try {
        spawnCountTag = NBTUtils.getChildTag(values, "SpawnCount", ShortTag.class);
    } catch (InvalidFormatException ignored) {
    }
    try {
        spawnRangeTag = NBTUtils.getChildTag(values, "SpawnRange", ShortTag.class);
    } catch (InvalidFormatException ignored) {
    }
    try {
        minSpawnDelayTag = NBTUtils.getChildTag(values, "MinSpawnDelay", ShortTag.class);
    } catch (InvalidFormatException ignored) {
    }
    try {
        maxSpawnDelayTag = NBTUtils.getChildTag(values, "MaxSpawnDelay", ShortTag.class);
    } catch (InvalidFormatException ignored) {
    }
    try {
        maxNearbyEntitiesTag = NBTUtils.getChildTag(values, "MaxNearbyEntities", ShortTag.class);
    } catch (InvalidFormatException ignored) {
    }
    try {
        requiredPlayerRangeTag = NBTUtils.getChildTag(values, "RequiredPlayerRange", ShortTag.class);
    } catch (InvalidFormatException ignored) {
    }
    try {
        spawnPotentialsTag = NBTUtils.getChildTag(values, "SpawnPotentials", ListTag.class);
    } catch (InvalidFormatException ignored) {
    }
    if (spawnCountTag != null) {
        this.spawnCount = spawnCountTag.getValue();
    }
    if (spawnRangeTag != null) {
        this.spawnRange = spawnRangeTag.getValue();
    }
    if (minSpawnDelayTag != null) {
        this.minSpawnDelay = minSpawnDelayTag.getValue();
    }
    if (maxSpawnDelayTag != null) {
        this.maxSpawnDelay = maxSpawnDelayTag.getValue();
    }
    if (maxNearbyEntitiesTag != null) {
        this.maxNearbyEntities = maxNearbyEntitiesTag.getValue();
    }
    if (requiredPlayerRangeTag != null) {
        this.requiredPlayerRange = requiredPlayerRangeTag.getValue();
    }
    if (spawnPotentialsTag != null) {
        this.spawnPotentials = new ListTag(CompoundTag.class, spawnPotentialsTag.getValue());
    }
}
Also used : StringTag(com.sk89q.jnbt.StringTag) ListTag(com.sk89q.jnbt.ListTag) StringTag(com.sk89q.jnbt.StringTag) ShortTag(com.sk89q.jnbt.ShortTag) IntTag(com.sk89q.jnbt.IntTag) CompoundTag(com.sk89q.jnbt.CompoundTag) Tag(com.sk89q.jnbt.Tag) InvalidFormatException(com.sk89q.worldedit.world.storage.InvalidFormatException) ListTag(com.sk89q.jnbt.ListTag) CompoundTag(com.sk89q.jnbt.CompoundTag) ShortTag(com.sk89q.jnbt.ShortTag)

Example 15 with CompoundTag

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

the class MobSpawnerBlock method getNbtData.

@Override
public CompoundTag getNbtData() {
    Map<String, Tag> values = new HashMap<>();
    values.put("Delay", new ShortTag(delay));
    values.put("SpawnCount", new ShortTag(spawnCount));
    values.put("SpawnRange", new ShortTag(spawnRange));
    values.put("MinSpawnDelay", new ShortTag(minSpawnDelay));
    values.put("MaxSpawnDelay", new ShortTag(maxSpawnDelay));
    values.put("MaxNearbyEntities", new ShortTag(maxNearbyEntities));
    values.put("RequiredPlayerRange", new ShortTag(requiredPlayerRange));
    if (spawnData == null) {
        values.put("SpawnData", new CompoundTag(ImmutableMap.of("id", new StringTag(mobType))));
    } else {
        values.put("SpawnData", new CompoundTag(spawnData.getValue()));
    }
    if (spawnPotentials == null) {
        values.put("SpawnPotentials", new ListTag(CompoundTag.class, ImmutableList.of(new CompoundTag(ImmutableMap.of("Weight", new IntTag(1), "Entity", new CompoundTag(ImmutableMap.of("id", new StringTag(mobType))))))));
    } else {
        values.put("SpawnPotentials", new ListTag(CompoundTag.class, spawnPotentials.getValue()));
    }
    return new CompoundTag(values);
}
Also used : StringTag(com.sk89q.jnbt.StringTag) HashMap(java.util.HashMap) ListTag(com.sk89q.jnbt.ListTag) StringTag(com.sk89q.jnbt.StringTag) ShortTag(com.sk89q.jnbt.ShortTag) IntTag(com.sk89q.jnbt.IntTag) CompoundTag(com.sk89q.jnbt.CompoundTag) Tag(com.sk89q.jnbt.Tag) ListTag(com.sk89q.jnbt.ListTag) ShortTag(com.sk89q.jnbt.ShortTag) CompoundTag(com.sk89q.jnbt.CompoundTag) IntTag(com.sk89q.jnbt.IntTag)

Aggregations

CompoundTag (com.sk89q.jnbt.CompoundTag)69 Tag (com.sk89q.jnbt.Tag)38 StringTag (com.sk89q.jnbt.StringTag)26 HashMap (java.util.HashMap)25 IntTag (com.sk89q.jnbt.IntTag)24 ListTag (com.sk89q.jnbt.ListTag)21 ShortTag (com.sk89q.jnbt.ShortTag)16 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)16 ByteArrayTag (com.sk89q.jnbt.ByteArrayTag)14 IntArrayTag (com.sk89q.jnbt.IntArrayTag)14 IOException (java.io.IOException)14 Map (java.util.Map)13 BaseBlock (com.sk89q.worldedit.world.block.BaseBlock)11 NamedTag (com.sk89q.jnbt.NamedTag)9 Location (com.sk89q.worldedit.util.Location)9 BlockState (com.sk89q.worldedit.world.block.BlockState)9 BaseEntity (com.sk89q.worldedit.entity.BaseEntity)8 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)6 Region (com.sk89q.worldedit.regions.Region)6 ArrayList (java.util.ArrayList)6