Fixed oredict not working, fixes #1130
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
- Storage Monitors don't render any quantity text when no item is specified to monitor anymore (raoulvdberge)
|
||||
- Fixed bug where disks in Disk Drive didn't respect access type or void excess stacks option (raoulvdberge)
|
||||
- Fixed crash in Disk Manipulator (raoulvdberge)
|
||||
- Fixed oredict not working (raoulvdberge)
|
||||
- You can now shift click Grid Filters into a Grid instead of manually inserting them (raoulvdberge)
|
||||
- The Solderer inventory isn't sided anymore (raoulvdberge)
|
||||
|
||||
|
||||
@@ -48,6 +48,8 @@ import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
import net.minecraftforge.items.wrapper.InvWrapper;
|
||||
import net.minecraftforge.items.wrapper.SidedInvWrapper;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -55,9 +57,7 @@ import javax.annotation.Nullable;
|
||||
import java.math.RoundingMode;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
|
||||
public final class RSUtils {
|
||||
@@ -69,10 +69,55 @@ public final class RSUtils {
|
||||
private static final String NBT_SLOT = "Slot";
|
||||
private static final String NBT_ACCESS_TYPE = "AccessType";
|
||||
|
||||
private static final Map<Integer, List<ItemStack>> OREDICT_CACHE = new HashMap<>();
|
||||
private static final Map<Integer, Boolean> OREDICT_EQUIVALENCY_CACHE = new HashMap<>();
|
||||
|
||||
static {
|
||||
QUANTITY_FORMATTER.setRoundingMode(RoundingMode.DOWN);
|
||||
}
|
||||
|
||||
public static List<ItemStack> getEquivalentStacks(ItemStack stack) {
|
||||
int hash = API.instance().getItemStackHashCode(stack, false);
|
||||
|
||||
if (OREDICT_CACHE.containsKey(hash)) {
|
||||
return OREDICT_CACHE.get(hash);
|
||||
}
|
||||
|
||||
List<ItemStack> ores = new ArrayList<>();
|
||||
|
||||
for (int id : OreDictionary.getOreIDs(stack)) {
|
||||
ores.addAll(OreDictionary.getOres(OreDictionary.getOreName(id)));
|
||||
}
|
||||
|
||||
OREDICT_CACHE.put(hash, ores);
|
||||
|
||||
return ores;
|
||||
}
|
||||
|
||||
public static boolean areStacksEquivalent(ItemStack left, ItemStack right) {
|
||||
int code = API.instance().getItemStackHashCode(left, false);
|
||||
code = 31 * code + API.instance().getItemStackHashCode(right, false);
|
||||
|
||||
if (OREDICT_EQUIVALENCY_CACHE.containsKey(code)) {
|
||||
return OREDICT_EQUIVALENCY_CACHE.get(code);
|
||||
}
|
||||
|
||||
int[] leftIds = OreDictionary.getOreIDs(left);
|
||||
int[] rightIds = OreDictionary.getOreIDs(right);
|
||||
|
||||
for (int i : rightIds) {
|
||||
if (ArrayUtils.contains(leftIds, i)) {
|
||||
OREDICT_EQUIVALENCY_CACHE.put(code, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
OREDICT_EQUIVALENCY_CACHE.put(code, false);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void writeItemStack(ByteBuf buf, ItemStack stack) {
|
||||
writeItemStack(buf, stack, null, false);
|
||||
}
|
||||
|
||||
@@ -2,9 +2,11 @@ package com.raoulvdberge.refinedstorage.apiimpl.storage;
|
||||
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.raoulvdberge.refinedstorage.RSUtils;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageDisk;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.StorageDiskType;
|
||||
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -14,6 +16,7 @@ import net.minecraftforge.items.ItemHandlerHelper;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@@ -190,7 +193,23 @@ public class StorageDiskItem implements IStorageDisk<ItemStack> {
|
||||
@Override
|
||||
@Nullable
|
||||
public synchronized ItemStack extract(@Nonnull ItemStack stack, int size, int flags, boolean simulate) {
|
||||
for (ItemStack otherStack : stacks.get(stack.getItem())) {
|
||||
Collection<ItemStack> toAttempt = null;
|
||||
|
||||
if ((flags & IComparer.COMPARE_OREDICT) == IComparer.COMPARE_OREDICT) {
|
||||
for (ItemStack ore : RSUtils.getEquivalentStacks(stack)) {
|
||||
if (toAttempt == null) {
|
||||
toAttempt = new ArrayList<>(stacks.get(ore.getItem()));
|
||||
} else {
|
||||
toAttempt.addAll(stacks.get(ore.getItem()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (toAttempt == null) {
|
||||
toAttempt = stacks.get(stack.getItem());
|
||||
}
|
||||
|
||||
for (ItemStack otherStack : toAttempt) {
|
||||
if (API.instance().getComparer().isEqual(otherStack, stack, flags)) {
|
||||
if (size > otherStack.getCount()) {
|
||||
size = otherStack.getCount();
|
||||
|
||||
@@ -1,23 +1,18 @@
|
||||
package com.raoulvdberge.refinedstorage.apiimpl.util;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.RSUtils;
|
||||
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import com.raoulvdberge.refinedstorage.block.BlockNode;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Comparer implements IComparer {
|
||||
private Map<Integer, Boolean> oredictCache = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public boolean isEqual(@Nullable ItemStack left, @Nullable ItemStack right, int flags) {
|
||||
EnumActionResult validity = validityCheck(left, right);
|
||||
@@ -119,28 +114,7 @@ public class Comparer implements IComparer {
|
||||
return validity == EnumActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
// We do not care about the NBT tag since the oredict doesn't care either, and generating a NBT hashcode is slow.
|
||||
int code = API.instance().getItemStackHashCode(left, false);
|
||||
code = 31 * code + API.instance().getItemStackHashCode(right, false);
|
||||
|
||||
if (oredictCache.containsKey(code)) {
|
||||
return oredictCache.get(code);
|
||||
}
|
||||
|
||||
int[] leftIds = OreDictionary.getOreIDs(left);
|
||||
int[] rightIds = OreDictionary.getOreIDs(right);
|
||||
|
||||
for (int i : rightIds) {
|
||||
if (ArrayUtils.contains(leftIds, i)) {
|
||||
oredictCache.put(code, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
oredictCache.put(code, false);
|
||||
|
||||
return false;
|
||||
return RSUtils.areStacksEquivalent(left, right);
|
||||
}
|
||||
|
||||
private EnumActionResult validityCheck(@Nullable ItemStack left, @Nullable ItemStack right) {
|
||||
|
||||
@@ -71,6 +71,7 @@ public class GridStackItem implements IGridStack {
|
||||
if (oreIds == null) {
|
||||
oreIds = Arrays.stream(OreDictionary.getOreIDs(stack)).mapToObj(OreDictionary::getOreName).collect(Collectors.toList()).toArray(new String[0]);
|
||||
}
|
||||
|
||||
return oreIds;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user