Liquid total bugfixes
This commit is contained in:
@@ -1506,7 +1506,7 @@ public class Blocks implements ContentList{
|
||||
//TODO different name
|
||||
reinforcedPump = new Pump("reinforced-pump"){{
|
||||
requirements(Category.liquid, with(Items.beryllium, 70, Items.tungsten, 20, Items.silicon, 20));
|
||||
//TODO CUSTOM DRAW ANIMATION + 3x3?
|
||||
//TODO CUSTOM DRAW ANIMATION
|
||||
//TODO balance consumption
|
||||
consumes.liquid(Liquids.hydrogen, 1.5f / 60f);
|
||||
|
||||
|
||||
@@ -556,7 +556,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
||||
}
|
||||
|
||||
public boolean acceptItem(Building source, Item item){
|
||||
return block.consumes.itemFilters.get(item.id) && items.get(item) < getMaximumAccepted(item);
|
||||
return block.consumes.consumesItem(item) && items.get(item) < getMaximumAccepted(item);
|
||||
}
|
||||
|
||||
public boolean acceptLiquid(Building source, Liquid liquid){
|
||||
@@ -644,21 +644,23 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
||||
next.handleLiquid(self(), liquid, flow);
|
||||
liquids.remove(liquid, flow);
|
||||
return flow;
|
||||
}else if(next.liquids.currentAmount() / next.block.liquidCapacity > 0.1f && fract > 0.1f){
|
||||
//handle reactions between different liquid types ▼
|
||||
}else if(!next.block.consumes.consumesLiquid(liquid) && next.liquids.currentAmount() / next.block.liquidCapacity > 0.1f && fract > 0.1f){
|
||||
//TODO !IMPORTANT! uses current(), which is 1) wrong for multi-liquid blocks and 2) causes unwanted reactions, e.g. hydrogen + slag in pump
|
||||
//TODO these are incorrect effect positions
|
||||
float fx = (x + next.x) / 2f, fy = (y + next.y) / 2f;
|
||||
|
||||
Liquid other = next.liquids.current();
|
||||
//TODO liquid reaction handler for extensibility
|
||||
if((other.flammability > 0.3f && liquid.temperature > 0.7f) || (liquid.flammability > 0.3f && other.temperature > 0.7f)){
|
||||
damage(1 * Time.delta);
|
||||
next.damage(1 * Time.delta);
|
||||
if(Mathf.chance(0.1 * Time.delta)){
|
||||
damageContinuous(1);
|
||||
next.damageContinuous(1);
|
||||
if(Mathf.chanceDelta(0.1)){
|
||||
Fx.fire.at(fx, fy);
|
||||
}
|
||||
}else if((liquid.temperature > 0.7f && other.temperature < 0.55f) || (other.temperature > 0.7f && liquid.temperature < 0.55f)){
|
||||
liquids.remove(liquid, Math.min(liquids.get(liquid), 0.7f * Time.delta));
|
||||
if(Mathf.chance(0.2f * Time.delta)){
|
||||
if(Mathf.chanceDelta(0.2f)){
|
||||
Fx.steam.at(fx, fy);
|
||||
}
|
||||
}
|
||||
@@ -1468,7 +1470,8 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
||||
case range -> this instanceof Ranged r ? r.range() / tilesize : 0;
|
||||
case rotation -> rotation;
|
||||
case totalItems -> items == null ? 0 : items.total();
|
||||
case totalLiquids -> liquids == null ? 0 : liquids.total();
|
||||
//TODO will give wildly fluctuating amounts due to switching of current() for multi-liquid blocks. totalLiquids is inherently bad design, but unfortunately it is useful for conduits/tanks
|
||||
case totalLiquids -> liquids == null ? 0 : liquids.currentAmount();
|
||||
case totalPower -> power == null || !block.consumes.hasPower() ? 0 : power.status * (block.consumes.getPower().buffered ? block.consumes.getPower().capacity : 1f);
|
||||
case itemCapacity -> block.hasItems ? block.itemCapacity : 0;
|
||||
case liquidCapacity -> block.hasLiquids ? block.liquidCapacity : 0;
|
||||
|
||||
@@ -49,7 +49,7 @@ public class LiquidTurret extends Turret{
|
||||
consumes.add(new ConsumeLiquidFilter(i -> ammoTypes.containsKey(i), 1f){
|
||||
@Override
|
||||
public boolean valid(Building build){
|
||||
return build.liquids.total() > 0.001f;
|
||||
return build.liquids.currentAmount() >= 0.001f;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -78,7 +78,7 @@ public class LiquidTurret extends Turret{
|
||||
super.draw();
|
||||
|
||||
if(liquidRegion.found()){
|
||||
Drawf.liquid(liquidRegion, x + recoilOffset.x, y + recoilOffset.y, liquids.total() / liquidCapacity, liquids.current().color, rotation - 90);
|
||||
Drawf.liquid(liquidRegion, x + recoilOffset.x, y + recoilOffset.y, liquids.currentAmount() / liquidCapacity, liquids.current().color, rotation - 90);
|
||||
}
|
||||
if(topRegion.found()) Draw.rect(topRegion, x + recoilOffset.x, y + recoilOffset.y, rotation - 90);
|
||||
}
|
||||
@@ -140,7 +140,7 @@ public class LiquidTurret extends Turret{
|
||||
|
||||
@Override
|
||||
public boolean hasAmmo(){
|
||||
return ammoTypes.get(liquids.current()) != null && liquids.total() >= 1f / ammoTypes.get(liquids.current()).ammoMultiplier;
|
||||
return ammoTypes.get(liquids.current()) != null && liquids.currentAmount() >= 1f / ammoTypes.get(liquids.current()).ammoMultiplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -31,8 +31,8 @@ public class DirectionLiquidBridge extends DirectionBridge{
|
||||
public void draw(){
|
||||
Draw.rect(block.region, x, y);
|
||||
|
||||
if(liquids.total() > 0.001f){
|
||||
Drawf.liquid(liquidRegion, x, y, liquids.total() / liquidCapacity, liquids.current().color);
|
||||
if(liquids.currentAmount() > 0.001f){
|
||||
Drawf.liquid(liquidRegion, x, y, liquids.currentAmount() / liquidCapacity, liquids.current().color);
|
||||
}
|
||||
|
||||
Draw.rect(dirRegion, x, y, rotdeg());
|
||||
@@ -52,7 +52,7 @@ public class DirectionLiquidBridge extends DirectionBridge{
|
||||
}
|
||||
|
||||
if(link == null){
|
||||
if(liquids.total() > 0.0001f && timer(timerFlow, 1)){
|
||||
if(liquids.currentAmount() > 0.0001f && timer(timerFlow, 1)){
|
||||
moveLiquidForward(false, liquids.current());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ public class Conduit extends LiquidBlock implements Autotiler{
|
||||
public void updateTile(){
|
||||
smoothLiquid = Mathf.lerpDelta(smoothLiquid, liquids.currentAmount() / liquidCapacity, 0.05f);
|
||||
|
||||
if(liquids.total() > 0.001f && timer(timerFlow, 1)){
|
||||
if(liquids.currentAmount() > 0.001f && timer(timerFlow, 1)){
|
||||
moveLiquidForward(leaks, liquids.current());
|
||||
noSleep();
|
||||
}else{
|
||||
|
||||
@@ -33,8 +33,8 @@ public class LiquidBlock extends Block{
|
||||
float rotation = rotate ? rotdeg() : 0;
|
||||
Draw.rect(bottomRegion, x, y, rotation);
|
||||
|
||||
if(liquids.total() > 0.001f){
|
||||
Drawf.liquid(liquidRegion, x, y, liquids.total() / liquidCapacity, liquids.current().color);
|
||||
if(liquids.currentAmount() > 0.001f){
|
||||
Drawf.liquid(liquidRegion, x, y, liquids.currentAmount() / liquidCapacity, liquids.current().color);
|
||||
}
|
||||
|
||||
Draw.rect(topRegion, x, y, rotation);
|
||||
|
||||
@@ -15,7 +15,7 @@ public class LiquidRouter extends LiquidBlock{
|
||||
public class LiquidRouterBuild extends LiquidBuild{
|
||||
@Override
|
||||
public void updateTile(){
|
||||
if(liquids.total() > 0.01f){
|
||||
if(liquids.currentAmount() > 0.01f){
|
||||
dumpLiquid(liquids.current());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ public class PayloadLoader extends PayloadBlock{
|
||||
}
|
||||
|
||||
//load up liquids
|
||||
if(payload.block().hasLiquids && liquids.total() >= 0.001f){
|
||||
if(payload.block().hasLiquids && liquids.currentAmount() >= 0.001f){
|
||||
Liquid liq = liquids.current();
|
||||
float total = liquids.currentAmount();
|
||||
float flow = Math.min(Math.min(liquidsLoaded * edelta(), payload.block().liquidCapacity - payload.build.liquids.get(liq)), total);
|
||||
@@ -160,7 +160,7 @@ public class PayloadLoader extends PayloadBlock{
|
||||
public boolean shouldExport(){
|
||||
return payload != null && (
|
||||
exporting ||
|
||||
(payload.block().hasLiquids && liquids.total() >= 0.1f && payload.build.liquids.total() >= payload.block().liquidCapacity - 0.001f) ||
|
||||
(payload.block().hasLiquids && liquids.currentAmount() >= 0.1f && payload.build.liquids.currentAmount() >= payload.block().liquidCapacity - 0.001f) ||
|
||||
(payload.block().hasItems && items.any() && payload.block().separateItemCapacity && content.items().contains(i -> payload.build.items.get(i) >= payload.block().itemCapacity)));
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ public class BurnerGenerator extends ItemLiquidGenerator{
|
||||
}
|
||||
|
||||
if(hasLiquids && liquidRegion.found()){
|
||||
Drawf.liquid(liquidRegion, x, y, liquids.total() / liquidCapacity, liquids.current().color);
|
||||
Drawf.liquid(liquidRegion, x, y, liquids.currentAmount() / liquidCapacity, liquids.current().color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ public class ItemLiquidGenerator extends PowerGenerator{
|
||||
}
|
||||
|
||||
if(hasLiquids){
|
||||
Drawf.liquid(liquidRegion, x, y, liquids.total() / liquidCapacity, liquids.current().color);
|
||||
Drawf.liquid(liquidRegion, x, y, liquids.currentAmount() / liquidCapacity, liquids.current().color);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -104,6 +104,10 @@ public class GenericCrafter extends Block{
|
||||
if(outputLiquids == null && outputLiquid != null){
|
||||
outputLiquids = new LiquidStack[]{outputLiquid};
|
||||
}
|
||||
//write back to outputLiquid, as it helps with sensing
|
||||
if(outputLiquid == null && outputLiquids != null && outputLiquids.length > 0){
|
||||
outputLiquid = outputLiquids[0];
|
||||
}
|
||||
outputsLiquid = outputLiquids != null;
|
||||
super.init();
|
||||
}
|
||||
@@ -236,6 +240,8 @@ public class GenericCrafter extends Block{
|
||||
@Override
|
||||
public double sense(LAccess sensor){
|
||||
if(sensor == LAccess.progress) return Mathf.clamp(progress);
|
||||
//attempt to prevent wild total liquid fluctuation, at least for crafters
|
||||
if(sensor == LAccess.totalLiquids && outputLiquid != null) return liquids.get(outputLiquid.liquid);
|
||||
return super.sense(sensor);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import arc.graphics.g2d.*;
|
||||
import arc.util.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.logic.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.liquid.*;
|
||||
@@ -114,6 +115,12 @@ public class Pump extends LiquidBlock{
|
||||
amount = 0f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double sense(LAccess sensor){
|
||||
if(sensor == LAccess.totalLiquids) return liquidDrop == null ? 0f : liquids.get(liquidDrop);
|
||||
return super.sense(sensor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProximityUpdate(){
|
||||
super.onProximityUpdate();
|
||||
|
||||
@@ -76,7 +76,7 @@ public class Separator extends Block{
|
||||
public void draw(){
|
||||
super.draw();
|
||||
|
||||
Drawf.liquid(liquidRegion, x, y, liquids.total() / liquidCapacity, liquids.current().color);
|
||||
Drawf.liquid(liquidRegion, x, y, liquids.currentAmount() / liquidCapacity, liquids.current().color);
|
||||
|
||||
if(Core.atlas.isFound(spinnerRegion)){
|
||||
Draw.rect(spinnerRegion, x, y, totalProgress * spinnerSpeed);
|
||||
@@ -132,7 +132,7 @@ public class Separator extends Block{
|
||||
|
||||
@Override
|
||||
public boolean canDump(Building to, Item item){
|
||||
return !consumes.itemFilters.get(item.id);
|
||||
return !consumes.consumesItem(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package mindustry.world.draw;
|
||||
|
||||
import arc.*;
|
||||
import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.production.GenericCrafter.*;
|
||||
|
||||
@@ -22,10 +22,9 @@ public class DrawAnimation extends DrawBlock{
|
||||
frames[(int)Mathf.absin(build.totalProgress, frameSpeed, frameCount - 0.001f)] :
|
||||
frames[(int)((build.totalProgress / frameSpeed) % frameCount)],
|
||||
build.x, build.y);
|
||||
|
||||
if(build.liquids != null){
|
||||
Draw.color(Color.clear, build.liquids.current().color, build.liquids.total() / build.block.liquidCapacity);
|
||||
Draw.rect(liquid, build.x, build.y);
|
||||
Draw.color();
|
||||
Drawf.liquid(liquid, build.x, build.y, build.liquids.currentAmount() / build.block.liquidCapacity, build.liquids.current().color);
|
||||
}
|
||||
if(top.found()){
|
||||
Draw.rect(top, build.x, build.y);
|
||||
|
||||
@@ -22,6 +22,7 @@ public class DrawMixer extends DrawBlock{
|
||||
|
||||
@Override
|
||||
public void draw(GenericCrafterBuild build){
|
||||
GenericCrafter crafter = (GenericCrafter)build.block;
|
||||
float rotation = build.block.rotate ? build.rotdeg() : 0;
|
||||
Draw.rect(bottom, build.x, build.y, rotation);
|
||||
|
||||
@@ -33,11 +34,10 @@ public class DrawMixer extends DrawBlock{
|
||||
);
|
||||
}
|
||||
|
||||
if(build.liquids.total() > 0.001f){
|
||||
Draw.color(((GenericCrafter)build.block).outputLiquid.liquid.color);
|
||||
Draw.alpha(build.liquids.get(((GenericCrafter)build.block).outputLiquid.liquid) / build.block.liquidCapacity);
|
||||
Draw.rect(liquid, build.x, build.y, rotation);
|
||||
Draw.color();
|
||||
if(crafter.outputLiquid != null && build.liquids.get(crafter.outputLiquid.liquid) > 0.001f){
|
||||
var liq = crafter.outputLiquid.liquid;
|
||||
|
||||
Drawf.liquid(liquid, build.x, build.y, build.liquids.get(liq) / crafter.liquidCapacity, liq.color);
|
||||
}
|
||||
|
||||
Draw.rect(top, build.x, build.y, rotation);
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.*;
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class LiquidModule extends BlockModule{
|
||||
private static final int windowSize = 3, updateInterval = 60;
|
||||
private static final int windowSize = 3;
|
||||
private static final Interval flowTimer = new Interval(2);
|
||||
private static final float pollScl = 20f;
|
||||
|
||||
@@ -21,30 +21,15 @@ public class LiquidModule extends BlockModule{
|
||||
private static final Bits cacheBits = new Bits();
|
||||
|
||||
private float[] liquids = new float[content.liquids().size];
|
||||
private float total;
|
||||
private Liquid current = content.liquid(0);
|
||||
private float smoothLiquid;
|
||||
private float total, smoothLiquid;
|
||||
|
||||
//TODO broken for multi flow
|
||||
private @Nullable WindowedMean[] flow;
|
||||
|
||||
public void update(boolean showFlow){
|
||||
smoothLiquid = Mathf.lerpDelta(smoothLiquid, currentAmount(), 0.1f);
|
||||
|
||||
|
||||
if(showFlow){
|
||||
/*
|
||||
if(flowTimer.get(1, pollScl)){
|
||||
|
||||
if(flow == null) flow = new WindowedMean(windowSize);
|
||||
if(lastAdded > 0.0001f) hadFlow = true;
|
||||
|
||||
flow.add(lastAdded);
|
||||
lastAdded = 0;
|
||||
if(currentFlowRate < 0 || flowTimer.get(updateInterval)){
|
||||
currentFlowRate = flow.hasEnoughData() ? flow.mean() / pollScl : -1f;
|
||||
}
|
||||
}*/
|
||||
|
||||
if(flowTimer.get(1, pollScl)){
|
||||
|
||||
@@ -101,7 +86,12 @@ public class LiquidModule extends BlockModule{
|
||||
return smoothLiquid;
|
||||
}
|
||||
|
||||
/** @return total amount of liquids. */
|
||||
/**
|
||||
* @deprecated There is no good reason to check the total amount of liquids of a block.
|
||||
* Use of this method is almost certainly a bug; currentAmount() is probably what you want instead.
|
||||
* All liquid storage systems either store one liquid type, or have per-liquid inventories, and as such total liquid is irrelevant.
|
||||
* */
|
||||
@Deprecated
|
||||
public float total(){
|
||||
return total;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user