diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/FilterSettingsGui.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/FilterSettingsGui.java new file mode 100644 index 000000000..1e7582e74 --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/FilterSettingsGui.java @@ -0,0 +1,75 @@ +/* + * This file ("FilterSettingsGui.java") is part of the Actually Additions mod for Minecraft. + * It is created and owned by Ellpeck and distributed + * under the Actually Additions License to be found at + * http://ellpeck.de/actaddlicense + * View the source code at https://github.com/Ellpeck/ActuallyAdditions + * + * © 2015-2016 Ellpeck + */ + +package de.ellpeck.actuallyadditions.mod.inventory.gui; + +import de.ellpeck.actuallyadditions.mod.inventory.gui.GuiInputter.SmallerButton; +import de.ellpeck.actuallyadditions.mod.tile.FilterSettings; +import de.ellpeck.actuallyadditions.mod.util.ModUtil; +import de.ellpeck.actuallyadditions.mod.util.StringUtil; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.util.text.TextFormatting; +import net.minecraftforge.fml.client.config.GuiUtils; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +@SideOnly(Side.CLIENT) +public class FilterSettingsGui extends Gui{ + + private final FilterSettings theSettings; + + public SmallerButton whitelistButton; + public SmallerButton metaButton; + public SmallerButton nbtButton; + + public FilterSettingsGui(FilterSettings settings, int x, int y, List buttonList){ + this.theSettings = settings; + + this.whitelistButton = new SmallerButton(this.theSettings.whitelistButtonId, x, y, ""); + buttonList.add(this.whitelistButton); + + this.metaButton = new SmallerButton(this.theSettings.metaButtonId, x, y+18, ""); + buttonList.add(this.metaButton); + + this.nbtButton = new SmallerButton(this.theSettings.nbtButtonId, x, y+36, ""); + buttonList.add(this.nbtButton); + + 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"; + } + + public void drawHover(int mouseX, int mouseY){ + Minecraft mc = Minecraft.getMinecraft(); + + if(this.whitelistButton.isMouseOver()){ + List list = new ArrayList(); + list.add(TextFormatting.BOLD+(this.theSettings.isWhitelist ? StringUtil.localize("info."+ModUtil.MOD_ID+".gui.whitelist") : StringUtil.localize("info."+ModUtil.MOD_ID+".gui.blacklist"))); + list.addAll(mc.fontRendererObj.listFormattedStringToWidth(StringUtil.localizeFormatted("info."+ModUtil.MOD_ID+".gui.whitelistInfo"), 200)); + GuiUtils.drawHoveringText(list, mouseX, mouseY, mc.displayWidth, mc.displayHeight, -1, mc.fontRendererObj); + } + else if(this.metaButton.isMouseOver()){ + GuiUtils.drawHoveringText(Collections.singletonList(TextFormatting.BOLD+(this.theSettings.respectMeta ? "Respecting" : "Ignoring")+" Metadata"), mouseX, mouseY, mc.displayWidth, mc.displayHeight, -1, mc.fontRendererObj); + } + 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); + } + } +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiInputter.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiInputter.java index 7e6dcd7b1..53c4f6f0a 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiInputter.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiInputter.java @@ -56,13 +56,14 @@ public class GuiInputter extends GuiContainer{ private final int z; private final World world; private final boolean isAdvanced; - private SmallerButton whitelistPut; - private SmallerButton whitelistPull; private GuiTextField fieldPutStart; private GuiTextField fieldPutEnd; private GuiTextField fieldPullStart; private GuiTextField fieldPullEnd; + private FilterSettingsGui leftFilter; + private FilterSettingsGui rightFilter; + public GuiInputter(InventoryPlayer inventory, TileEntityBase tile, int x, int y, int z, World world, boolean isAdvanced){ super(new ContainerInputter(inventory, tile, isAdvanced)); this.tileInputter = (TileEntityInputter)tile; @@ -79,6 +80,11 @@ public class GuiInputter extends GuiContainer{ public void initGui(){ super.initGui(); + if(this.isAdvanced){ + this.leftFilter = new FilterSettingsGui(this.tileInputter.leftFilter, this.guiLeft+3, this.guiTop+16, this.buttonList); + this.rightFilter = new FilterSettingsGui(this.tileInputter.rightFilter, this.guiLeft+157, this.guiTop+16, this.buttonList); + } + this.fieldPullStart = new GuiTextField(3000, this.fontRendererObj, this.guiLeft+6, this.guiTop+80+(this.isAdvanced ? OFFSET_ADVANCED : 0), 34, 8); this.fieldPullStart.setMaxStringLength(5); this.fieldPullStart.setEnableBackgroundDrawing(false); @@ -99,17 +105,10 @@ public class GuiInputter extends GuiContainer{ SmallerButton buttonSidePullP = new SmallerButton(2, this.guiLeft+70, this.guiTop+43+(this.isAdvanced ? OFFSET_ADVANCED : 0), ">"); SmallerButton buttonSidePullM = new SmallerButton(3, this.guiLeft+5, this.guiTop+43+(this.isAdvanced ? OFFSET_ADVANCED : 0), "<"); - this.whitelistPull = new SmallerButton(TileEntityInputter.WHITELIST_PULL_BUTTON_ID, this.guiLeft+3, this.guiTop+16, ""); - this.whitelistPut = new SmallerButton(TileEntityInputter.WHITELIST_PUT_BUTTON_ID, this.guiLeft+157, this.guiTop+16, ""); - this.buttonList.add(buttonSidePutP); this.buttonList.add(buttonSidePullP); this.buttonList.add(buttonSidePutM); this.buttonList.add(buttonSidePullM); - if(this.isAdvanced){ - this.buttonList.add(this.whitelistPut); - this.buttonList.add(this.whitelistPull); - } this.buttonList.add(new TinyButton(TileEntityInputter.OKAY_BUTTON_ID, this.guiLeft+84, this.guiTop+91+(this.isAdvanced ? OFFSET_ADVANCED : 0))); } @@ -118,27 +117,6 @@ public class GuiInputter extends GuiContainer{ public void drawScreen(int x, int y, float f){ super.drawScreen(x, y, f); - this.whitelistPull.displayString = this.tileInputter.isPullWhitelist ? "O" : "X"; - this.whitelistPut.displayString = this.tileInputter.isPutWhitelist ? "O" : "X"; - - if(this.isAdvanced){ - List infoList = this.fontRendererObj.listFormattedStringToWidth(StringUtil.localizeFormatted("info."+ModUtil.MOD_ID+".inputter.whitelistInfo"), 200); - String text1 = this.tileInputter.isPullWhitelist ? StringUtil.localize("info."+ModUtil.MOD_ID+".gui.whitelist") : StringUtil.localize("info."+ModUtil.MOD_ID+".gui.blacklist"); - if(x >= this.guiLeft+3 && y >= this.guiTop+16 && x <= this.guiLeft+18 && y <= this.guiTop+31){ - ArrayList list = new ArrayList(); - list.add(TextFormatting.BOLD+text1); - list.addAll(infoList); - this.drawHoveringText(list, x, y); - } - String text2 = this.tileInputter.isPutWhitelist ? StringUtil.localize("info."+ModUtil.MOD_ID+".gui.whitelist") : StringUtil.localize("info."+ModUtil.MOD_ID+".gui.blacklist"); - if(x >= this.guiLeft+157 && y >= this.guiTop+16 && x <= this.guiLeft+172 && y <= this.guiTop+31){ - ArrayList list = new ArrayList(); - list.add(TextFormatting.BOLD+text2); - list.addAll(infoList); - this.drawHoveringText(list, x, y); - } - } - int newTopOffset = this.guiTop+(this.isAdvanced ? OFFSET_ADVANCED : 0); //Info Mode on! if(x >= this.guiLeft+4 && y >= newTopOffset+65 && x <= this.guiLeft+4+38 && y <= newTopOffset+65+12){ @@ -153,6 +131,11 @@ public class GuiInputter extends GuiContainer{ if(x >= this.guiLeft+133 && y >= newTopOffset+65 && x <= this.guiLeft+133+38 && y <= newTopOffset+65+12){ this.drawHoveringText(this.fontRendererObj.listFormattedStringToWidth(StringUtil.localizeFormatted("info."+ModUtil.MOD_ID+".inputter.info.2").replace("

", StringUtil.localize("info."+ModUtil.MOD_ID+".gui.put")), 200), x, y); } + + if(this.isAdvanced){ + this.leftFilter.drawHover(x, y); + this.rightFilter.drawHover(x, y); + } } @Override @@ -232,6 +215,11 @@ public class GuiInputter extends GuiContainer{ this.fieldPutEnd.updateCursorCounter(); this.fieldPullStart.updateCursorCounter(); this.fieldPullEnd.updateCursorCounter(); + + if(this.isAdvanced){ + this.leftFilter.update(); + this.rightFilter.update(); + } } public void setVariable(GuiTextField field, int sendInt){ diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiLaserRelayItemWhitelist.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiLaserRelayItemWhitelist.java index 52d43326c..1cf6e9c6f 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiLaserRelayItemWhitelist.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiLaserRelayItemWhitelist.java @@ -14,6 +14,7 @@ import de.ellpeck.actuallyadditions.mod.inventory.ContainerLaserRelayItemWhiteli import de.ellpeck.actuallyadditions.mod.inventory.gui.GuiInputter.SmallerButton; import de.ellpeck.actuallyadditions.mod.network.PacketClientToServer; import de.ellpeck.actuallyadditions.mod.network.PacketHandler; +import de.ellpeck.actuallyadditions.mod.tile.FilterSettings; import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase; import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelayItemWhitelist; import de.ellpeck.actuallyadditions.mod.util.AssetUtil; @@ -39,8 +40,11 @@ public class GuiLaserRelayItemWhitelist extends GuiContainer{ private static final ResourceLocation RES_LOC = AssetUtil.getGuiLocation("guiLaserRelayItemWhitelist"); private final TileEntityLaserRelayItemWhitelist tile; - private SmallerButton whitelistLeft; - private SmallerButton whitelistRight; + private FilterSettingsGui leftFilter; + private FilterSettingsGui rightFilter; + + private GuiButton buttonSmartWhitelistLeft; + private GuiButton buttonSmartWhitelistRight; public GuiLaserRelayItemWhitelist(InventoryPlayer inventory, TileEntityBase tile){ super(new ContainerLaserRelayItemWhitelist(inventory, tile)); @@ -49,19 +53,25 @@ public class GuiLaserRelayItemWhitelist extends GuiContainer{ this.ySize = 93+86; } + @Override + public void updateScreen(){ + super.updateScreen(); + + this.leftFilter.update(); + this.rightFilter.update(); + } + @Override public void initGui(){ super.initGui(); - this.whitelistLeft = new SmallerButton(0, this.guiLeft+3, this.guiTop+16, ""); - this.whitelistRight = new SmallerButton(1, this.guiLeft+157, this.guiTop+16, ""); - SmallerButton smartWhitelistLeft = new SmallerButton(2, this.guiLeft+3, this.guiTop+34, "S"); - SmallerButton smartWhitelistRight = new SmallerButton(3, this.guiLeft+157, this.guiTop+34, "S"); + this.leftFilter = new FilterSettingsGui(this.tile.leftFilter, this.guiLeft+3, this.guiTop+8, this.buttonList); + this.rightFilter = new FilterSettingsGui(this.tile.rightFilter, this.guiLeft+157, this.guiTop+8, this.buttonList); - this.buttonList.add(this.whitelistLeft); - this.buttonList.add(this.whitelistRight); - this.buttonList.add(smartWhitelistLeft); - this.buttonList.add(smartWhitelistRight); + this.buttonSmartWhitelistLeft = new SmallerButton(2, this.guiLeft+3, this.guiTop+64, "S"); + this.buttonSmartWhitelistRight = new SmallerButton(3, this.guiLeft+157, this.guiTop+64, "S"); + this.buttonList.add(this.buttonSmartWhitelistLeft); + this.buttonList.add(this.buttonSmartWhitelistRight); } @Override @@ -80,30 +90,15 @@ public class GuiLaserRelayItemWhitelist extends GuiContainer{ public void drawScreen(int x, int y, float f){ super.drawScreen(x, y, f); - this.whitelistLeft.displayString = this.tile.isLeftWhitelist ? "O" : "X"; - this.whitelistRight.displayString = this.tile.isRightWhitelist ? "O" : "X"; - - List infoList = this.fontRendererObj.listFormattedStringToWidth(StringUtil.localizeFormatted("info."+ModUtil.MOD_ID+".inputter.whitelistInfo"), 200); - String text1 = this.tile.isLeftWhitelist ? StringUtil.localize("info."+ModUtil.MOD_ID+".gui.whitelist") : StringUtil.localize("info."+ModUtil.MOD_ID+".gui.blacklist"); - if(x >= this.guiLeft+3 && y >= this.guiTop+16 && x <= this.guiLeft+18 && y <= this.guiTop+31){ - ArrayList list = new ArrayList(); - list.add(TextFormatting.BOLD+text1); - list.addAll(infoList); - this.drawHoveringText(list, x, y); - } - String text2 = this.tile.isRightWhitelist ? StringUtil.localize("info."+ModUtil.MOD_ID+".gui.whitelist") : StringUtil.localize("info."+ModUtil.MOD_ID+".gui.blacklist"); - if(x >= this.guiLeft+157 && y >= this.guiTop+16 && x <= this.guiLeft+172 && y <= this.guiTop+31){ - ArrayList list = new ArrayList(); - list.add(TextFormatting.BOLD+text2); - list.addAll(infoList); - this.drawHoveringText(list, x, y); - } - if(((x >= this.guiLeft+3 && x <= this.guiLeft+3+15) || (x >= this.guiLeft+157 && x <= this.guiLeft+157+15)) && y <= this.guiTop+34+15 && y >= this.guiTop+34){ + if(this.buttonSmartWhitelistLeft.isMouseOver() || this.buttonSmartWhitelistRight.isMouseOver()){ List list = new ArrayList(); list.add(TextFormatting.BOLD+StringUtil.localize("info."+ModUtil.MOD_ID+".gui.smart")); list.addAll(this.fontRendererObj.listFormattedStringToWidth(StringUtil.localize("info."+ModUtil.MOD_ID+".gui.smartInfo"), 200)); this.drawHoveringText(list, x, y); } + + this.leftFilter.drawHover(x, y); + this.rightFilter.drawHover(x, y); } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiRangedCollector.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiRangedCollector.java index 25ab78282..1599eaf3b 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiRangedCollector.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiRangedCollector.java @@ -40,7 +40,8 @@ public class GuiRangedCollector extends GuiContainer{ private final int y; private final int z; private final World world; - private GuiInputter.SmallerButton whitelistButton; + + private FilterSettingsGui filter; public GuiRangedCollector(InventoryPlayer inventory, TileEntityBase tile, int x, int y, int z, World world){ super(new ContainerRangedCollector(inventory, tile)); @@ -57,20 +58,21 @@ public class GuiRangedCollector extends GuiContainer{ public void initGui(){ super.initGui(); - this.whitelistButton = new GuiInputter.SmallerButton(0, this.guiLeft+3, this.guiTop+16, ""); - this.buttonList.add(this.whitelistButton); + this.filter = new FilterSettingsGui(this.collector.filter, this.guiLeft+3, this.guiTop+16, this.buttonList); } @Override public void drawScreen(int x, int y, float f){ super.drawScreen(x, y, f); - this.whitelistButton.displayString = this.collector.isWhitelist ? "O" : "X"; + this.filter.drawHover(x, y); + } - String text1 = this.collector.isWhitelist ? StringUtil.localize("info."+ModUtil.MOD_ID+".gui.whitelist") : StringUtil.localize("info."+ModUtil.MOD_ID+".gui.blacklist"); - if(x >= this.guiLeft+3 && y >= this.guiTop+16 && x <= this.guiLeft+18 && y <= this.guiTop+31){ - this.drawHoveringText(Collections.singletonList(text1), x, y); - } + @Override + public void updateScreen(){ + super.updateScreen(); + + this.filter.update(); } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/FilterSettings.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/FilterSettings.java new file mode 100644 index 000000000..1da3d2007 --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/FilterSettings.java @@ -0,0 +1,125 @@ +/* + * This file ("FilterSettings.java") is part of the Actually Additions mod for Minecraft. + * It is created and owned by Ellpeck and distributed + * under the Actually Additions License to be found at + * http://ellpeck.de/actaddlicense + * View the source code at https://github.com/Ellpeck/ActuallyAdditions + * + * © 2015-2016 Ellpeck + */ + +package de.ellpeck.actuallyadditions.mod.tile; + +import de.ellpeck.actuallyadditions.mod.inventory.ContainerFilter; +import de.ellpeck.actuallyadditions.mod.items.ItemDrill; +import de.ellpeck.actuallyadditions.mod.items.ItemFilter; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +public class FilterSettings{ + + public final int startSlot; + public final int endSlot; + + public boolean isWhitelist; + private boolean lastWhitelist; + + public boolean respectMeta; + private boolean lastRespectMeta; + + public boolean respectNBT; + private boolean lastRespectNBT; + + public final int whitelistButtonId; + public final int metaButtonId; + public final int nbtButtonId; + + public FilterSettings(int startSlot, int endSlot, boolean defaultWhitelist, boolean defaultRespectMeta, boolean defaultRespectNBT, int buttonIdStart){ + this.startSlot = startSlot; + this.endSlot = endSlot; + + this.isWhitelist = defaultWhitelist; + this.respectMeta = defaultRespectMeta; + this.respectNBT = defaultRespectNBT; + + this.whitelistButtonId = buttonIdStart; + this.metaButtonId = buttonIdStart+1; + this.nbtButtonId = buttonIdStart+2; + } + + public void writeToNBT(NBTTagCompound tag, String name){ + NBTTagCompound compound = new NBTTagCompound(); + compound.setBoolean("Whitelist", this.isWhitelist); + compound.setBoolean("Meta", this.respectMeta); + compound.setBoolean("NBT", this.respectNBT); + tag.setTag(name, compound); + } + + public void readFromNBT(NBTTagCompound tag, String name){ + NBTTagCompound compound = tag.getCompoundTag(name); + this.isWhitelist = compound.getBoolean("Whitelist"); + this.respectMeta = compound.getBoolean("Meta"); + this.respectNBT = compound.getBoolean("NBT"); + } + + public boolean needsUpdateSend(){ + return this.lastWhitelist != this.isWhitelist || this.lastRespectMeta != this.respectMeta || this.lastRespectNBT != this.respectNBT; + } + + public void updateLasts(){ + this.lastWhitelist = this.isWhitelist; + this.lastRespectMeta = this.respectMeta; + this.lastRespectNBT = this.respectNBT; + } + + public void onButtonPressed(int id){ + if(id == this.whitelistButtonId){ + this.isWhitelist = !this.isWhitelist; + } + else if(id == this.metaButtonId){ + this.respectMeta = !this.respectMeta; + } + else if(id == this.nbtButtonId){ + this.respectNBT = !this.respectNBT; + } + } + + public boolean check(ItemStack stack, ItemStack[] slots){ + return check(stack, slots, this.startSlot, this.endSlot, this.isWhitelist, this.respectMeta, this.respectNBT); + } + + public static boolean check(ItemStack stack, ItemStack[] slots, int startSlot, int endSlot, boolean whitelist, boolean meta, boolean nbt){ + if(stack != null){ + for(int i = startSlot; i < endSlot; i++){ + if(slots[i] != null){ + if(areEqualEnough(slots[i], stack, meta, nbt)){ + return whitelist; + } + else if(slots[i].getItem() instanceof ItemFilter){ + ItemStack[] filterSlots = new ItemStack[ContainerFilter.SLOT_AMOUNT]; + ItemDrill.loadSlotsFromNBT(filterSlots, slots[i]); + if(filterSlots != null && filterSlots.length > 0){ + for(ItemStack filterSlot : filterSlots){ + if(filterSlot != null && areEqualEnough(filterSlot, stack, meta, nbt)){ + return whitelist; + } + } + } + } + } + } + } + return !whitelist; + } + + private static boolean areEqualEnough(ItemStack first, ItemStack second, boolean meta, boolean nbt){ + if(first.getItem() != second.getItem()){ + return false; + } + else{ + boolean metaFine = !meta || first.getItemDamage() == second.getItemDamage(); + boolean nbtFine = !nbt || ItemStack.areItemStackTagsEqual(first, second); + return metaFine && nbtFine; + } + } +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityInputter.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityInputter.java index 9868a6c4b..ffb20258d 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityInputter.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityInputter.java @@ -11,6 +11,7 @@ package de.ellpeck.actuallyadditions.mod.tile; +import com.sun.org.apache.bcel.internal.generic.PUTFIELD; import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor; import de.ellpeck.actuallyadditions.mod.network.gui.INumberReactor; import de.ellpeck.actuallyadditions.mod.util.WorldUtil; @@ -41,16 +42,14 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt public int slotToPullEnd; public TileEntity placeToPull; public boolean isAdvanced; - public boolean isPullWhitelist; - public boolean isPutWhitelist; private int lastPutSide; private int lastPutStart; private int lastPutEnd; private int lastPullSide; private int lastPullStart; private int lastPullEnd; - private boolean lastPullWhite; - private boolean lastPutWhite; + public FilterSettings leftFilter = new FilterSettings(PULL_FILTER_START, PULL_FILTER_START+12, true, true, false, -1000); + public FilterSettings rightFilter = new FilterSettings(PUT_FILTER_START, PUT_FILTER_START+12, true, true, false, -2000); private boolean hasCheckedTilesAround; @@ -314,8 +313,7 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt return true; } else{ - int slotStart = output ? PUT_FILTER_START : PULL_FILTER_START; - return TileEntityLaserRelayItemWhitelist.checkFilter(stack, output ? this.isPutWhitelist : this.isPullWhitelist, this.slots, slotStart, slotStart+12); + return (output ? this.rightFilter : this.leftFilter).check(stack, this.slots); } } @@ -364,14 +362,8 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt @Override public void onButtonPressed(int buttonID, EntityPlayer player){ - if(buttonID == WHITELIST_PULL_BUTTON_ID){ - this.isPullWhitelist = !this.isPullWhitelist; - return; - } - if(buttonID == WHITELIST_PUT_BUTTON_ID){ - this.isPutWhitelist = !this.isPutWhitelist; - return; - } + this.leftFilter.onButtonPressed(buttonID); + this.rightFilter.onButtonPressed(buttonID); //Reset the Slots if(buttonID == 0 || buttonID == 1){ @@ -424,8 +416,9 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt compound.setInteger("SideToPull", this.sideToPull); compound.setInteger("SlotToPull", this.slotToPullStart); compound.setInteger("SlotToPullEnd", this.slotToPullEnd); - compound.setBoolean("PullWhitelist", this.isPullWhitelist); - compound.setBoolean("PutWhitelist", this.isPutWhitelist); + + this.leftFilter.writeToNBT(compound, "LeftFilter"); + this.rightFilter.writeToNBT(compound, "RightFilter"); } } @@ -438,8 +431,9 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt this.sideToPull = compound.getInteger("SideToPull"); this.slotToPullStart = compound.getInteger("SlotToPull"); this.slotToPullEnd = compound.getInteger("SlotToPullEnd"); - this.isPullWhitelist = compound.getBoolean("PullWhitelist"); - this.isPutWhitelist = compound.getBoolean("PutWhitelist"); + + this.leftFilter.readFromNBT(compound, "LeftFilter"); + this.rightFilter.readFromNBT(compound, "RightFilter"); } super.readSyncableNBT(compound, type); } @@ -466,15 +460,15 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt } //Update the Client - if((this.sideToPut != this.lastPutSide || this.sideToPull != this.lastPullSide || this.slotToPullStart != this.lastPullStart || this.slotToPullEnd != this.lastPullEnd || this.slotToPutStart != this.lastPutStart || this.slotToPutEnd != this.lastPutEnd || this.isPullWhitelist != this.lastPullWhite || this.isPutWhitelist != this.lastPutWhite) && this.sendUpdateWithInterval()){ + if((this.sideToPut != this.lastPutSide || this.sideToPull != this.lastPullSide || this.slotToPullStart != this.lastPullStart || this.slotToPullEnd != this.lastPullEnd || this.slotToPutStart != this.lastPutStart || this.slotToPutEnd != this.lastPutEnd || this.leftFilter.needsUpdateSend() || this.rightFilter.needsUpdateSend()) && this.sendUpdateWithInterval()){ this.lastPutSide = this.sideToPut; this.lastPullSide = this.sideToPull; this.lastPullStart = this.slotToPullStart; this.lastPullEnd = this.slotToPullEnd; this.lastPutStart = this.slotToPutStart; this.lastPutEnd = this.slotToPutEnd; - this.lastPullWhite = this.isPullWhitelist; - this.lastPutWhite = this.isPutWhitelist; + this.leftFilter.updateLasts(); + this.rightFilter.updateLasts(); } } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityInventoryBase.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityInventoryBase.java index 10cdaaa3c..6040486c2 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityInventoryBase.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityInventoryBase.java @@ -28,7 +28,7 @@ public abstract class TileEntityInventoryBase extends TileEntityBase implements public TileEntityInventoryBase(int slots, String name){ super(name); - this.initializeSlots(slots); + this.slots = new ItemStack[slots]; if(this.hasInvWrapperCapabilities()){ for(int i = 0; i < this.invWrappers.length; i++){ @@ -61,10 +61,6 @@ public abstract class TileEntityInventoryBase extends TileEntityBase implements } } - public void initializeSlots(int itemAmount){ - this.slots = new ItemStack[itemAmount]; - } - @Override public void writeSyncableNBT(NBTTagCompound compound, NBTType type){ super.writeSyncableNBT(compound, type); @@ -138,7 +134,9 @@ public abstract class TileEntityInventoryBase extends TileEntityBase implements @Override public void clear(){ - this.initializeSlots(this.slots.length); + for(int i = 0; i < this.slots.length; i++){ + this.removeStackFromSlot(i); + } } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayItemWhitelist.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayItemWhitelist.java index 0391f274e..bfba7695b 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayItemWhitelist.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayItemWhitelist.java @@ -27,11 +27,9 @@ import java.util.List; public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem implements IButtonReactor{ public final IInventory filterInventory; - public boolean isLeftWhitelist; - public boolean isRightWhitelist; private ItemStack[] slots = new ItemStack[24]; - private boolean lastLeftWhitelist; - private boolean lastRightWhitelist; + public FilterSettings leftFilter = new FilterSettings(0, 12, true, true, false, -1000); + public FilterSettings rightFilter = new FilterSettings(12, 24, true, true, false, -2000); public TileEntityLaserRelayItemWhitelist(){ super("laserRelayItemWhitelist"); @@ -163,34 +161,9 @@ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem }.setTile(this); } - public static boolean checkFilter(ItemStack stack, boolean isWhitelist, ItemStack[] slots, int start, int end){ - if(stack != null){ - for(int i = start; i < end; i++){ - if(slots[i] != null){ - if(slots[i].isItemEqual(stack)){ - return isWhitelist; - } - else if(slots[i].getItem() instanceof ItemFilter){ - ItemStack[] filterSlots = new ItemStack[ContainerFilter.SLOT_AMOUNT]; - ItemDrill.loadSlotsFromNBT(filterSlots, slots[i]); - if(filterSlots != null && filterSlots.length > 0){ - for(ItemStack filterSlot : filterSlots){ - if(filterSlot != null && filterSlot.isItemEqual(stack)){ - return isWhitelist; - } - } - } - } - } - } - } - return !isWhitelist; - } - @Override public boolean isWhitelisted(ItemStack stack, boolean output){ - int slotStart = output ? 12 : 0; - return checkFilter(stack, output ? this.isRightWhitelist : this.isLeftWhitelist, this.slots, slotStart, slotStart+12); + return output ? this.rightFilter.check(stack, this.slots) : this.leftFilter.check(stack, this.slots); } @Override @@ -199,8 +172,10 @@ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem if(type == NBTType.SAVE_TILE){ TileEntityInventoryBase.saveSlots(this.slots, compound); } - compound.setBoolean("LeftWhitelist", this.isLeftWhitelist); - compound.setBoolean("RightWhitelist", this.isRightWhitelist); + if(type != NBTType.SAVE_BLOCK){ + this.leftFilter.writeToNBT(compound, "LeftFilter"); + this.rightFilter.writeToNBT(compound, "RightFilter"); + } } @Override @@ -209,19 +184,17 @@ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem if(type == NBTType.SAVE_TILE){ TileEntityInventoryBase.loadSlots(this.slots, compound); } - this.isLeftWhitelist = compound.getBoolean("LeftWhitelist"); - this.isRightWhitelist = compound.getBoolean("RightWhitelist"); + if(type != NBTType.SAVE_BLOCK){ + this.leftFilter.readFromNBT(compound, "LeftFilter"); + this.rightFilter.readFromNBT(compound, "RightFilter"); + } } @Override public void onButtonPressed(int buttonID, EntityPlayer player){ - if(buttonID == 0){ - this.isLeftWhitelist = !this.isLeftWhitelist; - } - else if(buttonID == 1){ - this.isRightWhitelist = !this.isRightWhitelist; - } - else if(buttonID == 2){ + this.leftFilter.onButtonPressed(buttonID); + this.rightFilter.onButtonPressed(buttonID); + if(buttonID == 2){ this.addWhitelistSmart(false); } else if(buttonID == 3){ @@ -230,9 +203,7 @@ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem } private void addWhitelistSmart(boolean output){ - int slotStart = output ? 12 : 0; - int slotStop = slotStart+12; - + FilterSettings usedSettings = output ? this.rightFilter : this.leftFilter; List handlers = this.handlersAround; for(IItemHandler handler : handlers){ for(int i = 0; i < handler.getSlots(); i++){ @@ -241,8 +212,8 @@ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem ItemStack copy = stack.copy(); copy.stackSize = 1; - if(!checkFilter(copy, true, this.slots, slotStart, slotStop)){ - for(int k = slotStart; k < slotStop; k++){ + if(!FilterSettings.check(copy, this.slots, usedSettings.startSlot, usedSettings.endSlot, true, usedSettings.respectMeta, usedSettings.respectNBT)){ + for(int k = usedSettings.startSlot; k < usedSettings.endSlot; k++){ if(this.slots[k] != null){ if(this.slots[k].getItem() instanceof ItemFilter){ ItemStack[] filterSlots = new ItemStack[ContainerFilter.SLOT_AMOUNT]; @@ -281,9 +252,9 @@ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem super.updateEntity(); if(!this.worldObj.isRemote){ - if((this.isLeftWhitelist != this.lastLeftWhitelist || this.isRightWhitelist != this.lastRightWhitelist) && this.sendUpdateWithInterval()){ - this.lastLeftWhitelist = this.isLeftWhitelist; - this.lastRightWhitelist = this.isRightWhitelist; + if((this.leftFilter.needsUpdateSend() || this.rightFilter.needsUpdateSend()) && this.sendUpdateWithInterval()){ + this.leftFilter.updateLasts(); + this.rightFilter.updateLasts(); } } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityRangedCollector.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityRangedCollector.java index caedbe252..1c4c39fb4 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityRangedCollector.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityRangedCollector.java @@ -25,8 +25,7 @@ public class TileEntityRangedCollector extends TileEntityInventoryBase implement public static final int WHITELIST_START = 6; public static final int RANGE = 6; - public boolean isWhitelist = true; - private boolean lastWhitelist; + public FilterSettings filter = new FilterSettings(WHITELIST_START, WHITELIST_START+12, true, true, false, -1000); public TileEntityRangedCollector(){ super(18, "rangedCollector"); @@ -36,7 +35,7 @@ public class TileEntityRangedCollector extends TileEntityInventoryBase implement public void writeSyncableNBT(NBTTagCompound compound, NBTType type){ super.writeSyncableNBT(compound, type); if(type != NBTType.SAVE_BLOCK){ - compound.setBoolean("Whitelist", this.isWhitelist); + this.filter.writeToNBT(compound, "Filter"); } } @@ -44,7 +43,7 @@ public class TileEntityRangedCollector extends TileEntityInventoryBase implement public void readSyncableNBT(NBTTagCompound compound, NBTType type){ super.readSyncableNBT(compound, type); if(type != NBTType.SAVE_BLOCK){ - this.isWhitelist = compound.getBoolean("Whitelist"); + this.filter.readFromNBT(compound, "Filter"); } } @@ -58,7 +57,7 @@ public class TileEntityRangedCollector extends TileEntityInventoryBase implement for(EntityItem item : items){ if(!item.isDead && item.getEntityItem() != null){ ItemStack toAdd = item.getEntityItem().copy(); - if(TileEntityLaserRelayItemWhitelist.checkFilter(toAdd, this.isWhitelist, this.slots, WHITELIST_START, WHITELIST_START+12)){ + if(this.filter.check(toAdd, this.slots)){ ArrayList checkList = new ArrayList(); checkList.add(toAdd); if(WorldUtil.addToInventory(this, 0, WHITELIST_START, checkList, EnumFacing.UP, false, true)){ @@ -71,8 +70,8 @@ public class TileEntityRangedCollector extends TileEntityInventoryBase implement } } - if(this.isWhitelist != this.lastWhitelist && this.sendUpdateWithInterval()){ - this.lastWhitelist = this.isWhitelist; + if(this.filter.needsUpdateSend() && this.sendUpdateWithInterval()){ + this.filter.updateLasts(); } } } @@ -94,6 +93,6 @@ public class TileEntityRangedCollector extends TileEntityInventoryBase implement @Override public void onButtonPressed(int buttonID, EntityPlayer player){ - this.isWhitelist = !this.isWhitelist; + this.filter.onButtonPressed(buttonID); } } diff --git a/src/main/resources/assets/actuallyadditions/lang/en_US.lang b/src/main/resources/assets/actuallyadditions/lang/en_US.lang index 00c4a8ded..997202625 100644 --- a/src/main/resources/assets/actuallyadditions/lang/en_US.lang +++ b/src/main/resources/assets/actuallyadditions/lang/en_US.lang @@ -554,6 +554,7 @@ info.actuallyadditions.gui.put=Put info.actuallyadditions.gui.pull=Pull info.actuallyadditions.gui.whitelist=Whitelist info.actuallyadditions.gui.blacklist=Blacklist +info.actuallyadditions.gui.whitelistInfo=To let all items through, an empty blacklist can be used, to let no items through, an empty whitelist can be used. To configure certain items, place them or configured Item Filters in the slots. info.actuallyadditions.gui.coffee=Coffee info.actuallyadditions.gui.ok=Ok info.actuallyadditions.gui.the=the @@ -561,7 +562,6 @@ info.actuallyadditions.gui.smart=Smart Whitelist info.actuallyadditions.gui.smartInfo=When pressing this, all items from inventories adjacent to this relay will be added to this part of the white- or blacklist. Adding Item Filters to the list before will cause them to also be filled. info.actuallyadditions.inputter.info.1=This is the first Slot in the connected Inventory to

at. info.actuallyadditions.inputter.info.2=This is the slot after the last Slot in the connected Inventory to

at. What that means: If you, for example, write 2 in the field to the left and 5 in this one, it will

at Slot 2, 3, and 4. -info.actuallyadditions.inputter.whitelistInfo=When pressing this, this side's whitelist mode will be changed. To let all items through, an empty blacklist can be used, to let no items through, an empty whitelist can be used. To configure certain items, place them or configured Item Filters in the slots. info.actuallyadditions.noLens=No Lens info.actuallyadditions.booklet.manualName.1.1=Actually Additions info.actuallyadditions.booklet.manualName.1.2=Actual Additions