Search in sources :

Example 1 with Point3i

use of javax.vecmath.Point3i in project WorldPainter by Captain-Chaos.

the class DynMapPreviewer method createImage.

public BufferedImage createImage() {
    Point3i offset = object.getOffset();
    Point3i dimensions = object.getDimensions();
    Rectangle tileCoords = tileProvider.getBounds(new Box(offset.x, offset.x + dimensions.x - 1, offset.y, offset.y + dimensions.y - 1, offset.z, offset.z + dimensions.z - 1));
    BufferedImage image = new BufferedImage(tileCoords.width * 128, tileCoords.height * 128, BufferedImage.TYPE_INT_ARGB);
    for (int dx = 0; dx < tileCoords.width; dx++) {
        for (int dy = 0; dy < tileCoords.height; dy++) {
            tileProvider.paintTile(image, tileCoords.x + dx, tileCoords.y + dy, dx * 128, dy * 128);
        }
    }
    return image;
}
Also used : Point3i(javax.vecmath.Point3i) Box(org.pepsoft.util.Box) BufferedImage(java.awt.image.BufferedImage)

Example 2 with Point3i

use of javax.vecmath.Point3i in project WorldPainter by Captain-Chaos.

the class WPObject method guestimateOffset.

/**
 * Guestimate an offset for the object. If an offset cannot be calculated
 * because the object is entirely empty, <code>null</code> will be returned.
 *
 * <p><strong>Note</strong> that this method calls {@link #getDimensions()}
 * and {@link #getMask(int, int, int)}, so they must return valid values.
 */
default Point3i guestimateOffset() {
    final Point3i dims = getDimensions();
    int offsetZ = Integer.MIN_VALUE, lowestX = 0, highestX = 0, lowestY = 0, highestY = 0;
    for (int z = 0; (z < dims.z) && (offsetZ == Integer.MIN_VALUE); z++) {
        for (int x = 0; x < dims.x; x++) {
            for (int y = 0; y < dims.y; y++) {
                if (getMask(x, y, z)) {
                    if (offsetZ == Integer.MIN_VALUE) {
                        offsetZ = z;
                        lowestX = highestX = x;
                        lowestY = highestY = y;
                    } else {
                        if (x < lowestX) {
                            lowestX = x;
                        } else if (x > highestX) {
                            highestX = x;
                        }
                        if (y < lowestY) {
                            lowestY = y;
                        } else if (y > highestY) {
                            highestY = y;
                        }
                    }
                }
            }
        }
    }
    return (offsetZ > Integer.MIN_VALUE) ? new Point3i(-(lowestX + highestX) / 2, -(lowestY + highestY) / 2, -offsetZ) : null;
}
Also used : Point3i(javax.vecmath.Point3i)

Example 3 with Point3i

use of javax.vecmath.Point3i in project WorldPainter by Captain-Chaos.

the class WPDynmapWorld method forDimension.

public static WPDynmapWorld forDimension(MinecraftWorld minecraftWorld, Dimension dimension) {
    int waterLevel;
    TileFactory tileFactory = dimension.getTileFactory();
    if (tileFactory instanceof HeightMapTileFactory) {
        waterLevel = ((HeightMapTileFactory) tileFactory).getWaterHeight();
    } else {
        waterLevel = 62;
    }
    World2 wpWorld = dimension.getWorld();
    Point spawnPoint = wpWorld.getSpawnPoint();
    return forMinecraftWorld(minecraftWorld, wpWorld.getName() + " - " + dimension.getName(), dimension.getDim(), waterLevel, new Point3i(spawnPoint.x, spawnPoint.y, dimension.getIntHeightAt(spawnPoint.x, spawnPoint.y)));
}
Also used : Point3i(javax.vecmath.Point3i)

Example 4 with Point3i

use of javax.vecmath.Point3i in project WorldPainter by Captain-Chaos.

the class WPObjectExporter method isSane.

/**
 * Check whether the coordinates of the extents of the object make sense. In
 * other words: whether it could potentially be placeable at all given its
 * dimensions and location.
 *
 * @return <code>true</code> if the object could potentially be placeable
 *     and the caller can proceed with further checks.
 */
