Updated BuildCraft API, implemented full-fledged BC energy support, allowed Logistical Transporters to connect to BuildCraft machines, allowed Logistical Transporters to output to double chests, fixed energy leak
This commit is contained in:
parent
e2e9c791a2
commit
f27381453c
14 changed files with 353 additions and 65 deletions
|
@ -19,12 +19,12 @@ public class ActionManager {
|
|||
triggerProviders.add(provider);
|
||||
}
|
||||
}
|
||||
|
||||
public static void registerTrigger(ITrigger trigger){
|
||||
|
||||
public static void registerTrigger(ITrigger trigger) {
|
||||
triggers.put(trigger.getUniqueTag(), trigger);
|
||||
}
|
||||
|
||||
public static void registerAction(IAction action){
|
||||
|
||||
public static void registerAction(IAction action) {
|
||||
actions.put(action.getUniqueTag(), action);
|
||||
}
|
||||
|
||||
|
@ -52,6 +52,7 @@ public class ActionManager {
|
|||
}
|
||||
}
|
||||
|
||||
//TODO: Use sets not lists
|
||||
public static LinkedList<IAction> getNeighborActions(Block block, TileEntity entity) {
|
||||
LinkedList<IAction> actions = new LinkedList<IAction>();
|
||||
|
||||
|
@ -87,18 +88,18 @@ public class ActionManager {
|
|||
|
||||
return triggers;
|
||||
}
|
||||
|
||||
public static ITrigger getTriggerFromLegacyId(int legacyId){
|
||||
for(ITrigger trigger : triggers.values()){
|
||||
if(trigger.getLegacyId() == legacyId)
|
||||
|
||||
public static ITrigger getTriggerFromLegacyId(int legacyId) {
|
||||
for (ITrigger trigger : triggers.values()) {
|
||||
if (trigger.getLegacyId() == legacyId)
|
||||
return trigger;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static IAction getActionFromLegacyId(int legacyId){
|
||||
for(IAction action : actions.values()){
|
||||
if(action.getLegacyId() == legacyId)
|
||||
|
||||
public static IAction getActionFromLegacyId(int legacyId) {
|
||||
for (IAction action : actions.values()) {
|
||||
if (action.getLegacyId() == legacyId)
|
||||
return action;
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -28,6 +28,11 @@ public interface ITrigger {
|
|||
*/
|
||||
boolean hasParameter();
|
||||
|
||||
/**
|
||||
* Return true if this trigger requires a parameter
|
||||
*/
|
||||
boolean requiresParameter();
|
||||
|
||||
/**
|
||||
* Return the trigger description in the UI
|
||||
*/
|
||||
|
|
|
@ -13,6 +13,7 @@ public interface ITriggerParameter {
|
|||
|
||||
public abstract void readFromNBT(NBTTagCompound compound);
|
||||
|
||||
@Deprecated
|
||||
public abstract ItemStack getItem();
|
||||
|
||||
}
|
||||
|
|
|
@ -66,12 +66,8 @@ public class TriggerParameter implements ITriggerParameter {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see net.minecraft.src.buildcraft.api.gates.ITriggerParameter#getItem()
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public ItemStack getItem() {
|
||||
return stack;
|
||||
}
|
||||
|
|
|
@ -11,6 +11,24 @@ import buildcraft.api.core.SafeTimeTracker;
|
|||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
/**
|
||||
* The PowerHandler is similar to FluidTank in that it holds your power and
|
||||
* allows standardized interaction between machines.
|
||||
*
|
||||
* To receive power to your machine you needs create an instance of PowerHandler
|
||||
* and implement IPowerReceptor on the TileEntity.
|
||||
*
|
||||
* If you plan emit power, you need only implement IPowerEmitter. You do not
|
||||
* need a PowerHandler. Engines have a PowerHandler because they can also
|
||||
* receive power from other Engines.
|
||||
*
|
||||
* See TileRefinery for a simple example of a power using machine.
|
||||
*
|
||||
* @see IPowerReceptor
|
||||
* @see IPowerEmitter
|
||||
*
|
||||
* @author CovertJaguar <http://www.railcraft.info/>
|
||||
*/
|
||||
public final class PowerHandler {
|
||||
|
||||
public static enum Type {
|
||||
|
@ -76,18 +94,20 @@ public final class PowerHandler {
|
|||
* @return
|
||||
*/
|
||||
public float applyPerdition(PowerHandler powerHandler, float current, long ticksPassed) {
|
||||
// float prev = current;
|
||||
current -= powerLoss * ticksPassed;
|
||||
if (current < 0) {
|
||||
current = 0;
|
||||
}
|
||||
// powerHandler.totalLostPower += prev - current;
|
||||
return current;
|
||||
}
|
||||
|
||||
/**
|
||||
* Taxes a flat rate on all incoming power.
|
||||
*
|
||||
*
|
||||
* Defaults to 0% tax rate.
|
||||
*
|
||||
*
|
||||
* @return percent of input to tax
|
||||
*/
|
||||
public float getTaxPercent() {
|
||||
|
@ -108,6 +128,11 @@ public final class PowerHandler {
|
|||
private PerditionCalculator perdition;
|
||||
private final PowerReceiver receiver;
|
||||
private final Type type;
|
||||
// Debug
|
||||
// private double totalLostPower = 0;
|
||||
// private double totalReceivedPower = 0;
|
||||
// private double totalUsedPower = 0;
|
||||
// private long startTime = -1;
|
||||
|
||||
public PowerHandler(IPowerReceptor receptor, Type type) {
|
||||
this.receptor = receptor;
|
||||
|
@ -168,6 +193,16 @@ public final class PowerHandler {
|
|||
this.activationEnergy = activationEnergy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows you define perdition in terms of loss/ticks.
|
||||
*
|
||||
* This function is mostly for legacy implementations. See
|
||||
* PerditionCalculator for more complex perdition formulas.
|
||||
*
|
||||
* @param powerLoss
|
||||
* @param powerLossRegularity
|
||||
* @see PerditionCalculator
|
||||
*/
|
||||
public void configurePowerPerdition(int powerLoss, int powerLossRegularity) {
|
||||
if (powerLoss == 0 || powerLossRegularity == 0) {
|
||||
perdition = new PerditionCalculator(0);
|
||||
|
@ -207,6 +242,13 @@ public final class PowerHandler {
|
|||
* design around this though if you are aware of the limitations.
|
||||
*/
|
||||
public void update() {
|
||||
// if (startTime == -1)
|
||||
// startTime = receptor.getWorld().getTotalWorldTime();
|
||||
// else {
|
||||
// long duration = receptor.getWorld().getTotalWorldTime() - startTime;
|
||||
// System.out.printf("Power Stats: %s - Stored: %.2f Gained: %.2f - %.2f/t Lost: %.2f - %.2f/t Used: %.2f - %.2f/t%n", receptor.getClass().getSimpleName(), energyStored, totalReceivedPower, totalReceivedPower / duration, totalLostPower, totalLostPower / duration, totalUsedPower, totalUsedPower / duration);
|
||||
// }
|
||||
|
||||
applyPerdition();
|
||||
applyWork();
|
||||
validateEnergy();
|
||||
|
@ -275,6 +317,9 @@ public final class PowerHandler {
|
|||
|
||||
validateEnergy();
|
||||
|
||||
// if (doUse)
|
||||
// totalUsedPower += result;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -343,6 +388,8 @@ public final class PowerHandler {
|
|||
/**
|
||||
* Add power to the PowerReceiver from an external source.
|
||||
*
|
||||
* IPowerEmitters are responsible for calling this themselves.
|
||||
*
|
||||
* @param quantity
|
||||
* @param from
|
||||
* @return the amount of power used
|
||||
|
@ -358,7 +405,7 @@ public final class PowerHandler {
|
|||
}
|
||||
|
||||
updateSources(from);
|
||||
|
||||
|
||||
used -= used * getPerdition().getTaxPercent();
|
||||
|
||||
used = addEnergy(used);
|
||||
|
@ -366,9 +413,11 @@ public final class PowerHandler {
|
|||
applyWork();
|
||||
|
||||
if (source == Type.ENGINE && type.eatsEngineExcess()) {
|
||||
return Math.min(quantity, maxEnergyReceived);
|
||||
used = Math.min(quantity, maxEnergyReceived);
|
||||
}
|
||||
|
||||
// totalReceivedPower += used;
|
||||
|
||||
return used;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -243,6 +243,14 @@ public class GuiRobitMain extends GuiContainer
|
|||
return (int)(robit.getEnergy()*i / robit.MAX_ELECTRICITY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen()
|
||||
{
|
||||
super.updateScreen();
|
||||
|
||||
nameChangeField.updateCursorCounter();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int button)
|
||||
{
|
||||
|
|
|
@ -11,10 +11,12 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import mekanism.api.Object3D;
|
||||
import mekanism.api.energy.IStrictEnergyAcceptor;
|
||||
import mekanism.api.transmitters.DynamicNetwork;
|
||||
import mekanism.api.transmitters.ITransmitter;
|
||||
import mekanism.api.transmitters.TransmissionType;
|
||||
import mekanism.common.tileentity.TileEntityUniversalCable;
|
||||
import mekanism.common.util.CableUtils;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
@ -86,7 +88,7 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
|
|||
}
|
||||
else if(acceptor instanceof IElectrical)
|
||||
{
|
||||
totalNeeded += ((IElectrical)acceptor).getRequest(acceptorDirections.get(acceptor))*Mekanism.FROM_UE;
|
||||
totalNeeded += ((IElectrical)acceptor).getRequest(acceptorDirections.get(acceptor).getOpposite())*Mekanism.FROM_UE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -115,6 +117,7 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
|
|||
{
|
||||
TileEntity acceptor = (TileEntity)obj;
|
||||
double currentSending = sending+remaining;
|
||||
ForgeDirection side = acceptorDirections.get(acceptor);
|
||||
|
||||
remaining = 0;
|
||||
|
||||
|
@ -125,21 +128,23 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
|
|||
else if(acceptor instanceof IEnergySink)
|
||||
{
|
||||
double toSend = Math.min(currentSending, (((IEnergySink)acceptor).getMaxSafeInput()*Mekanism.FROM_IC2));
|
||||
energyToSend -= (toSend - (((IEnergySink)acceptor).injectEnergyUnits(acceptorDirections.get(acceptor).getOpposite(), toSend*Mekanism.TO_IC2)*Mekanism.FROM_IC2));
|
||||
energyToSend -= (toSend - (((IEnergySink)acceptor).injectEnergyUnits(side.getOpposite(), toSend*Mekanism.TO_IC2)*Mekanism.FROM_IC2));
|
||||
}
|
||||
else if(acceptor instanceof IPowerReceptor && MekanismUtils.useBuildcraft())
|
||||
{
|
||||
PowerReceiver receiver = ((IPowerReceptor)acceptor).getPowerReceiver(acceptorDirections.get(acceptor).getOpposite());
|
||||
double electricityNeeded = Math.min(receiver.powerRequest(), receiver.getMaxEnergyStored() - receiver.getEnergyStored())*Mekanism.FROM_BC;
|
||||
double transferEnergy = Math.min(electricityNeeded, currentSending);
|
||||
receiver.receiveEnergy(Type.STORAGE, (float)(transferEnergy*Mekanism.TO_BC), acceptorDirections.get(acceptor).getOpposite());
|
||||
energyToSend -= transferEnergy;
|
||||
PowerReceiver receiver = ((IPowerReceptor)acceptor).getPowerReceiver(side.getOpposite());
|
||||
|
||||
if(receiver != null)
|
||||
{
|
||||
float toSend = receiver.receiveEnergy(Type.PIPE, (float)(Math.min(receiver.powerRequest(), currentSending*Mekanism.TO_BC)), side.getOpposite());
|
||||
energyToSend -= toSend*Mekanism.FROM_BC;
|
||||
}
|
||||
}
|
||||
else if(acceptor instanceof IElectrical)
|
||||
{
|
||||
double toSend = Math.min(currentSending, ((IElectrical)acceptor).getRequest(acceptorDirections.get(acceptor).getOpposite())*Mekanism.FROM_UE);
|
||||
double toSend = Math.min(currentSending, ((IElectrical)acceptor).getRequest(side.getOpposite())*Mekanism.FROM_UE);
|
||||
ElectricityPack pack = ElectricityPack.getFromWatts((float)(toSend*Mekanism.TO_UE), ((IElectrical)acceptor).getVoltage());
|
||||
energyToSend -= ((IElectrical)acceptor).receiveElectricity(acceptorDirections.get(acceptor).getOpposite(), pack, true)*Mekanism.FROM_UE;
|
||||
energyToSend -= ((IElectrical)acceptor).receiveElectricity(side.getOpposite(), pack, true)*Mekanism.FROM_UE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -184,7 +189,12 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
|
|||
{
|
||||
if((((IPowerReceptor)acceptor).getPowerReceiver(acceptorDirections.get(acceptor).getOpposite()).powerRequest()*Mekanism.FROM_BC) > 0)
|
||||
{
|
||||
toReturn.add(acceptor);
|
||||
TileEntityUniversalCable cable = (TileEntityUniversalCable)Object3D.get(acceptor).getFromSide(acceptorDirections.get(acceptor).getOpposite()).getTileEntity(acceptor.worldObj);
|
||||
|
||||
if(cable != null && !cable.getBuildCraftIgnored().contains(acceptor))
|
||||
{
|
||||
toReturn.add(acceptor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -168,7 +168,7 @@ public class TileEntityChargepad extends TileEntityElectricBlock implements IAct
|
|||
@Override
|
||||
protected EnumSet<ForgeDirection> getConsumingSides()
|
||||
{
|
||||
return EnumSet.of(ForgeDirection.DOWN, ForgeDirection.getOrientation(facing));
|
||||
return EnumSet.of(ForgeDirection.DOWN, ForgeDirection.getOrientation(facing).getOpposite());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -243,7 +243,7 @@ public class TileEntityChargepad extends TileEntityElectricBlock implements IAct
|
|||
@Override
|
||||
public boolean canReceiveEnergy(ForgeDirection side)
|
||||
{
|
||||
return side == ForgeDirection.DOWN || side == ForgeDirection.getOrientation(facing).getOpposite();
|
||||
return getConsumingSides().contains(side);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -281,7 +281,7 @@ public class TileEntityChargepad extends TileEntityElectricBlock implements IAct
|
|||
@Override
|
||||
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction)
|
||||
{
|
||||
return direction == ForgeDirection.DOWN || direction == ForgeDirection.getOrientation(facing).getOpposite();
|
||||
return getConsumingSides().contains(direction);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -12,6 +12,7 @@ import mekanism.api.Object3D;
|
|||
import mekanism.api.energy.IStrictEnergyStorage;
|
||||
import mekanism.common.ITileNetwork;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
@ -48,8 +49,9 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
|
|||
super(name);
|
||||
MAX_ELECTRICITY = maxEnergy;
|
||||
|
||||
powerHandler = new PowerHandler(this, PowerHandler.Type.MACHINE);
|
||||
powerHandler.configure(0, 100, 0, (int)(maxEnergy*Mekanism.TO_BC));
|
||||
powerHandler = new PowerHandler(this, PowerHandler.Type.STORAGE);
|
||||
powerHandler.configurePowerPerdition(0, 0);
|
||||
powerHandler.configure(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
public void register()
|
||||
|
@ -67,13 +69,7 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
|
|||
@Override
|
||||
public void onUpdate()
|
||||
{
|
||||
if(!worldObj.isRemote)
|
||||
{
|
||||
if(getEnergy() < getMaxEnergy() && powerHandler.getEnergyStored() > 0)
|
||||
{
|
||||
setEnergy(getEnergy() + powerHandler.useEnergy(0, (float)((getMaxEnergy()-getEnergy())*Mekanism.TO_BC), true)*Mekanism.FROM_BC);
|
||||
}
|
||||
}
|
||||
reconfigure();
|
||||
}
|
||||
|
||||
public ForgeDirection getOutputtingSide()
|
||||
|
@ -154,7 +150,7 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
|
|||
super.readFromNBT(nbtTags);
|
||||
|
||||
electricityStored = nbtTags.getDouble("electricityStored");
|
||||
powerHandler.readFromNBT(nbtTags);
|
||||
reconfigure();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -163,7 +159,6 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
|
|||
super.writeToNBT(nbtTags);
|
||||
|
||||
nbtTags.setDouble("electricityStored", getEnergy());
|
||||
powerHandler.writeToNBT(nbtTags);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -172,8 +167,34 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
|
|||
return powerHandler.getPowerReceiver();
|
||||
}
|
||||
|
||||
protected void reconfigure()
|
||||
{
|
||||
if(MekanismUtils.useBuildcraft())
|
||||
{
|
||||
powerHandler.configure(1, (float)((getMaxEnergy()-getEnergy())*Mekanism.TO_BC), 0, (float)(getMaxEnergy()*Mekanism.TO_BC));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doWork(PowerHandler workProvider) {}
|
||||
public void doWork(PowerHandler workProvider)
|
||||
{
|
||||
if(powerHandler.getEnergyStored() > 0)
|
||||
{
|
||||
if(getEnergy() < getMaxEnergy())
|
||||
{
|
||||
setEnergy(getEnergy() + powerHandler.useEnergy(0, (float)((getMaxEnergy()-getEnergy())*Mekanism.TO_BC), true)*Mekanism.FROM_BC);
|
||||
}
|
||||
|
||||
if(powerHandler.getEnergyStored() > 0)
|
||||
{
|
||||
System.out.println(powerHandler.getEnergyStored() + "J of energy was just wasted.");
|
||||
}
|
||||
|
||||
powerHandler.setEnergy(0);
|
||||
}
|
||||
|
||||
reconfigure();
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld()
|
||||
|
|
|
@ -20,13 +20,19 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
import buildcraft.api.transport.IPipe;
|
||||
import buildcraft.api.transport.IPipeTile;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class TileEntityLogisticalTransporter extends TileEntity implements ITileNetwork
|
||||
public class TileEntityLogisticalTransporter extends TileEntity implements ITileNetwork, IPipeTile
|
||||
{
|
||||
public static final int SPEED = 5;
|
||||
|
||||
|
@ -382,4 +388,81 @@ public class TileEntityLogisticalTransporter extends TileEntity implements ITile
|
|||
{
|
||||
return INFINITE_EXTENT_AABB;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSolidOnSide(ForgeDirection side)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFill(ForgeDirection from, Fluid fluid)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDrain(ForgeDirection from, Fluid fluid)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidTankInfo[] getTankInfo(ForgeDirection from)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPipe getPipe()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PipeType getPipeType()
|
||||
{
|
||||
return PipeType.ITEM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int injectItem(ItemStack stack, boolean doAdd, ForgeDirection from)
|
||||
{
|
||||
if(doAdd)
|
||||
{
|
||||
if(TransporterUtils.insert(Object3D.get(this).getFromSide(from).getTileEntity(worldObj), this, stack, null))
|
||||
{
|
||||
return stack.stackSize;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPipeConnected(ForgeDirection with)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import mekanism.api.transmitters.TransmissionType;
|
|||
import mekanism.common.EnergyNetwork;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.util.CableUtils;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
@ -23,6 +24,7 @@ import net.minecraftforge.common.MinecraftForge;
|
|||
import universalelectricity.core.block.IConductor;
|
||||
import universalelectricity.core.electricity.ElectricityPack;
|
||||
import universalelectricity.core.grid.IElectricityNetwork;
|
||||
import buildcraft.api.power.IPowerEmitter;
|
||||
import buildcraft.api.power.IPowerReceptor;
|
||||
import buildcraft.api.power.PowerHandler;
|
||||
import buildcraft.api.power.PowerHandler.PowerReceiver;
|
||||
|
@ -41,7 +43,8 @@ public class TileEntityUniversalCable extends TileEntityTransmitter<EnergyNetwor
|
|||
{
|
||||
ueNetwork = new FakeUENetwork();
|
||||
powerHandler = new PowerHandler(this, PowerHandler.Type.STORAGE);
|
||||
powerHandler.configure(0, 100, 0, 100);
|
||||
powerHandler.configurePowerPerdition(0, 0);
|
||||
powerHandler.configure(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -135,6 +138,7 @@ public class TileEntityUniversalCable extends TileEntityTransmitter<EnergyNetwor
|
|||
}
|
||||
|
||||
getTransmitterNetwork().refresh();
|
||||
reconfigure();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -167,9 +171,64 @@ public class TileEntityUniversalCable extends TileEntityTransmitter<EnergyNetwor
|
|||
{
|
||||
return worldObj;
|
||||
}
|
||||
|
||||
private void reconfigure()
|
||||
{
|
||||
if(MekanismUtils.useBuildcraft())
|
||||
{
|
||||
float needed = (float)(getTransmitterNetwork().getEnergyNeeded(getBuildCraftIgnored())*Mekanism.TO_BC);
|
||||
powerHandler.configure(1, needed, 0, needed);
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<TileEntity> getBuildCraftIgnored()
|
||||
{
|
||||
ArrayList<TileEntity> ignored = new ArrayList<TileEntity>();
|
||||
|
||||
for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
TileEntity tile = Object3D.get(this).getFromSide(side).getTileEntity(worldObj);
|
||||
|
||||
if(tile != null)
|
||||
{
|
||||
if(powerHandler.powerSources[side.ordinal()] > 0)
|
||||
{
|
||||
ignored.add(tile);
|
||||
}
|
||||
else if(tile instanceof IPowerEmitter)
|
||||
{
|
||||
IPowerEmitter emitter = (IPowerEmitter)tile;
|
||||
|
||||
if(emitter.canEmitPowerFrom(side.getOpposite()))
|
||||
{
|
||||
ignored.add(tile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ignored;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doWork(PowerHandler workProvider) {}
|
||||
public void doWork(PowerHandler workProvider)
|
||||
{
|
||||
if(MekanismUtils.useBuildcraft())
|
||||
{
|
||||
if(powerHandler.getEnergyStored() > 0)
|
||||
{
|
||||
double rejected = getTransmitterNetwork().emit(powerHandler.getEnergyStored()*Mekanism.FROM_BC, getBuildCraftIgnored());
|
||||
|
||||
if(rejected > 0)
|
||||
{
|
||||
System.out.println(rejected + "J of energy was just wasted.");
|
||||
}
|
||||
}
|
||||
|
||||
powerHandler.setEnergy(0);
|
||||
reconfigure();
|
||||
}
|
||||
}
|
||||
|
||||
public void setCachedEnergy(double scale)
|
||||
{
|
||||
|
@ -190,7 +249,7 @@ public class TileEntityUniversalCable extends TileEntityTransmitter<EnergyNetwor
|
|||
@Override
|
||||
public double demandedEnergyUnits()
|
||||
{
|
||||
return getTransmitterNetwork().getEnergyNeeded(new ArrayList())*Mekanism.TO_IC2;
|
||||
return getTransmitterNetwork().getEnergyNeeded(getBuildCraftIgnored())*Mekanism.TO_IC2;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -287,10 +287,9 @@ public final class CableUtils
|
|||
|
||||
if(receiver != null)
|
||||
{
|
||||
double electricityNeeded = Math.min(receiver.powerRequest(), receiver.getMaxEnergyStored() - receiver.getEnergyStored())*Mekanism.FROM_BC;
|
||||
double transferEnergy = Math.min(emitter.getEnergy(), Math.min(electricityNeeded, emitter.getMaxOutput()));
|
||||
receiver.receiveEnergy(Type.STORAGE, (float)(transferEnergy*Mekanism.TO_BC), emitter.getOutputtingSide().getOpposite());
|
||||
emitter.setEnergy(emitter.getEnergy() - transferEnergy);
|
||||
double transferEnergy = Math.min(emitter.getEnergy(), Math.min(receiver.powerRequest()*Mekanism.FROM_BC, emitter.getMaxOutput()));
|
||||
float sent = receiver.receiveEnergy(Type.STORAGE, (float)(transferEnergy*Mekanism.TO_BC), emitter.getOutputtingSide().getOpposite());
|
||||
emitter.setEnergy(emitter.getEnergy() - sent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,9 +13,13 @@ import mekanism.common.transporter.TransporterStack;
|
|||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.inventory.InventoryLargeChest;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityChest;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import buildcraft.api.power.IPowerReceptor;
|
||||
import buildcraft.api.power.PowerHandler.Type;
|
||||
|
||||
public final class TransporterUtils
|
||||
{
|
||||
|
@ -82,10 +86,20 @@ public final class TransporterUtils
|
|||
for(IInventory inventory : connectedInventories)
|
||||
{
|
||||
if(inventory != null)
|
||||
{
|
||||
{
|
||||
int side = Arrays.asList(connectedInventories).indexOf(inventory);
|
||||
ForgeDirection forgeSide = ForgeDirection.getOrientation(side).getOpposite();
|
||||
|
||||
//Immature BuildCraft inv check
|
||||
if(MekanismUtils.useBuildcraft() && inventory instanceof IPowerReceptor)
|
||||
{
|
||||
if(((IPowerReceptor)inventory).getPowerReceiver(forgeSide).getType() == Type.MACHINE)
|
||||
{
|
||||
connectable[side] = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if(inventory.getSizeInventory() > 0)
|
||||
{
|
||||
if(inventory instanceof ISidedInventory)
|
||||
|
@ -170,6 +184,8 @@ public final class TransporterUtils
|
|||
|
||||
if(!(inventory instanceof ISidedInventory))
|
||||
{
|
||||
inventory = checkChestInv(inventory);
|
||||
|
||||
for(int i = 0; i <= inventory.getSizeInventory() - 1; i++)
|
||||
{
|
||||
if(inventory.isItemValidForSlot(i, itemStack))
|
||||
|
@ -239,12 +255,47 @@ public final class TransporterUtils
|
|||
return false;
|
||||
}
|
||||
|
||||
public static IInventory checkChestInv(IInventory inv)
|
||||
{
|
||||
if(inv instanceof TileEntityChest)
|
||||
{
|
||||
TileEntityChest main = (TileEntityChest)inv;
|
||||
TileEntityChest adj = null;
|
||||
|
||||
if(main.adjacentChestXNeg != null)
|
||||
{
|
||||
adj = main.adjacentChestXNeg;
|
||||
}
|
||||
else if(main.adjacentChestXPos != null)
|
||||
{
|
||||
adj = main.adjacentChestXPos;
|
||||
}
|
||||
else if(main.adjacentChestZNeg != null)
|
||||
{
|
||||
adj = main.adjacentChestZNeg;
|
||||
}
|
||||
else if(main.adjacentChestZPosition != null)
|
||||
{
|
||||
adj = main.adjacentChestZPosition;
|
||||
}
|
||||
|
||||
if(adj != null)
|
||||
{
|
||||
return new InventoryLargeChest("", main, adj);
|
||||
}
|
||||
}
|
||||
|
||||
return inv;
|
||||
}
|
||||
|
||||
public static ItemStack putStackInInventory(IInventory inventory, ItemStack itemStack, int side)
|
||||
{
|
||||
ItemStack toInsert = itemStack.copy();
|
||||
|
||||
if(!(inventory instanceof ISidedInventory))
|
||||
{
|
||||
inventory = checkChestInv(inventory);
|
||||
|
||||
for(int i = 0; i <= inventory.getSizeInventory() - 1; i++)
|
||||
{
|
||||
if(inventory.isItemValidForSlot(i, toInsert))
|
||||
|
|
|
@ -8,7 +8,6 @@ import java.util.EnumSet;
|
|||
|
||||
import mekanism.api.Object3D;
|
||||
import mekanism.api.energy.ICableOutputter;
|
||||
import mekanism.api.transmitters.TransmissionType;
|
||||
import mekanism.client.sound.IHasSound;
|
||||
import mekanism.common.IActiveState;
|
||||
import mekanism.common.IRedstoneControl;
|
||||
|
@ -20,18 +19,12 @@ import mekanism.common.tileentity.TileEntityElectricBlock;
|
|||
import mekanism.common.tileentity.TileEntityUniversalCable;
|
||||
import mekanism.common.util.CableUtils;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import mekanism.generators.common.MekanismGenerators;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import universalelectricity.core.block.IConductor;
|
||||
import universalelectricity.core.electricity.ElectricityHelper;
|
||||
import universalelectricity.core.electricity.ElectricityPack;
|
||||
import universalelectricity.core.grid.IElectricityNetwork;
|
||||
import buildcraft.api.power.IPowerEmitter;
|
||||
import buildcraft.api.power.IPowerReceptor;
|
||||
import buildcraft.api.power.PowerHandler.PowerReceiver;
|
||||
import buildcraft.api.power.PowerHandler.Type;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
|
||||
|
@ -40,7 +33,7 @@ import cpw.mods.fml.relauncher.SideOnly;
|
|||
import dan200.computer.api.IComputerAccess;
|
||||
import dan200.computer.api.IPeripheral;
|
||||
|
||||
public abstract class TileEntityGenerator extends TileEntityElectricBlock implements IEnergySource, IEnergyStorage, IPowerReceptor, IPeripheral, IActiveState, IHasSound, ICableOutputter, IRedstoneControl
|
||||
public abstract class TileEntityGenerator extends TileEntityElectricBlock implements IEnergySource, IEnergyStorage, IPowerReceptor, IPeripheral, IActiveState, IHasSound, ICableOutputter, IRedstoneControl, IPowerEmitter
|
||||
{
|
||||
/** Output per tick this generator can transfer. */
|
||||
public double output;
|
||||
|
@ -67,7 +60,7 @@ public abstract class TileEntityGenerator extends TileEntityElectricBlock implem
|
|||
{
|
||||
super(name, maxEnergy);
|
||||
|
||||
powerHandler.configure(0, 0, 0, (int)(maxEnergy*Mekanism.TO_BC));
|
||||
powerHandler.configure(0, 0, 0, 0);
|
||||
|
||||
output = out;
|
||||
isActive = false;
|
||||
|
@ -353,4 +346,16 @@ public abstract class TileEntityGenerator extends TileEntityElectricBlock implem
|
|||
{
|
||||
controlType = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canEmitPowerFrom(ForgeDirection side)
|
||||
{
|
||||
return getOutputtingSide() == side;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void reconfigure()
|
||||
{
|
||||
powerHandler.configure(0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue