Search in sources :

Example 26 with CompoundTag

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

the class PaperweightGetBlocks_Copy method storeEntity.

@SuppressWarnings({ "unchecked", "rawtypes" })
protected void storeEntity(Entity entity) {
    BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
    net.minecraft.nbt.CompoundTag compoundTag = new net.minecraft.nbt.CompoundTag();
    entities.add((CompoundTag) adapter.toNative(entity.save(compoundTag)));
}
Also used : BukkitImplAdapter(com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter) PaperweightLazyCompoundTag(com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_18_R2.nbt.PaperweightLazyCompoundTag) CompoundTag(com.sk89q.jnbt.CompoundTag)

Example 27 with CompoundTag

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

the class ForgePlayer method sendFakeBlock.

@Override
public <B extends BlockStateHolder<B>> void sendFakeBlock(BlockVector3 pos, B block) {
    World world = getWorld();
    if (!(world instanceof ForgeWorld)) {
        return;
    }
    BlockPos loc = ForgeAdapter.toBlockPos(pos);
    if (block == null) {
        final SChangeBlockPacket packetOut = new SChangeBlockPacket(((ForgeWorld) world).getWorld(), loc);
        player.connection.sendPacket(packetOut);
    } else {
        final SChangeBlockPacket packetOut = new SChangeBlockPacket();
        PacketBuffer buf = new PacketBuffer(Unpooled.buffer());
        buf.writeBlockPos(loc);
        buf.writeVarInt(Block.getStateId(ForgeAdapter.adapt(block.toImmutableState())));
        try {
            packetOut.readPacketData(buf);
        } catch (IOException e) {
            return;
        }
        player.connection.sendPacket(packetOut);
        if (block instanceof BaseBlock && block.getBlockType().equals(BlockTypes.STRUCTURE_BLOCK)) {
            final BaseBlock baseBlock = (BaseBlock) block;
            final CompoundTag nbtData = baseBlock.getNbtData();
            if (nbtData != null) {
                player.connection.sendPacket(new SUpdateTileEntityPacket(new BlockPos(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()), STRUCTURE_BLOCK_PACKET_ID, NBTConverter.toNative(nbtData)));
            }
        }
    }
}
Also used : SChangeBlockPacket(net.minecraft.network.play.server.SChangeBlockPacket) SUpdateTileEntityPacket(net.minecraft.network.play.server.SUpdateTileEntityPacket) BlockPos(net.minecraft.util.math.BlockPos) IOException(java.io.IOException) World(com.sk89q.worldedit.world.World) BaseBlock(com.sk89q.worldedit.world.block.BaseBlock) PacketBuffer(net.minecraft.network.PacketBuffer) CompoundTag(com.sk89q.jnbt.CompoundTag)

Example 28 with CompoundTag

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

the class ForgeWorld method createEntity.

@Nullable
@Override
public Entity createEntity(Location location, BaseEntity entity) {
    World world = getWorld();
    final Optional<EntityType<?>> entityType = EntityType.byKey(entity.getType().getId());
    if (!entityType.isPresent())
        return null;
    net.minecraft.entity.Entity createdEntity = entityType.get().create(world);
    if (createdEntity != null) {
        CompoundTag nativeTag = entity.getNbtData();
        if (nativeTag != null) {
            CompoundNBT tag = NBTConverter.toNative(entity.getNbtData());
            for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
                tag.remove(name);
            }
            createdEntity.read(tag);
        }
        createdEntity.setLocationAndAngles(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
        world.addEntity(createdEntity);
        return new ForgeEntity(createdEntity);
    } else {
        return null;
    }
}
Also used : EntityType(net.minecraft.entity.EntityType) CompoundNBT(net.minecraft.nbt.CompoundNBT) World(net.minecraft.world.World) ServerWorld(net.minecraft.world.server.ServerWorld) AbstractWorld(com.sk89q.worldedit.world.AbstractWorld) CompoundTag(com.sk89q.jnbt.CompoundTag) Nullable(javax.annotation.Nullable)

Example 29 with CompoundTag

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

the class AbstractChangeSet method processSet.

