BuildCraft 6.2.6, update RF API

This commit is contained in:
asiekierka 2014-12-14 22:25:56 +01:00
parent 87fffc2456
commit fba2a37941
13 changed files with 159 additions and 36 deletions

View file

@ -6,6 +6,6 @@ public class CoFHAPIProps {
}
public static final String VERSION = "1.7.10R1.0.0";
public static final String VERSION = "1.7.10R1.0.1";
}

View file

@ -87,8 +87,8 @@ public class EnergyStorage implements IEnergyStorage {
}
/**
* This function is included to allow for server -> client sync. Do not call this externally to the containing Tile Entity, as not all IEnergyHandlers are
* guaranteed to have it.
* This function is included to allow for server -> client sync. Do not call this externally to the containing Tile Entity, as not all IEnergyHandlers
* are guaranteed to have it.
*
* @param energy
*/

View file

@ -5,7 +5,7 @@ import net.minecraftforge.common.util.ForgeDirection;
/**
* Implement this interface on TileEntities which should connect to energy transportation blocks. This is intended for blocks which generate energy but do not
* accept it; otherwise just use IEnergyHandler.
*
* <p>
* Note that {@link IEnergyHandler} is an extension of this.
*
* @author King Lemming

View file

@ -4,7 +4,7 @@ import net.minecraft.item.ItemStack;
/**
* Implement this interface on Item classes that support external manipulation of their internal energy storages.
*
* <p>
* A reference implementation is provided {@link ItemEnergyContainer}.
*
* @author King Lemming

View file

@ -4,16 +4,18 @@ import net.minecraftforge.common.util.ForgeDirection;
/**
* Implement this interface on Tile Entities which should handle energy, generally storing it in one or more internal {@link IEnergyStorage} objects.
*
* <p>
* A reference implementation is provided {@link TileEnergyHandler}.
*
* @author King Lemming
*
*/
public interface IEnergyHandler extends IEnergyConnection {
public interface IEnergyHandler extends IEnergyProvider, IEnergyReceiver {
// merely a convenience interface (remove these methods in 1.8; provided here for back-compat via compiler doing things)
/**
* Add energy to an IEnergyHandler, internal distribution is left entirely to the IEnergyHandler.
* Add energy to an IEnergyReceiver, internal distribution is left entirely to the IEnergyReceiver.
*
* @param from
* Orientation the energy is received from.
@ -23,10 +25,11 @@ public interface IEnergyHandler extends IEnergyConnection {
* If TRUE, the charge will only be simulated.
* @return Amount of energy that was (or would have been, if simulated) received.
*/
@Override
int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate);
/**
* Remove energy from an IEnergyHandler, internal distribution is left entirely to the IEnergyHandler.
* Remove energy from an IEnergyProvider, internal distribution is left entirely to the IEnergyProvider.
*
* @param from
* Orientation the energy is extracted from.
@ -36,16 +39,20 @@ public interface IEnergyHandler extends IEnergyConnection {
* If TRUE, the extraction will only be simulated.
* @return Amount of energy that was (or would have been, if simulated) extracted.
*/
@Override
int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate);
/**
* Returns the amount of energy currently stored.
*/
@Override
int getEnergyStored(ForgeDirection from);
/**
* Returns the maximum amount of energy that can be stored.
*/
@Override
int getMaxEnergyStored(ForgeDirection from);
}

View file

@ -0,0 +1,38 @@
package cofh.api.energy;
import net.minecraftforge.common.util.ForgeDirection;
/**
* Implement this interface on Tile Entities which should provide energy, generally storing it in one or more internal {@link IEnergyStorage} objects.
* <p>
* A reference implementation is provided {@link TileEnergyHandler}.
*
* @author King Lemming
*
*/
public interface IEnergyProvider extends IEnergyConnection {
/**
* Remove energy from an IEnergyProvider, internal distribution is left entirely to the IEnergyProvider.
*
* @param from
* Orientation the energy is extracted from.
* @param maxExtract
* Maximum amount of energy to extract.
* @param simulate
* If TRUE, the extraction will only be simulated.
* @return Amount of energy that was (or would have been, if simulated) extracted.
*/
int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate);
/**
* Returns the amount of energy currently stored.
*/
int getEnergyStored(ForgeDirection from);
/**
* Returns the maximum amount of energy that can be stored.
*/
int getMaxEnergyStored(ForgeDirection from);
}

View file

