mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 08:48:34 +01:00
Made Laser Relay not output to the same block it got the energy from /cc Didi
This commit is contained in:
parent
4c6d76d82e
commit
bf65cc4edb
2 changed files with 19 additions and 15 deletions
|
@ -160,7 +160,7 @@ public class LaserRelayConnectionHandler{
|
|||
System.out.println("Merged Two Networks!");
|
||||
}
|
||||
|
||||
public int transferEnergyToReceiverInNeed(Network network, int maxTransfer, boolean simulate){
|
||||
public int transferEnergyToReceiverInNeed(WorldPos energyGottenFrom, Network network, int maxTransfer, boolean simulate){
|
||||
int transmitted = 0;
|
||||
//Go through all of the connections in the network
|
||||
for(ConnectionPair pair : network.connections){
|
||||
|
@ -171,18 +171,21 @@ public class LaserRelayConnectionHandler{
|
|||
//Get every side of the relay
|
||||
for(int i = 0; i <= 5; i++){
|
||||
ForgeDirection side = ForgeDirection.getOrientation(i);
|
||||
//Get the TileEntity at the side
|
||||
TileEntity tile = WorldUtil.getTileEntityFromSide(side, relay.getWorld(), relay.getX(), relay.getY(), relay.getZ());
|
||||
if(tile instanceof IEnergyReceiver && !(tile instanceof TileEntityLaserRelay)){
|
||||
IEnergyReceiver receiver = (IEnergyReceiver)tile;
|
||||
if(receiver.canConnectEnergy(side.getOpposite())){
|
||||
//Transfer the energy (with the energy loss!)
|
||||
int theoreticalReceived = ((IEnergyReceiver)tile).receiveEnergy(side.getOpposite(), maxTransfer-transmitted, true);
|
||||
//The amount of energy lost during a transfer
|
||||
int deduct = (int)(theoreticalReceived*((double)ConfigIntValues.LASER_RELAY_LOSS.getValue()/100));
|
||||
//Get the Position at the side
|
||||
WorldPos pos = WorldUtil.getCoordsFromSide(side, relay.getWorld(), relay.getX(), relay.getY(), relay.getZ(), 0);
|
||||
if(!pos.isEqual(energyGottenFrom)){
|
||||
TileEntity tile = pos.getTileEntity();
|
||||
if(tile instanceof IEnergyReceiver && !(tile instanceof TileEntityLaserRelay)){
|
||||
IEnergyReceiver receiver = (IEnergyReceiver)tile;
|
||||
if(receiver.canConnectEnergy(side.getOpposite())){
|
||||
//Transfer the energy (with the energy loss!)
|
||||
int theoreticalReceived = ((IEnergyReceiver)tile).receiveEnergy(side.getOpposite(), maxTransfer-transmitted, true);
|
||||
//The amount of energy lost during a transfer
|
||||
int deduct = (int)(theoreticalReceived*((double)ConfigIntValues.LASER_RELAY_LOSS.getValue()/100));
|
||||
|
||||
transmitted += ((IEnergyReceiver)tile).receiveEnergy(side.getOpposite(), theoreticalReceived-deduct, simulate);
|
||||
transmitted += deduct;
|
||||
transmitted += ((IEnergyReceiver)tile).receiveEnergy(side.getOpposite(), theoreticalReceived-deduct, simulate);
|
||||
transmitted += deduct;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import cpw.mods.fml.relauncher.SideOnly;
|
|||
import ellpeck.actuallyadditions.config.values.ConfigBoolValues;
|
||||
import ellpeck.actuallyadditions.misc.LaserRelayConnectionHandler;
|
||||
import ellpeck.actuallyadditions.util.WorldPos;
|
||||
import ellpeck.actuallyadditions.util.WorldUtil;
|
||||
import io.netty.util.internal.ConcurrentSet;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.particle.EntityReddustFX;
|
||||
|
@ -98,7 +99,7 @@ public class TileEntityLaserRelay extends TileEntityBase implements IEnergyRecei
|
|||
|
||||
@Override
|
||||
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate){
|
||||
return this.transmitEnergy(maxReceive, simulate);
|
||||
return this.transmitEnergy(WorldUtil.getCoordsFromSide(from, worldObj, xCoord, yCoord, zCoord, 0), maxReceive, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -111,12 +112,12 @@ public class TileEntityLaserRelay extends TileEntityBase implements IEnergyRecei
|
|||
return 0;
|
||||
}
|
||||
|
||||
public int transmitEnergy(int maxTransmit, boolean simulate){
|
||||
public int transmitEnergy(WorldPos blockFrom, int maxTransmit, boolean simulate){
|
||||
int transmitted = 0;
|
||||
if(maxTransmit > 0){
|
||||
LaserRelayConnectionHandler.Network network = LaserRelayConnectionHandler.getInstance().getNetworkFor(new WorldPos(this.worldObj, this.xCoord, this.yCoord, this.zCoord));
|
||||
if(network != null){
|
||||
transmitted = LaserRelayConnectionHandler.getInstance().transferEnergyToReceiverInNeed(network, maxTransmit, simulate);
|
||||
transmitted = LaserRelayConnectionHandler.getInstance().transferEnergyToReceiverInNeed(blockFrom, network, maxTransmit, simulate);
|
||||
}
|
||||
}
|
||||
return transmitted;
|
||||
|
|
Loading…
Reference in a new issue