use of buildcraft.lib.misc.NBTUtilBC in project BuildCraft by BuildCraft.
the class SchematicBlockDefault method build.
@Override
@SuppressWarnings("Duplicates")
public boolean build(World world, BlockPos blockPos) {
if (placeBlock == Blocks.AIR) {
return true;
}
world.profiler.startSection("prepare block");
IBlockState newBlockState = blockState;
if (placeBlock != blockState.getBlock()) {
newBlockState = placeBlock.getDefaultState();
for (IProperty<?> property : blockState.getPropertyKeys()) {
if (newBlockState.getPropertyKeys().contains(property)) {
newBlockState = BlockUtil.copyProperty(property, newBlockState, blockState);
}
}
}
for (IProperty<?> property : ignoredProperties) {
newBlockState = BlockUtil.copyProperty(property, newBlockState, placeBlock.getDefaultState());
}
world.profiler.endSection();
world.profiler.startSection("place block");
boolean b = world.setBlockState(blockPos, newBlockState, 11);
world.profiler.endSection();
if (b) {
world.profiler.startSection("notify");
updateBlockOffsets.stream().map(blockPos::add).forEach(updatePos -> world.notifyNeighborsOfStateChange(updatePos, placeBlock, false));
world.profiler.endSection();
if (tileNbt != null && blockState.getBlock().hasTileEntity(blockState)) {
world.profiler.startSection("prepare tile");
Set<JsonRule> rules = RulesLoader.getRules(blockState, tileNbt);
NBTTagCompound replaceNbt = rules.stream().map(rule -> rule.replaceNbt).filter(Objects::nonNull).map(NBTBase.class::cast).reduce(NBTUtilBC::merge).map(NBTTagCompound.class::cast).orElse(null);
NBTTagCompound newTileNbt = new NBTTagCompound();
tileNbt.getKeySet().stream().map(key -> Pair.of(key, tileNbt.getTag(key))).forEach(kv -> newTileNbt.setTag(kv.getKey(), kv.getValue()));
newTileNbt.setInteger("x", blockPos.getX());
newTileNbt.setInteger("y", blockPos.getY());
newTileNbt.setInteger("z", blockPos.getZ());
world.profiler.endSection();
world.profiler.startSection("place tile");
TileEntity tileEntity = TileEntity.create(world, replaceNbt != null ? (NBTTagCompound) NBTUtilBC.merge(newTileNbt, replaceNbt) : newTileNbt);
if (tileEntity != null) {
tileEntity.setWorld(world);
world.setTileEntity(blockPos, tileEntity);
if (tileRotation != Rotation.NONE) {
tileEntity.rotate(tileRotation);
}
}
world.profiler.endSection();
}
return true;
}
return false;
}
use of buildcraft.lib.misc.NBTUtilBC in project BuildCraft by BuildCraft.
the class SchematicEntityDefault method build.
@Override
public Entity build(World world, BlockPos basePos) {
Set<JsonRule> rules = RulesLoader.getRules(new ResourceLocation(entityNbt.getString("id")), entityNbt);
NBTTagCompound replaceNbt = rules.stream().map(rule -> rule.replaceNbt).filter(Objects::nonNull).map(NBTBase.class::cast).reduce(NBTUtilBC::merge).map(NBTTagCompound.class::cast).orElse(null);
Vec3d placePos = new Vec3d(basePos).add(pos);
BlockPos placeHangingPos = basePos.add(hangingPos);
NBTTagCompound newEntityNbt = new NBTTagCompound();
entityNbt.getKeySet().stream().map(key -> Pair.of(key, entityNbt.getTag(key))).forEach(kv -> newEntityNbt.setTag(kv.getKey(), kv.getValue()));
newEntityNbt.setTag("Pos", NBTUtilBC.writeVec3d(placePos));
newEntityNbt.setUniqueId("UUID", UUID.randomUUID());
boolean rotate = false;
if (Stream.of("TileX", "TileY", "TileZ", "Facing").allMatch(newEntityNbt::hasKey)) {
newEntityNbt.setInteger("TileX", placeHangingPos.getX());
newEntityNbt.setInteger("TileY", placeHangingPos.getY());
newEntityNbt.setInteger("TileZ", placeHangingPos.getZ());
newEntityNbt.setByte("Facing", (byte) hangingFacing.getHorizontalIndex());
} else {
rotate = true;
}
Entity entity = EntityList.createEntityFromNBT(replaceNbt != null ? (NBTTagCompound) NBTUtilBC.merge(newEntityNbt, replaceNbt) : newEntityNbt, world);
if (entity != null) {
if (rotate) {
entity.setLocationAndAngles(placePos.x, placePos.y, placePos.z, entity.rotationYaw + (entity.rotationYaw - entity.getRotatedYaw(entityRotation)), entity.rotationPitch);
}
world.spawnEntity(entity);
}
return entity;
}
Aggregations