Reinstated Compression sigil. (#1374)
* Reinstated Compression sigil. - does not compress wooden planks into crafting tables - searches for reversible 3x3/2x2 recipes with a single material type - probably has a lot of redundant stuff and looks silly - uses try/catch (might want to find a different approach, some people scoff at this) - should probably have spent the night sleeping, I'm taking exams tomorrow and will probably sleep the whole day through. * Learned how to properly handle the "NullPointerException"-situation. * Update BaseCompressionHandler.java * Update CompressionRegistry.java * Removed (almost) all code comments (only a one-liner remains that serves as pointer to a completly commented-out class (StorageBlockCraftingRecipeAssimilator)). Made methods and variables for long function calls to be more efficient. Fixed an oversight that resulted in a NullPointerException after removing redundant checks that were made to prevent exactly that. Rearranged and reformatted code. * corrected something that could be considered a typo but was an oversight * This should be it. An Array should be more efficient but you can correct me if I'm wrong. In either case it does what it is supposed to do. * Fixed. Needed a seperate inventory for the reversible check (or clear the previously used one, but then I'd had to repopulate again and that would just have been messy) * Forgot one of my lines. * Fix and cleanup. Could definitely clean more but that should suffice for now.
This commit is contained in:
parent
9440d3c0b9
commit
1f392721fa
7 changed files with 153 additions and 180 deletions
|
@ -8,11 +8,11 @@ public class BaseCompressionHandler extends CompressionHandler {
|
|||
private final ItemStack result;
|
||||
private final int leftover;
|
||||
|
||||
public BaseCompressionHandler(ItemStack requested, ItemStack result, int leftover) {
|
||||
public BaseCompressionHandler(ItemStack input, ItemStack output, int remainder) {
|
||||
super();
|
||||
this.required = requested;
|
||||
this.result = result;
|
||||
this.leftover = leftover;
|
||||
this.required = input;
|
||||
this.result = output;
|
||||
this.leftover = remainder;
|
||||
}
|
||||
|
||||
public ItemStack getResultStack() {
|
||||
|
@ -35,57 +35,18 @@ public class BaseCompressionHandler extends CompressionHandler {
|
|||
}
|
||||
|
||||
public int getRemainingNeeded(ItemStack[] inv) {
|
||||
return iterateThroughInventory(inv, false);
|
||||
int needed = this.required.getCount();
|
||||
int kept = this.getLeftover();
|
||||
return iterateThroughInventory(this.required, kept, inv, needed, true);
|
||||
}
|
||||
|
||||
public int drainInventory(ItemStack[] inv) {
|
||||
return iterateThroughInventory(inv, true);
|
||||
}
|
||||
|
||||
public int iterateThroughInventory(ItemStack[] inv, boolean doDrain) {
|
||||
int needed = this.required.getCount();
|
||||
int kept = this.getLeftover();
|
||||
int i = -1;
|
||||
|
||||
for (ItemStack invStack : inv) {
|
||||
i++;
|
||||
|
||||
if (invStack == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (invStack.isItemEqual(this.required) && (invStack.getTagCompound() == null ? this.required.getTagCompound() == null : invStack.getTagCompound().equals(this.required.getTagCompound()))) {
|
||||
int stackSize = invStack.getCount();
|
||||
int used = 0;
|
||||
if (kept > 0) {
|
||||
int remainingFromStack = Math.max(stackSize - kept, 0);
|
||||
used += stackSize - remainingFromStack;
|
||||
}
|
||||
|
||||
kept -= used;
|
||||
|
||||
if (kept <= 0 && needed > 0) {
|
||||
int remainingFromStack = Math.max(stackSize - used - needed, 0);
|
||||
if (doDrain) {
|
||||
invStack.setCount(remainingFromStack + used);
|
||||
if (invStack.isEmpty()) {
|
||||
inv[i] = ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
needed -= (stackSize - used - remainingFromStack);
|
||||
}
|
||||
|
||||
if (needed <= 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return needed;
|
||||
return iterateThroughInventory(this.required, kept, inv, needed, true);
|
||||
}
|
||||
|
||||
public int getLeftover() {
|
||||
return this.leftover;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue