diff --git a/core/src/io/anuke/mindustry/world/Block.java b/core/src/io/anuke/mindustry/world/Block.java index 5921345f13..789c63943b 100644 --- a/core/src/io/anuke/mindustry/world/Block.java +++ b/core/src/io/anuke/mindustry/world/Block.java @@ -45,6 +45,8 @@ public class Block extends BlockStorage{ public boolean update; /** whether this block has health and can be destroyed */ public boolean destructible; + /** whether unloaders work on this block*/ + public boolean unloadable = true; /** whether this is solid */ public boolean solid; /** whether this block CAN be solid. */ diff --git a/core/src/io/anuke/mindustry/world/blocks/distribution/Conveyor.java b/core/src/io/anuke/mindustry/world/blocks/distribution/Conveyor.java index de6c98d3e3..2024c7f176 100644 --- a/core/src/io/anuke/mindustry/world/blocks/distribution/Conveyor.java +++ b/core/src/io/anuke/mindustry/world/blocks/distribution/Conveyor.java @@ -42,6 +42,7 @@ public class Conveyor extends Block{ idleSound = Sounds.conveyor; idleSoundVolume = 0.004f; + unloadable = false; } private static int compareItems(long a, long b){ diff --git a/core/src/io/anuke/mindustry/world/blocks/distribution/Junction.java b/core/src/io/anuke/mindustry/world/blocks/distribution/Junction.java index febd11f5d7..e184492864 100644 --- a/core/src/io/anuke/mindustry/world/blocks/distribution/Junction.java +++ b/core/src/io/anuke/mindustry/world/blocks/distribution/Junction.java @@ -26,6 +26,7 @@ public class Junction extends Block{ solid = true; instantTransfer = true; group = BlockGroup.transportation; + unloadable = false; } @Override diff --git a/core/src/io/anuke/mindustry/world/blocks/distribution/OverflowGate.java b/core/src/io/anuke/mindustry/world/blocks/distribution/OverflowGate.java index c03b3b7a97..e1bdc27bd8 100644 --- a/core/src/io/anuke/mindustry/world/blocks/distribution/OverflowGate.java +++ b/core/src/io/anuke/mindustry/world/blocks/distribution/OverflowGate.java @@ -18,6 +18,7 @@ public class OverflowGate extends Block{ solid = true; update = true; group = BlockGroup.transportation; + unloadable = false; } @Override diff --git a/core/src/io/anuke/mindustry/world/blocks/distribution/Router.java b/core/src/io/anuke/mindustry/world/blocks/distribution/Router.java index 6aea6275a0..47496bfbfd 100644 --- a/core/src/io/anuke/mindustry/world/blocks/distribution/Router.java +++ b/core/src/io/anuke/mindustry/world/blocks/distribution/Router.java @@ -17,6 +17,7 @@ public class Router extends Block{ hasItems = true; itemCapacity = 1; group = BlockGroup.transportation; + unloadable = false; } @Override diff --git a/core/src/io/anuke/mindustry/world/blocks/distribution/Sorter.java b/core/src/io/anuke/mindustry/world/blocks/distribution/Sorter.java index a7497079f4..0243f3e8ee 100644 --- a/core/src/io/anuke/mindustry/world/blocks/distribution/Sorter.java +++ b/core/src/io/anuke/mindustry/world/blocks/distribution/Sorter.java @@ -26,6 +26,7 @@ public class Sorter extends Block{ instantTransfer = true; group = BlockGroup.transportation; configurable = true; + unloadable = false; } @Override diff --git a/core/src/io/anuke/mindustry/world/blocks/storage/Unloader.java b/core/src/io/anuke/mindustry/world/blocks/storage/Unloader.java index a9644f7f21..80d1fa405f 100644 --- a/core/src/io/anuke/mindustry/world/blocks/storage/Unloader.java +++ b/core/src/io/anuke/mindustry/world/blocks/storage/Unloader.java @@ -59,9 +59,9 @@ public class Unloader extends Block{ if(tile.entity.timer.get(timerUnload, speed / entity.timeScale) && tile.entity.items.total() == 0){ for(Tile other : tile.entity.proximity()){ - if(other.interactable(tile.getTeam()) && other.block() instanceof StorageBlock && entity.items.total() == 0 && - ((entity.sortItem == null && other.entity.items.total() > 0) || ((StorageBlock)other.block()).hasItem(other, entity.sortItem))){ - offloadNear(tile, ((StorageBlock)other.block()).removeItem(other, entity.sortItem)); + if(other.interactable(tile.getTeam()) && other.block().unloadable && entity.items.total() == 0 && + ((entity.sortItem == null && other.entity.items.total() > 0) || hasItem(other, entity.sortItem))){ + offloadNear(tile, removeItem(other, entity.sortItem)); } } } @@ -71,6 +71,38 @@ public class Unloader extends Block{ } } + /** + * Removes an item and returns it. If item is not null, it should return the item. + * Returns null if no items are there. + */ + private Item removeItem(Tile tile, Item item){ + TileEntity entity = tile.entity; + + if(item == null){ + return entity.items.take(); + }else{ + if(entity.items.has(item)){ + entity.items.remove(item, 1); + return item; + } + + return null; + } + } + + /** + * Returns whether this storage block has the specified item. + * If the item is null, it should return whether it has ANY items. + */ + private boolean hasItem(Tile tile, Item item){ + TileEntity entity = tile.entity; + if(item == null){ + return entity.items.total() > 0; + }else{ + return entity.items.has(item); + } + } + @Override public void draw(Tile tile){ super.draw(tile);