Better unit factory implementation
This commit is contained in:
@@ -1674,12 +1674,10 @@ public class Blocks implements ContentList{
|
||||
requirements(Category.units, ItemStack.with(Items.copper, 30, Items.lead, 70));
|
||||
plans = new UnitPlan[]{
|
||||
new UnitPlan(UnitTypes.dagger, 200f, ItemStack.with(Items.silicon, 10)),
|
||||
new UnitPlan(UnitTypes.titan, 400f, ItemStack.with(Items.silicon, 10)),
|
||||
new UnitPlan(UnitTypes.titan, 400f, ItemStack.with(Items.silicon, 20, Items.thorium, 20)),
|
||||
};
|
||||
size = 3;
|
||||
consumes.power(1.2f);
|
||||
//TODO this is incorrect
|
||||
consumes.items(new ItemStack(Items.silicon, 10));
|
||||
}};
|
||||
|
||||
airFactory = new UnitFactory("air-factory"){{
|
||||
@@ -1690,8 +1688,6 @@ public class Blocks implements ContentList{
|
||||
};
|
||||
size = 3;
|
||||
consumes.power(1.2f);
|
||||
//TODO
|
||||
consumes.items(new ItemStack(Items.silicon, 10));
|
||||
}};
|
||||
|
||||
navalFactory = new UnitFactory("naval-factory"){{
|
||||
@@ -1702,8 +1698,6 @@ public class Blocks implements ContentList{
|
||||
size = 3;
|
||||
requiresWater = true;
|
||||
consumes.power(1.2f);
|
||||
//TODO
|
||||
consumes.items(new ItemStack(Items.silicon, 10));
|
||||
}};
|
||||
|
||||
repairPoint = new RepairPoint("repair-point"){{
|
||||
|
||||
@@ -4,6 +4,8 @@ import arc.struct.Array;
|
||||
import mindustry.content.Items;
|
||||
|
||||
public class ItemStack implements Comparable<ItemStack>{
|
||||
public static final ItemStack[] empty = {};
|
||||
|
||||
public Item item;
|
||||
public int amount = 0;
|
||||
|
||||
|
||||
@@ -45,7 +45,6 @@ public class ForceProjector extends Block{
|
||||
update = true;
|
||||
solid = true;
|
||||
hasPower = true;
|
||||
canOverdrive = false;
|
||||
hasLiquids = true;
|
||||
hasItems = true;
|
||||
expanded = true;
|
||||
@@ -118,7 +117,7 @@ public class ForceProjector extends Block{
|
||||
scale *= (cooldownLiquid * (1f + (liquids.current().heatCapacity - 0.4f) * 0.9f));
|
||||
}
|
||||
|
||||
buildup -= Time.delta() * scale;
|
||||
buildup -= delta() * scale;
|
||||
}
|
||||
|
||||
if(broken && buildup <= 0){
|
||||
|
||||
@@ -5,6 +5,7 @@ import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
@@ -23,6 +24,8 @@ import mindustry.world.meta.*;
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class UnitFactory extends Block{
|
||||
|
||||
|
||||
public float launchVelocity = 5f;
|
||||
public TextureRegion topRegion;
|
||||
public int[] capacities;
|
||||
@@ -39,6 +42,15 @@ public class UnitFactory extends Block{
|
||||
configurable = true;
|
||||
|
||||
config(Integer.class, (tile, i) -> ((UnitFactoryEntity)tile).currentPlan = i < 0 || i >= plans.length ? -1 : i);
|
||||
consumes.add(new ConsumeItemDynamic(e -> {
|
||||
UnitFactoryEntity entity = (UnitFactoryEntity)e;
|
||||
|
||||
if(entity.currentPlan != -1){
|
||||
return plans[entity.currentPlan].requirements;
|
||||
}
|
||||
|
||||
return ItemStack.empty;
|
||||
}));
|
||||
}
|
||||
|
||||
@Remote(called = Loc.server)
|
||||
@@ -52,10 +64,9 @@ public class UnitFactory extends Block{
|
||||
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;
|
||||
for(UnitPlan plan : plans){
|
||||
for(ItemStack stack : plan.requirements){
|
||||
capacities[stack.item.id] = Math.max(capacities[stack.item.id], stack.amount * 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -211,6 +222,12 @@ public class UnitFactory extends Block{
|
||||
return capacities[item.id];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Tilec source, Item item){
|
||||
return currentPlan != -1 && items.get(item) < getMaximumAccepted(item) &&
|
||||
Structs.contains(plans[currentPlan].requirements, stack -> stack.item == item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte version(){
|
||||
return 1;
|
||||
|
||||
@@ -9,7 +9,6 @@ import mindustry.type.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.world.meta.*;
|
||||
|
||||
//TODO
|
||||
public class ConsumeItemDynamic extends Consume{
|
||||
public final @NonNull Func<Tilec, ItemStack[]> items;
|
||||
|
||||
@@ -29,6 +28,19 @@ public class ConsumeItemDynamic extends Consume{
|
||||
|
||||
@Override
|
||||
public void build(Tilec tile, Table table){
|
||||
ItemStack[][] current = {items.get(tile)};
|
||||
|
||||
table.update(() -> {
|
||||
if(current[0] != items.get(tile)){
|
||||
rebuild(tile, table);
|
||||
current[0] = items.get(tile);
|
||||
}
|
||||
});
|
||||
|
||||
rebuild(tile, table);
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -59,7 +71,6 @@ public class ConsumeItemDynamic extends Consume{
|
||||
|
||||
@Override
|
||||
public void display(BlockStats stats){
|
||||
//TODO
|
||||
//stats.add(booster ? BlockStat.booster : BlockStat.input, new ItemListValue(items));
|
||||
//should be handled by the block
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user