Search in sources :

Example 1 with ListBinaryTag

use of com.sk89q.worldedit.util.nbt.ListBinaryTag in project FastAsyncWorldEdit by IntellectualSites.

the class AnvilChunk13 method populateEntities.

/**
 * Used to load the biomes.
 */
private void populateEntities() throws DataException {
    entities = new ArrayList<>();
    if (rootTag.get("Entities") == null) {
        return;
    }
    ListBinaryTag tags = NbtUtils.getChildTag(rootTag, "Entities", BinaryTagTypes.LIST);
    for (BinaryTag tag : tags) {
        if (!(tag instanceof CompoundBinaryTag)) {
            throw new InvalidFormatException("CompoundTag expected in Entities");
        }
        CompoundBinaryTag t = (CompoundBinaryTag) tag;
        entities.add(new BaseEntity(EntityTypes.get(t.getString("id")), LazyReference.computed(t)));
    }
}
Also used : ListBinaryTag(com.sk89q.worldedit.util.nbt.ListBinaryTag) BaseEntity(com.sk89q.worldedit.entity.BaseEntity) IntBinaryTag(com.sk89q.worldedit.util.nbt.IntBinaryTag) CompoundBinaryTag(com.sk89q.worldedit.util.nbt.CompoundBinaryTag) BinaryTag(com.sk89q.worldedit.util.nbt.BinaryTag) ListBinaryTag(com.sk89q.worldedit.util.nbt.ListBinaryTag) InvalidFormatException(com.sk89q.worldedit.world.storage.InvalidFormatException) CompoundBinaryTag(com.sk89q.worldedit.util.nbt.CompoundBinaryTag)

Example 2 with ListBinaryTag

use of com.sk89q.worldedit.util.nbt.ListBinaryTag in project FastAsyncWorldEdit by IntellectualSites.

the class OldChunk method populateTileEntities.

/**
 * Used to load the tile entities.
 *
 * @throws DataException if there is an error getting the chunk data
 */
private void populateTileEntities() throws DataException {
    ListBinaryTag tags = NbtUtils.getChildTag(rootTag, "TileEntities", BinaryTagTypes.LIST);
    tileEntities = new HashMap<>();
    for (BinaryTag tag : tags) {
        if (!(tag instanceof CompoundBinaryTag)) {
            throw new InvalidFormatException("CompoundTag expected in TileEntities");
        }
        CompoundBinaryTag t = (CompoundBinaryTag) tag;
        int x = 0;
        int y = 0;
        int z = 0;
        CompoundBinaryTag.Builder values = CompoundBinaryTag.builder();
        for (String key : t.keySet()) {
            BinaryTag value = t.get(key);
            switch(key) {
                case "x":
                    if (value instanceof IntBinaryTag) {
                        x = ((IntBinaryTag) value).value();
                    }
                    break;
                case "y":
                    if (value instanceof IntBinaryTag) {
                        y = ((IntBinaryTag) value).value();
                    }
                    break;
                case "z":
                    if (value instanceof IntBinaryTag) {
                        z = ((IntBinaryTag) value).value();
                    }
                    break;
                default:
                    break;
            }
            values.put(key, value);
        }
        BlockVector3 vec = BlockVector3.at(x, y, z);
        tileEntities.put(vec, values.build());
    }
}
Also used : ListBinaryTag(com.sk89q.worldedit.util.nbt.ListBinaryTag) IntBinaryTag(com.sk89q.worldedit.util.nbt.IntBinaryTag) BinaryTag(com.sk89q.worldedit.util.nbt.BinaryTag) CompoundBinaryTag(com.sk89q.worldedit.util.nbt.CompoundBinaryTag) ListBinaryTag(com.sk89q.worldedit.util.nbt.ListBinaryTag) IntBinaryTag(com.sk89q.worldedit.util.nbt.IntBinaryTag) BlockVector3(com.sk89q.worldedit.math.BlockVector3) InvalidFormatException(com.sk89q.worldedit.world.storage.InvalidFormatException) CompoundBinaryTag(com.sk89q.worldedit.util.nbt.CompoundBinaryTag)

Example 3 with ListBinaryTag

use of com.sk89q.worldedit.util.nbt.ListBinaryTag in project FastAsyncWorldEdit by IntellectualSites.

