Skip to content

Commit

Permalink
Fix Sorting AA Crates & Other Slots
Browse files Browse the repository at this point in the history
  • Loading branch information
IntegerLimit committed Aug 13, 2024
1 parent 41ba99a commit 4427c5f
Showing 1 changed file with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.cleanroommc.bogosorter.api.ISlot;
import com.cleanroommc.bogosorter.common.sort.SlotGroup;
import com.cleanroommc.bogosorter.common.sort.SortHandler;
import com.google.common.collect.ImmutableList;

/**
* Prevents Modification of 'Locked' Slots.
Expand Down Expand Up @@ -86,8 +87,27 @@ private void newSortBogo(SlotGroup instance) {
List<ISlot> result = new ArrayList<>();

for (var slot : slots) {
if (slot.bogo$canTakeStack(player)) result.add(slot);
/*
* Logic being used to check if we cannot access the slot:
* 1. Can the player take the stack?
* This usually returns true, but some slot implementations return false if the slot is empty.
*
* 2. Can we insert the current stack into the slot?
* This may seem roundabout, but this means that if it returns false, then most likely, the slot is
* always returning false.
*
* 3. Is the stack in the slot empty?
* If it is empty, some implementations return false for both above methods.
* Although this might risk changing actually inaccessible slots, most likely, those slots would not be
* empty.
*
* The slot should only be marked as inaccessible if all three conditions return false.
*/
boolean canTake = slot.bogo$canTakeStack(player);
boolean canInsert = slot.bogo$isItemValid(slot.bogo$getStack().copy());
boolean isEmpty = slot.bogo$getStack().isEmpty();
if (canTake || canInsert || isEmpty) result.add(slot);
}
return result;
return ImmutableList.copyOf(result);
}
}

0 comments on commit 4427c5f

Please sign in to comment.