mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-12-23 03:49:22 +01:00
Re-did the laser relay checking system so that it will never target one block twice
This commit is contained in:
parent
af2ef37554
commit
97c9e0f454
4 changed files with 47 additions and 55 deletions
|
@ -231,24 +231,6 @@ public class TileEntityItemViewer extends TileEntityInventoryBase{
|
|||
this.relayInQuestion = relayInQuestion;
|
||||
}
|
||||
|
||||
public static boolean containsHandler(List<GenericItemHandlerInfo> infos, IItemHandler handler){
|
||||
for(GenericItemHandlerInfo info : infos){
|
||||
if(info.handlers.contains(handler)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean containsTile(List<GenericItemHandlerInfo> infos, TileEntityLaserRelayItem tile){
|
||||
for(GenericItemHandlerInfo info : infos){
|
||||
if(info.relayInQuestion == tile){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(GenericItemHandlerInfo other){
|
||||
boolean thisWhitelist = this.relayInQuestion instanceof TileEntityLaserRelayItemWhitelist;
|
||||
|
|
|
@ -89,10 +89,10 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay implements
|
|||
|
||||
private int transferEnergyToReceiverInNeed(EnumFacing from, Network network, int maxTransfer, boolean simulate){
|
||||
int transmitted = 0;
|
||||
//Keeps track of all the Laser Relays and Energy Acceptors that have been checked already to make nothing run multiple times
|
||||
List<BlockPos> alreadyChecked = new ArrayList<BlockPos>();
|
||||
//Go through all of the connections in the network
|
||||
|
||||
for(ConnectionPair pair : network.connections){
|
||||
//Go through both relays in the connection
|
||||
for(BlockPos relay : pair.positions){
|
||||
if(relay != null && !alreadyChecked.contains(relay)){
|
||||
alreadyChecked.add(relay);
|
||||
|
@ -106,29 +106,32 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay implements
|
|||
EnumFacing side = receiver.getKey();
|
||||
EnumFacing opp = side.getOpposite();
|
||||
TileEntity tile = receiver.getValue();
|
||||
if(theRelay != this || side != from){
|
||||
if(tile instanceof IEnergyReceiver){
|
||||
IEnergyReceiver iReceiver = (IEnergyReceiver)tile;
|
||||
if(iReceiver.canConnectEnergy(opp)){
|
||||
int theoreticalReceived = iReceiver.receiveEnergy(opp, Math.min(maxTransfer, lowestCap)-transmitted, true);
|
||||
int deduct = this.calcDeduction(theoreticalReceived, highestLoss);
|
||||
transmitted += iReceiver.receiveEnergy(opp, theoreticalReceived-deduct, simulate);
|
||||
transmitted += deduct;
|
||||
if(!alreadyChecked.contains(tile.getPos())){
|
||||
alreadyChecked.add(tile.getPos());
|
||||
if(theRelay != this || side != from){
|
||||
if(tile instanceof IEnergyReceiver){
|
||||
IEnergyReceiver iReceiver = (IEnergyReceiver)tile;
|
||||
if(iReceiver.canConnectEnergy(opp)){
|
||||
int theoreticalReceived = iReceiver.receiveEnergy(opp, Math.min(maxTransfer, lowestCap)-transmitted, true);
|
||||
int deduct = this.calcDeduction(theoreticalReceived, highestLoss);
|
||||
transmitted += iReceiver.receiveEnergy(opp, theoreticalReceived-deduct, simulate);
|
||||
transmitted += deduct;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(ActuallyAdditions.teslaLoaded && tile.hasCapability(TeslaUtil.teslaConsumer, opp)){
|
||||
ITeslaConsumer cap = tile.getCapability(TeslaUtil.teslaConsumer, opp);
|
||||
if(cap != null){
|
||||
int theoreticalReceived = (int)cap.givePower(Math.min(maxTransfer, lowestCap)-transmitted, true);
|
||||
int deduct = this.calcDeduction(theoreticalReceived, highestLoss);
|
||||
transmitted += cap.givePower(theoreticalReceived-deduct, simulate);
|
||||
transmitted += deduct;
|
||||
else if(ActuallyAdditions.teslaLoaded && tile.hasCapability(TeslaUtil.teslaConsumer, opp)){
|
||||
ITeslaConsumer cap = tile.getCapability(TeslaUtil.teslaConsumer, opp);
|
||||
if(cap != null){
|
||||
int theoreticalReceived = (int)cap.givePower(Math.min(maxTransfer, lowestCap)-transmitted, true);
|
||||
int deduct = this.calcDeduction(theoreticalReceived, highestLoss);
|
||||
transmitted += cap.givePower(theoreticalReceived-deduct, simulate);
|
||||
transmitted += deduct;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//If everything that could be transmitted was transmitted
|
||||
if(transmitted >= maxTransfer){
|
||||
return transmitted;
|
||||
//If everything that could be transmitted was transmitted
|
||||
if(transmitted >= maxTransfer){
|
||||
return transmitted;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,11 +22,13 @@ import net.minecraftforge.items.CapabilityItemHandler;
|
|||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class TileEntityLaserRelayItem extends TileEntityLaserRelay{
|
||||
|
||||
public final List<IItemHandler> handlersAround = new ArrayList<IItemHandler>();
|
||||
public final Map<BlockPos, IItemHandler> handlersAround = new HashMap<BlockPos, IItemHandler>();
|
||||
|
||||
public TileEntityLaserRelayItem(String name){
|
||||
super(name, true);
|
||||
|
@ -48,35 +50,39 @@ public class TileEntityLaserRelayItem extends TileEntityLaserRelay{
|
|||
EnumFacing side = WorldUtil.getDirectionBySidesInOrder(i);
|
||||
BlockPos pos = this.getPos().offset(side);
|
||||
TileEntity tile = this.worldObj.getTileEntity(pos);
|
||||
if(tile != null && !(tile instanceof TileEntityItemViewer)){
|
||||
if(tile != null && !(tile instanceof TileEntityItemViewer) && !(tile instanceof TileEntityLaserRelay)){
|
||||
IItemHandler handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side.getOpposite());
|
||||
if(handler != null){
|
||||
this.handlersAround.add(handler);
|
||||
this.handlersAround.put(tile.getPos(), handler);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<GenericItemHandlerInfo> getItemHandlersInNetwork(Network network){
|
||||
//Keeps track of all the Laser Relays and Item Handlers that have been checked already to make nothing run multiple times
|
||||
List<BlockPos> alreadyChecked = new ArrayList<BlockPos>();
|
||||
|
||||
List<GenericItemHandlerInfo> handlers = new ArrayList<GenericItemHandlerInfo>();
|
||||
for(ConnectionPair pair : network.connections){
|
||||
for(BlockPos relay : pair.positions){
|
||||
if(relay != null){
|
||||
if(relay != null && !alreadyChecked.contains(relay)){
|
||||
alreadyChecked.add(relay);
|
||||
TileEntity aRelayTile = this.worldObj.getTileEntity(relay);
|
||||
if(aRelayTile instanceof TileEntityLaserRelayItem){
|
||||
TileEntityLaserRelayItem relayTile = (TileEntityLaserRelayItem)aRelayTile;
|
||||
if(!GenericItemHandlerInfo.containsTile(handlers, relayTile)){
|
||||
GenericItemHandlerInfo info = new GenericItemHandlerInfo(relayTile);
|
||||
GenericItemHandlerInfo info = new GenericItemHandlerInfo(relayTile);
|
||||
|
||||
List<IItemHandler> handlersAroundTile = relayTile.handlersAround;
|
||||
for(IItemHandler handler : handlersAroundTile){
|
||||
if(!GenericItemHandlerInfo.containsHandler(handlers, handler)){
|
||||
info.handlers.add(handler);
|
||||
}
|
||||
Map<BlockPos, IItemHandler> handlersAroundTile = relayTile.handlersAround;
|
||||
for(Map.Entry<BlockPos, IItemHandler> handler : handlersAroundTile.entrySet()){
|
||||
if(!alreadyChecked.contains(handler.getKey())){
|
||||
alreadyChecked.add(handler.getKey());
|
||||
|
||||
info.handlers.add(handler.getValue());
|
||||
}
|
||||
|
||||
handlers.add(info);
|
||||
}
|
||||
|
||||
handlers.add(info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,11 +18,13 @@ import net.minecraft.entity.player.EntityPlayer;
|
|||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem implements IButtonReactor{
|
||||
|
||||
|
@ -204,8 +206,7 @@ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem
|
|||
|
||||
private void addWhitelistSmart(boolean output){
|
||||
FilterSettings usedSettings = output ? this.rightFilter : this.leftFilter;
|
||||
List<IItemHandler> handlers = this.handlersAround;
|
||||
for(IItemHandler handler : handlers){
|
||||
for(IItemHandler handler : this.handlersAround.values()){
|
||||
for(int i = 0; i < handler.getSlots(); i++){
|
||||
ItemStack stack = handler.getStackInSlot(i);
|
||||
if(stack != null){
|
||||
|
|
Loading…
Reference in a new issue