the class PaperweightAdapter method fromNativeBinary.

/**
 * Converts a WorldEdit-native NBT structure to a NMS structure.
 *
 * @param foreign structure to convert
 * @return non-native structure
 */
@Override
public net.minecraft.nbt.Tag fromNativeBinary(BinaryTag foreign) {
    if (foreign == null) {
        return null;
    }
    if (foreign instanceof CompoundBinaryTag) {
        net.minecraft.nbt.CompoundTag tag = new net.minecraft.nbt.CompoundTag();
        for (String key : ((CompoundBinaryTag) foreign).keySet()) {
            tag.put(key, fromNativeBinary(((CompoundBinaryTag) foreign).get(key)));
        }
        return tag;
    } else if (foreign instanceof ByteBinaryTag) {
        return net.minecraft.nbt.ByteTag.valueOf(((ByteBinaryTag) foreign).value());
    } else if (foreign instanceof ByteArrayBinaryTag) {
        return new net.minecraft.nbt.ByteArrayTag(((ByteArrayBinaryTag) foreign).value());
    } else if (foreign instanceof DoubleBinaryTag) {
        return net.minecraft.nbt.DoubleTag.valueOf(((DoubleBinaryTag) foreign).value());
    } else if (foreign instanceof FloatBinaryTag) {
        return net.minecraft.nbt.FloatTag.valueOf(((FloatBinaryTag) foreign).value());
    } else if (foreign instanceof IntBinaryTag) {
        return net.minecraft.nbt.IntTag.valueOf(((IntBinaryTag) foreign).value());
    } else if (foreign instanceof IntArrayBinaryTag) {
        return new net.minecraft.nbt.IntArrayTag(((IntArrayBinaryTag) foreign).value());
    } else if (foreign instanceof LongArrayBinaryTag) {
        return new net.minecraft.nbt.LongArrayTag(((LongArrayBinaryTag) foreign).value());
    } else if (foreign instanceof ListBinaryTag) {
        net.minecraft.nbt.ListTag tag = new net.minecraft.nbt.ListTag();
        ListBinaryTag foreignList = (ListBinaryTag) foreign;
        for (BinaryTag t : foreignList) {
            tag.add(fromNativeBinary(t));
        }
        return tag;
    } else if (foreign instanceof LongBinaryTag) {
        return net.minecraft.nbt.LongTag.valueOf(((LongBinaryTag) foreign).value());
    } else if (foreign instanceof ShortBinaryTag) {
        return net.minecraft.nbt.ShortTag.valueOf(((ShortBinaryTag) foreign).value());
    } else if (foreign instanceof StringBinaryTag) {
        return net.minecraft.nbt.StringTag.valueOf(((StringBinaryTag) foreign).value());
    } else if (foreign instanceof EndBinaryTag) {
        return net.minecraft.nbt.EndTag.INSTANCE;
    } else {
        throw new IllegalArgumentException("Don't know how to make NMS " + foreign.getClass().getCanonicalName());
    }
}
Also used : ListBinaryTag(com.sk89q.worldedit.util.nbt.ListBinaryTag) LongArrayBinaryTag(com.sk89q.worldedit.util.nbt.LongArrayBinaryTag) LongBinaryTag(com.sk89q.worldedit.util.nbt.LongBinaryTag) BinaryTag(com.sk89q.worldedit.util.nbt.BinaryTag) StringBinaryTag(com.sk89q.worldedit.util.nbt.StringBinaryTag) IntBinaryTag(com.sk89q.worldedit.util.nbt.IntBinaryTag) IntArrayBinaryTag(com.sk89q.worldedit.util.nbt.IntArrayBinaryTag) ShortBinaryTag(com.sk89q.worldedit.util.nbt.ShortBinaryTag) ByteArrayBinaryTag(com.sk89q.worldedit.util.nbt.ByteArrayBinaryTag) ListBinaryTag(com.sk89q.worldedit.util.nbt.ListBinaryTag) CompoundBinaryTag(com.sk89q.worldedit.util.nbt.CompoundBinaryTag) EndBinaryTag(com.sk89q.worldedit.util.nbt.EndBinaryTag) DoubleBinaryTag(com.sk89q.worldedit.util.nbt.DoubleBinaryTag) FloatBinaryTag(com.sk89q.worldedit.util.nbt.FloatBinaryTag) ByteBinaryTag(com.sk89q.worldedit.util.nbt.ByteBinaryTag) DoubleBinaryTag(com.sk89q.worldedit.util.nbt.DoubleBinaryTag) EndBinaryTag(com.sk89q.worldedit.util.nbt.EndBinaryTag) ByteBinaryTag(com.sk89q.worldedit.util.nbt.ByteBinaryTag) CompoundBinaryTag(com.sk89q.worldedit.util.nbt.CompoundBinaryTag) ShortBinaryTag(com.sk89q.worldedit.util.nbt.ShortBinaryTag) ByteArrayBinaryTag(com.sk89q.worldedit.util.nbt.ByteArrayBinaryTag) IntBinaryTag(com.sk89q.worldedit.util.nbt.IntBinaryTag) LongBinaryTag(com.sk89q.worldedit.util.nbt.LongBinaryTag) FloatBinaryTag(com.sk89q.worldedit.util.nbt.FloatBinaryTag) IntArrayBinaryTag(com.sk89q.worldedit.util.nbt.IntArrayBinaryTag) StringBinaryTag(com.sk89q.worldedit.util.nbt.StringBinaryTag) LongArrayBinaryTag(com.sk89q.worldedit.util.nbt.LongArrayBinaryTag)

