This commit is contained in:
Anuken 2019-09-13 08:13:40 -04:00
parent 4b26c57a20
commit 55da9df2a1
7 changed files with 42 additions and 3 deletions

View File

@ -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. */

View File

@ -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){

View File

@ -26,6 +26,7 @@ public class Junction extends Block{
solid = true;
instantTransfer = true;
group = BlockGroup.transportation;
unloadable = false;
}
@Override

View File

@ -18,6 +18,7 @@ public class OverflowGate extends Block{
solid = true;
update = true;
group = BlockGroup.transportation;
unloadable = false;
}
@Override

View File

@ -17,6 +17,7 @@ public class Router extends Block{
hasItems = true;
itemCapacity = 1;
group = BlockGroup.transportation;
unloadable = false;
}
@Override

View File

@ -26,6 +26,7 @@ public class Sorter extends Block{
instantTransfer = true;
group = BlockGroup.transportation;
configurable = true;
unloadable = false;
}
@Override

View File

@ -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);