Search in sources :

Example 1 with Block

use of io.anuke.mindustry.world.Block in project Mindustry by Anuken.

the class Door method anyEntities.

boolean anyEntities(Tile tile) {
    int x = tile.x, y = tile.y;
    Block type = tile.block();
    rect.setSize(type.width * tilesize, type.height * tilesize);
    rect.setCenter(tile.drawx(), tile.drawy());
    for (SolidEntity e : Entities.getNearby(enemyGroup, x * tilesize, y * tilesize, tilesize * 2f)) {
        Rectangle rect = e.hitbox.getRect(e.x, e.y);
        if (this.rect.overlaps(rect)) {
            return true;
        }
    }
    for (SolidEntity e : Entities.getNearby(playerGroup, x * tilesize, y * tilesize, tilesize * 2f)) {
        Rectangle rect = e.hitbox.getRect(e.x, e.y);
        if (this.rect.overlaps(rect)) {
            return true;
        }
    }
    return false;
}
Also used : SolidEntity(io.anuke.ucore.entities.SolidEntity) Rectangle(com.badlogic.gdx.math.Rectangle) Block(io.anuke.mindustry.world.Block)

Example 2 with Block

use of io.anuke.mindustry.world.Block in project Mindustry by Anuken.

the class MapFilter method process.

public Pixmap process(Pixmap pixmap) {
    if (prefs.get("terrain").enabled) {
        for (int x = 0; x < pixmap.getWidth(); x++) {
            for (int y = 0; y < pixmap.getHeight(); y++) {
                float dist = Vector2.dst((float) x / pixmap.getWidth(), (float) y / pixmap.getHeight(), 0.5f, 0.5f) * 2f;
                double noise = sim.octaveNoise2D(6, 0.6, 1 / 180.0, x, y + 9999) / (prefs.get("circle").enabled ? 1.7 : 1f) + dist / 10f;
                if (dist > 0.8) {
                    noise += 2 * (dist - 0.8);
                }
                Block block = noise > 0.6 ? Blocks.stoneblock : Blocks.stone;
                pixmap.drawPixel(x, y, ColorMapper.getColor(block));
            }
        }
    }
    Pixmap src = Pixmaps.copy(pixmap);
    for (int x = 0; x < pixmap.getWidth(); x++) {
        for (int y = 0; y < pixmap.getHeight(); y++) {
            int dx = 0, dy = 0;
            if (prefs.get("distort").enabled) {
                double intensity = 12;
                double scale = 80;
                double octaves = 4;
                double falloff = 0.6;
                double nx = (sim.octaveNoise2D(octaves, falloff, 1 / scale, x, y) - 0.5f) * intensity;
                double ny = (sim.octaveNoise2D(octaves, falloff, 1 / scale, x, y + 99999) - 0.5f) * intensity;
                dx = (int) nx;
                dy = (int) ny;
            }
            int pix = src.getPixel(x + dx, y + dy);
            BlockPair pair = ColorMapper.get(pix);
            Block block = pair == null ? null : pair.wall == Blocks.air ? pair.floor : pair.wall;
            if (block == null)
                continue;
            boolean floor = block instanceof Floor;
            double noise = sim.octaveNoise2D(4, 0.6, 1 / 170.0, x, y) + sim.octaveNoise2D(1, 1.0, 1 / 5.0, x, y) / 18.0;
            double nwater = sim.octaveNoise2D(1, 1.0, 1 / 130.0, x, y);
            noise += nwater / 5.0;
            double noil = sim.octaveNoise2D(1, 1.0, 1 / 150.0, x + 9999, y) + sim.octaveNoise2D(1, 1.0, 1 / 2.0, x, y) / 290.0;
            if (!floor || prefs.get("replace").enabled) {
                if (prefs.get("allgrass").enabled) {
                    block = floor ? Blocks.grass : Blocks.grassblock;
                } else if (prefs.get("allsnow").enabled) {
                    block = floor ? Blocks.snow : Blocks.snowblock;
                } else if (prefs.get("allsand").enabled) {
                    block = floor ? Blocks.sand : Blocks.sandblock;
                } else if (prefs.get("replace").enabled) {
                    block = floor ? Blocks.stone : Blocks.stoneblock;
                }
                if (noise > 0.7 && prefs.get("grass").enabled) {
                    block = floor ? Blocks.grass : Blocks.grassblock;
                }
                if (noise > 0.7 && prefs.get("blackstone").enabled) {
                    block = floor ? Blocks.blackstone : Blocks.blackstoneblock;
                }
                if (noise > 0.7 && prefs.get("sand").enabled) {
                    block = floor ? Blocks.sand : Blocks.sandblock;
                }
                if (noise > 0.8 && prefs.get("stone").enabled) {
                    block = floor ? Blocks.stone : Blocks.stoneblock;
                }
            }
            if (floor) {
                if (nwater > 0.93 && prefs.get("water").enabled) {
                    block = Blocks.water;
                    if (nwater > 0.943) {
                        block = Blocks.deepwater;
                    }
                }
                if (noil > 0.95 && prefs.get("oil").enabled) {
                    block = Blocks.dirt;
                    if (noil > 0.955) {
                        block = Blocks.oil;
                    }
                }
            }
            if (floor && prefs.get("lavariver").enabled) {
                double lava = rid.getValue(x, y, 1 / 100f);
                double t = 0.6;
                if (lava > t) {
                    block = Blocks.lava;
                } else if (lava > t - 0.2) {
                    block = Blocks.blackstone;
                }
            }
            if (floor && prefs.get("slavariver").enabled) {
                double lava = rid.getValue(x, y, 1 / 40f);
                double t = 0.7;
                if (lava > t) {
                    block = Blocks.lava;
                } else if (lava > t - 0.3) {
                    block = Blocks.blackstone;
                }
            }
            if (floor && prefs.get("oilriver").enabled) {
                double lava = rid3.getValue(x, y, 1 / 100f);
                double t = 0.9;
                if (lava > t) {
                    block = Blocks.oil;
                } else if (lava > t - 0.2) {
                    block = Blocks.dirt;
                }
            }
            if (floor && prefs.get("river").enabled) {
                double riv = rid2.getValue(x, y, 1 / 140f);
                double t = 0.4;
                if (riv > t + 0.1) {
                    block = Blocks.deepwater;
                } else if (riv > t) {
                    block = Blocks.water;
                } else if (riv > t - 0.2) {
                    block = Blocks.grass;
                }
            }
            if (floor && prefs.get("iceriver").enabled) {
                double riv = rid2.getValue(x, y, 1 / 140f);
                double t = 0.4;
                if (riv > t + 0.1) {
                    block = Blocks.ice;
                } else if (riv > t) {
                    block = Blocks.ice;
                } else if (riv > t - 0.2) {
                    block = Blocks.snow;
                }
            }
            pixmap.drawPixel(x, y, ColorMapper.getColor(block));
        }
    }
    src.dispose();
    return pixmap;
}
Also used : Floor(io.anuke.mindustry.world.blocks.types.Floor) BlockPair(io.anuke.mindustry.world.ColorMapper.BlockPair) Block(io.anuke.mindustry.world.Block) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Example 3 with Block

