use of io.anuke.mindustry.world.Tile in project Mindustry by Anuken.
the class Sorter 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 Sorter method getTileTarget.
Tile getTileTarget(Item item, Tile dest, Tile source, boolean flip) {
SorterEntity entity = dest.entity();
int dir = source.relativeTo(dest.x, dest.y);
if (dir == -1)
return null;
Tile to;
if (item == entity.sortItem) {
to = dest.getNearby(dir);
} else {
Tile a = dest.getNearby(Mathf.mod(dir - 1, 4));
Tile b = dest.getNearby(Mathf.mod(dir + 1, 4));
boolean ac = a != null && !(a.block().instantTransfer && source.block().instantTransfer) && a.block().acceptItem(item, a, dest);
boolean bc = b != null && !(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 (!bc) {
return null;
} 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 TunnelConveyor method handleItem.
@Override
public void handleItem(Item item, Tile tile, Tile source) {
TunnelEntity entity = tile.entity();
if (entity.index >= entity.buffer.length)
return;
Tile tunnel = getDestTunnel(tile, item);
if (tunnel == null)
return;
Tile to = tunnel.getNearby(tunnel.getRotation());
if (to == null)
return;
entity.buffer[entity.index++] = Bits.packLong(NumberUtils.floatToIntBits(Timers.time()), item.id);
}
use of io.anuke.mindustry.world.Tile in project Mindustry by Anuken.
the class TunnelConveyor method update.
@Override
public void update(Tile tile) {
TunnelEntity entity = tile.entity();
if (entity.index > 0) {
long l = entity.buffer[0];
float time = NumberUtils.intBitsToFloat(Bits.getLeftInt(l));
if (Timers.time() >= time + speed || Timers.time() < time) {
Item item = Item.getByID(Bits.getRightInt(l));
Tile tunnel = getDestTunnel(tile, item);
if (tunnel == null)
return;
Tile target = tunnel.getNearby(tunnel.getRotation());
if (target == null)
return;
if (!target.block().acceptItem(item, target, tunnel))
return;
target.block().handleItem(item, target, tunnel);
System.arraycopy(entity.buffer, 1, entity.buffer, 0, entity.index - 1);
entity.index--;
}
}
}
use of io.anuke.mindustry.world.Tile in project Mindustry by Anuken.
the class Generator method distributeLaserPower.
protected void distributeLaserPower(Tile tile) {
PowerEntity entity = tile.entity();
for (int i = 0; i < laserDirections; i++) {
int rot = (tile.getRotation() + i) - laserDirections / 2;
Tile target = laserTarget(tile, rot);
if (target == null || isInterfering(target, rot))
continue;
PowerAcceptor p = (PowerAcceptor) target.block();
float transmit = Math.min(powerSpeed * Timers.delta(), entity.power);
if (p.acceptsPower(target)) {
float accepted = p.addPower(target, transmit);
entity.power -= accepted;
}
}
}
Aggregations