From d5c430fcdc8af8c3a1af7ee4c107740779bbf46e Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sat, 4 Feb 2017 16:32:20 +0100 Subject: [PATCH] Some changes to common capabilities integration for performance improvements --- .../mod/tile/FilterSettings.java | 11 +++++++++- .../actuallyadditions/mod/util/WorldUtil.java | 20 +++++++++++-------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/FilterSettings.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/FilterSettings.java index a453fd100..d5dc2e1ac 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/FilterSettings.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/FilterSettings.java @@ -210,6 +210,15 @@ public class FilterSettings{ } public boolean check(ItemStack stack){ - return check(stack, this.filterInventory, this.isWhitelist, this.respectMeta, this.respectNBT, this.respectMod, this.respectOredict); + return !this.needsCheck() || check(stack, this.filterInventory, this.isWhitelist, this.respectMeta, this.respectNBT, this.respectMod, this.respectOredict); + } + + public boolean needsCheck(){ + for(int i = 0; i < this.filterInventory.getSlots(); i++){ + if(StackUtil.isValid(this.filterInventory.getStackInSlot(i))){ + return true; + } + } + return this.isWhitelist; } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/util/WorldUtil.java b/src/main/java/de/ellpeck/actuallyadditions/mod/util/WorldUtil.java index b00c56c0a..3362d118d 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/util/WorldUtil.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/util/WorldUtil.java @@ -87,8 +87,9 @@ public final class WorldUtil{ if(handler instanceof ISlotlessItemHandler){ ISlotlessItemHandler slotless = (ISlotlessItemHandler)handler; - if(filter == null){ + if(filter == null || !filter.needsCheck()){ extracted = slotless.extractItem(maxExtract, simulate); + return extracted; } else{ ItemStack would = slotless.extractItem(maxExtract, true); @@ -100,6 +101,7 @@ public final class WorldUtil{ extracted = slotless.extractItem(maxExtract, false); } } + //Leave the possibility to fall back to vanilla when there is a filter } } } @@ -108,7 +110,7 @@ public final class WorldUtil{ IItemHandler handler = extractWrapper.getNormalHandler(); if(handler != null){ for(int i = Math.max(0, slotStart); i < Math.min(slotEnd, handler.getSlots()); i++){ - if(filter == null || filter.check(handler.getStackInSlot(i))){ + if(filter == null || !filter.needsCheck() || filter.check(handler.getStackInSlot(i))){ extracted = handler.extractItem(i, maxExtract, simulate); if(StackUtil.isValid(extracted)){ @@ -129,15 +131,17 @@ public final class WorldUtil{ Object handler = insertWrapper.getSlotlessHandler(); if(handler instanceof ISlotlessItemHandler){ remain = ((ISlotlessItemHandler)handler).insertItem(remain, simulate); + + if(!ItemStack.areItemStacksEqual(remain, stack)){ + return remain; + } } } - if(StackUtil.isValid(remain)){ - IItemHandler handler = insertWrapper.getNormalHandler(); - if(handler != null){ - for(int i = Math.max(0, slotStart); i < Math.min(slotEnd, handler.getSlots()); i++){ - remain = handler.insertItem(i, remain, simulate); - } + IItemHandler handler = insertWrapper.getNormalHandler(); + if(handler != null){ + for(int i = Math.max(0, slotStart); i < Math.min(slotEnd, handler.getSlots()); i++){ + remain = handler.insertItem(i, remain, simulate); } }