Search in sources :

Example 11 with Material

use of org.pepsoft.minecraft.Material in project WorldPainter by Captain-Chaos.

the class MixedMaterial method getMaterial.

public Material getMaterial(long seed, int x, int y, float z) {
    switch(mode) {
        case SIMPLE:
            return simpleMaterial;
        case NOISE:
            return materials[random.nextInt(1000)];
        case BLOBS:
            double xx = x / Constants.TINY_BLOBS, yy = y / Constants.TINY_BLOBS, zz = z / Constants.TINY_BLOBS;
            if (seed + 1 != noiseGenerators[0].getSeed()) {
                for (int i = 0; i < noiseGenerators.length; i++) {
                    noiseGenerators[i].setSeed(seed + i + 1);
                }
            }
            Material material = sortedRows[sortedRows.length - 1].material;
            for (int i = noiseGenerators.length - 1; i >= 0; i--) {
                final float rowScale = sortedRows[i].scale * this.scale;
                if (noiseGenerators[i].getPerlinNoise(xx / rowScale, yy / rowScale, zz / rowScale) >= sortedRows[i].chance) {
                    material = sortedRows[i].material;
                }
            }
            return material;
        case LAYERED:
            if (layerNoiseheightMap != null) {
                if (layerNoiseheightMap.getSeed() != seed) {
                    layerNoiseheightMap.setSeed(seed);
                }
                z += layerNoiseheightMap.getValue(x, y, z) - layerNoiseOffset;
            }
            if (repeat) {
                if (layerXSlope != 0.0) {
                    z += layerXSlope * x;
                }
                if (layerYSlope != 0.0) {
                    z += layerYSlope * y;
                }
                return materials[Math.floorMod((int) (z + 0.5f), materials.length)];
            } else {
                final int iZ = (int) (z + 0.5f);
                if (iZ < 0) {
                    return materials[0];
                } else if (iZ >= materials.length) {
                    return materials[materials.length - 1];
                } else {
                    return materials[iZ];
                }
            }
        default:
            throw new InternalError();
    }
}
Also used : Material(org.pepsoft.minecraft.Material)

Example 12 with Material

use of org.pepsoft.minecraft.Material in project WorldPainter by Captain-Chaos.

the class MixedMaterial method init.

private void init() {
    switch(mode) {
        case SIMPLE:
            if (rows.length != 1) {
                throw new IllegalArgumentException("Only one row allowed for SIMPLE mode");
            }
            simpleMaterial = rows[0].material;
            break;
        case NOISE:
            if (rows.length < 2) {
                throw new IllegalArgumentException("Multiple rows required for NOISE mode");
            }
            materials = new Material[1000];
            int index = 0;
            for (Row row : rows) {
                for (int i = 0; i < row.occurrence; i++) {
                    materials[index++] = row.material;
                }
            }
            random = new Random();
            break;
        case BLOBS:
            if (rows.length < 2) {
                throw new IllegalArgumentException("Multiple rows required for BLOBS mode");
            }
            sortedRows = Arrays.copyOf(rows, rows.length);
            Arrays.sort(sortedRows, (r1, r2) -> r1.occurrence - r2.occurrence);
            noiseGenerators = new PerlinNoise[rows.length - 1];
            int cumulativePermillage = 0;
            for (int i = 0; i < noiseGenerators.length; i++) {
                noiseGenerators[i] = new PerlinNoise(0);
                cumulativePermillage += sortedRows[i].occurrence * (1000 - cumulativePermillage) / 1000;
                sortedRows[i].chance = PerlinNoise.getLevelForPromillage(cumulativePermillage);
            }
            break;
        case LAYERED:
            if (rows.length < 2) {
                throw new IllegalArgumentException("Multiple rows required for LAYERED mode");
            }
            if ((!repeat) && ((layerXSlope != 0) || (layerYSlope != 0))) {
                throw new IllegalArgumentException("Angle may not be non-zero if repeat is false");
            }
            List<Material> tmpMaterials = new ArrayList<>(org.pepsoft.minecraft.Constants.DEFAULT_MAX_HEIGHT_2);
            for (int i = rows.length - 1; i >= 0; i--) {
                for (int j = 0; j < rows[i].occurrence; j++) {
                    tmpMaterials.add(rows[i].material);
                }
            }
            materials = tmpMaterials.toArray(new Material[tmpMaterials.size()]);
            if (variation != null) {
                layerNoiseheightMap = new NoiseHeightMap(variation, NOISE_SEED_OFFSET);
                layerNoiseOffset = variation.getRange();
            } else {
                layerNoiseheightMap = null;
                layerNoiseOffset = 0;
            }
            break;
    }
}
Also used : NoiseHeightMap(org.pepsoft.worldpainter.heightMaps.NoiseHeightMap) PerlinNoise(org.pepsoft.util.PerlinNoise) Material(org.pepsoft.minecraft.Material)

Example 13 with Material

use of org.pepsoft.minecraft.Material in project WorldPainter by Captain-Chaos.

the class GroundCoverLayerExporter method apply.

@Override
public Fixup apply(Dimension dimension, Point3i location, int intensity, Rectangle exportedArea, MinecraftWorld minecraftWorld) {
    if (intensity > 0) {
        final int blockBelow = minecraftWorld.getBlockTypeAt(location.x, location.y, location.z - 1);
        if ((blockBelow != BLK_AIR) && (!Block.BLOCKS[blockBelow].insubstantial)) {
            final int thickness = layer.getThickness();
            final MixedMaterial mixedMaterial = layer.getMaterial();
            final long seed = dimension.getSeed();
            int effectiveThickness = Math.abs(thickness);
            if (noiseHeightMap != null) {
                noiseHeightMap.setSeed(seed);
                effectiveThickness += noiseHeightMap.getHeight(location.x, location.y) - noiseOffset;
            }
            if (thickness > 0) {
                final int maxZ = dimension.getMaxHeight() - 1;
                for (int dz = 0; dz < effectiveThickness; dz++) {
                    final int z = location.z + dz;
                    if (z > maxZ) {
                        break;
                    }
                    final int existingBlockType = minecraftWorld.getBlockTypeAt(location.x, location.y, z);
                    final Material material = mixedMaterial.getMaterial(seed, location.x, location.y, z);
                    if ((material != Material.AIR) && ((!material.block.veryInsubstantial) || (existingBlockType == BLK_AIR) || Block.BLOCKS[existingBlockType].insubstantial)) {
                        minecraftWorld.setMaterialAt(location.x, location.y, z, material);
                    }
                }
            } else {
                final int minZ = dimension.isBottomless() ? 0 : 1;
                for (int dz = 0; dz < effectiveThickness; dz++) {
                    final int z = location.z - 1 - dz;
                    if (z < minZ) {
                        break;
                    }
                    int existingBlockType = minecraftWorld.getBlockTypeAt(location.x, location.y, z);
                    if (existingBlockType != BLK_AIR) {
                        minecraftWorld.setMaterialAt(location.x, location.y, z, mixedMaterial.getMaterial(seed, location.x, location.y, z));
                    }
                }
            }
        }
    }
    return null;
}
Also used : Material(org.pepsoft.minecraft.Material) MixedMaterial(org.pepsoft.worldpainter.MixedMaterial) MixedMaterial(org.pepsoft.worldpainter.MixedMaterial)

Example 14 with Material

use of org.pepsoft.minecraft.Material in project WorldPainter by Captain-Chaos.

the class JungleTree method renderRoot.

private void renderRoot(int x, int y, int height, int size, float angle, MinecraftWorld world, Random random) {
    int h = (int) (size / 5f + 0.5f);
    Material capMaterial = getCapMaterial();
    int i = 1, maxDepth = -1;
    int previousDx = Integer.MIN_VALUE, previousDy = Integer.MIN_VALUE;
    while (h > 0) {
        int dx = (int) (Math.sin(angle) * i + 0.5f);
        int dy = (int) (Math.cos(angle) * i + 0.5f);
        if ((dx == previousDx) && (dy == previousDy)) {
            i++;
            continue;
        } else {
            previousDx = dx;
            previousDy = dy;
        }
        int worldX = x + dx, worldY = y + dy;
        int depth = 0;
        for (int z = height + h; z > 0; z--) {
            if (!BLOCKS[world.getBlockTypeAt(worldX, worldY, z)].veryInsubstantial) {
                depth++;
            }
            world.setMaterialAt(worldX, worldY, z, (z < (height + h)) ? trunkMaterial : capMaterial);
            if (depth > maxDepth) {
                break;
            }
        }
        if (random.nextInt(15) == 0) {
            world.setMaterialAt(worldX, worldY, height + h + 1, random.nextBoolean() ? RED_MUSHROOM : BROWN_MUSHROOM);
        // System.out.println("Rendered mushroom @ " + worldX + "," + worldY + "," + (height + h + 1));
        }
        h -= (random.nextInt(2) + 1);
        i++;
        maxDepth++;
    }
}
Also used : Material(org.pepsoft.minecraft.Material)

Example 15 with Material

use of org.pepsoft.minecraft.Material in project WorldPainter by Captain-Chaos.

the class WPObjectRenderer method render.

public BufferedImage render() {
    final BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    final Graphics2D g2 = image.createGraphics();
    try {
        for (int z = 0; z < dim.z; z++) {
            for (int y = dim.y - 1; y >= 0; y--) {
                for (int x = dim.x - 1; x >= 0; x--) {
                    if (object.getMask(x, dim.y - y - 1, z)) {
                        final Material material = object.getMaterial(x, dim.y - y - 1, z);
                        if (material != Material.AIR) {
                            final Point coords = getImageCoordinates(x, y, z);
                            final int blockType = material.blockType;
                            final int alpha = ((blockType == Constants.BLK_LEAVES) || (blockType == Constants.BLK_LEAVES2)) ? 192 : 255;
                            paintBlock(g2, coords.x, coords.y, material, alpha);
                        }
                    }
                }
            }
        }
    } finally {
        g2.dispose();
    }
    return image;
}
Also used : Material(org.pepsoft.minecraft.Material) Point(java.awt.Point) BufferedImage(java.awt.image.BufferedImage) Point(java.awt.Point) Graphics2D(java.awt.Graphics2D)

Aggregations

Material (org.pepsoft.minecraft.Material)15 Point3i (javax.vecmath.Point3i)3 BufferedImage (java.awt.image.BufferedImage)2 TileEntity (org.pepsoft.minecraft.TileEntity)2 MixedMaterial (org.pepsoft.worldpainter.MixedMaterial)2 DefaultMaterial (com.khorn.terraincontrol.util.minecraftTypes.DefaultMaterial)1 Graphics2D (java.awt.Graphics2D)1 Point (java.awt.Point)1 Line2D (java.awt.geom.Line2D)1 Rectangle2D (java.awt.geom.Rectangle2D)1 FileOutputStream (java.io.FileOutputStream)1 PrintStream (java.io.PrintStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HashMap (java.util.HashMap)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 Test (org.junit.Test)1 Entity (org.pepsoft.minecraft.Entity)1 PerlinNoise (org.pepsoft.util.PerlinNoise)1 Row (org.pepsoft.worldpainter.MixedMaterial.Row)1 MixedMaterialTableModel (org.pepsoft.worldpainter.MixedMaterialTableModel)1