Example 4 with ListBinaryTag

use of com.sk89q.worldedit.util.nbt.ListBinaryTag in project FastAsyncWorldEdit by IntellectualSites.

the class AnvilChunk method populateTileEntities.

/**
 * Used to load the tile entities.
 */
private void populateTileEntities() throws DataException {
    ListBinaryTag tags = NbtUtils.getChildTag(rootTag, "TileEntities", BinaryTagTypes.LIST);
    tileEntities = new HashMap<>();
    for (BinaryTag tag : tags) {
        if (!(tag instanceof CompoundBinaryTag)) {
            throw new InvalidFormatException("CompoundTag expected in TileEntities");
        }
        CompoundBinaryTag t = (CompoundBinaryTag) tag;
        int x = 0;
        int y = 0;
        int z = 0;
        CompoundBinaryTag.Builder values = CompoundBinaryTag.builder();
        for (String key : t.keySet()) {
            BinaryTag value = t.get(key);
            switch(key) {
                case "x":
                    if (value instanceof IntBinaryTag) {
                        x = ((IntBinaryTag) value).value();
                    }
                    break;
                case "y":
                    if (value instanceof IntBinaryTag) {
                        y = ((IntBinaryTag) value).value();
                    }
                    break;
                case "z":
                    if (value instanceof IntBinaryTag) {
                        z = ((IntBinaryTag) value).value();
                    }
                    break;
                default:
                    break;
            }
            values.put(key, value);
        }
        BlockVector3 vec = BlockVector3.at(x, y, z);
        tileEntities.put(vec, values.build());
    }
}
Also used : ListBinaryTag(com.sk89q.worldedit.util.nbt.ListBinaryTag) IntBinaryTag(com.sk89q.worldedit.util.nbt.IntBinaryTag) BinaryTag(com.sk89q.worldedit.util.nbt.BinaryTag) CompoundBinaryTag(com.sk89q.worldedit.util.nbt.CompoundBinaryTag) ListBinaryTag(com.sk89q.worldedit.util.nbt.ListBinaryTag) IntBinaryTag(com.sk89q.worldedit.util.nbt.IntBinaryTag) BlockVector3(com.sk89q.worldedit.math.BlockVector3) InvalidFormatException(com.sk89q.worldedit.world.storage.InvalidFormatException) CompoundBinaryTag(com.sk89q.worldedit.util.nbt.CompoundBinaryTag)

Example 5 with ListBinaryTag

use of com.sk89q.worldedit.util.nbt.ListBinaryTag in project FastAsyncWorldEdit by IntellectualSites.

the class SnapshotRestore method restore.

/**
 * Restores to world.
 *
 * @throws MaxChangedBlocksException if the max block change limit is exceeded
 */
