Added liquid bridge / Smoothed conduit liquid display
This commit is contained in:
@@ -114,6 +114,7 @@ public class Recipes {
|
||||
new Recipe(liquid, LiquidBlocks.liquidtank, stack(Items.steel, 2)),
|
||||
new Recipe(liquid, LiquidBlocks.liquidjunction, stack(Items.steel, 2)),
|
||||
new Recipe(liquid, LiquidBlocks.conduittunnel, stack(Items.titanium, 2), stack(Items.steel, 2)),
|
||||
new Recipe(liquid, LiquidBlocks.liquidbridge, stack(Items.titanium, 2), stack(Items.steel, 2)),
|
||||
|
||||
new Recipe(liquid, LiquidBlocks.pump, stack(Items.steel, 10)),
|
||||
new Recipe(liquid, LiquidBlocks.fluxpump, stack(Items.steel, 10), stack(Items.densealloy, 5)),
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
package io.anuke.mindustry.content.blocks;
|
||||
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.blocks.types.distribution.Conduit;
|
||||
import io.anuke.mindustry.world.blocks.types.distribution.LiquidJunction;
|
||||
import io.anuke.mindustry.world.blocks.types.distribution.LiquidRouter;
|
||||
import io.anuke.mindustry.world.blocks.types.distribution.TunnelConduit;
|
||||
import io.anuke.mindustry.world.blocks.types.distribution.*;
|
||||
import io.anuke.mindustry.world.blocks.types.production.Pump;
|
||||
|
||||
public class LiquidBlocks {
|
||||
@@ -41,5 +38,9 @@ public class LiquidBlocks {
|
||||
|
||||
conduittunnel = new TunnelConduit("conduittunnel") {{
|
||||
speed = 53;
|
||||
}},
|
||||
|
||||
liquidbridge = new LiquidBridge("liquidbridge"){{
|
||||
range = 7;
|
||||
}};
|
||||
}
|
||||
|
||||
@@ -81,8 +81,8 @@ public abstract class BaseBlock {
|
||||
}
|
||||
}
|
||||
|
||||
public void tryMoveLiquid(Tile tile, Tile next){
|
||||
if(next == null) return;
|
||||
public float tryMoveLiquid(Tile tile, Tile next){
|
||||
if(next == null) return 0;
|
||||
|
||||
next = next.target();
|
||||
|
||||
@@ -90,21 +90,23 @@ public abstract class BaseBlock {
|
||||
float ofract = next.entity.liquid.amount / next.block().liquidCapacity;
|
||||
float fract = tile.entity.liquid.amount / liquidCapacity;
|
||||
|
||||
if(ofract > fract) return;
|
||||
if(ofract > fract) return 0;
|
||||
|
||||
float flow = Math.min(Mathf.clamp((fract - ofract)*(1f)) * (liquidCapacity), tile.entity.liquid.amount);
|
||||
|
||||
flow = Math.min(flow, next.block().liquidCapacity - next.entity.liquid.amount - 0.001f);
|
||||
|
||||
if(flow <= 0f) return;
|
||||
if(flow <= 0f) return 0;
|
||||
|
||||
float amount = flow;
|
||||
|
||||
if(next.block().acceptLiquid(next, tile, tile.entity.liquid.liquid, amount)){
|
||||
next.block().handleLiquid(next, tile, tile.entity.liquid.liquid, amount);
|
||||
tile.entity.liquid.amount -= amount;
|
||||
return flow;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
package io.anuke.mindustry.world.blocks.types.distribution;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.resource.Liquid;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.LiquidBlock;
|
||||
import io.anuke.mindustry.world.blocks.types.modules.LiquidModule;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Conduit extends LiquidBlock {
|
||||
protected final int timerFlow = timers++;
|
||||
@@ -16,8 +23,28 @@ public class Conduit extends LiquidBlock {
|
||||
solid = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Tile tile){
|
||||
ConduitEntity entity = tile.entity();
|
||||
LiquidModule mod = tile.entity.liquid;
|
||||
|
||||
int rotation = rotate ? tile.getRotation() * 90 : 0;
|
||||
|
||||
Draw.rect(name() + "-bottom", tile.drawx(), tile.drawy(), rotation);
|
||||
|
||||
Draw.color(mod.liquid.color);
|
||||
Draw.alpha(entity.smoothLiquid);
|
||||
Draw.rect(liquidRegion, tile.drawx(), tile.drawy(), rotation);
|
||||
Draw.color();
|
||||
|
||||
Draw.rect(name() + "-top", tile.drawx(), tile.drawy(), rotation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
ConduitEntity entity = tile.entity();
|
||||
entity.smoothLiquid = Mathf.lerpDelta(entity.smoothLiquid, entity.liquid.amount/liquidCapacity, 0.05f);
|
||||
|
||||
if(tile.entity.liquid.amount > 0.001f && tile.entity.timer.get(timerFlow, 1)){
|
||||
tryMoveLiquid(tile, tile.getNearby(tile.getRotation()));
|
||||
}
|
||||
@@ -32,4 +59,23 @@ public class Conduit extends LiquidBlock {
|
||||
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount) {
|
||||
return super.acceptLiquid(tile, source, liquid, amount) && ((2 + source.relativeTo(tile.x, tile.y)) % 4 != tile.getRotation());
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity getEntity() {
|
||||
return new ConduitEntity();
|
||||
}
|
||||
|
||||
public static class ConduitEntity extends TileEntity {
|
||||
public float smoothLiquid;
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream stream) throws IOException {
|
||||
stream.writeFloat(smoothLiquid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInputStream stream) throws IOException {
|
||||
smoothLiquid = stream.readFloat();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,11 +143,11 @@ public class ItemBridge extends Block {
|
||||
Draw.color(Color.WHITE, Color.BLACK, Mathf.absin(Timers.time(), 6f, 0.07f));
|
||||
Draw.alpha(Math.max(entity.uptime, 0.25f));
|
||||
|
||||
Draw.rect("lightbridge-end", tile.drawx(), tile.drawy(), i*90 + 90);
|
||||
Draw.rect("lightbridge-end", other.drawx(), other.drawy(), i*90 + 270);
|
||||
Draw.rect(name + "-end", tile.drawx(), tile.drawy(), i*90 + 90);
|
||||
Draw.rect(name + "-end", other.drawx(), other.drawy(), i*90 + 270);
|
||||
|
||||
Lines.stroke(8f);
|
||||
Lines.line(Draw.region("lightbridge"),
|
||||
Lines.line(Draw.region(name + "-bridge"),
|
||||
tile.worldx(),
|
||||
tile.worldy(),
|
||||
other.worldx(),
|
||||
@@ -162,7 +162,7 @@ public class ItemBridge extends Block {
|
||||
|
||||
for(int a = 0; a < arrows; a ++){
|
||||
Draw.alpha(Mathf.absin(a/(float)arrows - entity.time/100f, 0.1f, 1f) * entity.uptime);
|
||||
Draw.rect("lightbridge-arrow",
|
||||
Draw.rect(name + "-arrow",
|
||||
tile.worldx() + Geometry.d4[i].x*(tilesize/2f + a*4f + time % 4f),
|
||||
tile.worldy() + Geometry.d4[i].y*(tilesize/2f + a*4f + time % 4f),
|
||||
i*90f);
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package io.anuke.mindustry.world.blocks.types.distribution;
|
||||
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
|
||||
public class LiquidBridge extends ItemBridge {
|
||||
protected float transportSpeed = 0.5f;
|
||||
|
||||
public LiquidBridge(String name) {
|
||||
super(name);
|
||||
hasInventory = false;
|
||||
hasLiquids = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Tile tile) {
|
||||
ItemBridgeEntity entity = tile.entity();
|
||||
|
||||
entity.time += entity.cycleSpeed* Timers.delta();
|
||||
entity.time2 += (entity.cycleSpeed-1f)*Timers.delta();
|
||||
|
||||
Tile other = world.tile(entity.link);
|
||||
if(!linkValid(tile, other)){
|
||||
tryDumpLiquid(tile);
|
||||
}else{
|
||||
float use = Math.min(powerCapacity, powerUse * Timers.delta());
|
||||
|
||||
if(entity.power.amount >= use){
|
||||
entity.uptime = Mathf.lerpDelta(entity.uptime, 1f, 0.04f);
|
||||
entity.power.amount -= use;
|
||||
}else{
|
||||
entity.uptime = Mathf.lerpDelta(entity.uptime, 0f, 0.02f);
|
||||
}
|
||||
|
||||
if(entity.uptime >= 0.5f){
|
||||
|
||||
if(tryMoveLiquid(tile, other) > 0.1f){
|
||||
entity.cycleSpeed = Mathf.lerpDelta(entity.cycleSpeed, 4f, 0.05f);
|
||||
}else{
|
||||
entity.cycleSpeed = Mathf.lerpDelta(entity.cycleSpeed, 1f, 0.01f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user