Research system progress
This commit is contained in:
@@ -388,12 +388,12 @@ public class Block extends UnlockableContent{
|
||||
}
|
||||
|
||||
/** Configure when a null value is passed.*/
|
||||
public void configClear(Cons<Tilec> cons){
|
||||
configurations.put(void.class, (tile, value) -> cons.get((Tilec)tile));
|
||||
public <E extends Tilec> void configClear(Cons<E> cons){
|
||||
configurations.put(void.class, (tile, value) -> cons.get((E)tile));
|
||||
}
|
||||
|
||||
/** Listen for a config by class type. */
|
||||
public <T> void config(Class<T> type, Cons2<Tilec, T> config){
|
||||
public <T, E extends Tilec> void config(Class<T> type, Cons2<E, T> config){
|
||||
configurations.put(type, config);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ public class ItemSelection{
|
||||
int i = 0;
|
||||
|
||||
for(T item : items){
|
||||
if(!data.isUnlocked(item) && state.isCampaign()) continue;
|
||||
if(!item.unlockedNow()) continue;
|
||||
|
||||
ImageButton button = cont.button(Tex.whiteui, Styles.clearToggleTransi, 24, () -> control.input.frag.config.hideConfig()).group(group).get();
|
||||
button.changed(() -> consumer.get(button.isChecked() ? item : null));
|
||||
|
||||
@@ -177,7 +177,8 @@ public class LaunchPad extends Block{
|
||||
//actually launch the items upon removal
|
||||
if(team() == Vars.state.rules.defaultTeam){
|
||||
for(ItemStack stack : stacks){
|
||||
Vars.data.addItem(stack.item, stack.amount);
|
||||
//TODO where do the items go?
|
||||
//Vars.data.addItem(stack.item, stack.amount);
|
||||
Events.fire(new LaunchItemEvent(stack));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,27 @@
|
||||
package mindustry.world.blocks.campaign;
|
||||
|
||||
import arc.*;
|
||||
import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.scene.style.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.content.TechTree.*;
|
||||
import mindustry.ctype.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.storage.*;
|
||||
import mindustry.world.consumers.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class ResearchBlock extends StorageBlock{
|
||||
public class ResearchBlock extends Block{
|
||||
public float researchSpeed = 1f;
|
||||
public @Load("@-top") TextureRegion topRegion;
|
||||
|
||||
@@ -31,7 +33,11 @@ public class ResearchBlock extends StorageBlock{
|
||||
hasPower = true;
|
||||
hasItems = true;
|
||||
configurable = true;
|
||||
itemCapacity = 0;
|
||||
itemCapacity = 100;
|
||||
|
||||
//TODO requirements shrink as time goes on
|
||||
consumes.add(new ConsumeItemDynamic((ResearchBlockEntity entity) -> entity.researching != null ? entity.researching.requirements : ItemStack.empty));
|
||||
config(TechNode.class, ResearchBlockEntity::setTo);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -40,33 +46,100 @@ public class ResearchBlock extends StorageBlock{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlaceOn(Tile tile, Team team){
|
||||
if(tile == null) return false;
|
||||
public void setBars(){
|
||||
super.setBars();
|
||||
|
||||
//only allow placing next to cores
|
||||
for(Point2 edge : Edges.getEdges(size)){
|
||||
Tile other = tile.getNearby(edge);
|
||||
if(other != null && other.block() instanceof CoreBlock && other.team() == team){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
bars.add("progress", (ResearchBlockEntity e) -> new Bar("bar.progress", Pal.ammo, () -> e.researching == null ? 0f : e.researching.progress / e.researching.time));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawPlace(int x, int y, int rotation, boolean valid){
|
||||
boolean hasCore = canPlaceOn(world.tile(x, y), player.team());
|
||||
if(!hasCore){
|
||||
drawPlaceText(Core.bundle.get("bar.corereq"), x, y, valid);
|
||||
}
|
||||
}
|
||||
public class ResearchBlockEntity extends TileEntity{
|
||||
public @Nullable TechNode researching;
|
||||
|
||||
public class ResearchBlockEntity extends StorageBlockEntity{
|
||||
public @Nullable UnlockableContent researching;
|
||||
public double[] accumulator;
|
||||
public double[] totalAccumulator;
|
||||
|
||||
@Override
|
||||
public void updateTile(){
|
||||
if(researching != null){
|
||||
double totalTicks = researching.time * 60.0;
|
||||
double amount = researchSpeed * edelta() / totalTicks;
|
||||
|
||||
double maxProgress = checkRequired(amount, false);
|
||||
|
||||
for(int i = 0; i < researching.requirements.length; i++){
|
||||
int reqamount = Math.round(state.rules.buildCostMultiplier * researching.requirements[i].amount);
|
||||
accumulator[i] += Math.min(reqamount * maxProgress, reqamount - totalAccumulator[i] + 0.00001); //add min amount progressed to the accumulator
|
||||
totalAccumulator[i] = Math.min(totalAccumulator[i] + reqamount * maxProgress, reqamount);
|
||||
}
|
||||
|
||||
maxProgress = checkRequired(maxProgress, true);
|
||||
|
||||
float increment = (float)(maxProgress * researching.time);
|
||||
researching.progress += increment;
|
||||
|
||||
//check if it has been researched
|
||||
if(researching.progress >= researching.time){
|
||||
data.unlockContent(researching.content);
|
||||
|
||||
setTo(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private double checkRequired(double amount, boolean remove){
|
||||
double maxProgress = amount;
|
||||
|
||||
for(int i = 0; i < researching.requirements.length; i++){
|
||||
int ramount = researching.requirements[i].amount;
|
||||
int required = (int)(accumulator[i]); //calculate items that are required now
|
||||
|
||||
if(!items.has(researching.requirements[i].item) && ramount > 0){
|
||||
maxProgress = 0f;
|
||||
}else if(required > 0){ //if this amount is positive...
|
||||
//calculate how many items it can actually use
|
||||
int maxUse = Math.min(required, items.get(researching.requirements[i].item));
|
||||
//get this as a fraction
|
||||
double fraction = maxUse / (double)required;
|
||||
|
||||
//move max progress down if this fraction is less than 1
|
||||
maxProgress = Math.min(maxProgress, maxProgress * fraction);
|
||||
|
||||
accumulator[i] -= maxUse;
|
||||
|
||||
//remove stuff that is actually used
|
||||
if(remove){
|
||||
items.remove(researching.requirements[i].item, maxUse);
|
||||
}
|
||||
}
|
||||
//else, no items are required yet, so just keep going
|
||||
}
|
||||
|
||||
return maxProgress;
|
||||
}
|
||||
|
||||
private void setTo(@Nullable TechNode value){
|
||||
researching = value;
|
||||
if(value != null){
|
||||
accumulator = new double[researching.requirements.length];
|
||||
totalAccumulator = new double[researching.requirements.length];
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void display(Table table){
|
||||
super.display(table);
|
||||
|
||||
TextureRegionDrawable reg = new TextureRegionDrawable();
|
||||
|
||||
table.row();
|
||||
table.table(t -> {
|
||||
t.image().update(i -> {
|
||||
i.setDrawable(researching == null ? Icon.cancel : reg.set(researching.content.icon(Cicon.medium)));
|
||||
i.setScaling(Scaling.fit);
|
||||
i.setColor(researching == null ? Color.lightGray : Color.white);
|
||||
}).size(32).pad(3);
|
||||
t.label(() -> researching == null ? "$none" : researching.content.localizedName).color(Color.lightGray);
|
||||
}).left().padTop(4);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -85,14 +158,25 @@ public class ResearchBlock extends StorageBlock{
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Tilec source, Item item){
|
||||
//research blocks can only transfer items to the core
|
||||
return linkedCore != null && super.acceptItem(source, item);
|
||||
return items.get(item) < getMaximumAccepted(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaximumAccepted(Item item){
|
||||
if(researching == null) return 0;
|
||||
for(int i = 0; i < researching.requirements.length; i++){
|
||||
if(researching.requirements[i].item == item) return researching.requirements[i].amount;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configTapped(){
|
||||
//TODO select target
|
||||
Vars.ui.tech.show();
|
||||
//configure with tech node
|
||||
ui.tech.show(node -> {
|
||||
configure(node);
|
||||
ui.tech.hide();
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -102,8 +186,8 @@ public class ResearchBlock extends StorageBlock{
|
||||
super.write(write);
|
||||
|
||||
if(researching != null){
|
||||
write.b(researching.getContentType().ordinal());
|
||||
write.s(researching.id);
|
||||
write.b(researching.content.getContentType().ordinal());
|
||||
write.s(researching.content.id);
|
||||
}else{
|
||||
write.b(-1);
|
||||
}
|
||||
@@ -115,7 +199,7 @@ public class ResearchBlock extends StorageBlock{
|
||||
|
||||
byte type = read.b();
|
||||
if(type != -1){
|
||||
researching = Vars.content.getByID(ContentType.all[type], read.s());
|
||||
setTo(TechTree.get(content.getByID(ContentType.all[type], read.s())));
|
||||
}else{
|
||||
researching = null;
|
||||
}
|
||||
|
||||
@@ -28,12 +28,11 @@ public class Door extends Wall{
|
||||
solidifes = true;
|
||||
consumesTap = true;
|
||||
|
||||
config(Boolean.class, (entity, open) -> {
|
||||
DoorEntity door = (DoorEntity)entity;
|
||||
door.open = open;
|
||||
pathfinder.updateTile(door.tile());
|
||||
(open ? closefx : openfx).at(door);
|
||||
Sounds.door.at(door);
|
||||
config(Boolean.class, (DoorEntity entity, Boolean open) -> {
|
||||
entity.open = open;
|
||||
pathfinder.updateTile(entity.tile());
|
||||
(open ? closefx : openfx).at(entity);
|
||||
Sounds.door.at(entity);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ public class ItemTurret extends Turret{
|
||||
@Override
|
||||
public void build(Tilec tile, Table table){
|
||||
MultiReqImage image = new MultiReqImage();
|
||||
content.items().each(i -> filter.get(i) && (!state.isCampaign() || data.isUnlocked(i)), item -> image.add(new ReqImage(new ItemImage(item.icon(Cicon.medium)),
|
||||
content.items().each(i -> filter.get(i) && i.unlockedNow(), item -> image.add(new ReqImage(new ItemImage(item.icon(Cicon.medium)),
|
||||
() -> tile != null && !((ItemTurretEntity)tile).ammo.isEmpty() && ((ItemEntry)((ItemTurretEntity)tile).ammo.peek()).item == item)));
|
||||
|
||||
table.add(image).size(8 * 4);
|
||||
|
||||
@@ -44,9 +44,9 @@ public class ItemBridge extends Block{
|
||||
canOverdrive = false;
|
||||
|
||||
//point2 config is relative
|
||||
config(Point2.class, (tile, i) -> ((ItemBridgeEntity)tile).link = Point2.pack(i.x + tile.tileX(), i.y + tile.tileY()));
|
||||
config(Point2.class, (ItemBridgeEntity tile, Point2 i) -> tile.link = Point2.pack(i.x + tile.tileX(), i.y + tile.tileY()));
|
||||
//integer is not
|
||||
config(Integer.class, (tile, i) -> ((ItemBridgeEntity)tile).link = i);
|
||||
config(Integer.class, (ItemBridgeEntity tile, Integer i) -> tile.link = i);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -42,8 +42,8 @@ public class MassDriver extends Block{
|
||||
hasPower = true;
|
||||
outlineIcon = true;
|
||||
//point2 is relative
|
||||
config(Point2.class, (tile, point) -> ((MassDriverEntity)tile).link = Point2.pack(point.x + tile.tileX(), point.y + tile.tileY()));
|
||||
config(Integer.class, (tile, point) -> ((MassDriverEntity)tile).link = point);
|
||||
config(Point2.class, (MassDriverEntity tile, Point2 point) -> tile.link = Point2.pack(point.x + tile.tileX(), point.y + tile.tileY()));
|
||||
config(Integer.class, (MassDriverEntity tile, Integer point) -> tile.link = point);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -28,8 +28,8 @@ public class Sorter extends Block{
|
||||
unloadable = false;
|
||||
saveConfig = true;
|
||||
|
||||
config(Item.class, (tile, item) -> ((SorterEntity)tile).sortItem = item);
|
||||
configClear(tile -> ((SorterEntity)tile).sortItem = null);
|
||||
config(Item.class, (SorterEntity tile, Item item) -> tile.sortItem = item);
|
||||
configClear((SorterEntity tile) -> tile.sortItem = null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -33,17 +33,9 @@ public class BlockForge extends PayloadAcceptor{
|
||||
hasPower = true;
|
||||
rotate = true;
|
||||
|
||||
config(Block.class, (tile, block) -> ((BlockForgeEntity)tile).recipe = block);
|
||||
config(Block.class, (BlockForgeEntity tile, Block block) -> tile.recipe = block);
|
||||
|
||||
consumes.add(new ConsumeItemDynamic(e -> {
|
||||
BlockForgeEntity entity = (BlockForgeEntity)e;
|
||||
|
||||
if(entity.recipe != null){
|
||||
return entity.recipe.requirements;
|
||||
}
|
||||
|
||||
return ItemStack.empty;
|
||||
}));
|
||||
consumes.add(new ConsumeItemDynamic((BlockForgeEntity e) -> e.recipe != null ? e.recipe.requirements : ItemStack.empty));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -43,11 +43,11 @@ public class ImpactReactor extends PowerGenerator{
|
||||
public void setBars(){
|
||||
super.setBars();
|
||||
|
||||
bars.add("poweroutput", entity -> new Bar(() ->
|
||||
bars.add("poweroutput", (GeneratorEntity entity) -> new Bar(() ->
|
||||
Core.bundle.format("bar.poweroutput",
|
||||
Strings.fixed(Math.max(entity.getPowerProduction() - consumes.getPower().usage, 0) * 60 * entity.timeScale(), 1)),
|
||||
() -> Pal.powerBar,
|
||||
() -> ((GeneratorEntity)entity).productionEfficiency));
|
||||
() -> entity.productionEfficiency));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -24,7 +24,7 @@ public class LightBlock extends Block{
|
||||
configurable = true;
|
||||
saveConfig = true;
|
||||
|
||||
config(Integer.class, (tile, value) -> ((LightEntity)tile).color = value);
|
||||
config(Integer.class, (LightEntity tile, Integer value) -> tile.color = value);
|
||||
}
|
||||
|
||||
public class LightEntity extends TileEntity{
|
||||
|
||||
@@ -60,7 +60,7 @@ public class NuclearReactor extends PowerGenerator{
|
||||
@Override
|
||||
public void setBars(){
|
||||
super.setBars();
|
||||
bars.add("heat", entity -> new Bar("bar.heat", Pal.lightOrange, () -> ((NuclearReactorEntity)entity).heat));
|
||||
bars.add("heat", (NuclearReactorEntity entity) -> new Bar("bar.heat", Pal.lightOrange, () -> entity.heat));
|
||||
}
|
||||
|
||||
public class NuclearReactorEntity extends GeneratorEntity{
|
||||
|
||||
@@ -32,11 +32,11 @@ public class PowerGenerator extends PowerDistributor{
|
||||
super.setBars();
|
||||
|
||||
if(hasPower && outputsPower && !consumes.hasPower()){
|
||||
bars.add("power", entity -> new Bar(() ->
|
||||
bars.add("power", (GeneratorEntity entity) -> new Bar(() ->
|
||||
Core.bundle.format("bar.poweroutput",
|
||||
Strings.fixed(entity.getPowerProduction() * 60 * entity.timeScale(), 1)),
|
||||
() -> Pal.powerBar,
|
||||
() -> ((GeneratorEntity)entity).productionEfficiency));
|
||||
() -> entity.productionEfficiency));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,11 +31,11 @@ public class Cultivator extends GenericCrafter{
|
||||
@Override
|
||||
public void setBars(){
|
||||
super.setBars();
|
||||
bars.add("multiplier", entity -> new Bar(() ->
|
||||
bars.add("multiplier", (CultivatorEntity entity) -> new Bar(() ->
|
||||
Core.bundle.formatFloat("bar.efficiency",
|
||||
((((CultivatorEntity)entity).boost + 1f) * ((CultivatorEntity)entity).warmup) * 100f, 1),
|
||||
((entity.boost + 1f) * entity.warmup) * 100f, 1),
|
||||
() -> Pal.ammo,
|
||||
() -> ((CultivatorEntity)entity).warmup));
|
||||
() -> entity.warmup));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -86,11 +86,8 @@ public class Drill extends Block{
|
||||
public void setBars(){
|
||||
super.setBars();
|
||||
|
||||
bars.add("drillspeed", e -> {
|
||||
DrillEntity entity = (DrillEntity)e;
|
||||
|
||||
return new Bar(() -> Core.bundle.format("bar.drillspeed", Strings.fixed(entity.lastDrillSpeed * 60 * entity.timeScale(), 2)), () -> Pal.ammo, () -> entity.warmup);
|
||||
});
|
||||
bars.add("drillspeed", (DrillEntity e) ->
|
||||
new Bar(() -> Core.bundle.format("bar.drillspeed", Strings.fixed(e.lastDrillSpeed * 60 * e.timeScale(), 2)), () -> Pal.ammo, () -> e.warmup));
|
||||
}
|
||||
|
||||
public Item getDrop(Tile tile){
|
||||
@@ -285,7 +282,6 @@ public class Drill extends Block{
|
||||
|
||||
if(dominantItems > 0 && progress >= delay && items.total() < itemCapacity){
|
||||
offload(dominantItem);
|
||||
useContent(dominantItem);
|
||||
|
||||
index ++;
|
||||
progress %= delay;
|
||||
|
||||
@@ -116,14 +116,12 @@ public class GenericCrafter extends Block{
|
||||
consume();
|
||||
|
||||
if(outputItem != null){
|
||||
useContent(outputItem.item);
|
||||
for(int i = 0; i < outputItem.amount; i++){
|
||||
offload(outputItem.item);
|
||||
}
|
||||
}
|
||||
|
||||
if(outputLiquid != null){
|
||||
useContent(outputLiquid.liquid);
|
||||
handleLiquid(this, outputLiquid.liquid, outputLiquid.amount);
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,6 @@ public class LiquidConverter extends GenericCrafter{
|
||||
if(cons.valid()){
|
||||
float use = Math.min(cl.amount * edelta(), liquidCapacity - liquids.get(outputLiquid.liquid));
|
||||
|
||||
useContent(outputLiquid.liquid);
|
||||
progress += use / cl.amount;
|
||||
liquids.add(outputLiquid.liquid, use);
|
||||
if(progress >= craftTime){
|
||||
|
||||
@@ -13,8 +13,6 @@ import mindustry.world.meta.*;
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class Pump extends LiquidBlock{
|
||||
public final int timerContentCheck = timers++;
|
||||
|
||||
/** Pump amount, total. */
|
||||
protected float pumpAmount = 1f;
|
||||
|
||||
@@ -115,10 +113,6 @@ public class Pump extends LiquidBlock{
|
||||
liquids.add(liquidDrop, maxPump);
|
||||
}
|
||||
|
||||
if(liquids.currentAmount() > 0f && timer(timerContentCheck, 10)){
|
||||
useContent(liquids.current());
|
||||
}
|
||||
|
||||
dumpLiquid(liquids.current());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,11 +43,11 @@ public class SolidPump extends Pump{
|
||||
@Override
|
||||
public void setBars(){
|
||||
super.setBars();
|
||||
bars.add("efficiency", entity -> new Bar(() ->
|
||||
bars.add("efficiency", (SolidPumpEntity entity) -> new Bar(() ->
|
||||
Core.bundle.formatFloat("bar.pumpspeed",
|
||||
((SolidPumpEntity)entity).lastPump / Time.delta() * 60, 1),
|
||||
entity.lastPump / Time.delta() * 60, 1),
|
||||
() -> Pal.ammo,
|
||||
() -> ((SolidPumpEntity)entity).warmup));
|
||||
() -> entity.warmup));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -124,7 +124,6 @@ public class SolidPump extends Pump{
|
||||
liquids.add(result, maxPump);
|
||||
lastPump = maxPump;
|
||||
warmup = Mathf.lerpDelta(warmup, 1f, 0.02f);
|
||||
if(timer(timerContentCheck, 10)) useContent(result);
|
||||
if(Mathf.chance(delta() * updateEffectChance))
|
||||
updateEffect.at(getX() + Mathf.range(size * 2f), getY() + Mathf.range(size * 2f));
|
||||
}else{
|
||||
|
||||
@@ -24,8 +24,8 @@ public class ItemSource extends Block{
|
||||
configurable = true;
|
||||
saveConfig = true;
|
||||
|
||||
config(Item.class, (tile, item) -> ((ItemSourceEntity)tile).outputItem = item);
|
||||
configClear(tile -> ((ItemSourceEntity)tile).outputItem = null);
|
||||
config(Item.class, (ItemSourceEntity tile, Item item) -> tile.outputItem = item);
|
||||
configClear((ItemSourceEntity tile) -> tile.outputItem = null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -25,8 +25,8 @@ public class LiquidSource extends Block{
|
||||
outputsLiquid = true;
|
||||
saveConfig = true;
|
||||
|
||||
config(Liquid.class, (tile, l) -> ((LiquidSourceEntity)tile).source = l);
|
||||
configClear(tile -> ((LiquidSourceEntity)tile).source = null);
|
||||
config(Liquid.class, (LiquidSourceEntity tile, Liquid l) -> tile.source = l);
|
||||
configClear((LiquidSourceEntity tile) -> tile.source = null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -69,11 +69,11 @@ public class CoreBlock extends StorageBlock{
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
|
||||
bars.add("capacity", e ->
|
||||
bars.add("capacity", (CoreEntity e) ->
|
||||
new Bar(
|
||||
() -> Core.bundle.format("bar.capacity", ui.formatAmount(((CoreEntity)e).storageCapacity)),
|
||||
() -> Core.bundle.format("bar.capacity", ui.formatAmount(e.storageCapacity)),
|
||||
() -> Pal.items,
|
||||
() -> e.items().total() / (float)(((CoreEntity)e).storageCapacity * content.items().count(i -> i.type == ItemType.material))
|
||||
() -> e.items().total() / ((float)e.storageCapacity * content.items().count(i -> i.type == ItemType.material))
|
||||
));
|
||||
|
||||
bars.add("units", e ->
|
||||
|
||||
@@ -29,9 +29,7 @@ public class MessageBlock extends Block{
|
||||
solid = true;
|
||||
destructible = true;
|
||||
|
||||
config(String.class, (tile, text) -> {
|
||||
MessageBlockEntity entity = (MessageBlockEntity)tile;
|
||||
|
||||
config(String.class, (MessageBlockEntity tile, String text) -> {
|
||||
if(net.server() && text.length() > maxTextLength){
|
||||
throw new ValidateException(player, "Player has gone above text limit.");
|
||||
}
|
||||
@@ -51,8 +49,8 @@ public class MessageBlock extends Block{
|
||||
}
|
||||
}
|
||||
|
||||
entity.message = result.toString();
|
||||
entity.lines = entity.message.split("\n");
|
||||
tile.message = result.toString();
|
||||
tile.lines = tile.message.split("\n");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -27,12 +27,8 @@ public class Unloader extends Block{
|
||||
saveConfig = true;
|
||||
itemCapacity = 0;
|
||||
|
||||
config(Item.class, (tile, item) -> {
|
||||
tile.items().clear();
|
||||
((UnloaderEntity)tile).sortItem = item;
|
||||
});
|
||||
|
||||
configClear(tile -> ((UnloaderEntity)tile).sortItem = null);
|
||||
config(Item.class, (UnloaderEntity tile, Item item) -> tile.sortItem = item);
|
||||
configClear((UnloaderEntity tile) -> tile.sortItem = null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -41,7 +41,7 @@ public class Reconstructor extends UnitBlock{
|
||||
@Override
|
||||
public void setBars(){
|
||||
super.setBars();
|
||||
bars.add("progress", entity -> new Bar("bar.progress", Pal.ammo, ((ReconstructorEntity)entity)::fraction));
|
||||
bars.add("progress", (ReconstructorEntity entity) -> new Bar("bar.progress", Pal.ammo, entity::fraction));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -37,20 +37,12 @@ public class UnitFactory extends UnitBlock{
|
||||
outputsPayload = true;
|
||||
rotate = true;
|
||||
|
||||
config(Integer.class, (tile, i) -> {
|
||||
((UnitFactoryEntity)tile).currentPlan = i < 0 || i >= plans.length ? -1 : i;
|
||||
((UnitFactoryEntity)tile).progress = 0;
|
||||
config(Integer.class, (UnitFactoryEntity tile, Integer i) -> {
|
||||
tile.currentPlan = i < 0 || i >= plans.length ? -1 : i;
|
||||
tile.progress = 0;
|
||||
});
|
||||
|
||||
consumes.add(new ConsumeItemDynamic(e -> {
|
||||
UnitFactoryEntity entity = (UnitFactoryEntity)e;
|
||||
|
||||
if(entity.currentPlan != -1){
|
||||
return plans[entity.currentPlan].requirements;
|
||||
}
|
||||
|
||||
return ItemStack.empty;
|
||||
}));
|
||||
consumes.add(new ConsumeItemDynamic((UnitFactoryEntity e) -> e.currentPlan != -1 ? plans[e.currentPlan].requirements : ItemStack.empty));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -69,7 +61,7 @@ public class UnitFactory extends UnitBlock{
|
||||
@Override
|
||||
public void setBars(){
|
||||
super.setBars();
|
||||
bars.add("progress", entity -> new Bar("bar.progress", Pal.ammo, ((UnitFactoryEntity)entity)::fraction));
|
||||
bars.add("progress", (UnitFactoryEntity entity) -> new Bar("bar.progress", Pal.ammo, entity::fraction));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package mindustry.world.consumers;
|
||||
|
||||
import arc.func.*;
|
||||
import arc.math.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
@@ -12,8 +13,8 @@ import mindustry.world.meta.*;
|
||||
public class ConsumeItemDynamic extends Consume{
|
||||
public final @NonNull Func<Tilec, ItemStack[]> items;
|
||||
|
||||
public ConsumeItemDynamic(Func<Tilec, ItemStack[]> items){
|
||||
this.items = items;
|
||||
public <T extends Tilec> ConsumeItemDynamic(Func<T, ItemStack[]> items){
|
||||
this.items = (Func<Tilec, ItemStack[]>)items;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -43,7 +44,7 @@ public class ConsumeItemDynamic extends Consume{
|
||||
private void rebuild(Tilec tile, Table table){
|
||||
for(ItemStack stack : items.get(tile)){
|
||||
table.add(new ReqImage(new ItemImage(stack.item.icon(Cicon.medium), stack.amount),
|
||||
() -> tile.items() != null && tile.items().has(stack.item, stack.amount))).size(8 * 4).padRight(5);
|
||||
() -> tile.items() != null && tile.items().has(stack.item, stack.amount))).size(8 * 4).padRight(6 * Mathf.digits(stack.amount));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ public class ConsumeItemFilter extends Consume{
|
||||
@Override
|
||||
public void build(Tilec tile, Table table){
|
||||
MultiReqImage image = new MultiReqImage();
|
||||
content.items().each(i -> filter.get(i) && (!state.isCampaign() || data.isUnlocked(i)), item -> image.add(new ReqImage(new ItemImage(item.icon(Cicon.medium), 1),
|
||||
content.items().each(i -> filter.get(i) && i.unlockedNow(), item -> image.add(new ReqImage(new ItemImage(item.icon(Cicon.medium), 1),
|
||||
() -> tile.items() != null && tile.items().has(item))));
|
||||
|
||||
table.add(image).size(8 * 4);
|
||||
|
||||
@@ -8,8 +8,8 @@ import mindustry.ui.Bar;
|
||||
public class BlockBars{
|
||||
private OrderedMap<String, Func<Tilec, Bar>> bars = new OrderedMap<>();
|
||||
|
||||
public void add(String name, Func<Tilec, Bar> sup){
|
||||
bars.put(name, sup);
|
||||
public <T extends Tilec> void add(String name, Func<T, Bar> sup){
|
||||
bars.put(name, (Func<Tilec, Bar>)sup);
|
||||
}
|
||||
|
||||
public void remove(String name){
|
||||
|
||||
Reference in New Issue
Block a user