Search in sources :

Example 36 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_R1.nbt.PaperweightLazyCompoundTag) CompoundTag(com.sk89q.jnbt.CompoundTag)

Example 37 with CompoundTag

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

the class FabricPlayer method sendFakeBlock.

@Override
public <B extends BlockStateHolder<B>> void sendFakeBlock(BlockVector3 pos, B block) {
    World world = getWorld();
    if (!(world instanceof FabricWorld)) {
        return;
    }
    BlockPos loc = FabricAdapter.toBlockPos(pos);
    if (block == null) {
        final BlockUpdateS2CPacket packetOut = new BlockUpdateS2CPacket(((FabricWorld) world).getWorld(), loc);
        player.networkHandler.sendPacket(packetOut);
    } else {
        final BlockUpdateS2CPacket packetOut = new BlockUpdateS2CPacket();
        PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
        buf.writeBlockPos(loc);
        buf.writeVarInt(Block.getRawIdFromState(FabricAdapter.adapt(block.toImmutableState())));
        try {
            packetOut.read(buf);
        } catch (IOException e) {
            return;
        }
        player.networkHandler.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.networkHandler.sendPacket(new BlockEntityUpdateS2CPacket(new BlockPos(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()), STRUCTURE_BLOCK_PACKET_ID, NBTConverter.toNative(nbtData)));
            }
        }
    }
}
Also used : BlockUpdateS2CPacket(net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket) BlockEntityUpdateS2CPacket(net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket) PacketByteBuf(net.minecraft.util.PacketByteBuf) BlockPos(net.minecraft.util.math.BlockPos) IOException(java.io.IOException) World(com.sk89q.worldedit.world.World) BaseBlock(com.sk89q.worldedit.world.block.BaseBlock) CompoundTag(com.sk89q.jnbt.CompoundTag)

Example 38 with CompoundTag

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

the class FabricWorld method createEntity.

@Nullable
@Override
public Entity createEntity(Location location, BaseEntity entity) {
    World world = getWorld();
    final Optional<EntityType<?>> entityType = EntityType.get(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) {
            net.minecraft.nbt.CompoundTag tag = NBTConverter.toNative(entity.getNbtData());
            for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
                tag.remove(name);
            }
            createdEntity.fromTag(tag);
        }
        createdEntity.setPositionAndAngles(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
        world.spawnEntity(createdEntity);
        return new FabricEntity(createdEntity);
    } else {
        return null;
    }
}
Also used : EntityType(net.minecraft.entity.EntityType) ServerWorld(net.minecraft.server.world.ServerWorld) AbstractWorld(com.sk89q.worldedit.world.AbstractWorld) World(net.minecraft.world.World) CompoundTag(com.sk89q.jnbt.CompoundTag) Nullable(javax.annotation.Nullable)

Example 39 with CompoundTag

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

the class ChunkStore method getChunk.

// FAWE end
/**
 * Get a chunk at a location.
 *
 * @param position the position of the chunk
 * @return a chunk
 * @throws ChunkStoreException thrown if there is an error from the chunk store
 * @throws DataException       thrown on data error
 * @throws IOException         thrown on I/O error
 */
public Chunk getChunk(BlockVector2 position, World world) throws DataException, IOException {
    CompoundTag rootTag = getChunkTag(position, world);
    // FAWE start - biome and entity restore
    int dataVersion = rootTag.getInt("DataVersion");
    if (dataVersion == 0) {
        dataVersion = -1;
    }
    if (dataVersion >= Constants.DATA_VERSION_MC_1_17) {
        return ChunkStoreHelper.getChunk(rootTag, () -> getEntitiesTag(position, world));
    } else {
        return ChunkStoreHelper.getChunk(rootTag);
    }
// FAWE end
}
Also used : CompoundTag(com.sk89q.jnbt.CompoundTag)

Example 40 with CompoundTag

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

the class AbstractChangeSet method add.

public void add(EntityCreate change) {
    CompoundTag tag = change.state.getNbtData();
    addEntityCreate(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