@Override
public synchronized IChunkSet processSet(IChunk chunk, IChunkGet get, IChunkSet set) {
    int bx = chunk.getX() << 4;
    int bz = chunk.getZ() << 4;
    Map<BlockVector3, CompoundTag> tilesFrom = get.getTiles();
    Map<BlockVector3, CompoundTag> tilesTo = set.getTiles();
    if (!tilesFrom.isEmpty()) {
        for (Map.Entry<BlockVector3, CompoundTag> entry : tilesFrom.entrySet()) {
            BlockVector3 pos = entry.getKey();
            BlockState fromBlock = get.getBlock(pos.getX() & 15, pos.getY(), pos.getZ() & 15);
            BlockState toBlock = set.getBlock(pos.getX() & 15, pos.getY(), pos.getZ() & 15);
            if (fromBlock != toBlock || tilesTo.containsKey(pos)) {
                addTileRemove(MainUtil.setPosition(entry.getValue(), entry.getKey().getX(), entry.getKey().getY(), entry.getKey().getZ()));
            }
        }
    }
    if (!tilesTo.isEmpty()) {
        for (Map.Entry<BlockVector3, CompoundTag> entry : tilesTo.entrySet()) {
            BlockVector3 pos = entry.getKey();
            addTileCreate(MainUtil.setPosition(entry.getValue(), pos.getX() + bx, pos.getY(), pos.getZ() + bz));
        }
    }
    Set<UUID> entRemoves = set.getEntityRemoves();
    if (!entRemoves.isEmpty()) {
        for (UUID uuid : entRemoves) {
            CompoundTag found = get.getEntity(uuid);
            if (found != null) {
                addEntityRemove(found);
            }
        }
    }
    Set<CompoundTag> ents = set.getEntities();
    if (!ents.isEmpty()) {
        for (CompoundTag tag : ents) {
            addEntityCreate(tag);
        }
    }
    for (int layer = get.getMinSectionPosition(); layer <= get.getMaxSectionPosition(); layer++) {
        if (!set.hasSection(layer)) {
            continue;
        }
        // add each block and tile
        char[] blocksGet;
        char[] tmp = get.load(layer);
        if (tmp == null) {
            blocksGet = FaweCache.INSTANCE.EMPTY_CHAR_4096;
        } else {
            System.arraycopy(tmp, 0, (blocksGet = new char[4096]), 0, 4096);
        }
        char[] blocksSet;
        // loadIfPresent shouldn't be null if set.hasSection(layer) is true
        System.arraycopy(Objects.requireNonNull(set.loadIfPresent(layer)), 0, (blocksSet = new char[4096]), 0, 4096);
        // Account for negative layers
        int by = layer << 4;
        for (int y = 0, index = 0; y < 16; y++) {
            int yy = y + by;
            for (int z = 0; z < 16; z++) {
                int zz = z + bz;
                for (int x = 0; x < 16; x++, index++) {
                    int xx = bx + x;
                    int from = blocksGet[index];
                    if (from == BlockTypesCache.ReservedIDs.__RESERVED__) {
                        from = BlockTypesCache.ReservedIDs.AIR;
                    }
                    final int combinedFrom = from;
                    final int combinedTo = blocksSet[index];
                    if (combinedTo != 0) {
                        add(xx, yy, zz, combinedFrom, combinedTo);
                    }
                }
            }
        }
    }
    BiomeType[][] biomes = set.getBiomes();
    if (biomes != null) {
        for (int layer = get.getMinSectionPosition(); layer <= get.getMaxSectionPosition(); layer++) {
            if (!set.hasBiomes(layer)) {
                continue;
            }
            BiomeType[] biomeSection = biomes[layer - set.getMinSectionPosition()];
            int index = 0;
            int yy = layer << 4;
            for (int y = 0; y < 16; y += 4) {
                for (int z = 0; z < 16; z += 4) {
                    for (int x = 0; x < 16; x += 4, index++) {
                        BiomeType newBiome = biomeSection[index];
                        if (newBiome != null) {
                            BiomeType oldBiome = get.getBiomeType(x, yy + y, z);
                            if (oldBiome != newBiome) {
                                addBiomeChange(bx + x, yy + y, bz + z, oldBiome, newBiome);
                            }
                        }
                    }
                }
            }
        }
    }
    return set;
}
Also used : BlockVector3(com.sk89q.worldedit.math.BlockVector3) BiomeType(com.sk89q.worldedit.world.biome.BiomeType) BlockState(com.sk89q.worldedit.world.block.BlockState) UUID(java.util.UUID) Map(java.util.Map) CompoundTag(com.sk89q.jnbt.CompoundTag)

Example 30 with CompoundTag

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

the class AbstractChangeSet method add.

public void add(EntityRemove change) {
    CompoundTag tag = change.state.getNbtData();
    addEntityRemove(MainUtil.setEntityInfo(tag, change.getEntity()));
}
Also used : CompoundTag(com.sk89q.jnbt.CompoundTag)

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