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 b393643fb..36fcac329 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 @@ -31,6 +31,7 @@ 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) @@ -55,8 +56,11 @@ public class GuiLaserRelayItemWhitelist extends GuiContainer{ this.whitelistLeft = new SmallerButton(0, this.guiLeft+3, this.guiTop+16, ""); this.whitelistRight = new SmallerButton(1, this.guiLeft+157, this.guiTop+16, ""); + SmallerButton smartWhitelist = new SmallerButton(2, this.guiLeft+80, this.guiTop+33, "S"); + this.buttonList.add(this.whitelistLeft); this.buttonList.add(this.whitelistRight); + this.buttonList.add(smartWhitelist); } @Override @@ -87,6 +91,12 @@ public class GuiLaserRelayItemWhitelist extends GuiContainer{ list.addAll(infoList); this.drawHoveringText(list, x, y); } + if(x >= this.guiLeft+80 && y >= this.guiTop+33 && x <= this.guiLeft+95 && y <= this.guiTop+46){ + 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); + } } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelay.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelay.java index 847677996..733feee3b 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelay.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelay.java @@ -17,10 +17,7 @@ import de.ellpeck.actuallyadditions.mod.misc.LaserRelayConnectionHandler; import de.ellpeck.actuallyadditions.mod.network.PacketParticle; import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor; import de.ellpeck.actuallyadditions.mod.tile.TileEntityItemViewer.GenericItemHandlerInfo; -import de.ellpeck.actuallyadditions.mod.util.PosUtil; -import de.ellpeck.actuallyadditions.mod.util.StringUtil; -import de.ellpeck.actuallyadditions.mod.util.Util; -import de.ellpeck.actuallyadditions.mod.util.WorldUtil; +import de.ellpeck.actuallyadditions.mod.util.*; import io.netty.util.internal.ConcurrentSet; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; @@ -132,6 +129,22 @@ public abstract class TileEntityLaserRelay extends TileEntityBase{ return true; } + public List getAllHandlersAround(){ + List handlers = new ArrayList(); + for(int i = 0; i <= 5; i++){ + EnumFacing side = WorldUtil.getDirectionBySidesInOrder(i); + BlockPos pos = WorldUtil.getCoordsFromSide(side, this.getPos(), 0); + TileEntity tile = this.worldObj.getTileEntity(pos); + if(tile != null && !(tile instanceof TileEntityItemViewer)){ + IItemHandler handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side.getOpposite()); + if(handler != null){ + handlers.add(handler); + } + } + } + return handlers; + } + public List getItemHandlersInNetwork(LaserRelayConnectionHandler.Network network){ List handlers = new ArrayList(); for(LaserRelayConnectionHandler.ConnectionPair pair : network.connections){ @@ -143,17 +156,14 @@ public abstract class TileEntityLaserRelay extends TileEntityBase{ TileEntityLaserRelayItem relayTile = (TileEntityLaserRelayItem)aRelayTile; if(!GenericItemHandlerInfo.containsTile(handlers, relayTile)){ GenericItemHandlerInfo info = new GenericItemHandlerInfo(relayTile); - for(int i = 0; i <= 5; i++){ - EnumFacing side = WorldUtil.getDirectionBySidesInOrder(i); - BlockPos pos = WorldUtil.getCoordsFromSide(side, relay, 0); - TileEntity tile = this.worldObj.getTileEntity(pos); - if(tile != null && !(tile instanceof TileEntityItemViewer)){ - IItemHandler handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side.getOpposite()); - if(handler != null && !GenericItemHandlerInfo.containsHandler(handlers, handler)){ - info.handlers.add(handler); - } + + List handlersAroundTile = relayTile.getAllHandlersAround(); + for(IItemHandler handler : handlersAroundTile){ + if(!GenericItemHandlerInfo.containsHandler(handlers, handler)){ + info.handlers.add(handler); } } + handlers.add(info); } } @@ -346,6 +356,30 @@ public abstract class TileEntityLaserRelay extends TileEntityBase{ else if(buttonID == 1){ this.isRightWhitelist = !this.isRightWhitelist; } + else if(buttonID == 2){ + this.addWhitelistSmart(); + } + } + + private void addWhitelistSmart(){ + List handlers = this.getAllHandlersAround(); + for(IItemHandler handler : handlers){ + for(int i = 0; i < handler.getSlots(); i++){ + ItemStack stack = handler.getStackInSlot(i); + if(stack != null){ + if(!ItemUtil.contains(this.slots, stack, false)){ + for(int j = 0; j < this.slots.length; j++){ + if(this.slots[j] == null || this.slots[j].stackSize <= 0){ + ItemStack whitelistStack = stack.copy(); + whitelistStack.stackSize = 1; + this.slots[j] = whitelistStack; + break; + } + } + } + } + } + } } @Override diff --git a/src/main/resources/assets/actuallyadditions/lang/en_US.lang b/src/main/resources/assets/actuallyadditions/lang/en_US.lang index 928ded2b9..efcd4cd01 100644 --- a/src/main/resources/assets/actuallyadditions/lang/en_US.lang +++ b/src/main/resources/assets/actuallyadditions/lang/en_US.lang @@ -535,6 +535,8 @@ info.actuallyadditions.gui.blacklist=Blacklist info.actuallyadditions.gui.coffee=Coffee info.actuallyadditions.gui.ok=Ok info.actuallyadditions.gui.the=the +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 the white- and blacklist. First, the left side will be completely filled, and if there's more items, they will go to the right side. 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=This applies for this part of the white-/blacklist. The other side applies as well, so you can have some Items whitelisted and some blacklisted. Note that, if you have an empty blacklist or an item whitelisted on at least one side, it will always go through.