diff --git a/core/src/io/anuke/mindustry/world/blocks/power/ItemGenerator.java b/core/src/io/anuke/mindustry/world/blocks/power/ItemGenerator.java index 3a16d3df04..b18092c111 100644 --- a/core/src/io/anuke/mindustry/world/blocks/power/ItemGenerator.java +++ b/core/src/io/anuke/mindustry/world/blocks/power/ItemGenerator.java @@ -76,6 +76,11 @@ public abstract class ItemGenerator extends PowerGenerator{ public void update(Tile tile){ ItemGeneratorEntity entity = tile.entity(); + if(!entity.cons.valid()){ + entity.productionEfficiency = 0.0f; + return; + } + if(entity.generateTime <= 0f && entity.items.total() > 0){ Effects.effect(generateEffect, tile.worldx() + Mathf.range(3f), tile.worldy() + Mathf.range(3f)); Item item = entity.items.take(); @@ -92,6 +97,8 @@ public abstract class ItemGenerator extends PowerGenerator{ entity.damage(Mathf.random(8f)); Effects.effect(explodeEffect, tile.worldx() + Mathf.range(size * tilesize / 2f), tile.worldy() + Mathf.range(size * tilesize / 2f)); } + }else{ + entity.productionEfficiency = 0.0f; } super.update(tile); diff --git a/core/src/io/anuke/mindustry/world/blocks/power/ItemLiquidGenerator.java b/core/src/io/anuke/mindustry/world/blocks/power/ItemLiquidGenerator.java index 974ade4db5..c8af36a3ff 100644 --- a/core/src/io/anuke/mindustry/world/blocks/power/ItemLiquidGenerator.java +++ b/core/src/io/anuke/mindustry/world/blocks/power/ItemLiquidGenerator.java @@ -35,8 +35,6 @@ public abstract class ItemLiquidGenerator extends ItemGenerator{ public void update(Tile tile){ ItemGeneratorEntity entity = tile.entity(); - entity.power.graph.update(); - Liquid liquid = null; for(Liquid other : content.liquids()){ if(entity.liquids.get(other) >= 0.001f && getLiquidEfficiency(other) >= minLiquidEfficiency){ @@ -67,30 +65,13 @@ public abstract class ItemLiquidGenerator extends ItemGenerator{ if(used > 0.001f && Mathf.chance(0.05 * entity.delta())){ Effects.effect(generateEffect, tile.drawx() + Mathf.range(3f), tile.drawy() + Mathf.range(3f)); } + + // Update the graph manually instead of letting the base class do it since that would consume items + entity.power.graph.update(); }else{ - - if(entity.generateTime <= 0f && entity.items.total() > 0){ - Effects.effect(generateEffect, tile.worldx() + Mathf.range(3f), tile.worldy() + Mathf.range(3f)); - Item item = entity.items.take(); - entity.productionEfficiency = getItemEfficiency(item); - entity.explosiveness = item.explosiveness; - entity.generateTime = 1f; - } - - if(entity.generateTime > 0f){ - entity.generateTime -= 1f / itemDuration * entity.delta(); - entity.generateTime = Mathf.clamp(entity.generateTime); - - if(Mathf.chance(entity.delta() * 0.06 * Mathf.clamp(entity.explosiveness - 0.25f))){ - entity.damage(Mathf.random(8f)); - Effects.effect(explodeEffect, tile.worldx() + Mathf.range(size * tilesize / 2f), tile.worldy() + Mathf.range(size * tilesize / 2f)); - } - }else{ - entity.productionEfficiency = 0.0f; - } + // No liquids accepted, act like a default ItemGenerator + super.update(tile); } - - super.update(tile); } @Override diff --git a/core/src/io/anuke/mindustry/world/blocks/power/LiquidGenerator.java b/core/src/io/anuke/mindustry/world/blocks/power/LiquidGenerator.java index fd909bae76..67701ec58d 100644 --- a/core/src/io/anuke/mindustry/world/blocks/power/LiquidGenerator.java +++ b/core/src/io/anuke/mindustry/world/blocks/power/LiquidGenerator.java @@ -48,18 +48,21 @@ public abstract class LiquidGenerator extends PowerGenerator{ @Override public void update(Tile tile){ - TileEntity entity = tile.entity(); + ItemGeneratorEntity entity = tile.entity(); + + // Note: Do not use this delta when calculating the amount of power or the power efficiency, but use it for resource consumption if necessary. + // Power amount is delta'd by PowerGraph class already. + float calculationDelta = entity.delta(); - // TODO Code duplication with ItemLiquidGenerator if(entity.liquids.get(entity.liquids.current()) >= 0.001f){ - //float powerPerLiquid = getEfficiency(entity.liquids.current()) * this.powerPerLiquid; - float used = Math.min(entity.liquids.currentAmount(), maxLiquidGenerate * entity.delta()); - // TODO Adapt to new power system - //used = Math.min(used, (powerCapacity - entity.power.amount) / powerPerLiquid); + float baseLiquidEfficiency = getEfficiency(entity.liquids.current()) * this.liquidPowerMultiplier; + float maximumPossible = maxLiquidGenerate * calculationDelta; + float used = Math.min(entity.liquids.currentAmount() * calculationDelta, maximumPossible); entity.liquids.remove(entity.liquids.current(), used); - // TODO Adapt to new power system - //entity.power.amount += used * powerPerLiquid; + + // Note: 1 Item with 100% Flammability = 100% efficiency. This means 100% is not max but rather a reference point for this generator. + entity.productionEfficiency = baseLiquidEfficiency * used / maximumPossible; if(used > 0.001f && Mathf.chance(0.05 * entity.delta())){ Effects.effect(generateEffect, tile.drawx() + Mathf.range(3f), tile.drawy() + Mathf.range(3f)); diff --git a/core/src/io/anuke/mindustry/world/blocks/units/MechPad.java b/core/src/io/anuke/mindustry/world/blocks/units/MechPad.java index a1fa070367..6eafeb2a1d 100644 --- a/core/src/io/anuke/mindustry/world/blocks/units/MechPad.java +++ b/core/src/io/anuke/mindustry/world/blocks/units/MechPad.java @@ -52,13 +52,6 @@ public class MechPad extends Block{ super.init(); } - @Override - public void setStats(){ - super.setStats(); - // TODO Verify for new power system - //stats.remove(BlockStat.powerUse); - } - @Override public boolean shouldConsume(Tile tile){ return false; diff --git a/tests/src/test/java/power/ItemLiquidGeneratorTests.java b/tests/src/test/java/power/ItemLiquidGeneratorTests.java index 9511059fda..aae193543d 100644 --- a/tests/src/test/java/power/ItemLiquidGeneratorTests.java +++ b/tests/src/test/java/power/ItemLiquidGeneratorTests.java @@ -22,6 +22,7 @@ import static org.junit.jupiter.api.DynamicTest.dynamicTest; * Additionally, each PowerGraph::update() call will have its own thread frame, i.e. the method will never be called twice within the same frame. * Both of these constraints are handled by FakeThreadHandler within PowerTestFixture. * Any power amount (produced, consumed, buffered) should be affected by FakeThreadHandler.fakeDelta but satisfaction should not! + * TODO Find a way to reuse these tests for LiquidGenerator and ItemGenerator */ public class ItemLiquidGeneratorTests extends PowerTestFixture{