use of org.pepsoft.worldpainter.objects.MirroredObject in project WorldPainter by Captain-Chaos.
the class Bo2LayerExporter method render.
@Override
public List<Fixup> render(final Dimension dimension, Rectangle area, Rectangle exportedArea, MinecraftWorld minecraftWorld) {
final Bo2ObjectProvider objectProvider = layer.getObjectProvider();
final int maxHeight = dimension.getMaxHeight();
final int maxZ = maxHeight - 1;
final List<Fixup> fixups = new ArrayList<>();
final int density = layer.getDensity() * 64;
for (int chunkX = area.x; chunkX < area.x + area.width; chunkX += 16) {
for (int chunkY = area.y; chunkY < area.y + area.height; chunkY += 16) {
// Set the seed and randomizer according to the chunk
// coordinates to make sure the chunk is always rendered the
// same, no matter how often it is rendered
final long seed = dimension.getSeed() + (chunkX >> 4) * 65537 + (chunkY >> 4) * 4099;
final Random random = new Random(seed);
objectProvider.setSeed(seed);
for (int x = chunkX; x < chunkX + 16; x++) {
for (int y = chunkY; y < chunkY + 16; y++) {
final int height = dimension.getIntHeightAt(x, y);
if ((height == -1) || (height >= maxZ)) {
// height == -1 means no tile present
continue;
}
final int strength = dimension.getLayerValueAt(layer, x, y);
if ((strength > 0) && (random.nextInt(density) <= strength * strength)) {
WPObject object = objectProvider.getObject();
final Placement placement = getPlacement(minecraftWorld, dimension, x, y, height + 1, object, random);
if (placement == Placement.NONE) {
continue;
}
if (object.getAttribute(ATTRIBUTE_RANDOM_ROTATION)) {
if (random.nextBoolean()) {
object = new MirroredObject(object, false);
}
int rotateSteps = random.nextInt(4);
if (rotateSteps > 0) {
object = new RotatedObject(object, rotateSteps);
}
}
final int z = (placement == Placement.ON_LAND) ? height + 1 : dimension.getWaterLevelAt(x, y) + 1;
if (!isSane(object, x, y, z, maxHeight)) {
continue;
}
prepareForExport(object, dimension);
if (!isRoom(minecraftWorld, dimension, object, x, y, z, placement)) {
continue;
}
if (!fitsInExportedArea(exportedArea, object, x, y)) {
// There is room on our side of the border, but
// the object extends outside the exported area,
// so it might clash with an object from another
// area. Schedule a fixup to retest whether
// there is room after all the objects have been
// placed on both sides of the border
fixups.add(new WPObjectFixup(object, x, y, z, placement));
continue;
}
renderObject(minecraftWorld, dimension, object, x, y, z);
}
}
}
}
}
return fixups;
}
use of org.pepsoft.worldpainter.objects.MirroredObject in project WorldPainter by Captain-Chaos.
the class Bo2LayerExporter method apply.
@Override
public Fixup apply(Dimension dimension, Point3i location, int intensity, Rectangle exportedArea, MinecraftWorld minecraftWorld) {
final long seed = dimension.getSeed() ^ ((long) location.x << 40) ^ ((long) location.y << 20) ^ (location.z);
applyRandom.setSeed(seed);
if ((intensity > 0) && (applyRandom.nextInt(layer.getDensity() * 20) <= intensity * intensity / 225)) {
final Bo2ObjectProvider objectProvider = layer.getObjectProvider();
objectProvider.setSeed(seed);
WPObject object = objectProvider.getObject();
int existingBlockType = minecraftWorld.getBlockTypeAt(location.x, location.y, location.z);
int blockBelow = minecraftWorld.getBlockTypeAt(location.x, location.y, location.z - 1);
if ((object.getAttribute(ATTRIBUTE_SPAWN_IN_LAVA) && ((existingBlockType == BLK_LAVA) || (existingBlockType == BLK_STATIONARY_LAVA))) || (object.getAttribute(ATTRIBUTE_SPAWN_IN_WATER) && ((existingBlockType == BLK_WATER) || (existingBlockType == BLK_STATIONARY_WATER))) || (object.getAttribute(ATTRIBUTE_SPAWN_ON_LAND) && (!BLOCKS[blockBelow].veryInsubstantial)) || (!object.getAttribute(ATTRIBUTE_NEEDS_FOUNDATION) && BLOCKS[blockBelow].veryInsubstantial)) {
if (object.getAttribute(ATTRIBUTE_RANDOM_ROTATION)) {
if (applyRandom.nextBoolean()) {
object = new MirroredObject(object, false);
}
int rotateSteps = applyRandom.nextInt(4);
if (rotateSteps > 0) {
object = new RotatedObject(object, rotateSteps);
}
}
if (!isSane(object, location.x, location.y, location.z, minecraftWorld.getMaxHeight())) {
return null;
}
prepareForExport(object, dimension);
if (!isRoom(minecraftWorld, dimension, object, location.x, location.y, location.z, Placement.ON_LAND)) {
return null;
}
if (!fitsInExportedArea(exportedArea, object, location.x, location.y)) {
// sides of the border
return new WPObjectFixup(object, location.x, location.y, location.z, Placement.ON_LAND);
}
renderObject(minecraftWorld, dimension, object, location.x, location.y, location.z);
}
}
return null;
}
Aggregations