mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-03 04:44:24 +07:00
Synchronized Item/Liquid generator code
This commit is contained in:
parent
1d57568322
commit
bcb9cfd2fe
@ -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);
|
||||
|
@ -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,31 +65,14 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Tile tile){
|
||||
|
@ -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));
|
||||
|
@ -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;
|
||||
|
@ -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{
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user