Fix Filters Closes #1209

This commit is contained in:
Shadows_of_Fire 2019-02-06 15:27:38 -05:00
parent 7fe79f09be
commit 06ca0ad4cd

View file

@ -20,7 +20,6 @@ import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.OreDictionary;
public class FilterSettings { public class FilterSettings {
@ -69,14 +68,9 @@ public class FilterSettings{
ItemDrill.loadSlotsFromNBT(inv, slot); ItemDrill.loadSlotsFromNBT(inv, slot);
for (int k = 0; k < inv.getSlots(); k++) { for (int k = 0; k < inv.getSlots(); k++) {
ItemStack filterSlot = inv.getStackInSlot(k); ItemStack filterSlot = inv.getStackInSlot(k);
if(StackUtil.isValid(filterSlot) && areEqualEnough(filterSlot, stack, meta, nbt, mod, oredict)){ if (StackUtil.isValid(filterSlot) && areEqualEnough(filterSlot, stack, meta, nbt, mod, oredict)) { return whitelist; }
return whitelist;
}
}
}
else if(areEqualEnough(slot, stack, meta, nbt, mod, oredict)){
return whitelist;
} }
} else if (areEqualEnough(slot, stack, meta, nbt, mod, oredict)) { return whitelist; }
} }
} }
} }
@ -86,30 +80,9 @@ public class FilterSettings{
private static boolean areEqualEnough(ItemStack first, ItemStack second, boolean meta, boolean nbt, boolean mod, int oredict) { private static boolean areEqualEnough(ItemStack first, ItemStack second, boolean meta, boolean nbt, boolean mod, int oredict) {
Item firstItem = first.getItem(); Item firstItem = first.getItem();
Item secondItem = second.getItem(); Item secondItem = second.getItem();
if(mod){ if (mod && firstItem.getRegistryName().getNamespace().equals(secondItem.getRegistryName().getNamespace())) return true;
ResourceLocation firstReg = firstItem.getRegistryName();
ResourceLocation secondReg = secondItem.getRegistryName();
if(firstReg != null && secondReg != null){
String firstDomain = firstReg.getNamespace();
String secondDomain = secondReg.getNamespace();
if(firstDomain != null && secondDomain != null){
if(!firstDomain.equals(secondDomain)){
return false;
}
}
}
}
else if(firstItem != secondItem){
return false;
}
boolean metaFine = !meta || first.getItemDamage() == second.getItemDamage(); if (oredict != 0) {
boolean nbtFine = !nbt || ItemStack.areItemStackTagsEqual(first, second);
if(metaFine && nbtFine){
if(oredict == 0){
return true;
}
else{
int[] firstIds = OreDictionary.getOreIDs(first); int[] firstIds = OreDictionary.getOreIDs(first);
int[] secondIds = OreDictionary.getOreIDs(second); int[] secondIds = OreDictionary.getOreIDs(second);
boolean firstEmpty = ArrayUtils.isEmpty(firstIds); boolean firstEmpty = ArrayUtils.isEmpty(firstIds);
@ -122,19 +95,14 @@ public class FilterSettings{
//Only one empty, meaning they are not equal //Only one empty, meaning they are not equal
else if (firstEmpty || secondEmpty) { else if (firstEmpty || secondEmpty) {
return false; return false;
} } else {
else{
for (int id : firstIds) { for (int id : firstIds) {
if (ArrayUtils.contains(secondIds, id)) { if (ArrayUtils.contains(secondIds, id)) {
//Needs to match only one id, so return true on first match //Needs to match only one id, so return true on first match
if(oredict == 1){ if (oredict == 1) { return true; }
return true;
}
} }
//Needs to match every id, so just return false when no match //Needs to match every id, so just return false when no match
else if(oredict == 2){ else if (oredict == 2) { return false; }
return false;
}
} }
//If oredict mode 1, this will fail because nothing matched //If oredict mode 1, this will fail because nothing matched
@ -142,11 +110,14 @@ public class FilterSettings{
return oredict == 2; return oredict == 2;
} }
} }
}
else{ if (firstItem != secondItem) return false;
boolean metaFine = !meta || first.getItemDamage() == second.getItemDamage();
boolean nbtFine = !nbt || ItemStack.areItemStackTagsEqual(first, second);
if (metaFine && nbtFine) return true;
return false; return false;
} }
}
public void writeToNBT(NBTTagCompound tag, String name) { public void writeToNBT(NBTTagCompound tag, String name) {
NBTTagCompound compound = new NBTTagCompound(); NBTTagCompound compound = new NBTTagCompound();
@ -184,14 +155,11 @@ public class FilterSettings{
public void onButtonPressed(int id) { public void onButtonPressed(int id) {
if (id == this.whitelistButtonId) { if (id == this.whitelistButtonId) {
this.isWhitelist = !this.isWhitelist; this.isWhitelist = !this.isWhitelist;
} } else if (id == this.metaButtonId) {
else if(id == this.metaButtonId){
this.respectMeta = !this.respectMeta; this.respectMeta = !this.respectMeta;
} } else if (id == this.nbtButtonId) {
else if(id == this.nbtButtonId){
this.respectNBT = !this.respectNBT; this.respectNBT = !this.respectNBT;
} } else if (id == this.modButtonId) {
else if(id == this.modButtonId){
this.respectMod = !this.respectMod; this.respectMod = !this.respectMod;
if (this.respectMod) { if (this.respectMod) {
@ -199,12 +167,10 @@ public class FilterSettings{
this.respectNBT = false; this.respectNBT = false;
this.respectOredict = 0; this.respectOredict = 0;
} }
} } else if (id == this.oredictButtonId) {
else if(id == this.oredictButtonId){
if (this.respectOredict + 1 > 2) { if (this.respectOredict + 1 > 2) {
this.respectOredict = 0; this.respectOredict = 0;
} } else {
else{
this.respectOredict++; this.respectOredict++;
} }
} }
@ -216,9 +182,7 @@ public class FilterSettings{
public boolean needsCheck() { public boolean needsCheck() {
for (int i = 0; i < this.filterInventory.getSlots(); i++) { for (int i = 0; i < this.filterInventory.getSlots(); i++) {
if(StackUtil.isValid(this.filterInventory.getStackInSlot(i))){ if (StackUtil.isValid(this.filterInventory.getStackInSlot(i))) { return true; }
return true;
}
} }
return this.isWhitelist; return this.isWhitelist;
} }