Update BC API and fix up EnergyNet and CableUtils to work with the new MjAPI

This commit is contained in:
Ben Spiers 2014-07-31 18:41:32 +01:00
parent d8321196d9
commit d7c060d6fb
28 changed files with 231 additions and 902 deletions

View file

@ -31,7 +31,7 @@ public final class BCLog {
logger.info("http://www.mod-buildcraft.com");
}
public static void logErrorAPI(String mod, Throwable error, Class<?> classFile) {
public static void logErrorAPI(String mod, Throwable error, Class classFile) {
StringBuilder msg = new StringBuilder(mod);
msg.append(" API error, please update your mods. Error: ").append(error);
StackTraceElement[] stackTrace = error.getStackTrace();

View file

@ -1,104 +0,0 @@
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.api.core;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
/**
* This class is a comparable container for block positions. TODO: should this be merged with position?
*/
public class BlockIndex implements Comparable<BlockIndex> {
public int x;
public int y;
public int z;
public BlockIndex() {
}
/**
* Creates an index for a block located on x, y. z
*/
public BlockIndex(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
public BlockIndex(NBTTagCompound c) {
this.x = c.getInteger("i");
this.y = c.getInteger("j");
this.z = c.getInteger("k");
}
public BlockIndex(Entity entity) {
x = (int) Math.floor(entity.posX);
y = (int) Math.floor(entity.posY);
z = (int) Math.floor(entity.posZ);
}
/**
* Provides a deterministic and complete ordering of block positions.
*/
@Override
public int compareTo(BlockIndex o) {
if (o.x < x) {
return 1;
} else if (o.x > x) {
return -1;
} else if (o.z < z) {
return 1;
} else if (o.z > z) {
return -1;
} else if (o.y < y) {
return 1;
} else if (o.y > y) {
return -1;
} else {
return 0;
}
}
public void writeTo(NBTTagCompound c) {
c.setInteger("i", x);
c.setInteger("j", y);
c.setInteger("k", z);
}
public Block getBlock(World world) {
return world.getBlock(x, y, z);
}
@Override
public String toString() {
return "{" + x + ", " + y + ", " + z + "}";
}
@Override
public boolean equals(Object obj) {
if (obj instanceof BlockIndex) {
BlockIndex b = (BlockIndex) obj;
return b.x == x && b.y == y && b.z == z;
}
return super.equals(obj);
}
@Override
public int hashCode() {
return (x * 37 + y) * 37 + z;
}
}

View file

@ -12,7 +12,7 @@ import java.util.HashSet;
import java.util.Set;
import net.minecraft.block.Block;
import net.minecraft.world.World;
import net.minecraft.world.IBlockAccess;
public final class BuildCraftAPI {
@ -20,23 +20,18 @@ public final class BuildCraftAPI {
public static final Set<Block> softBlocks = new HashSet<Block>();
public static IWorldProperty isSoftProperty;
public static IWorldProperty isWoodProperty;
public static IWorldProperty isLeavesProperty;
public static IWorldProperty isBasicOreProperty;
public static IWorldProperty isExtendedOreProperty;
public static IWorldProperty isHarvestableProperty;
public static IWorldProperty isFarmlandProperty;
public static IWorldProperty isDirtProperty;
public static IWorldProperty isShoveled;
/**
* Deactivate constructor
*/
private BuildCraftAPI() {
}
public static boolean isSoftBlock(World world, int x, int y, int z) {
return isSoftProperty.get(world, x, y, z);
public static boolean isSoftBlock(IBlockAccess world, int x, int y, int z) {
return isSoftBlock(world.getBlock(x, y, z), world, x, y, z);
}
public static boolean isSoftBlock(Block block, IBlockAccess world, int x, int y, int z) {
return block == null || BuildCraftAPI.softBlocks.contains(block) || block.isReplaceable(world, x, y, z) || block.isAir(world, x, y, z);
}
}

View file

@ -22,7 +22,7 @@ public interface IInvSlot {
boolean canTakeStackFromSlot(ItemStack stack);
ItemStack decreaseStackInSlot(int amount);
ItemStack decreaseStackInSlot();
ItemStack getStackInSlot();

View file

@ -1,18 +0,0 @@
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.api.core;
import net.minecraft.world.World;
public interface IWorldProperty {
boolean get(World world, int x, int y, int z);
void clear();
}

View file

@ -50,10 +50,10 @@ public class JavaTools {
return c;
}
public static List<Field> getAllFields(Class<?> clas) {
public static List<Field> getAllFields(Class clas) {
List<Field> result = new ArrayList<Field>();
Class<?> current = clas;
Class current = clas;
while (current != null && current != Object.class) {
for (Field f : current.getDeclaredFields()) {
@ -66,10 +66,10 @@ public class JavaTools {
return result;
}
public static List<Method> getAllMethods(Class<?> clas) {
public static List<Method> getAllMethods(Class clas) {
List<Method> result = new ArrayList<Method>();
Class<?> current = clas;
Class current = clas;
while (current != null && current != Object.class) {
for (Method m : current.getDeclaredMethods()) {

View file

@ -8,9 +8,12 @@
*/
package buildcraft.api.mj;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.logging.Level;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.core.BCLog;
import buildcraft.api.core.JavaTools;
@ -19,7 +22,7 @@ import buildcraft.api.core.JavaTools;
* battery field is of type double, and is the only piece of data specific to
* this object. Others are class-wide.
*/
public class BatteryObject implements IBatteryIOObject, MjReconfigurator.IConfigurableBatteryObject {
public class BatteryObject implements IBatteryIOObject {
protected Field energyStored;
protected Object obj;
protected MjBattery batteryData;
@ -54,6 +57,9 @@ public class BatteryObject implements IBatteryIOObject, MjReconfigurator.IConfig
*/
@Override
public double addEnergy(double mj, boolean ignoreCycleLimit) {
if (!batteryData.mode().canReceive) {
return 0;
}
try {
double contained = energyStored.getDouble(obj);
double maxAccepted = batteryData.maxCapacity() - contained + batteryData.minimumConsumption();
@ -68,30 +74,7 @@ public class BatteryObject implements IBatteryIOObject, MjReconfigurator.IConfig
} catch (IllegalAccessException e) {
BCLog.logger.log(Level.WARNING, "can't add energy", e);
}
return 0;
}
@Override
public double extractEnergy(double mj) {
return extractEnergy(mj, false);
}
@Override
public double extractEnergy(double mj, boolean ignoreCycleLimit) {
try {
double contained = energyStored.getDouble(obj);
double maxExtracted = contained;
if (!ignoreCycleLimit && maxExtracted > batteryData.maxSendedPerCycle()) {
maxExtracted = batteryData.maxSendedPerCycle();
}
double used = Math.min(maxExtracted, mj);
if (used > 0) {
energyStored.setDouble(obj, Math.max(contained - used, 0));
return used;
}
} catch (IllegalAccessException e) {
BCLog.logger.log(Level.WARNING, "can't extract energy", e);
}
return 0;
}
@ -145,23 +128,61 @@ public class BatteryObject implements IBatteryIOObject, MjReconfigurator.IConfig
return batteryData.maxReceivedPerCycle();
}
/**
* {@inheritDoc}
*/
@Override
public BatteryObject reconfigure(double maxCapacity, double maxReceivedPerCycle, double minimumConsumption) {
overrideBattery(maxCapacity, maxReceivedPerCycle, minimumConsumption,
batteryData.kind(), batteryData.sides(), batteryData.mode());
return this;
}
public void overrideBattery(final double maxCapacity, final double maxReceivedPerCycle, final double minimumConsumption,
final String kind, final ForgeDirection[] sides, final IOMode mode) {
batteryData = new MjBattery() {
@Override
public double maxCapacity() {
return maxCapacity;
}
@Override
public double maxReceivedPerCycle() {
return maxReceivedPerCycle;
}
@Override
public double minimumConsumption() {
return minimumConsumption;
}
@Override
public Class<? extends Annotation> annotationType() {
return MjBattery.class;
}
@Override
public String kind() {
return kind;
}
@Override
public ForgeDirection[] sides() {
return sides;
}
@Override
public IOMode mode() {
return mode;
}
};
}
@Override
public String kind() {
return batteryData.kind();
}
@Override
public void init(Object object, Field storedField, MjBattery battery) {
this.obj = object;
this.energyStored = storedField;
this.batteryData = battery;
}
@Override
public double maxSendedPerCycle() {
return batteryData.maxSendedPerCycle();
}
@Override
public IOMode mode() {
return batteryData.mode();
@ -176,24 +197,4 @@ public class BatteryObject implements IBatteryIOObject, MjReconfigurator.IConfig
public boolean canReceive() {
return batteryData.mode().canReceive;
}
@Override
public boolean isActive() {
return batteryData.mode().active;
}
@Override
public boolean isCacheable() {
return batteryData.cacheable();
}
@Override
public MjBattery getMjBattery() {
return batteryData;
}
@Override
public void setMjBattery(MjBattery battery) {
batteryData = battery;
}
}

View file

@ -9,19 +9,9 @@
package buildcraft.api.mj;
public interface IBatteryIOObject extends IBatteryObject {
double maxSendedPerCycle();
double extractEnergy(double mj);
double extractEnergy(double mj, boolean ignoreCycleLimit);
IOMode mode();
boolean canSend();
boolean canReceive();
boolean isActive();
boolean isCacheable();
}

View file

@ -8,8 +8,6 @@
*/
package buildcraft.api.mj;
import java.lang.reflect.Field;
public interface IBatteryObject {
/**
* @return Current energy requirement for keeping machine state
@ -47,31 +45,39 @@ public interface IBatteryObject {
void setEnergyStored(double mj);
/**
* Can be overrided via {@link #reconfigure(double, double, double)}
*
* @return Maximal energy amount for this battery.
*/
double maxCapacity();
/**
* Can be overrided via {@link #reconfigure(double, double, double)}
*
* @return Minimal energy amount for keep your machine in active state
*/
double minimumConsumption();
/**
* Can be overrided via {@link #reconfigure(double, double, double)}
*
* @return Maximal energy received per one tick
*/
double maxReceivedPerCycle();
/**
* Allow to dynamically reconfigure your battery.
* Usually it's not very good change battery parameters for already present machines, but if you want...
*
* @param maxCapacity {@link #maxCapacity()}
* @param maxReceivedPerCycle {@link #maxReceivedPerCycle()}
* @param minimumConsumption {@link #minimumConsumption()}
* @return Current battery object instance
*/
IBatteryObject reconfigure(double maxCapacity, double maxReceivedPerCycle, double minimumConsumption);
/**
* @return kind of this energy battery
*/
String kind();
/**
* Basic initialization method
*
* @param object Basic object which hold a battery field
* @param storedField Field for energy storing
* @param battery Battery data
*/
void init(Object object, Field storedField, MjBattery battery);
}

View file

@ -9,22 +9,12 @@
package buildcraft.api.mj;
public enum IOMode {
Both(true, true, false),
BothActive(true, true, true),
Both(true, true), Receive(true, false), Send(false, true), None(false, false);
Receive(true, false, false),
ReceiveActive(true, false, true),
public final boolean canReceive, canSend;
Send(false, true, false),
SendActive(false, true, true),
None(false, false, false);
public final boolean canReceive, canSend, active;
IOMode(boolean canReceive, boolean canSend, boolean active) {
IOMode(boolean canReceive, boolean canSend) {
this.canReceive = canReceive;
this.canSend = canSend;
this.active = active;
}
}

View file

@ -12,19 +12,12 @@ import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.logging.Level;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.core.BCLog;
import buildcraft.api.core.JavaTools;
import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerHandler;
import gnu.trove.map.TIntObjectMap;
import gnu.trove.map.hash.TIntObjectHashMap;
/**
* The class MjAPI provides services to the Minecraft Joules power framework.
@ -33,13 +26,10 @@ import gnu.trove.map.hash.TIntObjectHashMap;
* Joules batteries and provide different models.
*/
public final class MjAPI {
public static final String DEFAULT_POWER_FRAMEWORK = "buildcraft.kinesis";
private static Map<BatteryHolder, BatteryField> mjBatteryFields = new HashMap<BatteryHolder, BatteryField>();
private static Map<String, Class<? extends IBatteryObject>> mjBatteryKinds = new HashMap<String, Class<? extends IBatteryObject>>();
private static Map<BatteryHolder, BatteryField> mjBatteries = new HashMap<BatteryHolder, BatteryField>();
private static Map<String, Class<? extends BatteryObject>> mjBatteryKinds = new HashMap<String, Class<? extends BatteryObject>>();
private static final BatteryField invalidBatteryField = new BatteryField();
private static final MjReconfigurator reconfigurator = new MjReconfigurator();
private static final Map<Object, BatteryCache> mjBatteryCache = new WeakHashMap<Object, BatteryCache>();
/**
* Deactivate constructor
@ -48,106 +38,79 @@ public final class MjAPI {
}
/**
* @see #getMjBattery(Object, String, ForgeDirection)
* Returns the default battery related to the object given in parameter. For
* performance optimization, it's good to cache this object in the providing
* power framework if possible.
*/
public static IBatteryObject getMjBattery(Object o) {
return getMjBattery(o, null, null);
return getMjBattery(o, DEFAULT_POWER_FRAMEWORK);
}
/**
* @see #getMjBattery(Object, String, ForgeDirection)
* Returns the battery related to the object given in parameter. For
* performance optimization, it's good to cache this object in the providing
* power framework if possible.
*/
public static IBatteryObject getMjBattery(Object o, String kind) {
return getMjBattery(o, kind, null);
return getMjBattery(o, kind, ForgeDirection.UNKNOWN);
}
/**
* @see #getMjBattery(Object, String, ForgeDirection)
* Returns the battery related to the object given in parameter. For
* performance optimization, it's good to cache this object in the providing
* power framework if possible.
*/
public static IBatteryObject getMjBattery(Object o, ForgeDirection side) {
return getMjBattery(o, null, side);
}
/**
* Returns the battery related to the object given in parameter.
*/
public static IBatteryObject getMjBattery(Object o, String kindRaw, ForgeDirection sideRaw) {
public static IBatteryObject getMjBattery(Object o, String kind, ForgeDirection side) {
if (o == null) {
return null;
}
String kind = kindRaw == null ? DEFAULT_POWER_FRAMEWORK : kindRaw;
ForgeDirection side = sideRaw == null ? ForgeDirection.UNKNOWN : sideRaw;
IBatteryObject battery;
BatteryCache cache = mjBatteryCache.get(o);
if (cache == null) {
cache = new BatteryCache();
mjBatteryCache.put(o, cache);
} else {
battery = cache.get(kind, side);
if (isCacheable(battery)) {
return battery;
}
}
IBatteryObject battery = null;
if (o instanceof ISidedBatteryProvider) {
battery = ((ISidedBatteryProvider) o).getMjBattery(kind, side);
if (battery == null && side != ForgeDirection.UNKNOWN) {
battery = ((ISidedBatteryProvider) o).getMjBattery(kind, ForgeDirection.UNKNOWN);
}
} else if (o instanceof IBatteryProvider) {
battery = ((IBatteryProvider) o).getMjBattery(kind);
} else {
battery = createBattery(o, kind, side);
}
if (battery == null && o instanceof IPowerReceptor) {
PowerHandler.PowerReceiver receiver = ((IPowerReceptor) o).getPowerReceiver(side);
if (receiver == null && side != ForgeDirection.UNKNOWN) {
receiver = ((IPowerReceptor) o).getPowerReceiver(ForgeDirection.UNKNOWN);
}
if (receiver != null) {
battery = receiver.getMjBattery();
}
}
cache.put(kind, side, battery);
return battery;
}
/**
* Create new battery instance.
* This method ignore all providers/caches and only create battery for given kind/side.
*
* @param o Object which contains {@link MjBattery}
* @param kind Kind of power
* @param side Side of block
* @return New {@link IBatteryObject} implementation registered for given kind of power
*/
public static IBatteryObject createBattery(Object o, String kind, ForgeDirection side) {
if (o == null) {
return null;
if (o instanceof IBatteryProvider) {
battery = ((IBatteryProvider) o).getMjBattery(kind);
}
if (battery != null) {
return battery;
}
BatteryField f = getMjBatteryField(o.getClass(), kind, side);
if (f == null && side != ForgeDirection.UNKNOWN) {
f = getMjBatteryField(o.getClass(), kind, ForgeDirection.UNKNOWN);
}
if (f == null) {
return null;
} else if (!mjBatteryKinds.containsKey(kind)) {
return null;
} else if (f.kind == BatteryKind.Value) {
try {
IBatteryObject obj = mjBatteryKinds.get(kind).newInstance();
obj.init(o, f.field, f.battery);
BatteryObject obj = mjBatteryKinds.get(kind).newInstance();
obj.obj = o;
obj.energyStored = f.field;
obj.batteryData = f.battery;
return obj;
} catch (InstantiationException e) {
BCLog.logger.log(Level.WARNING, "can't instantiate class for energy kind \"" + kind + "\"");
return null;
} catch (IllegalAccessException e) {
BCLog.logger.log(Level.WARNING, "can't instantiate class for energy kind \"" + kind + "\"");
return null;
}
} else {
try {
return createBattery(f.field.get(o), kind, side);
return getMjBattery(f.field.get(o), kind, side);
} catch (IllegalAccessException e) {
e.printStackTrace();
return null;
@ -155,19 +118,12 @@ public final class MjAPI {
}
}
/**
* @return All non-sided batteries for passed object
*/
public static IBatteryObject[] getAllMjBatteries(Object o) {
return getAllMjBatteries(o, ForgeDirection.UNKNOWN);
}
/**
* @param direction Side of block
* @return All sided batteries for passed object
*/
public static IBatteryObject[] getAllMjBatteries(Object o, ForgeDirection direction) {
IBatteryObject[] result = new IBatteryObject[mjBatteryFields.size()];
IBatteryObject[] result = new IBatteryObject[mjBatteries.size()];
int id = 0;
@ -181,143 +137,12 @@ public final class MjAPI {
return Arrays.copyOfRange(result, 0, id);
}
/**
* Register new battery kind implementation.
* Allowing to have a custom power types alongside default "kinesis" kind
* @param kind Kind name
* @param clazz Battery implementation class
*/
public static void registerMJBatteryKind(String kind, Class<? extends IBatteryObject> clazz) {
public static void registerMJBatteryKind(String kind, Class<? extends BatteryObject> clas) {
if (!mjBatteryKinds.containsKey(kind)) {
mjBatteryKinds.put(kind, clazz);
mjBatteryKinds.put(kind, clas);
} else {
BCLog.logger.log(Level.WARNING,
"energy kind \"" + kind + "\" already registered with " + clazz.getCanonicalName());
}
}
/**
* @see IOMode#canReceive
*/
public static boolean canReceive(IBatteryObject battery) {
return battery != null && (!(battery instanceof IBatteryIOObject) || ((IBatteryIOObject) battery).canReceive());
}
/**
* @see IOMode#canSend
*/
public static boolean canSend(IBatteryObject battery) {
return battery != null && battery instanceof IBatteryIOObject && ((IBatteryIOObject) battery).canSend();
}
/**
* @see IOMode#active
*/
public static boolean isActive(IBatteryObject battery) {
return battery != null && battery instanceof IBatteryIOObject && ((IBatteryIOObject) battery).isActive();
}
/**
* @see MjBattery#cacheable()
*/
public static boolean isCacheable(IBatteryObject battery) {
return battery != null && battery instanceof IBatteryIOObject && ((IBatteryIOObject) battery).isCacheable();
}
/**
* @see MjBattery#maxReceivedPerCycle()
* @see MjBattery#maxSendedPerCycle()
* @return Actual IO limit for passed mode (only send/receive supported)
*/
public static double getIOLimit(IBatteryObject batteryObject, IOMode mode) {
if (mode == IOMode.Receive && canReceive(batteryObject)) {
return batteryObject.maxReceivedPerCycle();
} else if (mode == IOMode.Send && canSend(batteryObject)) {
return ((IBatteryIOObject) batteryObject).maxSendedPerCycle();
}
return 0;
}
/**
* Obtain battery parameters reconfigurator.
* Usage:<br />
* <code>
* MjAPI.reconfigure().maxCapacity(battery, 15000);
* </code>
* @return Reconfigurator instance
*/
public static MjReconfigurator reconfigure() {
return reconfigurator;
}
/**
* Transfer mj energy amount from battery "fromBattery" to "toBattery"
* @param fromBattery Source battery
* @param toBattery Target battery
* @param mj Amount of energy
* @return Transferred amount
*/
public static double transferEnergy(IBatteryObject fromBattery, IBatteryObject toBattery, double mj) {
if (!canSend(fromBattery) || !canReceive(toBattery)) {
return 0;
}
IBatteryIOObject from = (IBatteryIOObject) fromBattery;
double attemptToTransfer = Math.min(getIOLimit(from, IOMode.Send), mj);
attemptToTransfer = Math.min(attemptToTransfer, getIOLimit(toBattery, IOMode.Receive));
double extracted = from.extractEnergy(attemptToTransfer);
double received = toBattery.addEnergy(extracted);
if (extracted > received) {
from.addEnergy(extracted - received);
}
return received;
}
/**
* Transfer maximal energy amount from battery "fromBattery" to "toBattery"
* @param fromBattery Source battery
* @param toBattery Target battery
* @return Transferred amount
*/
public static double transferEnergy(IBatteryObject fromBattery, IBatteryObject toBattery) {
return transferEnergy(fromBattery, toBattery, Math.min(
getIOLimit(fromBattery, IOMode.Send),
getIOLimit(toBattery, IOMode.Receive)));
}
/**
* Helper method which you should invoke in every game tick for supporting Active IO modes
* @param tile Tile which contains active battery
*/
public static void updateEntity(TileEntity tile) {
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
IBatteryObject batteryObject = getMjBattery(tile, direction);
TileEntity anotherTile = tile.getWorldObj().getTileEntity(tile.xCoord + direction.offsetX, tile.yCoord + direction.offsetY, tile.zCoord + direction.offsetZ);
IBatteryObject anotherBattery = getMjBattery(anotherTile, direction.getOpposite());
if (batteryObject == null || anotherBattery == null) {
continue;
}
if (canSend(batteryObject) && canReceive(anotherBattery) && isActive(batteryObject)) {
transferEnergy(batteryObject, anotherBattery);
}
if (canReceive(batteryObject) && canSend(anotherBattery) && isActive(anotherBattery) && !isActive(batteryObject)) {
transferEnergy(anotherBattery, batteryObject);
}
}
}
/**
* Reset all caches for passed tile
*/
public static void resetBatteriesCache(TileEntity tile) {
mjBatteryCache.remove(tile);
}
/**
* Remove cached instance of passed battery
*/
public static void resetBatteriesCache(IBatteryObject battery) {
for (BatteryCache cache : mjBatteryCache.values()) {
cache.reset(battery);
"energy kind \"" + kind + "\" already registered with " + clas.getCanonicalName());
}
}
@ -325,34 +150,10 @@ public final class MjAPI {
Value, Container
}
private static final class BatteryCache {
TIntObjectMap<IBatteryObject> cache = new TIntObjectHashMap<IBatteryObject>();
IBatteryObject get(String kind, ForgeDirection side) {
return cache.get(hash(kind, side));
}
void put(String kind, ForgeDirection side, IBatteryObject battery) {
cache.put(hash(kind, side), battery);
}
void reset(IBatteryObject battery) {
for (int key : cache.keys()) {
if (cache.get(key) == battery) {
cache.remove(key);
}
}
}
private int hash(String kind, ForgeDirection side) {
return kind.hashCode() * 31 + side.hashCode();
}
}
private static final class BatteryHolder {
private String kind;
private ForgeDirection side;
private Class<? extends Object> clazz;
private Class clazz;
@Override
public boolean equals(Object o) {
@ -383,13 +184,13 @@ public final class MjAPI {
public BatteryKind kind;
}
private static BatteryField getMjBatteryField(Class<?> c, String kind, ForgeDirection side) {
private static BatteryField getMjBatteryField(Class c, String kind, ForgeDirection side) {
BatteryHolder holder = new BatteryHolder();
holder.clazz = c;
holder.kind = kind;
holder.side = side;
BatteryField bField = mjBatteryFields.get(holder);
BatteryField bField = mjBatteries.get(holder);
if (bField == null) {
for (Field f : JavaTools.getAllFields(c)) {
@ -413,12 +214,12 @@ public final class MjAPI {
bField.kind = BatteryKind.Container;
}
mjBatteryFields.put(holder, bField);
mjBatteries.put(holder, bField);
return bField;
}
}
mjBatteryFields.put(holder, invalidBatteryField);
mjBatteries.put(holder, invalidBatteryField);
}
return bField == invalidBatteryField ? null : bField;
@ -434,6 +235,7 @@ public final class MjAPI {
}
static {
registerMJBatteryKind(DEFAULT_POWER_FRAMEWORK, BatteryObject.class);
mjBatteryKinds.put(MjAPI.DEFAULT_POWER_FRAMEWORK, BatteryObject.class);
}
}

View file

@ -27,7 +27,7 @@ import net.minecraftforge.common.util.ForgeDirection;
* "maxReceivedPerCycle" units of energy. As an optional behavior, the system
* can have a minimum amount of energy consumed even if the system is at max
* capacity, modelized by the "minimumConsumption" value.
*
*
* If the field designated by MjBattery is an object, then it will be considered
* as a nested battery, and will look for the field in the designated object.
*
@ -49,11 +49,6 @@ public @interface MjBattery {
*/
double maxReceivedPerCycle() default 10.0;
/**
* @return Max energy received per one tick
*/
double maxSendedPerCycle() default 10.0;
/**
* @return Minimal energy for keep machine is active
*/
@ -61,26 +56,18 @@ public @interface MjBattery {
/**
* @return The kind of battery stored. Specific power systems can be created
* through this system, as several battery of different kind can
* coexist in the same tile.
* through this system, as several battery of different kind can
* coexist in the same tile.
*/
String kind() default MjAPI.DEFAULT_POWER_FRAMEWORK;
/**
* @return Sides on which this battery should works.
*/
ForgeDirection[] sides() default {ForgeDirection.UNKNOWN};
ForgeDirection[] sides() default { ForgeDirection.UNKNOWN };
/**
* @return Current battery input/output mode
*/
IOMode mode() default IOMode.Receive;
/**
* @return Ability to cache this battery instance for performance reasons. Usual
* not required to modify it for every battery, you can dynamicaly reconfigure
* your batteries with {@link MjAPI#reconfigure()} and reset cache
* for tile with {@link MjAPI#resetBatteriesCache(IBatteryObject)}
*/
boolean cacheable() default true;
}

View file

@ -1,183 +0,0 @@
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.api.mj;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.core.BCLog;
/**
* Reconfiguration helper.
* Allow to change battery parameters in runtime.
*/
public class MjReconfigurator {
private static final class ConfigurableMjBattery implements MjBattery {
double maxCapacity, maxReceivedPerCycle, maxSendedPerCycle, minimumConsumption;
String kind;
ForgeDirection[] sides;
IOMode mode;
boolean cacheable;
@Override
public double maxCapacity() {
return maxCapacity;
}
@Override
public double maxReceivedPerCycle() {
return maxReceivedPerCycle;
}
@Override
public double minimumConsumption() {
return minimumConsumption;
}
@Override
public double maxSendedPerCycle() {
return maxSendedPerCycle;
}
@Override
public String kind() {
return kind;
}
@Override
public ForgeDirection[] sides() {
return sides;
}
@Override
public IOMode mode() {
return mode;
}
@Override
public boolean cacheable() {
return cacheable;
}
@Override
public Class<? extends Annotation> annotationType() {
return MjBattery.class;
}
}
/**
* Helper interface which should implement all configurable batteries.
*/
public interface IConfigurableBatteryObject extends IBatteryObject {
MjBattery getMjBattery();
void setMjBattery(MjBattery battery);
}
private ConfigurableMjBattery obtainConfigurableBattery(IBatteryObject battery) {
if (!(battery instanceof IConfigurableBatteryObject)) {
BCLog.logger.warning("Attempt to reconfigure unsupported battery: " + battery);
return null;
}
IConfigurableBatteryObject configurableBattery = (IConfigurableBatteryObject) battery;
MjBattery mjBattery = configurableBattery.getMjBattery();
if (mjBattery instanceof ConfigurableMjBattery) {
return (ConfigurableMjBattery) mjBattery;
}
ConfigurableMjBattery configurableMjBattery = new ConfigurableMjBattery();
configurableMjBattery.maxCapacity = mjBattery.maxCapacity();
configurableMjBattery.maxReceivedPerCycle = mjBattery.maxReceivedPerCycle();
configurableMjBattery.maxSendedPerCycle = mjBattery.maxSendedPerCycle();
configurableMjBattery.minimumConsumption = mjBattery.minimumConsumption();
configurableMjBattery.kind = mjBattery.kind();
configurableMjBattery.sides = mjBattery.sides();
configurableMjBattery.mode = mjBattery.mode();
configurableMjBattery.cacheable = mjBattery.cacheable();
configurableBattery.setMjBattery(configurableMjBattery);
return configurableMjBattery;
}
public void maxCapacity(IBatteryObject batteryObject, double maxCapacity) {
ConfigurableMjBattery battery = obtainConfigurableBattery(batteryObject);
if (battery != null) {
battery.maxCapacity = maxCapacity;
}
}
public void maxReceivedPerCycle(IBatteryObject batteryObject, double maxReceivedPerCycle) {
ConfigurableMjBattery battery = obtainConfigurableBattery(batteryObject);
if (battery != null) {
battery.maxReceivedPerCycle = maxReceivedPerCycle;
}
}
public void maxSendedPerCycle(IBatteryObject batteryObject, double maxSendedPerCycle) {
ConfigurableMjBattery battery = obtainConfigurableBattery(batteryObject);
if (battery != null) {
battery.maxSendedPerCycle = maxSendedPerCycle;
}
}
public void minimumConsumption(IBatteryObject batteryObject, double minimumConsumption) {
ConfigurableMjBattery battery = obtainConfigurableBattery(batteryObject);
if (battery != null) {
battery.minimumConsumption = minimumConsumption;
}
}
public void kind(IBatteryObject batteryObject, String kind) {
ConfigurableMjBattery battery = obtainConfigurableBattery(batteryObject);
if (battery != null) {
battery.kind = kind;
MjAPI.resetBatteriesCache(batteryObject);
}
}
/**
* Reconfigure passed battery instance for working with passed sides only
* @param sides Enabled sides
*/
public void sides(IBatteryObject batteryObject, ForgeDirection... sides) {
ConfigurableMjBattery battery = obtainConfigurableBattery(batteryObject);
if (battery != null) {
battery.sides = sides;
MjAPI.resetBatteriesCache(batteryObject);
}
}
/**
* Reconfigure passed battery instance for working with all sides exclude passed
* @param sides Disabled sides
*/
public void sidesExclude(IBatteryObject batteryObject, ForgeDirection... sides) {
List<ForgeDirection> newSides = new ArrayList<ForgeDirection>(Arrays.asList(ForgeDirection.VALID_DIRECTIONS));
for (ForgeDirection side : sides) {
newSides.remove(side);
}
sides(batteryObject, newSides.toArray(new ForgeDirection[newSides.size()]));
}
public void mode(IBatteryObject batteryObject, IOMode mode) {
ConfigurableMjBattery battery = obtainConfigurableBattery(batteryObject);
if (battery != null) {
battery.mode = mode;
}
}
public void cacheable(IBatteryObject batteryObject, boolean cacheable) {
ConfigurableMjBattery battery = obtainConfigurableBattery(batteryObject);
if (battery != null) {
battery.cacheable = cacheable;
}
}
}

View file

@ -1,11 +0,0 @@
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
@API(apiVersion = "1.1", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|mj")
package buildcraft.api.mj;
import cpw.mods.fml.common.API;

View file

@ -16,7 +16,6 @@ import buildcraft.api.core.SafeTimeTracker;
import buildcraft.api.mj.BatteryObject;
import buildcraft.api.mj.IBatteryObject;
import buildcraft.api.mj.IBatteryProvider;
import buildcraft.api.mj.IOMode;
import buildcraft.api.mj.MjAPI;
import buildcraft.api.mj.MjBattery;
@ -84,7 +83,11 @@ public final class PowerHandler implements IBatteryProvider {
* @param powerLoss power loss per tick
*/
public PerditionCalculator(double powerLoss) {
this.powerLoss = powerLoss;
if (powerLoss < MIN_POWERLOSS) {
this.powerLoss = MIN_POWERLOSS;
} else {
this.powerLoss = powerLoss;
}
}
/**
@ -148,18 +151,12 @@ public final class PowerHandler implements IBatteryProvider {
this.receiver = new PowerReceiver();
this.perdition = DEFAULT_PERDITION;
boolean created = false;
if (battery instanceof IBatteryObject) {
this.battery = (BatteryObject) battery;
} else if (battery != null) {
this.battery = MjAPI.createBattery(battery, MjAPI.DEFAULT_POWER_FRAMEWORK, ForgeDirection.UNKNOWN);
created = true;
this.battery = MjAPI.getMjBattery(battery);
} else {
this.battery = MjAPI.createBattery(new AnonymousBattery(), MjAPI.DEFAULT_POWER_FRAMEWORK, ForgeDirection.UNKNOWN);
created = true;
}
if (receptor instanceof IPowerEmitter && created) {
MjAPI.reconfigure().mode(this.battery, IOMode.Send);
this.battery = MjAPI.getMjBattery(new AnonymousBattery());
}
}
@ -224,9 +221,7 @@ public final class PowerHandler implements IBatteryProvider {
}
this.activationEnergy = activationEnergy;
MjAPI.reconfigure().maxCapacity(battery, maxStoredEnergy);
MjAPI.reconfigure().maxReceivedPerCycle(battery, localMaxEnergyReceived);
MjAPI.reconfigure().minimumConsumption(battery, minEnergyReceived);
battery.reconfigure(maxStoredEnergy, localMaxEnergyReceived, minEnergyReceived);
}
/**
@ -290,13 +285,16 @@ public final class PowerHandler implements IBatteryProvider {
private void applyPerdition() {
double energyStored = getEnergyStored();
if (perditionTracker.markTimeIfDelay(receptor.getWorld()) && energyStored > 0) {
double prev = energyStored;
double newEnergy = getPerdition().applyPerdition(this, energyStored, perditionTracker.durationOfLastDelay());
if (newEnergy != energyStored) {
if (newEnergy == 0 || newEnergy < energyStored) {
battery.setEnergyStored(energyStored = newEnergy);
} else {
battery.setEnergyStored(energyStored = DEFAULT_PERDITION.applyPerdition(this, energyStored, perditionTracker.durationOfLastDelay()));
}
validateEnergy();
averageLostPower = (averageLostPower * ROLLING_AVERAGE_NUMERATOR + (getEnergyStored() - energyStored)) * ROLLING_AVERAGE_DENOMINATOR;
averageLostPower = (averageLostPower * ROLLING_AVERAGE_NUMERATOR + (prev - energyStored)) * ROLLING_AVERAGE_DENOMINATOR;
}
}
@ -471,10 +469,6 @@ public final class PowerHandler implements IBatteryProvider {
return used;
}
public IBatteryObject getMjBattery() {
return battery;
}
}
/**

View file

@ -8,12 +8,12 @@
*/
package buildcraft.api.recipes;
public final class BuildcraftRecipeRegistry {
public final class BuildcraftRecipes {
public static IAssemblyRecipeManager assemblyTable;
public static IIntegrationRecipeManager integrationTable;
public static IRefineryRecipeManager refinery;
private BuildcraftRecipeRegistry() {
private BuildcraftRecipes() {
}
}

View file

@ -1,25 +0,0 @@
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.api.recipes;
import java.util.ArrayList;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
public class CraftingResult<T> {
public T crafted = null;
public ArrayList<ItemStack> usedItems = new ArrayList<ItemStack>();
public ArrayList<FluidStack> usedFluids = new ArrayList<FluidStack>();
public double energyCost = 0;
public long craftingTime = 0;
public IFlexibleRecipe<?> recipe;
}

View file

@ -8,15 +8,24 @@
*/
package buildcraft.api.recipes;
import java.util.Collection;
import java.util.List;
import net.minecraft.item.ItemStack;
public interface IAssemblyRecipeManager {
public interface IAssemblyRecipe {
ItemStack getOutput();
Object[] getInputs();
double getEnergyCost();
}
/**
* Add an Assembly Table recipe.
*
*
* @param input
* Object... containing either an ItemStack, or a paired string
* and integer(ex: "dyeBlue", 1)
@ -25,9 +34,7 @@ public interface IAssemblyRecipeManager {
* @param output
* resulting ItemStack
*/
void addRecipe(String id, double energyCost, ItemStack output, Object... input);
void addRecipe(double energyCost, ItemStack output, Object... input);
void addRecipe(IFlexibleRecipe<ItemStack> recipe);
Collection<IFlexibleRecipe<ItemStack>> getRecipes();
List<? extends IAssemblyRecipe> getRecipes();
}

View file

@ -1,29 +0,0 @@
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.api.recipes;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
public interface IFlexibleCrafter {
int getCraftingItemStackSize();
ItemStack getCraftingItemStack(int slotid);
ItemStack decrCraftingItemgStack(int slotid, int val);
FluidStack getCraftingFluidStack(int tankid);
FluidStack decrCraftingFluidStack(int tankid, int val);
int getCraftingFluidStackSize();
}

View file

@ -1,18 +0,0 @@
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.api.recipes;
public interface IFlexibleRecipe<T> {
boolean canBeCrafted(IFlexibleCrafter crafter);
CraftingResult<T> craft(IFlexibleCrafter crafter, boolean preview);
String getId();
}

View file

@ -1,19 +0,0 @@
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.api.recipes;
import net.minecraft.item.ItemStack;
public interface IIntegrationRecipe extends IFlexibleRecipe<ItemStack> {
boolean isValidInputA(ItemStack inputA);
boolean isValidInputB(ItemStack inputB);
}

View file

@ -10,14 +10,35 @@ package buildcraft.api.recipes;
import java.util.List;
import net.minecraft.item.ItemStack;
/**
* The Integration Table's primary purpose is to modify an input item's NBT
* data. As such its not a "traditional" type of recipe. Rather than predefined
* inputs and outputs, it takes an input and transforms it.
*/
public interface IIntegrationRecipeManager {
public interface IIntegrationRecipe {
double getEnergyCost();
boolean isValidInputA(ItemStack inputA);
boolean isValidInputB(ItemStack inputB);
ItemStack getOutputForInputs(ItemStack inputA, ItemStack inputB, ItemStack[] components);
ItemStack[] getComponents();
ItemStack[] getExampleInputsA();
ItemStack[] getExampleInputsB();
}
/**
* Add an Integration Table recipe.
*
*/
void addRecipe(IIntegrationRecipe recipe);

View file

@ -8,18 +8,30 @@
*/
package buildcraft.api.recipes;
import java.util.Collection;
import java.util.SortedSet;
import net.minecraftforge.fluids.FluidStack;
public interface IRefineryRecipeManager {
void addRecipe(String id, FluidStack ingredient, FluidStack result, int energy, int delay);
void addRecipe(FluidStack ingredient, FluidStack result, int energy, int delay);
void addRecipe(String id, FluidStack ingredient1, FluidStack ingredient2, FluidStack result, int energy, int delay);
void addRecipe(FluidStack ingredient1, FluidStack ingredient2, FluidStack result, int energy, int delay);
Collection<IFlexibleRecipe<FluidStack>> getRecipes();
SortedSet<? extends IRefineryRecipe> getRecipes();
IFlexibleRecipe<FluidStack> getRecipe(String currentRecipeId);
IRefineryRecipe findRefineryRecipe(FluidStack ingredient1, FluidStack ingredient2);
public interface IRefineryRecipe {
FluidStack getIngredient1();
FluidStack getIngredient2();
FluidStack getResult();
int getEnergyCost();
int getTimeRequired();
}
}

View file

@ -1,26 +0,0 @@
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.api.transport;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
public interface IPipe {
int x();
int y();
int z();
IPipeTile getTile();
TileEntity getAdjacentTile(ForgeDirection dir);
}

View file

@ -1,32 +0,0 @@
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.api.transport;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
public interface IPipePluggable {
void writeToNBT(NBTTagCompound nbt);
void readFromNBT(NBTTagCompound nbt);
ItemStack[] getDropItems(IPipeTile pipe);
void onAttachedPipe(IPipeTile pipe, ForgeDirection direction);
void onDetachedPipe(IPipeTile pipe, ForgeDirection direction);
boolean blocking(IPipeTile pipe, ForgeDirection direction);
void invalidate();
void validate(IPipeTile pipe, ForgeDirection direction);
}

View file

@ -1,5 +1,7 @@
package mekanism.common;
import buildcraft.api.mj.IBatteryObject;
import buildcraft.api.mj.MjAPI;
import ic2.api.energy.EnergyNet;
import ic2.api.energy.tile.IEnergySink;
@ -22,10 +24,6 @@ import mekanism.common.util.MekanismUtils;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.power.IPowerEmitter;
import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerHandler.PowerReceiver;
import buildcraft.api.power.PowerHandler.Type;
import cofh.api.energy.IEnergyHandler;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.Event;
@ -145,10 +143,10 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
boolean tryAgain = false;
do {
tryAgain = false;
double prev = sent;
sent += doEmit(energyToSend-sent);
sent += doEmit(energyToSend-sent, tryAgain);
tryAgain = false;
if(energyToSend-sent > 0 && sent-prev > 0)
{
@ -170,7 +168,7 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
/**
* @return sent
*/
public synchronized double doEmit(double energyToSend)
public synchronized double doEmit(double energyToSend, boolean retrying)
{
double sent = 0;
@ -220,13 +218,13 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
sent += used;
if(used > 0) continue;
}
if(MekanismUtils.useBuildCraft() && acceptor instanceof IPowerReceptor)
if(MekanismUtils.useBuildCraft() && !retrying)
{
PowerReceiver receiver = ((IPowerReceptor)acceptor).getPowerReceiver(side.getOpposite());
IBatteryObject battery = MjAPI.getMjBattery(acceptor, MjAPI.DEFAULT_POWER_FRAMEWORK, side.getOpposite());
if(receiver != null)
if(battery != null)
{
double toSend = receiver.receiveEnergy(Type.PIPE, (float)(Math.min(receiver.powerRequest(), currentSending*Mekanism.TO_BC)), side.getOpposite());
double toSend = battery.addEnergy(Math.min(battery.getEnergyRequested(), currentSending*Mekanism.TO_BC));
sent += toSend*Mekanism.FROM_BC;
if(toSend > 0) continue;
}
@ -276,7 +274,7 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
if(handler.canConnectEnergy(side.getOpposite()))
{
if(handler.getMaxEnergyStored(side.getOpposite()) - handler.getEnergyStored(side.getOpposite()) > 0 || handler.receiveEnergy(side.getOpposite(), 1, true) > 0)
if(handler.receiveEnergy(side.getOpposite(), 1, true) > 0)
{
toReturn.add(acceptor);
continue;
@ -299,22 +297,14 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
}
}
}
if(MekanismUtils.useBuildCraft() && acceptor instanceof IPowerReceptor)
if(MekanismUtils.useBuildCraft() && MjAPI.getMjBattery(acceptor, MjAPI.DEFAULT_POWER_FRAMEWORK, side.getOpposite()) != null)
{
IPowerReceptor handler = (IPowerReceptor)acceptor;
IBatteryObject battery = MjAPI.getMjBattery(acceptor, MjAPI.DEFAULT_POWER_FRAMEWORK, side.getOpposite());
if(handler.getPowerReceiver(side.getOpposite()) != null)
if(battery.getEnergyRequested() > 0)
{
if((handler.getPowerReceiver(side.getOpposite()).powerRequest()*Mekanism.FROM_BC) > 0)
{
if(handler instanceof IPowerEmitter && ((IPowerEmitter)handler).canEmitPowerFrom(side.getOpposite()))
{
continue;
}
toReturn.add(acceptor);
continue;
}
toReturn.add(acceptor);
continue;
}
}
}

View file

@ -209,7 +209,7 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
@Method(modid = "BuildCraftAPI|power")
protected void reconfigure()
{
powerHandler.configure(1, (float)((getMaxEnergy()-getEnergy())*Mekanism.TO_BC), 0, (float)(getMaxEnergy()*Mekanism.TO_BC));
powerHandler.configure(0, (float)((getMaxEnergy()-getEnergy())*Mekanism.TO_BC), 0, (float)(getMaxEnergy()*Mekanism.TO_BC));
}
@Override

View file

@ -1,5 +1,7 @@
package mekanism.common.util;
import buildcraft.api.mj.IBatteryObject;
import buildcraft.api.mj.MjAPI;
import ic2.api.energy.EnergyNet;
import ic2.api.energy.tile.IEnergyAcceptor;
import ic2.api.energy.tile.IEnergySink;
@ -20,9 +22,6 @@ import mekanism.common.tile.TileEntityElectricBlock;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.power.IPowerEmitter;
import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerHandler.PowerReceiver;
import buildcraft.api.power.PowerHandler.Type;
import cofh.api.energy.IEnergyHandler;
public final class CableUtils
@ -61,7 +60,7 @@ public final class CableUtils
{
return (tileEntity instanceof IStrictEnergyAcceptor ||
(MekanismUtils.useIC2() && tileEntity instanceof IEnergySink) ||
(MekanismUtils.useBuildCraft() && tileEntity instanceof IPowerReceptor && !(tileEntity instanceof IGridTransmitter)) ||
(MekanismUtils.useBuildCraft() && MjAPI.getMjBattery(tileEntity) != null && !(tileEntity instanceof IGridTransmitter)) ||
(MekanismUtils.useRF() && tileEntity instanceof IEnergyHandler));
}
@ -208,9 +207,9 @@ public final class CableUtils
return true;
}
}
else if(MekanismUtils.useBuildCraft() && tileEntity instanceof IPowerReceptor)
else if(MekanismUtils.useBuildCraft())
{
if(((IPowerReceptor)tileEntity).getPowerReceiver(side.getOpposite()) != null)
if(MjAPI.getMjBattery(tileEntity, MjAPI.DEFAULT_POWER_FRAMEWORK, side.getOpposite()) != null)
{
return true;
}
@ -325,14 +324,14 @@ public final class CableUtils
sent += (toSend - rejects);
}
}
else if(MekanismUtils.useBuildCraft() && tileEntity instanceof IPowerReceptor)
else if(MekanismUtils.useBuildCraft())
{
PowerReceiver receiver = ((IPowerReceptor)tileEntity).getPowerReceiver(side.getOpposite());
IBatteryObject battery = MjAPI.getMjBattery(tileEntity, MjAPI.DEFAULT_POWER_FRAMEWORK, side.getOpposite());
if(receiver != null)
if(battery != null)
{
double transferEnergy = Math.min(sendingEnergy, receiver.powerRequest()*Mekanism.FROM_BC);
double used = receiver.receiveEnergy(Type.STORAGE, (float)(transferEnergy*Mekanism.TO_BC), side.getOpposite());
double transferEnergy = Math.min(sendingEnergy, battery.getEnergyRequested()*Mekanism.FROM_BC);
double used = battery.addEnergy(transferEnergy*Mekanism.TO_BC);
sent += used*Mekanism.FROM_BC;
}
}