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);
}
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;
}
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;
}
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;
}
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;
}
Aggregations