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)));
}
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)));
}
}
}
}
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;
}
}
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;
}
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()));
}
Aggregations