Fixed #3899
This commit is contained in:
@@ -168,7 +168,7 @@ public class Drill extends Block{
|
||||
}
|
||||
|
||||
itemArray.sort((item1, item2) -> {
|
||||
int type = Boolean.compare(item1 != Items.sand, item2 != Items.sand);
|
||||
int type = Boolean.compare(!item1.lowPriority, !item2.lowPriority);
|
||||
if(type != 0) return type;
|
||||
int amounts = Integer.compare(oreCount.get(item1, 0), oreCount.get(item2, 0));
|
||||
if(amounts != 0) return amounts;
|
||||
|
||||
@@ -27,6 +27,7 @@ public class Unloader extends Block{
|
||||
saveConfig = true;
|
||||
itemCapacity = 0;
|
||||
noUpdateDisabled = true;
|
||||
unloadable = false;
|
||||
|
||||
config(Item.class, (UnloaderBuild tile, Item item) -> tile.sortItem = item);
|
||||
configClear((UnloaderBuild tile) -> tile.sortItem = null);
|
||||
@@ -47,10 +48,17 @@ public class Unloader extends Block{
|
||||
public Item sortItem = null;
|
||||
public Building dumpingTo;
|
||||
public int offset = 0;
|
||||
public int[] rotations;
|
||||
|
||||
@Override
|
||||
public void updateTile(){
|
||||
if(timer(timerUnload, speed / timeScale())){
|
||||
if(rotations == null || rotations.length != proximity.size){
|
||||
rotations = new int[proximity.size];
|
||||
}
|
||||
|
||||
Log.info("unloader @", id);
|
||||
|
||||
for(int i = 0; i < proximity.size; i++){
|
||||
int pos = (offset + i) % proximity.size;
|
||||
var other = proximity.get(pos);
|
||||
@@ -61,18 +69,19 @@ public class Unloader extends Block{
|
||||
dumpingTo = other;
|
||||
|
||||
//get item to be taken
|
||||
Item item = sortItem == null ? other.items.beginTake() : sortItem;
|
||||
Item item = sortItem == null ? other.items.takeIndex(rotations[pos]) : sortItem;
|
||||
|
||||
//remove item if it's dumped correctly
|
||||
if(put(item)){
|
||||
other.items.remove(item, 1);
|
||||
|
||||
if(sortItem == null){
|
||||
other.items.endTake(item);
|
||||
}else{
|
||||
other.items.remove(item, 1);
|
||||
rotations[pos] = item.id + 1;
|
||||
}
|
||||
|
||||
other.itemTaken(item);
|
||||
}else if(sortItem == null){
|
||||
other.items.failTake();
|
||||
rotations[pos] = other.items.nextIndex(rotations[pos]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,7 +206,7 @@ public class ItemModule extends BlockModule{
|
||||
|
||||
/** Begins a speculative take operation. This returns the item that would be returned by #take(), but does not change state. */
|
||||
@Nullable
|
||||
public Item beginTake(){
|
||||
public Item takeIndex(int takeRotation){
|
||||
for(int i = 0; i < items.length; i++){
|
||||
int index = (i + takeRotation);
|
||||
if(index >= items.length) index -= items.length;
|
||||
@@ -217,23 +217,15 @@ public class ItemModule extends BlockModule{
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Finishes a take operation. Updates take state, removes the item. */
|
||||
public void endTake(Item item){
|
||||
items[item.id] --;
|
||||
total --;
|
||||
takeRotation = item.id + 1;
|
||||
}
|
||||
|
||||
public void failTake(){
|
||||
public int nextIndex(int takeRotation){
|
||||
for(int i = 1; i < items.length; i++){
|
||||
int index = (i + takeRotation);
|
||||
if(index >= items.length) index -= items.length;
|
||||
if(items[index] > 0){
|
||||
takeRotation += i;
|
||||
takeRotation %= items.length;
|
||||
return;
|
||||
return (takeRotation + i) % items.length;
|
||||
}
|
||||
}
|
||||
return takeRotation;
|
||||
}
|
||||
|
||||
public int get(int id){
|
||||
|
||||
Reference in New Issue
Block a user