Search in sources :

Example 11 with WPObject

use of org.pepsoft.worldpainter.objects.WPObject in project WorldPainter by Captain-Chaos.

the class EditObjectAttributes method autoOffset.

private void autoOffset() {
    boolean singleSelection = objects.size() == 1;
    for (WPObject object : objects) {
        Point3i offset = object.guestimateOffset();
        if (offset == null) {
            // This object has size zero or consists of nothing but air!
            offsets.clear();
            if (singleSelection) {
                labelOffset.setText("<html><u>0, 0, 0</u></html>");
            }
        } else {
            offsets.put(object, offset);
            if (singleSelection) {
                String offsetStr = "<html><u>" + offset.x + ", " + offset.y + ", " + offset.z + "</u></html>";
                labelOffset.setText(offsetStr);
            }
        }
    }
    if (!singleSelection) {
        JOptionPane.showMessageDialog(this, objects.size() + " offsets autoset");
    }
}
Also used : Point3i(javax.vecmath.Point3i) WPObject(org.pepsoft.worldpainter.objects.WPObject)

Example 12 with WPObject

use of org.pepsoft.worldpainter.objects.WPObject in project WorldPainter by Captain-Chaos.

the class RegressionIT method testObjects.

private void testObjects(String path, Loader loader, Tester tester) throws IOException {
    URL baseURL = RegressionIT.class.getResource(path);
    try (BufferedReader in = new BufferedReader(new InputStreamReader(baseURL.openStream()))) {
        String fileName;
        while ((fileName = in.readLine()) != null) {
            WPObject object = loader.load(RegressionIT.class.getResourceAsStream(path + "/" + fileName));
            tester.test(object);
            System.out.println("Tested " + fileName);
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) WPObject(org.pepsoft.worldpainter.objects.WPObject) BufferedReader(java.io.BufferedReader) URL(java.net.URL)

Example 13 with WPObject

use of org.pepsoft.worldpainter.objects.WPObject 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;
}
Also used : Random(java.util.Random) WPObject(org.pepsoft.worldpainter.objects.WPObject) ArrayList(java.util.ArrayList) RotatedObject(org.pepsoft.worldpainter.objects.RotatedObject) Fixup(org.pepsoft.worldpainter.exporting.Fixup) MirroredObject(org.pepsoft.worldpainter.objects.MirroredObject)

Example 14 with WPObject

use of org.pepsoft.worldpainter.objects.WPObject 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;
}
Also used : WPObject(org.pepsoft.worldpainter.objects.WPObject) RotatedObject(org.pepsoft.worldpainter.objects.RotatedObject) MirroredObject(org.pepsoft.worldpainter.objects.MirroredObject)

Example 15 with WPObject

use of org.pepsoft.worldpainter.objects.WPObject in project WorldPainter by Captain-Chaos.

the class PlantLayer method getObjectProvider.

public Bo2ObjectProvider getObjectProvider() {
    int total = 0;
    for (PlantSettings setting : settings) {
        if (setting != null) {
            total += setting.occurrence;
        }
    }
    final byte[] pool = new byte[total], growthOffset = new byte[total], growthRange = new byte[total];
    int index = 0;
    for (byte i = 0; i < settings.length; i++) {
        if (settings[i] != null) {
            for (short j = 0; j < settings[i].occurrence; j++) {
                growthOffset[index] = settings[i].dataValueFrom;
                growthRange[index] = (byte) (settings[i].dataValueTo - settings[i].dataValueFrom);
                pool[index++] = i;
            }
        }
    }
    return new Bo2ObjectProvider() {

        @Override
        public String getName() {
            return PlantLayer.this.getName();
        }

        @Override
        public WPObject getObject() {
            final int index = random.nextInt(pool.length);
            final Plant plant = Plant.ALL_PLANTS[pool[index]];
            if (growthRange[index] == 0) {
                return plant.withGrowth(growthOffset[index]);
            } else {
                return plant.withGrowth(growthOffset[index] + random.nextInt(growthRange[index] + 1));
            }
        }

        @Override
        public List<WPObject> getAllObjects() {
            throw new UnsupportedOperationException("Not supported");
        }

        @Override
        public void setSeed(long seed) {
            random.setSeed(seed);
        }

        private final Random random = new Random();
    };
}
Also used : Random(java.util.Random) WPObject(org.pepsoft.worldpainter.objects.WPObject) Bo2ObjectProvider(org.pepsoft.worldpainter.layers.bo2.Bo2ObjectProvider)

Aggregations

WPObject (org.pepsoft.worldpainter.objects.WPObject)17 File (java.io.File)4 Point3i (javax.vecmath.Point3i)3 CustomObjectManager (org.pepsoft.worldpainter.plugins.CustomObjectManager)3 IOException (java.io.IOException)2 Serializable (java.io.Serializable)2 ArrayList (java.util.ArrayList)2 Random (java.util.Random)2 MirroredObject (org.pepsoft.worldpainter.objects.MirroredObject)2 RotatedObject (org.pepsoft.worldpainter.objects.RotatedObject)2 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 URL (java.net.URL)1 CertificateException (java.security.cert.CertificateException)1 CertificateFactory (java.security.cert.CertificateFactory)1 X509Certificate (java.security.cert.X509Certificate)1 Dimension (org.pepsoft.worldpainter.Dimension)1 Fixup (org.pepsoft.worldpainter.exporting.Fixup)1 Bo2Layer (org.pepsoft.worldpainter.layers.Bo2Layer)1 Bo2ObjectProvider (org.pepsoft.worldpainter.layers.bo2.Bo2ObjectProvider)1