@ -0,0 +1,38 @@
package cofh.api.energy;
import net.minecraftforge.common.util.ForgeDirection;
/**
* Implement this interface on Tile Entities which should receive energy, generally storing it in one or more internal {@link IEnergyStorage} objects.
* <p>
* A reference implementation is provided {@link TileEnergyHandler}.
*
* @author King Lemming
*
*/
public interface IEnergyReceiver extends IEnergyConnection {
/**
* Add energy to an IEnergyReceiver, internal distribution is left entirely to the IEnergyReceiver.
*
* @param from
* Orientation the energy is received from.
* @param maxReceive
* Maximum amount of energy to receive.
* @param simulate
* If TRUE, the charge will only be simulated.
* @return Amount of energy that was (or would have been, if simulated) received.
*/
int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate);
/**
* Returns the amount of energy currently stored.
*/
int getEnergyStored(ForgeDirection from);
/**
* Returns the maximum amount of energy that can be stored.
*/
int getMaxEnergyStored(ForgeDirection from);
}

View file

@ -1,8 +1,9 @@
package cofh.api.energy;
/**
* An energy storage is the unit of interaction with Energy inventories.
*
* An energy storage is the unit of interaction with Energy inventories.<br>
* This is not to be implemented on TileEntities. This is for internal use only.
* <p>
* A reference implementation can be found at {@link EnergyStorage}.
*
* @author King Lemming

View file

@ -28,25 +28,28 @@ public class TileEnergyHandler extends TileEntity implements IEnergyHandler {
storage.writeToNBT(nbt);
}
/* IEnergyHandler */
/* IEnergyConnection */
@Override
public boolean canConnectEnergy(ForgeDirection from) {
return true;
}
/* IEnergyReceiver */
@Override
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate) {
return storage.receiveEnergy(maxReceive, simulate);
}
/* IEnergyProvider */
@Override
public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate) {
return storage.extractEnergy(maxExtract, simulate);
}
/* IEnergyReceiver and IEnergyProvider */
@Override
public int getEnergyStored(ForgeDirection from) {

View file

@ -22,7 +22,7 @@ apply plugin: 'forge' // adds the forge dependency
apply plugin: 'maven' // for uploading to a maven repo
apply plugin: 'checkstyle'
version = "6.2.5"
version = "6.2.6"
group= "com.mod-buildcraft"
archivesBaseName = "buildcraft" // the name that all artifacts will use as a base. artifacts names follow this pattern: [baseName]-[appendix]-[version]-[classifier].[extension]

View file

@ -15,7 +15,10 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import cofh.api.energy.IEnergyConnection;
import cofh.api.energy.IEnergyHandler;
import cofh.api.energy.IEnergyProvider;
import cofh.api.energy.IEnergyReceiver;
import buildcraft.BuildCraftCore;
import buildcraft.api.statements.IStatementContainer;
import buildcraft.api.statements.ITriggerExternal;
@ -57,10 +60,14 @@ public class DefaultTriggerProvider implements ITriggerProvider {
res.add(BuildCraftCore.triggerMachineInactive);
}
if (tile instanceof IEnergyHandler && ((IEnergyHandler) tile).getMaxEnergyStored(side.getOpposite()) > 0) {
if (tile instanceof IEnergyConnection && ((IEnergyConnection) tile).canConnectEnergy(side.getOpposite())) {
if ((tile instanceof IEnergyHandler && ((IEnergyHandler) tile).getMaxEnergyStored(side.getOpposite()) > 0)
|| (tile instanceof IEnergyReceiver && ((IEnergyReceiver) tile).getMaxEnergyStored(side.getOpposite()) > 0)
|| (tile instanceof IEnergyProvider && ((IEnergyProvider) tile).getMaxEnergyStored(side.getOpposite()) > 0)) {
res.add((ITriggerExternal) BuildCraftCore.triggerEnergyHigh);
res.add((ITriggerExternal) BuildCraftCore.triggerEnergyLow);
}
}
return res;
}

View file

@ -13,7 +13,10 @@ import net.minecraft.tileentity.TileEntity;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.common.util.ForgeDirection;
import cofh.api.energy.IEnergyConnection;
import cofh.api.energy.IEnergyHandler;
import cofh.api.energy.IEnergyProvider;
import cofh.api.energy.IEnergyReceiver;
import buildcraft.api.gates.IGate;
import buildcraft.api.statements.IStatementContainer;
import buildcraft.api.statements.IStatementParameter;
@ -36,13 +39,21 @@ public class TriggerEnergy extends BCStatement implements ITriggerInternal, ITri
return StringUtils.localize("gate.trigger.machine.energyStored" + (high ? "High" : "Low"));
}
private boolean isValidEnergyHandler(IEnergyHandler handler) {
return handler != null;
}
private boolean isTriggeredEnergyHandler(IEnergyConnection connection, ForgeDirection side) {
int energyStored, energyMaxStored;
private boolean isTriggeredEnergyHandler(IEnergyHandler handler, ForgeDirection side) {
int energyStored = handler.getEnergyStored(side);
int energyMaxStored = handler.getMaxEnergyStored(side);
if (connection instanceof IEnergyHandler) {
energyStored = ((IEnergyHandler) connection).getEnergyStored(side);
energyMaxStored = ((IEnergyHandler) connection).getMaxEnergyStored(side);
} else if (connection instanceof IEnergyProvider) {
energyStored = ((IEnergyProvider) connection).getEnergyStored(side);
energyMaxStored = ((IEnergyProvider) connection).getMaxEnergyStored(side);
} else if (connection instanceof IEnergyReceiver) {
energyStored = ((IEnergyReceiver) connection).getEnergyStored(side);
energyMaxStored = ((IEnergyReceiver) connection).getMaxEnergyStored(side);
} else {
return false;
}
if (energyMaxStored > 0) {
if (high) {
@ -58,11 +69,9 @@ public class TriggerEnergy extends BCStatement implements ITriggerInternal, ITri
if (container instanceof IGate) {
IGate gate = (IGate) container;
if (gate.getPipe() instanceof IEnergyHandler) {
if (isValidEnergyHandler((IEnergyHandler) gate.getPipe())) {
return isTriggeredEnergyHandler((IEnergyHandler) gate.getPipe(), ForgeDirection.UNKNOWN);
}
}
}
return false;
}
@ -70,10 +79,10 @@ public class TriggerEnergy extends BCStatement implements ITriggerInternal, ITri
@Override
public boolean isTriggerActive(TileEntity tile, ForgeDirection side, IStatementContainer container, IStatementParameter[] parameters) {
if (tile instanceof IEnergyHandler) {
// Since we return false upon the trigger being invalid anyway,
// we can skip the isValidEnergyHandler(...) check.
return isTriggeredEnergyHandler((IEnergyHandler) tile, side.getOpposite());
if (tile instanceof IEnergyHandler || tile instanceof IEnergyProvider || tile instanceof IEnergyReceiver) {
if (((IEnergyConnection) tile).canConnectEnergy(side.getOpposite())) {
return isTriggeredEnergyHandler((IEnergyConnection) tile, side.getOpposite());
}
}
return false;

View file

@ -17,6 +17,7 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import cofh.api.energy.IEnergyConnection;
import cofh.api.energy.IEnergyHandler;
import cofh.api.energy.IEnergyReceiver;
import buildcraft.BuildCraftCore;
import buildcraft.BuildCraftTransport;
import buildcraft.api.core.SafeTimeTracker;
@ -99,7 +100,7 @@ public class PipeTransportPower extends PipeTransport {
// Disregard engines for this.
return false;
}
if (tile instanceof IEnergyHandler) {
if (tile instanceof IEnergyHandler || tile instanceof IEnergyReceiver) {
IEnergyConnection handler = (IEnergyConnection) tile;
if (handler.canConnectEnergy(side.getOpposite())) {
return true;
@ -230,6 +231,16 @@ public class PipeTransportPower extends PipeTransport {
} else if (tiles[out] instanceof IEnergyHandler) {
IEnergyHandler handler = (IEnergyHandler) tiles[out];
if (handler.canConnectEnergy(ForgeDirection.VALID_DIRECTIONS[out].getOpposite())) {
// Transmit power to an RF energy handler
powerConsumed = handler.receiveEnergy(ForgeDirection.VALID_DIRECTIONS[out].getOpposite(),
powerConsumed, false);
tilePowered = true;
}
} else if (tiles[out] instanceof IEnergyReceiver) {
IEnergyReceiver handler = (IEnergyReceiver) tiles[out];
if (handler.canConnectEnergy(ForgeDirection.VALID_DIRECTIONS[out].getOpposite())) {
// Transmit power to an RF energy handler
@ -300,6 +311,15 @@ public class PipeTransportPower extends PipeTransport {
if (handler.canConnectEnergy(dir.getOpposite())) {
int request = handler.receiveEnergy(dir.getOpposite(), this.maxPower, true);
if (request > 0) {
requestEnergy(dir, request);
}
}
} else if (tile instanceof IEnergyReceiver) {
IEnergyReceiver handler = (IEnergyReceiver) tile;
if (handler.canConnectEnergy(dir.getOpposite())) {
int request = handler.receiveEnergy(dir.getOpposite(), this.maxPower, true);
if (request > 0) {
requestEnergy(dir, request);
}