Skip to content

Commit

Permalink
Fix for compacting drawers saving invalid state if one of the items w…
Browse files Browse the repository at this point in the history
…as removed from the game
  • Loading branch information
jaquadro committed Mar 27, 2018
1 parent 03426f6 commit 051dd88
Showing 1 changed file with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,35 @@ private void populateRawSlot (int slot, @Nonnull ItemStack itemPrototype, int ra
: new ItemStackMatcher(protoStack[slot]);
}

private void normalizeGroup () {
for (int limit = slotCount - 1; limit > 0; limit--) {
for (int i = 0; i < limit; i++) {
if (protoStack[i].isEmpty()) {
protoStack[i] = protoStack[i + 1];
matchers[i] = matchers[i + 1];
convRate[i] = convRate[i + 1];

protoStack[i + 1] = ItemStack.EMPTY;
matchers[i + 1] = ItemStackMatcher.EMPTY;
convRate[i + 1] = 0;
}
}
}

int minConvRate = Integer.MAX_VALUE;
for (int i = 0; i < slotCount; i++) {
if (convRate[i] > 0)
minConvRate = Math.min(minConvRate, convRate[i]);
}

if (minConvRate > 1) {
for (int i = 0; i < slotCount; i++)
convRate[i] /= minConvRate;

pooledCount /= minConvRate;
}
}

@Override
public NBTTagCompound serializeNBT () {
NBTTagList itemList = new NBTTagList();
Expand Down Expand Up @@ -535,6 +564,9 @@ public void deserializeNBT (NBTTagCompound tag) {
? new ItemStackOreMatcher(protoStack[slot])
: new ItemStackMatcher(protoStack[slot]);
}

// TODO: We should only need to normalize if we had blank items with a conv rate, but this fixes blocks that were saved broken
normalizeGroup();
}

public void deserializeLegacyNBT (NBTTagCompound tag) {
Expand Down

0 comments on commit 051dd88

Please sign in to comment.