public static boolean isSane(WPObject object, int x, int y, int z, int maxHeight) {
    final Point3i dimensions = object.getDimensions();
    final Point3i offset = object.getOffset();
    if ((((long) x + offset.x) < Integer.MIN_VALUE) || (((long) x + offset.x) > Integer.MAX_VALUE)) {
        if (logger.isDebugEnabled()) {
            logger.debug("Object {0}@{1},{2},{3} extends beyond the limits of a 32 bit signed integer in the X dimension", object.getName(), x, y, z);
        }
        return false;
    }
    if ((((long) x + dimensions.x - 1 + offset.x) < Integer.MIN_VALUE) || (((long) x + dimensions.x - 1 + offset.x) > Integer.MAX_VALUE)) {
        // The object extends beyond the limits of a 32 bit signed integer in the X dimension
        return false;
    }
    if ((((long) y + offset.y) < Integer.MIN_VALUE) || (((long) y + offset.y) > Integer.MAX_VALUE)) {
        // The object extends beyond the limits of a 32 bit signed integer in the Y dimension
        return false;
    }
    if ((((long) y + dimensions.y - 1 + offset.y) < Integer.MIN_VALUE) || (((long) y + dimensions.y - 1 + offset.y) > Integer.MAX_VALUE)) {
        // The object extends beyond the limits of a 32 bit signed integer in the Y dimension
        return false;
    }
    if (((long) z + offset.z) >= maxHeight) {
        // The object is entirely above maxHeight
        return false;
    }
    if (((long) z + dimensions.z - 1 + offset.z) < 0) {
        // The object is entirely below bedrock
        return false;
    }
    return true;
}
Also used : Point3i(javax.vecmath.Point3i)

Example 5 with Point3i

use of javax.vecmath.Point3i in project WorldPainter by Captain-Chaos.

the class WPObjectExporter method isRoom.

/**
 * Checks block by block and taking the object's collision mode attributes
 * and other rules into account whether it can be placed at a particular
 * location. This is a slow operation, so use
 * {@link #isSane(WPObject, int, int, int, int)} first to weed out objects
 * for which this check does not even apply.
 *
 * @return <code>true</code> if the object may be placed at the specified
 *     location according to its collision mode attributes.
 */
