use of com.github.lunatrius.schematica.nbt.NBTConversionException in project Spark-Client by Spark-Client-Development.
the class CommonProxy method copyChunkToSchematic.
public void copyChunkToSchematic(final ISchematic schematic, final World world, final int chunkX, final int chunkZ, final int minX, final int maxX, final int minY, final int maxY, final int minZ, final int maxZ) {
final MBlockPos pos = new MBlockPos();
final MBlockPos localPos = new MBlockPos();
final int localMinX = minX < (chunkX << 4) ? 0 : (minX & 15);
final int localMaxX = maxX > ((chunkX << 4) + 15) ? 15 : (maxX & 15);
final int localMinZ = minZ < (chunkZ << 4) ? 0 : (minZ & 15);
final int localMaxZ = maxZ > ((chunkZ << 4) + 15) ? 15 : (maxZ & 15);
for (int chunkLocalX = localMinX; chunkLocalX <= localMaxX; chunkLocalX++) {
for (int chunkLocalZ = localMinZ; chunkLocalZ <= localMaxZ; chunkLocalZ++) {
for (int y = minY; y <= maxY; y++) {
final int x = chunkLocalX | (chunkX << 4);
final int z = chunkLocalZ | (chunkZ << 4);
final int localX = x - minX;
final int localY = y - minY;
final int localZ = z - minZ;
pos.set(x, y, z);
localPos.set(localX, localY, localZ);
try {
final IBlockState blockState = world.getBlockState(pos);
final Block block = blockState.getBlock();
final boolean success = schematic.setBlockState(localPos, blockState);
if (success && block.hasTileEntity(blockState)) {
final TileEntity tileEntity = world.getTileEntity(pos);
if (tileEntity != null) {
try {
final TileEntity reloadedTileEntity = NBTHelper.reloadTileEntity(tileEntity, minX, minY, minZ);
schematic.setTileEntity(localPos, reloadedTileEntity);
} catch (final NBTConversionException nce) {
Reference.logger.error("Error while trying to save tile entity '{}'!", tileEntity, nce);
schematic.setBlockState(localPos, Blocks.BEDROCK.getDefaultState());
}
}
}
} catch (final Exception e) {
Reference.logger.error("Something went wrong!", e);
}
}
}
}
final int minX1 = localMinX | (chunkX << 4);
final int minZ1 = localMinZ | (chunkZ << 4);
final int maxX1 = localMaxX | (chunkX << 4);
final int maxZ1 = localMaxZ | (chunkZ << 4);
final AxisAlignedBB bb = new AxisAlignedBB(minX1, minY, minZ1, maxX1 + 1, maxY + 1, maxZ1 + 1);
final List<Entity> entities = world.getEntitiesWithinAABB(Entity.class, bb);
for (final Entity entity : entities) {
try {
final Entity reloadedEntity = NBTHelper.reloadEntity(entity, minX, minY, minZ);
schematic.addEntity(reloadedEntity);
} catch (final NBTConversionException nce) {
Reference.logger.error("Error while trying to save entity '{}'!", entity, nce);
}
}
}
use of com.github.lunatrius.schematica.nbt.NBTConversionException in project defrag by Edouard127.
the class CommonProxy method copyChunkToSchematic.
public void copyChunkToSchematic(final ISchematic schematic, final World world, final int chunkX, final int chunkZ, final int minX, final int maxX, final int minY, final int maxY, final int minZ, final int maxZ) {
final MBlockPos pos = new MBlockPos();
final MBlockPos localPos = new MBlockPos();
final int localMinX = minX < (chunkX << 4) ? 0 : (minX & 15);
final int localMaxX = maxX > ((chunkX << 4) + 15) ? 15 : (maxX & 15);
final int localMinZ = minZ < (chunkZ << 4) ? 0 : (minZ & 15);
final int localMaxZ = maxZ > ((chunkZ << 4) + 15) ? 15 : (maxZ & 15);
for (int chunkLocalX = localMinX; chunkLocalX <= localMaxX; chunkLocalX++) {
for (int chunkLocalZ = localMinZ; chunkLocalZ <= localMaxZ; chunkLocalZ++) {
for (int y = minY; y <= maxY; y++) {
final int x = chunkLocalX | (chunkX << 4);
final int z = chunkLocalZ | (chunkZ << 4);
final int localX = x - minX;
final int localY = y - minY;
final int localZ = z - minZ;
pos.set(x, y, z);
localPos.set(localX, localY, localZ);
try {
final IBlockState blockState = world.getBlockState(pos);
final Block block = blockState.getBlock();
final boolean success = schematic.setBlockState(localPos, blockState);
if (success && block.hasTileEntity(blockState)) {
final TileEntity tileEntity = world.getTileEntity(pos);
if (tileEntity != null) {
try {
final TileEntity reloadedTileEntity = NBTHelper.reloadTileEntity(tileEntity, minX, minY, minZ);
schematic.setTileEntity(localPos, reloadedTileEntity);
} catch (final NBTConversionException nce) {
Reference.logger.error("Error while trying to save tile entity '{}'!", tileEntity, nce);
schematic.setBlockState(localPos, Blocks.BEDROCK.getDefaultState());
}
}
}
} catch (final Exception e) {
Reference.logger.error("Something went wrong!", e);
}
}
}
}
final int minX1 = localMinX | (chunkX << 4);
final int minZ1 = localMinZ | (chunkZ << 4);
final int maxX1 = localMaxX | (chunkX << 4);
final int maxZ1 = localMaxZ | (chunkZ << 4);
final AxisAlignedBB bb = new AxisAlignedBB(minX1, minY, minZ1, maxX1 + 1, maxY + 1, maxZ1 + 1);
final List<Entity> entities = world.getEntitiesWithinAABB(Entity.class, bb);
for (final Entity entity : entities) {
try {
final Entity reloadedEntity = NBTHelper.reloadEntity(entity, minX, minY, minZ);
schematic.addEntity(reloadedEntity);
} catch (final NBTConversionException nce) {
Reference.logger.error("Error while trying to save entity '{}'!", entity, nce);
}
}
}
Aggregations