public void restore() throws MaxChangedBlocksException {
    missingChunks = new ArrayList<>();
    errorChunks = new ArrayList<>();
    // Now let's start restoring!
    for (Map.Entry<BlockVector2, Set<BlockVector3>> entry : neededChunks.entrySet()) {
        BlockVector2 chunkPos = entry.getKey();
        Chunk chunk;
        try {
            chunk = chunkStore.getChunk(chunkPos, editSession.getWorld());
            // Now just copy blocks!
            for (BlockVector3 pos : entry.getValue()) {
                try {
                    editSession.setBlock(pos, chunk.getBlock(pos));
                    // FAWE start - biome and entity restore
                    if (restoreBiomes && (pos.getX() & 3) == 0 && (pos.getY() & 3) == 0 && (pos.getZ() & 3) == 0) {
                        editSession.setBiome(pos, chunk.getBiome(pos));
                    }
                // FAWE end
                } catch (DataException e) {
                // this is a workaround: just ignore for now
                }
            }
            // FAWE start - biome and entity restore
            if (restoreEntities) {
                try {
                    for (BaseEntity entity : chunk.getEntities()) {
                        CompoundBinaryTag tag = entity.getNbtReference().getValue();
                        ListBinaryTag pos = tag.getList("Pos");
                        ListBinaryTag rotation = tag.getList("Rotation");
                        double x = pos.getDouble(0);
                        double y = pos.getDouble(1);
                        double z = pos.getDouble(2);
                        float yRot = rotation.getFloat(0);
                        float xRot = rotation.getFloat(1);
                        Location location = new Location(editSession.getWorld(), x, y, z, yRot, xRot);
                        editSession.createEntity(location, entity);
                    }
                } catch (DataException e) {
                // this is a workaround: just ignore for now
                }
            }
        // FAWE end
        } catch (MissingChunkException me) {
            missingChunks.add(chunkPos);
        } catch (IOException | DataException me) {
            errorChunks.add(chunkPos);
            lastErrorMessage = me.getMessage();
        }
    }
}
Also used : Set(java.util.Set) LocalBlockVectorSet(com.fastasyncworldedit.core.math.LocalBlockVectorSet) ListBinaryTag(com.sk89q.worldedit.util.nbt.ListBinaryTag) BaseEntity(com.sk89q.worldedit.entity.BaseEntity) IOException(java.io.IOException) Chunk(com.sk89q.worldedit.world.chunk.Chunk) BlockVector3(com.sk89q.worldedit.math.BlockVector3) BlockVector2(com.sk89q.worldedit.math.BlockVector2) MissingChunkException(com.sk89q.worldedit.world.storage.MissingChunkException) DataException(com.sk89q.worldedit.world.DataException) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) CompoundBinaryTag(com.sk89q.worldedit.util.nbt.CompoundBinaryTag) Location(com.sk89q.worldedit.util.Location)

Aggregations

CompoundBinaryTag (com.sk89q.worldedit.util.nbt.CompoundBinaryTag)7 ListBinaryTag (com.sk89q.worldedit.util.nbt.ListBinaryTag)7 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)5 BinaryTag (com.sk89q.worldedit.util.nbt.BinaryTag)5 IntBinaryTag (com.sk89q.worldedit.util.nbt.IntBinaryTag)5 InvalidFormatException (com.sk89q.worldedit.world.storage.InvalidFormatException)4 BaseEntity (com.sk89q.worldedit.entity.BaseEntity)3 BlockVector2 (com.sk89q.worldedit.math.BlockVector2)2 Location (com.sk89q.worldedit.util.Location)2 DataException (com.sk89q.worldedit.world.DataException)2 Chunk (com.sk89q.worldedit.world.chunk.Chunk)2 MissingChunkException (com.sk89q.worldedit.world.storage.MissingChunkException)2 IOException (java.io.IOException)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 LocalBlockVectorSet (com.fastasyncworldedit.core.math.LocalBlockVectorSet)1 ByteArrayBinaryTag (com.sk89q.worldedit.util.nbt.ByteArrayBinaryTag)1 ByteBinaryTag (com.sk89q.worldedit.util.nbt.ByteBinaryTag)1 DoubleBinaryTag (com.sk89q.worldedit.util.nbt.DoubleBinaryTag)1 EndBinaryTag (com.sk89q.worldedit.util.nbt.EndBinaryTag)1