public static boolean isRoom(final MinecraftWorld world, final Dimension dimension, final WPObject object, final int x, final int y, final int z, final Placement placement) {
    final Point3i dimensions = object.getDimensions();
    final Point3i offset = object.getOffset();
    final int collisionMode = object.getAttribute(ATTRIBUTE_COLLISION_MODE), maxHeight = world.getMaxHeight();
    final boolean allowConnectingBlocks = false, bottomlessWorld = dimension.isBottomless();
    // Check if the object fits vertically
    if (((long) z + dimensions.z - 1 + offset.z) >= world.getMaxHeight()) {
        if (logger.isTraceEnabled()) {
            logger.trace("No room for object " + object.getName() + " @ " + x + "," + y + "," + z + " with placement " + placement + " because it does not fit below the map height of " + world.getMaxHeight());
        }
        return false;
    }
    if (((long) z + dimensions.z - 1 + offset.z) < 0) {
        if (logger.isTraceEnabled()) {
            logger.trace("No room for object " + object.getName() + " @ " + x + "," + y + "," + z + " with placement " + placement + " because it is entirely below the bedrock");
        }
        return false;
    }
    if ((placement == Placement.ON_LAND) && (collisionMode != COLLISION_MODE_NONE)) {
        // Check block by block whether there is room
        for (int dx = 0; dx < dimensions.x; dx++) {
            for (int dy = 0; dy < dimensions.y; dy++) {
                final int worldX = x + dx + offset.x, worldY = y + dy + offset.y;
                for (int dz = 0; dz < dimensions.z; dz++) {
                    if (object.getMask(dx, dy, dz)) {
                        final Block objectBlock = object.getMaterial(dx, dy, dz).block;
                        if (!objectBlock.veryInsubstantial) {
                            final int worldZ = z + dz + offset.z;
                            if (worldZ < (bottomlessWorld ? 0 : 1)) {
                                if (logger.isTraceEnabled()) {
                                    logger.trace("No room for object " + object.getName() + " @ " + x + "," + y + "," + z + " with placement " + placement + " because it extends below the bottom of the map");
                                }
                                return false;
                            } else if (worldZ >= maxHeight) {
                                if (logger.isTraceEnabled()) {
                                    logger.trace("No room for object " + object.getName() + " @ " + x + "," + y + "," + z + " with placement " + placement + " because it extends above the top of the map");
                                }
                                return false;
                            } else if (worldZ > dimension.getIntHeightAt(worldX, worldY)) {
                                if ((collisionMode == COLLISION_MODE_ALL) ? (!AIR_AND_FLUIDS.contains(world.getBlockTypeAt(worldX, worldY, worldZ))) : (!BLOCKS[world.getBlockTypeAt(worldX, worldY, worldZ)].veryInsubstantial)) {
                                    // there is no room for this object
                                    if (logger.isTraceEnabled()) {
                                        logger.trace("No room for object " + object.getName() + " @ " + x + "," + y + "," + z + " with placement " + placement + " due to collision with existing above ground block of type " + BLOCKS[world.getBlockTypeAt(worldX, worldY, worldZ)]);
                                    }
                                    return false;
                                } else if ((!allowConnectingBlocks) && wouldConnect(world, worldX, worldY, worldZ, objectBlock.id)) {
                                    if (logger.isTraceEnabled()) {
                                        logger.trace("No room for object " + object.getName() + " @ " + x + "," + y + "," + z + " with placement " + placement + " because it would cause a connecting block");
                                    }
                                    return false;
                                }
                            }
                        }
                    }
                }
            }
        }
    } else if (placement == Placement.FLOATING) {
        // with the floor
        for (int dx = 0; dx < dimensions.x; dx++) {
            for (int dy = 0; dy < dimensions.y; dy++) {
                final int worldX = x + dx + offset.x, worldY = y + dy + offset.y;
                final int terrainHeight = dimension.getIntHeightAt(worldX, worldY);
                for (int dz = 0; dz < dimensions.z; dz++) {
                    if (object.getMask(dx, dy, dz)) {
                        final Block objectBlock = object.getMaterial(dx, dy, dz).block;
                        if (!objectBlock.veryInsubstantial) {
                            final int worldZ = z + dz + offset.z;
                            if (worldZ < (bottomlessWorld ? 0 : 1)) {
                                if (logger.isTraceEnabled()) {
                                    logger.trace("No room for object " + object.getName() + " @ " + x + "," + y + "," + z + " with placement " + placement + " because it extends below the bottom of the map");
                                }
                                return false;
                            } else if (worldZ >= maxHeight) {
                                if (logger.isTraceEnabled()) {
                                    logger.trace("No room for object " + object.getName() + " @ " + x + "," + y + "," + z + " with placement " + placement + " because it extends above the top of the map");
                                }
                                return false;
                            } else if (worldZ <= terrainHeight) {
                                // the floor
                                if (logger.isTraceEnabled()) {
                                    logger.trace("No room for object " + object.getName() + " @ " + x + "," + y + "," + z + " with placement " + placement + " due to collision with floor");
                                }
                                return false;
                            } else if (collisionMode != COLLISION_MODE_NONE) {
                                if ((collisionMode == COLLISION_MODE_ALL) ? (!AIR_AND_FLUIDS.contains(world.getBlockTypeAt(worldX, worldY, worldZ))) : (!BLOCKS[world.getBlockTypeAt(worldX, worldY, worldZ)].veryInsubstantial)) {
                                    // world; there is no room for this object
                                    if (logger.isTraceEnabled()) {
                                        logger.trace("No room for object " + object.getName() + " @ " + x + "," + y + "," + z + " with placement " + placement + " due to collision with existing above ground block of type " + BLOCK_TYPE_NAMES[world.getBlockTypeAt(worldX, worldY, worldZ)]);
                                    }
                                    return false;
                                } else if ((!allowConnectingBlocks) && wouldConnect(world, worldX, worldY, worldZ, objectBlock.id)) {
                                    if (logger.isTraceEnabled()) {
                                        logger.trace("No room for object " + object.getName() + " @ " + x + "," + y + "," + z + " with placement " + placement + " because it would cause a connecting block");
                                    }
                                    return false;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if (logger.isTraceEnabled()) {
        logger.trace("There is room for object " + object.getName() + " @ " + x + "," + y + "," + z + " with placement " + placement);
    }
    return true;
}
Also used : Point3i(javax.vecmath.Point3i) Block(org.pepsoft.minecraft.Block)

Aggregations

Point3i (javax.vecmath.Point3i)22 Material (org.pepsoft.minecraft.Material)3 Box (org.pepsoft.util.Box)3 WPObject (org.pepsoft.worldpainter.objects.WPObject)3 HashMap (java.util.HashMap)2 TileEntity (org.pepsoft.minecraft.TileEntity)2 DefaultMaterial (com.khorn.terraincontrol.util.minecraftTypes.DefaultMaterial)1 Graphics2D (java.awt.Graphics2D)1 BufferedImage (java.awt.image.BufferedImage)1 File (java.io.File)1 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Random (java.util.Random)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 NBTOutputStream (org.jnbt.NBTOutputStream)1 Block (org.pepsoft.minecraft.Block)1 Chunk (org.pepsoft.minecraft.Chunk)1 Entity (org.pepsoft.minecraft.Entity)1