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 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 InventoryBag bagInventory;
private final InventoryPlayer inventory; private final InventoryPlayer inventory;
private final boolean isVoid; 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, 2, this.filter.respectNBT ? 1 : 0);
listener.sendProgressBarUpdate(this, 3, this.filter.respectOredict); listener.sendProgressBarUpdate(this, 3, this.filter.respectOredict);
listener.sendProgressBarUpdate(this, 4, this.autoInsert ? 1 : 0); listener.sendProgressBarUpdate(this, 4, this.autoInsert ? 1 : 0);
listener.sendProgressBarUpdate(this, 5, this.filter.respectMod ? 1 : 0);
} }
this.filter.updateLasts(); this.filter.updateLasts();
this.oldAutoInsert = this.autoInsert; this.oldAutoInsert = this.autoInsert;
@ -134,6 +135,9 @@ public class ContainerBag extends Container implements IButtonReactor{
else if(id == 4){ else if(id == 4){
this.autoInsert = data == 1; this.autoInsert = data == 1;
} }
else if(id == 5){
this.filter.respectMod = data == 1;
}
} }
@Override @Override

View file

@ -34,31 +34,36 @@ public class FilterSettingsGui extends Gui{
public SmallerButton whitelistButton; public SmallerButton whitelistButton;
public SmallerButton metaButton; public SmallerButton metaButton;
public SmallerButton nbtButton; public SmallerButton nbtButton;
public SmallerButton modButton;
public SmallerButton oredictButton; public SmallerButton oredictButton;
public FilterSettingsGui(FilterSettings settings, int x, int y, List<GuiButton> buttonList){ public FilterSettingsGui(FilterSettings settings, int x, int y, List<GuiButton> buttonList){
this.theSettings = settings; 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); buttonList.add(this.whitelistButton);
y+=14;
this.metaButton = new SmallerButton(this.theSettings.metaButtonId, x, y+18, ""); this.metaButton = new SmallerButton(this.theSettings.metaButtonId, x, y, "", true);
buttonList.add(this.metaButton); buttonList.add(this.metaButton);
y+=14;
this.nbtButton = new SmallerButton(this.theSettings.nbtButtonId, x, y+36, ""); this.nbtButton = new SmallerButton(this.theSettings.nbtButtonId, x, y, "", true);
buttonList.add(this.nbtButton); buttonList.add(this.nbtButton);
y+=14;
this.oredictButton = new SmallerButton(this.theSettings.oredictButtonId, x, y+54, ""); this.oredictButton = new SmallerButton(this.theSettings.oredictButtonId, x, y, "", true);
buttonList.add(this.oredictButton); buttonList.add(this.oredictButton);
y+=15;
this.modButton = new SmallerButton(this.theSettings.modButtonId, x, y, "", true);
buttonList.add(this.modButton);
this.update(); this.update();
} }
public void update(){ public void update(){
this.whitelistButton.displayString = (this.theSettings.isWhitelist ? TextFormatting.DARK_GREEN : TextFormatting.RED)+"W"; this.whitelistButton.displayString = (this.theSettings.isWhitelist ? TextFormatting.DARK_GREEN : TextFormatting.RED)+"WH";
this.metaButton.displayString = (this.theSettings.respectMeta ? TextFormatting.DARK_GREEN : TextFormatting.RED)+"M"; this.metaButton.displayString = (this.theSettings.respectMeta ? TextFormatting.DARK_GREEN : TextFormatting.RED)+"ME";
this.nbtButton.displayString = (this.theSettings.respectNBT ? TextFormatting.DARK_GREEN : TextFormatting.RED)+"N"; this.nbtButton.displayString = (this.theSettings.respectNBT ? TextFormatting.DARK_GREEN : TextFormatting.RED)+"NB";
this.oredictButton.displayString = (this.theSettings.respectOredict == 0 ? TextFormatting.RED : (this.theSettings.respectOredict == 1 ? TextFormatting.GREEN : TextFormatting.DARK_GREEN))+"O"; 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){ public void drawHover(int mouseX, int mouseY){
@ -76,6 +81,12 @@ public class FilterSettingsGui extends Gui{
else if(this.nbtButton.isMouseOver()){ 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); 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()){ else if(this.oredictButton.isMouseOver()){
List<String> list = new ArrayList<String>(); List<String> list = new ArrayList<String>();
list.add(TextFormatting.BOLD+(this.theSettings.respectOredict == 0 ? "Ignoring" : (this.theSettings.respectOredict == 1 ? "Soft Respecting" : "Hard Respecting"))+" OreDictionary"); 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 static class SmallerButton extends GuiButton{
public final ResourceLocation resLoc = AssetUtil.getGuiLocation("guiInputter"); public final ResourceLocation resLoc = AssetUtil.getGuiLocation("guiInputter");
private final boolean smaller;
public SmallerButton(int id, int x, int y, String display){ 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 @Override
@ -280,7 +286,7 @@ public class GuiInputter extends GuiContainer{
GlStateManager.enableBlend(); GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
GlStateManager.blendFunc(770, 771); 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); this.mouseDragged(mc, x, y);
int color = 14737632; int color = 14737632;

View file

@ -78,7 +78,7 @@ public class ItemBag extends ItemBase{
ItemStack[] inventory = new ItemStack[ContainerBag.getSlotAmount(isVoid)]; ItemStack[] inventory = new ItemStack[ContainerBag.getSlotAmount(isVoid)];
ItemDrill.loadSlotsFromNBT(inventory, invStack); 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"); filter.readFromNBT(invStack.getTagCompound(), "Filter");
if(filter.check(stack, inventory)){ if(filter.check(stack, inventory)){
if(isVoid){ 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.ItemDrill;
import de.ellpeck.actuallyadditions.mod.items.ItemFilter; import de.ellpeck.actuallyadditions.mod.items.ItemFilter;
import de.ellpeck.actuallyadditions.mod.util.StackUtil; import de.ellpeck.actuallyadditions.mod.util.StackUtil;
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;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
public class FilterSettings{ public class FilterSettings{
public final int startSlot;
public final int endSlot;
public final int whitelistButtonId; public final int whitelistButtonId;
public final int metaButtonId; public final int metaButtonId;
public final int nbtButtonId; public final int nbtButtonId;
public final int oredictButtonId; public final int oredictButtonId;
public final int modButtonId;
public final int startSlot;
public final int endSlot;
public boolean isWhitelist; public boolean isWhitelist;
public boolean respectMeta; public boolean respectMeta;
public boolean respectNBT; public boolean respectNBT;
public boolean respectMod;
public int respectOredict; public int respectOredict;
private boolean lastWhitelist; private boolean lastWhitelist;
private boolean lastRespectMeta; private boolean lastRespectMeta;
private boolean lastRespectNBT; private boolean lastRespectNBT;
private boolean lastRespectMod;
private int lastRecpectOredict; 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.startSlot = startSlot;
this.endSlot = endSlot; this.endSlot = endSlot;
this.isWhitelist = defaultWhitelist; this.isWhitelist = defaultWhitelist;
this.respectMeta = defaultRespectMeta; this.respectMeta = defaultRespectMeta;
this.respectNBT = defaultRespectNBT; this.respectNBT = defaultRespectNBT;
this.respectMod = defaultRespectMod;
this.respectOredict = defaultRespectOredict; this.respectOredict = defaultRespectOredict;
this.whitelistButtonId = buttonIdStart; this.whitelistButtonId = buttonIdStart;
this.metaButtonId = buttonIdStart+1; this.metaButtonId = buttonIdStart+1;
this.nbtButtonId = buttonIdStart+2; this.nbtButtonId = buttonIdStart+2;
this.oredictButtonId = buttonIdStart+3; 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)){ if(StackUtil.isValid(stack)){
for(int i = startSlot; i < endSlot; i++){ for(int i = startSlot; i < endSlot; i++){
if(StackUtil.isValid(slots[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; return whitelist;
} }
else if(slots[i].getItem() instanceof ItemFilter){ else if(slots[i].getItem() instanceof ItemFilter){
@ -63,7 +73,7 @@ public class FilterSettings{
ItemDrill.loadSlotsFromNBT(filterSlots, slots[i]); ItemDrill.loadSlotsFromNBT(filterSlots, slots[i]);
if(filterSlots != null && filterSlots.length > 0){ if(filterSlots != null && filterSlots.length > 0){
for(ItemStack filterSlot : filterSlots){ 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; return whitelist;
} }
} }
@ -75,11 +85,26 @@ public class FilterSettings{
return !whitelist; return !whitelist;
} }
private static boolean areEqualEnough(ItemStack first, ItemStack second, boolean meta, boolean nbt, int oredict){ private static boolean areEqualEnough(ItemStack first, ItemStack second, boolean meta, boolean nbt, boolean mod, int oredict){
if(first.getItem() != second.getItem()){ 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; return false;
} }
else{ }
}
}
else if(firstItem != secondItem){
return false;
}
boolean metaFine = !meta || first.getItemDamage() == second.getItemDamage(); boolean metaFine = !meta || first.getItemDamage() == second.getItemDamage();
boolean nbtFine = !nbt || ItemStack.areItemStackTagsEqual(first, second); boolean nbtFine = !nbt || ItemStack.areItemStackTagsEqual(first, second);
if(metaFine && nbtFine){ if(metaFine && nbtFine){
@ -124,13 +149,13 @@ public class FilterSettings{
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();
compound.setBoolean("Whitelist", this.isWhitelist); compound.setBoolean("Whitelist", this.isWhitelist);
compound.setBoolean("Meta", this.respectMeta); compound.setBoolean("Meta", this.respectMeta);
compound.setBoolean("NBT", this.respectNBT); compound.setBoolean("NBT", this.respectNBT);
compound.setBoolean("Mod", this.respectMod);
compound.setInteger("Oredict", this.respectOredict); compound.setInteger("Oredict", this.respectOredict);
tag.setTag(name, compound); tag.setTag(name, compound);
} }
@ -140,17 +165,19 @@ public class FilterSettings{
this.isWhitelist = compound.getBoolean("Whitelist"); this.isWhitelist = compound.getBoolean("Whitelist");
this.respectMeta = compound.getBoolean("Meta"); this.respectMeta = compound.getBoolean("Meta");
this.respectNBT = compound.getBoolean("NBT"); this.respectNBT = compound.getBoolean("NBT");
this.respectMod = compound.getBoolean("Mod");
this.respectOredict = compound.getInteger("Oredict"); this.respectOredict = compound.getInteger("Oredict");
} }
public boolean needsUpdateSend(){ 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(){ public void updateLasts(){
this.lastWhitelist = this.isWhitelist; this.lastWhitelist = this.isWhitelist;
this.lastRespectMeta = this.respectMeta; this.lastRespectMeta = this.respectMeta;
this.lastRespectNBT = this.respectNBT; this.lastRespectNBT = this.respectNBT;
this.lastRespectMod = this.respectMod;
this.lastRecpectOredict = this.respectOredict; this.lastRecpectOredict = this.respectOredict;
} }
@ -164,6 +191,9 @@ public class FilterSettings{
else if(id == this.nbtButtonId){ else if(id == this.nbtButtonId){
this.respectNBT = !this.respectNBT; this.respectNBT = !this.respectNBT;
} }
else if(id == this.modButtonId){
this.respectMod = !this.respectMod;
}
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;
@ -175,6 +205,6 @@ public class FilterSettings{
} }
public boolean check(ItemStack stack, ItemStack[] slots){ 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 int slotToPullEnd;
public TileEntity placeToPull; public TileEntity placeToPull;
public boolean isAdvanced; public boolean isAdvanced;
public FilterSettings leftFilter = new FilterSettings(PULL_FILTER_START, PULL_FILTER_START+12, true, true, false, 0, -1000); 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, 0, -2000); public FilterSettings rightFilter = new FilterSettings(PUT_FILTER_START, PUT_FILTER_START+12, true, true, false, false, 0, -2000);
private int lastPutSide; private int lastPutSide;
private int lastPutStart; private int lastPutStart;
private int lastPutEnd; private int lastPutEnd;

View file

@ -28,8 +28,8 @@ import java.util.Arrays;
public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem implements IButtonReactor{ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem implements IButtonReactor{
public final IInventory filterInventory; public final IInventory filterInventory;
public FilterSettings leftFilter = new FilterSettings(0, 12, true, true, false, 0, -1000); public FilterSettings leftFilter = new FilterSettings(0, 12, true, true, false, false, 0, -1000);
public FilterSettings rightFilter = new FilterSettings(12, 24, true, true, false, 0, -2000); public FilterSettings rightFilter = new FilterSettings(12, 24, true, true, false, false, 0, -2000);
private ItemStack[] slots = new ItemStack[24]; private ItemStack[] slots = new ItemStack[24];
public TileEntityLaserRelayItemWhitelist(){ public TileEntityLaserRelayItemWhitelist(){
@ -219,7 +219,7 @@ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem
ItemStack copy = stack.copy(); ItemStack copy = stack.copy();
copy = StackUtil.setStackSize(copy, 1); 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++){ for(int k = usedSettings.startSlot; k < usedSettings.endSlot; k++){
if(StackUtil.isValid(this.slots[k])){ if(StackUtil.isValid(this.slots[k])){
if(this.slots[k].getItem() instanceof ItemFilter){ 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 WHITELIST_START = 6;
public static final int RANGE = 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(){ public TileEntityRangedCollector(){
super(18, "rangedCollector"); super(18, "rangedCollector");

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 4 KiB