diff --git a/core/assets/icons/icons.properties b/core/assets/icons/icons.properties index dc3f50f422..8186900200 100755 --- a/core/assets/icons/icons.properties +++ b/core/assets/icons/icons.properties @@ -424,3 +424,4 @@ 63284=carbide-crucible|block-carbide-crucible-ui 63283=surge-duct|block-surge-duct-ui 63282=surge-conveyor|block-surge-conveyor-ui +63281=duct-unloader|block-duct-unloader-ui diff --git a/core/assets/logicids.dat b/core/assets/logicids.dat index 4f09d2749f..966264a93f 100644 Binary files a/core/assets/logicids.dat and b/core/assets/logicids.dat differ diff --git a/core/src/mindustry/content/Blocks.java b/core/src/mindustry/content/Blocks.java index 7348863fb4..22f0fec617 100644 --- a/core/src/mindustry/content/Blocks.java +++ b/core/src/mindustry/content/Blocks.java @@ -74,7 +74,7 @@ public class Blocks implements ContentList{ //transport conveyor, titaniumConveyor, plastaniumConveyor, armoredConveyor, distributor, junction, itemBridge, phaseConveyor, sorter, invertedSorter, router, overflowGate, underflowGate, massDriver, - duct, ductRouter, ductBridge, + duct, ductRouter, ductBridge, ductUnloader, surgeConveyor, //liquid @@ -1308,6 +1308,11 @@ public class Blocks implements ContentList{ speed = 4f; }}; + ductUnloader = new DirectionalUnloader("duct-unloader"){{ + requirements(Category.distribution, with(Items.graphite, 10)); + speed = 4f; + }}; + surgeConveyor = new StackConveyor("surge-conveyor"){{ requirements(Category.distribution, with(Items.surgeAlloy, 3, Items.graphite, 5)); health = 90; diff --git a/core/src/mindustry/world/blocks/distribution/DirectionalUnloader.java b/core/src/mindustry/world/blocks/distribution/DirectionalUnloader.java new file mode 100644 index 0000000000..29cc41a4cd --- /dev/null +++ b/core/src/mindustry/world/blocks/distribution/DirectionalUnloader.java @@ -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 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 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(); + } + } +} diff --git a/core/src/mindustry/world/blocks/storage/Unloader.java b/core/src/mindustry/world/blocks/storage/Unloader.java index bf70385092..eae61826d3 100644 --- a/core/src/mindustry/world/blocks/storage/Unloader.java +++ b/core/src/mindustry/world/blocks/storage/Unloader.java @@ -6,6 +6,7 @@ import arc.scene.ui.layout.*; import arc.struct.*; import arc.util.*; import arc.util.io.*; +import mindustry.annotations.Annotations.*; import mindustry.entities.units.*; import mindustry.gen.*; import mindustry.type.*; @@ -16,6 +17,8 @@ import mindustry.world.meta.*; import static mindustry.Vars.*; public class Unloader extends Block{ + public @Load(value = "@-center", fallback = "unloader-center") TextureRegion centerRegion; + public float speed = 1f; public Unloader(String name){ @@ -29,7 +32,6 @@ public class Unloader extends Block{ itemCapacity = 0; noUpdateDisabled = true; unloadable = false; - envEnabled = Env.any; config(Item.class, (UnloaderBuild tile, Item item) -> tile.sortItem = item); configClear((UnloaderBuild tile) -> tile.sortItem = null); @@ -203,7 +205,7 @@ public class Unloader extends Block{ super.draw(); Draw.color(sortItem == null ? Color.clear : sortItem.color); - Draw.rect("unloader-center", x, y); + Draw.rect(centerRegion, x, y); Draw.color(); } diff --git a/core/src/mindustry/world/meta/Env.java b/core/src/mindustry/world/meta/Env.java index 1355087484..ba7d0fa1ce 100644 --- a/core/src/mindustry/world/meta/Env.java +++ b/core/src/mindustry/world/meta/Env.java @@ -20,5 +20,7 @@ public class Env{ //has oxygen in the atmosphere oxygen = 1 << 7, //all attributes combined, only used for bitmasking purposes - any = 0xffffffff; + any = 0xffffffff, + //no attributes (0) + none = 0; } diff --git a/core/src/mindustry/world/modules/ItemModule.java b/core/src/mindustry/world/modules/ItemModule.java index 835ae45fb4..2a27f82df3 100644 --- a/core/src/mindustry/world/modules/ItemModule.java +++ b/core/src/mindustry/world/modules/ItemModule.java @@ -119,6 +119,10 @@ public class ItemModule extends BlockModule{ return sum; } + public boolean has(int id){ + return items[id] > 0; + } + public boolean has(Item item){ return get(item) > 0; }