Made Item Laser relays that have a whitelist have more priority than those who don't

This commit is contained in:
Ellpeck 2016-05-12 19:00:42 +02:00
parent 8e93abf05a
commit 3ad6b1c7cb

View file

@ -2,6 +2,7 @@ package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.mod.misc.LaserRelayConnectionHandler; import de.ellpeck.actuallyadditions.mod.misc.LaserRelayConnectionHandler;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelay.TileEntityLaserRelayItem; import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelay.TileEntityLaserRelayItem;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelay.TileEntityLaserRelayItemWhitelist;
import de.ellpeck.actuallyadditions.mod.util.PosUtil; import de.ellpeck.actuallyadditions.mod.util.PosUtil;
import de.ellpeck.actuallyadditions.mod.util.WorldUtil; import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -11,6 +12,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandler;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
public class TileEntityItemViewer extends TileEntityInventoryBase{ public class TileEntityItemViewer extends TileEntityInventoryBase{
@ -32,6 +34,7 @@ public class TileEntityItemViewer extends TileEntityInventoryBase{
private SpecificItemHandlerInfo getSwitchedIndexHandler(int i){ private SpecificItemHandlerInfo getSwitchedIndexHandler(int i){
List<GenericItemHandlerInfo> infos = this.getItemHandlerInfos(); List<GenericItemHandlerInfo> infos = this.getItemHandlerInfos();
Collections.sort(infos);
int currentI = 0; int currentI = 0;
if(infos != null && !infos.isEmpty()){ if(infos != null && !infos.isEmpty()){
for(GenericItemHandlerInfo info : infos){ for(GenericItemHandlerInfo info : infos){
@ -195,7 +198,7 @@ public class TileEntityItemViewer extends TileEntityInventoryBase{
} }
} }
public static class GenericItemHandlerInfo{ public static class GenericItemHandlerInfo implements Comparable<GenericItemHandlerInfo>{
public List<IItemHandler> handlers = new ArrayList<IItemHandler>(); public List<IItemHandler> handlers = new ArrayList<IItemHandler>();
public TileEntityLaserRelayItem relayInQuestion; public TileEntityLaserRelayItem relayInQuestion;
@ -221,5 +224,21 @@ public class TileEntityItemViewer extends TileEntityInventoryBase{
} }
return false; return false;
} }
@Override
public int compareTo(GenericItemHandlerInfo other){
if(other != null){
boolean thisWhitelist = this.relayInQuestion instanceof TileEntityLaserRelayItemWhitelist;
boolean otherWhitelist = other.relayInQuestion instanceof TileEntityLaserRelayItemWhitelist;
if(!thisWhitelist && otherWhitelist){
return 1;
}
else if(thisWhitelist && !otherWhitelist){
return -1;
}
}
return 0;
}
} }
} }