Added liquid tunnel recipe, fixed crashes/bugs

This commit is contained in:
Anuken
2018-03-04 00:17:30 -05:00
parent 9b3c9aaea2
commit 992fcc73b8
8 changed files with 159 additions and 146 deletions

View File

@@ -87,6 +87,7 @@ public class Recipes {
new Recipe(liquid, DistributionBlocks.pulseconduit, stack(Item.titanium, 1), stack(Item.steel, 1)),
new Recipe(liquid, DistributionBlocks.liquidrouter, stack(Item.steel, 2)),
new Recipe(liquid, DistributionBlocks.liquidjunction, stack(Item.steel, 2)),
new Recipe(liquid, DistributionBlocks.conduittunnel, stack(Item.titanium, 2), stack(Item.steel, 2)),
new Recipe(liquid, ProductionBlocks.pump, stack(Item.steel, 10)),
new Recipe(liquid, ProductionBlocks.fluxpump, stack(Item.steel, 10), stack(Item.dirium, 5)),

View File

@@ -57,6 +57,9 @@ public class DistributionBlocks{
}},
tunnel = new TunnelConveyor("conveyortunnel"){{
}},
conduittunnel = new TunnelConduit("conduittunnel"){{
}},
liquidjunction = new LiquidJunction("liquidjunction"){{

View File

@@ -60,7 +60,6 @@ public class LiquidBlock extends Block implements LiquidAcceptor{
if(entity.liquidAmount > 0.01f && entity.timer.get(timerFlow, 1)){
tryMoveLiquid(tile, tile.getNearby(tile.getRotation()));
}
}
public void tryDumpLiquid(Tile tile){

View File

@@ -3,6 +3,8 @@ package io.anuke.mindustry.world.blocks.types.distribution;
import io.anuke.mindustry.resource.Liquid;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.types.LiquidAcceptor;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.util.Log;
public class TunnelConduit extends Conduit {
protected int maxdist = 3;
@@ -11,18 +13,23 @@ public class TunnelConduit extends Conduit {
protected TunnelConduit(String name) {
super(name);
rotate = true;
update = false;
solid = true;
health = 70;
instantTransfer = true;
}
@Override
public void draw(Tile tile){
Draw.rect(name, tile.drawx(), tile.drawy(), tile.getRotation() * 90);
}
@Override
public void handleLiquid(Tile tile, Tile source, Liquid liquid, float amount) {
Tile tunnel = getDestTunnel(tile, liquid, amount);
Log.info("handle");
Tile tunnel = getDestTunnel(tile);
if (tunnel == null) return;
Tile to = tunnel.getNearby(tunnel.getRotation());
if (to == null || !(to instanceof LiquidAcceptor)) return;
if (to == null || !(to.block() instanceof LiquidAcceptor)) return;
LiquidAcceptor a = (LiquidAcceptor) to.block();
@@ -31,31 +38,27 @@ public class TunnelConduit extends Conduit {
@Override
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount) {
TunnelConveyor.TunnelEntity entity = tile.entity();
if (entity.index >= entity.buffer.length - 1) return false;
int rot = source.relativeTo(tile.x, tile.y);
if (rot != (tile.getRotation() + 2) % 4) return false;
Tile tunnel = getDestTunnel(tile, liquid, amount);
Tile tunnel = getDestTunnel(tile);
if (tunnel != null) {
Tile to = tunnel.getNearby(tunnel.getRotation());
return to != null && (to instanceof LiquidAcceptor) && ((LiquidAcceptor) to.block()).acceptLiquid(to, tunnel, liquid, amount);
return to != null && (to.block() instanceof LiquidAcceptor) &&
((LiquidAcceptor) to.block()).acceptLiquid(to, tunnel, liquid, amount);
} else {
return false;
}
}
Tile getDestTunnel(Tile tile, Liquid liquid, float amount) {
Tile getDestTunnel(Tile tile) {
Tile dest = tile;
int rel = (tile.getRotation() + 2) % 4;
for (int i = 0; i < maxdist; i++) {
if (dest == null) return null;
dest = dest.getNearby(rel);
if (dest != null && dest.block() instanceof TunnelConduit && dest.getRotation() == rel
&& dest.getNearby(rel) != null
&& ((TunnelConduit) dest.getNearby(rel).block()).acceptLiquid(dest.getNearby(rel), dest, liquid, amount)) {
&& dest.getNearby(rel) != null) {
return dest;
}
}