Improved drawer validity check

This commit is contained in:
Buuz135 2021-12-27 18:42:54 +01:00
parent e96b9207e6
commit 105f45d67b
3 changed files with 15 additions and 3 deletions

View File

@ -38,7 +38,7 @@ public abstract class ArmoryCabinetInventoryHandler implements IItemHandler, INB
@NotNull @NotNull
@Override @Override
public ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate) { public ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate) {
if (isItemValid(slot, stack)) { if (isValid(slot, stack)) {
if (!simulate){ if (!simulate){
this.stackList.set(slot, stack); this.stackList.set(slot, stack);
onChange(); onChange();
@ -68,6 +68,10 @@ public abstract class ArmoryCabinetInventoryHandler implements IItemHandler, INB
@Override @Override
public boolean isItemValid(int slot, @NotNull ItemStack stack) { public boolean isItemValid(int slot, @NotNull ItemStack stack) {
return isCertifiedStack(stack);
}
private boolean isValid(int slot, @NotNull ItemStack stack) {
return !stack.isEmpty() && this.stackList.get(slot).isEmpty() && isCertifiedStack(stack); return !stack.isEmpty() && this.stackList.get(slot).isEmpty() && isCertifiedStack(stack);
} }

View File

@ -46,7 +46,7 @@ public abstract class BigInventoryHandler implements IItemHandler, INBTSerializa
@Nonnull @Nonnull
@Override @Override
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) { public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
if (isItemValid(slot, stack)) { if (isValid(slot, stack)) {
BigStack bigStack = this.storedStacks.get(slot); BigStack bigStack = this.storedStacks.get(slot);
int inserted = Math.min(getSlotLimit(slot) - bigStack.getAmount(), stack.getCount()); int inserted = Math.min(getSlotLimit(slot) - bigStack.getAmount(), stack.getCount());
if (!simulate){ if (!simulate){
@ -96,6 +96,10 @@ public abstract class BigInventoryHandler implements IItemHandler, INBTSerializa
@Override @Override
public boolean isItemValid(int slot, @Nonnull ItemStack stack) { public boolean isItemValid(int slot, @Nonnull ItemStack stack) {
return !stack.isEmpty();
}
private boolean isValid(int slot, @Nonnull ItemStack stack){
if (slot < type.getSlots()){ if (slot < type.getSlots()){
BigStack bigStack = this.storedStacks.get(slot); BigStack bigStack = this.storedStacks.get(slot);
ItemStack fl = bigStack.getStack(); ItemStack fl = bigStack.getStack();

View File

@ -49,7 +49,7 @@ public abstract class CompactingInventoryHandler implements IItemHandler, INBTSe
@Nonnull @Nonnull
@Override @Override
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) { public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
if (isItemValid(slot, stack)) { if (isValid(slot, stack)) {
CompactingUtil.Result result = this.resultList.get(slot); CompactingUtil.Result result = this.resultList.get(slot);
int inserted = Math.min(getSlotLimit(slot) * result.getNeeded() - amount, stack.getCount() * result.getNeeded()); int inserted = Math.min(getSlotLimit(slot) * result.getNeeded() - amount, stack.getCount() * result.getNeeded());
inserted = (int) (Math.floor(inserted / result.getNeeded()) * result.getNeeded()); inserted = (int) (Math.floor(inserted / result.getNeeded()) * result.getNeeded());
@ -125,6 +125,10 @@ public abstract class CompactingInventoryHandler implements IItemHandler, INBTSe
@Override @Override
public boolean isItemValid(int slot, @Nonnull ItemStack stack) { public boolean isItemValid(int slot, @Nonnull ItemStack stack) {
return isSetup() && slot < 3 && stack.isEmpty();
}
private boolean isValid(int slot, @Nonnull ItemStack stack){
if (slot < 3){ if (slot < 3){
CompactingUtil.Result bigStack = this.resultList.get(slot); CompactingUtil.Result bigStack = this.resultList.get(slot);
ItemStack fl = bigStack.getResult(); ItemStack fl = bigStack.getResult();