Added smart whitelist button to the whitelist laser relay that automatically adds items from adjacent chests to the whitelist

This commit is contained in:
Ellpeck 2016-05-14 13:13:35 +02:00
parent 1f2f0e7cbf
commit 1df694c8e9
3 changed files with 59 additions and 13 deletions

View file

@ -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<String> list = new ArrayList<String>();
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

View file

@ -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<IItemHandler> getAllHandlersAround(){
List<IItemHandler> handlers = new ArrayList<IItemHandler>();
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<GenericItemHandlerInfo> getItemHandlersInNetwork(LaserRelayConnectionHandler.Network network){
List<GenericItemHandlerInfo> handlers = new ArrayList<GenericItemHandlerInfo>();
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)){
List<IItemHandler> 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<IItemHandler> 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

View file

@ -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 <p> at.
info.actuallyadditions.inputter.info.2=This is the slot after the last Slot in the connected Inventory to <p> at. What that means: If you, for example, write 2 in the field to the left and 5 in this one, it will <p> 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.