This commit is contained in:
Anuken
2019-03-31 22:27:11 -04:00
parent 8f853c8f18
commit a83c0b2e9a
7 changed files with 31 additions and 10 deletions

View File

@ -58,7 +58,7 @@ public class Drone extends FlyingUnit implements BuilderTrait{
if(core == null) return; if(core == null) return;
if((entity.progress() < 1f || entity.progress() > 0f) && entity.tile.block() instanceof BuildBlock){ //building is valid if((entity.progress() < 1f || entity.progress() > 0f) && entity.block instanceof BuildBlock){ //building is valid
if(!isBuilding() && dst(target) < placeDistance * 0.9f){ //within distance, begin placing if(!isBuilding() && dst(target) < placeDistance * 0.9f){ //within distance, begin placing
if(isBreaking){ if(isBreaking){
getPlaceQueue().addLast(new BuildRequest(entity.tile.x, entity.tile.y)); getPlaceQueue().addLast(new BuildRequest(entity.tile.x, entity.tile.y));
@ -127,7 +127,7 @@ public class Drone extends FlyingUnit implements BuilderTrait{
} }
//core full //core full
if(targetItem != null && entity.tile.block().acceptStack(targetItem, 1, entity.tile, Drone.this) == 0){ if(targetItem != null && entity.block.acceptStack(targetItem, 1, entity.tile, Drone.this) == 0){
setState(repair); setState(repair);
return; return;
} }

View File

@ -53,7 +53,7 @@ public class ImpactReactor extends PowerGenerator{
bars.add("poweroutput", entity -> new Bar(() -> bars.add("poweroutput", entity -> new Bar(() ->
Core.bundle.format("bar.poweroutput", Core.bundle.format("bar.poweroutput",
Strings.fixed(Math.max(entity.tile.block().getPowerProduction(entity.tile) - consumes.getPower().powerPerTick, 0)*60 * entity.delta(), 1)), Strings.fixed(Math.max(entity.block.getPowerProduction(entity.tile) - consumes.getPower().powerPerTick, 0)*60 * entity.delta(), 1)),
() -> Pal.powerBar, () -> Pal.powerBar,
() -> ((GeneratorEntity)entity).productionEfficiency)); () -> ((GeneratorEntity)entity).productionEfficiency));
} }

View File

@ -40,7 +40,7 @@ public class PowerGenerator extends PowerDistributor{
if(hasPower && outputsPower && !consumes.hasPower()){ if(hasPower && outputsPower && !consumes.hasPower()){
bars.add("power", entity -> new Bar(() -> bars.add("power", entity -> new Bar(() ->
Core.bundle.format("bar.poweroutput", Core.bundle.format("bar.poweroutput",
Strings.fixed(entity.tile.block().getPowerProduction(entity.tile)*60 * entity.timeScale, 1)), Strings.fixed(entity.block.getPowerProduction(entity.tile)*60 * entity.timeScale, 1)),
() -> Pal.powerBar, () -> Pal.powerBar,
() -> ((GeneratorEntity)entity).productionEfficiency)); () -> ((GeneratorEntity)entity).productionEfficiency));
} }

View File

@ -41,6 +41,7 @@ public class GenericCrafter extends Block{
super(name); super(name);
update = true; update = true;
solid = true; solid = true;
hasItems = true;
health = 60; health = 60;
} }

View File

@ -1,5 +1,6 @@
package io.anuke.mindustry.world.modules; package io.anuke.mindustry.world.modules;
import io.anuke.arc.util.Log;
import io.anuke.mindustry.entities.type.TileEntity; import io.anuke.mindustry.entities.type.TileEntity;
import io.anuke.mindustry.world.consumers.Consume; import io.anuke.mindustry.world.consumers.Consume;
@ -19,9 +20,12 @@ public class ConsumeModule extends BlockModule{
boolean prevValid = valid(); boolean prevValid = valid();
valid = true; valid = true;
optionalValid = true; optionalValid = true;
boolean docons = entity.tile.block().shouldConsume(entity.tile); boolean docons = entity.block.shouldConsume(entity.tile);
for(Consume cons : entity.tile.block().consumes.all()){ Log.info("update begin: is valid");
for(Consume cons : entity.block.consumes.all()){
Log.info("check cons {1}: {0}", cons, cons.valid(entity));
if(docons && cons.isUpdate() && prevValid && cons.valid(entity)){ if(docons && cons.isUpdate() && prevValid && cons.valid(entity)){
cons.update(entity); cons.update(entity);
} }
@ -31,7 +35,7 @@ public class ConsumeModule extends BlockModule{
} }
} }
for(Consume cons : entity.tile.block().consumes.optionals()){ for(Consume cons : entity.block.consumes.optionals()){
if(docons && cons.isUpdate() && prevValid && cons.valid(entity)){ if(docons && cons.isUpdate() && prevValid && cons.valid(entity)){
cons.update(entity); cons.update(entity);
} }
@ -41,13 +45,13 @@ public class ConsumeModule extends BlockModule{
} }
public void trigger(){ public void trigger(){
for(Consume cons : entity.tile.block().consumes.all()){ for(Consume cons : entity.block.consumes.all()){
cons.trigger(entity); cons.trigger(entity);
} }
} }
public boolean valid(){ public boolean valid(){
return valid && entity.tile.block().canProduce(entity.tile); return valid && entity.block.canProduce(entity.tile);
} }
public boolean optionalValid(){ public boolean optionalValid(){

View File

@ -1,5 +1,6 @@
package power; package power;
import io.anuke.arc.util.Log;
import io.anuke.arc.util.Time; import io.anuke.arc.util.Time;
import io.anuke.mindustry.content.Items; import io.anuke.mindustry.content.Items;
import io.anuke.mindustry.content.Liquids; import io.anuke.mindustry.content.Liquids;
@ -7,6 +8,8 @@ import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.type.Liquid; import io.anuke.mindustry.type.Liquid;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.power.ItemLiquidGenerator; import io.anuke.mindustry.world.blocks.power.ItemLiquidGenerator;
import io.anuke.mindustry.world.consumers.Consume;
import io.anuke.mindustry.world.consumers.ConsumeItemFilter;
import org.junit.jupiter.api.DynamicTest; import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestFactory; import org.junit.jupiter.api.TestFactory;
@ -36,7 +39,6 @@ public class ItemLiquidGeneratorTests extends PowerTestFixture{
generator = new ItemLiquidGenerator(inputType != InputType.liquids, inputType != InputType.items, "fakegen"){ generator = new ItemLiquidGenerator(inputType != InputType.liquids, inputType != InputType.items, "fakegen"){
{ {
powerProduction = 0.1f; powerProduction = 0.1f;
itemDuration = 60f;
itemDuration = fakeItemDuration; itemDuration = fakeItemDuration;
maxLiquidGenerate = maximumLiquidUsage; maxLiquidGenerate = maximumLiquidUsage;
} }
@ -135,6 +137,13 @@ public class ItemLiquidGeneratorTests extends PowerTestFixture{
entity.items.add(item, amount); entity.items.add(item, amount);
} }
entity.cons.update(); entity.cons.update();
if(!entity.cons.valid()){
Log.info("not valid: ");
for(Consume cons : entity.block.consumes.all()){
if(cons instanceof ConsumeItemFilter)
Log.info("--" + cons.getClass().getSimpleName() + ": " + cons.valid(entity) + " " + ((ConsumeItemFilter)cons).filter.test(item) + " update: " + cons.isUpdate() + " optional: " + cons.isOptional());
}
}
assertTrue(entity.cons.valid()); assertTrue(entity.cons.valid());
// Perform an update on the generator once - This should use up one or zero items - dependent on if the item is accepted and available or not. // Perform an update on the generator once - This should use up one or zero items - dependent on if the item is accepted and available or not.

View File

@ -2,6 +2,7 @@ package power;
import io.anuke.arc.Core; import io.anuke.arc.Core;
import io.anuke.arc.math.Mathf; import io.anuke.arc.math.Mathf;
import io.anuke.arc.util.Log;
import io.anuke.arc.util.Time; import io.anuke.arc.util.Time;
import io.anuke.mindustry.Vars; import io.anuke.mindustry.Vars;
import io.anuke.mindustry.content.Blocks; import io.anuke.mindustry.content.Blocks;
@ -34,6 +35,7 @@ public class PowerTestFixture{
Core.graphics = new FakeGraphics(); Core.graphics = new FakeGraphics();
Vars.content = new ContentLoader(); Vars.content = new ContentLoader();
Vars.content.load(); Vars.content.load();
Log.setUseColors(false);
Time.setDeltaProvider(() -> 0.5f); Time.setDeltaProvider(() -> 0.5f);
} }
@ -71,6 +73,11 @@ public class PowerTestFixture{
try{ try{
Tile tile = new Tile(x, y); Tile tile = new Tile(x, y);
//workaround since init() is not called for custom blocks
if(block.consumes.all() == null){
block.consumes.init();
}
// Using the Tile(int, int, byte, byte) constructor would require us to register any fake block or tile we create // Using the Tile(int, int, byte, byte) constructor would require us to register any fake block or tile we create
// Since this part shall not be part of the test and would require more work anyway, we manually set the block and floor // Since this part shall not be part of the test and would require more work anyway, we manually set the block and floor
// through reflections and then simulate part of what the changed() method does. // through reflections and then simulate part of what the changed() method does.