Search in sources :

Example 36 with Tile

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

the class Splitter method handleItem.

@Override
public void handleItem(Item item, Tile tile, Tile source) {
    Tile to = getTileTarget(item, tile, source, true);
    to.block().handleItem(item, to, tile);
}
Also used : Tile(io.anuke.mindustry.world.Tile)

Example 37 with Tile

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

the class Splitter method getTileTarget.

Tile getTileTarget(Item item, Tile dest, Tile source, boolean flip) {
    int dir = source.relativeTo(dest.x, dest.y);
    if (dir == -1)
        return null;
    Tile to;
    Tile a = dest.getNearby(Mathf.mod(dir - 1, 4));
    Tile b = dest.getNearby(Mathf.mod(dir + 1, 4));
    boolean ac = !(a.block().instantTransfer && source.block().instantTransfer) && a.block().acceptItem(item, a, dest);
    boolean bc = !(b.block().instantTransfer && source.block().instantTransfer) && b.block().acceptItem(item, b, dest);
    if (ac && !bc) {
        to = a;
    } else if (bc && !ac) {
        to = b;
    } else {
        if (dest.getDump() == 0) {
            to = a;
            if (flip)
                dest.setDump((byte) 1);
        } else {
            to = b;
            if (flip)
                dest.setDump((byte) 0);
        }
    }
    return to;
}
Also used : Tile(io.anuke.mindustry.world.Tile)

Example 38 with Tile

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

the class Teleporter method handleItem.

@Override
public void handleItem(Item item, Tile tile, Tile source) {
    PowerEntity entity = tile.entity();
    Array<Tile> links = findLinks(tile);
    if (links.size > 0) {
        if (!syncBlockState || Net.server() || !Net.active()) {
            Tile target = links.random();
            target.entity.addItem(item, 1);
        }
    }
    entity.power -= powerPerItem;
}
Also used : Tile(io.anuke.mindustry.world.Tile)

Example 39 with Tile

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

the class Teleporter method findLinks.

private Array<Tile> findLinks(Tile tile) {
    TeleporterEntity entity = tile.entity();
    removal.clear();
    returns.clear();
    for (Tile other : teleporters[entity.color]) {
        if (other != tile) {
            if (other.block() instanceof Teleporter) {
                if (other.<TeleporterEntity>entity().color != entity.color) {
                    removal.add(other);
                } else if (other.entity.totalItems() == 0) {
                    returns.add(other);
                }
            } else {
                removal.add(other);
            }
        }
    }
    for (Tile remove : removal) teleporters[entity.color].remove(remove);
    return returns;
}
Also used : Tile(io.anuke.mindustry.world.Tile)

Example 40 with Tile

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

the class TunnelConveyor method getDebugInfo.

@Override
public Array<Object> getDebugInfo(Tile tile) {
    TunnelEntity entity = tile.entity();
    Array<Object> arr = super.getDebugInfo(tile);
    for (int i = 0; i < 4; i++) {
        arr.add("nearby." + i);
        arr.add(tile.getNearby(i));
    }
    arr.add("buffer");
    arr.add(entity.index);
    for (int i = 0; i < entity.index; i++) {
        long l = entity.items[i];
        float time = NumberUtils.intBitsToFloat(Bits.getLeftInt(l));
        Item item = Item.getByID(Bits.getRightInt(l));
        Tile dest = getDestTunnel(tile, item);
        arr.add("  buffer.item");
        arr.add(time + " | " + item.name + " | " + (dest == null ? "no dest" : dest.block() + ":" + dest.floor()));
    }
    return arr;
}
Also used : Item(io.anuke.mindustry.resource.Item) Tile(io.anuke.mindustry.world.Tile)

Aggregations

Tile (io.anuke.mindustry.world.Tile)45 Enemy (io.anuke.mindustry.entities.enemies.Enemy)10 Item (io.anuke.mindustry.resource.Item)7 SpawnPoint (io.anuke.mindustry.game.SpawnPoint)6 Block (io.anuke.mindustry.world.Block)6 Vector2 (com.badlogic.gdx.math.Vector2)5 IOException (java.io.IOException)5 Array (com.badlogic.gdx.utils.Array)4 Player (io.anuke.mindustry.entities.Player)3 BlockPart (io.anuke.mindustry.world.blocks.types.BlockPart)3 PowerAcceptor (io.anuke.mindustry.world.blocks.types.PowerAcceptor)3 Rock (io.anuke.mindustry.world.blocks.types.Rock)3 IntMap (com.badlogic.gdx.utils.IntMap)2 LiquidBlock (io.anuke.mindustry.world.blocks.types.LiquidBlock)2 StaticBlock (io.anuke.mindustry.world.blocks.types.StaticBlock)2 GridPoint2 (com.badlogic.gdx.math.GridPoint2)1 Rectangle (com.badlogic.gdx.math.Rectangle)1 Vars (io.anuke.mindustry.Vars)1 TileEntity (io.anuke.mindustry.entities.TileEntity)1 Difficulty (io.anuke.mindustry.game.Difficulty)1