Optimizations / Very broken changes
This commit is contained in:
@@ -287,11 +287,11 @@ public class UI implements ApplicationListener{
|
|||||||
|
|
||||||
public String formatAmount(int number){
|
public String formatAmount(int number){
|
||||||
if(number >= 1000000){
|
if(number >= 1000000){
|
||||||
return Strings.toFixed(number / 1000000f, 1) + "[gray]mil[]";
|
return Strings.fixed(number / 1000000f, 1) + "[gray]mil[]";
|
||||||
}else if(number >= 10000){
|
}else if(number >= 10000){
|
||||||
return number / 1000 + "[gray]k[]";
|
return number / 1000 + "[gray]k[]";
|
||||||
}else if(number >= 1000){
|
}else if(number >= 1000){
|
||||||
return Strings.toFixed(number / 1000f, 1) + "[gray]k[]";
|
return Strings.fixed(number / 1000f, 1) + "[gray]k[]";
|
||||||
}else{
|
}else{
|
||||||
return number + "";
|
return number + "";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ public class WaveInfoDialog extends FloatingDialog{
|
|||||||
}).width(80f);
|
}).width(80f);
|
||||||
|
|
||||||
a.add(" + ");
|
a.add(" + ");
|
||||||
a.addField(Strings.toFixed(Math.max((Mathf.isZero(group.unitScaling) ? 0 : 1f/group.unitScaling), 0), 2), TextFieldFilter.floatsOnly, text -> {
|
a.addField(Strings.fixed(Math.max((Mathf.isZero(group.unitScaling) ? 0 : 1f/group.unitScaling), 0), 2), TextFieldFilter.floatsOnly, text -> {
|
||||||
if(Strings.canParsePositiveFloat(text)){
|
if(Strings.canParsePositiveFloat(text)){
|
||||||
group.unitScaling = 1f / Strings.parseFloat(text);
|
group.unitScaling = 1f / Strings.parseFloat(text);
|
||||||
updateWaves();
|
updateWaves();
|
||||||
|
|||||||
@@ -5,17 +5,17 @@ import io.anuke.annotations.Annotations.Remote;
|
|||||||
import io.anuke.arc.Events;
|
import io.anuke.arc.Events;
|
||||||
import io.anuke.arc.collection.Array;
|
import io.anuke.arc.collection.Array;
|
||||||
import io.anuke.arc.collection.ObjectSet;
|
import io.anuke.arc.collection.ObjectSet;
|
||||||
import io.anuke.mindustry.entities.Effects;
|
|
||||||
import io.anuke.mindustry.entities.EntityGroup;
|
|
||||||
import io.anuke.mindustry.entities.impl.BaseEntity;
|
|
||||||
import io.anuke.mindustry.entities.traits.HealthTrait;
|
|
||||||
import io.anuke.arc.math.Mathf;
|
import io.anuke.arc.math.Mathf;
|
||||||
import io.anuke.arc.math.geom.Point2;
|
import io.anuke.arc.math.geom.Point2;
|
||||||
import io.anuke.arc.math.geom.Vector2;
|
import io.anuke.arc.math.geom.Vector2;
|
||||||
import io.anuke.arc.util.Interval;
|
import io.anuke.arc.util.Interval;
|
||||||
import io.anuke.arc.util.Time;
|
import io.anuke.arc.util.Time;
|
||||||
import io.anuke.mindustry.content.Fx;
|
import io.anuke.mindustry.content.Fx;
|
||||||
|
import io.anuke.mindustry.entities.Effects;
|
||||||
|
import io.anuke.mindustry.entities.EntityGroup;
|
||||||
import io.anuke.mindustry.entities.bullet.Bullet;
|
import io.anuke.mindustry.entities.bullet.Bullet;
|
||||||
|
import io.anuke.mindustry.entities.impl.BaseEntity;
|
||||||
|
import io.anuke.mindustry.entities.traits.HealthTrait;
|
||||||
import io.anuke.mindustry.entities.traits.TargetTrait;
|
import io.anuke.mindustry.entities.traits.TargetTrait;
|
||||||
import io.anuke.mindustry.game.EventType.BlockDestroyEvent;
|
import io.anuke.mindustry.game.EventType.BlockDestroyEvent;
|
||||||
import io.anuke.mindustry.game.Team;
|
import io.anuke.mindustry.game.Team;
|
||||||
@@ -24,7 +24,6 @@ import io.anuke.mindustry.world.Block;
|
|||||||
import io.anuke.mindustry.world.Edges;
|
import io.anuke.mindustry.world.Edges;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
import io.anuke.mindustry.world.blocks.defense.Wall;
|
import io.anuke.mindustry.world.blocks.defense.Wall;
|
||||||
import io.anuke.mindustry.world.consumers.Consume;
|
|
||||||
import io.anuke.mindustry.world.modules.ConsumeModule;
|
import io.anuke.mindustry.world.modules.ConsumeModule;
|
||||||
import io.anuke.mindustry.world.modules.ItemModule;
|
import io.anuke.mindustry.world.modules.ItemModule;
|
||||||
import io.anuke.mindustry.world.modules.LiquidModule;
|
import io.anuke.mindustry.world.modules.LiquidModule;
|
||||||
@@ -164,10 +163,6 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
|
|||||||
return tile;
|
return tile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean consumed(Class<? extends Consume> type){
|
|
||||||
return tile.block().consumes.get(type).valid(tile.block(), this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeFromProximity(){
|
public void removeFromProximity(){
|
||||||
tile.block().onProximityRemoved(tile);
|
tile.block().onProximityRemoved(tile);
|
||||||
|
|
||||||
|
|||||||
@@ -60,7 +60,9 @@ public class ContentDisplay{
|
|||||||
Array<StatValue> arr = map.get(stat);
|
Array<StatValue> arr = map.get(stat);
|
||||||
for(StatValue value : arr){
|
for(StatValue value : arr){
|
||||||
value.display(inset);
|
value.display(inset);
|
||||||
|
inset.add().size(10f);
|
||||||
}
|
}
|
||||||
|
|
||||||
//map.get(stat).display(inset);
|
//map.get(stat).display(inset);
|
||||||
}).fillX().padLeft(10);
|
}).fillX().padLeft(10);
|
||||||
table.row();
|
table.row();
|
||||||
@@ -201,7 +203,7 @@ public class ContentDisplay{
|
|||||||
|
|
||||||
table.add(Core.bundle.format("unit.health", unit.health));
|
table.add(Core.bundle.format("unit.health", unit.health));
|
||||||
table.row();
|
table.row();
|
||||||
table.add(Core.bundle.format("unit.speed", Strings.toFixed(unit.speed, 1)));
|
table.add(Core.bundle.format("unit.speed", Strings.fixed(unit.speed, 1)));
|
||||||
table.row();
|
table.row();
|
||||||
table.row();
|
table.row();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ public class ItemDisplay extends Table{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ItemDisplay(Item item, int amount){
|
public ItemDisplay(Item item, int amount){
|
||||||
add(new ItemImage(new ItemStack(item, amount))).size(8*3);
|
add(new ItemImage(new ItemStack(item, amount))).size(8*4);
|
||||||
add(item.localizedName()).padLeft(4);
|
add(item.localizedName()).padLeft(4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public class ItemImage extends Stack{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ItemImage(ItemStack stack){
|
public ItemImage(ItemStack stack){
|
||||||
add(new Image(stack.item.icon(Icon.medium)));
|
add(new Image(stack.item.icon(Icon.large)));
|
||||||
|
|
||||||
if(stack.amount != 0){
|
if(stack.amount != 0){
|
||||||
Table t = new Table().left().bottom();
|
Table t = new Table().left().bottom();
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import io.anuke.mindustry.type.Liquid;
|
|||||||
public class LiquidDisplay extends Table{
|
public class LiquidDisplay extends Table{
|
||||||
|
|
||||||
public LiquidDisplay(Liquid liquid){
|
public LiquidDisplay(Liquid liquid){
|
||||||
add(new Image(liquid.getContentIcon())).size(8*3);
|
add(new Image(liquid.getContentIcon())).size(8*4);
|
||||||
add(liquid.localizedName()).padLeft(3);
|
add(liquid.localizedName()).padLeft(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ public class LiquidDisplay extends Table{
|
|||||||
|
|
||||||
if(amount != 0){
|
if(amount != 0){
|
||||||
Table t = new Table().left().bottom();
|
Table t = new Table().left().bottom();
|
||||||
t.add(Strings.toFixed(amount, 2));
|
t.add(Strings.autoFixed(amount));
|
||||||
add(t);
|
add(t);
|
||||||
}
|
}
|
||||||
}}).size(8*4);
|
}}).size(8*4);
|
||||||
|
|||||||
@@ -187,9 +187,9 @@ public class BlockInventoryFragment extends Fragment{
|
|||||||
private String round(float f){
|
private String round(float f){
|
||||||
f = (int) f;
|
f = (int) f;
|
||||||
if(f >= 1000000){
|
if(f >= 1000000){
|
||||||
return Strings.toFixed(f / 1000000f, 1) + "[gray]mil[]";
|
return Strings.fixed(f / 1000000f, 1) + "[gray]mil[]";
|
||||||
}else if(f >= 1000){
|
}else if(f >= 1000){
|
||||||
return Strings.toFixed(f / 1000, 1) + "k";
|
return Strings.fixed(f / 1000, 1) + "k";
|
||||||
}else{
|
}else{
|
||||||
return (int) f + "";
|
return (int) f + "";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -395,7 +395,7 @@ public class Block extends BlockStorage{
|
|||||||
stats.add(BlockStat.size, "{0}x{0}", size);
|
stats.add(BlockStat.size, "{0}x{0}", size);
|
||||||
stats.add(BlockStat.health, health, StatUnit.none);
|
stats.add(BlockStat.health, health, StatUnit.none);
|
||||||
|
|
||||||
consumes.forEach(cons -> cons.display(stats));
|
consumes.display(stats);
|
||||||
|
|
||||||
// Note: Power stats are added by the consumers.
|
// Note: Power stats are added by the consumers.
|
||||||
if(hasLiquids) stats.add(BlockStat.liquidCapacity, liquidCapacity, StatUnit.liquidUnits);
|
if(hasLiquids) stats.add(BlockStat.liquidCapacity, liquidCapacity, StatUnit.liquidUnits);
|
||||||
|
|||||||
@@ -12,11 +12,7 @@ import io.anuke.mindustry.entities.type.TileEntity;
|
|||||||
import io.anuke.mindustry.entities.type.Unit;
|
import io.anuke.mindustry.entities.type.Unit;
|
||||||
import io.anuke.mindustry.game.UnlockableContent;
|
import io.anuke.mindustry.game.UnlockableContent;
|
||||||
import io.anuke.mindustry.type.Item;
|
import io.anuke.mindustry.type.Item;
|
||||||
import io.anuke.mindustry.type.ItemStack;
|
|
||||||
import io.anuke.mindustry.type.Liquid;
|
import io.anuke.mindustry.type.Liquid;
|
||||||
import io.anuke.mindustry.world.consumers.ConsumeItem;
|
|
||||||
import io.anuke.mindustry.world.consumers.ConsumeItems;
|
|
||||||
import io.anuke.mindustry.world.consumers.ConsumeLiquid;
|
|
||||||
import io.anuke.mindustry.world.consumers.Consumers;
|
import io.anuke.mindustry.world.consumers.Consumers;
|
||||||
import io.anuke.mindustry.world.meta.BlockBars;
|
import io.anuke.mindustry.world.meta.BlockBars;
|
||||||
import io.anuke.mindustry.world.meta.BlockStats;
|
import io.anuke.mindustry.world.meta.BlockStats;
|
||||||
@@ -27,7 +23,6 @@ public abstract class BlockStorage extends UnlockableContent{
|
|||||||
public boolean hasPower;
|
public boolean hasPower;
|
||||||
|
|
||||||
public boolean outputsLiquid = false;
|
public boolean outputsLiquid = false;
|
||||||
public boolean singleLiquid = true;
|
|
||||||
public boolean consumesPower = true;
|
public boolean consumesPower = true;
|
||||||
public boolean outputsPower = false;
|
public boolean outputsPower = false;
|
||||||
|
|
||||||
@@ -97,21 +92,11 @@ public abstract class BlockStorage extends UnlockableContent{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||||
if(tile.entity != null && consumes.has(ConsumeItems.class)){
|
return consumes.itemFilters[item.id] && tile.entity.items.get(item) < getMaximumAccepted(tile, item);
|
||||||
for(ItemStack stack : consumes.items()){
|
|
||||||
if(stack.item == item){
|
|
||||||
return tile.entity.items.get(item) < getMaximumAccepted(tile, item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return tile.entity != null && consumes.has(ConsumeItem.class) && consumes.item() == item &&
|
|
||||||
tile.entity.items.get(item) < getMaximumAccepted(tile, item);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
||||||
return hasLiquids && tile.entity.liquids.get(liquid) + amount < liquidCapacity &&
|
return hasLiquids && tile.entity.liquids.get(liquid) + amount < liquidCapacity && consumes.liquidfilters[liquid.id];
|
||||||
(!singleLiquid || (tile.entity.liquids.current() == liquid || tile.entity.liquids.get(tile.entity.liquids.current()) < 0.2f)) &&
|
|
||||||
(!consumes.has(ConsumeLiquid.class) || consumes.liquid() == liquid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
public void handleLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ public class LaserTurret extends PowerTurret{
|
|||||||
super(name);
|
super(name);
|
||||||
canOverdrive = false;
|
canOverdrive = false;
|
||||||
|
|
||||||
consumes.remove(ConsumeLiquidFilter.class);
|
|
||||||
consumes.add(new ConsumeLiquidFilter(liquid -> liquid.temperature <= 0.5f && liquid.flammability < 0.1f, 0.01f)).update(false);
|
consumes.add(new ConsumeLiquidFilter(liquid -> liquid.temperature <= 0.5f && liquid.flammability < 0.1f, 0.01f)).update(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package io.anuke.mindustry.world.blocks.power;
|
|||||||
import io.anuke.mindustry.type.Item;
|
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.consumers.ConsumeItem;
|
|
||||||
import io.anuke.mindustry.world.consumers.ConsumeLiquid;
|
import io.anuke.mindustry.world.consumers.ConsumeLiquid;
|
||||||
|
|
||||||
public class DifferentialGenerator extends TurbineGenerator{
|
public class DifferentialGenerator extends TurbineGenerator{
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public class ImpactReactor extends PowerGenerator{
|
|||||||
|
|
||||||
bars.add("poweroutput", entity -> new Bar(() ->
|
bars.add("poweroutput", entity -> new Bar(() ->
|
||||||
Core.bundle.format("blocks.poweroutput",
|
Core.bundle.format("blocks.poweroutput",
|
||||||
Strings.toFixed(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.get(ConsumePower.class).powerPerTick, 0)*60 * entity.delta(), 1)),
|
||||||
() -> Pal.powerBar,
|
() -> Pal.powerBar,
|
||||||
() -> ((GeneratorEntity)entity).productionEfficiency));
|
() -> ((GeneratorEntity)entity).productionEfficiency));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public class PowerGenerator extends PowerDistributor{
|
|||||||
if(hasPower && outputsPower && !consumes.has(ConsumePower.class)){
|
if(hasPower && outputsPower && !consumes.has(ConsumePower.class)){
|
||||||
bars.add("power", entity -> new Bar(() ->
|
bars.add("power", entity -> new Bar(() ->
|
||||||
Core.bundle.format("blocks.poweroutput",
|
Core.bundle.format("blocks.poweroutput",
|
||||||
Strings.toFixed(entity.tile.block().getPowerProduction(entity.tile)*60 * entity.timeScale, 1)),
|
Strings.fixed(entity.tile.block().getPowerProduction(entity.tile)*60 * entity.timeScale, 1)),
|
||||||
() -> Pal.powerBar,
|
() -> Pal.powerBar,
|
||||||
() -> ((GeneratorEntity)entity).productionEfficiency));
|
() -> ((GeneratorEntity)entity).productionEfficiency));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ public class PowerNode extends PowerBlock{
|
|||||||
super.setBars();
|
super.setBars();
|
||||||
bars.add("power", entity -> new Bar(() ->
|
bars.add("power", entity -> new Bar(() ->
|
||||||
Core.bundle.format("blocks.powerbalance",
|
Core.bundle.format("blocks.powerbalance",
|
||||||
((entity.power.graph.getPowerBalance() >= 0 ? "+" : "") + Strings.toFixed(entity.power.graph.getPowerBalance()*60, 1))),
|
((entity.power.graph.getPowerBalance() >= 0 ? "+" : "") + Strings.fixed(entity.power.graph.getPowerBalance()*60, 1))),
|
||||||
() -> Pal.powerBar,
|
() -> Pal.powerBar,
|
||||||
() -> Mathf.clamp(entity.power.graph.getPowerProduced() / entity.power.graph.getPowerNeeded())));
|
() -> Mathf.clamp(entity.power.graph.getPowerProduced() / entity.power.graph.getPowerNeeded())));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ public class ThermalGenerator extends PowerGenerator{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawPlace(int x, int y, int rotation, boolean valid){
|
public void drawPlace(int x, int y, int rotation, boolean valid){
|
||||||
drawPlaceText(Core.bundle.formatDouble("blocks.efficiency", sumAttribute(Attribute.heat, x, y)*100, 1), x, y, valid);
|
drawPlaceText(Core.bundle.formatFloat("blocks.efficiency", sumAttribute(Attribute.heat, x, y)*100, 1), x, y, valid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ public class Cultivator extends GenericCrafter{
|
|||||||
public void setBars(){
|
public void setBars(){
|
||||||
super.setBars();
|
super.setBars();
|
||||||
bars.add("multiplier", entity -> new Bar(() ->
|
bars.add("multiplier", entity -> new Bar(() ->
|
||||||
Core.bundle.formatDouble("blocks.efficiency",
|
Core.bundle.formatFloat("blocks.efficiency",
|
||||||
((((CultivatorEntity)entity).boost + 1f) * ((CultivatorEntity)entity).warmup)*100f,1),
|
((((CultivatorEntity)entity).boost + 1f) * ((CultivatorEntity)entity).warmup)*100f,1),
|
||||||
() -> Pal.ammo,
|
() -> Pal.ammo,
|
||||||
() -> ((CultivatorEntity)entity).warmup));
|
() -> ((CultivatorEntity)entity).warmup));
|
||||||
@@ -61,7 +61,7 @@ public class Cultivator extends GenericCrafter{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawPlace(int x, int y, int rotation, boolean valid){
|
public void drawPlace(int x, int y, int rotation, boolean valid){
|
||||||
drawPlaceText(Core.bundle.formatDouble("blocks.efficiency", (1+sumAttribute(Attribute.spores, x, y))*100, 1), x, y, valid);
|
drawPlaceText(Core.bundle.formatFloat("blocks.efficiency", (1+sumAttribute(Attribute.spores, x, y))*100, 1), x, y, valid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ public class Drill extends Block{
|
|||||||
bars.add("drillspeed", e -> {
|
bars.add("drillspeed", e -> {
|
||||||
DrillEntity entity = (DrillEntity)e;
|
DrillEntity entity = (DrillEntity)e;
|
||||||
|
|
||||||
return new Bar(() -> Core.bundle.format("blocks.outputspeed", Strings.toFixed(entity.lastDrillSpeed * 60 * entity.timeScale, 2)), () -> Pal.ammo, () -> entity.warmup);
|
return new Bar(() -> Core.bundle.format("blocks.outputspeed", Strings.fixed(entity.lastDrillSpeed * 60 * entity.timeScale, 2)), () -> Pal.ammo, () -> entity.warmup);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import io.anuke.arc.graphics.g2d.TextureRegion;
|
|||||||
import io.anuke.mindustry.entities.type.TileEntity;
|
import io.anuke.mindustry.entities.type.TileEntity;
|
||||||
import io.anuke.mindustry.type.Item;
|
import io.anuke.mindustry.type.Item;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
import io.anuke.mindustry.world.consumers.ConsumeItem;
|
|
||||||
import io.anuke.arc.graphics.g2d.Draw;
|
import io.anuke.arc.graphics.g2d.Draw;
|
||||||
|
|
||||||
public class Fracker extends SolidPump{
|
public class Fracker extends SolidPump{
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import io.anuke.mindustry.type.ItemStack;
|
|||||||
import io.anuke.mindustry.type.LiquidStack;
|
import io.anuke.mindustry.type.LiquidStack;
|
||||||
import io.anuke.mindustry.world.Block;
|
import io.anuke.mindustry.world.Block;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
|
import io.anuke.mindustry.world.consumers.ConsumeType;
|
||||||
import io.anuke.mindustry.world.meta.BlockStat;
|
import io.anuke.mindustry.world.meta.BlockStat;
|
||||||
import io.anuke.mindustry.world.meta.StatUnit;
|
import io.anuke.mindustry.world.meta.StatUnit;
|
||||||
|
|
||||||
@@ -47,6 +48,11 @@ public class GenericCrafter extends Block{
|
|||||||
super.setStats();
|
super.setStats();
|
||||||
stats.add(BlockStat.productionTime, craftTime / 60f, StatUnit.seconds);
|
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){
|
if(outputItem != null){
|
||||||
stats.add(BlockStat.output, outputItem);
|
stats.add(BlockStat.output, outputItem);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import io.anuke.mindustry.type.ItemStack;
|
|||||||
import io.anuke.mindustry.world.Block;
|
import io.anuke.mindustry.world.Block;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
import io.anuke.mindustry.world.blocks.production.GenericCrafter.GenericCrafterEntity;
|
import io.anuke.mindustry.world.blocks.production.GenericCrafter.GenericCrafterEntity;
|
||||||
import io.anuke.mindustry.world.consumers.ConsumeItem;
|
|
||||||
import io.anuke.mindustry.world.meta.BlockStat;
|
import io.anuke.mindustry.world.meta.BlockStat;
|
||||||
import io.anuke.mindustry.world.meta.values.ItemFilterValue;
|
import io.anuke.mindustry.world.meta.values.ItemFilterValue;
|
||||||
|
|
||||||
@@ -99,9 +98,7 @@ public class Separator extends Block{
|
|||||||
count += stack.amount;
|
count += stack.amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(consumes.has(ConsumeItem.class)){
|
entity.cons.trigger();
|
||||||
entity.items.remove(consumes.item(), consumes.itemAmount());
|
|
||||||
}
|
|
||||||
|
|
||||||
if(item != null && entity.items.get(item) < itemCapacity){
|
if(item != null && entity.items.get(item) < itemCapacity){
|
||||||
offloadNear(tile, item);
|
offloadNear(tile, item);
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ public class SolidPump extends Pump{
|
|||||||
@Override
|
@Override
|
||||||
public void drawPlace(int x, int y, int rotation, boolean valid){
|
public void drawPlace(int x, int y, int rotation, boolean valid){
|
||||||
if(attribute != null){
|
if(attribute != null){
|
||||||
drawPlaceText(Core.bundle.formatDouble("blocks.efficiency", (sumAttribute(attribute, x, y) + 1f)*100, 1), x, y, valid);
|
drawPlaceText(Core.bundle.formatFloat("blocks.efficiency", (sumAttribute(attribute, x, y) + 1f)*100, 1), x, y, valid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ public class SolidPump extends Pump{
|
|||||||
public void setBars(){
|
public void setBars(){
|
||||||
super.setBars();
|
super.setBars();
|
||||||
bars.add("efficiency", entity -> new Bar(() ->
|
bars.add("efficiency", entity -> new Bar(() ->
|
||||||
Core.bundle.formatDouble("blocks.efficiency",
|
Core.bundle.formatFloat("blocks.efficiency",
|
||||||
((((SolidPumpEntity)entity).boost + 1f) * ((SolidPumpEntity)entity).warmup) * 100, 1),
|
((((SolidPumpEntity)entity).boost + 1f) * ((SolidPumpEntity)entity).warmup) * 100, 1),
|
||||||
() -> Pal.ammo,
|
() -> Pal.ammo,
|
||||||
() -> ((SolidPumpEntity)entity).warmup));
|
() -> ((SolidPumpEntity)entity).warmup));
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ public class UnitFactory extends Block{
|
|||||||
|
|
||||||
if(!tile.isEnemyCheat()){
|
if(!tile.isEnemyCheat()){
|
||||||
//player-made spawners have default behavior
|
//player-made spawners have default behavior
|
||||||
if(hasRequirements(entity.items, entity.buildTime / produceTime) && entity.cons.valid()){
|
if(entity.cons.valid()){
|
||||||
entity.time += entity.delta() * entity.speedScl;
|
entity.time += entity.delta() * entity.speedScl;
|
||||||
entity.buildTime += entity.delta() * entity.power.satisfaction;
|
entity.buildTime += entity.delta() * entity.power.satisfaction;
|
||||||
entity.speedScl = Mathf.lerpDelta(entity.speedScl, 1f, 0.05f);
|
entity.speedScl = Mathf.lerpDelta(entity.speedScl, 1f, 0.05f);
|
||||||
@@ -186,9 +186,7 @@ public class UnitFactory extends Block{
|
|||||||
Call.onUnitFactorySpawn(tile, entity.spawned + 1);
|
Call.onUnitFactorySpawn(tile, entity.spawned + 1);
|
||||||
useContent(tile, type);
|
useContent(tile, type);
|
||||||
|
|
||||||
for(ItemStack stack : consumes.items()){
|
entity.cons.trigger();
|
||||||
entity.items.remove(stack.item, stack.amount);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,15 +221,6 @@ public class UnitFactory extends Block{
|
|||||||
return entity.spawned < maxSpawn;
|
return entity.spawned < maxSpawn;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean hasRequirements(ItemModule inv, float fraction){
|
|
||||||
for(ItemStack stack : consumes.items()){
|
|
||||||
if(!inv.has(stack.item, (int) (fraction * stack.amount))){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class UnitFactoryEntity extends TileEntity{
|
public static class UnitFactoryEntity extends TileEntity{
|
||||||
public float buildTime;
|
public float buildTime;
|
||||||
public float time;
|
public float time;
|
||||||
|
|||||||
@@ -11,6 +11,18 @@ public abstract class Consume{
|
|||||||
protected boolean optional;
|
protected boolean optional;
|
||||||
protected boolean update = true, boost = false;
|
protected boolean update = true, boost = false;
|
||||||
|
|
||||||
|
/**Apply a filter to items accepted.
|
||||||
|
* This should set all item IDs that are present in the filter to true.*/
|
||||||
|
public void applyItemFilter(boolean[] filter){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**Apply a filter to liquids accepted.
|
||||||
|
* This should set all liquid IDs that are present in the filter to true.*/
|
||||||
|
public void applyLiquidFilter(boolean[] filter){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public Consume optional(boolean optional){
|
public Consume optional(boolean optional){
|
||||||
this.optional = optional;
|
this.optional = optional;
|
||||||
return this;
|
return this;
|
||||||
@@ -34,6 +46,8 @@ public abstract class Consume{
|
|||||||
return update;
|
return update;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract ConsumeType type();
|
||||||
|
|
||||||
public abstract void build(Tile tile, Table table);
|
public abstract void build(Tile tile, Table table);
|
||||||
|
|
||||||
/**Called when a consumption is triggered manually.*/
|
/**Called when a consumption is triggered manually.*/
|
||||||
|
|||||||
@@ -1,66 +0,0 @@
|
|||||||
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.Item;
|
|
||||||
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;
|
|
||||||
|
|
||||||
public class ConsumeItem extends Consume{
|
|
||||||
private final Item item;
|
|
||||||
private final int amount;
|
|
||||||
|
|
||||||
public ConsumeItem(Item item){
|
|
||||||
this.item = item;
|
|
||||||
this.amount = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConsumeItem(Item item, int amount){
|
|
||||||
this.item = item;
|
|
||||||
this.amount = amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getAmount(){
|
|
||||||
return amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Item get(){
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void trigger(Block block, TileEntity entity){
|
|
||||||
entity.items.remove(item, amount);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void build(Tile tile, Table table){
|
|
||||||
table.add(new ReqImage(new ItemImage(item.icon(Icon.large), amount), () -> valid(tile.block(), tile.entity))).size(8*4);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getIcon(){
|
|
||||||
return "icon-item";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void update(Block block, TileEntity entity){
|
|
||||||
//doesn't update because consuming items is very specific
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean valid(Block block, TileEntity entity){
|
|
||||||
return entity != null && entity.items != null && entity.items.has(item, amount);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void display(BlockStats stats){
|
|
||||||
stats.add(boost ? BlockStat.booster : BlockStat.input, new ItemStack(item, amount));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -24,6 +24,16 @@ public class ConsumeItemFilter extends Consume{
|
|||||||
this.filter = item;
|
this.filter = item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void applyItemFilter(boolean[] arr){
|
||||||
|
content.items().each(filter, item -> arr[item.id] = true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConsumeType type(){
|
||||||
|
return ConsumeType.item;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void build(Tile tile, Table table){
|
public void build(Tile tile, Table table){
|
||||||
Array<Item> list = content.items().select(filter);
|
Array<Item> list = content.items().select(filter);
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import io.anuke.mindustry.world.meta.BlockStats;
|
|||||||
import io.anuke.mindustry.world.meta.values.ItemListValue;
|
import io.anuke.mindustry.world.meta.values.ItemListValue;
|
||||||
|
|
||||||
public class ConsumeItems extends Consume{
|
public class ConsumeItems extends Consume{
|
||||||
private ItemStack[] items;
|
private final ItemStack[] items;
|
||||||
|
|
||||||
public ConsumeItems(ItemStack[] items){
|
public ConsumeItems(ItemStack[] items){
|
||||||
this.items = items;
|
this.items = items;
|
||||||
@@ -23,6 +23,18 @@ public class ConsumeItems extends Consume{
|
|||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void applyItemFilter(boolean[] filter){
|
||||||
|
for(ItemStack stack : items){
|
||||||
|
filter[stack.item.id] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConsumeType type(){
|
||||||
|
return ConsumeType.item;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void build(Tile tile, Table table){
|
public void build(Tile tile, Table table){
|
||||||
for(ItemStack stack : items){
|
for(ItemStack stack : items){
|
||||||
|
|||||||
@@ -3,12 +3,12 @@ package io.anuke.mindustry.world.consumers;
|
|||||||
import io.anuke.arc.scene.ui.layout.Table;
|
import io.anuke.arc.scene.ui.layout.Table;
|
||||||
import io.anuke.mindustry.entities.type.TileEntity;
|
import io.anuke.mindustry.entities.type.TileEntity;
|
||||||
import io.anuke.mindustry.type.Liquid;
|
import io.anuke.mindustry.type.Liquid;
|
||||||
|
import io.anuke.mindustry.type.LiquidStack;
|
||||||
import io.anuke.mindustry.ui.ReqImage;
|
import io.anuke.mindustry.ui.ReqImage;
|
||||||
import io.anuke.mindustry.world.Block;
|
import io.anuke.mindustry.world.Block;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
import io.anuke.mindustry.world.meta.BlockStat;
|
import io.anuke.mindustry.world.meta.BlockStat;
|
||||||
import io.anuke.mindustry.world.meta.BlockStats;
|
import io.anuke.mindustry.world.meta.BlockStats;
|
||||||
import io.anuke.mindustry.world.meta.StatUnit;
|
|
||||||
|
|
||||||
public class ConsumeLiquid extends Consume{
|
public class ConsumeLiquid extends Consume{
|
||||||
protected final float use;
|
protected final float use;
|
||||||
@@ -19,6 +19,11 @@ public class ConsumeLiquid extends Consume{
|
|||||||
this.use = use;
|
this.use = use;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void applyLiquidFilter(boolean[] filter){
|
||||||
|
filter[liquid.id] = true;
|
||||||
|
}
|
||||||
|
|
||||||
public float used(){
|
public float used(){
|
||||||
return use;
|
return use;
|
||||||
}
|
}
|
||||||
@@ -27,6 +32,11 @@ public class ConsumeLiquid extends Consume{
|
|||||||
return liquid;
|
return liquid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConsumeType type(){
|
||||||
|
return ConsumeType.liquid;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void build(Tile tile, Table table){
|
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.block(), tile.entity))).size(8*4);
|
||||||
@@ -49,12 +59,8 @@ public class ConsumeLiquid extends Consume{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void display(BlockStats stats){
|
public void display(BlockStats stats){
|
||||||
if(!boost){
|
//stats.add(BlockStat.liquidUse, use * 60f, StatUnit.liquidSecond);
|
||||||
stats.add(BlockStat.liquidUse, use * 60f, StatUnit.liquidSecond);
|
stats.add(boost ? BlockStat.booster : BlockStat.input, new LiquidStack(liquid, use * 60f));
|
||||||
stats.add(BlockStat.input, liquid);
|
|
||||||
}else{
|
|
||||||
stats.add(BlockStat.booster, liquid);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float use(Block block, TileEntity entity){
|
float use(Block block, TileEntity entity){
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import io.anuke.mindustry.world.Block;
|
|||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
import io.anuke.mindustry.world.meta.BlockStat;
|
import io.anuke.mindustry.world.meta.BlockStat;
|
||||||
import io.anuke.mindustry.world.meta.BlockStats;
|
import io.anuke.mindustry.world.meta.BlockStats;
|
||||||
import io.anuke.mindustry.world.meta.StatUnit;
|
|
||||||
import io.anuke.mindustry.world.meta.values.LiquidFilterValue;
|
import io.anuke.mindustry.world.meta.values.LiquidFilterValue;
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.content;
|
import static io.anuke.mindustry.Vars.content;
|
||||||
@@ -25,6 +24,16 @@ public class ConsumeLiquidFilter extends Consume{
|
|||||||
this.use = amount;
|
this.use = amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void applyLiquidFilter(boolean[] arr){
|
||||||
|
content.liquids().each(filter, item -> arr[item.id] = true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConsumeType type(){
|
||||||
|
return ConsumeType.liquid;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void build(Tile tile, Table table){
|
public void build(Tile tile, Table table){
|
||||||
Array<Liquid> list = content.liquids().select(l -> !l.isHidden() && filter.test(l));
|
Array<Liquid> list = content.liquids().select(l -> !l.isHidden() && filter.test(l));
|
||||||
@@ -51,12 +60,7 @@ public class ConsumeLiquidFilter extends Consume{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void display(BlockStats stats){
|
public void display(BlockStats stats){
|
||||||
if(boost){
|
stats.add(boost ? BlockStat.booster : BlockStat.input, new LiquidFilterValue(filter, use * 60f));
|
||||||
stats.add(BlockStat.booster, new LiquidFilterValue(filter));
|
|
||||||
}else {
|
|
||||||
stats.add(BlockStat.input, new LiquidFilterValue(filter));
|
|
||||||
stats.add(BlockStat.liquidUse, 60f * use, StatUnit.liquidSecond);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float use(Block block, TileEntity entity){
|
float use(Block block, TileEntity entity){
|
||||||
|
|||||||
@@ -24,6 +24,11 @@ public class ConsumePower extends Consume{
|
|||||||
this.isBuffered = isBuffered;
|
this.isBuffered = isBuffered;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConsumeType type(){
|
||||||
|
return ConsumeType.power;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void build(Tile tile, Table table){
|
public void build(Tile tile, Table table){
|
||||||
//No tooltip for power, for now
|
//No tooltip for power, for now
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package io.anuke.mindustry.world.consumers;
|
||||||
|
|
||||||
|
public enum ConsumeType{
|
||||||
|
item,
|
||||||
|
power,
|
||||||
|
liquid
|
||||||
|
}
|
||||||
@@ -1,39 +1,51 @@
|
|||||||
package io.anuke.mindustry.world.consumers;
|
package io.anuke.mindustry.world.consumers;
|
||||||
|
|
||||||
import io.anuke.arc.collection.Array;
|
import io.anuke.arc.collection.Array;
|
||||||
import io.anuke.arc.collection.ObjectMap;
|
|
||||||
import io.anuke.arc.collection.ObjectSet;
|
import io.anuke.arc.collection.ObjectSet;
|
||||||
import io.anuke.arc.function.Consumer;
|
import io.anuke.arc.util.Log;
|
||||||
|
import io.anuke.mindustry.Vars;
|
||||||
import io.anuke.mindustry.type.Item;
|
import io.anuke.mindustry.type.Item;
|
||||||
import io.anuke.mindustry.type.ItemStack;
|
import io.anuke.mindustry.type.ItemStack;
|
||||||
import io.anuke.mindustry.type.Liquid;
|
import io.anuke.mindustry.type.Liquid;
|
||||||
import io.anuke.mindustry.world.Block;
|
import io.anuke.mindustry.world.Block;
|
||||||
|
import io.anuke.mindustry.world.meta.BlockStats;
|
||||||
|
|
||||||
public class Consumers{
|
public class Consumers{
|
||||||
private ObjectMap<Class<? extends Consume>, Consume> map = new ObjectMap<>();
|
private Consume[] map = new Consume[ConsumeType.values().length];
|
||||||
private ObjectSet<Class<? extends Consume>> required = new ObjectSet<>();
|
private ObjectSet<ConsumeType> required = new ObjectSet<>();
|
||||||
private Array<Consume> results = new Array<>();
|
private Consume[] results;
|
||||||
|
|
||||||
public void require(Class<? extends Consume> type){
|
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);
|
required.add(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkRequired(Block block){
|
public void checkRequired(Block block){
|
||||||
for(Class<? extends Consume> c : required){
|
for(ConsumeType c : required){
|
||||||
if(!map.containsKey(c)){
|
if(!has(c)){
|
||||||
throw new RuntimeException("Missing required consumer of type \"" + c + "\" in block \"" + block.name + "\"!");
|
throw new RuntimeException("Missing required consumer of type \"" + c + "\" in block \"" + block.name + "\"!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(Consume cons : map.values()){
|
Array<Consume> array = new Array<>(Consume.class);
|
||||||
results.add(cons);
|
for(Consume cons : map){
|
||||||
|
if(cons != null){
|
||||||
|
array.add(cons);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
results = array.toArray();
|
||||||
|
|
||||||
|
for(Consume cons : all()){
|
||||||
|
cons.applyItemFilter(itemFilters);
|
||||||
|
cons.applyLiquidFilter(liquidfilters);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConsumeLiquid liquid(Liquid liquid, float amount){
|
public ConsumeLiquid liquid(Liquid liquid, float amount){
|
||||||
ConsumeLiquid c = new ConsumeLiquid(liquid, amount);
|
return add(new ConsumeLiquid(liquid, amount));
|
||||||
add(c);
|
|
||||||
return c;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,9 +54,7 @@ public class Consumers{
|
|||||||
* @return the created consumer object.
|
* @return the created consumer object.
|
||||||
*/
|
*/
|
||||||
public ConsumePower power(float powerPerTick){
|
public ConsumePower power(float powerPerTick){
|
||||||
ConsumePower c = new ConsumePower(powerPerTick, 0.0f, false);
|
return add(new ConsumePower(powerPerTick, 0.0f, false));
|
||||||
add(c);
|
|
||||||
return c;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -62,83 +72,55 @@ public class Consumers{
|
|||||||
* @param ticksToFill The number of ticks it shall take to fill the buffer.
|
* @param ticksToFill The number of ticks it shall take to fill the buffer.
|
||||||
*/
|
*/
|
||||||
public ConsumePower powerBuffered(float powerCapacity, float ticksToFill){
|
public ConsumePower powerBuffered(float powerCapacity, float ticksToFill){
|
||||||
ConsumePower c = new ConsumePower(powerCapacity / ticksToFill, powerCapacity, true);
|
return add(new ConsumePower(powerCapacity / ticksToFill, powerCapacity, true));
|
||||||
add(c);
|
|
||||||
return c;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConsumeItem item(Item item){
|
public ConsumeItems item(Item item){
|
||||||
return item(item, 1);
|
return item(item, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConsumeItem item(Item item, int amount){
|
public ConsumeItems item(Item item, int amount){
|
||||||
ConsumeItem i = new ConsumeItem(item, amount);
|
return add(new ConsumeItems(new ItemStack[]{new ItemStack(item, amount)}));
|
||||||
add(i);
|
|
||||||
return i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConsumeItems items(ItemStack... items){
|
public ConsumeItems items(ItemStack... items){
|
||||||
ConsumeItems i = new ConsumeItems(items);
|
return add(new ConsumeItems(items));
|
||||||
add(i);
|
|
||||||
return i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Item item(){
|
public <T extends Consume> T add(T consume){
|
||||||
return get(ConsumeItem.class).get();
|
if(map[consume.type().ordinal()] != null){
|
||||||
}
|
Log.warn("[WARN] Conflict: Replacing {0} with {1}", consume, map[consume.type().ordinal()]);
|
||||||
|
}
|
||||||
|
|
||||||
public ItemStack[] items(){
|
map[consume.type().ordinal()] = consume;
|
||||||
return get(ConsumeItems.class).getItems();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int itemAmount(){
|
|
||||||
return get(ConsumeItem.class).getAmount();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Liquid liquid(){
|
|
||||||
return get(ConsumeLiquid.class).get();
|
|
||||||
}
|
|
||||||
|
|
||||||
public float liquidAmount(){
|
|
||||||
return get(ConsumeLiquid.class).use;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Consume add(Consume consume){
|
|
||||||
map.put((consume instanceof ConsumePower ? ConsumePower.class : consume.getClass()), consume);
|
|
||||||
return consume;
|
return consume;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(Class<? extends Consume> type){
|
public void remove(ConsumeType type){
|
||||||
map.remove(type);
|
map[type.ordinal()] = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean has(Class<? extends Consume> type){
|
public boolean has(ConsumeType type){
|
||||||
return map.containsKey(type);
|
return map[type.ordinal()] != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <T extends Consume> T get(Class<T> type){
|
public <T extends Consume> T get(ConsumeType type){
|
||||||
if(!map.containsKey(type)){
|
if(map[type.ordinal()] == null){
|
||||||
throw new IllegalArgumentException("Block does not contain consumer of type '" + type + "'!");
|
throw new IllegalArgumentException("Block does not contain consumer of type '" + type + "'!");
|
||||||
}
|
}
|
||||||
return (T) map.get(type);
|
return (T) map[type.ordinal()];
|
||||||
}
|
}
|
||||||
|
|
||||||
public Iterable<Consume> all(){
|
public Consume[] all(){
|
||||||
return map.values();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Array<Consume> array(){
|
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasAny(){
|
public void display(BlockStats stats){
|
||||||
return map.size > 0;
|
for(Consume c : map){
|
||||||
}
|
if(c != null){
|
||||||
|
c.display(stats);
|
||||||
public void forEach(Consumer<Consume> cons){
|
}
|
||||||
for(Consume c : all()){
|
|
||||||
cons.accept(c);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ public class BlockStats{
|
|||||||
|
|
||||||
/**Adds an item value.*/
|
/**Adds an item value.*/
|
||||||
public void add(BlockStat stat, Item item){
|
public void add(BlockStat stat, Item item){
|
||||||
add(stat, new ItemValue(new ItemStack(item, 1)));
|
add(stat, new ItemListValue(new ItemStack(item, 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**Adds a liquid value.*/
|
/**Adds a liquid value.*/
|
||||||
@@ -36,7 +36,7 @@ public class BlockStats{
|
|||||||
|
|
||||||
/**Adds an item value.*/
|
/**Adds an item value.*/
|
||||||
public void add(BlockStat stat, ItemStack item){
|
public void add(BlockStat stat, ItemStack item){
|
||||||
add(stat, new ItemValue(item));
|
add(stat, new ItemListValue(item));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**Adds an item value.*/
|
/**Adds an item value.*/
|
||||||
@@ -51,10 +51,6 @@ public class BlockStats{
|
|||||||
|
|
||||||
/**Adds a stat value.*/
|
/**Adds a stat value.*/
|
||||||
public void add(BlockStat stat, StatValue value){
|
public void add(BlockStat stat, StatValue value){
|
||||||
//if(map.containsKey(stat.category) && map.get(stat.category).containsKey(stat)){
|
|
||||||
// throw new RuntimeException("Duplicate stat entry: \"" + stat + "\" in block.");
|
|
||||||
//}
|
|
||||||
|
|
||||||
if(!map.containsKey(stat.category)){
|
if(!map.containsKey(stat.category)){
|
||||||
map.put(stat.category, new OrderedMap<>());
|
map.put(stat.category, new OrderedMap<>());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
package io.anuke.mindustry.world.meta;
|
|
||||||
|
|
||||||
import io.anuke.mindustry.game.UnlockableContent;
|
|
||||||
|
|
||||||
public interface ContentStatValue extends StatValue{
|
|
||||||
UnlockableContent[] getValueContent();
|
|
||||||
}
|
|
||||||
@@ -35,14 +35,14 @@ public class AmmoListValue<T extends UnlockableContent> implements StatValue{
|
|||||||
bt.add(Core.bundle.format("bullet.damage", type.damage));
|
bt.add(Core.bundle.format("bullet.damage", type.damage));
|
||||||
|
|
||||||
if(type.splashDamage > 0){
|
if(type.splashDamage > 0){
|
||||||
sep(bt, Core.bundle.format("bullet.splashdamage", (int)type.splashDamage, Strings.toFixed(type.splashDamageRadius / tilesize, 1)));
|
sep(bt, Core.bundle.format("bullet.splashdamage", (int)type.splashDamage, Strings.fixed(type.splashDamageRadius / tilesize, 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!Mathf.isEqual(type.ammoMultiplier, 1f)) sep(bt, Core.bundle.format("bullet.multiplier", (int)type.ammoMultiplier));
|
if(!Mathf.isEqual(type.ammoMultiplier, 1f)) sep(bt, Core.bundle.format("bullet.multiplier", (int)type.ammoMultiplier));
|
||||||
if(!Mathf.isEqual(type.reloadMultiplier, 1f)) sep(bt, Core.bundle.format("bullet.reload", Strings.toFixed(type.reloadMultiplier, 1)));
|
if(!Mathf.isEqual(type.reloadMultiplier, 1f)) sep(bt, Core.bundle.format("bullet.reload", Strings.fixed(type.reloadMultiplier, 1)));
|
||||||
|
|
||||||
if(type.knockback > 0){
|
if(type.knockback > 0){
|
||||||
sep(bt, Core.bundle.format("bullet.knockback", Strings.toFixed(type.knockback, 1)));
|
sep(bt, Core.bundle.format("bullet.knockback", Strings.fixed(type.knockback, 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if((type.status == StatusEffects.burning || type.status == StatusEffects.melting) || type.incendAmount > 0){
|
if((type.status == StatusEffects.burning || type.status == StatusEffects.melting) || type.incendAmount > 0){
|
||||||
|
|||||||
@@ -1,49 +1,21 @@
|
|||||||
package io.anuke.mindustry.world.meta.values;
|
package io.anuke.mindustry.world.meta.values;
|
||||||
|
|
||||||
import io.anuke.mindustry.game.UnlockableContent;
|
import io.anuke.arc.scene.ui.layout.Table;
|
||||||
import io.anuke.mindustry.type.Item;
|
|
||||||
import io.anuke.mindustry.type.ItemStack;
|
import io.anuke.mindustry.type.ItemStack;
|
||||||
import io.anuke.mindustry.ui.ItemDisplay;
|
import io.anuke.mindustry.ui.ItemDisplay;
|
||||||
import io.anuke.mindustry.world.meta.ContentStatValue;
|
import io.anuke.mindustry.world.meta.StatValue;
|
||||||
import io.anuke.arc.scene.ui.layout.Table;
|
|
||||||
|
|
||||||
public class ItemListValue implements ContentStatValue{
|
public class ItemListValue implements StatValue{
|
||||||
private final Item[] items;
|
|
||||||
private final ItemStack[] stacks;
|
private final ItemStack[] stacks;
|
||||||
|
|
||||||
public ItemListValue(Item[] items){
|
public ItemListValue(ItemStack... stacks){
|
||||||
this.items = items;
|
|
||||||
this.stacks = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemListValue(ItemStack[] stacks){
|
|
||||||
this.stacks = stacks;
|
this.stacks = stacks;
|
||||||
this.items = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public UnlockableContent[] getValueContent(){
|
|
||||||
if(items != null){
|
|
||||||
return items;
|
|
||||||
}else{
|
|
||||||
Item[] res = new Item[stacks.length];
|
|
||||||
for(int i = 0; i < res.length; i++){
|
|
||||||
res[i] = stacks[i].item;
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void display(Table table){
|
public void display(Table table){
|
||||||
if(items != null){
|
for(ItemStack stack : stacks){
|
||||||
for(Item item : items){
|
table.add(new ItemDisplay(stack.item, stack.amount)).padRight(5);
|
||||||
table.add(new ItemDisplay(item)).padRight(5);
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
for(ItemStack stack : stacks){
|
|
||||||
table.add(new ItemDisplay(stack.item, stack.amount)).padRight(5);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
package io.anuke.mindustry.world.meta.values;
|
|
||||||
|
|
||||||
import io.anuke.mindustry.game.UnlockableContent;
|
|
||||||
import io.anuke.mindustry.type.Item;
|
|
||||||
import io.anuke.mindustry.type.ItemStack;
|
|
||||||
import io.anuke.mindustry.ui.ItemDisplay;
|
|
||||||
import io.anuke.mindustry.world.meta.ContentStatValue;
|
|
||||||
import io.anuke.arc.scene.ui.layout.Table;
|
|
||||||
|
|
||||||
public class ItemValue implements ContentStatValue{
|
|
||||||
private final ItemStack item;
|
|
||||||
|
|
||||||
public ItemValue(ItemStack item){
|
|
||||||
this.item = item;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public UnlockableContent[] getValueContent(){
|
|
||||||
return new Item[]{item.item};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void display(Table table){
|
|
||||||
table.add(new ItemDisplay(item.item, item.amount));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -11,9 +11,11 @@ import static io.anuke.mindustry.Vars.content;
|
|||||||
|
|
||||||
public class LiquidFilterValue implements StatValue{
|
public class LiquidFilterValue implements StatValue{
|
||||||
private final Predicate<Liquid> filter;
|
private final Predicate<Liquid> filter;
|
||||||
|
private final float amount;
|
||||||
|
|
||||||
public LiquidFilterValue(Predicate<Liquid> filter){
|
public LiquidFilterValue(Predicate<Liquid> filter, float amount){
|
||||||
this.filter = filter;
|
this.filter = filter;
|
||||||
|
this.amount = amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -25,7 +27,7 @@ public class LiquidFilterValue implements StatValue{
|
|||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < list.size; i++){
|
for(int i = 0; i < list.size; i++){
|
||||||
table.add(new LiquidDisplay(list.get(i))).padRight(5);
|
table.add(new LiquidDisplay(list.get(i), amount)).padRight(5);
|
||||||
|
|
||||||
if(i != list.size - 1){
|
if(i != list.size - 1){
|
||||||
table.add("/");
|
table.add("/");
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
package io.anuke.mindustry.world.meta.values;
|
package io.anuke.mindustry.world.meta.values;
|
||||||
|
|
||||||
import io.anuke.mindustry.game.UnlockableContent;
|
import io.anuke.arc.scene.ui.layout.Table;
|
||||||
import io.anuke.mindustry.type.Liquid;
|
import io.anuke.mindustry.type.Liquid;
|
||||||
import io.anuke.mindustry.ui.LiquidDisplay;
|
import io.anuke.mindustry.ui.LiquidDisplay;
|
||||||
import io.anuke.mindustry.world.meta.ContentStatValue;
|
import io.anuke.mindustry.world.meta.StatValue;
|
||||||
import io.anuke.arc.scene.ui.layout.Table;
|
|
||||||
|
|
||||||
public class LiquidValue implements ContentStatValue{
|
public class LiquidValue implements StatValue{
|
||||||
private final Liquid liquid;
|
private final Liquid liquid;
|
||||||
private final float amount;
|
private final float amount;
|
||||||
|
|
||||||
@@ -19,11 +18,6 @@ public class LiquidValue implements ContentStatValue{
|
|||||||
this(liquid, 0f);
|
this(liquid, 0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public UnlockableContent[] getValueContent(){
|
|
||||||
return new UnlockableContent[]{liquid};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void display(Table table){
|
public void display(Table table){
|
||||||
table.add(new LiquidDisplay(liquid, amount));
|
table.add(new LiquidDisplay(liquid, amount));
|
||||||
|
|||||||
@@ -20,10 +20,9 @@ public class NumberValue implements StatValue{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void display(Table table){
|
public void display(Table table){
|
||||||
float diff = Math.abs((int) value - value);
|
int precision = Math.abs((int) value - value) <= 0.001f ? 0 : Math.abs((int) (value * 10) - value * 10) <= 0.001f ? 1 : 2;
|
||||||
int precision = diff <= 0.01f ? 0 : diff <= 0.1f ? 1 : 2;
|
|
||||||
|
|
||||||
table.add(Strings.toFixed(value, precision));
|
table.add(Strings.fixed(value, precision));
|
||||||
table.add(" " + unit.localized());
|
table.add(" " + unit.localized());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user