use of io.anuke.mindustry.world.Block in project Mindustry by Anuken.

the class InputHandler method validPlace.

public boolean validPlace(int x, int y, Block type) {
    if (!type.isMultiblock() && control.tutorial().active() && control.tutorial().showBlock()) {
        GridPoint2 point = control.tutorial().getPlacePoint();
        int rotation = control.tutorial().getPlaceRotation();
        Block block = control.tutorial().getPlaceBlock();
        if (type != block || point.x != x - world.getCore().x || point.y != y - world.getCore().y || (rotation != -1 && rotation != this.rotation)) {
            return false;
        }
    } else if (control.tutorial().active()) {
        return false;
    }
    return Placement.validPlace(x, y, type);
}
Also used : Block(io.anuke.mindustry.world.Block) GridPoint2(com.badlogic.gdx.math.GridPoint2)

Example 4 with Block

use of io.anuke.mindustry.world.Block in project Mindustry by Anuken.

the class BlockLoader method load.

public static void load() {
    Block[] blockClasses = { Blocks.air, DefenseBlocks.compositewall, DistributionBlocks.conduit, ProductionBlocks.coaldrill, WeaponBlocks.chainturret, SpecialBlocks.enemySpawn // add any new block sections here
    };
    for (String string : defaultMap.keys()) {
        Block block = Block.getByName(string);
        blockmap.put(defaultMap.get(string, -1), block);
    }
    for (Block block : Block.getAllBlocks()) {
        block.init();
    }
    Log.info("Total blocks loaded: {0}", Block.getAllBlocks().size);
}
Also used : Block(io.anuke.mindustry.world.Block)

Example 5 with Block

use of io.anuke.mindustry.world.Block in project Mindustry by Anuken.

the class TileEntity method onDeath.

public void onDeath(boolean force) {
    if (Net.server()) {
        NetEvents.handleBlockDestroyed(this);
    }
    if (!Net.active() || Net.server() || force) {
        if (!dead) {
            dead = true;
            Block block = tile.block();
            block.onDestroyed(tile);
            world.removeBlock(tile);
            remove();
        }
    }
}
Also used : Block(io.anuke.mindustry.world.Block)

Aggregations

Block (io.anuke.mindustry.world.Block)16 Tile (io.anuke.mindustry.world.Tile)6 Enemy (io.anuke.mindustry.entities.enemies.Enemy)5 Array (com.badlogic.gdx.utils.Array)3 Item (io.anuke.mindustry.resource.Item)3 BlockPair (io.anuke.mindustry.world.ColorMapper.BlockPair)3 IOException (java.io.IOException)3 GridPoint2 (com.badlogic.gdx.math.GridPoint2)2 IntMap (com.badlogic.gdx.utils.IntMap)2 BlockPart (io.anuke.mindustry.world.blocks.types.BlockPart)2 Rock (io.anuke.mindustry.world.blocks.types.Rock)2 StaticBlock (io.anuke.mindustry.world.blocks.types.StaticBlock)2 Pixmap (com.badlogic.gdx.graphics.Pixmap)1 Rectangle (com.badlogic.gdx.math.Rectangle)1 SpawnPoint (io.anuke.mindustry.game.SpawnPoint)1 Layer (io.anuke.mindustry.world.Layer)1 Floor (io.anuke.mindustry.world.blocks.types.Floor)1 SolidEntity (io.anuke.ucore.entities.SolidEntity)1 Table (io.anuke.ucore.scene.ui.layout.Table)1