Search in sources :

Example 1 with ListTag

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

the class ClipboardWriter method writeVector.

// FAWE start
default Tag writeVector(Vector3 vector) {
    List<DoubleTag> list = new ArrayList<>();
    list.add(new DoubleTag(vector.getX()));
    list.add(new DoubleTag(vector.getY()));
    list.add(new DoubleTag(vector.getZ()));
    return new ListTag(DoubleTag.class, list);
}
Also used : ArrayList(java.util.ArrayList) DoubleTag(com.sk89q.jnbt.DoubleTag) ListTag(com.sk89q.jnbt.ListTag)

Example 2 with ListTag

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

the class ClipboardWriter method writeRotation.

default Tag writeRotation(Location location) {
    List<FloatTag> list = new ArrayList<>();
    list.add(new FloatTag(location.getYaw()));
    list.add(new FloatTag(location.getPitch()));
    return new ListTag(FloatTag.class, list);
}
Also used : FloatTag(com.sk89q.jnbt.FloatTag) ArrayList(java.util.ArrayList) ListTag(com.sk89q.jnbt.ListTag)

Example 3 with ListTag

use of com.sk89q.jnbt.ListTag 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 4 with ListTag

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

the class NBTConverter method fromNative.

public static ListTag fromNative(net.minecraft.nbt.ListTag other) {
    other = (net.minecraft.nbt.ListTag) other.copy();
    List<Tag> list = new ArrayList<>();
    Class<? extends Tag> listClass = StringTag.class;
    int tags = other.size();
    for (int i = 0; i < tags; i++) {
        Tag child = fromNative(other.remove(0));
        list.add(child);
        listClass = child.getClass();
    }
    return new ListTag(listClass, list);
}
Also used : StringTag(com.sk89q.jnbt.StringTag) ArrayList(java.util.ArrayList) ByteTag(com.sk89q.jnbt.ByteTag) ListTag(com.sk89q.jnbt.ListTag) EndTag(com.sk89q.jnbt.EndTag) FloatTag(com.sk89q.jnbt.FloatTag) StringTag(com.sk89q.jnbt.StringTag) ShortTag(com.sk89q.jnbt.ShortTag) DoubleTag(com.sk89q.jnbt.DoubleTag) IntTag(com.sk89q.jnbt.IntTag) ByteArrayTag(com.sk89q.jnbt.ByteArrayTag) CompoundTag(com.sk89q.jnbt.CompoundTag) Tag(com.sk89q.jnbt.Tag) IntArrayTag(com.sk89q.jnbt.IntArrayTag) LongTag(com.sk89q.jnbt.LongTag) ListTag(com.sk89q.jnbt.ListTag)

Example 5 with ListTag

use of com.sk89q.jnbt.ListTag 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)

Aggregations

ListTag (com.sk89q.jnbt.ListTag)14 CompoundTag (com.sk89q.jnbt.CompoundTag)12 Tag (com.sk89q.jnbt.Tag)12 IntTag (com.sk89q.jnbt.IntTag)10 StringTag (com.sk89q.jnbt.StringTag)10 ShortTag (com.sk89q.jnbt.ShortTag)8 ArrayList (java.util.ArrayList)8 ByteArrayTag (com.sk89q.jnbt.ByteArrayTag)6 IntArrayTag (com.sk89q.jnbt.IntArrayTag)6 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)6 HashMap (java.util.HashMap)6 BaseEntity (com.sk89q.worldedit.entity.BaseEntity)5 Location (com.sk89q.worldedit.util.Location)5 BlockState (com.sk89q.worldedit.world.block.BlockState)5 FloatTag (com.sk89q.jnbt.FloatTag)4 BlockArrayClipboard (com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard)4 Region (com.sk89q.worldedit.regions.Region)4 BaseBlock (com.sk89q.worldedit.world.block.BaseBlock)4 DoubleTag (com.sk89q.jnbt.DoubleTag)3 NamedTag (com.sk89q.jnbt.NamedTag)3