Directional duct unloader
This commit is contained in:
@@ -424,3 +424,4 @@
|
|||||||
63284=carbide-crucible|block-carbide-crucible-ui
|
63284=carbide-crucible|block-carbide-crucible-ui
|
||||||
63283=surge-duct|block-surge-duct-ui
|
63283=surge-duct|block-surge-duct-ui
|
||||||
63282=surge-conveyor|block-surge-conveyor-ui
|
63282=surge-conveyor|block-surge-conveyor-ui
|
||||||
|
63281=duct-unloader|block-duct-unloader-ui
|
||||||
|
|||||||
Binary file not shown.
@@ -74,7 +74,7 @@ public class Blocks implements ContentList{
|
|||||||
//transport
|
//transport
|
||||||
conveyor, titaniumConveyor, plastaniumConveyor, armoredConveyor, distributor, junction, itemBridge, phaseConveyor, sorter, invertedSorter, router,
|
conveyor, titaniumConveyor, plastaniumConveyor, armoredConveyor, distributor, junction, itemBridge, phaseConveyor, sorter, invertedSorter, router,
|
||||||
overflowGate, underflowGate, massDriver,
|
overflowGate, underflowGate, massDriver,
|
||||||
duct, ductRouter, ductBridge,
|
duct, ductRouter, ductBridge, ductUnloader,
|
||||||
surgeConveyor,
|
surgeConveyor,
|
||||||
|
|
||||||
//liquid
|
//liquid
|
||||||
@@ -1308,6 +1308,11 @@ public class Blocks implements ContentList{
|
|||||||
speed = 4f;
|
speed = 4f;
|
||||||
}};
|
}};
|
||||||
|
|
||||||
|
ductUnloader = new DirectionalUnloader("duct-unloader"){{
|
||||||
|
requirements(Category.distribution, with(Items.graphite, 10));
|
||||||
|
speed = 4f;
|
||||||
|
}};
|
||||||
|
|
||||||
surgeConveyor = new StackConveyor("surge-conveyor"){{
|
surgeConveyor = new StackConveyor("surge-conveyor"){{
|
||||||
requirements(Category.distribution, with(Items.surgeAlloy, 3, Items.graphite, 5));
|
requirements(Category.distribution, with(Items.surgeAlloy, 3, Items.graphite, 5));
|
||||||
health = 90;
|
health = 90;
|
||||||
|
|||||||
@@ -0,0 +1,159 @@
|
|||||||
|
package mindustry.world.blocks.distribution;
|
||||||
|
|
||||||
|
import arc.graphics.g2d.*;
|
||||||
|
import arc.scene.ui.layout.*;
|
||||||
|
import arc.util.*;
|
||||||
|
import arc.util.io.*;
|
||||||
|
import mindustry.annotations.Annotations.*;
|
||||||
|
import mindustry.entities.units.*;
|
||||||
|
import mindustry.gen.*;
|
||||||
|
import mindustry.type.*;
|
||||||
|
import mindustry.world.*;
|
||||||
|
import mindustry.world.blocks.*;
|
||||||
|
import mindustry.world.meta.*;
|
||||||
|
|
||||||
|
import static mindustry.Vars.*;
|
||||||
|
|
||||||
|
public class DirectionalUnloader extends Block{
|
||||||
|
public @Load(value = "@-center", fallback = "unloader-center") TextureRegion centerRegion;
|
||||||
|
public @Load("@-top") TextureRegion topRegion;
|
||||||
|
public @Load("@-arrow") TextureRegion arrowRegion;
|
||||||
|
|
||||||
|
public float speed = 1f;
|
||||||
|
|
||||||
|
public DirectionalUnloader(String name){
|
||||||
|
super(name);
|
||||||
|
|
||||||
|
update = true;
|
||||||
|
solid = true;
|
||||||
|
hasItems = true;
|
||||||
|
configurable = true;
|
||||||
|
saveConfig = true;
|
||||||
|
rotate = true;
|
||||||
|
itemCapacity = 0;
|
||||||
|
noUpdateDisabled = true;
|
||||||
|
unloadable = false;
|
||||||
|
envDisabled = Env.none;
|
||||||
|
|
||||||
|
config(Item.class, (DirectionalUnloaderBuild tile, Item item) -> tile.unloadItem = item);
|
||||||
|
configClear((DirectionalUnloaderBuild tile) -> tile.unloadItem = null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setStats(){
|
||||||
|
super.setStats();
|
||||||
|
stats.add(Stat.speed, 60f / speed, StatUnit.itemsSecond);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawRequestRegion(BuildPlan req, Eachable<BuildPlan> list){
|
||||||
|
Draw.rect(region, req.drawx(), req.drawy());
|
||||||
|
Draw.rect(topRegion, req.drawx(), req.drawy(), req.rotation * 90);
|
||||||
|
drawRequestConfig(req, list);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawRequestConfig(BuildPlan req, Eachable<BuildPlan> list){
|
||||||
|
drawRequestConfigCenter(req, req.config, "duct-unloader-center");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBars(){
|
||||||
|
super.setBars();
|
||||||
|
bars.remove("items");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TextureRegion[] icons(){
|
||||||
|
return new TextureRegion[]{region, topRegion, arrowRegion};
|
||||||
|
}
|
||||||
|
|
||||||
|
public class DirectionalUnloaderBuild extends Building{
|
||||||
|
public float unloadTimer = 0f;
|
||||||
|
public Item unloadItem = null;
|
||||||
|
public int offset = 0;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateTile(){
|
||||||
|
if((unloadTimer += edelta()) >= speed){
|
||||||
|
Building front = front(), back = back();
|
||||||
|
|
||||||
|
if(front != null && back != null && back.items != null && front.team == team && back.team == team && back.canUnload()){
|
||||||
|
if(unloadItem == null){
|
||||||
|
var itemseq = content.items();
|
||||||
|
int itemc = itemseq.size;
|
||||||
|
for(int i = 0; i < itemc; i++){
|
||||||
|
Item item = itemseq.get((i + offset) % itemc);
|
||||||
|
if(back.items.has(item) && front.acceptItem(this, item)){
|
||||||
|
front.handleItem(this, item);
|
||||||
|
back.items.remove(item, 1);
|
||||||
|
back.itemTaken(item);
|
||||||
|
offset ++;
|
||||||
|
offset %= itemc;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else if(back.items.has(unloadItem) && front.acceptItem(this, unloadItem)){
|
||||||
|
front.handleItem(this, unloadItem);
|
||||||
|
back.items.remove(unloadItem, 1);
|
||||||
|
back.itemTaken(unloadItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unloadTimer %= speed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw(){
|
||||||
|
Draw.rect(region, x, y);
|
||||||
|
|
||||||
|
Draw.rect(topRegion, x, y, rotdeg());
|
||||||
|
|
||||||
|
if(unloadItem != null){
|
||||||
|
Draw.color(unloadItem.color);
|
||||||
|
Draw.rect(centerRegion, x, y);
|
||||||
|
Draw.color();
|
||||||
|
}else{
|
||||||
|
Draw.rect(arrowRegion, x, y, rotdeg());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void buildConfiguration(Table table){
|
||||||
|
ItemSelection.buildTable(DirectionalUnloader.this, table, content.items(), () -> unloadItem, this::configure);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onConfigureTileTapped(Building other){
|
||||||
|
if(this == other){
|
||||||
|
deselect();
|
||||||
|
configure(null);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Item config(){
|
||||||
|
return unloadItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(Writes write){
|
||||||
|
super.write(write);
|
||||||
|
write.s(unloadItem == null ? -1 : unloadItem.id);
|
||||||
|
write.s(offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(Reads read, byte revision){
|
||||||
|
super.read(read, revision);
|
||||||
|
int id = read.s();
|
||||||
|
unloadItem = id == -1 ? null : content.items().get(id);
|
||||||
|
offset = read.s();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ import arc.scene.ui.layout.*;
|
|||||||
import arc.struct.*;
|
import arc.struct.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
import arc.util.io.*;
|
import arc.util.io.*;
|
||||||
|
import mindustry.annotations.Annotations.*;
|
||||||
import mindustry.entities.units.*;
|
import mindustry.entities.units.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.type.*;
|
import mindustry.type.*;
|
||||||
@@ -16,6 +17,8 @@ import mindustry.world.meta.*;
|
|||||||
import static mindustry.Vars.*;
|
import static mindustry.Vars.*;
|
||||||
|
|
||||||
public class Unloader extends Block{
|
public class Unloader extends Block{
|
||||||
|
public @Load(value = "@-center", fallback = "unloader-center") TextureRegion centerRegion;
|
||||||
|
|
||||||
public float speed = 1f;
|
public float speed = 1f;
|
||||||
|
|
||||||
public Unloader(String name){
|
public Unloader(String name){
|
||||||
@@ -29,7 +32,6 @@ public class Unloader extends Block{
|
|||||||
itemCapacity = 0;
|
itemCapacity = 0;
|
||||||
noUpdateDisabled = true;
|
noUpdateDisabled = true;
|
||||||
unloadable = false;
|
unloadable = false;
|
||||||
envEnabled = Env.any;
|
|
||||||
|
|
||||||
config(Item.class, (UnloaderBuild tile, Item item) -> tile.sortItem = item);
|
config(Item.class, (UnloaderBuild tile, Item item) -> tile.sortItem = item);
|
||||||
configClear((UnloaderBuild tile) -> tile.sortItem = null);
|
configClear((UnloaderBuild tile) -> tile.sortItem = null);
|
||||||
@@ -203,7 +205,7 @@ public class Unloader extends Block{
|
|||||||
super.draw();
|
super.draw();
|
||||||
|
|
||||||
Draw.color(sortItem == null ? Color.clear : sortItem.color);
|
Draw.color(sortItem == null ? Color.clear : sortItem.color);
|
||||||
Draw.rect("unloader-center", x, y);
|
Draw.rect(centerRegion, x, y);
|
||||||
Draw.color();
|
Draw.color();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,5 +20,7 @@ public class Env{
|
|||||||
//has oxygen in the atmosphere
|
//has oxygen in the atmosphere
|
||||||
oxygen = 1 << 7,
|
oxygen = 1 << 7,
|
||||||
//all attributes combined, only used for bitmasking purposes
|
//all attributes combined, only used for bitmasking purposes
|
||||||
any = 0xffffffff;
|
any = 0xffffffff,
|
||||||
|
//no attributes (0)
|
||||||
|
none = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,6 +119,10 @@ public class ItemModule extends BlockModule{
|
|||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean has(int id){
|
||||||
|
return items[id] > 0;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean has(Item item){
|
public boolean has(Item item){
|
||||||
return get(item) > 0;
|
return get(item) > 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user