Added filter mod mode

This commit is contained in:
Ellpeck 2016-11-17 14:56:26 +01:00
parent 31bbbe2902
commit 346b0b54f7
9 changed files with 123 additions and 72 deletions

View file

@ -33,7 +33,7 @@ import java.util.Arrays;
public class ContainerBag extends Container implements IButtonReactor{
public final FilterSettings filter = new FilterSettings(0, 4, false, true, false, 0, -1000);
public final FilterSettings filter = new FilterSettings(0, 4, false, true, false, false, 0, -1000);
private final InventoryBag bagInventory;
private final InventoryPlayer inventory;
private final boolean isVoid;
@ -110,6 +110,7 @@ public class ContainerBag extends Container implements IButtonReactor{
listener.sendProgressBarUpdate(this, 2, this.filter.respectNBT ? 1 : 0);
listener.sendProgressBarUpdate(this, 3, this.filter.respectOredict);
listener.sendProgressBarUpdate(this, 4, this.autoInsert ? 1 : 0);
listener.sendProgressBarUpdate(this, 5, this.filter.respectMod ? 1 : 0);
}
this.filter.updateLasts();
this.oldAutoInsert = this.autoInsert;
@ -134,6 +135,9 @@ public class ContainerBag extends Container implements IButtonReactor{
else if(id == 4){
this.autoInsert = data == 1;
}
else if(id == 5){
this.filter.respectMod = data == 1;
}
}
@Override

View file

@ -34,31 +34,36 @@ public class FilterSettingsGui extends Gui{
public SmallerButton whitelistButton;
public SmallerButton metaButton;
public SmallerButton nbtButton;
public SmallerButton modButton;
public SmallerButton oredictButton;
public FilterSettingsGui(FilterSettings settings, int x, int y, List<GuiButton> buttonList){
this.theSettings = settings;
this.whitelistButton = new SmallerButton(this.theSettings.whitelistButtonId, x, y, "");
this.whitelistButton = new SmallerButton(this.theSettings.whitelistButtonId, x, y, "", true);
buttonList.add(this.whitelistButton);
this.metaButton = new SmallerButton(this.theSettings.metaButtonId, x, y+18, "");
y+=14;
this.metaButton = new SmallerButton(this.theSettings.metaButtonId, x, y, "", true);
buttonList.add(this.metaButton);
this.nbtButton = new SmallerButton(this.theSettings.nbtButtonId, x, y+36, "");
y+=14;
this.nbtButton = new SmallerButton(this.theSettings.nbtButtonId, x, y, "", true);
buttonList.add(this.nbtButton);
this.oredictButton = new SmallerButton(this.theSettings.oredictButtonId, x, y+54, "");
y+=14;
this.oredictButton = new SmallerButton(this.theSettings.oredictButtonId, x, y, "", true);
buttonList.add(this.oredictButton);
y+=15;
this.modButton = new SmallerButton(this.theSettings.modButtonId, x, y, "", true);
buttonList.add(this.modButton);
this.update();
}
public void update(){
this.whitelistButton.displayString = (this.theSettings.isWhitelist ? TextFormatting.DARK_GREEN : TextFormatting.RED)+"W";
this.metaButton.displayString = (this.theSettings.respectMeta ? TextFormatting.DARK_GREEN : TextFormatting.RED)+"M";
this.nbtButton.displayString = (this.theSettings.respectNBT ? TextFormatting.DARK_GREEN : TextFormatting.RED)+"N";
this.oredictButton.displayString = (this.theSettings.respectOredict == 0 ? TextFormatting.RED : (this.theSettings.respectOredict == 1 ? TextFormatting.GREEN : TextFormatting.DARK_GREEN))+"O";
this.whitelistButton.displayString = (this.theSettings.isWhitelist ? TextFormatting.DARK_GREEN : TextFormatting.RED)+"WH";
this.metaButton.displayString = (this.theSettings.respectMeta ? TextFormatting.DARK_GREEN : TextFormatting.RED)+"ME";
this.nbtButton.displayString = (this.theSettings.respectNBT ? TextFormatting.DARK_GREEN : TextFormatting.RED)+"NB";
this.modButton.displayString = (this.theSettings.respectMod ? TextFormatting.DARK_GREEN : TextFormatting.RED)+"MO";
this.oredictButton.displayString = (this.theSettings.respectOredict == 0 ? TextFormatting.RED : (this.theSettings.respectOredict == 1 ? TextFormatting.GREEN : TextFormatting.DARK_GREEN))+"OR";
}
public void drawHover(int mouseX, int mouseY){
@ -76,6 +81,12 @@ public class FilterSettingsGui extends Gui{
else if(this.nbtButton.isMouseOver()){
GuiUtils.drawHoveringText(Collections.singletonList(TextFormatting.BOLD+(this.theSettings.respectNBT ? "Respecting" : "Ignoring")+" NBT"), mouseX, mouseY, mc.displayWidth, mc.displayHeight, -1, mc.fontRendererObj);
}
else if(this.modButton.isMouseOver()){
List<String> list = new ArrayList<String>();
list.add(TextFormatting.BOLD+"Mod Mode "+(this.theSettings.respectMod ? "On" : "Off"));
list.addAll(mc.fontRendererObj.listFormattedStringToWidth("If this is enabled, the filter will compare the mods items come from "+TextFormatting.RED+"instead of comparing the items themselves"+TextFormatting.RESET+". This can be useful for storage systems with mod-based chests. \nCan also be combined with the other options, but that normally isn't very useful.", 200));
GuiUtils.drawHoveringText(list, mouseX, mouseY, mc.displayWidth, mc.displayHeight, -1, mc.fontRendererObj);
}
else if(this.oredictButton.isMouseOver()){
List<String> list = new ArrayList<String>();
list.add(TextFormatting.BOLD+(this.theSettings.respectOredict == 0 ? "Ignoring" : (this.theSettings.respectOredict == 1 ? "Soft Respecting" : "Hard Respecting"))+" OreDictionary");

View file

@ -265,9 +265,15 @@ public class GuiInputter extends GuiContainer{
public static class SmallerButton extends GuiButton{
public final ResourceLocation resLoc = AssetUtil.getGuiLocation("guiInputter");
private final boolean smaller;
public SmallerButton(int id, int x, int y, String display){
super(id, x, y, 16, 16, display);
this(id, x, y, display, false);
}
public SmallerButton(int id, int x, int y, String display, boolean smaller){
super(id, x, y, 16, smaller ? 12 : 16, display);
this.smaller = smaller;
}
@Override
@ -280,7 +286,7 @@ public class GuiInputter extends GuiContainer{
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
GlStateManager.blendFunc(770, 771);
this.drawTexturedModalRect(this.xPosition, this.yPosition, 176, k*16, 16, 16);
this.drawTexturedModalRect(this.xPosition, this.yPosition, this.smaller ? 200 : 176, k*this.height, this.width, this.height);
this.mouseDragged(mc, x, y);
int color = 14737632;

View file

@ -78,7 +78,7 @@ public class ItemBag extends ItemBase{
ItemStack[] inventory = new ItemStack[ContainerBag.getSlotAmount(isVoid)];
ItemDrill.loadSlotsFromNBT(inventory, invStack);
FilterSettings filter = new FilterSettings(0, 4, false, false, false, 0, 0);
FilterSettings filter = new FilterSettings(0, 4, false, false, false, false, 0, 0);
filter.readFromNBT(invStack.getTagCompound(), "Filter");
if(filter.check(stack, inventory)){
if(isVoid){

View file

@ -14,48 +14,58 @@ import de.ellpeck.actuallyadditions.mod.inventory.ContainerFilter;
import de.ellpeck.actuallyadditions.mod.items.ItemDrill;
import de.ellpeck.actuallyadditions.mod.items.ItemFilter;
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;
import org.apache.commons.lang3.ArrayUtils;
public class FilterSettings{
public final int startSlot;
public final int endSlot;
public final int whitelistButtonId;
public final int metaButtonId;
public final int nbtButtonId;
public final int oredictButtonId;
public final int modButtonId;
public final int startSlot;
public final int endSlot;
public boolean isWhitelist;
public boolean respectMeta;
public boolean respectNBT;
public boolean respectMod;
public int respectOredict;
private boolean lastWhitelist;
private boolean lastRespectMeta;
private boolean lastRespectNBT;
private boolean lastRespectMod;
private int lastRecpectOredict;
public FilterSettings(int startSlot, int endSlot, boolean defaultWhitelist, boolean defaultRespectMeta, boolean defaultRespectNBT, int defaultRespectOredict, int buttonIdStart){
public FilterSettings(int startSlot, int endSlot, boolean defaultWhitelist, boolean defaultRespectMeta, boolean defaultRespectNBT, boolean defaultRespectMod, int defaultRespectOredict, int buttonIdStart){
this.startSlot = startSlot;
this.endSlot = endSlot;
this.isWhitelist = defaultWhitelist;
this.respectMeta = defaultRespectMeta;
this.respectNBT = defaultRespectNBT;
this.respectMod = defaultRespectMod;
this.respectOredict = defaultRespectOredict;
this.whitelistButtonId = buttonIdStart;
this.metaButtonId = buttonIdStart+1;
this.nbtButtonId = buttonIdStart+2;
this.oredictButtonId = buttonIdStart+3;
this.modButtonId = buttonIdStart+4;
}
public static boolean check(ItemStack stack, ItemStack[] slots, int startSlot, int endSlot, boolean whitelist, boolean meta, boolean nbt, int oredict){
public static boolean check(ItemStack stack, ItemStack[] slots, int startSlot, int endSlot, boolean whitelist, boolean meta, boolean nbt, boolean mod, int oredict){
if(StackUtil.isValid(stack)){
for(int i = startSlot; i < endSlot; i++){
if(StackUtil.isValid(slots[i])){
if(areEqualEnough(slots[i], stack, meta, nbt, oredict)){
if(areEqualEnough(slots[i], stack, meta, nbt, mod, oredict)){
return whitelist;
}
else if(slots[i].getItem() instanceof ItemFilter){
@ -63,7 +73,7 @@ public class FilterSettings{
ItemDrill.loadSlotsFromNBT(filterSlots, slots[i]);
if(filterSlots != null && filterSlots.length > 0){
for(ItemStack filterSlot : filterSlots){
if(StackUtil.isValid(filterSlot) && areEqualEnough(filterSlot, stack, meta, nbt, oredict)){
if(StackUtil.isValid(filterSlot) && areEqualEnough(filterSlot, stack, meta, nbt, mod, oredict)){
return whitelist;
}
}
@ -75,54 +85,68 @@ public class FilterSettings{
return !whitelist;
}
private static boolean areEqualEnough(ItemStack first, ItemStack second, boolean meta, boolean nbt, int oredict){
if(first.getItem() != second.getItem()){
return false;
}
else{
boolean metaFine = !meta || first.getItemDamage() == second.getItemDamage();
boolean nbtFine = !nbt || ItemStack.areItemStackTagsEqual(first, second);
if(metaFine && nbtFine){
if(oredict == 0){
return true;
}
else{
int[] firstIds = OreDictionary.getOreIDs(first);
int[] secondIds = OreDictionary.getOreIDs(second);
boolean firstEmpty = ArrayUtils.isEmpty(firstIds);
boolean secondEmpty = ArrayUtils.isEmpty(secondIds);
//Both empty, meaning none has OreDict entries, so they are equal
if(firstEmpty && secondEmpty){
return true;
}
//Only one empty, meaning they are not equal
else if(firstEmpty || secondEmpty){
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.getResourceDomain();
String secondDomain = secondReg.getResourceDomain();
if(firstDomain != null && secondDomain != null){
if(!firstDomain.equals(secondDomain)){
return false;
}
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;
}
}
//Needs to match every id, so just return false when no match
else if(oredict == 2){
return false;
}
}
//If oredict mode 1, this will fail because nothing matched
//If oredict mode 2, this will mean nothing hasn't matched
return oredict == 2;
}
}
}
else{
return false;
}
else if(firstItem != secondItem){
return false;
}
boolean metaFine = !meta || first.getItemDamage() == second.getItemDamage();
boolean nbtFine = !nbt || ItemStack.areItemStackTagsEqual(first, second);
if(metaFine && nbtFine){
if(oredict == 0){
return true;
}
else{
int[] firstIds = OreDictionary.getOreIDs(first);
int[] secondIds = OreDictionary.getOreIDs(second);
boolean firstEmpty = ArrayUtils.isEmpty(firstIds);
boolean secondEmpty = ArrayUtils.isEmpty(secondIds);
//Both empty, meaning none has OreDict entries, so they are equal
if(firstEmpty && secondEmpty){
return true;
}
//Only one empty, meaning they are not equal
else if(firstEmpty || secondEmpty){
return false;
}
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;
}
}
//Needs to match every id, so just return false when no match
else if(oredict == 2){
return false;
}
}
//If oredict mode 1, this will fail because nothing matched
//If oredict mode 2, this will mean nothing hasn't matched
return oredict == 2;
}
}
}
else{
return false;
}
}
@ -131,6 +155,7 @@ public class FilterSettings{
compound.setBoolean("Whitelist", this.isWhitelist);
compound.setBoolean("Meta", this.respectMeta);
compound.setBoolean("NBT", this.respectNBT);
compound.setBoolean("Mod", this.respectMod);
compound.setInteger("Oredict", this.respectOredict);
tag.setTag(name, compound);
}
@ -140,17 +165,19 @@ public class FilterSettings{
this.isWhitelist = compound.getBoolean("Whitelist");
this.respectMeta = compound.getBoolean("Meta");
this.respectNBT = compound.getBoolean("NBT");
this.respectMod = compound.getBoolean("Mod");
this.respectOredict = compound.getInteger("Oredict");
}
public boolean needsUpdateSend(){
return this.lastWhitelist != this.isWhitelist || this.lastRespectMeta != this.respectMeta || this.lastRespectNBT != this.respectNBT || this.lastRecpectOredict != this.respectOredict;
return this.lastWhitelist != this.isWhitelist || this.lastRespectMeta != this.respectMeta || this.lastRespectNBT != this.respectNBT || this.lastRespectMod != this.respectMod || this.lastRecpectOredict != this.respectOredict;
}
public void updateLasts(){
this.lastWhitelist = this.isWhitelist;
this.lastRespectMeta = this.respectMeta;
this.lastRespectNBT = this.respectNBT;
this.lastRespectMod = this.respectMod;
this.lastRecpectOredict = this.respectOredict;
}
@ -164,6 +191,9 @@ public class FilterSettings{
else if(id == this.nbtButtonId){
this.respectNBT = !this.respectNBT;
}
else if(id == this.modButtonId){
this.respectMod = !this.respectMod;
}
else if(id == this.oredictButtonId){
if(this.respectOredict+1 > 2){
this.respectOredict = 0;
@ -175,6 +205,6 @@ public class FilterSettings{
}
public boolean check(ItemStack stack, ItemStack[] slots){
return check(stack, slots, this.startSlot, this.endSlot, this.isWhitelist, this.respectMeta, this.respectNBT, this.respectOredict);
return check(stack, slots, this.startSlot, this.endSlot, this.isWhitelist, this.respectMeta, this.respectNBT, this.respectMod, this.respectOredict);
}
}

View file

@ -38,8 +38,8 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
public int slotToPullEnd;
public TileEntity placeToPull;
public boolean isAdvanced;
public FilterSettings leftFilter = new FilterSettings(PULL_FILTER_START, PULL_FILTER_START+12, true, true, false, 0, -1000);
public FilterSettings rightFilter = new FilterSettings(PUT_FILTER_START, PUT_FILTER_START+12, true, true, false, 0, -2000);
public FilterSettings leftFilter = new FilterSettings(PULL_FILTER_START, PULL_FILTER_START+12, true, true, false, false, 0, -1000);
public FilterSettings rightFilter = new FilterSettings(PUT_FILTER_START, PUT_FILTER_START+12, true, true, false, false, 0, -2000);
private int lastPutSide;
private int lastPutStart;
private int lastPutEnd;

View file

@ -28,8 +28,8 @@ import java.util.Arrays;
public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem implements IButtonReactor{
public final IInventory filterInventory;
public FilterSettings leftFilter = new FilterSettings(0, 12, true, true, false, 0, -1000);
public FilterSettings rightFilter = new FilterSettings(12, 24, true, true, false, 0, -2000);
public FilterSettings leftFilter = new FilterSettings(0, 12, true, true, false, false, 0, -1000);
public FilterSettings rightFilter = new FilterSettings(12, 24, true, true, false, false, 0, -2000);
private ItemStack[] slots = new ItemStack[24];
public TileEntityLaserRelayItemWhitelist(){
@ -219,7 +219,7 @@ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem
ItemStack copy = stack.copy();
copy = StackUtil.setStackSize(copy, 1);
if(!FilterSettings.check(copy, this.slots, usedSettings.startSlot, usedSettings.endSlot, true, usedSettings.respectMeta, usedSettings.respectNBT, usedSettings.respectOredict)){
if(!FilterSettings.check(copy, this.slots, usedSettings.startSlot, usedSettings.endSlot, true, usedSettings.respectMeta, usedSettings.respectNBT, usedSettings.respectMod, usedSettings.respectOredict)){
for(int k = usedSettings.startSlot; k < usedSettings.endSlot; k++){
if(StackUtil.isValid(this.slots[k])){
if(this.slots[k].getItem() instanceof ItemFilter){

View file

@ -28,7 +28,7 @@ public class TileEntityRangedCollector extends TileEntityInventoryBase implement
public static final int WHITELIST_START = 6;
public static final int RANGE = 6;
public FilterSettings filter = new FilterSettings(WHITELIST_START, WHITELIST_START+12, true, true, false, 0, -1000);
public FilterSettings filter = new FilterSettings(WHITELIST_START, WHITELIST_START+12, true, true, false, false, 0, -1000);
public TileEntityRangedCollector(){
super(18, "rangedCollector");

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 4 KiB