Created
August 6, 2019 21:58
-
-
Save hnOsmium0001/c21e8efb2ce54c3968c993463aa784f7 to your computer and use it in GitHub Desktop.
Item filtering logic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import net.minecraft.item.ItemStack; | |
@FunctionalInterface | |
public interface IItemFilter { | |
boolean isValid(ItemStack stack); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import net.minecraft.item.ItemStack; | |
public class WhitelistFilter implements IItemFilter { | |
public static final int LISTING_MODE = 1; | |
public static final int DAMAGE = 1 << 2; | |
public static final int NBT = 1 << 3; | |
public static final int ORE_DICT = 1 << 4; | |
private ItemStack filter; | |
private int mode; | |
@Override | |
public boolean isValid(ItemStack stack) { | |
return filter.isItemEqualIgnoreDurability(stack); | |
} | |
public boolean isComparingDamage() { | |
return isComparing(DAMAGE); | |
} | |
public boolean isComparingNBT() { | |
return isComparing(NBT); | |
} | |
public boolean isComparingOreDict() { | |
return isComparing(ORE_DICT); | |
} | |
public boolean isComparing(int mask) { | |
return (mode | mask) == mode; | |
} | |
public void setMatchDamage() { | |
setMatch(DAMAGE); | |
} | |
public void setMatchNBT() { | |
setMatch(NBT); | |
} | |
public void setMatchOreDict() { | |
setMatch(ORE_DICT); | |
} | |
public void setMatch(int mask) { | |
mode = mode | mask; | |
} | |
public void setIgnoreDamage() { | |
setIgnore(DAMAGE); | |
} | |
public void setIgnoreNBT() { | |
setIgnore(NBT); | |
} | |
public void setIgnoreOreDict() { | |
setIgnore(ORE_DICT); | |
} | |
public void setIgnore(int mask) { | |
mode = mode & ~mask; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment