mirror of
https://github.com/Anuken/Mindustry.git
synced 2024-11-10 15:05:23 +03:00
Sweeping rework
This commit is contained in:
parent
6392330e70
commit
de0235ad94
@ -372,6 +372,7 @@ blocks.basepowergeneration = Base Power Generation
|
||||
blocks.powertransferspeed = Power Transfer
|
||||
blocks.productiontime = Production Time
|
||||
blocks.repairtime = Block Full Repair Time
|
||||
blocks.speedincrease = Speed Increase
|
||||
blocks.range = Range
|
||||
blocks.inputliquid = Input Liquid
|
||||
blocks.inputliquidaux = Aux Liquid
|
||||
@ -380,6 +381,7 @@ blocks.inputitems = Input Items
|
||||
blocks.outputitem = Output Item
|
||||
blocks.drilltier = Drillables
|
||||
blocks.drillspeed = Base Drill Speed
|
||||
blocks.boosteffect = Boost Effect
|
||||
blocks.maxunits = Max Active Units
|
||||
blocks.liquidoutput = Liquid Output
|
||||
blocks.liquidoutputspeed = Liquid Output Speed
|
||||
@ -426,6 +428,10 @@ unit.liquidunits = liquid units
|
||||
unit.powerunits = power units
|
||||
unit.degrees = degrees
|
||||
unit.seconds = seconds
|
||||
unit.persecond = /sec
|
||||
unit.timesspeed = x speed
|
||||
unit.timesRadius = x radius
|
||||
unit.percent = %
|
||||
unit.items = items
|
||||
category.general = General
|
||||
category.power = Power
|
||||
|
@ -30,7 +30,6 @@ import io.anuke.mindustry.world.blocks.storage.Vault;
|
||||
import io.anuke.mindustry.world.blocks.units.MechPad;
|
||||
import io.anuke.mindustry.world.blocks.units.RepairPoint;
|
||||
import io.anuke.mindustry.world.blocks.units.UnitFactory;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeItemFilter;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeLiquidFilter;
|
||||
import io.anuke.mindustry.world.meta.Attribute;
|
||||
import io.anuke.mindustry.world.modules.LiquidModule;
|
||||
@ -521,7 +520,6 @@ public class Blocks implements ContentList{
|
||||
hasItems = true;
|
||||
rotate = false;
|
||||
solid = true;
|
||||
singleLiquid = false;
|
||||
outputsLiquid = true;
|
||||
|
||||
consumes.power(1f);
|
||||
@ -594,7 +592,7 @@ public class Blocks implements ContentList{
|
||||
Items.titanium, 2
|
||||
);
|
||||
hasPower = true;
|
||||
filterTime = 35f;
|
||||
craftTime = 35f;
|
||||
spinnerLength = 1.5f;
|
||||
spinnerRadius = 3.5f;
|
||||
spinnerThickness = 1.5f;
|
||||
@ -829,13 +827,13 @@ public class Blocks implements ContentList{
|
||||
requirements(Category.effect, ItemStack.with(Items.lead, 200, Items.titanium, 150, Items.silicon, 150, Items.plastanium, 60));
|
||||
consumes.power(3.50f);
|
||||
size = 2;
|
||||
consumes.item(Items.phasefabric).optional(true).boost(true);
|
||||
consumes.item(Items.phasefabric).optional(true);
|
||||
}};
|
||||
|
||||
forceProjector = new ForceProjector("force-projector"){{
|
||||
requirements(Category.effect, ItemStack.with(Items.lead, 200, Items.titanium, 150, Items.silicon, 250));
|
||||
size = 3;
|
||||
consumes.item(Items.phasefabric).optional(true).boost(true);
|
||||
consumes.item(Items.phasefabric).optional(true);
|
||||
}};
|
||||
|
||||
shockMine = new ShockMine("shock-mine"){{
|
||||
@ -1024,7 +1022,7 @@ public class Blocks implements ContentList{
|
||||
size = 2;
|
||||
}};
|
||||
|
||||
turbineGenerator = new TurbineGenerator("turbine-generator"){{
|
||||
turbineGenerator = new BurnerGenerator("turbine-generator"){{
|
||||
requirements(Category.power, ItemStack.with(Items.copper, 70, Items.graphite, 50, Items.lead, 80, Items.silicon, 60));
|
||||
powerProduction = 6f;
|
||||
itemDuration = 30f;
|
||||
@ -1033,15 +1031,15 @@ public class Blocks implements ContentList{
|
||||
size = 2;
|
||||
}};
|
||||
|
||||
differentialGenerator = new DifferentialGenerator("differential-generator"){{
|
||||
differentialGenerator = new ItemLiquidGenerator(true, true, "differential-generator"){{
|
||||
requirements(Category.power, ItemStack.with(Items.copper, 140, Items.titanium, 100, Items.lead, 200, Items.silicon, 130, Items.metaglass, 100));
|
||||
powerProduction = 13f;
|
||||
itemDuration = 50f;
|
||||
consumes.remove(ConsumeItemFilter.class);
|
||||
consumes.remove(ConsumeLiquidFilter.class);
|
||||
hasLiquids = true;
|
||||
size = 3;
|
||||
|
||||
consumes.item(Items.pyratite);
|
||||
consumes.liquid(Liquids.cryofluid, 0.2f);
|
||||
size = 3;
|
||||
}};
|
||||
|
||||
rtgGenerator = new DecayGenerator("rtg-generator"){{
|
||||
@ -1076,7 +1074,7 @@ public class Blocks implements ContentList{
|
||||
size = 4;
|
||||
health = 900;
|
||||
powerProduction = 80f;
|
||||
useTime = 40f;
|
||||
itemDuration = 40f;
|
||||
consumes.power(23f);
|
||||
consumes.item(Items.blastCompound);
|
||||
consumes.liquid(Liquids.cryofluid, 0.8f);
|
||||
@ -1091,6 +1089,7 @@ public class Blocks implements ContentList{
|
||||
drillTime = 600;
|
||||
size = 2;
|
||||
drawMineItem = true;
|
||||
consumes.liquid(Liquids.water, 0.05f).optional(true);
|
||||
}};
|
||||
|
||||
pneumaticDrill = new Drill("pneumatic-drill"){{
|
||||
@ -1470,7 +1469,6 @@ public class Blocks implements ContentList{
|
||||
);
|
||||
reload = 6f;
|
||||
coolantMultiplier = 0.5f;
|
||||
maxCoolantUsed = 1.5f;
|
||||
restitution = 0.1f;
|
||||
ammoUseEffect = Fx.shellEjectBig;
|
||||
range = 200f;
|
||||
@ -1484,6 +1482,7 @@ public class Blocks implements ContentList{
|
||||
shootCone = 24f;
|
||||
|
||||
health = 155 * size * size;
|
||||
consumes.add(new ConsumeLiquidFilter(liquid -> liquid.temperature <= 0.5f && liquid.flammability < 0.1f, 2f)).update(false).optional(true);
|
||||
}};
|
||||
|
||||
meltdown = new LaserTurret("meltdown"){{
|
||||
|
@ -65,7 +65,7 @@ public class Items implements ContentList{
|
||||
|
||||
plastanium = new Item("plastanium", Color.valueOf("cbd97f")){{
|
||||
type = ItemType.material;
|
||||
flammability = 0.2f;
|
||||
flammability = 0.1f;
|
||||
explosiveness = 0.2f;
|
||||
cost = 1.6f;
|
||||
}};
|
||||
|
@ -43,6 +43,7 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
|
||||
public static int sleepingEntities = 0;
|
||||
|
||||
public Tile tile;
|
||||
public Block block;
|
||||
public Interval timer;
|
||||
public float health;
|
||||
public float timeScale = 1f, timeScaleDuration;
|
||||
@ -76,10 +77,10 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
|
||||
this.tile = tile;
|
||||
x = tile.drawx();
|
||||
y = tile.drawy();
|
||||
block = tile.block();
|
||||
|
||||
health = tile.block().health;
|
||||
|
||||
timer = new Interval(tile.block().timers);
|
||||
health = block.health;
|
||||
timer = new Interval(block.timers);
|
||||
|
||||
if(shouldAdd){
|
||||
add();
|
||||
@ -134,7 +135,7 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
|
||||
}
|
||||
|
||||
public void collision(Bullet other){
|
||||
tile.block().handleBulletHit(this, other);
|
||||
block.handleBulletHit(this, other);
|
||||
}
|
||||
|
||||
public void kill(){
|
||||
@ -146,7 +147,7 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
|
||||
|
||||
float preHealth = health;
|
||||
|
||||
Call.onTileDamage(tile, health - tile.block().handleDamage(tile, damage));
|
||||
Call.onTileDamage(tile, health - block.handleDamage(tile, damage));
|
||||
|
||||
if(health <= 0){
|
||||
Call.onTileDestroyed(tile);
|
||||
@ -164,9 +165,9 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
|
||||
}
|
||||
|
||||
public void removeFromProximity(){
|
||||
tile.block().onProximityRemoved(tile);
|
||||
block.onProximityRemoved(tile);
|
||||
|
||||
Point2[] nearby = Edges.getEdges(tile.block().size);
|
||||
Point2[] nearby = Edges.getEdges(block.size);
|
||||
for(Point2 point : nearby){
|
||||
Tile other = world.tile(tile.x + point.x, tile.y + point.y);
|
||||
//remove this tile from all nearby tile's proximities
|
||||
@ -184,7 +185,7 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
|
||||
tmpTiles.clear();
|
||||
proximity.clear();
|
||||
|
||||
Point2[] nearby = Edges.getEdges(tile.block().size);
|
||||
Point2[] nearby = Edges.getEdges(block.size);
|
||||
for(Point2 point : nearby){
|
||||
Tile other = world.tile(tile.x + point.x, tile.y + point.y);
|
||||
|
||||
@ -207,8 +208,8 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
|
||||
proximity.add(tile);
|
||||
}
|
||||
|
||||
tile.block().onProximityAdded(tile);
|
||||
tile.block().onProximityUpdate(tile);
|
||||
block.onProximityAdded(tile);
|
||||
block.onProximityUpdate(tile);
|
||||
}
|
||||
|
||||
public Array<Tile> proximity(){
|
||||
@ -227,7 +228,7 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
|
||||
|
||||
@Override
|
||||
public float maxHealth(){
|
||||
return tile.block().health;
|
||||
return block.health;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -239,7 +240,6 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
|
||||
public void onDeath(){
|
||||
if(!dead){
|
||||
dead = true;
|
||||
Block block = tile.block();
|
||||
|
||||
Events.fire(new BlockDestroyEvent(tile));
|
||||
block.onDestroyed(tile);
|
||||
@ -262,22 +262,22 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
|
||||
@Override
|
||||
public void update(){
|
||||
//TODO better smoke effect, this one is awful
|
||||
if(health != 0 && health < tile.block().health && !(tile.block() instanceof Wall) &&
|
||||
Mathf.chance(0.009f * Time.delta() * (1f - health / tile.block().health))){
|
||||
if(health != 0 && health < block.health && !(block instanceof Wall) &&
|
||||
Mathf.chance(0.009f * Time.delta() * (1f - health / block.health))){
|
||||
Effects.effect(Fx.smoke, x + Mathf.range(4), y + Mathf.range(4));
|
||||
}
|
||||
|
||||
timeScaleDuration -= Time.delta();
|
||||
if(timeScaleDuration <= 0f || !tile.block().canOverdrive){
|
||||
if(timeScaleDuration <= 0f || !block.canOverdrive){
|
||||
timeScale = 1f;
|
||||
}
|
||||
|
||||
if(health <= 0){
|
||||
onDeath();
|
||||
}
|
||||
Block previous = tile.block();
|
||||
tile.block().update(tile);
|
||||
if(tile.block() == previous && cons != null){
|
||||
Block previous = block;
|
||||
block.update(tile);
|
||||
if(block == previous && cons != null){
|
||||
cons.update();
|
||||
}
|
||||
}
|
||||
|
@ -1,29 +1,31 @@
|
||||
package io.anuke.mindustry.ui;
|
||||
|
||||
import io.anuke.arc.graphics.Color;
|
||||
import io.anuke.arc.scene.ui.Image;
|
||||
import io.anuke.arc.scene.ui.layout.Stack;
|
||||
import io.anuke.arc.scene.ui.layout.Table;
|
||||
import io.anuke.arc.util.Strings;
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
|
||||
/**An ItemDisplay, but for liquids.*/
|
||||
public class LiquidDisplay extends Table{
|
||||
|
||||
public LiquidDisplay(Liquid liquid){
|
||||
add(new Image(liquid.getContentIcon())).size(8*4);
|
||||
add(liquid.localizedName()).padLeft(3);
|
||||
}
|
||||
|
||||
public LiquidDisplay(Liquid liquid, float amount){
|
||||
public LiquidDisplay(Liquid liquid, float amount, boolean perSecond){
|
||||
add(new Stack(){{
|
||||
add(new Image(liquid.getContentIcon()));
|
||||
|
||||
if(amount != 0){
|
||||
Table t = new Table().left().bottom();
|
||||
t.add(Strings.autoFixed(amount));
|
||||
t.add(Strings.autoFixed(amount, 1));
|
||||
add(t);
|
||||
}
|
||||
}}).size(8*4);
|
||||
add(liquid.localizedName()).padLeft(3);
|
||||
}}).size(8*4).padRight(3);
|
||||
|
||||
if(perSecond){
|
||||
add(StatUnit.perSecond.localized()).padLeft(2).padRight(5).color(Color.LIGHT_GRAY);
|
||||
}
|
||||
|
||||
add(liquid.localizedName());
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ import io.anuke.mindustry.ui.Bar;
|
||||
import io.anuke.mindustry.ui.ContentDisplay;
|
||||
import io.anuke.mindustry.world.consumers.Consume;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeLiquid;
|
||||
import io.anuke.mindustry.world.consumers.ConsumePower;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeType;
|
||||
import io.anuke.mindustry.world.meta.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
@ -321,7 +321,7 @@ public class Block extends BlockStorage{
|
||||
setStats();
|
||||
setBars();
|
||||
|
||||
consumes.checkRequired(this);
|
||||
consumes.init();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -407,8 +407,8 @@ public class Block extends BlockStorage{
|
||||
|
||||
if(hasLiquids){
|
||||
Function<TileEntity, Liquid> current;
|
||||
if(consumes.has(ConsumeLiquid.class)){
|
||||
Liquid liquid = consumes.liquid();
|
||||
if(consumes.has(ConsumeType.liquid) && consumes.get(ConsumeType.liquid) instanceof ConsumeLiquid){
|
||||
Liquid liquid = consumes.<ConsumeLiquid>get(ConsumeType.liquid).liquid;
|
||||
current = entity -> liquid;
|
||||
}else{
|
||||
current = entity -> entity.liquids.current();
|
||||
@ -416,9 +416,9 @@ public class Block extends BlockStorage{
|
||||
bars.add("liquid", entity -> new Bar(() -> entity.liquids.get(current.get(entity)) <= 0.001f ? Core.bundle.get("blocks.liquid") : current.get(entity).localizedName(), () -> current.get(entity).color, () -> entity.liquids.get(current.get(entity)) / liquidCapacity));
|
||||
}
|
||||
|
||||
if(hasPower && consumes.has(ConsumePower.class)){
|
||||
boolean buffered = consumes.get(ConsumePower.class).isBuffered;
|
||||
float capacity = consumes.get(ConsumePower.class).powerCapacity;
|
||||
if(hasPower && consumes.hasPower()){
|
||||
boolean buffered = consumes.getPower().isBuffered;
|
||||
float capacity = consumes.getPower().powerCapacity;
|
||||
|
||||
bars.add("power", entity -> new Bar(() -> buffered ? Core.bundle.format("blocks.powerbalance", Float.isNaN(entity.power.satisfaction * capacity) ? "<ERROR>" : (int)(entity.power.satisfaction * capacity)) :
|
||||
Core.bundle.get("blocks.power"), () -> Pal.powerBar, () -> entity.power.satisfaction));
|
||||
@ -477,8 +477,8 @@ public class Block extends BlockStorage{
|
||||
explosiveness += tile.entity.liquids.sum((liquid, amount) -> liquid.flammability * amount / 2f);
|
||||
}
|
||||
|
||||
if(consumes.has(ConsumePower.class) && consumes.get(ConsumePower.class).isBuffered){
|
||||
power += tile.entity.power.satisfaction * consumes.get(ConsumePower.class).powerCapacity;
|
||||
if(consumes.hasPower() && consumes.getPower().isBuffered){
|
||||
power += tile.entity.power.satisfaction * consumes.getPower().powerCapacity;
|
||||
}
|
||||
|
||||
if(hasLiquids){
|
||||
|
@ -33,7 +33,6 @@ public abstract class BlockStorage extends UnlockableContent{
|
||||
public final BlockStats stats = new BlockStats();
|
||||
public final BlockBars bars = new BlockBars();
|
||||
public final Consumers consumes = new Consumers();
|
||||
//public final Producers produces = new Producers();
|
||||
|
||||
public BlockStorage(String name){
|
||||
super(name);
|
||||
@ -112,7 +111,7 @@ public abstract class BlockStorage extends UnlockableContent{
|
||||
Tile other = proximity.get((i + dump) % proximity.size);
|
||||
Tile in = Edges.getFacingEdge(tile, other);
|
||||
|
||||
if(other.getTeamID() == tile.getTeamID() && other.block().hasLiquids && canDumpLiquid(tile, other, liquid)){
|
||||
if(other.getTeam() == tile.getTeam() && other.block().hasLiquids && canDumpLiquid(tile, other, liquid)){
|
||||
float ofract = other.entity.liquids.get(liquid) / other.block().liquidCapacity;
|
||||
float fract = tile.entity.liquids.get(liquid) / liquidCapacity;
|
||||
|
||||
@ -140,7 +139,7 @@ public abstract class BlockStorage extends UnlockableContent{
|
||||
|
||||
next = next.target();
|
||||
|
||||
if(next.getTeamID() == tile.getTeamID() && next.block().hasLiquids && tile.entity.liquids.get(liquid) > 0f){
|
||||
if(next.getTeam() == tile.getTeam() && next.block().hasLiquids && tile.entity.liquids.get(liquid) > 0f){
|
||||
|
||||
if(next.block().acceptLiquid(next, tile, liquid, 0f)){
|
||||
float ofract = next.entity.liquids.get(liquid) / next.block().liquidCapacity;
|
||||
@ -190,7 +189,7 @@ public abstract class BlockStorage extends UnlockableContent{
|
||||
incrementDump(tile, proximity.size);
|
||||
Tile other = proximity.get((i + dump) % proximity.size);
|
||||
Tile in = Edges.getFacingEdge(tile, other);
|
||||
if(other.getTeamID() == tile.getTeamID() && other.block().acceptItem(item, other, in) && canDump(tile, other, item)){
|
||||
if(other.getTeam() == tile.getTeam() && other.block().acceptItem(item, other, in) && canDump(tile, other, item)){
|
||||
other.block().handleItem(item, other, in);
|
||||
return;
|
||||
}
|
||||
@ -199,9 +198,7 @@ public abstract class BlockStorage extends UnlockableContent{
|
||||
handleItem(item, tile, tile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Try dumping any item near the tile.
|
||||
*/
|
||||
/**Try dumping any item near the tile.*/
|
||||
public boolean tryDump(Tile tile){
|
||||
return tryDump(tile, null);
|
||||
}
|
||||
@ -230,7 +227,7 @@ public abstract class BlockStorage extends UnlockableContent{
|
||||
for(int ii = 0; ii < Vars.content.items().size; ii++){
|
||||
Item item = Vars.content.item(ii);
|
||||
|
||||
if(other.getTeamID() == tile.getTeamID() && entity.items.has(item) && other.block().acceptItem(item, other, in) && canDump(tile, other, item)){
|
||||
if(other.getTeam() == tile.getTeam() && entity.items.has(item) && other.block().acceptItem(item, other, in) && canDump(tile, other, item)){
|
||||
other.block().handleItem(item, other, in);
|
||||
tile.entity.items.remove(item, 1);
|
||||
incrementDump(tile, proximity.size);
|
||||
@ -239,7 +236,7 @@ public abstract class BlockStorage extends UnlockableContent{
|
||||
}
|
||||
}else{
|
||||
|
||||
if(other.getTeamID() == tile.getTeamID() && other.block().acceptItem(todump, other, in) && canDump(tile, other, todump)){
|
||||
if(other.getTeam() == tile.getTeam() && other.block().acceptItem(todump, other, in) && canDump(tile, other, todump)){
|
||||
other.block().handleItem(todump, other, in);
|
||||
tile.entity.items.remove(todump, 1);
|
||||
incrementDump(tile, proximity.size);
|
||||
|
@ -21,6 +21,7 @@ import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeLiquidFilter;
|
||||
import io.anuke.mindustry.world.consumers.ConsumePower;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeType;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
|
||||
@ -54,7 +55,7 @@ public class ForceProjector extends Block {
|
||||
canOverdrive = false;
|
||||
hasLiquids = true;
|
||||
hasItems = true;
|
||||
consumes.add(new ConsumeLiquidFilter(liquid -> liquid.temperature <= 0.5f && liquid.flammability < 0.1f, 0.1f)).optional(true).boost(true).update(false);
|
||||
consumes.add(new ConsumeLiquidFilter(liquid -> liquid.temperature <= 0.5f && liquid.flammability < 0.1f, 0.1f)).optional(true).update(false);
|
||||
consumePower = new ConsumeForceProjectorPower(60f, 60f);
|
||||
consumes.add(consumePower);
|
||||
}
|
||||
@ -71,6 +72,8 @@ public class ForceProjector extends Block {
|
||||
|
||||
stats.add(BlockStat.powerUse, basePowerDraw * 60f, StatUnit.powerSecond);
|
||||
stats.add(BlockStat.powerDamage, powerDamage, StatUnit.powerUnits);
|
||||
|
||||
stats.add(BlockStat.boostEffect, phaseRadiusBoost/tilesize, StatUnit.blocks);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -83,10 +86,10 @@ public class ForceProjector extends Block {
|
||||
entity.shield.add();
|
||||
}
|
||||
|
||||
entity.phaseHeat = Mathf.lerpDelta(entity.phaseHeat, (float)entity.items.get(consumes.item()) / itemCapacity, 0.1f);
|
||||
entity.phaseHeat = Mathf.lerpDelta(entity.phaseHeat, Mathf.num(entity.cons.optionalValid()), 0.1f);
|
||||
|
||||
if(entity.cons.valid() && !entity.broken && entity.timer.get(timerUse, phaseUseTime) && entity.items.total() > 0){
|
||||
entity.items.remove(consumes.item(), 1);
|
||||
if(entity.cons.optionalValid() && !entity.broken && entity.timer.get(timerUse, phaseUseTime)){
|
||||
entity.cons.trigger();
|
||||
}
|
||||
|
||||
entity.radscl = Mathf.lerpDelta(entity.radscl, entity.broken ? 0f : 1f, 0.05f);
|
||||
@ -95,7 +98,7 @@ public class ForceProjector extends Block {
|
||||
Effects.effect(Fx.reactorsmoke, tile.drawx() + Mathf.range(tilesize/2f), tile.drawy() + Mathf.range(tilesize/2f));
|
||||
}
|
||||
|
||||
// Use Cases:
|
||||
//use cases:
|
||||
// - There is enough power in the buffer, and there are no shots fired => Draw base power and keep shield up
|
||||
// - There is enough power in the buffer, but not enough power to cope for shots being fired => Draw all power and break shield
|
||||
// - There is enough power in the buffer and enough power to cope for shots being fired => Draw base power + additional power based on shots absorbed
|
||||
@ -120,8 +123,9 @@ public class ForceProjector extends Block {
|
||||
|
||||
if(entity.buildup > 0){
|
||||
float scale = !entity.broken ? cooldownNormal : cooldownBrokenBase;
|
||||
if(consumes.get(ConsumeLiquidFilter.class).valid(this, entity)){
|
||||
consumes.get(ConsumeLiquidFilter.class).update(this, entity);
|
||||
ConsumeLiquidFilter cons = consumes.get(ConsumeType.liquid);
|
||||
if(cons.valid(entity)){
|
||||
cons.update(entity);
|
||||
scale *= (cooldownLiquid * (1f+(entity.liquids.current().heatCapacity-0.4f)*0.9f));
|
||||
}
|
||||
|
||||
@ -268,8 +272,8 @@ public class ForceProjector extends Block {
|
||||
super(powerCapacity / ticksToFill, powerCapacity, true);
|
||||
}
|
||||
@Override
|
||||
public boolean valid(Block block, TileEntity entity){
|
||||
return entity.power.satisfaction >= basePowerDraw / powerCapacity && super.valid(block, entity);
|
||||
public boolean valid(TileEntity entity){
|
||||
return entity.power.satisfaction >= basePowerDraw / powerCapacity && super.valid(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -60,6 +60,9 @@ public class MendProjector extends Block{
|
||||
|
||||
stats.add(BlockStat.repairTime, (int)(100f / healPercent * reload / 60f), StatUnit.seconds);
|
||||
stats.add(BlockStat.range, range / tilesize, StatUnit.blocks);
|
||||
|
||||
stats.add(BlockStat.boostEffect, phaseRangeBoost/tilesize, StatUnit.blocks);
|
||||
stats.add(BlockStat.boostEffect, (phaseBoost + healPercent) / healPercent, StatUnit.timesSpeed);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -68,10 +71,10 @@ public class MendProjector extends Block{
|
||||
entity.heat = Mathf.lerpDelta(entity.heat, entity.cons.valid() || tile.isEnemyCheat() ? 1f : 0f, 0.08f);
|
||||
entity.charge += entity.heat * entity.delta();
|
||||
|
||||
entity.phaseHeat = Mathf.lerpDelta(entity.phaseHeat, (float)entity.items.get(consumes.item()) / itemCapacity, 0.1f);
|
||||
entity.phaseHeat = Mathf.lerpDelta(entity.phaseHeat, Mathf.num(entity.cons.optionalValid()), 0.1f);
|
||||
|
||||
if(entity.cons.valid() && entity.timer.get(timerUse, useTime) && entity.items.total() > 0){
|
||||
entity.items.remove(consumes.item(), 1);
|
||||
if(entity.cons.optionalValid() && entity.timer.get(timerUse, useTime)){
|
||||
entity.cons.trigger();
|
||||
}
|
||||
|
||||
if(entity.charge >= reload){
|
||||
|
@ -12,6 +12,8 @@ import io.anuke.arc.util.Time;
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
@ -50,16 +52,27 @@ public class OverdriveProjector extends Block{
|
||||
topRegion = Core.atlas.find(name + "-top");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
|
||||
stats.add(BlockStat.speedIncrease, (int)(100f * speedBoost), StatUnit.percent);
|
||||
stats.add(BlockStat.range, range / tilesize, StatUnit.blocks);
|
||||
|
||||
stats.add(BlockStat.boostEffect, phaseRangeBoost/tilesize, StatUnit.blocks);
|
||||
stats.add(BlockStat.boostEffect, (int)((speedBoost + speedBoostPhase) * 100f), StatUnit.percent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
OverdriveEntity entity = tile.entity();
|
||||
entity.heat = Mathf.lerpDelta(entity.heat, entity.cons.valid() ? 1f : 0f, 0.08f);
|
||||
entity.charge += entity.heat * Time.delta();
|
||||
|
||||
entity.phaseHeat = Mathf.lerpDelta(entity.phaseHeat, (float)entity.items.get(consumes.item()) / itemCapacity, 0.1f);
|
||||
entity.phaseHeat = Mathf.lerpDelta(entity.phaseHeat, Mathf.num(entity.cons.optionalValid()), 0.1f);
|
||||
|
||||
if(entity.timer.get(timerUse, useTime) && entity.items.total() > 0){
|
||||
entity.items.remove(consumes.item(), 1);
|
||||
if(entity.timer.get(timerUse, useTime)){
|
||||
entity.cons.trigger();
|
||||
}
|
||||
|
||||
if(entity.charge >= reload){
|
||||
|
@ -1,21 +1,23 @@
|
||||
package io.anuke.mindustry.world.blocks.defense.turrets;
|
||||
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.arc.util.Time;
|
||||
import io.anuke.mindustry.content.Fx;
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeLiquidFilter;
|
||||
import io.anuke.mindustry.entities.Effects;
|
||||
import io.anuke.mindustry.entities.Effects.Effect;
|
||||
import io.anuke.arc.util.Time;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeLiquidBase;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeLiquidFilter;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeType;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
|
||||
import static io.anuke.mindustry.Vars.tilesize;
|
||||
|
||||
public class CooledTurret extends Turret{
|
||||
/**How much reload is lowered by for each unit of liquid of heat capacity 1.*/
|
||||
protected float coolantMultiplier = 1f;
|
||||
/**Max coolant used per tick.*/
|
||||
protected float maxCoolantUsed = 1f;
|
||||
/**How much reload is lowered by for each unit of liquid of heat capacity.*/
|
||||
protected float coolantMultiplier = 2f;
|
||||
protected Effect coolEffect = Fx.fuelburn;
|
||||
|
||||
public CooledTurret(String name){
|
||||
@ -23,17 +25,28 @@ public class CooledTurret extends Turret{
|
||||
hasLiquids = true;
|
||||
liquidCapacity = 20f;
|
||||
|
||||
consumes.add(new ConsumeLiquidFilter(liquid -> liquid.temperature <= 0.5f && liquid.flammability < 0.1f, 0.01f)).update(false).optional(true);
|
||||
consumes.add(new ConsumeLiquidFilter(liquid -> liquid.temperature <= 0.5f && liquid.flammability < 0.1f, 0.5f)).update(false).optional(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
|
||||
float maxUsed = consumes.<ConsumeLiquidBase>get(ConsumeType.liquid).amount;
|
||||
|
||||
stats.add(BlockStat.boostEffect, 1f + maxUsed * coolantMultiplier, StatUnit.timesSpeed);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateShooting(Tile tile){
|
||||
super.updateShooting(tile);
|
||||
|
||||
float maxUsed = consumes.<ConsumeLiquidBase>get(ConsumeType.liquid).amount;
|
||||
|
||||
TurretEntity entity = tile.entity();
|
||||
Liquid liquid = entity.liquids.current();
|
||||
|
||||
float used = Math.min(Math.min(entity.liquids.get(liquid), maxCoolantUsed * Time.delta()), Math.max(0, ((reload - entity.reload) / coolantMultiplier) / liquid.heatCapacity));
|
||||
float used = Math.min(Math.min(entity.liquids.get(liquid), maxUsed * Time.delta()), Math.max(0, ((reload - entity.reload) / coolantMultiplier) / liquid.heatCapacity));
|
||||
entity.reload += (used * liquid.heatCapacity) / liquid.heatCapacity;
|
||||
entity.liquids.remove(liquid, used);
|
||||
|
||||
@ -41,9 +54,4 @@ public class CooledTurret extends Turret{
|
||||
Effects.effect(coolEffect, tile.drawx() + Mathf.range(size * tilesize / 2f), tile.drawy() + Mathf.range(size * tilesize / 2f));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
||||
return super.acceptLiquid(tile, source, liquid, amount) && liquid.temperature <= 0.5f;
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,17 @@
|
||||
package io.anuke.mindustry.world.blocks.defense.turrets;
|
||||
|
||||
import io.anuke.mindustry.entities.Effects;
|
||||
import io.anuke.arc.math.Angles;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.arc.util.Time;
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.entities.Effects;
|
||||
import io.anuke.mindustry.entities.bullet.Bullet;
|
||||
import io.anuke.mindustry.entities.bullet.BulletType;
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeLiquidBase;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeLiquidFilter;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeType;
|
||||
|
||||
import static io.anuke.mindustry.Vars.tilesize;
|
||||
|
||||
@ -60,8 +62,9 @@ public class LaserTurret extends PowerTurret{
|
||||
entity.reload = 0f;
|
||||
}else{
|
||||
Liquid liquid = entity.liquids.current();
|
||||
float maxUsed = consumes.<ConsumeLiquidBase>get(ConsumeType.liquid).amount;
|
||||
|
||||
float used = Math.min(Math.min(entity.liquids.get(liquid), maxCoolantUsed * Time.delta()), Math.max(0, ((reload - entity.reload) / coolantMultiplier) / liquid.heatCapacity));
|
||||
float used = Math.min(Math.min(entity.liquids.get(liquid), maxUsed * Time.delta()), Math.max(0, ((reload - entity.reload) / coolantMultiplier) / liquid.heatCapacity));
|
||||
entity.reload += (used * liquid.heatCapacity) / liquid.heatCapacity;
|
||||
entity.liquids.remove(liquid, used);
|
||||
|
||||
|
@ -2,7 +2,6 @@ package io.anuke.mindustry.world.blocks.defense.turrets;
|
||||
|
||||
import io.anuke.mindustry.entities.bullet.BulletType;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.consumers.ConsumePower;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
|
||||
@ -20,7 +19,7 @@ public abstract class PowerTurret extends CooledTurret{
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
|
||||
stats.add(BlockStat.powerShot, powerUsed * consumes.get(ConsumePower.class).powerCapacity, StatUnit.powerUnits);
|
||||
stats.add(BlockStat.powerShot, powerUsed * consumes.getPower().powerCapacity, StatUnit.powerUnits);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -125,7 +125,7 @@ public class MassDriver extends Block{
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
|
||||
stats.add(BlockStat.powerShot, consumes.get(ConsumePower.class).powerCapacity * powerPercentageUsed, StatUnit.powerUnits);
|
||||
stats.add(BlockStat.powerShot, consumes.getPower().powerCapacity * powerPercentageUsed, StatUnit.powerUnits);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,27 +0,0 @@
|
||||
package io.anuke.mindustry.world.blocks.power;
|
||||
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeLiquid;
|
||||
|
||||
public class DifferentialGenerator extends TurbineGenerator{
|
||||
|
||||
public DifferentialGenerator(String name){
|
||||
super(name);
|
||||
|
||||
hasLiquids = true;
|
||||
consumes.require(ConsumeItem.class);
|
||||
consumes.require(ConsumeLiquid.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
return hasItems && consumes.item() == item && tile.entity.items.total() < itemCapacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
||||
return hasLiquids && consumes.liquid() == liquid && tile.entity.liquids.get(liquid) < liquidCapacity;
|
||||
}
|
||||
}
|
@ -16,7 +16,8 @@ import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.graphics.Pal;
|
||||
import io.anuke.mindustry.ui.Bar;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.consumers.ConsumePower;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
@ -29,7 +30,7 @@ public class ImpactReactor extends PowerGenerator{
|
||||
|
||||
protected int plasmas = 4;
|
||||
protected float warmupSpeed = 0.001f;
|
||||
protected float useTime = 60f;
|
||||
protected float itemDuration = 60f;
|
||||
protected int explosionRadius = 30;
|
||||
protected int explosionDamage = 180;
|
||||
|
||||
@ -52,11 +53,20 @@ public class ImpactReactor extends PowerGenerator{
|
||||
|
||||
bars.add("poweroutput", entity -> new Bar(() ->
|
||||
Core.bundle.format("blocks.poweroutput",
|
||||
Strings.fixed(Math.max(entity.tile.block().getPowerProduction(entity.tile) - consumes.get(ConsumePower.class).powerPerTick, 0)*60 * entity.delta(), 1)),
|
||||
Strings.fixed(Math.max(entity.tile.block().getPowerProduction(entity.tile) - consumes.getPower().powerPerTick, 0)*60 * entity.delta(), 1)),
|
||||
() -> Pal.powerBar,
|
||||
() -> ((GeneratorEntity)entity).productionEfficiency));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
|
||||
if(hasItems){
|
||||
stats.add(BlockStat.productionTime, itemDuration / 60f, StatUnit.seconds);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
FusionReactorEntity entity = tile.entity();
|
||||
@ -64,8 +74,8 @@ public class ImpactReactor extends PowerGenerator{
|
||||
if(entity.cons.valid()){
|
||||
entity.warmup = Mathf.lerpDelta(entity.warmup, 1f, warmupSpeed);
|
||||
|
||||
if(entity.timer.get(timerUse, useTime)){
|
||||
entity.items.remove(consumes.item(), consumes.itemAmount());
|
||||
if(entity.timer.get(timerUse, itemDuration)){
|
||||
entity.cons.trigger();
|
||||
}
|
||||
}else{
|
||||
entity.warmup = Mathf.lerpDelta(entity.warmup, 0f, 0.01f);
|
||||
|
@ -1,19 +1,21 @@
|
||||
package io.anuke.mindustry.world.blocks.power;
|
||||
|
||||
import io.anuke.arc.Core;
|
||||
import io.anuke.mindustry.entities.Effects;
|
||||
import io.anuke.arc.graphics.Color;
|
||||
import io.anuke.arc.graphics.g2d.Draw;
|
||||
import io.anuke.arc.graphics.g2d.TextureRegion;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.arc.util.Time;
|
||||
import io.anuke.mindustry.content.Fx;
|
||||
import io.anuke.mindustry.entities.Effects;
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeItemFilter;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeLiquidFilter;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
|
||||
import static io.anuke.mindustry.Vars.content;
|
||||
import static io.anuke.mindustry.Vars.tilesize;
|
||||
@ -44,11 +46,11 @@ public class ItemLiquidGenerator extends PowerGenerator{
|
||||
this.hasLiquids = hasLiquids;
|
||||
|
||||
if(hasItems){
|
||||
consumes.add(new ConsumeItemFilter(item -> getItemEfficiency(item) >= minItemEfficiency)).update(false).optional(true);
|
||||
consumes.add(new ConsumeItemFilter(item -> getItemEfficiency(item) >= minItemEfficiency)).update(false);
|
||||
}
|
||||
|
||||
if(hasLiquids){
|
||||
consumes.add(new ConsumeLiquidFilter(liquid -> getLiquidEfficiency(liquid) >= minLiquidEfficiency, maxLiquidGenerate)).update(false).optional(true);
|
||||
consumes.add(new ConsumeLiquidFilter(liquid -> getLiquidEfficiency(liquid) >= minLiquidEfficiency, maxLiquidGenerate)).update(false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -60,6 +62,15 @@ public class ItemLiquidGenerator extends PowerGenerator{
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
|
||||
if(hasItems){
|
||||
stats.add(BlockStat.productionTime, itemDuration / 60f, StatUnit.seconds);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
ItemLiquidGeneratorEntity entity = tile.entity();
|
||||
|
@ -12,9 +12,15 @@ import io.anuke.mindustry.entities.Damage;
|
||||
import io.anuke.mindustry.entities.Effects;
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.graphics.Pal;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.mindustry.ui.Bar;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeItems;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeLiquid;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeType;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
@ -29,7 +35,7 @@ public class NuclearReactor extends PowerGenerator{
|
||||
|
||||
protected Color coolColor = new Color(1, 1, 1, 0f);
|
||||
protected Color hotColor = Color.valueOf("ff9575a3");
|
||||
protected int fuelUseTime = 120; //time to consume 1 fuel
|
||||
protected int itemDuration = 120; //time to consume 1 fuel
|
||||
protected float heating = 0.01f; //heating per frame * fullness
|
||||
protected float smokeThreshold = 0.3f; //threshold at which block starts smoking
|
||||
protected int explosionRadius = 19;
|
||||
@ -47,6 +53,15 @@ public class NuclearReactor extends PowerGenerator{
|
||||
hasLiquids = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
|
||||
if(hasItems){
|
||||
stats.add(BlockStat.productionTime, itemDuration / 60f, StatUnit.seconds);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(){
|
||||
super.load();
|
||||
@ -65,20 +80,23 @@ public class NuclearReactor extends PowerGenerator{
|
||||
public void update(Tile tile){
|
||||
NuclearReactorEntity entity = tile.entity();
|
||||
|
||||
int fuel = entity.items.get(consumes.item());
|
||||
ConsumeLiquid cliquid = consumes.get(ConsumeType.liquid);
|
||||
Item item = consumes.<ConsumeItems>get(ConsumeType.item).items[0].item;
|
||||
|
||||
int fuel = entity.items.get(item);
|
||||
float fullness = (float) fuel / itemCapacity;
|
||||
entity.productionEfficiency = fullness;
|
||||
|
||||
if(fuel > 0){
|
||||
entity.heat += fullness * heating * Math.min(entity.delta(), 4f);
|
||||
|
||||
if(entity.timer.get(timerFuel, fuelUseTime)){
|
||||
if(entity.timer.get(timerFuel, itemDuration)){
|
||||
entity.cons.trigger();
|
||||
}
|
||||
}
|
||||
|
||||
Liquid liquid = consumes.liquid();
|
||||
float liquidAmount = consumes.liquidAmount();
|
||||
Liquid liquid = cliquid.liquid;
|
||||
float liquidAmount = cliquid.amount;
|
||||
|
||||
if(entity.heat > 0){
|
||||
float maxUsed = Math.min(Math.min(entity.liquids.get(liquid), entity.heat / coolantPower), liquidAmount * entity.delta());
|
||||
@ -109,7 +127,7 @@ public class NuclearReactor extends PowerGenerator{
|
||||
|
||||
NuclearReactorEntity entity = tile.entity();
|
||||
|
||||
int fuel = entity.items.get(consumes.item());
|
||||
int fuel = entity.items.get(consumes.<ConsumeItems>get(ConsumeType.item).items[0].item);
|
||||
|
||||
if(fuel < 5 && entity.heat < 0.5f) return;
|
||||
|
||||
|
@ -37,7 +37,7 @@ public class PowerGenerator extends PowerDistributor{
|
||||
public void setBars(){
|
||||
super.setBars();
|
||||
|
||||
if(hasPower && outputsPower && !consumes.has(ConsumePower.class)){
|
||||
if(hasPower && outputsPower && !consumes.hasPower()){
|
||||
bars.add("power", entity -> new Bar(() ->
|
||||
Core.bundle.format("blocks.poweroutput",
|
||||
Strings.fixed(entity.tile.block().getPowerProduction(entity.tile)*60 * entity.timeScale, 1)),
|
||||
|
@ -54,8 +54,8 @@ public class PowerGraph{
|
||||
float powerNeeded = 0f;
|
||||
for(Tile consumer : consumers){
|
||||
Consumers consumes = consumer.block().consumes;
|
||||
if(consumes.has(ConsumePower.class)){
|
||||
ConsumePower consumePower = consumes.get(ConsumePower.class);
|
||||
if(consumes.hasPower()){
|
||||
ConsumePower consumePower = consumes.getPower();
|
||||
if(otherConsumersAreValid(consumer, consumePower)){
|
||||
powerNeeded += consumePower.requestedPower(consumer.block(), consumer.entity) * consumer.entity.delta();
|
||||
}
|
||||
@ -68,8 +68,8 @@ public class PowerGraph{
|
||||
float totalAccumulator = 0f;
|
||||
for(Tile battery : batteries){
|
||||
Consumers consumes = battery.block().consumes;
|
||||
if(consumes.has(ConsumePower.class)){
|
||||
totalAccumulator += battery.entity.power.satisfaction * consumes.get(ConsumePower.class).powerCapacity;
|
||||
if(consumes.hasPower()){
|
||||
totalAccumulator += battery.entity.power.satisfaction * consumes.getPower().powerCapacity;
|
||||
}
|
||||
}
|
||||
return totalAccumulator;
|
||||
@ -79,8 +79,8 @@ public class PowerGraph{
|
||||
float totalCapacity = 0f;
|
||||
for(Tile battery : batteries){
|
||||
Consumers consumes = battery.block().consumes;
|
||||
if(consumes.has(ConsumePower.class)){
|
||||
totalCapacity += consumes.get(ConsumePower.class).requestedPower(battery.block(), battery.entity) * battery.entity.delta();
|
||||
if(consumes.hasPower()){
|
||||
totalCapacity += consumes.getPower().requestedPower(battery.block(), battery.entity) * battery.entity.delta();
|
||||
}
|
||||
}
|
||||
return totalCapacity;
|
||||
@ -94,8 +94,8 @@ public class PowerGraph{
|
||||
float consumedPowerPercentage = Math.min(1.0f, needed / stored);
|
||||
for(Tile battery : batteries){
|
||||
Consumers consumes = battery.block().consumes;
|
||||
if(consumes.has(ConsumePower.class)){
|
||||
ConsumePower consumePower = consumes.get(ConsumePower.class);
|
||||
if(consumes.hasPower()){
|
||||
ConsumePower consumePower = consumes.getPower();
|
||||
if(consumePower.powerCapacity > 0f){
|
||||
battery.entity.power.satisfaction = Math.max(0.0f, battery.entity.power.satisfaction - consumedPowerPercentage);
|
||||
}
|
||||
@ -110,8 +110,8 @@ public class PowerGraph{
|
||||
|
||||
for(Tile battery : batteries){
|
||||
Consumers consumes = battery.block().consumes;
|
||||
if(consumes.has(ConsumePower.class)){
|
||||
ConsumePower consumePower = consumes.get(ConsumePower.class);
|
||||
if(consumes.hasPower()){
|
||||
ConsumePower consumePower = consumes.getPower();
|
||||
if(consumePower.powerCapacity > 0f){
|
||||
float additionalPowerPercentage = Math.min(1.0f, excess / consumePower.powerCapacity);
|
||||
battery.entity.power.satisfaction = Math.min(1.0f, battery.entity.power.satisfaction + additionalPowerPercentage);
|
||||
@ -126,8 +126,8 @@ public class PowerGraph{
|
||||
float coverage = Mathf.isZero(needed) ? 1f : Math.min(1, produced / needed);
|
||||
for(Tile consumer : consumers){
|
||||
Consumers consumes = consumer.block().consumes;
|
||||
if(consumes.has(ConsumePower.class)){
|
||||
ConsumePower consumePower = consumes.get(ConsumePower.class);
|
||||
if(consumes.hasPower()){
|
||||
ConsumePower consumePower = consumes.getPower();
|
||||
//currently satisfies power even if it's not required yet
|
||||
if(consumePower.isBuffered){
|
||||
if(!Mathf.isZero(consumePower.powerCapacity)){
|
||||
@ -176,7 +176,7 @@ public class PowerGraph{
|
||||
}
|
||||
|
||||
public void add(Tile tile){
|
||||
if(tile.block().consumes.has(ConsumePower.class) && !tile.block().consumes.get(ConsumePower.class).isBuffered){
|
||||
if(tile.block().consumes.hasPower() && !tile.block().consumes.getPower().isBuffered){
|
||||
//reset satisfaction to zero in case of direct consumer. There is no reason to clear power from buffered consumers.
|
||||
tile.entity.power.satisfaction = 0.0f;
|
||||
}
|
||||
@ -184,7 +184,7 @@ public class PowerGraph{
|
||||
tile.entity.power.graph = this;
|
||||
all.add(tile);
|
||||
|
||||
if(tile.block().outputsPower && tile.block().consumesPower && !tile.block().consumes.get(ConsumePower.class).isBuffered){
|
||||
if(tile.block().outputsPower && tile.block().consumesPower && !tile.block().consumes.getPower().isBuffered){
|
||||
producers.add(tile);
|
||||
consumers.add(tile);
|
||||
}else if(tile.block().outputsPower && tile.block().consumesPower){
|
||||
@ -259,7 +259,7 @@ public class PowerGraph{
|
||||
|
||||
private boolean otherConsumersAreValid(Tile tile, Consume consumePower){
|
||||
for(Consume cons : tile.block().consumes.all()){
|
||||
if(cons != consumePower && !cons.isOptional() && !cons.valid(tile.block(), tile.entity())){
|
||||
if(cons != consumePower && !cons.isOptional() && !cons.valid(tile.entity())){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +0,0 @@
|
||||
package io.anuke.mindustry.world.blocks.power;
|
||||
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeLiquid;
|
||||
|
||||
public class TurbineGenerator extends BurnerGenerator{
|
||||
|
||||
public TurbineGenerator(String name){
|
||||
super(name);
|
||||
singleLiquid = false;
|
||||
|
||||
consumes.require(ConsumeLiquid.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
||||
return (liquid == consumes.liquid() && tile.entity.liquids.get(consumes.liquid()) < liquidCapacity);
|
||||
}
|
||||
}
|
@ -3,17 +3,16 @@ package io.anuke.mindustry.world.blocks.production;
|
||||
import io.anuke.arc.Core;
|
||||
import io.anuke.arc.collection.Array;
|
||||
import io.anuke.arc.collection.ObjectIntMap;
|
||||
import io.anuke.arc.util.Strings;
|
||||
import io.anuke.mindustry.entities.Effects;
|
||||
import io.anuke.mindustry.entities.Effects.Effect;
|
||||
import io.anuke.arc.graphics.Blending;
|
||||
import io.anuke.arc.graphics.Color;
|
||||
import io.anuke.arc.graphics.g2d.Draw;
|
||||
import io.anuke.arc.graphics.g2d.TextureRegion;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.arc.util.Strings;
|
||||
import io.anuke.arc.util.Time;
|
||||
import io.anuke.mindustry.content.Fx;
|
||||
import io.anuke.mindustry.content.Liquids;
|
||||
import io.anuke.mindustry.entities.Effects;
|
||||
import io.anuke.mindustry.entities.Effects.Effect;
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.graphics.Layer;
|
||||
import io.anuke.mindustry.graphics.Pal;
|
||||
@ -22,7 +21,6 @@ import io.anuke.mindustry.type.ItemType;
|
||||
import io.anuke.mindustry.ui.Bar;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeLiquid;
|
||||
import io.anuke.mindustry.world.meta.BlockGroup;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
@ -40,8 +38,6 @@ public class Drill extends Block{
|
||||
protected int tier;
|
||||
/**Base time to drill one ore, in frames.*/
|
||||
protected float drillTime = 300;
|
||||
/**Whether the liquid is required to drill. If false, then it will be used as a speed booster.*/
|
||||
protected boolean liquidRequired = false;
|
||||
/**How many times faster the drill will progress when boosted by liquid.*/
|
||||
protected float liquidBoostIntensity = 1.6f;
|
||||
/**Speed at which the drill speeds up.*/
|
||||
@ -74,8 +70,6 @@ public class Drill extends Block{
|
||||
hasLiquids = true;
|
||||
liquidCapacity = 5f;
|
||||
hasItems = true;
|
||||
|
||||
consumes.liquid(Liquids.water, 0.05f).optional(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -161,6 +155,7 @@ public class Drill extends Block{
|
||||
});
|
||||
|
||||
stats.add(BlockStat.drillSpeed, 60f / drillTime * size * size, StatUnit.itemsSecond);
|
||||
stats.add(BlockStat.boostEffect, liquidBoostIntensity, StatUnit.timesSpeed);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -204,9 +199,10 @@ public class Drill extends Block{
|
||||
|
||||
float speed = 1f;
|
||||
|
||||
if(entity.consumed(ConsumeLiquid.class) && !liquidRequired){
|
||||
if(entity.cons.optionalValid()){
|
||||
speed = liquidBoostIntensity;
|
||||
}
|
||||
|
||||
if(hasPower){
|
||||
speed *= entity.power.satisfaction; // Drill slower when not at full power
|
||||
}
|
||||
|
@ -1,11 +1,12 @@
|
||||
package io.anuke.mindustry.world.blocks.production;
|
||||
|
||||
import io.anuke.arc.Core;
|
||||
import io.anuke.arc.graphics.g2d.Draw;
|
||||
import io.anuke.arc.graphics.g2d.TextureRegion;
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.arc.graphics.g2d.Draw;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
|
||||
public class Fracker extends SolidPump{
|
||||
protected final float itemUseTime = 100f;
|
||||
@ -17,9 +18,13 @@ public class Fracker extends SolidPump{
|
||||
public Fracker(String name){
|
||||
super(name);
|
||||
hasItems = true;
|
||||
singleLiquid = false;
|
||||
}
|
||||
|
||||
consumes.require(ConsumeItem.class);
|
||||
@Override
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
|
||||
stats.add(BlockStat.productionTime, itemUseTime / 60f, StatUnit.seconds);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -54,14 +59,13 @@ public class Fracker extends SolidPump{
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
FrackerEntity entity = tile.entity();
|
||||
Item item = consumes.item();
|
||||
|
||||
while(entity.accumulator >= itemUseTime && entity.items.has(item, 1)){
|
||||
entity.items.remove(item, 1);
|
||||
entity.accumulator -= itemUseTime;
|
||||
}
|
||||
|
||||
if(entity.cons.valid() && entity.accumulator < itemUseTime){
|
||||
if(entity.accumulator >= itemUseTime){
|
||||
entity.cons.trigger();
|
||||
entity.accumulator -= itemUseTime;
|
||||
}
|
||||
|
||||
super.update(tile);
|
||||
entity.accumulator += entity.delta() * entity.power.satisfaction;
|
||||
}else{
|
||||
|
@ -14,6 +14,7 @@ import io.anuke.mindustry.type.ItemStack;
|
||||
import io.anuke.mindustry.type.LiquidStack;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeLiquidBase;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeType;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
@ -45,20 +46,20 @@ public class GenericCrafter extends Block{
|
||||
|
||||
@Override
|
||||
public void setStats(){
|
||||
if(consumes.has(ConsumeType.liquid)){
|
||||
ConsumeLiquidBase cons = consumes.get(ConsumeType.liquid);
|
||||
cons.timePeriod = craftTime;
|
||||
}
|
||||
|
||||
super.setStats();
|
||||
stats.add(BlockStat.productionTime, craftTime / 60f, StatUnit.seconds);
|
||||
|
||||
if(consumes.has(ConsumeType.liquid)){
|
||||
//TODO replace with per second instead of
|
||||
//stats.remove();
|
||||
}
|
||||
|
||||
if(outputItem != null){
|
||||
stats.add(BlockStat.output, outputItem);
|
||||
}
|
||||
|
||||
if(outputLiquid != null){
|
||||
stats.add(BlockStat.output, outputLiquid);
|
||||
stats.add(BlockStat.output, outputLiquid.liquid, outputLiquid.amount, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,17 +1,16 @@
|
||||
package io.anuke.mindustry.world.blocks.production;
|
||||
|
||||
import io.anuke.arc.Core;
|
||||
import io.anuke.arc.graphics.g2d.TextureRegion;
|
||||
import io.anuke.arc.collection.Array;
|
||||
import io.anuke.arc.graphics.g2d.Draw;
|
||||
import io.anuke.arc.graphics.g2d.TextureRegion;
|
||||
import io.anuke.mindustry.graphics.Layer;
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.LiquidBlock;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeLiquid;
|
||||
import io.anuke.mindustry.world.meta.BlockGroup;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
import io.anuke.arc.graphics.g2d.Draw;
|
||||
|
||||
public class Pump extends LiquidBlock{
|
||||
protected final Array<Tile> drawTiles = new Array<>();
|
||||
@ -107,11 +106,6 @@ public class Pump extends LiquidBlock{
|
||||
tryDumpLiquid(tile, tile.entity.liquids.current());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
||||
return consumes.has(ConsumeLiquid.class) && consumes.liquid() == liquid && super.acceptLiquid(tile, source, liquid, amount);
|
||||
}
|
||||
|
||||
protected boolean isValid(Tile tile){
|
||||
return tile != null && tile.floor().liquidDrop != null;
|
||||
}
|
||||
|
@ -10,7 +10,10 @@ import io.anuke.mindustry.type.ItemStack;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.production.GenericCrafter.GenericCrafterEntity;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeLiquidBase;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeType;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
import io.anuke.mindustry.world.meta.values.ItemFilterValue;
|
||||
|
||||
/**
|
||||
@ -20,7 +23,7 @@ public class Separator extends Block{
|
||||
protected final int timerDump = timers++;
|
||||
|
||||
protected ItemStack[] results;
|
||||
protected float filterTime;
|
||||
protected float craftTime;
|
||||
protected float spinnerRadius = 2.5f;
|
||||
protected float spinnerLength = 1f;
|
||||
protected float spinnerThickness = 1f;
|
||||
@ -41,6 +44,11 @@ public class Separator extends Block{
|
||||
|
||||
@Override
|
||||
public void setStats(){
|
||||
if(consumes.has(ConsumeType.liquid)){
|
||||
ConsumeLiquidBase cons = consumes.get(ConsumeType.liquid);
|
||||
cons.timePeriod = craftTime;
|
||||
}
|
||||
|
||||
super.setStats();
|
||||
|
||||
stats.add(BlockStat.output, new ItemFilterValue(item -> {
|
||||
@ -49,6 +57,9 @@ public class Separator extends Block{
|
||||
}
|
||||
return false;
|
||||
}));
|
||||
|
||||
stats.add(BlockStat.productionTime, craftTime / 60f, StatUnit.seconds);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -74,7 +85,7 @@ public class Separator extends Block{
|
||||
entity.totalProgress += entity.warmup * entity.delta();
|
||||
|
||||
if(entity.cons.valid()){
|
||||
entity.progress += getProgressIncrease(entity, filterTime);
|
||||
entity.progress += getProgressIncrease(entity, craftTime);
|
||||
entity.warmup = Mathf.lerpDelta(entity.warmup, 1f, 0.02f);
|
||||
}else{
|
||||
entity.warmup = Mathf.lerpDelta(entity.warmup, 0f, 0.02f);
|
||||
|
@ -60,7 +60,8 @@ public class SolidPump extends Pump{
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
|
||||
stats.add(BlockStat.output, result);
|
||||
stats.remove(BlockStat.output);
|
||||
stats.add(BlockStat.output, result, 60f * pumpAmount, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -23,6 +23,8 @@ import io.anuke.mindustry.graphics.Shaders;
|
||||
import io.anuke.mindustry.type.Mech;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
@ -45,6 +47,13 @@ public class MechPad extends Block{
|
||||
hasPower = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
|
||||
stats.add(BlockStat.productionTime, buildTime/60f, StatUnit.seconds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(){
|
||||
super.init();
|
||||
|
@ -25,10 +25,10 @@ import io.anuke.mindustry.ui.Bar;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeItems;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeType;
|
||||
import io.anuke.mindustry.world.meta.BlockFlag;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
import io.anuke.mindustry.world.modules.ItemModule;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
@ -45,6 +45,7 @@ public class UnitFactory extends Block{
|
||||
protected float launchVelocity = 0f;
|
||||
protected TextureRegion topRegion;
|
||||
protected int maxSpawn = 2;
|
||||
protected int[] capacities;
|
||||
|
||||
public UnitFactory(String name){
|
||||
super(name);
|
||||
@ -53,8 +54,6 @@ public class UnitFactory extends Block{
|
||||
hasItems = true;
|
||||
solid = false;
|
||||
flags = EnumSet.of(BlockFlag.producer);
|
||||
|
||||
consumes.require(ConsumeItems.class);
|
||||
}
|
||||
|
||||
@Remote(called = Loc.server)
|
||||
@ -79,6 +78,19 @@ public class UnitFactory extends Block{
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(){
|
||||
super.init();
|
||||
|
||||
capacities = new int[Vars.content.items().size];
|
||||
if(consumes.has(ConsumeType.item)){
|
||||
ConsumeItems cons = consumes.get(ConsumeType.item);
|
||||
for(ItemStack stack : cons.items){
|
||||
capacities[stack.item.id] = stack.amount*2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(){
|
||||
super.load();
|
||||
@ -102,6 +114,7 @@ public class UnitFactory extends Block{
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
|
||||
stats.remove(BlockStat.itemCapacity);
|
||||
stats.add(BlockStat.productionTime, produceTime / 60f, StatUnit.seconds);
|
||||
stats.add(BlockStat.maxUnits, maxSpawn, StatUnit.none);
|
||||
}
|
||||
@ -190,24 +203,9 @@ public class UnitFactory extends Block{
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
for(ItemStack stack : consumes.items()){
|
||||
if(item == stack.item && tile.entity.items.get(item) < stack.amount * 2){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaximumAccepted(Tile tile, Item item){
|
||||
for(ItemStack stack : consumes.items()){
|
||||
if(item == stack.item){
|
||||
return stack.amount * 2;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return capacities[item.id];
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -222,11 +220,11 @@ public class UnitFactory extends Block{
|
||||
}
|
||||
|
||||
public static class UnitFactoryEntity extends TileEntity{
|
||||
public float buildTime;
|
||||
public float time;
|
||||
public float speedScl;
|
||||
public float warmup; //only for enemy spawners
|
||||
public int spawned;
|
||||
float buildTime;
|
||||
float time;
|
||||
float speedScl;
|
||||
float warmup; //only for enemy spawners
|
||||
int spawned;
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
|
@ -2,14 +2,13 @@ package io.anuke.mindustry.world.consumers;
|
||||
|
||||
import io.anuke.arc.scene.ui.layout.Table;
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.meta.BlockStats;
|
||||
|
||||
/**An abstract class that defines a type of resource that a block can consume.*/
|
||||
public abstract class Consume{
|
||||
protected boolean optional;
|
||||
protected boolean update = true, boost = false;
|
||||
protected boolean update = true;
|
||||
|
||||
/**Apply a filter to items accepted.
|
||||
* This should set all item IDs that are present in the filter to true.*/
|
||||
@ -33,11 +32,6 @@ public abstract class Consume{
|
||||
return this;
|
||||
}
|
||||
|
||||
public Consume boost(boolean boost){
|
||||
this.boost = boost;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isOptional(){
|
||||
return optional;
|
||||
}
|
||||
@ -51,15 +45,15 @@ public abstract class Consume{
|
||||
public abstract void build(Tile tile, Table table);
|
||||
|
||||
/**Called when a consumption is triggered manually.*/
|
||||
public void trigger(Block block, TileEntity entity){
|
||||
public void trigger(TileEntity entity){
|
||||
|
||||
}
|
||||
|
||||
public abstract String getIcon();
|
||||
|
||||
public abstract void update(Block block, TileEntity entity);
|
||||
public abstract void update(TileEntity entity);
|
||||
|
||||
public abstract boolean valid(Block block, TileEntity entity);
|
||||
public abstract boolean valid(TileEntity entity);
|
||||
|
||||
public abstract void display(BlockStats stats);
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ import io.anuke.mindustry.type.Item.Icon;
|
||||
import io.anuke.mindustry.ui.ItemImage;
|
||||
import io.anuke.mindustry.ui.MultiReqImage;
|
||||
import io.anuke.mindustry.ui.ReqImage;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.BlockStats;
|
||||
@ -18,7 +17,7 @@ import io.anuke.mindustry.world.meta.values.ItemFilterValue;
|
||||
import static io.anuke.mindustry.Vars.content;
|
||||
|
||||
public class ConsumeItemFilter extends Consume{
|
||||
private final Predicate<Item> filter;
|
||||
public final Predicate<Item> filter;
|
||||
|
||||
public ConsumeItemFilter(Predicate<Item> item){
|
||||
this.filter = item;
|
||||
@ -49,12 +48,12 @@ public class ConsumeItemFilter extends Consume{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Block block, TileEntity entity){
|
||||
public void update(TileEntity entity){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void trigger(Block block, TileEntity entity){
|
||||
public void trigger(TileEntity entity){
|
||||
for(int i = 0; i < content.items().size; i++){
|
||||
Item item = content.item(i);
|
||||
if(entity.items != null && entity.items.has(item) && this.filter.test(item)){
|
||||
@ -65,7 +64,7 @@ public class ConsumeItemFilter extends Consume{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valid(Block block, TileEntity entity){
|
||||
public boolean valid(TileEntity entity){
|
||||
for(int i = 0; i < content.items().size; i++){
|
||||
Item item = content.item(i);
|
||||
if(entity.items != null && entity.items.has(item) && this.filter.test(item)){
|
||||
@ -77,6 +76,6 @@ public class ConsumeItemFilter extends Consume{
|
||||
|
||||
@Override
|
||||
public void display(BlockStats stats){
|
||||
stats.add(boost ? BlockStat.booster : BlockStat.input, new ItemFilterValue(filter));
|
||||
stats.add(optional ? BlockStat.booster : BlockStat.input, new ItemFilterValue(filter));
|
||||
}
|
||||
}
|
||||
|
@ -6,23 +6,18 @@ import io.anuke.mindustry.type.Item.Icon;
|
||||
import io.anuke.mindustry.type.ItemStack;
|
||||
import io.anuke.mindustry.ui.ItemImage;
|
||||
import io.anuke.mindustry.ui.ReqImage;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.BlockStats;
|
||||
import io.anuke.mindustry.world.meta.values.ItemListValue;
|
||||
|
||||
public class ConsumeItems extends Consume{
|
||||
private final ItemStack[] items;
|
||||
public final ItemStack[] items;
|
||||
|
||||
public ConsumeItems(ItemStack[] items){
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
public ItemStack[] getItems(){
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyItemFilter(boolean[] filter){
|
||||
for(ItemStack stack : items){
|
||||
@ -48,24 +43,24 @@ public class ConsumeItems extends Consume{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Block block, TileEntity entity){
|
||||
public void update(TileEntity entity){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void trigger(Block block, TileEntity entity){
|
||||
public void trigger(TileEntity entity){
|
||||
for(ItemStack stack : items){
|
||||
entity.items.remove(stack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valid(Block block, TileEntity entity){
|
||||
public boolean valid(TileEntity entity){
|
||||
return entity.items != null && entity.items.has(items);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void display(BlockStats stats){
|
||||
stats.add(boost ? BlockStat.booster : BlockStat.input, new ItemListValue(items));
|
||||
stats.add(optional ? BlockStat.booster : BlockStat.input, new ItemListValue(items));
|
||||
}
|
||||
}
|
||||
|
@ -3,20 +3,17 @@ package io.anuke.mindustry.world.consumers;
|
||||
import io.anuke.arc.scene.ui.layout.Table;
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.mindustry.type.LiquidStack;
|
||||
import io.anuke.mindustry.ui.ReqImage;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.BlockStats;
|
||||
|
||||
public class ConsumeLiquid extends Consume{
|
||||
protected final float use;
|
||||
protected final Liquid liquid;
|
||||
public class ConsumeLiquid extends ConsumeLiquidBase{
|
||||
public final Liquid liquid;
|
||||
|
||||
public ConsumeLiquid(Liquid liquid, float use){
|
||||
public ConsumeLiquid(Liquid liquid, float amount){
|
||||
super(amount);
|
||||
this.liquid = liquid;
|
||||
this.use = use;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -24,22 +21,9 @@ public class ConsumeLiquid extends Consume{
|
||||
filter[liquid.id] = true;
|
||||
}
|
||||
|
||||
public float used(){
|
||||
return use;
|
||||
}
|
||||
|
||||
public Liquid get(){
|
||||
return liquid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConsumeType type(){
|
||||
return ConsumeType.liquid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(Tile tile, Table table){
|
||||
table.add(new ReqImage(liquid.getContentIcon(), () -> valid(tile.block(), tile.entity))).size(8*4);
|
||||
table.add(new ReqImage(liquid.getContentIcon(), () -> valid(tile.entity))).size(8*4);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -48,22 +32,17 @@ public class ConsumeLiquid extends Consume{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Block block, TileEntity entity){
|
||||
entity.liquids.remove(liquid, Math.min(use(block, entity), entity.liquids.get(liquid)));
|
||||
public void update(TileEntity entity){
|
||||
entity.liquids.remove(liquid, Math.min(use(entity), entity.liquids.get(liquid)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valid(Block block, TileEntity entity){
|
||||
return entity != null && entity.liquids != null && entity.liquids.get(liquid) >= use(block, entity);
|
||||
public boolean valid(TileEntity entity){
|
||||
return entity != null && entity.liquids != null && entity.liquids.get(liquid) >= use(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void display(BlockStats stats){
|
||||
//stats.add(BlockStat.liquidUse, use * 60f, StatUnit.liquidSecond);
|
||||
stats.add(boost ? BlockStat.booster : BlockStat.input, new LiquidStack(liquid, use * 60f));
|
||||
}
|
||||
|
||||
float use(Block block, TileEntity entity){
|
||||
return Math.min(use * entity.delta(), block.liquidCapacity);
|
||||
stats.add(optional ? BlockStat.booster : BlockStat.input, liquid, amount * timePeriod, timePeriod == 60);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,26 @@
|
||||
package io.anuke.mindustry.world.consumers;
|
||||
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
|
||||
public abstract class ConsumeLiquidBase extends Consume{
|
||||
/**amount used per frame*/
|
||||
public final float amount;
|
||||
/**How much time is taken to use this liquid, in ticks. Used only for visual purposes.
|
||||
* Example: a normal ConsumeLiquid with 10/s and a 10 second timePeriod would display as "100 seconds".
|
||||
* Without a time override, it would display as "10 liquid/second".
|
||||
* This is used for generic crafters.*/
|
||||
public float timePeriod = 60;
|
||||
|
||||
public ConsumeLiquidBase(float amount){
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConsumeType type(){
|
||||
return ConsumeType.liquid;
|
||||
}
|
||||
|
||||
protected float use(TileEntity entity){
|
||||
return Math.min(amount * entity.delta(), entity.block.liquidCapacity);
|
||||
}
|
||||
}
|
@ -7,7 +7,6 @@ import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.mindustry.ui.MultiReqImage;
|
||||
import io.anuke.mindustry.ui.ReqImage;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.BlockStats;
|
||||
@ -15,13 +14,12 @@ import io.anuke.mindustry.world.meta.values.LiquidFilterValue;
|
||||
|
||||
import static io.anuke.mindustry.Vars.content;
|
||||
|
||||
public class ConsumeLiquidFilter extends Consume{
|
||||
private final Predicate<Liquid> filter;
|
||||
private final float use;
|
||||
public class ConsumeLiquidFilter extends ConsumeLiquidBase{
|
||||
public final Predicate<Liquid> filter;
|
||||
|
||||
public ConsumeLiquidFilter(Predicate<Liquid> liquid, float amount){
|
||||
super(amount);
|
||||
this.filter = liquid;
|
||||
this.use = amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -29,16 +27,11 @@ public class ConsumeLiquidFilter extends Consume{
|
||||
content.liquids().each(filter, item -> arr[item.id] = true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConsumeType type(){
|
||||
return ConsumeType.liquid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(Tile tile, Table table){
|
||||
Array<Liquid> list = content.liquids().select(l -> !l.isHidden() && filter.test(l));
|
||||
MultiReqImage image = new MultiReqImage();
|
||||
list.each(liquid -> image.add(new ReqImage(liquid.getContentIcon(), () -> tile.entity != null && tile.entity.liquids != null && tile.entity.liquids.get(liquid) >= use(tile.block(), tile.entity))));
|
||||
list.each(liquid -> image.add(new ReqImage(liquid.getContentIcon(), () -> tile.entity != null && tile.entity.liquids != null && tile.entity.liquids.get(liquid) >= use(tile.entity))));
|
||||
|
||||
table.add(image).size(8*4);
|
||||
}
|
||||
@ -49,21 +42,17 @@ public class ConsumeLiquidFilter extends Consume{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Block block, TileEntity entity){
|
||||
entity.liquids.remove(entity.liquids.current(), use(block, entity));
|
||||
public void update(TileEntity entity){
|
||||
entity.liquids.remove(entity.liquids.current(), use(entity));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valid(Block block, TileEntity entity){
|
||||
return entity != null && entity.liquids != null && filter.test(entity.liquids.current()) && entity.liquids.currentAmount() >= use(block, entity);
|
||||
public boolean valid(TileEntity entity){
|
||||
return entity != null && entity.liquids != null && filter.test(entity.liquids.current()) && entity.liquids.currentAmount() >= use(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void display(BlockStats stats){
|
||||
stats.add(boost ? BlockStat.booster : BlockStat.input, new LiquidFilterValue(filter, use * 60f));
|
||||
}
|
||||
|
||||
float use(Block block, TileEntity entity){
|
||||
return Math.min(use * entity.delta(), block.liquidCapacity);
|
||||
stats.add(optional ? BlockStat.booster : BlockStat.input, new LiquidFilterValue(filter, amount * timePeriod, timePeriod == 60f));
|
||||
}
|
||||
}
|
||||
|
@ -40,12 +40,12 @@ public class ConsumePower extends Consume{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Block block, TileEntity entity){
|
||||
public void update(TileEntity entity){
|
||||
// Nothing to do since PowerGraph directly updates entity.power.satisfaction
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valid(Block block, TileEntity entity){
|
||||
public boolean valid(TileEntity entity){
|
||||
if(isBuffered){
|
||||
return true;
|
||||
}else{
|
||||
|
@ -1,49 +1,37 @@
|
||||
package io.anuke.mindustry.world.consumers;
|
||||
|
||||
import io.anuke.arc.collection.Array;
|
||||
import io.anuke.arc.collection.ObjectSet;
|
||||
import io.anuke.arc.util.Log;
|
||||
import io.anuke.arc.util.Structs;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.type.ItemStack;
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.meta.BlockStats;
|
||||
|
||||
public class Consumers{
|
||||
private Consume[] map = new Consume[ConsumeType.values().length];
|
||||
private ObjectSet<ConsumeType> required = new ObjectSet<>();
|
||||
private Consume[] results;
|
||||
private Consume[] results, optionalResults;
|
||||
|
||||
public final boolean[] itemFilters = new boolean[Vars.content.items().size];
|
||||
public final boolean[] liquidfilters = new boolean[Vars.content.liquids().size];
|
||||
|
||||
public void require(ConsumeType type){
|
||||
required.add(type);
|
||||
}
|
||||
public void init(){
|
||||
results = Structs.filter(Consume.class, map, m -> m != null);
|
||||
optionalResults = Structs.filter(Consume.class, map, m -> m != null && m.isOptional());
|
||||
|
||||
public void checkRequired(Block block){
|
||||
for(ConsumeType c : required){
|
||||
if(!has(c)){
|
||||
throw new RuntimeException("Missing required consumer of type \"" + c + "\" in block \"" + block.name + "\"!");
|
||||
}
|
||||
}
|
||||
|
||||
Array<Consume> array = new Array<>(Consume.class);
|
||||
for(Consume cons : map){
|
||||
if(cons != null){
|
||||
array.add(cons);
|
||||
}
|
||||
}
|
||||
|
||||
results = array.toArray();
|
||||
|
||||
for(Consume cons : all()){
|
||||
for(Consume cons : results){
|
||||
cons.applyItemFilter(itemFilters);
|
||||
cons.applyLiquidFilter(liquidfilters);
|
||||
}
|
||||
}
|
||||
|
||||
public ConsumePower getPower(){
|
||||
return get(ConsumeType.power);
|
||||
}
|
||||
|
||||
public boolean hasPower(){
|
||||
return has(ConsumeType.power);
|
||||
}
|
||||
|
||||
public ConsumeLiquid liquid(Liquid liquid, float amount){
|
||||
return add(new ConsumeLiquid(liquid, amount));
|
||||
}
|
||||
@ -88,10 +76,6 @@ public class Consumers{
|
||||
}
|
||||
|
||||
public <T extends Consume> T add(T consume){
|
||||
if(map[consume.type().ordinal()] != null){
|
||||
Log.warn("[WARN] Conflict: Replacing {0} with {1}", consume, map[consume.type().ordinal()]);
|
||||
}
|
||||
|
||||
map[consume.type().ordinal()] = consume;
|
||||
return consume;
|
||||
}
|
||||
@ -116,6 +100,10 @@ public class Consumers{
|
||||
return results;
|
||||
}
|
||||
|
||||
public Consume[] optionals(){
|
||||
return optionalResults;
|
||||
}
|
||||
|
||||
public void display(BlockStats stats){
|
||||
for(Consume c : map){
|
||||
if(c != null){
|
||||
|
@ -14,8 +14,6 @@ public enum BlockStat{
|
||||
launchTime(StatCategory.items),
|
||||
|
||||
liquidCapacity(StatCategory.liquids),
|
||||
coolant(StatCategory.liquids),
|
||||
coolantUse(StatCategory.liquids),
|
||||
|
||||
powerCapacity(StatCategory.power),
|
||||
powerUse(StatCategory.power),
|
||||
@ -31,6 +29,7 @@ public enum BlockStat{
|
||||
drillSpeed(StatCategory.crafting),
|
||||
maxUnits(StatCategory.crafting),
|
||||
|
||||
speedIncrease(StatCategory.shooting),
|
||||
repairTime(StatCategory.shooting),
|
||||
range(StatCategory.shooting),
|
||||
shootRange(StatCategory.shooting),
|
||||
@ -43,7 +42,7 @@ public enum BlockStat{
|
||||
ammo(StatCategory.shooting),
|
||||
|
||||
booster(StatCategory.optional),
|
||||
|
||||
boostEffect(StatCategory.optional)
|
||||
;
|
||||
|
||||
public final StatCategory category;
|
||||
|
@ -6,7 +6,6 @@ import io.anuke.arc.collection.OrderedMap;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.type.ItemStack;
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.mindustry.type.LiquidStack;
|
||||
import io.anuke.mindustry.world.meta.values.*;
|
||||
|
||||
/**Hold and organizes a list of block stats.*/
|
||||
@ -29,19 +28,14 @@ public class BlockStats{
|
||||
add(stat, new ItemListValue(new ItemStack(item, 1)));
|
||||
}
|
||||
|
||||
/**Adds a liquid value.*/
|
||||
public void add(BlockStat stat, Liquid liquid){
|
||||
add(stat, new LiquidValue(liquid));
|
||||
}
|
||||
|
||||
/**Adds an item value.*/
|
||||
public void add(BlockStat stat, ItemStack item){
|
||||
add(stat, new ItemListValue(item));
|
||||
}
|
||||
|
||||
/**Adds an item value.*/
|
||||
public void add(BlockStat stat, LiquidStack stack){
|
||||
add(stat, new LiquidValue(stack.liquid, stack.amount));
|
||||
public void add(BlockStat stat, Liquid liquid, float amount, boolean perSecond){
|
||||
add(stat, new LiquidValue(liquid, amount, perSecond));
|
||||
}
|
||||
|
||||
/**Adds a single string value with this stat.*/
|
||||
|
@ -16,9 +16,23 @@ public enum StatUnit{
|
||||
powerUnits,
|
||||
degrees,
|
||||
seconds,
|
||||
perSecond,
|
||||
timesSpeed(false),
|
||||
timesRadius(false),
|
||||
percent(false),
|
||||
none,
|
||||
items;
|
||||
|
||||
public final boolean space;
|
||||
|
||||
StatUnit(boolean space){
|
||||
this.space = space;
|
||||
}
|
||||
|
||||
StatUnit(){
|
||||
this(true);
|
||||
}
|
||||
|
||||
public String localized(){
|
||||
if(this == none) return "";
|
||||
return Core.bundle.get("unit." + name().toLowerCase(Locale.ROOT));
|
||||
|
@ -12,10 +12,12 @@ import static io.anuke.mindustry.Vars.content;
|
||||
public class LiquidFilterValue implements StatValue{
|
||||
private final Predicate<Liquid> filter;
|
||||
private final float amount;
|
||||
private final boolean perSecond;
|
||||
|
||||
public LiquidFilterValue(Predicate<Liquid> filter, float amount){
|
||||
public LiquidFilterValue(Predicate<Liquid> filter, float amount, boolean perSecond){
|
||||
this.filter = filter;
|
||||
this.amount = amount;
|
||||
this.perSecond = perSecond;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -27,7 +29,7 @@ public class LiquidFilterValue implements StatValue{
|
||||
}
|
||||
|
||||
for(int i = 0; i < list.size; i++){
|
||||
table.add(new LiquidDisplay(list.get(i), amount)).padRight(5);
|
||||
table.add(new LiquidDisplay(list.get(i), amount, perSecond)).padRight(5);
|
||||
|
||||
if(i != list.size - 1){
|
||||
table.add("/");
|
||||
|
@ -8,18 +8,16 @@ import io.anuke.mindustry.world.meta.StatValue;
|
||||
public class LiquidValue implements StatValue{
|
||||
private final Liquid liquid;
|
||||
private final float amount;
|
||||
private final boolean perSecond;
|
||||
|
||||
public LiquidValue(Liquid liquid, float amount){
|
||||
public LiquidValue(Liquid liquid, float amount, boolean perSecond){
|
||||
this.liquid = liquid;
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public LiquidValue(Liquid liquid){
|
||||
this(liquid, 0f);
|
||||
this.perSecond = perSecond;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void display(Table table){
|
||||
table.add(new LiquidDisplay(liquid, amount));
|
||||
table.add(new LiquidDisplay(liquid, amount, perSecond));
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,6 @@ public class NumberValue implements StatValue{
|
||||
int precision = Math.abs((int) value - value) <= 0.001f ? 0 : Math.abs((int) (value * 10) - value * 10) <= 0.001f ? 1 : 2;
|
||||
|
||||
table.add(Strings.fixed(value, precision));
|
||||
table.add(" " + unit.localized());
|
||||
table.add((unit.space ? " " : "") + unit.localized());
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
||||
public class ConsumeModule extends BlockModule{
|
||||
private boolean valid;
|
||||
private boolean valid, optionalValid;
|
||||
private final TileEntity entity;
|
||||
|
||||
public ConsumeModule(TileEntity entity){
|
||||
@ -18,22 +18,31 @@ public class ConsumeModule extends BlockModule{
|
||||
public void update(){
|
||||
boolean prevValid = valid();
|
||||
valid = true;
|
||||
optionalValid = true;
|
||||
boolean docons = entity.tile.block().shouldConsume(entity.tile);
|
||||
|
||||
for(Consume cons : entity.tile.block().consumes.all()){
|
||||
if(docons && cons.isUpdate() && prevValid && cons.valid(entity.getTile().block(), entity)){
|
||||
cons.update(entity.getTile().block(), entity);
|
||||
if(docons && cons.isUpdate() && prevValid && cons.valid(entity)){
|
||||
cons.update(entity);
|
||||
}
|
||||
|
||||
if(!cons.isOptional()){
|
||||
valid &= cons.valid(entity.getTile().block(), entity);
|
||||
valid &= cons.valid(entity);
|
||||
}
|
||||
}
|
||||
|
||||
for(Consume cons : entity.tile.block().consumes.optionals()){
|
||||
if(docons && cons.isUpdate() && prevValid && cons.valid(entity)){
|
||||
cons.update(entity);
|
||||
}
|
||||
|
||||
optionalValid &= cons.valid(entity);
|
||||
}
|
||||
}
|
||||
|
||||
public void trigger(){
|
||||
for(Consume cons : entity.tile.block().consumes.all()){
|
||||
cons.trigger(entity.tile.block(), entity);
|
||||
cons.trigger(entity);
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,6 +50,10 @@ public class ConsumeModule extends BlockModule{
|
||||
return valid && entity.tile.block().canProduce(entity.tile);
|
||||
}
|
||||
|
||||
public boolean optionalValid(){
|
||||
return valid() && optionalValid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
stream.writeBoolean(valid);
|
||||
|
@ -176,9 +176,9 @@ public class PowerTests extends PowerTestFixture{
|
||||
powerGraph.update();
|
||||
|
||||
assertEquals(0.0f, consumerTile.entity.power.satisfaction, Mathf.FLOAT_ROUNDING_ERROR);
|
||||
if(consumerTile.block().consumes.has(ConsumePower.class)){
|
||||
ConsumePower consumePower = consumerTile.block().consumes.get(ConsumePower.class);
|
||||
assertFalse(consumePower.valid(consumerTile.block(), consumerTile.entity()));
|
||||
if(consumerTile.block().consumes.hasPower()){
|
||||
ConsumePower consumePower = consumerTile.block().consumes.getPower();
|
||||
assertFalse(consumePower.valid(consumerTile.entity()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user