Added an extra slot when the drawer is void for mods that do checks stuff too much and it doesn't send stuff when it's full closes #27

This commit is contained in:
Buuz135 2022-06-24 14:40:44 +02:00
parent b6b2422837
commit 5626fca71e
3 changed files with 25 additions and 3 deletions

View File

@ -30,12 +30,14 @@ public abstract class BigInventoryHandler implements IItemHandler, INBTSerializa
@Override
public int getSlots() {
if (isVoid()) return type.getSlots() + 1;
return type.getSlots();
}
@Nonnull
@Override
public ItemStack getStackInSlot(int slot) {
if (type.getSlots() == slot) return ItemStack.EMPTY;
BigStack bigStack = this.storedStacks.get(slot);
ItemStack copied = bigStack.getStack().copy();
copied.setCount(bigStack.getAmount());
@ -45,6 +47,7 @@ public abstract class BigInventoryHandler implements IItemHandler, INBTSerializa
@Nonnull
@Override
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
if (isVoid() && type.getSlots() == slot && isVoidValid(stack)) return ItemStack.EMPTY;
if (isValid(slot, stack)) {
BigStack bigStack = this.storedStacks.get(slot);
int inserted = Math.min(getSlotLimit(slot) - bigStack.getAmount(), stack.getCount());
@ -62,7 +65,7 @@ public abstract class BigInventoryHandler implements IItemHandler, INBTSerializa
@Nonnull
@Override
public ItemStack extractItem(int slot, int amount, boolean simulate) {
if (amount == 0) return ItemStack.EMPTY;
if (amount == 0 || type.getSlots() == slot) return ItemStack.EMPTY;
if (slot < type.getSlots()){
BigStack bigStack = this.storedStacks.get(slot);
if (bigStack.getStack().isEmpty()) return ItemStack.EMPTY;
@ -89,6 +92,7 @@ public abstract class BigInventoryHandler implements IItemHandler, INBTSerializa
@Override
public int getSlotLimit(int slot) {
if (type.getSlots() == slot) return Integer.MAX_VALUE;
double stackSize = 1;
if (!getStoredStacks().get(slot).getStack().isEmpty()) {
stackSize = getStoredStacks().get(slot).getStack().getMaxStackSize() / 64D;
@ -112,6 +116,13 @@ public abstract class BigInventoryHandler implements IItemHandler, INBTSerializa
return false;
}
private boolean isVoidValid(ItemStack stack){
for (BigStack storedStack : this.storedStacks) {
if (storedStack.getStack().sameItem(stack) && ItemStack.tagMatches(storedStack.getStack(), stack)) return true;
}
return false;
}
@Override
public CompoundTag serializeNBT() {
CompoundTag compoundTag = new CompoundTag();

View File

@ -34,12 +34,14 @@ public abstract class CompactingInventoryHandler implements IItemHandler, INBTSe
@Override
public int getSlots() {
if (isVoid()) return 4;
return 3;
}
@Nonnull
@Override
public ItemStack getStackInSlot(int slot) {
if (slot == 3) return ItemStack.EMPTY;
CompactingUtil.Result bigStack = this.resultList.get(slot);
ItemStack copied = bigStack.getResult().copy();
copied.setCount(this.amount / bigStack.getNeeded());
@ -49,6 +51,7 @@ public abstract class CompactingInventoryHandler implements IItemHandler, INBTSe
@Nonnull
@Override
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
if (isVoid() && slot == 3 && isVoidValid(stack)) return ItemStack.EMPTY;
if (isValid(slot, stack)) {
CompactingUtil.Result result = this.resultList.get(slot);
int inserted = Math.min(getSlotLimit(slot) * result.getNeeded() - amount, stack.getCount() * result.getNeeded());
@ -64,6 +67,13 @@ public abstract class CompactingInventoryHandler implements IItemHandler, INBTSe
return stack;
}
private boolean isVoidValid(ItemStack stack) {
for (CompactingUtil.Result result : this.resultList) {
if (result.getResult().sameItem(stack) && ItemStack.tagMatches(result.getResult(), stack)) return true;
}
return false;
}
public boolean isSetup(){
return !this.resultList.get(this.resultList.size() -1).getResult().isEmpty();
@ -96,7 +106,7 @@ public abstract class CompactingInventoryHandler implements IItemHandler, INBTSe
@Nonnull
@Override
public ItemStack extractItem(int slot, int amount, boolean simulate) {
if (amount == 0) return ItemStack.EMPTY;
if (amount == 0 || slot == 3) return ItemStack.EMPTY;
if (slot < 3){
CompactingUtil.Result bigStack = this.resultList.get(slot);
if (bigStack.getResult().isEmpty()) return ItemStack.EMPTY;
@ -126,6 +136,7 @@ public abstract class CompactingInventoryHandler implements IItemHandler, INBTSe
@Override
public int getSlotLimit(int slot) {
if (slot == 3) return Integer.MAX_VALUE;
return (int) Math.min(Integer.MAX_VALUE, Math.floor((TOTAL_AMOUNT * getMultiplier()) / this.resultList.get(slot).getNeeded()));
}

View File

@ -35,7 +35,6 @@ public class EnderInventoryHandler extends BigInventoryHandler implements ILocka
this.voidItems = nbt.getBoolean(NBT_VOID);
}
//TODO Implement all of these methods
@Override
public void onChange() {
manager.setDirty();
@ -43,6 +42,7 @@ public class EnderInventoryHandler extends BigInventoryHandler implements ILocka
@Override
public int getSlotLimit(int slot) {
if (slot == 1) return Integer.MAX_VALUE;
double stackSize = 1;
if (!getStoredStacks().get(slot).getStack().isEmpty()) {
stackSize = getStoredStacks().get(slot).getStack().getMaxStackSize() / 64D;