Restore filter filtering functionality
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.raoulvdberge.refinedstorage.apiimpl.network.node;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.RS;
|
||||
import com.raoulvdberge.refinedstorage.RSItems;
|
||||
import com.raoulvdberge.refinedstorage.api.util.Action;
|
||||
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.cover.CoverManager;
|
||||
@@ -8,6 +9,7 @@ import com.raoulvdberge.refinedstorage.inventory.fluid.FluidInventory;
|
||||
import com.raoulvdberge.refinedstorage.inventory.item.ItemHandlerBase;
|
||||
import com.raoulvdberge.refinedstorage.inventory.item.ItemHandlerUpgrade;
|
||||
import com.raoulvdberge.refinedstorage.inventory.listener.ListenerNetworkNode;
|
||||
import com.raoulvdberge.refinedstorage.item.ItemFilter;
|
||||
import com.raoulvdberge.refinedstorage.item.ItemUpgrade;
|
||||
import com.raoulvdberge.refinedstorage.tile.TileExporter;
|
||||
import com.raoulvdberge.refinedstorage.tile.config.IComparable;
|
||||
@@ -83,21 +85,15 @@ public class NetworkNodeExporter extends NetworkNode implements IComparable, ITy
|
||||
ItemStack slot = itemFilters.getStackInSlot(filterSlot);
|
||||
|
||||
if (!slot.isEmpty()) {
|
||||
int stackSize = upgrades.getItemInteractCount();
|
||||
|
||||
ItemStack took = network.extractItem(slot, Math.min(slot.getMaxStackSize(), stackSize), compare, Action.SIMULATE);
|
||||
|
||||
if (took == null) {
|
||||
if (upgrades.hasUpgrade(ItemUpgrade.TYPE_CRAFTING)) {
|
||||
network.getCraftingManager().request(new SlottedCraftingRequest(this, filterSlot), slot, stackSize);
|
||||
}
|
||||
} else if (ItemHandlerHelper.insertItem(handler, took, true).isEmpty()) {
|
||||
took = network.extractItem(slot, Math.min(slot.getMaxStackSize(), stackSize), compare, Action.PERFORM);
|
||||
|
||||
if (took != null) {
|
||||
ItemHandlerHelper.insertItem(handler, took, false);
|
||||
}
|
||||
}
|
||||
if (slot.getItem() == RSItems.FILTER) {
|
||||
for (ItemStack slotFilter : ItemFilter.getFilterItemsFromCache(slot)) {
|
||||
if (!slotFilter.isEmpty()) {
|
||||
doExport(handler, slotFilter);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
doExport(handler, slot);
|
||||
}
|
||||
}
|
||||
|
||||
filterSlot++;
|
||||
@@ -152,6 +148,24 @@ public class NetworkNodeExporter extends NetworkNode implements IComparable, ITy
|
||||
}
|
||||
}
|
||||
|
||||
private void doExport(IItemHandler handler, ItemStack slot) {
|
||||
int stackSize = upgrades.getItemInteractCount();
|
||||
|
||||
ItemStack took = network.extractItem(slot, Math.min(slot.getMaxStackSize(), stackSize), compare, Action.SIMULATE);
|
||||
|
||||
if (took == null) {
|
||||
if (upgrades.hasUpgrade(ItemUpgrade.TYPE_CRAFTING)) {
|
||||
network.getCraftingManager().request(new SlottedCraftingRequest(this, filterSlot), slot, stackSize);
|
||||
}
|
||||
} else if (ItemHandlerHelper.insertItem(handler, took, true).isEmpty()) {
|
||||
took = network.extractItem(slot, Math.min(slot.getMaxStackSize(), stackSize), compare, Action.PERFORM);
|
||||
|
||||
if (took != null) {
|
||||
ItemHandlerHelper.insertItem(handler, took, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCompare() {
|
||||
return compare;
|
||||
|
||||
@@ -15,11 +15,13 @@ import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
@@ -28,7 +30,9 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ItemFilter extends ItemBase {
|
||||
private static final String NBT_COMPARE = "Compare";
|
||||
@@ -40,6 +44,13 @@ public class ItemFilter extends ItemBase {
|
||||
private static final String NBT_TYPE = "Type";
|
||||
public static final String NBT_FLUID_FILTERS = "FluidFilters";
|
||||
|
||||
private static Map<ItemStack, NonNullList<ItemStack>> FILTER_CACHE = new HashMap<>();
|
||||
|
||||
public static NonNullList<ItemStack> getFilterItemsFromCache(ItemStack stack) {
|
||||
FILTER_CACHE.putIfAbsent(stack, new ItemHandlerFilterItems(stack).getFilteredItems());
|
||||
return FILTER_CACHE.get(stack);
|
||||
}
|
||||
|
||||
public ItemFilter() {
|
||||
super(new ItemInfo(RS.ID, "filter"));
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.raoulvdberge.refinedstorage.tile.config;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.RSItems;
|
||||
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNodeProxy;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import com.raoulvdberge.refinedstorage.inventory.fluid.FluidInventory;
|
||||
import com.raoulvdberge.refinedstorage.item.ItemFilter;
|
||||
import com.raoulvdberge.refinedstorage.tile.data.TileDataParameter;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.datasync.DataSerializers;
|
||||
@@ -24,21 +26,44 @@ public interface IFilterable {
|
||||
|
||||
static boolean acceptsItem(IItemHandler filters, int mode, int compare, ItemStack stack) {
|
||||
if (mode == WHITELIST) {
|
||||
int slots = 0;
|
||||
|
||||
for (int i = 0; i < filters.getSlots(); ++i) {
|
||||
ItemStack slot = filters.getStackInSlot(i);
|
||||
|
||||
if (API.instance().getComparer().isEqual(slot, stack, compare)) {
|
||||
return true;
|
||||
if (!slot.isEmpty()) {
|
||||
slots++;
|
||||
|
||||
if (slot.getItem() == RSItems.FILTER) {
|
||||
for (ItemStack slotInFilter : ItemFilter.getFilterItemsFromCache(slot)) {
|
||||
if (!slotInFilter.isEmpty() && API.instance().getComparer().isEqual(
|
||||
slotInFilter,
|
||||
stack,
|
||||
compare
|
||||
)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else if (API.instance().getComparer().isEqual(slot, stack, compare)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return slots == 0;
|
||||
} else if (mode == BLACKLIST) {
|
||||
for (int i = 0; i < filters.getSlots(); ++i) {
|
||||
ItemStack slot = filters.getStackInSlot(i);
|
||||
|
||||
if (API.instance().getComparer().isEqual(slot, stack, compare)) {
|
||||
return false;
|
||||
if (!slot.isEmpty()) {
|
||||
if (slot.getItem() == RSItems.FILTER) {
|
||||
for (ItemStack slotInFilter : ItemFilter.getFilterItemsFromCache(slot)) {
|
||||
if (!slotInFilter.isEmpty() && API.instance().getComparer().isEqual(slotInFilter, stack, compare)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else if (API.instance().getComparer().isEqual(slot, stack, compare)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user