mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-22 15:18:34 +01:00
Fix Filters Closes #1209
This commit is contained in:
parent
7fe79f09be
commit
06ca0ad4cd
1 changed files with 62 additions and 98 deletions
|
@ -20,7 +20,6 @@ import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
|||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
public class FilterSettings {
|
||||
|
@ -69,14 +68,9 @@ public class FilterSettings{
|
|||
ItemDrill.loadSlotsFromNBT(inv, slot);
|
||||
for (int k = 0; k < inv.getSlots(); k++) {
|
||||
ItemStack filterSlot = inv.getStackInSlot(k);
|
||||
if(StackUtil.isValid(filterSlot) && areEqualEnough(filterSlot, stack, meta, nbt, mod, oredict)){
|
||||
return whitelist;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(areEqualEnough(slot, stack, meta, nbt, mod, oredict)){
|
||||
return whitelist;
|
||||
if (StackUtil.isValid(filterSlot) && areEqualEnough(filterSlot, 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) {
|
||||
Item firstItem = first.getItem();
|
||||
Item secondItem = second.getItem();
|
||||
if(mod){
|
||||
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;
|
||||
}
|
||||
if (mod && firstItem.getRegistryName().getNamespace().equals(secondItem.getRegistryName().getNamespace())) return true;
|
||||
|
||||
boolean metaFine = !meta || first.getItemDamage() == second.getItemDamage();
|
||||
boolean nbtFine = !nbt || ItemStack.areItemStackTagsEqual(first, second);
|
||||
if(metaFine && nbtFine){
|
||||
if(oredict == 0){
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
if (oredict != 0) {
|
||||
int[] firstIds = OreDictionary.getOreIDs(first);
|
||||
int[] secondIds = OreDictionary.getOreIDs(second);
|
||||
boolean firstEmpty = ArrayUtils.isEmpty(firstIds);
|
||||
|
@ -122,19 +95,14 @@ public class FilterSettings{
|
|||
//Only one empty, meaning they are not equal
|
||||
else if (firstEmpty || secondEmpty) {
|
||||
return false;
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
for (int id : firstIds) {
|
||||
if (ArrayUtils.contains(secondIds, id)) {
|
||||
//Needs to match only one id, so return true on first match
|
||||
if(oredict == 1){
|
||||
return true;
|
||||
}
|
||||
if (oredict == 1) { return true; }
|
||||
}
|
||||
//Needs to match every id, so just return false when no match
|
||||
else if(oredict == 2){
|
||||
return false;
|
||||
}
|
||||
else if (oredict == 2) { return false; }
|
||||
|
||||
}
|
||||
//If oredict mode 1, this will fail because nothing matched
|
||||
|
@ -142,11 +110,14 @@ public class FilterSettings{
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound tag, String name) {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
|
@ -184,14 +155,11 @@ public class FilterSettings{
|
|||
public void onButtonPressed(int id) {
|
||||
if (id == this.whitelistButtonId) {
|
||||
this.isWhitelist = !this.isWhitelist;
|
||||
}
|
||||
else if(id == this.metaButtonId){
|
||||
} else if (id == this.metaButtonId) {
|
||||
this.respectMeta = !this.respectMeta;
|
||||
}
|
||||
else if(id == this.nbtButtonId){
|
||||
} else if (id == this.nbtButtonId) {
|
||||
this.respectNBT = !this.respectNBT;
|
||||
}
|
||||
else if(id == this.modButtonId){
|
||||
} else if (id == this.modButtonId) {
|
||||
this.respectMod = !this.respectMod;
|
||||
|
||||
if (this.respectMod) {
|
||||
|
@ -199,12 +167,10 @@ public class FilterSettings{
|
|||
this.respectNBT = false;
|
||||
this.respectOredict = 0;
|
||||
}
|
||||
}
|
||||
else if(id == this.oredictButtonId){
|
||||
} else if (id == this.oredictButtonId) {
|
||||
if (this.respectOredict + 1 > 2) {
|
||||
this.respectOredict = 0;
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
this.respectOredict++;
|
||||
}
|
||||
}
|
||||
|
@ -216,9 +182,7 @@ public class FilterSettings{
|
|||
|
||||
public boolean needsCheck() {
|
||||
for (int i = 0; i < this.filterInventory.getSlots(); i++) {
|
||||
if(StackUtil.isValid(this.filterInventory.getStackInSlot(i))){
|
||||
return true;
|
||||
}
|
||||
if (StackUtil.isValid(this.filterInventory.getStackInSlot(i))) { return true; }
|
||||
}
|
||||
return this.isWhitelist;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue