Stack router + Consistent item source + Item void flow
This commit is contained in:
BIN
core/assets-raw/sprites/blocks/distribution/ducts/arrow-glow.png
Normal file
BIN
core/assets-raw/sprites/blocks/distribution/ducts/arrow-glow.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.0 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 165 B |
Binary file not shown.
|
After Width: | Height: | Size: 443 B |
@@ -425,3 +425,4 @@
|
||||
63283=surge-duct|block-surge-duct-ui
|
||||
63282=surge-conveyor|block-surge-conveyor-ui
|
||||
63281=duct-unloader|block-duct-unloader-ui
|
||||
63280=surge-router|block-surge-router-ui
|
||||
|
||||
Binary file not shown.
@@ -75,7 +75,7 @@ public class Blocks implements ContentList{
|
||||
conveyor, titaniumConveyor, plastaniumConveyor, armoredConveyor, distributor, junction, itemBridge, phaseConveyor, sorter, invertedSorter, router,
|
||||
overflowGate, underflowGate, massDriver,
|
||||
duct, ductRouter, ductBridge, ductUnloader,
|
||||
surgeConveyor,
|
||||
surgeConveyor, surgeRouter,
|
||||
|
||||
//liquid
|
||||
mechanicalPump, rotaryPump, thermalPump, conduit, pulseConduit, platedConduit, liquidRouter, liquidContainer, liquidTank, liquidJunction, bridgeConduit, phaseConduit,
|
||||
@@ -1328,6 +1328,18 @@ public class Blocks implements ContentList{
|
||||
consumes.power(1f / 60f);
|
||||
}};
|
||||
|
||||
surgeRouter = new StackRouter("surge-router"){{
|
||||
requirements(Category.distribution, with(Items.graphite, 10, Items.surgeAlloy, 10));
|
||||
|
||||
speed = 6f;
|
||||
|
||||
hasPower = true;
|
||||
consumesPower = true;
|
||||
conductivePower = true;
|
||||
baseEfficiency = 1f;
|
||||
consumes.power(3f / 60f);
|
||||
}};
|
||||
|
||||
//endregion
|
||||
//region liquid
|
||||
|
||||
|
||||
@@ -1099,6 +1099,11 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
||||
return block.uiIcon;
|
||||
}
|
||||
|
||||
/** @return the item module to use for flow rate calculations */
|
||||
public ItemModule flowItems(){
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void display(Table table){
|
||||
//display the block stuff
|
||||
@@ -1126,7 +1131,9 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
||||
if(displayFlow){
|
||||
String ps = " " + StatUnit.perSecond.localized();
|
||||
|
||||
if(items != null){
|
||||
var flowItems = flowItems();
|
||||
|
||||
if(flowItems != null){
|
||||
table.row();
|
||||
table.left();
|
||||
table.table(l -> {
|
||||
@@ -1136,9 +1143,9 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
||||
l.clearChildren();
|
||||
l.left();
|
||||
for(Item item : content.items()){
|
||||
if(items.hasFlowItem(item)){
|
||||
if(flowItems.hasFlowItem(item)){
|
||||
l.image(item.uiIcon).padRight(3f);
|
||||
l.label(() -> items.getFlowRate(item) < 0 ? "..." : Strings.fixed(items.getFlowRate(item), 1) + ps).color(Color.lightGray);
|
||||
l.label(() -> flowItems.getFlowRate(item) < 0 ? "..." : Strings.fixed(flowItems.getFlowRate(item), 1) + ps).color(Color.lightGray);
|
||||
l.row();
|
||||
}
|
||||
}
|
||||
@@ -1147,7 +1154,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
||||
rebuild.run();
|
||||
l.update(() -> {
|
||||
for(Item item : content.items()){
|
||||
if(items.hasFlowItem(item) && !current.get(item.id)){
|
||||
if(flowItems.hasFlowItem(item) && !current.get(item.id)){
|
||||
current.set(item.id);
|
||||
rebuild.run();
|
||||
}
|
||||
|
||||
@@ -112,7 +112,6 @@ public class StackConveyor extends Block implements Autotiler{
|
||||
public int link = -1;
|
||||
public float cooldown;
|
||||
public Item lastItem;
|
||||
public float glow;
|
||||
|
||||
boolean proxUpdating = false;
|
||||
|
||||
@@ -133,9 +132,9 @@ public class StackConveyor extends Block implements Autotiler{
|
||||
Tile from = world.tile(link);
|
||||
|
||||
//TODO do not draw for certain configurations?
|
||||
if(glowRegion.found() && glow > 0f){
|
||||
if(glowRegion.found() && power != null && power.status > 0f){
|
||||
Draw.z(Layer.blockAdditive);
|
||||
Draw.color(glowColor, glowAlpha * glow);
|
||||
Draw.color(glowColor, glowAlpha * power.status);
|
||||
Draw.blend(Blending.additive);
|
||||
Draw.rect(glowRegion, x, y, rotation * 90);
|
||||
Draw.blend();
|
||||
@@ -253,8 +252,6 @@ public class StackConveyor extends Block implements Autotiler{
|
||||
lastItem = items.first();
|
||||
}
|
||||
|
||||
if(power != null) glow = Mathf.lerpDelta(glow, power.status, 0.6f);
|
||||
|
||||
//do not continue if disabled, will still allow one to be reeled in to prevent visual stacking
|
||||
if(!enabled) return;
|
||||
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
package mindustry.world.blocks.distribution;
|
||||
|
||||
import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.*;
|
||||
|
||||
public class StackRouter extends DuctRouter{
|
||||
public float baseEfficiency = 0f;
|
||||
|
||||
public @Load(value = "@-glow", fallback = "arrow-glow") TextureRegion glowRegion;
|
||||
public float glowAlpha = 1f;
|
||||
public Color glowColor = Pal.redLight;
|
||||
|
||||
public StackRouter(String name){
|
||||
super(name);
|
||||
itemCapacity = 10;
|
||||
}
|
||||
|
||||
public class StackRouterBuild extends DuctRouterBuild{
|
||||
public boolean unloading = false;
|
||||
|
||||
@Override
|
||||
public void updateTile(){
|
||||
float cap = speed;
|
||||
|
||||
if(!unloading && current != null && items.total() >= itemCapacity){
|
||||
if(progress < cap){
|
||||
//when items are full, begin offload timer
|
||||
progress += edelta();
|
||||
}
|
||||
|
||||
if(progress >= cap){
|
||||
unloading = true;
|
||||
progress %= cap;
|
||||
}
|
||||
}
|
||||
|
||||
//unload as many as possible when in unloading state
|
||||
if(unloading && current != null){
|
||||
//unload when possible
|
||||
var target = target();
|
||||
while(target != null && items.total() > 0){
|
||||
target.handleItem(this, current);
|
||||
int mod = sortItem != null && current != sortItem ? 2 : 3;
|
||||
cdump = (byte)((cdump + 1) % mod);
|
||||
items.remove(current, 1);
|
||||
|
||||
target = target();
|
||||
}
|
||||
|
||||
//if out of items, unloading is over
|
||||
if(items.total() == 0){
|
||||
current = null;
|
||||
unloading = false;
|
||||
}
|
||||
}
|
||||
|
||||
if(current == null && items.total() > 0){
|
||||
current = items.first();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
super.draw();
|
||||
|
||||
if(glowRegion.found() && power != null && power.status > 0){
|
||||
Draw.z(Layer.blockAdditive);
|
||||
Draw.color(glowColor, glowAlpha * power.status);
|
||||
Draw.blend(Blending.additive);
|
||||
Draw.rect(glowRegion, x, y, rotation * 90);
|
||||
Draw.blend();
|
||||
Draw.color();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float efficiency(){
|
||||
if(!enabled) return 0;
|
||||
return baseEfficiency + (power == null ? 0 : power.status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Building source, Item item){
|
||||
return !unloading && (current == null || item == current) && items.total() < itemCapacity &&
|
||||
(Edges.getFacingEdge(source.tile(), tile).relativeTo(tile) == rotation);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import mindustry.world.meta.*;
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class ItemSource extends Block{
|
||||
public int itemsPerSecond = 100;
|
||||
|
||||
public ItemSource(String name){
|
||||
super(name);
|
||||
@@ -36,6 +37,13 @@ public class ItemSource extends Block{
|
||||
bars.remove("items");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
|
||||
stats.add(Stat.output, itemsPerSecond, StatUnit.itemsSecond);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawRequestConfig(BuildPlan req, Eachable<BuildPlan> list){
|
||||
drawRequestConfigCenter(req, req.config, "center", true);
|
||||
@@ -47,7 +55,8 @@ public class ItemSource extends Block{
|
||||
}
|
||||
|
||||
public class ItemSourceBuild extends Building{
|
||||
Item outputItem;
|
||||
public float counter;
|
||||
public Item outputItem;
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
@@ -66,9 +75,15 @@ public class ItemSource extends Block{
|
||||
public void updateTile(){
|
||||
if(outputItem == null) return;
|
||||
|
||||
items.set(outputItem, 1);
|
||||
dump(outputItem);
|
||||
items.set(outputItem, 0);
|
||||
counter += edelta();
|
||||
float limit = 60f / itemsPerSecond;
|
||||
|
||||
while(counter >= limit){
|
||||
items.set(outputItem, 1);
|
||||
dump(outputItem);
|
||||
items.set(outputItem, 0);
|
||||
counter -= limit;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -4,6 +4,7 @@ import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.meta.*;
|
||||
import mindustry.world.modules.*;
|
||||
|
||||
public class ItemVoid extends Block{
|
||||
|
||||
@@ -15,8 +16,23 @@ public class ItemVoid extends Block{
|
||||
}
|
||||
|
||||
public class ItemVoidBuild extends Building{
|
||||
//I need a fake item module, because items can't be added to older blocks (breaks saves)
|
||||
public ItemModule flowItems = new ItemModule();
|
||||
|
||||
@Override
|
||||
public void handleItem(Building source, Item item){}
|
||||
public ItemModule flowItems(){
|
||||
return flowItems;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTile(){
|
||||
flowItems.update(updateFlow);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleItem(Building source, Item item){
|
||||
flowItems.handleFlow(item, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Building source, Item item){
|
||||
|
||||
@@ -273,6 +273,12 @@ public class ItemModule extends BlockModule{
|
||||
}
|
||||
}
|
||||
|
||||
public void handleFlow(Item item, int amount){
|
||||
if(flow != null){
|
||||
cacheSums[item.id] += amount;
|
||||
}
|
||||
}
|
||||
|
||||
public void undoFlow(Item item){
|
||||
if(flow != null){
|
||||
cacheSums[item.id] -= 1;
|
||||
|
||||
Reference in New Issue
Block a user