mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-22 04:28:27 +07:00
Fixed #655
This commit is contained in:
parent
4b26c57a20
commit
55da9df2a1
@ -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. */
|
||||
|
@ -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){
|
||||
|
@ -26,6 +26,7 @@ public class Junction extends Block{
|
||||
solid = true;
|
||||
instantTransfer = true;
|
||||
group = BlockGroup.transportation;
|
||||
unloadable = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -18,6 +18,7 @@ public class OverflowGate extends Block{
|
||||
solid = true;
|
||||
update = true;
|
||||
group = BlockGroup.transportation;
|
||||
unloadable = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -17,6 +17,7 @@ public class Router extends Block{
|
||||
hasItems = true;
|
||||
itemCapacity = 1;
|
||||
group = BlockGroup.transportation;
|
||||
unloadable = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -26,6 +26,7 @@ public class Sorter extends Block{
|
||||
instantTransfer = true;
|
||||
group = BlockGroup.transportation;
|
||||
configurable = true;
|
||||
unloadable = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user