Change the way UE integration works in Universal Cables

This commit is contained in:
Aidan Brady 2013-11-30 01:28:40 -05:00
parent 150c5dee0b
commit 14fb453bb8

View file

@ -5,9 +5,7 @@ import ic2.api.energy.event.EnergyTileUnloadEvent;
import ic2.api.energy.tile.IEnergySink; import ic2.api.energy.tile.IEnergySink;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set;
import mekanism.api.transmitters.ITransmitter; import mekanism.api.transmitters.ITransmitter;
import mekanism.api.transmitters.TransmissionType; import mekanism.api.transmitters.TransmissionType;
@ -15,16 +13,13 @@ import mekanism.api.transmitters.TransmitterNetworkRegistry;
import mekanism.common.EnergyNetwork; import mekanism.common.EnergyNetwork;
import mekanism.common.Mekanism; import mekanism.common.Mekanism;
import mekanism.common.Object3D; import mekanism.common.Object3D;
import mekanism.common.PacketHandler;
import mekanism.common.PacketHandler.Transmission;
import mekanism.common.network.PacketDataRequest;
import mekanism.common.util.CableUtils; import mekanism.common.util.CableUtils;
import mekanism.common.util.MekanismUtils; import mekanism.common.util.MekanismUtils;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import universalelectricity.core.block.IConductor; import universalelectricity.core.block.IElectrical;
import universalelectricity.core.electricity.ElectricityPack; import universalelectricity.core.electricity.ElectricityPack;
import universalelectricity.core.grid.IElectricityNetwork; import universalelectricity.core.grid.IElectricityNetwork;
import buildcraft.api.power.IPowerEmitter; import buildcraft.api.power.IPowerEmitter;
@ -33,7 +28,7 @@ import buildcraft.api.power.PowerHandler;
import buildcraft.api.power.PowerHandler.PowerReceiver; import buildcraft.api.power.PowerHandler.PowerReceiver;
import cofh.api.energy.IEnergyHandler; import cofh.api.energy.IEnergyHandler;
public class TileEntityUniversalCable extends TileEntityTransmitter<EnergyNetwork> implements IPowerReceptor, IEnergySink, IConductor, IEnergyHandler public class TileEntityUniversalCable extends TileEntityTransmitter<EnergyNetwork> implements IPowerReceptor, IEnergySink, IEnergyHandler, IElectrical
{ {
/** A fake power handler used to initiate energy transfer calculations. */ /** A fake power handler used to initiate energy transfer calculations. */
public PowerHandler powerHandler; public PowerHandler powerHandler;
@ -45,7 +40,6 @@ public class TileEntityUniversalCable extends TileEntityTransmitter<EnergyNetwor
public TileEntityUniversalCable() public TileEntityUniversalCable()
{ {
ueNetwork = new FakeUENetwork();
powerHandler = new PowerHandler(this, PowerHandler.Type.STORAGE); powerHandler = new PowerHandler(this, PowerHandler.Type.STORAGE);
powerHandler.configurePowerPerdition(0, 0); powerHandler.configurePowerPerdition(0, 0);
powerHandler.configure(0, 0, 0, 0); powerHandler.configure(0, 0, 0, 0);
@ -301,42 +295,6 @@ public class TileEntityUniversalCable extends TileEntityTransmitter<EnergyNetwor
return getTransmitterNetwork().getFlow(); return getTransmitterNetwork().getFlow();
} }
@Override
public IElectricityNetwork getNetwork()
{
return ueNetwork;
}
@Override
public void setNetwork(IElectricityNetwork network) {}
@Override
public TileEntity[] getAdjacentConnections()
{
return new TileEntity[6];
}
@Override
public void refresh() {}
@Override
public boolean canConnect(ForgeDirection direction)
{
return true;
}
@Override
public float getResistance()
{
return 0;
}
@Override
public float getCurrentCapacity()
{
return Integer.MAX_VALUE;
}
@Override @Override
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate) public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate)
{ {
@ -377,60 +335,49 @@ public class TileEntityUniversalCable extends TileEntityTransmitter<EnergyNetwor
return (int)Math.round(getTransmitterNetwork().getEnergyNeeded(list)*Mekanism.TO_TE); return (int)Math.round(getTransmitterNetwork().getEnergyNeeded(list)*Mekanism.TO_TE);
} }
public class FakeUENetwork implements IElectricityNetwork @Override
public boolean canConnect(ForgeDirection direction)
{ {
@Override return true;
public void split(IConductor connection) {}
@Override
public void refresh() {}
@Override
public void merge(IElectricityNetwork network) {}
@Override
public ArrayList<ForgeDirection> getPossibleDirections(TileEntity tile)
{
return new ArrayList<ForgeDirection>();
} }
@Override @Override
public Set<IConductor> getConductors() public float receiveElectricity(ForgeDirection from, ElectricityPack receive, boolean doReceive)
{ {
return new HashSet<IConductor>(); ArrayList list = new ArrayList();
list.add(Object3D.get(this).getFromSide(from).getTileEntity(worldObj));
if(doReceive && receive != null && receive.getWatts() > 0)
{
return receive.getWatts() - (float)(getTransmitterNetwork().emit(receive.getWatts()*Mekanism.FROM_UE, list));
}
return 0;
} }
@Override @Override
public Set<TileEntity> getAcceptors() public ElectricityPack provideElectricity(ForgeDirection from, ElectricityPack request, boolean doProvide)
{ {
return getTransmitterNetwork().getAcceptors(); return null;
} }
@Override @Override
public float produce(ElectricityPack electricityPack, TileEntity... ignoreTiles) public float getRequest(ForgeDirection direction)
{ {
ArrayList<TileEntity> ignore = new ArrayList<TileEntity>(); ArrayList list = new ArrayList();
ignore.addAll(Arrays.asList(ignoreTiles)); list.add(Object3D.get(this).getFromSide(direction).getTileEntity(worldObj));
double energy = electricityPack.getWatts() * Mekanism.FROM_UE; return (float)(getTransmitterNetwork().getEnergyNeeded(list)*Mekanism.TO_UE);
return (float)getTransmitterNetwork().emit(energy, ignore);
} }
@Override @Override
public float getTotalResistance() public float getProvide(ForgeDirection direction)
{ {
return 0; return 0;
} }
@Override @Override
public ElectricityPack getRequest(TileEntity... ignoreTiles) public float getVoltage()
{ {
return ElectricityPack.getFromWatts((float)getTransmitterNetwork().getEnergyNeeded(new ArrayList<TileEntity>()), 0.12F); return 120;
}
@Override
public float getLowestCurrentCapacity()
{
return Integer.MAX_VALUE;
}
} }
} }