Merge pull request #2007 from asiekierka/6.1.x

Initial RF energy port
This commit is contained in:
SpaceToad 2014-09-04 20:10:57 +02:00
commit ccaeffe763
114 changed files with 1931 additions and 2366 deletions

View file

@ -184,8 +184,8 @@ public abstract class Schematic {
* Returns the amount of energy required to build this slot, depends on the
* stacks selected for the build.
*/
public double getEnergyRequirement(LinkedList<ItemStack> stacksUsed) {
double result = 0;
public int getEnergyRequirement(LinkedList<ItemStack> stacksUsed) {
int result = 0;
if (stacksUsed != null) {
for (ItemStack s : stacksUsed) {

View file

@ -76,7 +76,7 @@ public class SchematicFluid extends SchematicBlock {
}
@Override
public double getEnergyRequirement(LinkedList<ItemStack> stacksUsed) {
public int getEnergyRequirement(LinkedList<ItemStack> stacksUsed) {
return 1 * SchematicRegistry.BUILD_ENERGY;
}
}

View file

@ -28,8 +28,8 @@ import buildcraft.api.core.JavaTools;
public final class SchematicRegistry {
public static double BREAK_ENERGY = 10;
public static final double BUILD_ENERGY = 20;
public static int BREAK_ENERGY = 100;
public static final int BUILD_ENERGY = 200;
private static final HashSet<Block> explicitSchematicBlocks = new HashSet<Block>();

View file

@ -1,200 +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.reflect.Field;
import org.apache.logging.log4j.Level;
import buildcraft.api.core.BCLog;
import buildcraft.api.core.JavaTools;
/**
* A battery object is a wrapper around a battery field in an object. This
* 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 {
protected Field energyStored;
protected Object obj;
protected MjBattery batteryData;
/**
* {@inheritDoc}
*/
@Override
public double getEnergyRequested() {
if (!batteryData.mode().canReceive) {
return 0;
}
try {
return JavaTools.bounds(batteryData.maxCapacity() - energyStored.getDouble(obj),
batteryData.minimumConsumption(), batteryData.maxReceivedPerCycle());
} catch (IllegalAccessException e) {
BCLog.logger.log(Level.WARN, "can't get energy requested", e);
}
return 0;
}
/**
* {@inheritDoc}
*/
@Override
public double addEnergy(double mj) {
return addEnergy(mj, false);
}
/**
* {@inheritDoc}
*/
@Override
public double addEnergy(double mj, boolean ignoreCycleLimit) {
try {
double contained = energyStored.getDouble(obj);
double maxAccepted = batteryData.maxCapacity() - contained + batteryData.minimumConsumption();
if (!ignoreCycleLimit && maxAccepted > batteryData.maxReceivedPerCycle()) {
maxAccepted = batteryData.maxReceivedPerCycle();
}
double used = Math.min(maxAccepted, mj);
if (used > 0) {
energyStored.setDouble(obj, Math.min(contained + used, batteryData.maxCapacity()));
return used;
}
} catch (IllegalAccessException e) {
BCLog.logger.log(Level.WARN, "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.WARN, "can't extract energy", e);
}
return 0;
}
/**
* {@inheritDoc}
*/
@Override
public double getEnergyStored() {
try {
return energyStored.getDouble(obj);
} catch (IllegalAccessException e) {
BCLog.logger.log(Level.WARN, "can't get return energy stored", e);
return 0;
}
}
/**
* {@inheritDoc}
*/
@Override
public void setEnergyStored(double mj) {
try {
energyStored.setDouble(obj, mj);
} catch (IllegalAccessException e) {
BCLog.logger.log(Level.WARN, "can't set energy stored", e);
throw new RuntimeException(e);
}
}
/**
* {@inheritDoc}
*/
@Override
public double maxCapacity() {
return batteryData.maxCapacity();
}
/**
* {@inheritDoc}
*/
@Override
public double minimumConsumption() {
return batteryData.minimumConsumption();
}
/**
* {@inheritDoc}
*/
@Override
public double maxReceivedPerCycle() {
return batteryData.maxReceivedPerCycle();
}
@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();
}
@Override
public boolean canSend() {
return batteryData.mode().canSend;
}
@Override
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

@ -1,27 +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;
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

@ -1,77 +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.reflect.Field;
public interface IBatteryObject {
/**
* @return Current energy requirement for keeping machine state
*/
double getEnergyRequested();
/**
* Add energy to this battery
*
* @param mj Energy amount
* @return Used energy
*/
double addEnergy(double mj);
/**
* Add energy to this battery
*
* @param mj Energy amount
* @param ignoreCycleLimit Force add all energy even if "maxReceivedPerCycle" limit is reached
* @return Used energy
*/
double addEnergy(double mj, boolean ignoreCycleLimit);
/**
* @return Current stored energy amount in this battery
*/
double getEnergyStored();
/**
* Set current stored energy amount.
* Doesn't use it for your machines! Decrease your battery field directly.
*
* @param mj New energy amount
*/
void setEnergyStored(double mj);
/**
* @return Maximal energy amount for this battery.
*/
double maxCapacity();
/**
* @return Minimal energy amount for keep your machine in active state
*/
double minimumConsumption();
/**
* @return Maximal energy received per one tick
*/
double maxReceivedPerCycle();
/**
* @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

@ -1,13 +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;
public interface IBatteryProvider {
IBatteryObject getMjBattery(String kind);
}

View file

@ -1,30 +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;
public enum IOMode {
Both(true, true, false),
BothActive(true, true, true),
Receive(true, false, false),
ReceiveActive(true, false, true),
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) {
this.canReceive = canReceive;
this.canSend = canSend;
this.active = active;
}
}

View file

@ -1,15 +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 net.minecraftforge.common.util.ForgeDirection;
public interface ISidedBatteryProvider {
IBatteryObject getMjBattery(String kind, ForgeDirection direction);
}

View file

@ -1,440 +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.reflect.Field;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.WeakHashMap;
import org.apache.logging.log4j.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.
* BuildCraft implements a default power model on top of this, the "kinesis"
* power model. Third party mods may provide they own version of Minecraft
* 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 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
*/
private MjAPI() {
}
/**
* @see #getMjBattery(Object, String, ForgeDirection)
*/
public static IBatteryObject getMjBattery(Object o) {
return getMjBattery(o, null, null);
}
/**
* @see #getMjBattery(Object, String, ForgeDirection)
*/
public static IBatteryObject getMjBattery(Object o, String kind) {
return getMjBattery(o, kind, null);
}
/**
* @see #getMjBattery(Object, String, ForgeDirection)
*/
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) {
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;
}
}
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;
}
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);
return obj;
} catch (InstantiationException e) {
BCLog.logger.log(Level.WARN, "can't instantiate class for energy kind \"" + kind + "\"");
return null;
} catch (IllegalAccessException e) {
BCLog.logger.log(Level.WARN, "can't instantiate class for energy kind \"" + kind + "\"");
return null;
}
} else {
try {
return createBattery(f.field.get(o), kind, side);
} catch (IllegalAccessException e) {
e.printStackTrace();
return null;
}
}
}
/**
* @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()];
int id = 0;
for (String kind : mjBatteryKinds.keySet()) {
result[id] = getMjBattery(o, kind, direction);
if (result[id] != null) {
id++;
}
}
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) {
if (!mjBatteryKinds.containsKey(kind)) {
mjBatteryKinds.put(kind, clazz);
} else {
BCLog.logger.log(Level.WARN,
"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);
}
}
private enum BatteryKind {
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;
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
BatteryHolder that = (BatteryHolder) o;
return kind.equals(that.kind) && clazz.equals(that.clazz) && side.equals(that.side);
}
@Override
public int hashCode() {
int result = kind.hashCode();
result = 31 * result + clazz.hashCode();
result = 31 * result + side.hashCode();
return result;
}
}
private static class BatteryField {
public Field field;
public MjBattery battery;
public BatteryKind kind;
}
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);
if (bField == null) {
for (Field f : JavaTools.getAllFields(c)) {
MjBattery battery = f.getAnnotation(MjBattery.class);
if (battery != null && kind.equals(battery.kind())) {
if (!contains(battery.sides(), side) && !contains(battery.sides(), ForgeDirection.UNKNOWN)) {
continue;
}
f.setAccessible(true);
bField = new BatteryField();
bField.field = f;
bField.battery = battery;
if (double.class.equals(f.getType())) {
bField.kind = BatteryKind.Value;
} else if (f.getType().isPrimitive()) {
throw new RuntimeException(
"MJ battery needs to be object or double type");
} else {
bField.kind = BatteryKind.Container;
}
mjBatteryFields.put(holder, bField);
return bField;
}
}
mjBatteryFields.put(holder, invalidBatteryField);
}
return bField == invalidBatteryField ? null : bField;
}
private static <T> boolean contains(T[] array, T value) {
for (T t : array) {
if (t == value) {
return true;
}
}
return false;
}
static {
registerMJBatteryKind(DEFAULT_POWER_FRAMEWORK, BatteryObject.class);
}
}

View file

@ -1,60 +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 net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerHandler;
public class MjAPILegacy implements IPowerReceptor {
private final PowerHandler powerHandler;
private final World world;
protected MjAPILegacy(World world, IBatteryObject battery, PowerHandler.Type type) {
if (battery == null) {
throw new NullPointerException();
}
this.world = world;
this.powerHandler = new PowerHandler(this, type, battery);
}
public static MjAPILegacy from(World world, IBatteryObject battery, PowerHandler.Type type) {
if (battery == null) {
return null;
}
return new MjAPILegacy(world, battery, type);
}
public static MjAPILegacy from(World world, Object object, PowerHandler.Type type) {
return from(world, MjAPI.getMjBattery(object), type);
}
public static MjAPILegacy from(TileEntity tileEntity, PowerHandler.Type type) {
return from(tileEntity.getWorldObj(), MjAPI.getMjBattery(tileEntity), type);
}
@Override
public PowerHandler.PowerReceiver getPowerReceiver(ForgeDirection side) {
return powerHandler.getPowerReceiver();
}
@Override
public void doWork(PowerHandler workProvider) {
}
@Override
public World getWorld() {
return world;
}
}

View file

@ -1,86 +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.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import net.minecraftforge.common.util.ForgeDirection;
/**
* This annotation is used for tiles that need to interface with BuildCraft
* energy framework, a.k.a MinecraftJoule or MJ. In order to receive power,
* tiles, need to declare a double field, with the annotation MjBattery. MJ
* provider machines able to provide power will then connect to these tiles, and
* feed energy up to max capacity. It's the responsibility of the implementer to
* manually decrease the value of the energy, as he simulates energy
* consumption. On each cycle, per power input, machines can receive up to
* "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.
*
* All the properties defined in this annotation are class wide. If you need to
* change them on a tile by tile basis, you will need to use interfaces, either
* {@link IBatteryProvider} or {@link ISidedBatteryProvider}
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@Inherited
public @interface MjBattery {
/**
* @return Max energy capacity of battery
*/
double maxCapacity() default 100.0;
/**
* @return Max energy received per one tick
*/
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
*/
double minimumConsumption() default 0.1;
/**
* @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.
*/
String kind() default MjAPI.DEFAULT_POWER_FRAMEWORK;
/**
* @return Sides on which this battery should works.
*/
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.warn("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

@ -23,7 +23,7 @@ public interface ILaserTarget {
*
* @param energy
*/
void receiveLaserEnergy(double energy);
void receiveLaserEnergy(int energy);
/**
* Return true if the Tile Entity object is no longer a valid target. For

View file

@ -17,5 +17,6 @@ import net.minecraftforge.common.util.ForgeDirection;
* from a specific side.
*/
public interface IPowerEmitter {
boolean canEmitPowerFrom(ForgeDirection side);
public boolean canEmitPowerFrom(ForgeDirection side);
}

View file

@ -9,7 +9,6 @@
package buildcraft.api.power;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
/**
@ -28,8 +27,9 @@ public interface IPowerReceptor {
* engines to eventually explode.
*
* @param side
* @return
*/
PowerHandler.PowerReceiver getPowerReceiver(ForgeDirection side);
public PowerHandler.PowerReceiver getPowerReceiver(ForgeDirection side);
/**
* Call back from the PowerHandler that is called when the stored power
@ -39,7 +39,7 @@ public interface IPowerReceptor {
*
* @param workProvider
*/
void doWork(PowerHandler workProvider);
public void doWork(PowerHandler workProvider);
World getWorld();
public World getWorld();
}

View file

@ -8,35 +8,27 @@
*/
package buildcraft.api.power;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
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;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
/**
* The PowerHandler is similar to FluidTank in that it holds your power and
* allows standardized interaction between machines.
* <p/>
*
* To receive power to your machine you needs create an instance of PowerHandler
* and implement IPowerReceptor on the TileEntity.
* <p/>
*
* 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.
* <p/>
*
* See TileRefinery for a simple example of a power using machine.
*
* @see IPowerReceptor
* @see IPowerEmitter
*/
public final class PowerHandler implements IBatteryProvider {
public final class PowerHandler {
public static enum Type {
@ -65,7 +57,7 @@ public final class PowerHandler implements IBatteryProvider {
/**
* Extend this class to create custom Perdition algorithms (its not final).
* <p/>
*
* NOTE: It is not possible to create a Zero perdition algorithm.
*/
public static class PerditionCalculator {
@ -84,6 +76,9 @@ public final class PowerHandler implements IBatteryProvider {
* @param powerLoss power loss per tick
*/
public PerditionCalculator(double powerLoss) {
if (powerLoss < MIN_POWERLOSS) {
powerLoss = MIN_POWERLOSS;
}
this.powerLoss = powerLoss;
}
@ -93,22 +88,21 @@ public final class PowerHandler implements IBatteryProvider {
* every tick. It is triggered by any manipulation of the stored energy.
*
* @param powerHandler the PowerHandler requesting the perdition update
* @param current the current stored energy
* @param ticksPassed ticks since the last time this function was called
* @param current the current stored energy
* @param ticksPassed ticks since the last time this function was called
* @return
*/
public double applyPerdition(PowerHandler powerHandler, double current, long ticksPassed) {
double newPower = current - powerLoss * ticksPassed;
if (newPower < 0) {
newPower = 0;
current -= powerLoss * ticksPassed;
if (current < 0) {
current = 0;
}
return newPower;
return current;
}
/**
* Taxes a flat rate on all incoming power.
* <p/>
*
* Defaults to 0% tax rate.
*
* @return percent of input to tax
@ -117,50 +111,33 @@ public final class PowerHandler implements IBatteryProvider {
return 0;
}
}
public static final PerditionCalculator DEFAULT_PERDITION = new PerditionCalculator();
public static final double ROLLING_AVERAGE_WEIGHT = 100.0;
public static final double ROLLING_AVERAGE_NUMERATOR = ROLLING_AVERAGE_WEIGHT - 1;
public static final double ROLLING_AVERAGE_DENOMINATOR = 1.0 / ROLLING_AVERAGE_WEIGHT;
public static final double ROLLING_AVERAGE_DENOMINATOR = 1.0 / ROLLING_AVERAGE_WEIGHT;
private double minEnergyReceived;
private double maxEnergyReceived;
private double maxEnergyStored;
private double activationEnergy;
private double energyStored = 0;
private final SafeTimeTracker doWorkTracker = new SafeTimeTracker();
private final SafeTimeTracker sourcesTracker = new SafeTimeTracker();
private final SafeTimeTracker perditionTracker = new SafeTimeTracker();
public final int[] powerSources = new int[6];
public final IPowerReceptor receptor;
private double activationEnergy;
private final SafeTimeTracker doWorkTracker = new SafeTimeTracker(1);
private final SafeTimeTracker sourcesTracker = new SafeTimeTracker(1);
private final SafeTimeTracker perditionTracker = new SafeTimeTracker(1);
private PerditionCalculator perdition;
private final PowerReceiver receiver;
private final Type type;
private IBatteryObject battery;
// Tracking
private double averageLostPower = 0;
private double averageReceivedPower = 0;
private double averageUsedPower = 0;
public PowerHandler(IPowerReceptor receptor, Type type) {
this(receptor, type, null);
}
public PowerHandler(IPowerReceptor receptor, Type type, Object battery) {
this.receptor = receptor;
this.type = type;
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;
} 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);
}
}
public PowerReceiver getPowerReceiver() {
@ -168,15 +145,15 @@ public final class PowerHandler implements IBatteryProvider {
}
public double getMinEnergyReceived() {
return battery.minimumConsumption();
return minEnergyReceived;
}
public double getMaxEnergyReceived() {
return battery.getEnergyRequested();
return maxEnergyReceived;
}
public double getMaxEnergyStored() {
return battery.maxCapacity();
return maxEnergyStored;
}
public double getActivationEnergy() {
@ -184,54 +161,40 @@ public final class PowerHandler implements IBatteryProvider {
}
public double getEnergyStored() {
return battery.getEnergyStored();
}
@Override
public IBatteryObject getMjBattery(String kind) {
return battery.kind().equals(kind) ? battery : null;
return energyStored;
}
/**
* Setup your PowerHandler's settings.
*
* @param minEnergyReceived
* This is the minimum about of power that will be accepted by
* the PowerHandler. This should generally be greater than the
* activationEnergy if you plan to use the doWork() callback.
* Anything greater than 1 will prevent Redstone Engines from
* powering this Provider.
* @param maxEnergyReceived
* The maximum amount of power accepted by the PowerHandler. This
* should generally be less than 500. Too low and larger engines
* will overheat while trying to power the machine. Too high, and
* the engines will never warm up. Greater values also place
* greater strain on the power net.
* @param activationEnergy
* If the stored energy is greater than this value, the doWork()
* callback is called (once per tick).
* @param maxStoredEnergy
* The maximum amount of power this PowerHandler can store.
* Values tend to range between 100 and 5000. With 1000 and 1500
* being common.
* @param minEnergyReceived This is the minimum about of power that will be
* accepted by the PowerHandler. This should generally be greater than the
* activationEnergy if you plan to use the doWork() callback. Anything
* greater than 1 will prevent Redstone Engines from powering this Provider.
* @param maxEnergyReceived The maximum amount of power accepted by the
* PowerHandler. This should generally be less than 500. Too low and larger
* engines will overheat while trying to power the machine. Too high, and
* the engines will never warm up. Greater values also place greater strain
* on the power net.
* @param activationEnergy If the stored energy is greater than this value,
* the doWork() callback is called (once per tick).
* @param maxStoredEnergy The maximum amount of power this PowerHandler can
* store. Values tend to range between 100 and 5000. With 1000 and 1500
* being common.
*/
public void configure(double minEnergyReceived, double maxEnergyReceived, double activationEnergy,
double maxStoredEnergy) {
double localMaxEnergyReceived = maxEnergyReceived;
if (minEnergyReceived > localMaxEnergyReceived) {
localMaxEnergyReceived = minEnergyReceived;
public void configure(double minEnergyReceived, double maxEnergyReceived, double activationEnergy, double maxStoredEnergy) {
if (minEnergyReceived > maxEnergyReceived) {
maxEnergyReceived = minEnergyReceived;
}
this.minEnergyReceived = minEnergyReceived;
this.maxEnergyReceived = maxEnergyReceived;
this.maxEnergyStored = maxStoredEnergy;
this.activationEnergy = activationEnergy;
MjAPI.reconfigure().maxCapacity(battery, maxStoredEnergy);
MjAPI.reconfigure().maxReceivedPerCycle(battery, localMaxEnergyReceived);
MjAPI.reconfigure().minimumConsumption(battery, minEnergyReceived);
}
/**
* Allows you define perdition in terms of loss/ticks.
* <p/>
*
* This function is mostly for legacy implementations. See
* PerditionCalculator for more complex perdition formulas.
*
@ -250,32 +213,28 @@ public final class PowerHandler implements IBatteryProvider {
/**
* Allows you to define a new PerditionCalculator class to handler perdition
* calculations.
* <p/>
*
* For example if you want exponentially increasing loss based on amount
* stored.
*
* @param perdition
*/
public void setPerdition(PerditionCalculator perdition) {
if (perdition == null) {
this.perdition = DEFAULT_PERDITION;
} else {
this.perdition = perdition;
}
if (perdition == null)
perdition = DEFAULT_PERDITION;
this.perdition = perdition;
}
public PerditionCalculator getPerdition() {
if (perdition == null) {
if (perdition == null)
return DEFAULT_PERDITION;
} else {
return perdition;
}
return perdition;
}
/**
* Ticks the power handler. You should call this if you can, but its not
* required.
* <p/>
*
* If you don't call it, the possibility exists for some weirdness with the
* perdition algorithm and work callback as its possible they will not be
* called on every tick they otherwise would be. You should be able to
@ -288,28 +247,29 @@ public final class PowerHandler implements IBatteryProvider {
}
private void applyPerdition() {
double energyStored = getEnergyStored();
if (perditionTracker.markTimeIfDelay(receptor.getWorld()) && energyStored > 0) {
if (perditionTracker.markTimeIfDelay(receptor.getWorld(), 1) && energyStored > 0) {
double prev = energyStored;
double newEnergy = getPerdition().applyPerdition(this, energyStored, perditionTracker.durationOfLastDelay());
if (newEnergy != energyStored) {
battery.setEnergyStored(energyStored = newEnergy);
}
if (newEnergy == 0 || newEnergy < energyStored)
energyStored = newEnergy;
else
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;
}
}
private void applyWork() {
if (getEnergyStored() >= activationEnergy) {
if (doWorkTracker.markTimeIfDelay(receptor.getWorld())) {
if (energyStored >= activationEnergy) {
if (doWorkTracker.markTimeIfDelay(receptor.getWorld(), 1)) {
receptor.doWork(this);
}
}
}
private void updateSources(ForgeDirection source) {
if (sourcesTracker.markTimeIfDelay(receptor.getWorld())) {
if (sourcesTracker.markTimeIfDelay(receptor.getWorld(), 1)) {
for (int i = 0; i < 6; ++i) {
powerSources[i] -= sourcesTracker.durationOfLastDelay();
if (powerSources[i] < 0) {
@ -318,9 +278,8 @@ public final class PowerHandler implements IBatteryProvider {
}
}
if (source != null) {
if (source != null)
powerSources[source.ordinal()] = 10;
}
}
/**
@ -337,7 +296,6 @@ public final class PowerHandler implements IBatteryProvider {
double result = 0;
double energyStored = getEnergyStored();
if (energyStored >= min) {
if (energyStored <= max) {
result = energyStored;
@ -351,15 +309,11 @@ public final class PowerHandler implements IBatteryProvider {
}
}
}
if (energyStored != getEnergyStored()) {
battery.setEnergyStored(energyStored);
}
validateEnergy();
if (doUse) {
if (doUse)
averageUsedPower = (averageUsedPower * ROLLING_AVERAGE_NUMERATOR + result) * ROLLING_AVERAGE_DENOMINATOR;
}
return result;
}
@ -370,7 +324,7 @@ public final class PowerHandler implements IBatteryProvider {
public void readFromNBT(NBTTagCompound data, String tag) {
NBTTagCompound nbt = data.getCompoundTag(tag);
battery.setEnergyStored(nbt.getDouble("energyStored"));
energyStored = nbt.getDouble("energyStored");
}
public void writeToNBT(NBTTagCompound data) {
@ -379,7 +333,7 @@ public final class PowerHandler implements IBatteryProvider {
public void writeToNBT(NBTTagCompound data, String tag) {
NBTTagCompound nbt = new NBTTagCompound();
nbt.setDouble("energyStored", battery.getEnergyStored());
nbt.setDouble("energyStored", energyStored);
data.setTag(tag, nbt);
}
@ -389,15 +343,15 @@ public final class PowerHandler implements IBatteryProvider {
}
public double getMinEnergyReceived() {
return PowerHandler.this.getMinEnergyReceived();
return minEnergyReceived;
}
public double getMaxEnergyReceived() {
return PowerHandler.this.getMaxEnergyReceived();
return maxEnergyReceived;
}
public double getMaxEnergyStored() {
return PowerHandler.this.getMaxEnergyStored();
return maxEnergyStored;
}
public double getActivationEnergy() {
@ -405,7 +359,7 @@ public final class PowerHandler implements IBatteryProvider {
}
public double getEnergyStored() {
return PowerHandler.this.getEnergyStored();
return energyStored;
}
public double getAveragePowerReceived() {
@ -430,15 +384,17 @@ public final class PowerHandler implements IBatteryProvider {
/**
* The amount of power that this PowerHandler currently needs.
*
* @return
*/
public double powerRequest() {
update();
return battery.getEnergyRequested();
return Math.min(maxEnergyReceived, maxEnergyStored - energyStored);
}
/**
* Add power to the PowerReceiver from an external source.
* <p/>
*
* IPowerEmitters are responsible for calling this themselves.
*
* @param quantity
@ -448,10 +404,10 @@ public final class PowerHandler implements IBatteryProvider {
public double receiveEnergy(Type source, final double quantity, ForgeDirection from) {
double used = quantity;
if (source == Type.ENGINE) {
if (used < getMinEnergyReceived()) {
if (used < minEnergyReceived) {
return 0;
} else if (used > getMaxEnergyReceived()) {
used = getMaxEnergyReceived();
} else if (used > maxEnergyReceived) {
used = maxEnergyReceived;
}
}
@ -464,30 +420,37 @@ public final class PowerHandler implements IBatteryProvider {
applyWork();
if (source == Type.ENGINE && type.eatsEngineExcess()) {
used = Math.min(quantity, getMaxEnergyReceived());
used = Math.min(quantity, maxEnergyReceived);
}
averageReceivedPower = (averageReceivedPower * ROLLING_AVERAGE_NUMERATOR + used) * ROLLING_AVERAGE_DENOMINATOR;
return used;
}
public IBatteryObject getMjBattery() {
return battery;
}
}
/**
*
* @return the amount the power changed by
*/
public double addEnergy(double quantity) {
final double used = battery.addEnergy(quantity);
energyStored += quantity;
if (energyStored > maxEnergyStored) {
quantity -= energyStored - maxEnergyStored;
energyStored = maxEnergyStored;
} else if (energyStored < 0) {
quantity -= energyStored;
energyStored = 0;
}
applyPerdition();
return used;
return quantity;
}
public void setEnergy(double quantity) {
battery.setEnergyStored(quantity);
this.energyStored = quantity;
validateEnergy();
}
@ -496,21 +459,11 @@ public final class PowerHandler implements IBatteryProvider {
}
private void validateEnergy() {
double energyStored = getEnergyStored();
double maxEnergyStored = getMaxEnergyStored();
if (energyStored < 0) {
energyStored = 0;
}
if (energyStored > maxEnergyStored) {
energyStored = maxEnergyStored;
}
if (energyStored != battery.getEnergyStored()) {
battery.setEnergyStored(energyStored);
}
}
private static class AnonymousBattery {
@MjBattery
public double mjStored;
}
}

View file

@ -1,11 +1,3 @@
/**
* 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|power")
@API(apiVersion="1.1",owner="BuildCraftAPI|core",provides="BuildCraftAPI|power")
package buildcraft.api.power;
import cpw.mods.fml.common.API;

View file

@ -19,7 +19,7 @@ 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 int energyCost = 0;
public long craftingTime = 0;
public IFlexibleRecipe<T> recipe;
}

View file

@ -21,11 +21,11 @@ public interface IAssemblyRecipeManager {
* Object... containing either an ItemStack, or a paired string
* and integer(ex: "dyeBlue", 1)
* @param energyCost
* MJ cost to produce
* RF cost to produce
* @param output
* resulting ItemStack
*/
void addRecipe(String id, double energyCost, ItemStack output, Object... input);
void addRecipe(String id, int energyCost, ItemStack output, Object... input);
void addRecipe(IFlexibleRecipe<ItemStack> recipe);

View file

@ -60,8 +60,8 @@ public class AIRobot {
return true;
}
public double getEnergyCost() {
return 0.1;
public int getEnergyCost() {
return 1;
}
public boolean canLoadFromNBT() {
@ -113,7 +113,7 @@ public class AIRobot {
if (delegateAI != null) {
delegateAI.cycle();
} else {
robot.setEnergy(robot.getEnergy() - getEnergyCost());
robot.getBattery().extractEnergy(getEnergyCost(), false);
update();
}
} catch (Throwable e) {

View file

@ -8,21 +8,20 @@
*/
package buildcraft.api.robots;
import cofh.api.energy.IEnergyStorage;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.fluids.IFluidHandler;
import buildcraft.api.boards.RedstoneBoardRobot;
import buildcraft.api.core.IZone;
public abstract class EntityRobotBase extends EntityLiving implements IInventory, IFluidHandler {
public static final double MAX_ENERGY = 10000;
public static final double SAFETY_ENERGY = MAX_ENERGY / 4;
public static final int MAX_ENERGY = 100000;
public static final int SAFETY_ENERGY = MAX_ENERGY / 4;
public static final long NULL_ROBOT_ID = Long.MAX_VALUE;
public EntityRobotBase(World par1World) {
@ -41,9 +40,9 @@ public abstract class EntityRobotBase extends EntityLiving implements IInventory
public abstract void aimItemAt(int x, int y, int z);
public abstract double getEnergy();
public abstract int getEnergy();
public abstract void setEnergy(double energy);
public abstract IEnergyStorage getBattery();
public abstract IDockingStation getDockingStation();

View file

@ -0,0 +1,11 @@
package cofh.api;
public class CoFHAPIProps {
private CoFHAPIProps() {
}
public static final String VERSION = "1.7.10R1.0.0";
}

View file

@ -0,0 +1,158 @@
package cofh.api.energy;
import net.minecraft.nbt.NBTTagCompound;
/**
* Reference implementation of {@link IEnergyStorage}. Use/extend this or implement your own.
*
* @author King Lemming
*
*/
public class EnergyStorage implements IEnergyStorage {
protected int energy;
protected int capacity;
protected int maxReceive;
protected int maxExtract;
public EnergyStorage(int capacity) {
this(capacity, capacity, capacity);
}
public EnergyStorage(int capacity, int maxTransfer) {
this(capacity, maxTransfer, maxTransfer);
}
public EnergyStorage(int capacity, int maxReceive, int maxExtract) {
this.capacity = capacity;
this.maxReceive = maxReceive;
this.maxExtract = maxExtract;
}
public EnergyStorage readFromNBT(NBTTagCompound nbt) {
this.energy = nbt.getInteger("Energy");
if (energy > capacity) {
energy = capacity;
}
return this;
}
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
if (energy < 0) {
energy = 0;
}
nbt.setInteger("Energy", energy);
return nbt;
}
public void setCapacity(int capacity) {
this.capacity = capacity;
if (energy > capacity) {
energy = capacity;
}
}
public void setMaxTransfer(int maxTransfer) {
setMaxReceive(maxTransfer);
setMaxExtract(maxTransfer);
}
public void setMaxReceive(int maxReceive) {
this.maxReceive = maxReceive;
}
public void setMaxExtract(int maxExtract) {
this.maxExtract = maxExtract;
}
public int getMaxReceive() {
return maxReceive;
}
public int getMaxExtract() {
return maxExtract;
}
/**
* 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
*/
public void setEnergyStored(int energy) {
this.energy = energy;
if (this.energy > capacity) {
this.energy = capacity;
} else if (this.energy < 0) {
this.energy = 0;
}
}
/**
* This function is included to allow the containing tile to directly and efficiently modify the energy contained in the EnergyStorage. Do not rely on this
* externally, as not all IEnergyHandlers are guaranteed to have it.
*
* @param energy
*/
public void modifyEnergyStored(int energy) {
this.energy += energy;
if (this.energy > capacity) {
this.energy = capacity;
} else if (this.energy < 0) {
this.energy = 0;
}
}
/* IEnergyStorage */
@Override
public int receiveEnergy(int maxReceive, boolean simulate) {
int energyReceived = Math.min(capacity - energy, Math.min(this.maxReceive, maxReceive));
if (!simulate) {
energy += energyReceived;
}
return energyReceived;
}
@Override
public int extractEnergy(int maxExtract, boolean simulate) {
int energyExtracted = Math.min(energy, Math.min(this.maxExtract, maxExtract));
if (!simulate) {
energy -= energyExtracted;
}
return energyExtracted;
}
@Override
public int getEnergyStored() {
return energy;
}
@Override
public int getMaxEnergyStored() {
return capacity;
}
}

View file

@ -0,0 +1,21 @@
package cofh.api.energy;
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.
*
* Note that {@link IEnergyHandler} is an extension of this.
*
* @author King Lemming
*
*/
public interface IEnergyConnection {
/**
* Returns TRUE if the TileEntity can connect on a given side.
*/
boolean canConnectEnergy(ForgeDirection from);
}

View file

@ -0,0 +1,52 @@
package cofh.api.energy;
import net.minecraft.item.ItemStack;
/**
* Implement this interface on Item classes that support external manipulation of their internal energy storages.
*
* A reference implementation is provided {@link ItemEnergyContainer}.
*
* @author King Lemming
*
*/
public interface IEnergyContainerItem {
/**
* Adds energy to a container item. Returns the quantity of energy that was accepted. This should always return 0 if the item cannot be externally charged.
*
* @param container
* ItemStack to be charged.
* @param maxReceive
* Maximum amount of energy to be sent into the item.
* @param simulate
* If TRUE, the charge will only be simulated.
* @return Amount of energy that was (or would have been, if simulated) received by the item.
*/
int receiveEnergy(ItemStack container, int maxReceive, boolean simulate);
/**
* Removes energy from a container item. Returns the quantity of energy that was removed. This should always return 0 if the item cannot be externally
* discharged.
*
* @param container
* ItemStack to be discharged.
* @param maxExtract
* Maximum amount of energy to be extracted from the item.
* @param simulate
* If TRUE, the discharge will only be simulated.
* @return Amount of energy that was (or would have been, if simulated) extracted from the item.
*/
int extractEnergy(ItemStack container, int maxExtract, boolean simulate);
/**
* Get the amount of energy currently stored in the container item.
*/
int getEnergyStored(ItemStack container);
/**
* Get the max amount of energy that can be stored in the container item.
*/
int getMaxEnergyStored(ItemStack container);
}

View file

@ -0,0 +1,51 @@
package cofh.api.energy;
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.
*
* A reference implementation is provided {@link TileEnergyHandler}.
*
* @author King Lemming
*
*/
public interface IEnergyHandler extends IEnergyConnection {
/**
* Add energy to an IEnergyHandler, internal distribution is left entirely to the IEnergyHandler.
*
* @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);
/**
* Remove energy from an IEnergyHandler, internal distribution is left entirely to the IEnergyHandler.
*
* @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,45 @@
package cofh.api.energy;
/**
* An energy storage is the unit of interaction with Energy inventories.
*
* A reference implementation can be found at {@link EnergyStorage}.
*
* @author King Lemming
*
*/
public interface IEnergyStorage {
/**
* Adds energy to the storage. Returns quantity of energy that was accepted.
*
* @param maxReceive
* Maximum amount of energy to be inserted.
* @param simulate
* If TRUE, the insertion will only be simulated.
* @return Amount of energy that was (or would have been, if simulated) accepted by the storage.
*/
int receiveEnergy(int maxReceive, boolean simulate);
/**
* Removes energy from the storage. Returns quantity of energy that was removed.
*
* @param maxExtract
* Maximum amount of energy to be extracted.
* @param simulate
* If TRUE, the extraction will only be simulated.
* @return Amount of energy that was (or would have been, if simulated) extracted from the storage.
*/
int extractEnergy(int maxExtract, boolean simulate);
/**
* Returns the amount of energy currently stored.
*/
int getEnergyStored();
/**
* Returns the maximum amount of energy that can be stored.
*/
int getMaxEnergyStored();
}

View file

@ -0,0 +1,110 @@
package cofh.api.energy;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
/**
* Reference implementation of {@link IEnergyContainerItem}. Use/extend this or implement your own.
*
* @author King Lemming
*
*/
public class ItemEnergyContainer extends Item implements IEnergyContainerItem {
protected int capacity;
protected int maxReceive;
protected int maxExtract;
public ItemEnergyContainer() {
}
public ItemEnergyContainer(int capacity) {
this(capacity, capacity, capacity);
}
public ItemEnergyContainer(int capacity, int maxTransfer) {
this(capacity, maxTransfer, maxTransfer);
}
public ItemEnergyContainer(int capacity, int maxReceive, int maxExtract) {
this.capacity = capacity;
this.maxReceive = maxReceive;
this.maxExtract = maxExtract;
}
public ItemEnergyContainer setCapacity(int capacity) {
this.capacity = capacity;
return this;
}
public void setMaxTransfer(int maxTransfer) {
setMaxReceive(maxTransfer);
setMaxExtract(maxTransfer);
}
public void setMaxReceive(int maxReceive) {
this.maxReceive = maxReceive;
}
public void setMaxExtract(int maxExtract) {
this.maxExtract = maxExtract;
}
/* IEnergyContainerItem */
@Override
public int receiveEnergy(ItemStack container, int maxReceive, boolean simulate) {
if (container.stackTagCompound == null) {
container.stackTagCompound = new NBTTagCompound();
}
int energy = container.stackTagCompound.getInteger("Energy");
int energyReceived = Math.min(capacity - energy, Math.min(this.maxReceive, maxReceive));
if (!simulate) {
energy += energyReceived;
container.stackTagCompound.setInteger("Energy", energy);
}
return energyReceived;
}
@Override
public int extractEnergy(ItemStack container, int maxExtract, boolean simulate) {
if (container.stackTagCompound == null || !container.stackTagCompound.hasKey("Energy")) {
return 0;
}
int energy = container.stackTagCompound.getInteger("Energy");
int energyExtracted = Math.min(energy, Math.min(this.maxExtract, maxExtract));
if (!simulate) {
energy -= energyExtracted;
container.stackTagCompound.setInteger("Energy", energy);
}
return energyExtracted;
}
@Override
public int getEnergyStored(ItemStack container) {
if (container.stackTagCompound == null || !container.stackTagCompound.hasKey("Energy")) {
return 0;
}
return container.stackTagCompound.getInteger("Energy");
}
@Override
public int getMaxEnergyStored(ItemStack container) {
return capacity;
}
}

View file

@ -0,0 +1,62 @@
package cofh.api.energy;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
/**
* Reference implementation of {@link IEnergyHandler}. Use/extend this or implement your own.
*
* @author King Lemming
*
*/
public class TileEnergyHandler extends TileEntity implements IEnergyHandler {
protected EnergyStorage storage = new EnergyStorage(32000);
@Override
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
storage.readFromNBT(nbt);
}
@Override
public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt);
storage.writeToNBT(nbt);
}
/* IEnergyHandler */
@Override
public boolean canConnectEnergy(ForgeDirection from) {
return true;
}
@Override
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate) {
return storage.receiveEnergy(maxReceive, simulate);
}
@Override
public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate) {
return storage.extractEnergy(maxExtract, simulate);
}
@Override
public int getEnergyStored(ForgeDirection from) {
return storage.getEnergyStored();
}
@Override
public int getMaxEnergyStored(ForgeDirection from) {
return storage.getMaxEnergyStored();
}
}

View file

@ -0,0 +1,10 @@
/**
* (C) 2014 Team CoFH / CoFH / Cult of the Full Hub
* http://www.teamcofh.com
*/
@API(apiVersion = CoFHAPIProps.VERSION, owner = "CoFHAPI", provides = "CoFHAPI|energy")
package cofh.api.energy;
import cofh.api.CoFHAPIProps;
import cpw.mods.fml.common.API;

View file

@ -0,0 +1,9 @@
/**
* (C) 2014 Team CoFH / CoFH / Cult of the Full Hub
* http://www.teamcofh.com
*/
@API(apiVersion = CoFHAPIProps.VERSION, owner = "CoFHLib", provides = "CoFHAPI")
package cofh.api;
import cpw.mods.fml.common.API;

View file

@ -18,10 +18,7 @@ buildcraft.boardRobotCrafter=Crafter
buildcraft.boardRobotDelivery=Delivery
buildcraft.boardRobotPump=Pump
chat.pipe.power.iron.mode=Switched to %d MJ/t limit
chat.pipe.power.energyConverter=Energy conversion: %s
chat.pipe.power.energyConverter.from_old_to_new=From old API to new API
chat.pipe.power.energyConverter.from_new_to_old=From new API to old API
chat.pipe.power.iron.mode=Switched to %d RF/t limit
color.black=Black
color.blue=Blue
@ -207,6 +204,7 @@ item.PipePowerQuartz.name=Quartz Kinesis Pipe
item.PipePowerIron.name=Iron Kinesis Pipe
item.PipePowerGold.name=Golden Kinesis Pipe
item.PipePowerDiamond.name=Diamond Kinesis Pipe
item.PipePowerEmerald.name=Emerald Kinesis Pipe
item.PipeItemsStripes.name=Stripes Transport Pipe
item.PipeStructureCobblestone.name=Cobblestone Structure Pipe
item.PipeItemsVoid.name=Void Transport Pipe
@ -298,6 +296,7 @@ tip.PipeItemsVoid=Destroys items
tip.PipeItemsWood=Extraction pipe
tip.PipeItemsEmzuli=Gate controlled extraction pipe
tip.PipePowerWood=Power Input Pipe
tip.PipePowerEmerald=Power Input Pipe
tip.PipePowerIron=Selectable Limiter Pipe
tip.PipeStructureCobblestone=Support pipe

Binary file not shown.

After

Width:  |  Height:  |  Size: 205 B

View file

@ -61,7 +61,6 @@ import buildcraft.core.science.TechnoSimpleItem;
import buildcraft.core.science.TechnoStatement;
import buildcraft.core.science.Tier;
import buildcraft.energy.BlockBuildcraftFluid;
import buildcraft.energy.BlockEnergyConverter;
import buildcraft.energy.BlockEnergyEmitter;
import buildcraft.energy.BlockEnergyReceiver;
import buildcraft.energy.BlockEngine;
@ -69,10 +68,8 @@ import buildcraft.energy.BucketHandler;
import buildcraft.energy.EnergyProxy;
import buildcraft.energy.GuiHandler;
import buildcraft.energy.ItemBucketBuildcraft;
import buildcraft.energy.ItemEnergyConverter;
import buildcraft.energy.ItemEngine;
import buildcraft.energy.SchematicEngine;
import buildcraft.energy.TileEnergyConverter;
import buildcraft.energy.TileEnergyEmitter;
import buildcraft.energy.TileEnergyReceiver;
import buildcraft.energy.TileEngine;
@ -189,13 +186,6 @@ public class BuildCraftEnergy extends BuildCraftMod {
engineBlock = new BlockEngine();
CoreProxy.proxy.registerBlock(engineBlock, ItemEngine.class);
if (BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_GENERAL, "energyConverter", true,
"Set true for enable energy converter").getBoolean(true)) {
blockEnergyConverter = new BlockEnergyConverter();
CoreProxy.proxy.registerBlock(blockEnergyConverter, ItemEnergyConverter.class);
CoreProxy.proxy.registerTileEntity(TileEnergyConverter.class, "EnergyConverter");
}
// Oil and fuel
buildcraftFluidOil = new Fluid("oil").setDensity(800).setViscosity(1500);
FluidRegistry.registerFluid(buildcraftFluidOil);
@ -274,7 +264,7 @@ public class BuildCraftEnergy extends BuildCraftMod {
MinecraftForge.EVENT_BUS.register(BucketHandler.INSTANCE);
BuildcraftRecipeRegistry.refinery.addRecipe("buildcraft:fuel", new FluidStack(fluidOil, 1), new FluidStack(
fluidFuel, 1), 12, 1);
fluidFuel, 1), 120, 1);
// Iron Engine Fuels
// IronEngineFuel.addFuel("lava", 1, 20000);

View file

@ -79,7 +79,7 @@ public class BuildCraftFactory extends BuildCraftMod {
@Mod.Instance("BuildCraft|Factory")
public static BuildCraftFactory instance;
public static final int MINING_MJ_COST_PER_BLOCK = 64;
public static final int MINING_RF_COST_PER_BLOCK = 640;
public static BlockQuarry quarryBlock;
public static BlockMiningWell miningWellBlock;
public static BlockAutoWorkbench autoWorkbenchBlock;

View file

@ -492,47 +492,47 @@ public class BuildCraftSilicon extends BuildCraftMod {
'G', BuildCraftCore.diamondGearItem);
// PIPE WIRE
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:redWire", 500, PipeWire.RED.getStack(8),
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:redWire", 5000, PipeWire.RED.getStack(8),
OreDictionary.getOres("dyeRed"), Items.redstone, Items.iron_ingot);
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:blueWire", 500, PipeWire.BLUE.getStack(8),
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:blueWire", 5000, PipeWire.BLUE.getStack(8),
OreDictionary.getOres("dyeBlue"), Items.redstone, Items.iron_ingot);
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:greenWire", 500, PipeWire.GREEN.getStack(8),
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:greenWire", 5000, PipeWire.GREEN.getStack(8),
OreDictionary.getOres("dyeGreen"), Items.redstone, Items.iron_ingot);
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:yellowWire", 500, PipeWire.YELLOW.getStack(8),
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:yellowWire", 5000, PipeWire.YELLOW.getStack(8),
OreDictionary.getOres("dyeYellow"), Items.redstone, Items.iron_ingot);
// CHIPSETS
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:redstoneChipset", 10000, Chipset.RED.getStack(),
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:redstoneChipset", 100000, Chipset.RED.getStack(),
Items.redstone);
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:ironChipset", 20000, Chipset.IRON.getStack(),
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:ironChipset", 200000, Chipset.IRON.getStack(),
Items.redstone, Items.iron_ingot);
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:goldChipset", 40000, Chipset.GOLD.getStack(),
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:goldChipset", 400000, Chipset.GOLD.getStack(),
Items.redstone, Items.gold_ingot);
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:diamondChipset", 80000,
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:diamondChipset", 800000,
Chipset.DIAMOND.getStack(), Items.redstone, Items.diamond);
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:pulsatingChipset", 40000,
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:pulsatingChipset", 400000,
Chipset.PULSATING.getStack(2), Items.redstone, Items.ender_pearl);
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:quartzChipset", 60000, Chipset.QUARTZ.getStack(),
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:quartzChipset", 600000, Chipset.QUARTZ.getStack(),
Items.redstone, Items.quartz);
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:compChipset", 60000, Chipset.COMP.getStack(),
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:compChipset", 600000, Chipset.COMP.getStack(),
Items.redstone, Items.comparator);
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:emeraldChipset", 120000,
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:emeraldChipset", 1200000,
Chipset.EMERALD.getStack(), Items.redstone, Items.emerald);
// GATES
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:simpleGate", 10000,
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:simpleGate", 100000,
ItemGate.makeGateItem(GateMaterial.REDSTONE, GateLogic.AND), Chipset.RED.getStack(),
PipeWire.RED.getStack());
addGateRecipe("Iron", 20000, GateMaterial.IRON, Chipset.IRON, PipeWire.RED, PipeWire.BLUE);
addGateRecipe("Gold", 40000, GateMaterial.GOLD, Chipset.GOLD, PipeWire.RED, PipeWire.BLUE, PipeWire.GREEN);
addGateRecipe("Diamond", 80000, GateMaterial.DIAMOND, Chipset.DIAMOND, PipeWire.RED, PipeWire.BLUE,
addGateRecipe("Iron", 200000, GateMaterial.IRON, Chipset.IRON, PipeWire.RED, PipeWire.BLUE);
addGateRecipe("Gold", 400000, GateMaterial.GOLD, Chipset.GOLD, PipeWire.RED, PipeWire.BLUE, PipeWire.GREEN);
addGateRecipe("Diamond", 800000, GateMaterial.DIAMOND, Chipset.DIAMOND, PipeWire.RED, PipeWire.BLUE,
PipeWire.GREEN, PipeWire.YELLOW);
addGateRecipe("Emerald", 120000, GateMaterial.EMERALD, Chipset.DIAMOND, PipeWire.RED, PipeWire.BLUE,
addGateRecipe("Emerald", 1200000, GateMaterial.EMERALD, Chipset.DIAMOND, PipeWire.RED, PipeWire.BLUE,
PipeWire.GREEN, PipeWire.YELLOW);
// ROBOTS AND BOARDS
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:redstoneCrystal", 1000000, new ItemStack(
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:redstoneCrystal", 10000000, new ItemStack(
redstoneCrystal), new ItemStack(
Blocks.redstone_block));
@ -569,7 +569,7 @@ public class BuildCraftSilicon extends BuildCraftMod {
BuildcraftRecipeRegistry.integrationTable.addRecipe(new AdvancedFacadeRecipe("buildcraft:advancedFacade"));
}
private static void addGateRecipe(String materialName, double energyCost, GateMaterial material, Chipset chipset,
private static void addGateRecipe(String materialName, int energyCost, GateMaterial material, Chipset chipset,
PipeWire... pipeWire) {
List<ItemStack> temp = new ArrayList<ItemStack>();
temp.add(chipset.getStack());

View file

@ -17,7 +17,6 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLInterModComms;
@ -26,12 +25,10 @@ import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.oredict.RecipeSorter;
import buildcraft.api.blueprints.SchematicRegistry;
import buildcraft.api.core.EnumColor;
import buildcraft.api.core.IIconProvider;
@ -101,6 +98,7 @@ import buildcraft.transport.pipes.PipeItemsVoid;
import buildcraft.transport.pipes.PipeItemsWood;
import buildcraft.transport.pipes.PipePowerCobblestone;
import buildcraft.transport.pipes.PipePowerDiamond;
import buildcraft.transport.pipes.PipePowerEmerald;
import buildcraft.transport.pipes.PipePowerGold;
import buildcraft.transport.pipes.PipePowerIron;
import buildcraft.transport.pipes.PipePowerIron.PowerMode;
@ -176,6 +174,7 @@ public class BuildCraftTransport extends BuildCraftMod {
public static Item pipePowerIron;
public static Item pipePowerGold;
public static Item pipePowerDiamond;
public static Item pipePowerEmerald;
public static int groupItemsTrigger;
public static String[] facadeBlacklist;
@ -231,6 +230,7 @@ public class BuildCraftTransport extends BuildCraftMod {
public static TechnoSimpleItem technoPipePowerIron = new TechnoSimpleItem();
public static TechnoSimpleItem technoPipePowerGold = new TechnoSimpleItem();
public static TechnoSimpleItem technoPipePowerDiamond = new TechnoSimpleItem();
public static TechnoSimpleItem technoPipePowerEmerald = new TechnoSimpleItem();
public static TechnoStatement technoTriggerPipe = new TechnoStatement();
public static TechnoStatement technoTriggerPipeWireActive = new TechnoStatement();
@ -410,6 +410,7 @@ public class BuildCraftTransport extends BuildCraftMod {
pipePowerIron = buildPipe(PipePowerIron.class, "Iron Kinesis Pipe", CreativeTabBuildCraft.PIPES, Items.redstone, pipeItemsIron);
pipePowerGold = buildPipe(PipePowerGold.class, "Golden Kinesis Pipe", CreativeTabBuildCraft.PIPES, Items.redstone, pipeItemsGold);
pipePowerDiamond = buildPipe(PipePowerDiamond.class, "Diamond Kinesis Pipe", CreativeTabBuildCraft.PIPES, Items.redstone, pipeItemsDiamond);
pipePowerEmerald = buildPipe(PipePowerEmerald.class, "Emerald Kinesis Pipe", CreativeTabBuildCraft.PIPES, Items.redstone, pipeItemsEmerald);
pipeStructureCobblestone = buildPipe(PipeStructureCobblestone.class, "Cobblestone Structure Pipe", CreativeTabBuildCraft.PIPES, Blocks.gravel, pipeItemsCobblestone);
@ -717,6 +718,13 @@ public class BuildCraftTransport extends BuildCraftMod {
technoPipeItemsDiamond,
technoPipePowerWood);
technoPipePowerEmerald.initialize(
Tier.GoldenGear,
pipePowerEmerald,
new ItemStack(BuildCraftCore.goldGearItem, 5),
technoPipeItemsEmerald,
technoPipePowerWood);
// Statements
technoTriggerPipe.initialize(
@ -800,7 +808,7 @@ public class BuildCraftTransport extends BuildCraftMod {
GameRegistry.addRecipe(facadeItem.new FacadeRecipe());
RecipeSorter.register("facadeTurningHelper", ItemFacade.FacadeRecipe.class, RecipeSorter.Category.SHAPELESS, "");
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:pipePlug", 1000, new ItemStack(plugItem, 8),
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:pipePlug", 10000, new ItemStack(plugItem, 8),
new ItemStack(pipeStructureCobblestone));
CoreProxy.proxy.addCraftingRecipe(new ItemStack(robotStationItem), " ", " I ", "ICI",

View file

@ -13,14 +13,13 @@ import java.util.LinkedList;
import net.minecraft.inventory.IInventory;
import net.minecraft.nbt.NBTTagCompound;
import buildcraft.api.blueprints.ITileBuilder;
import buildcraft.api.blueprints.SchematicRegistry;
import buildcraft.api.core.NetworkData;
import buildcraft.api.core.SafeTimeTracker;
import buildcraft.api.mj.MjBattery;
import buildcraft.core.IBoxProvider;
import buildcraft.core.LaserData;
import buildcraft.core.RFBattery;
import buildcraft.core.TileBuildCraft;
import buildcraft.core.network.RPC;
import buildcraft.core.network.RPCHandler;
@ -35,7 +34,7 @@ public abstract class TileAbstractBuilder extends TileBuildCraft implements ITil
* plus a safeguard. That's a nice way to evaluate maximum amount of energy
* that need to be in a builder.
*/
private static final double FULL_CHEST_ENERGY = 9 * 3 * 64 * SchematicRegistry.BUILD_ENERGY + 1000;
private static final int FULL_CHEST_ENERGY = 9 * 3 * 64 * SchematicRegistry.BUILD_ENERGY + 10000;
@NetworkData
public LinkedList<LaserData> pathLasers = new LinkedList<LaserData> ();
@ -43,12 +42,14 @@ public abstract class TileAbstractBuilder extends TileBuildCraft implements ITil
public ArrayList<BuildingItem> buildersInAction = new ArrayList<BuildingItem>();
protected SafeTimeTracker buildTracker = new SafeTimeTracker(5);
@MjBattery(maxReceivedPerCycle = 100, maxCapacity = FULL_CHEST_ENERGY, minimumConsumption = 1)
protected double mjStored = 0;
private double mjPrev = 0;
private int mjUnchangedCycles = 0;
private int rfPrev = 0;
private int rfUnchangedCycles = 0;
public TileAbstractBuilder() {
super();
this.setBattery(new RFBattery(FULL_CHEST_ENERGY, 1000, 0));
}
@Override
public void initialize () {
super.initialize();
@ -69,9 +70,11 @@ public abstract class TileAbstractBuilder extends TileBuildCraft implements ITil
public void updateEntity() {
super.updateEntity();
if (mjPrev != mjStored) {
mjPrev = mjStored;
mjUnchangedCycles = 0;
RFBattery battery = this.getBattery();
if (rfPrev != battery.getEnergyStored()) {
rfPrev = battery.getEnergyStored();
rfUnchangedCycles = 0;
}
BuildingItem toRemove = null;
@ -88,25 +91,21 @@ public abstract class TileAbstractBuilder extends TileBuildCraft implements ITil
buildersInAction.remove(toRemove);
}
if (mjPrev != mjStored) {
mjPrev = mjStored;
mjUnchangedCycles = 0;
if (rfPrev != battery.getEnergyStored()) {
rfPrev = battery.getEnergyStored();
rfUnchangedCycles = 0;
}
mjUnchangedCycles++;
rfUnchangedCycles++;
/**
* After 100 cycles with no consumption or additional power, start to
* slowly to decrease the amount of power available in the builder.
*/
if (mjUnchangedCycles > 100) {
mjStored -= 100;
if (rfUnchangedCycles > 100) {
battery.useEnergy(0, 1000, false);
if (mjStored < 0) {
mjStored = 0;
}
mjPrev = mjStored;
rfPrev = battery.getEnergyStored();
}
}
@ -129,33 +128,29 @@ public abstract class TileAbstractBuilder extends TileBuildCraft implements ITil
RPCHandler.rpcBroadcastWorldPlayers(worldObj, this, "launchItem", item);
}
public final double energyAvailable() {
return mjStored;
public final int energyAvailable() {
return getBattery().getEnergyStored();
}
public final void consumeEnergy(double quantity) {
mjStored -= quantity;
public final boolean consumeEnergy(int quantity) {
return (getBattery().useEnergy(quantity, quantity, false) > 0);
}
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound);
nbttagcompound.setDouble("mjStored", mjStored);
}
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
mjStored = nbttagcompound.getDouble("mjStored");
mjPrev = mjStored;
mjUnchangedCycles = 0;
rfPrev = getBattery().getEnergyStored();
rfUnchangedCycles = 0;
}
@Override
public double getMaxRenderDistanceSquared() {
return Double.MAX_VALUE;
}
public double getMaxRenderDistanceSquared() {
return Double.MAX_VALUE;
}
}

View file

@ -65,7 +65,7 @@ import buildcraft.core.robots.RobotRegistry;
public class TileBuilder extends TileAbstractBuilder implements IMachine, IFluidHandler, IRequestProvider {
private static int POWER_ACTIVATION = 50;
private static int POWER_ACTIVATION = 500;
@NetworkData
public Box box = new Box();
@ -591,7 +591,7 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine, IFluid
if (getWorld().getWorldInfo().getGameType() == GameType.CREATIVE) {
build();
} else {
if (mjStored > POWER_ACTIVATION) {
if (getBattery().getEnergyStored() > POWER_ACTIVATION) {
build();
}
}
@ -599,7 +599,7 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine, IFluid
if (done) {
return;
} else if (mjStored < 25) {
} else if (getBattery().getEnergyStored() < 25) {
return;
}
}

View file

@ -42,7 +42,7 @@ import buildcraft.core.utils.Utils;
public class TileFiller extends TileAbstractBuilder implements IMachine, IActionReceptor {
private static int POWER_ACTIVATION = 50;
private static int POWER_ACTIVATION = 500;
public FillerPattern currentPattern = PatternFill.INSTANCE;
@ -112,7 +112,7 @@ public class TileFiller extends TileAbstractBuilder implements IMachine, IAction
return;
}
if (mjStored < POWER_ACTIVATION || !buildTracker.markTimeIfDelay(worldObj)) {
if (getBattery().getEnergyStored() < POWER_ACTIVATION || !buildTracker.markTimeIfDelay(worldObj)) {
return;
}

View file

@ -86,7 +86,7 @@ public final class InterModComms {
}
ItemStack is = ItemStack.loadItemStackFromNBT(recipe.getCompoundTag("output"));
if (is != null && !input.isEmpty()) {
AssemblyRecipeManager.INSTANCE.addRecipe(recipe.getString("id"), recipe.getDouble("energy"), is,
AssemblyRecipeManager.INSTANCE.addRecipe(recipe.getString("id"), recipe.getInteger("energy"), is,
(Object[]) input.toArray(new ItemStack[input.size()]));
} else {
failed = true;

View file

@ -0,0 +1,84 @@
package buildcraft.core;
import cofh.api.energy.IEnergyStorage;
import net.minecraft.nbt.NBTTagCompound;
public class RFBattery implements IEnergyStorage {
private int energy, maxEnergy, maxReceive, maxExtract;
public RFBattery(int maxEnergy, int maxReceive, int maxExtract) {
this.maxEnergy = maxEnergy;
this.maxReceive = maxReceive;
this.maxExtract = maxExtract;
}
public void readFromNBT(NBTTagCompound tag) {
if(!(tag.hasKey("battery"))) return;
NBTTagCompound battery = tag.getCompoundTag("battery");
this.energy = battery.getInteger("energy");
this.maxEnergy = battery.getInteger("maxEnergy");
this.maxReceive = battery.getInteger("maxReceive");
this.maxExtract = battery.getInteger("maxExtract");
}
public void writeToNBT(NBTTagCompound tag) {
NBTTagCompound battery = new NBTTagCompound();
battery.setInteger("energy", this.energy);
battery.setInteger("maxEnergy", this.maxEnergy);
battery.setInteger("maxReceive", this.maxReceive);
battery.setInteger("maxExtract", this.maxExtract);
}
public int addEnergy(int minReceive, int maxReceive, boolean simulate) {
int amountReceived = Math.min(maxReceive, maxEnergy - energy);
if (amountReceived < minReceive) return 0;
if (!simulate) energy += amountReceived;
return amountReceived;
}
public int useEnergy(int minExtract, int maxExtract, boolean simulate) {
int amountExtracted = Math.min(maxExtract, energy);
if (amountExtracted < minExtract) return 0;
if (!simulate) energy -= amountExtracted;
return amountExtracted;
}
@Override
public int receiveEnergy(int maxReceive, boolean simulate) {
return addEnergy(0, Math.min(maxReceive, this.maxReceive), simulate);
}
@Override
public int extractEnergy(int maxExtract, boolean simulate) {
return useEnergy(0, Math.min(maxExtract, this.maxExtract), simulate);
}
@Override
public int getEnergyStored() {
return energy;
}
@Override
public int getMaxEnergyStored() {
return maxEnergy;
}
public int getMaxEnergyReceive() {
return maxReceive;
}
public int getMaxEnergyExtract() {
return maxExtract;
}
public void setEnergy(int energy) {
this.energy = energy;
if (energy < 0) {
energy = 0;
} else if (energy > maxEnergy) {
energy = maxEnergy;
}
}
}

View file

@ -12,6 +12,7 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import cofh.api.energy.IEnergyHandler;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
@ -19,7 +20,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.Packet;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftCore;
import buildcraft.api.power.IPowerReceptor;
import buildcraft.core.network.BuildCraftPacket;
@ -30,8 +31,7 @@ import buildcraft.core.network.PacketUpdate;
import buildcraft.core.network.TilePacketWrapper;
import buildcraft.core.utils.Utils;
public abstract class TileBuildCraft extends TileEntity implements ISynchronizedTile {
public abstract class TileBuildCraft extends TileEntity implements ISynchronizedTile, IEnergyHandler {
@SuppressWarnings("rawtypes")
private static Map<Class, TilePacketWrapper> updateWrappers = new HashMap<Class, TilePacketWrapper>();
@SuppressWarnings("rawtypes")
@ -40,6 +40,7 @@ public abstract class TileBuildCraft extends TileEntity implements ISynchronized
private final TilePacketWrapper updatePacket;
private boolean init = false;
private String owner = "[BuildCraft]";
private RFBattery battery;
public TileBuildCraft() {
if (!updateWrappers.containsKey(this.getClass())) {
@ -52,7 +53,6 @@ public abstract class TileBuildCraft extends TileEntity implements ISynchronized
updatePacket = updateWrappers.get(this.getClass());
descriptionPacket = descriptionWrappers.get(this.getClass());
}
public String getOwner() {
@ -131,6 +131,9 @@ public abstract class TileBuildCraft extends TileEntity implements ISynchronized
public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt);
nbt.setString("owner", owner);
if (battery != null) {
battery.writeToNBT(nbt);
}
}
@Override
@ -139,6 +142,9 @@ public abstract class TileBuildCraft extends TileEntity implements ISynchronized
if (nbt.hasKey("owner")) {
owner = nbt.getString("owner");
}
if (battery != null) {
battery.readFromNBT(nbt);
}
}
public World getWorld() {
@ -154,4 +160,42 @@ public abstract class TileBuildCraft extends TileEntity implements ISynchronized
public boolean equals(Object cmp) {
return this == cmp;
}
public boolean canConnectEnergy(ForgeDirection from) {
return (battery != null);
}
public int receiveEnergy(ForgeDirection from, int maxReceive,
boolean simulate) {
if(battery != null && this.canConnectEnergy(from))
return battery.receiveEnergy(maxReceive, simulate);
else return 0;
}
public int extractEnergy(ForgeDirection from, int maxExtract,
boolean simulate) {
if(battery != null && this.canConnectEnergy(from))
return battery.extractEnergy(maxExtract, simulate);
else return 0;
}
public int getEnergyStored(ForgeDirection from) {
if(battery != null && this.canConnectEnergy(from))
return battery.getEnergyStored();
else return 0;
}
public int getMaxEnergyStored(ForgeDirection from) {
if(battery != null && this.canConnectEnergy(from))
return battery.getMaxEnergyStored();
else return 0;
}
public RFBattery getBattery() {
return battery;
}
protected void setBattery(RFBattery battery) {
this.battery = battery;
}
}

View file

@ -187,9 +187,7 @@ public class BptBuilderTemplate extends BptBuilderBase {
iterator.remove();
builtLocations.add(new BlockIndex(slot.x, slot.y, slot.z));
} else {
if (builder.energyAvailable() > SchematicRegistry.BUILD_ENERGY && firstSlotToConsume != null) {
builder.consumeEnergy(SchematicRegistry.BUILD_ENERGY);
if (builder.consumeEnergy(SchematicRegistry.BUILD_ENERGY) && firstSlotToConsume != null) {
slot.addStackConsumed(firstSlotToConsume.decreaseStackInSlot(1));
result = slot;
iterator.remove();

View file

@ -65,6 +65,6 @@ public abstract class BuildingSlot {
public abstract void readFromNBT(NBTTagCompound nbt, MappingRegistry registry) throws MappingNotFoundException;
public abstract double getEnergyRequirement();
public abstract int getEnergyRequirement();
}

View file

@ -172,7 +172,7 @@ public class BuildingSlotBlock extends BuildingSlot {
}
@Override
public double getEnergyRequirement() {
public int getEnergyRequirement() {
return schematic.getEnergyRequirement(stackConsumed);
}

View file

@ -82,7 +82,7 @@ public class BuildingSlotEntity extends BuildingSlot {
}
@Override
public double getEnergyRequirement() {
public int getEnergyRequirement() {
return schematic.getEnergyRequirement(stackConsumed);
}
}

View file

@ -1,83 +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.core.inventory;
import java.lang.reflect.Field;
import buildcraft.api.mj.IBatteryObject;
import buildcraft.api.mj.MjBattery;
/**
* Creates a deep copy of an existing IInventory.
*
* Useful for performing inventory manipulations and then examining the results
* without affecting the original inventory.
*/
public class BatteryCopy implements IBatteryObject {
private IBatteryObject orignal;
private double contents;
public BatteryCopy(IBatteryObject orignal) {
this.orignal = orignal;
contents = orignal.getEnergyStored();
}
@Override
public double getEnergyRequested() {
return 0;
}
@Override
public double addEnergy(double mj) {
return 0;
}
@Override
public double addEnergy(double mj, boolean ignoreCycleLimit) {
return 0;
}
@Override
public double getEnergyStored() {
return contents;
}
@Override
public void setEnergyStored(double mj) {
contents = mj;
}
@Override
public double maxCapacity() {
return orignal.maxCapacity();
}
@Override
public double minimumConsumption() {
return orignal.minimumConsumption();
}
@Override
public double maxReceivedPerCycle() {
return orignal.maxReceivedPerCycle();
}
@Override
public String kind() {
return orignal.kind();
}
@Override
public void init(Object object, Field storedField, MjBattery battery) {
}
}

View file

@ -25,7 +25,7 @@ public class AssemblyRecipeManager implements IAssemblyRecipeManager {
private Map<String, IFlexibleRecipe<ItemStack>> assemblyRecipes = new HashMap<String, IFlexibleRecipe<ItemStack>>();
@Override
public void addRecipe(String id, double energyCost, ItemStack output, Object... input) {
public void addRecipe(String id, int energyCost, ItemStack output, Object... input) {
String name = Item.itemRegistry.getNameForObject(output.getItem());
if (BuildCraftCore.recipesBlacklist.contains(name)) {

View file

@ -25,7 +25,7 @@ import buildcraft.core.inventory.filters.ArrayStackFilter;
import buildcraft.core.inventory.filters.IStackFilter;
public class FlexibleRecipe<T> implements IFlexibleRecipe<T> {
public double energyCost = 0;
public int energyCost = 0;
public long craftingTime = 0;
public String id;
@ -40,11 +40,11 @@ public class FlexibleRecipe<T> implements IFlexibleRecipe<T> {
}
public FlexibleRecipe(String id, T output, double iEnergyCost, long craftingTime, Object... input) {
public FlexibleRecipe(String id, T output, int iEnergyCost, long craftingTime, Object... input) {
setContents(id, output, iEnergyCost, craftingTime, input);
}
public void setContents(String iid, Object ioutput, double iEnergyCost, long iCraftingTime, Object... input) {
public void setContents(String iid, Object ioutput, int iEnergyCost, long iCraftingTime, Object... input) {
id = iid;
if (ioutput instanceof ItemStack) {

View file

@ -85,7 +85,7 @@ public class AIRobotAttack extends AIRobot {
}
@Override
public double getEnergyCost() {
return 5;
public int getEnergyCost() {
return 50;
}
}

View file

@ -129,8 +129,8 @@ public class AIRobotBreak extends AIRobot {
}
@Override
public double getEnergyCost() {
return 2;
public int getEnergyCost() {
return 20;
}
@Override

View file

@ -245,7 +245,7 @@ public class AIRobotCraftWorkbench extends AIRobotCraftGeneric {
}
@Override
public double getEnergyCost() {
return 3;
public int getEnergyCost() {
return 30;
}
}

View file

@ -47,7 +47,7 @@ public abstract class AIRobotGoto extends AIRobot {
}
@Override
public double getEnergyCost() {
return 1;
public int getEnergyCost() {
return 10;
}
}

View file

@ -110,7 +110,7 @@ public class AIRobotLoad extends AIRobot {
}
@Override
public double getEnergyCost() {
return 2;
public int getEnergyCost() {
return 20;
}
}

View file

@ -90,8 +90,8 @@ public class AIRobotLoadFluids extends AIRobot {
}
@Override
public double getEnergyCost() {
return 2;
public int getEnergyCost() {
return 20;
}
@Override

View file

@ -67,8 +67,8 @@ public class AIRobotPumpBlock extends AIRobot {
}
@Override
public double getEnergyCost() {
return 2;
public int getEnergyCost() {
return 20;
}
@Override

View file

@ -37,9 +37,11 @@ public class AIRobotRecharge extends AIRobot {
public void update() {
PipeTransportPower powerProvider = (PipeTransportPower) ((DockingStation) robot.getDockingStation()).getPipe().pipe.transport;
powerProvider.requestEnergy(robot.getDockingStation().side(), 100);
robot.setEnergy(robot.getEnergy()
+ powerProvider.consumePower(robot.getDockingStation().side(), 100));
int amount = robot.getBattery().receiveEnergy(1000, false);
powerProvider.requestEnergy(robot.getDockingStation().side(), amount);
robot.getBattery().receiveEnergy(powerProvider.consumePower(robot.getDockingStation().side(), amount), false);
if (robot.getEnergy() >= EntityRobotBase.MAX_ENERGY) {
terminate();

View file

@ -42,7 +42,8 @@ public class AIRobotSleep extends AIRobot {
}
@Override
public double getEnergyCost() {
return 0.01;
public int getEnergyCost() {
// This trick is so we ge 0.1 RF per tick.
return sleptTime % 10;
}
}

View file

@ -72,8 +72,8 @@ public class AIRobotUnload extends AIRobot {
}
@Override
public double getEnergyCost() {
return 2;
public int getEnergyCost() {
return 20;
}
@Override

View file

@ -85,8 +85,8 @@ public class AIRobotUnloadFluids extends AIRobot {
}
@Override
public double getEnergyCost() {
return 2;
public int getEnergyCost() {
return 20;
}
@Override

View file

@ -69,7 +69,7 @@ public class AIRobotUseToolOnBlock extends AIRobot {
}
@Override
public double getEnergyCost() {
return 2;
public int getEnergyCost() {
return 20;
}
}

View file

@ -12,7 +12,6 @@ import java.util.Date;
import java.util.WeakHashMap;
import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
@ -27,11 +26,9 @@ import net.minecraft.util.EntityDamageSource;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
@ -39,7 +36,6 @@ import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import buildcraft.BuildCraftSilicon;
import buildcraft.api.boards.RedstoneBoardNBT;
import buildcraft.api.boards.RedstoneBoardRegistry;
@ -48,12 +44,12 @@ import buildcraft.api.boards.RedstoneBoardRobotNBT;
import buildcraft.api.core.BlockIndex;
import buildcraft.api.core.IZone;
import buildcraft.api.core.SafeTimeTracker;
import buildcraft.api.mj.MjBattery;
import buildcraft.api.robots.AIRobot;
import buildcraft.api.robots.EntityRobotBase;
import buildcraft.api.robots.IDockingStation;
import buildcraft.core.DefaultProps;
import buildcraft.core.LaserData;
import buildcraft.core.RFBattery;
import buildcraft.core.network.RPC;
import buildcraft.core.network.RPCHandler;
import buildcraft.core.network.RPCMessageInfo;
@ -113,14 +109,13 @@ public class EntityRobot extends EntityRobotBase implements
private NBTTagList stackRequestNBT;
@MjBattery
private double mjStored;
private RFBattery battery = new RFBattery(MAX_ENERGY, MAX_ENERGY, 0);
private boolean firstUpdateDone = false;
private long robotId = EntityRobotBase.NULL_ROBOT_ID;
private float energySpendPerCycle = 0;
private int energySpendPerCycle = 0;
private float energyFX = 0;
private int steamDx = 0;
private int steamDy = -1;
@ -189,7 +184,7 @@ public class EntityRobot extends EntityRobotBase implements
itemAngle1 = dataWatcher.getWatchableObjectFloat(17);
itemAngle2 = dataWatcher.getWatchableObjectFloat(18);
energySpendPerCycle = dataWatcher.getWatchableObjectFloat(19);
energySpendPerCycle = dataWatcher.getWatchableObjectInt(19);
}
protected void updateDataServer() {
@ -308,12 +303,12 @@ public class EntityRobot extends EntityRobotBase implements
if (linkedDockingStation != null) {
mainAI.cycle();
if (energySpendPerCycle != (float) mainAI.getActiveAI().getEnergyCost()) {
energySpendPerCycle = (float) mainAI.getActiveAI().getEnergyCost();
if (energySpendPerCycle != mainAI.getActiveAI().getEnergyCost()) {
energySpendPerCycle = mainAI.getActiveAI().getEnergyCost();
needsUpdate = true;
}
if (mjStored <= 0) {
if (this.battery.getEnergyStored() <= 0) {
setDead();
}
}
@ -442,7 +437,7 @@ public class EntityRobot extends EntityRobotBase implements
laser.writeToNBT(nbtLaser);
nbt.setTag("laser", nbtLaser);
nbt.setDouble("mjStored", mjStored);
battery.writeToNBT(nbt);
if (itemInUse != null) {
NBTTagCompound itemNBT = new NBTTagCompound();
@ -499,7 +494,7 @@ public class EntityRobot extends EntityRobotBase implements
laser.readFromNBT(nbt.getCompoundTag("laser"));
mjStored = nbt.getDouble("mjStored");
battery.readFromNBT(nbt);
if (nbt.hasKey("itemInUse")) {
itemInUse = ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("itemInUse"));
@ -788,17 +783,13 @@ public class EntityRobot extends EntityRobotBase implements
}
@Override
public double getEnergy() {
return mjStored;
public int getEnergy() {
return battery.getEnergyStored();
}
@Override
public void setEnergy(double energy) {
mjStored = energy;
if (mjStored > MAX_ENERGY) {
mjStored = MAX_ENERGY;
}
public RFBattery getBattery() {
return battery;
}
@Override

View file

@ -143,7 +143,7 @@ public class BoardRobotBuilder extends RedstoneBoardRobot {
return;
}
robot.setEnergy(robot.getEnergy() - currentBuildingSlot.getEnergyRequirement());
robot.getBattery().extractEnergy(currentBuildingSlot.getEnergyRequirement(), false);
launchingDelay = currentBuildingSlot.getStacksToDisplay().size() * BuildingItem.ITEMS_SPACE;
markerToBuild.bluePrintBuilder.buildSlot
(robot.worldObj, markerToBuild, currentBuildingSlot,

View file

@ -10,20 +10,17 @@ package buildcraft.core.triggers;
import java.util.LinkedList;
import cofh.api.energy.IEnergyHandler;
import net.minecraft.block.Block;
import net.minecraft.inventory.IInventory;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import buildcraft.BuildCraftCore;
import buildcraft.api.gates.IOverrideDefaultTriggers;
import buildcraft.api.gates.ITrigger;
import buildcraft.api.gates.ITriggerProvider;
import buildcraft.api.mj.IBatteryObject;
import buildcraft.api.mj.MjAPI;
import buildcraft.api.transport.IPipeTile;
import buildcraft.core.IMachine;
@ -65,9 +62,7 @@ public class DefaultTriggerProvider implements ITriggerProvider {
res.add(BuildCraftCore.triggerMachineInactive);
}
IBatteryObject battery = MjAPI.getMjBattery(tile);
if (battery != null && battery.maxCapacity() > 0) {
if (tile instanceof IEnergyHandler && ((IEnergyHandler)tile).getMaxEnergyStored(ForgeDirection.UNKNOWN) > 0) {
res.add(BuildCraftCore.triggerEnergyHigh);
res.add(BuildCraftCore.triggerEnergyLow);
}

View file

@ -8,19 +8,15 @@
*/
package buildcraft.core.triggers;
import cofh.api.energy.IEnergyHandler;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.gates.IGate;
import buildcraft.api.gates.ITriggerParameter;
import buildcraft.api.mj.IBatteryObject;
import buildcraft.api.mj.MjAPI;
import buildcraft.core.utils.StringUtils;
public class TriggerEnergy extends BCTrigger {
@ -40,20 +36,28 @@ public class TriggerEnergy extends BCTrigger {
return StringUtils.localize("gate.trigger.machine.energyStored" + (high ? "High" : "Low"));
}
private boolean isValidEnergyHandler(IEnergyHandler handler) {
return handler.getMaxEnergyStored(ForgeDirection.UNKNOWN) > 0;
}
private boolean isTriggeredEnergyHandler(IEnergyHandler handler) {
int energyStored = handler.getEnergyStored(ForgeDirection.UNKNOWN);
int energyMaxStored = handler.getMaxEnergyStored(ForgeDirection.UNKNOWN);
if (energyMaxStored > 0) {
if (high) {
return (energyStored / energyMaxStored) > 0.95;
} else {
return (energyStored / energyMaxStored) < 0.05;
}
}
return false;
}
@Override
public boolean isTriggerActive(IGate gate, ITriggerParameter[] parameters) {
IBatteryObject battery = MjAPI.getMjBattery(gate.getPipe());
if (battery != null) {
double maxCapacity = battery.maxCapacity();
if (maxCapacity > 0) {
if (high) {
return battery.getEnergyStored() / maxCapacity > 0.95;
} else {
return battery.getEnergyStored() / maxCapacity < 0.05;
}
}
if (gate.getPipe() instanceof IEnergyHandler) {
if(isValidEnergyHandler((IEnergyHandler)gate.getPipe()))
return isTriggeredEnergyHandler((IEnergyHandler)gate.getPipe());
}
// if the pipe can't set the trigger one way or the other, then look
@ -64,18 +68,10 @@ public class TriggerEnergy extends BCTrigger {
@Override
public boolean isTriggerActive(ForgeDirection side, TileEntity tile, ITriggerParameter parameter) {
IBatteryObject battery = MjAPI.getMjBattery(tile);
if (battery != null) {
double maxCapacity = battery.maxCapacity();
if (maxCapacity > 0) {
if (high) {
return battery.getEnergyStored() / maxCapacity > 0.95;
} else {
return battery.getEnergyStored() / maxCapacity < 0.05;
}
}
if(tile instanceof IEnergyHandler) {
// Since we return false upon the trigger being invalid anyway,
// we can skip the isValidEnergyHandler(...) check.
return isTriggeredEnergyHandler((IEnergyHandler)tile);
}
return false;

View file

@ -1,65 +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.energy;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.core.BlockBuildCraft;
import buildcraft.core.IItemPipe;
public class BlockEnergyConverter extends BlockBuildCraft {
@SideOnly(Side.CLIENT)
private IIcon blockTexture;
public BlockEnergyConverter() {
super(Material.ground);
setBlockName("energyConverter");
}
@Override
public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer player, int side, float par7, float par8, float par9) {
TileEntity tile = world.getTileEntity(i, j, k);
// Do not open guis when having a pipe in hand
if (player.getCurrentEquippedItem() != null &&
player.getCurrentEquippedItem().getItem() instanceof IItemPipe) {
return false;
}
return tile instanceof TileEnergyConverter
&& ((TileEnergyConverter) tile).onBlockActivated(player, ForgeDirection.getOrientation(side));
}
@Override
public TileEntity createNewTileEntity(World world, int metadata) {
return new TileEnergyConverter();
}
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister par1IconRegister) {
blockTexture = par1IconRegister.registerIcon("buildcraft:blockEnergyConverter");
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(int i, int j) {
return blockTexture;
}
}

View file

@ -1,31 +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.energy;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
public class ItemEnergyConverter extends ItemBlock {
public ItemEnergyConverter(Block block) {
super(block);
}
@Override
public void addInformation(ItemStack itemStack, EntityPlayer player, List list, boolean adv) {
super.addInformation(itemStack, player, list, adv);
list.add(TileEnergyConverter.getLocalizedModeName(itemStack));
list.add("");
// This is a bit too big in the tooltip at this stage.
// list.addAll(Arrays.asList(StringUtils.localize("tile.energyConverter.tooltip").split("\\|")));
}
}

View file

@ -1,168 +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.energy;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatComponentText;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.core.NetworkData;
import buildcraft.api.mj.IBatteryObject;
import buildcraft.api.mj.MjAPI;
import buildcraft.api.mj.MjBattery;
import buildcraft.api.power.IPowerEmitter;
import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerHandler;
import buildcraft.api.tools.IToolWrench;
import buildcraft.core.TileBuffer;
import buildcraft.core.TileBuildCraft;
import buildcraft.core.utils.StringUtils;
public class TileEnergyConverter extends TileBuildCraft implements IPowerReceptor, IPowerEmitter {
private static enum Mode {
FromOldToNew("from_old_to_new"), FromNewToOld("from_new_to_old");
private final String localizeName;
Mode(String localizeName) {
this.localizeName = localizeName;
}
public Mode next() {
if (this == FromOldToNew) {
return FromNewToOld;
}
return FromOldToNew;
}
}
@MjBattery(maxCapacity = 1000, maxReceivedPerCycle = 64, minimumConsumption = 1)
@NetworkData
private double mjStored = 0;
@NetworkData
private Mode mode = Mode.FromOldToNew;
private TileBuffer[] tileCache;
private PowerHandler powerHandler, zeroPowerHandler;
public TileEnergyConverter() {
powerHandler = new PowerHandler(this, PowerHandler.Type.MACHINE, MjAPI.createBattery(this, MjAPI.DEFAULT_POWER_FRAMEWORK, ForgeDirection.UNKNOWN));
zeroPowerHandler = new PowerHandler(this, PowerHandler.Type.MACHINE);
zeroPowerHandler.configure(0, 0, 0, 0);
}
public static String getLocalizedModeName(ItemStack stack) {
int mode = 0;
if (stack != null && stack.getTagCompound() != null) {
mode = stack.getTagCompound().getInteger("converterMode");
if (mode >= Mode.values().length || mode < 0) {
mode = 0;
}
}
return StringUtils.localize("chat.pipe.power.energyConverter." + Mode.values()[mode].localizeName);
}
public boolean onBlockActivated(EntityPlayer player, ForgeDirection side) {
if (!getWorld().isRemote) {
Item equipped = player.getCurrentEquippedItem() != null ? player.getCurrentEquippedItem().getItem() : null;
if (equipped instanceof IToolWrench && ((IToolWrench) equipped).canWrench(player, xCoord, yCoord, zCoord)) {
mode = mode.next();
player.addChatMessage(new ChatComponentText(String.format(
StringUtils.localize("chat.pipe.power.energyConverter"),
StringUtils.localize("chat.pipe.power.energyConverter." + mode.localizeName))));
sendNetworkUpdate();
((IToolWrench) equipped).wrenchUsed(player, xCoord, yCoord, zCoord);
return true;
}
}
return !player.isSneaking();
}
@Override
public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt);
nbt.setDouble("mjStored", mjStored);
nbt.setInteger("converterMode", mode.ordinal());
}
@Override
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
mjStored = nbt.getDouble("mjStored");
mode = Mode.values()[nbt.getInteger("converterMode")];
}
public TileBuffer getTileBuffer(ForgeDirection side) {
if (tileCache == null) {
tileCache = TileBuffer.makeBuffer(worldObj, xCoord, yCoord, zCoord, false);
}
return tileCache[side.ordinal()];
}
@Override
public void updateEntity() {
super.updateEntity();
if (mode == Mode.FromOldToNew) {
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
TileEntity tile = getTileBuffer(side).getTile();
if (tile instanceof TileEnergyConverter) {
continue;
}
IBatteryObject object = MjAPI.getMjBattery(tile, MjAPI.DEFAULT_POWER_FRAMEWORK, side.getOpposite());
if (object != null && mjStored > 0) {
double wantToUse = Math.min(mjStored, object.getEnergyRequested());
object.addEnergy(wantToUse);
mjStored -= wantToUse;
}
}
} else if (mode == Mode.FromNewToOld) {
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
TileEntity tile = getTileBuffer(side).getTile();
if (tile instanceof TileEnergyConverter) {
continue;
}
if (tile instanceof IPowerReceptor && mjStored > 0) {
IPowerReceptor receptor = (IPowerReceptor) tile;
PowerHandler.PowerReceiver powerReceiver = receptor.getPowerReceiver(side.getOpposite());
if (powerReceiver == null) {
continue;
}
double wantToUse = Math.min(mjStored, powerReceiver.getMaxEnergyReceived());
if (wantToUse > powerReceiver.getMinEnergyReceived()) {
powerReceiver.receiveEnergy(PowerHandler.Type.MACHINE, wantToUse, side);
mjStored -= wantToUse;
}
}
}
}
}
@Override
public PowerHandler.PowerReceiver getPowerReceiver(ForgeDirection side) {
return (mode == Mode.FromOldToNew ? powerHandler : zeroPowerHandler).getPowerReceiver();
}
@Override
public void doWork(PowerHandler workProvider) {
}
@Override
public boolean canEmitPowerFrom(ForgeDirection side) {
return mode == Mode.FromOldToNew;
}
}

View file

@ -13,11 +13,10 @@ import java.util.TreeMap;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import buildcraft.api.core.BlockIndex;
import buildcraft.api.core.SafeTimeTracker;
import buildcraft.api.mj.MjBattery;
import buildcraft.core.LaserData;
import buildcraft.core.RFBattery;
import buildcraft.core.TileBuildCraft;
import buildcraft.core.network.RPC;
import buildcraft.core.network.RPCHandler;
@ -25,13 +24,9 @@ import buildcraft.core.network.RPCMessageInfo;
import buildcraft.core.network.RPCSide;
public class TileEnergyEmitter extends TileBuildCraft {
@MjBattery (maxCapacity = 1024, maxReceivedPerCycle = 1204, minimumConsumption = 0)
public double mjStored;
public Map<BlockIndex, Target> targets = new TreeMap<BlockIndex, Target>();
public float mjAcc = 0;
public int rfAcc = 0;
public int accumulated = 0;
private SafeTimeTracker syncMJ = new SafeTimeTracker(20, 5);
@ -43,7 +38,8 @@ public class TileEnergyEmitter extends TileBuildCraft {
}
public TileEnergyEmitter () {
super();
this.setBattery(new RFBattery(10240, 10240, 0));
}
@Override
@ -67,7 +63,7 @@ public class TileEnergyEmitter extends TileBuildCraft {
if (t.data.wavePosition > t.data.renderSize) {
t.data.wavePosition = 0;
t.data.waveSize = (float) (mjStored / targets.size() / 10F);
t.data.waveSize = (float) (getBattery().getEnergyStored() / targets.size() / 100F);
if (t.data.waveSize > 1) {
t.data.waveSize = 1F;
@ -107,17 +103,17 @@ public class TileEnergyEmitter extends TileBuildCraft {
// synchronize regularly with the client an average of the energy in
// the emitter
mjAcc += mjStored;
rfAcc += getBattery().getEnergyStored();
accumulated++;
if (syncMJ.markTimeIfDelay(worldObj)) {
RPCHandler.rpcBroadcastWorldPlayers(worldObj, this, "synchronizeMJ", mjAcc
RPCHandler.rpcBroadcastWorldPlayers(worldObj, this, "synchronizeMJ", rfAcc
/ accumulated);
mjAcc = 0;
rfAcc = 0;
accumulated = 0;
}
if (mjStored == 0) {
if (getBattery().getEnergyStored() == 0) {
for (Target t : targets.values()) {
if (t.data.isVisible) {
t.data.isVisible = false;
@ -127,14 +123,7 @@ public class TileEnergyEmitter extends TileBuildCraft {
}
}
} else {
double perTargetEnergy = 10;
if (mjStored > targets.size() * 10) {
mjStored -= targets.size() * 10;
} else {
perTargetEnergy = mjStored / targets.size();
mjStored = 0;
}
int perTargetEnergy = (int)Math.floor(getBattery().useEnergy(targets.size(), targets.size() * 100, false) / targets.size());
for (Target t : targets.values()) {
if (!t.data.isVisible) {
@ -152,8 +141,8 @@ public class TileEnergyEmitter extends TileBuildCraft {
}
@RPC (RPCSide.CLIENT)
public void synchronizeMJ (float val) {
mjStored = val;
public void synchronizeMJ (int val) {
this.getBattery().setEnergy(val);
}
@RPC (RPCSide.CLIENT)

View file

@ -10,12 +10,9 @@ package buildcraft.energy;
import java.util.LinkedList;
import cofh.api.energy.IEnergyHandler;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.mj.IBatteryObject;
import buildcraft.api.mj.MjAPI;
import buildcraft.api.power.IPowerEmitter;
import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerHandler;
@ -28,7 +25,7 @@ import buildcraft.core.TileBuildCraft;
public class TileEnergyReceiver extends TileBuildCraft implements IPipeConnection, IPowerEmitter {
public static LinkedList<TileEnergyReceiver> knownReceivers = new LinkedList<TileEnergyReceiver>();
public float energyStored = 0;
public int energyStored = 0;
private TileBuffer[] tileCache;
@ -52,8 +49,8 @@ public class TileEnergyReceiver extends TileBuildCraft implements IPipeConnectio
public boolean isPoweredTile(TileEntity tile, ForgeDirection side) {
if (tile instanceof IPowerReceptor) {
return ((IPowerReceptor) tile).getPowerReceiver(side.getOpposite()) != null;
} else if (MjAPI.getMjBattery(tile) != null) {
return true;
} else if (tile instanceof IEnergyHandler) {
return ((IEnergyHandler) tile).canConnectEnergy(side.getOpposite());
}
return false;
@ -68,18 +65,14 @@ public class TileEnergyReceiver extends TileBuildCraft implements IPipeConnectio
.getPowerReceiver(s.getOpposite());
if (receptor != null) {
receptor.receiveEnergy(PowerHandler.Type.ENGINE, energyStored,
receptor.receiveEnergy(PowerHandler.Type.ENGINE, energyStored / 10.0,
s.getOpposite());
energyStored = 0;
}
} else if (tile != null) {
IBatteryObject battery = MjAPI.getMjBattery(tile);
if (battery != null) {
battery.addEnergy(energyStored);
energyStored = 0;
}
} else if (tile instanceof IEnergyHandler) {
int energyUsed = ((IEnergyHandler)tile).receiveEnergy(s.getOpposite(), energyStored, false);
energyStored -= energyUsed;
}
}
}

View file

@ -10,22 +10,17 @@ package buildcraft.energy;
import java.util.LinkedList;
import cofh.api.energy.IEnergyHandler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftEnergy;
import buildcraft.api.core.NetworkData;
import buildcraft.api.gates.IOverrideDefaultTriggers;
import buildcraft.api.gates.ITrigger;
import buildcraft.api.mj.IBatteryIOObject;
import buildcraft.api.mj.IBatteryObject;
import buildcraft.api.mj.ISidedBatteryProvider;
import buildcraft.api.mj.MjAPI;
import buildcraft.api.power.IPowerEmitter;
import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerHandler;
@ -37,10 +32,10 @@ import buildcraft.api.transport.IPipeTile.PipeType;
import buildcraft.core.DefaultProps;
import buildcraft.core.TileBuffer;
import buildcraft.core.TileBuildCraft;
import buildcraft.core.utils.AverageUtil;
import buildcraft.energy.gui.ContainerEngine;
public abstract class TileEngine extends TileBuildCraft implements ISidedBatteryProvider, IPowerReceptor, IPowerEmitter, IOverrideDefaultTriggers, IPipeConnection {
public abstract class TileEngine extends TileBuildCraft implements IPowerReceptor, IPowerEmitter, IOverrideDefaultTriggers, IPipeConnection, IEnergyHandler {
protected boolean constantPower = false;
// Index corresponds to metadata
public static final ResourceLocation[] BASE_TEXTURES = new ResourceLocation[]{
@ -79,8 +74,10 @@ public abstract class TileEngine extends TileBuildCraft implements ISidedBattery
public static final float MIN_HEAT = 20;
public static final float IDEAL_HEAT = 100;
public static final float MAX_HEAT = 250;
public double currentOutput = 0;
public boolean isRedstonePowered = false;
public float progress;
public double energy;
public float heat = MIN_HEAT;
@NetworkData
public EnergyStage energyStage = EnergyStage.BLUE;
@ -90,9 +87,6 @@ public abstract class TileEngine extends TileBuildCraft implements ISidedBattery
protected int progressPart = 0;
protected boolean lastPower = false;
protected PowerHandler powerHandler;
protected IBatteryIOObject mjStoredBattery;
protected AverageUtil currentOutputAverage = new AverageUtil(20);
protected double currentOutput = -1;
private boolean checkOrienation = false;
private TileBuffer[] tileCache;
@ -101,32 +95,14 @@ public abstract class TileEngine extends TileBuildCraft implements ISidedBattery
private boolean isPumping = false; // Used for SMP synch
public TileEngine() {
mjStoredBattery = (IBatteryIOObject) MjAPI.createBattery(this, MjAPI.DEFAULT_POWER_FRAMEWORK, ForgeDirection.UNKNOWN);
if (mjStoredBattery == null) {
throw new NullPointerException("Engine " + this + " doesn't has a battery!");
}
powerHandler = new PowerHandler(this, Type.ENGINE, mjStoredBattery);
powerHandler.configurePowerPerdition(0, 0);
}
public double getCurrentOutputAverage() {
if (currentOutput != -1) {
return currentOutput;
}
return currentOutputAverage.getAverage();
}
@Override
public IBatteryObject getMjBattery(String kind, ForgeDirection direction) {
if (mjStoredBattery.kind().equals(kind) && direction == orientation) {
return mjStoredBattery;
}
return null;
powerHandler = new PowerHandler(this, Type.ENGINE);
powerHandler.configurePowerPerdition(1, 100);
}
@Override
public void initialize() {
if (!worldObj.isRemote) {
powerHandler.configure(minEnergyReceived(), maxEnergyReceived(), 1, getMaxEnergy());
checkRedstonePower();
}
}
@ -155,7 +131,7 @@ public abstract class TileEngine extends TileBuildCraft implements ISidedBattery
}
public double getEnergyLevel() {
return mjStoredBattery.getEnergyStored() / mjStoredBattery.maxCapacity() + .01d;
return energy / getMaxEnergy();
}
protected EnergyStage computeEnergyStage() {
@ -228,7 +204,6 @@ public abstract class TileEngine extends TileBuildCraft implements ISidedBattery
@Override
public void updateEntity() {
super.updateEntity();
MjAPI.updateEntity(this);
if (worldObj.isRemote) {
if (progressPart != 0) {
@ -253,9 +228,6 @@ public abstract class TileEngine extends TileBuildCraft implements ISidedBattery
}
}
currentOutputAverage.tick();
burn();
updateHeatLevel();
getEnergyStage();
engineUpdate();
@ -267,29 +239,107 @@ public abstract class TileEngine extends TileBuildCraft implements ISidedBattery
if (progress > 0.5 && progressPart == 1) {
progressPart = 2;
if(!constantPower)
sendPower();
} else if (progress >= 1) {
progress = 0;
progressPart = 0;
}
} else if (isRedstonePowered && isActive()) {
if (isPoweredTile(tile, orientation)) {
progressPart = 1;
/*progressPart = 1;
setPumping(true);
if (getPowerToExtract() > 0) {
progressPart = 1;
setPumping(true);
} else {
setPumping(false);
}*/
} else {
setPumping(false);
}
} else {
progressPart = 0;
setPumping(false);
}
// Uncomment for constant power
if(constantPower) {
if (isRedstonePowered && isActive()) {
sendPower();
} else currentOutput = 0;
}
burn();
}
private double getPowerToExtract() {
TileEntity tile = getTileBuffer(orientation).getTile();
if(tile instanceof IEnergyHandler) {
IEnergyHandler handler = ((IEnergyHandler)tile);
int minEnergy = 0;
int maxEnergy = handler.receiveEnergy(
orientation.getOpposite(),
(int)Math.round(this.energy * 10), true);
return extractEnergy((double)minEnergy / 10.0, (double)maxEnergy / 10.0, false);
} else if (tile instanceof IPowerReceptor) {
PowerReceiver receptor = ((IPowerReceptor) tile)
.getPowerReceiver(orientation.getOpposite());
return extractEnergy(receptor.getMinEnergyReceived(),
receptor.getMaxEnergyReceived(), false);
} else {
return 0;
}
}
protected void sendPower() {
TileEntity tile = getTileBuffer(orientation).getTile();
if (isPoweredTile(tile, orientation)) {
double extracted = getPowerToExtract();
if(extracted > 0) setPumping(true);
else setPumping(false);
if (tile instanceof IEnergyHandler) {
IEnergyHandler handler = ((IEnergyHandler) tile);
if (Math.round(extracted * 10) > 0) {
int neededRF = handler.receiveEnergy(
orientation.getOpposite(),
(int)Math.round(extracted * 10), false);
extractEnergy(0.0, (double)neededRF / 10.0, true);
}
} else if (tile instanceof IPowerReceptor) {
PowerReceiver receptor = ((IPowerReceptor) tile)
.getPowerReceiver(orientation.getOpposite());
if (extracted > 0) {
double needed = receptor.receiveEnergy(
PowerHandler.Type.ENGINE, extracted,
orientation.getOpposite());
extractEnergy(receptor.getMinEnergyReceived(), needed, true);
}
}
}
}
// Uncomment out for constant power
// public float getActualOutput() {
// float heatLevel = getIdealHeatLevel();
// return getCurrentOutput() * heatLevel;
// }
protected void burn() {
}
protected void engineUpdate() {
if (!isRedstonePowered) {
mjStoredBattery.extractEnergy(1);
if (energy >= 1) {
energy -= 1;
} else if (energy < 1) {
energy = 0;
}
}
}
@ -327,6 +377,11 @@ public abstract class TileEngine extends TileBuildCraft implements ISidedBattery
TileEntity tile = getTileBuffer(o).getTile();
if ((!pipesOnly || tile instanceof IPipeTile) && isPoweredTile(tile, o)) {
if((tile instanceof IPipeTile) && (((IPipeTile)tile).getPipeType() != PipeType.POWER))
constantPower = false;
else if(tile instanceof IEnergyHandler) constantPower = true;
else constantPower = false;
orientation = o;
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, worldObj.getBlock(xCoord, yCoord, zCoord));
@ -366,8 +421,10 @@ public abstract class TileEngine extends TileBuildCraft implements ISidedBattery
orientation = ForgeDirection.getOrientation(data.getInteger("orientation"));
progress = data.getFloat("progress");
mjStoredBattery.setEnergyStored(data.getDouble("energy"));
energy = data.getDouble("energy");
heat = data.getFloat("heat");
if(data.hasKey("constantPower"))
constantPower = data.getBoolean("constantPower");
}
@Override
@ -376,21 +433,22 @@ public abstract class TileEngine extends TileBuildCraft implements ISidedBattery
data.setInteger("orientation", orientation.ordinal());
data.setFloat("progress", progress);
data.setDouble("energy", mjStoredBattery.getEnergyStored());
data.setDouble("energy", energy);
data.setFloat("heat", heat);
data.setBoolean("constantPower", constantPower);
}
public void getGUINetworkData(int id, int value) {
switch (id) {
case 0:
int iEnergy = (int) Math.round(mjStoredBattery.getEnergyStored() * 10);
int iEnergy = (int) Math.round(energy * 10);
iEnergy = (iEnergy & 0xffff0000) | (value & 0xffff);
mjStoredBattery.setEnergyStored(iEnergy / 10);
energy = iEnergy / 10;
break;
case 1:
iEnergy = (int) Math.round(mjStoredBattery.getEnergyStored() * 10);
iEnergy = (int) Math.round(energy * 10);
iEnergy = (iEnergy & 0xffff) | ((value & 0xffff) << 16);
mjStoredBattery.setEnergyStored(iEnergy / 10);
energy = iEnergy / 10;
break;
case 2:
currentOutput = value / 10F;
@ -402,9 +460,9 @@ public abstract class TileEngine extends TileBuildCraft implements ISidedBattery
}
public void sendGUINetworkData(ContainerEngine containerEngine, ICrafting iCrafting) {
iCrafting.sendProgressBarUpdate(containerEngine, 0, (int) Math.round(mjStoredBattery.getEnergyStored() * 10) & 0xffff);
iCrafting.sendProgressBarUpdate(containerEngine, 1, (int) (Math.round(mjStoredBattery.getEnergyStored() * 10) & 0xffff0000) >> 16);
iCrafting.sendProgressBarUpdate(containerEngine, 2, (int) Math.round(currentOutputAverage.getAverage() * 10));
iCrafting.sendProgressBarUpdate(containerEngine, 0, (int) Math.round(energy * 10) & 0xffff);
iCrafting.sendProgressBarUpdate(containerEngine, 1, (int) (Math.round(energy * 10) & 0xffff0000) >> 16);
iCrafting.sendProgressBarUpdate(containerEngine, 2, (int) Math.round(currentOutput * 10));
iCrafting.sendProgressBarUpdate(containerEngine, 3, Math.round(heat * 100));
}
@ -418,34 +476,92 @@ public abstract class TileEngine extends TileBuildCraft implements ISidedBattery
@Override
public void doWork(PowerHandler workProvider) {
if (worldObj.isRemote) {
return;
}
addEnergy(powerHandler.useEnergy(1, maxEnergyReceived(), true) * 0.95F);
}
public void addEnergy(double addition) {
double stored = mjStoredBattery.getEnergyStored();
double used = Math.min(addition, mjStoredBattery.maxReceivedPerCycle());
used = Math.min(used, mjStoredBattery.maxCapacity() - stored);
if (used > 0) {
currentOutputAverage.push(used);
mjStoredBattery.addEnergy(used);
}
energy += addition;
if (getEnergyStage() == EnergyStage.OVERHEAT) {
worldObj.createExplosion(null, xCoord, yCoord, zCoord, explosionRange(), true);
worldObj.setBlockToAir(xCoord, yCoord, zCoord);
}
if (energy > getMaxEnergy()) {
energy = getMaxEnergy();
}
}
public double extractEnergy(double min, double max, boolean doExtract) {
if (energy < min) {
return 0;
}
double actualMax;
if (max > maxEnergyExtracted()) {
actualMax = maxEnergyExtracted();
} else {
actualMax = max;
}
if (actualMax < min) {
return 0;
}
double extracted;
if (energy >= actualMax) {
extracted = actualMax;
if (doExtract) {
energy -= actualMax;
}
} else {
extracted = energy;
if (doExtract) {
energy = 0;
}
}
return extracted;
}
public boolean isPoweredTile(TileEntity tile, ForgeDirection side) {
return MjAPI.getMjBattery(tile, MjAPI.DEFAULT_POWER_FRAMEWORK, side.getOpposite()) != null;
if (tile == null) {
return false;
} else if (tile instanceof IPowerReceptor) {
return ((IPowerReceptor) tile).getPowerReceiver(side.getOpposite()) != null;
} else if (tile instanceof IEnergyHandler){
return ((IEnergyHandler) tile).canConnectEnergy(side.getOpposite());
} else {
return false;
}
}
public abstract double getMaxEnergy();
public double minEnergyReceived() {
return 2;
}
public abstract double maxEnergyReceived();
public abstract double maxEnergyExtracted();
public abstract float explosionRange();
public double getEnergyStored() {
return mjStoredBattery.getEnergyStored();
return energy;
}
public abstract double getCurrentOutput();
@Override
public LinkedList<ITrigger> getTriggers() {
LinkedList<ITrigger> triggers = new LinkedList<ITrigger>();
@ -477,4 +593,45 @@ public abstract class TileEngine extends TileBuildCraft implements ISidedBattery
public void checkRedstonePower() {
isRedstonePowered = worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord);
}
// RF support
@Override
public int receiveEnergy(ForgeDirection from, int maxReceive,
boolean simulate) {
return 0;
}
@Override
public int extractEnergy(ForgeDirection from, int maxExtract,
boolean simulate) {
return 0;
/*if(!(from == orientation)) return 0;
int energyRF = (int)Math.round(10 * energy);
int energyExtracted = Math.min(maxExtract, energyRF);
if(!simulate) {
if(energyExtracted == energyRF) energy = 0;
else energy -= (double)energyExtracted / 10.0;
}
return energyExtracted;*/
}
@Override
public int getEnergyStored(ForgeDirection from) {
if(!(from == orientation)) return 0;
return (int)Math.round(10 * energy);
}
@Override
public int getMaxEnergyStored(ForgeDirection from) {
return getEnergyStored(from);
}
@Override
public boolean canConnectEnergy(ForgeDirection from) {
return from == orientation;
}
}

View file

@ -17,17 +17,11 @@ import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.core.NetworkData;
import buildcraft.api.mj.IOMode;
import buildcraft.api.mj.MjAPI;
import buildcraft.api.mj.MjBattery;
import buildcraft.api.tools.IToolWrench;
import buildcraft.core.utils.StringUtils;
import buildcraft.transport.pipes.PipePowerIron;
public class TileEngineCreative extends TileEngine {
@MjBattery(mode = IOMode.SendActive, maxCapacity = 10000, maxReceivedPerCycle = 2, minimumConsumption = 0)
@NetworkData
private double mjStored;
@NetworkData
private PipePowerIron.PowerMode powerMode = PipePowerIron.PowerMode.M2;
@ -59,8 +53,7 @@ public class TileEngineCreative extends TileEngine {
if (equipped instanceof IToolWrench && ((IToolWrench) equipped).canWrench(player, xCoord, yCoord, zCoord)) {
powerMode = powerMode.getNext();
reconfigure();
mjStored = 0;
energy = 0;
player.addChatMessage(new ChatComponentText(String.format(StringUtils.localize("chat.pipe.power.iron.mode"), powerMode.maxPower)));
@ -79,11 +72,6 @@ public class TileEngineCreative extends TileEngine {
super.readFromNBT(data);
powerMode = PipePowerIron.PowerMode.fromId(data.getByte("mode"));
reconfigure();
}
private void reconfigure() {
MjAPI.reconfigure().maxReceivedPerCycle(mjStoredBattery, powerMode.maxPower);
}
@Override
@ -101,8 +89,9 @@ public class TileEngineCreative extends TileEngine {
@Override
public void engineUpdate() {
super.engineUpdate();
if (isRedstonePowered) {
mjStored = Math.min(mjStored + powerMode.maxPower, mjStoredBattery.maxCapacity());
addEnergy(getCurrentOutput());
}
}
@ -111,9 +100,28 @@ public class TileEngineCreative extends TileEngine {
return isRedstonePowered;
}
@Override
public double maxEnergyReceived() {
return getCurrentOutput();
}
@Override
public double maxEnergyExtracted() {
return getCurrentOutput();
}
@Override
public double getMaxEnergy() {
return getCurrentOutput();
}
@Override
public double getCurrentOutput() {
return powerMode.maxPower / 10.0;
}
@Override
public float explosionRange() {
return 0;
}
}

View file

@ -26,14 +26,11 @@ import net.minecraftforge.fluids.IFluidHandler;
import buildcraft.BuildCraftCore;
import buildcraft.BuildCraftEnergy;
import buildcraft.api.core.NetworkData;
import buildcraft.api.fuels.IronEngineCoolant;
import buildcraft.api.fuels.IronEngineCoolant.Coolant;
import buildcraft.api.fuels.IronEngineFuel;
import buildcraft.api.fuels.IronEngineFuel.Fuel;
import buildcraft.api.gates.ITrigger;
import buildcraft.api.mj.IOMode;
import buildcraft.api.mj.MjBattery;
import buildcraft.core.GuiIds;
import buildcraft.core.IItemPipe;
import buildcraft.core.fluids.FluidUtils;
@ -53,16 +50,12 @@ public class TileEngineIron extends TileEngineWithInventory implements IFluidHan
public Tank tankCoolant = new Tank("tankCoolant", MAX_LIQUID, this);
private int burnTime = 0;
private TankManager<Tank> tankManager = new TankManager<Tank>();
private TankManager tankManager = new TankManager();
private Fuel currentFuel = null;
private int penaltyCooling = 0;
private boolean lastPowered = false;
private BiomeGenBase biomeCache;
@MjBattery(mode = IOMode.SendActive, maxCapacity = 10000, maxSendedPerCycle = 500, minimumConsumption = 0)
@NetworkData
private double mjStored;
public TileEngineIron() {
super(1);
tankManager.add(tankFuel);
@ -180,6 +173,7 @@ public class TileEngineIron extends TileEngineWithInventory implements IFluidHan
return;
}
}
if(!this.constantPower) currentOutput = currentFuel.powerPerCycle;
addEnergy(currentFuel.powerPerCycle);
heat += currentFuel.powerPerCycle * HEAT_PER_MJ * getBiomeTempScalar();
}
@ -334,7 +328,7 @@ public class TileEngineIron extends TileEngineWithInventory implements IFluidHan
@Override
public boolean isActive() {
return currentFuel != null && penaltyCooling <= 0;
return penaltyCooling <= 0;
}
/* ITANKCONTAINER */
@ -364,9 +358,6 @@ public class TileEngineIron extends TileEngineWithInventory implements IFluidHan
@Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
if (resource == null) {
return 0;
}
// Handle coolant
if (IronEngineCoolant.getCoolant(resource) != null) {
@ -411,6 +402,29 @@ public class TileEngineIron extends TileEngineWithInventory implements IFluidHan
return tankCoolant.getFluid();
}
@Override
public double maxEnergyReceived() {
return 2000;
}
@Override
public double maxEnergyExtracted() {
return 500;
}
@Override
public double getMaxEnergy() {
return 10000;
}
@Override
public double getCurrentOutput() {
if (currentFuel == null) {
return 0;
}
return currentFuel.powerPerCycle;
}
@Override
public LinkedList<ITrigger> getTriggers() {
LinkedList<ITrigger> triggers = super.getTriggers();

View file

@ -0,0 +1,82 @@
/**
* 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.energy;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
/**
* This class is just intended to update pre 4.0 engines to the design.
* <p/>
* It can be deleted someday.
*/
public class TileEngineLegacy extends TileEngine {
private NBTTagCompound nbt;
@Override
public void updateEntity() {
worldObj.removeTileEntity(xCoord, yCoord, zCoord);
TileEntity newTile = worldObj.getTileEntity(xCoord, yCoord, zCoord);
if (newTile instanceof TileEngine) {
newTile.readFromNBT(nbt);
sendNetworkUpdate();
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
}
@Override
public void readFromNBT(NBTTagCompound data) {
nbt = (NBTTagCompound) data.copy();
this.xCoord = data.getInteger("x");
this.yCoord = data.getInteger("y");
this.zCoord = data.getInteger("z");
}
@Override
public ResourceLocation getBaseTexture() {
return BASE_TEXTURES[0];
}
@Override
public ResourceLocation getChamberTexture() {
return CHAMBER_TEXTURES[0];
}
@Override
public double getMaxEnergy() {
return 1;
}
@Override
public double maxEnergyReceived() {
return 0;
}
@Override
public float explosionRange() {
return 0;
}
@Override
public boolean isBurning() {
return false;
}
@Override
public double getCurrentOutput() {
return 1;
}
@Override
public double maxEnergyExtracted() {
return 1;
}
}

View file

@ -21,10 +21,7 @@ import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftCore;
import buildcraft.BuildCraftEnergy;
import buildcraft.api.core.NetworkData;
import buildcraft.api.gates.ITrigger;
import buildcraft.api.mj.IOMode;
import buildcraft.api.mj.MjBattery;
import buildcraft.core.GuiIds;
import buildcraft.core.inventory.InvUtils;
import buildcraft.core.utils.MathUtils;
@ -42,19 +39,10 @@ public class TileEngineStone extends TileEngineWithInventory {
int totalBurnTime = 0;
double esum = 0;
@MjBattery(mode = IOMode.SendActive, maxCapacity = 1000, maxSendedPerCycle = 500, minimumConsumption = 0)
@NetworkData
private double mjStored;
public TileEngineStone() {
super(1);
}
@Override
public boolean isActive() {
return isBurning();
}
@Override
public ResourceLocation getBaseTexture() {
return BASE_TEXTURES[1];
@ -88,11 +76,9 @@ public class TileEngineStone extends TileEngineWithInventory {
if (burnTime > 0) {
burnTime--;
double output = TARGET_OUTPUT * mjStoredBattery.maxCapacity() - mjStored;
esum = MathUtils.clamp(esum + output, -eLimit, eLimit);
addEnergy(MathUtils.clamp(output * kp + esum * ki, MIN_OUTPUT, MAX_OUTPUT));
} else {
totalBurnTime = 0;
double output = getCurrentOutput();
if(!constantPower) currentOutput = output; // Comment out for constant power
addEnergy(output);
}
if (burnTime == 0 && isRedstonePowered) {
@ -151,6 +137,28 @@ public class TileEngineStone extends TileEngineWithInventory {
iCrafting.sendProgressBarUpdate(containerEngine, 16, totalBurnTime);
}
@Override
public double maxEnergyReceived() {
return 200;
}
@Override
public double maxEnergyExtracted() {
return 100;
}
@Override
public double getMaxEnergy() {
return 1000;
}
@Override
public double getCurrentOutput() {
double e = TARGET_OUTPUT * getMaxEnergy() - energy;
esum = MathUtils.clamp(esum + e, -eLimit, eLimit);
return MathUtils.clamp(e * kp + esum * ki, MIN_OUTPUT, MAX_OUTPUT);
}
@Override
public LinkedList<ITrigger> getTriggers() {
LinkedList<ITrigger> triggers = super.getTriggers();

View file

@ -8,19 +8,16 @@
*/
package buildcraft.energy;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.core.NetworkData;
import buildcraft.api.mj.IOMode;
import buildcraft.api.mj.MjBattery;
import buildcraft.api.power.PowerHandler;
import buildcraft.api.transport.IPipeTile.PipeType;
import buildcraft.transport.TileGenericPipe;
public class TileEngineWood extends TileEngine {
@MjBattery(mode = IOMode.SendActive, maxCapacity = 100, maxSendedPerCycle = 1, minimumConsumption = 0)
@NetworkData
private double mjStored;
public static final float OUTPUT = 0.1F;
@Override
public ResourceLocation getBaseTexture() {
@ -37,6 +34,16 @@ public class TileEngineWood extends TileEngine {
return 1;
}
@Override
public double minEnergyReceived() {
return 0;
}
@Override
public double maxEnergyReceived() {
return 50;
}
@Override
protected EnergyStage computeEnergyStage() {
double energyLevel = getEnergyLevel();
@ -73,8 +80,10 @@ public class TileEngineWood extends TileEngine {
public void engineUpdate() {
super.engineUpdate();
if (isRedstonePowered && worldObj.getTotalWorldTime() % 16 == 0) {
addEnergy(1);
if (isRedstonePowered) {
if (worldObj.getTotalWorldTime() % 16 == 0) {
addEnergy(1);
}
}
}
@ -87,4 +96,34 @@ public class TileEngineWood extends TileEngine {
public boolean isBurning() {
return isRedstonePowered;
}
@Override
public double getMaxEnergy() {
return 100;
}
@Override
public double getCurrentOutput() {
return OUTPUT;
}
@Override
public double maxEnergyExtracted() {
return 1 + PowerHandler.PerditionCalculator.MIN_POWERLOSS;
}
// TODO: HACK
@Override
public boolean canConnectEnergy(ForgeDirection from) {
return false;
}
@Override
protected void sendPower() {
TileEntity tile = getTileBuffer(orientation).getTile();
if(tile instanceof TileGenericPipe && ((TileGenericPipe)tile).getPipeType() != PipeType.POWER)
super.sendPower();
else // pretend we're sending out our powers
this.energy = 0.0;
}
}

View file

@ -52,9 +52,9 @@ public abstract class GuiEngine extends GuiBuildCraft {
fontRendererObj.drawStringWithShadow(StringUtils.localize("gui.energy"), x + 22, y + 8, headerColour);
fontRendererObj.drawStringWithShadow(StringUtils.localize("gui.currentOutput") + ":", x + 22, y + 20, subheaderColour);
fontRendererObj.drawString(String.format("%.1f MJ/t", engine.getCurrentOutputAverage()), x + 22, y + 32, textColour);
fontRendererObj.drawString(String.format("%d RF/t", (int)Math.round(engine.getCurrentOutput() * 10)), x + 22, y + 32, textColour);
fontRendererObj.drawStringWithShadow(StringUtils.localize("gui.stored") + ":", x + 22, y + 44, subheaderColour);
fontRendererObj.drawString(String.format("%.1f MJ", engine.getEnergyStored()), x + 22, y + 56, textColour);
fontRendererObj.drawString(String.format("%d RF", (int)Math.round(engine.getEnergyStored() * 10)), x + 22, y + 56, textColour);
fontRendererObj.drawStringWithShadow(StringUtils.localize("gui.heat") + ":", x + 22, y + 68, subheaderColour);
fontRendererObj.drawString(String.format("%.2f \u00B0C", engine.getHeat()), x + 22, y + 80, textColour);
@ -62,7 +62,7 @@ public abstract class GuiEngine extends GuiBuildCraft {
@Override
public String getTooltip() {
return String.format("%.1f MJ/t", engine.getCurrentOutputAverage());
return String.format("%d RF/t", (int)Math.round(engine.getCurrentOutput() * 10));
}
}

View file

@ -14,14 +14,12 @@ import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftCore;
import buildcraft.BuildCraftFactory;
import buildcraft.api.gates.IAction;
import buildcraft.api.mj.MjBattery;
import buildcraft.core.IMachine;
import buildcraft.core.RFBattery;
import buildcraft.core.TileBuildCraft;
import buildcraft.core.utils.BlockUtil;
import buildcraft.core.utils.Utils;
@ -30,8 +28,10 @@ public class TileMiningWell extends TileBuildCraft implements IMachine {
boolean isDigging = true;
@MjBattery(maxCapacity = 1000, maxReceivedPerCycle = BuildCraftFactory.MINING_MJ_COST_PER_BLOCK, minimumConsumption = 1)
private double mjStored = 0;
public TileMiningWell() {
super();
this.setBattery(new RFBattery(10000, BuildCraftFactory.MINING_RF_COST_PER_BLOCK, 0));
}
/**
* Dig the next available piece of land if not done. As soon as it reaches
@ -43,12 +43,10 @@ public class TileMiningWell extends TileBuildCraft implements IMachine {
return;
}
float mj = BuildCraftFactory.MINING_MJ_COST_PER_BLOCK * BuildCraftFactory.miningMultiplier;
int miningCost = (int)Math.ceil(BuildCraftFactory.MINING_RF_COST_PER_BLOCK * BuildCraftFactory.miningMultiplier);
if (mjStored < mj) {
if (getBattery().useEnergy(miningCost, miningCost, false) == 0) {
return;
} else {
mjStored -= mj;
}
World world = worldObj;

View file

@ -16,12 +16,10 @@ import java.util.Set;
import java.util.TreeMap;
import io.netty.buffer.ByteBuf;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
@ -29,16 +27,15 @@ import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import buildcraft.BuildCraftCore;
import buildcraft.BuildCraftFactory;
import buildcraft.api.core.BlockIndex;
import buildcraft.api.core.SafeTimeTracker;
import buildcraft.api.gates.IAction;
import buildcraft.api.mj.MjBattery;
import buildcraft.core.CoreConstants;
import buildcraft.core.EntityBlock;
import buildcraft.core.IMachine;
import buildcraft.core.RFBattery;
import buildcraft.core.TileBuffer;
import buildcraft.core.TileBuildCraft;
import buildcraft.core.fluids.FluidUtils;
@ -66,8 +63,10 @@ public class TilePump extends TileBuildCraft implements IMachine, IFluidHandler
private int numFluidBlocksFound = 0;
private boolean powered = false;
@MjBattery(maxCapacity = 100, maxReceivedPerCycle = 15, minimumConsumption = 1)
private double mjStored = 0;
public TilePump() {
super();
this.setBattery(new RFBattery(1000, 150, 0));
}
@Override
public void updateEntity() {
@ -112,9 +111,7 @@ public class TilePump extends TileBuildCraft implements IMachine, IFluidHandler
FluidStack fluidToPump = index != null ? BlockUtil.drainBlock(worldObj, index.x, index.y, index.z, false) : null;
if (fluidToPump != null) {
if (isFluidAllowed(fluidToPump.getFluid()) && tank.fill(fluidToPump, false) == fluidToPump.amount) {
if (mjStored > 10) {
mjStored -= 10;
if (getBattery().useEnergy(100, 100, false) > 0) {
if (fluidToPump.getFluid() != FluidRegistry.WATER || BuildCraftCore.consumeWaterSources || numFluidBlocksFound < 9) {
index = getNextIndexToPump(true);
BlockUtil.drainBlock(worldObj, index.x, index.y, index.z, true);
@ -355,8 +352,6 @@ public class TilePump extends TileBuildCraft implements IMachine, IFluidHandler
aimY = data.getInteger("aimY");
tubeY = data.getFloat("tubeY");
mjStored = data.getDouble("mjStored");
}
@Override
@ -374,8 +369,6 @@ public class TilePump extends TileBuildCraft implements IMachine, IFluidHandler
} else {
data.setFloat("tubeY", yCoord);
}
data.setDouble("mjStored", mjStored);
}
@Override

View file

@ -165,14 +165,6 @@ public class TileQuarry extends TileAbstractBuilder implements IMachine {
return;
}
double energyToUse = 2 + mjStored / 500;
if (mjStored > energyToUse) {
mjStored -= energyToUse;
speed = 0.1 + energyToUse / 200F;
moveHead(speed);
}
if (stage == Stage.BUILDING) {
if (builder != null && !builder.isDone(this)) {
if (buildTracker.markTimeIfDelay(worldObj)) {
@ -183,6 +175,13 @@ public class TileQuarry extends TileAbstractBuilder implements IMachine {
}
} else if (stage == Stage.IDLE) {
dig();
} else if (stage == Stage.DIGGING) {
int energyToUse = 20 + (int)Math.round(getBattery().getEnergyStored() / 500);
if (this.consumeEnergy(energyToUse)) {
speed = 0.1 + energyToUse / 200F;
moveHead(speed);
}
}
createUtilsIfNeeded();
@ -193,12 +192,10 @@ public class TileQuarry extends TileAbstractBuilder implements IMachine {
}
protected void dig() {
float mj = BuildCraftFactory.MINING_MJ_COST_PER_BLOCK * BuildCraftFactory.miningMultiplier;
int rf = (int)Math.ceil(BuildCraftFactory.MINING_RF_COST_PER_BLOCK * BuildCraftFactory.miningMultiplier);
if (mjStored < mj) {
if (!consumeEnergy(rf)) {
return;
} else {
mjStored -= mj;
}
if (!findTarget(true)) {

View file

@ -11,14 +11,12 @@ package buildcraft.factory;
import java.io.IOException;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
@ -26,16 +24,15 @@ import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import buildcraft.BuildCraftCore;
import buildcraft.api.core.NetworkData;
import buildcraft.api.core.SafeTimeTracker;
import buildcraft.api.gates.IAction;
import buildcraft.api.mj.MjBattery;
import buildcraft.api.recipes.CraftingResult;
import buildcraft.api.recipes.IFlexibleCrafter;
import buildcraft.api.recipes.IFlexibleRecipe;
import buildcraft.core.IMachine;
import buildcraft.core.RFBattery;
import buildcraft.core.TileBuildCraft;
import buildcraft.core.fluids.SingleUseTank;
import buildcraft.core.fluids.TankManager;
@ -65,8 +62,10 @@ public class TileRefinery extends TileBuildCraft implements IFluidHandler, IInve
@NetworkData
private String currentRecipeId = "";
@MjBattery(maxCapacity = 1000, maxReceivedPerCycle = 150, minimumConsumption = 1)
private double mjStored = 0;
public TileRefinery() {
super();
this.setBattery(new RFBattery(10000, 1500, 0));
}
@Override
public int getSizeInventory() {
@ -137,7 +136,7 @@ public class TileRefinery extends TileBuildCraft implements IFluidHandler, IInve
isActive = true;
if (mjStored >= craftingResult.energyCost) {
if (getBattery().getEnergyStored() >= craftingResult.energyCost) {
increaseAnimation();
} else {
decreaseAnimation();
@ -147,8 +146,7 @@ public class TileRefinery extends TileBuildCraft implements IFluidHandler, IInve
return;
}
if (mjStored >= craftingResult.energyCost) {
mjStored -= craftingResult.energyCost;
if (getBattery().useEnergy(craftingResult.energyCost, craftingResult.energyCost, false) > 0) {
CraftingResult<FluidStack> r = currentRecipe.craft(this, false);
result.fill(r.crafted.copy(), true);
}
@ -203,8 +201,6 @@ public class TileRefinery extends TileBuildCraft implements IFluidHandler, IInve
animationStage = data.getInteger("animationStage");
animationSpeed = data.getFloat("animationSpeed");
mjStored = data.getDouble("mjStored");
updateRecipe();
}
@ -216,8 +212,6 @@ public class TileRefinery extends TileBuildCraft implements IFluidHandler, IInve
data.setInteger("animationStage", animationStage);
data.setFloat("animationSpeed", animationSpeed);
data.setDouble("mjStored", mjStored);
}
public int getAnimationStage() {

View file

@ -57,7 +57,7 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn
private static final int[] SLOTS = Utils.createSlotArray(0, 24);
private static final EnumSet<ForgeDirection> SEARCH_SIDES = EnumSet.of(ForgeDirection.DOWN, ForgeDirection.NORTH, ForgeDirection.SOUTH,
ForgeDirection.EAST, ForgeDirection.WEST);
private static final float REQUIRED_POWER = 500F;
private static final int REQUIRED_POWER = 5000;
private final CraftingGrid craftingSlots;
private final InventoryMapper invInput;
private final InventoryMapper invOutput;
@ -212,8 +212,8 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn
}
@Override
public double getRequiredEnergy() {
return craftResult.getStackInSlot(0) != null ? REQUIRED_POWER : 0f;
public int getRequiredEnergy() {
return craftResult.getStackInSlot(0) != null ? REQUIRED_POWER : 0;
}
@Override

View file

@ -209,7 +209,7 @@ public class TileAssemblyTable extends TileLaserTableBase implements IMachine, I
}
@Override
public double getRequiredEnergy() {
public int getRequiredEnergy() {
if (currentRecipe != null) {
CraftingResult<ItemStack> result = currentRecipe.craft(this, true);

View file

@ -124,7 +124,7 @@ public class TileIntegrationTable extends TileLaserTableBase implements IFlexibl
}
@Override
public double getRequiredEnergy() {
public int getRequiredEnergy() {
if (craftingPreview != null) {
return craftingPreview.energyCost;
} else {

View file

@ -15,21 +15,19 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftCore;
import buildcraft.api.core.NetworkData;
import buildcraft.api.core.Position;
import buildcraft.api.core.SafeTimeTracker;
import buildcraft.api.gates.IAction;
import buildcraft.api.gates.IActionReceptor;
import buildcraft.api.mj.MjBattery;
import buildcraft.api.power.ILaserTarget;
import buildcraft.core.Box;
import buildcraft.core.EntityLaser;
import buildcraft.core.IMachine;
import buildcraft.core.LaserData;
import buildcraft.core.RFBattery;
import buildcraft.core.TileBuildCraft;
import buildcraft.core.triggers.ActionMachineControl;
@ -48,13 +46,14 @@ public class TileLaser extends TileBuildCraft implements IActionReceptor, IMachi
private ActionMachineControl.Mode lastMode = ActionMachineControl.Mode.Unknown;
private int powerIndex = 0;
@MjBattery(maxCapacity = 1000, maxReceivedPerCycle = 25, minimumConsumption = 1)
private double mjStored = 0;
@NetworkData
private double powerAverage = 0;
private final double[] power = new double[POWER_AVERAGING];
public TileLaser() {
super();
this.setBattery(new RFBattery(10000, 250, 0));
}
@Override
public void initialize() {
super.initialize();
@ -97,7 +96,7 @@ public class TileLaser extends TileBuildCraft implements IActionReceptor, IMachi
}
// Disable the laser and do nothing if no energy is available.
if (mjStored == 0) {
if (getBattery().getEnergyStored() == 0) {
removeLaser();
return;
}
@ -112,8 +111,7 @@ public class TileLaser extends TileBuildCraft implements IActionReceptor, IMachi
}
// Consume power and transfer it to the table.
double localPower = mjStored > getMaxPowerSent() ? getMaxPowerSent() : mjStored;
mjStored -= localPower;
int localPower = getBattery().useEnergy(0, getMaxPowerSent(), false);
laserTarget.receiveLaserEnergy(localPower);
if (laser != null) {
@ -125,8 +123,8 @@ public class TileLaser extends TileBuildCraft implements IActionReceptor, IMachi
sendNetworkUpdate();
}
protected float getMaxPowerSent() {
return 4;
protected int getMaxPowerSent() {
return 40;
}
protected void onPowerSent(double power) {
@ -264,15 +262,11 @@ public class TileLaser extends TileBuildCraft implements IActionReceptor, IMachi
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
mjStored = nbttagcompound.getDouble("mjStored");
}
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound);
nbttagcompound.setDouble("mjStored", mjStored);
}
@Override

View file

@ -27,10 +27,10 @@ import buildcraft.core.utils.AverageUtil;
public abstract class TileLaserTableBase extends TileBuildCraft implements ILaserTarget, IInventory, IActionReceptor, IMachine {
public double clientRequiredEnergy = 0;
public int clientRequiredEnergy = 0;
protected SimpleInventory inv = new SimpleInventory(getSizeInventory(), "inv", 64);
protected ActionMachineControl.Mode lastMode = ActionMachineControl.Mode.Unknown;
private double energy = 0;
private int energy = 0;
private int recentEnergyAverage;
private AverageUtil recentEnergyAverageUtil = new AverageUtil(20);
@ -40,26 +40,26 @@ public abstract class TileLaserTableBase extends TileBuildCraft implements ILase
recentEnergyAverageUtil.tick();
}
public double getEnergy() {
public int getEnergy() {
return energy;
}
public void setEnergy(double energy) {
public void setEnergy(int energy) {
this.energy = energy;
}
public void addEnergy(double energy) {
public void addEnergy(int energy) {
this.energy += energy;
}
public void subtractEnergy(double energy) {
public void subtractEnergy(int energy) {
this.energy -= energy;
}
public abstract double getRequiredEnergy();
public abstract int getRequiredEnergy();
public int getProgressScaled(int ratio) {
if (clientRequiredEnergy == 0.0) {
if (clientRequiredEnergy == 0) {
return 0;
} else if (energy >= clientRequiredEnergy) {
return ratio;
@ -80,7 +80,7 @@ public abstract class TileLaserTableBase extends TileBuildCraft implements ILase
}
@Override
public void receiveLaserEnergy(double energy) {
public void receiveLaserEnergy(int energy) {
this.energy += energy;
recentEnergyAverageUtil.push(energy);
}
@ -147,36 +147,36 @@ public abstract class TileLaserTableBase extends TileBuildCraft implements ILase
public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt);
inv.writeToNBT(nbt, "inv");
nbt.setDouble("energy", energy);
nbt.setInteger("energy", energy);
}
@Override
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
inv.readFromNBT(nbt, "inv");
energy = nbt.getDouble("energy");
energy = nbt.getInteger("energy");
}
public void getGUINetworkData(int id, int data) {
int currentStored = (int) (energy * 100.0);
int requiredEnergy = (int) (clientRequiredEnergy * 100.0);
int currentStored = energy;
int requiredEnergy = clientRequiredEnergy;
switch (id) {
case 0:
requiredEnergy = (requiredEnergy & 0xFFFF0000) | (data & 0xFFFF);
clientRequiredEnergy = requiredEnergy / 100.0f;
clientRequiredEnergy = requiredEnergy;
break;
case 1:
currentStored = (currentStored & 0xFFFF0000) | (data & 0xFFFF);
energy = currentStored / 100.0f;
energy = currentStored;
break;
case 2:
requiredEnergy = (requiredEnergy & 0xFFFF) | ((data & 0xFFFF) << 16);
clientRequiredEnergy = requiredEnergy / 100.0f;
clientRequiredEnergy = requiredEnergy;
break;
case 3:
currentStored = (currentStored & 0xFFFF) | ((data & 0xFFFF) << 16);
energy = currentStored / 100.0f;
energy = currentStored;
break;
case 4:
recentEnergyAverage = recentEnergyAverage & 0xFFFF0000 | (data & 0xFFFF);
@ -188,8 +188,8 @@ public abstract class TileLaserTableBase extends TileBuildCraft implements ILase
}
public void sendGUINetworkData(Container container, ICrafting iCrafting) {
int requiredEnergy = (int) (getRequiredEnergy() * 100.0);
int currentStored = (int) (energy * 100.0);
int requiredEnergy = getRequiredEnergy();
int currentStored = energy;
int lRecentEnergy = (int) (recentEnergyAverageUtil.getAverage() * 100f);
iCrafting.sendProgressBarUpdate(container, 0, requiredEnergy & 0xFFFF);
iCrafting.sendProgressBarUpdate(container, 1, currentStored & 0xFFFF);

View file

@ -59,17 +59,17 @@ public class GuiAssemblyTable extends GuiAdvancedInterface {
fontRendererObj.drawStringWithShadow(StringUtils.localize("gui.energy"), x + 22, y + 8, headerColour);
fontRendererObj.drawStringWithShadow(StringUtils.localize("gui.assemblyCurrentRequired") + ":", x + 22, y + 20, subheaderColour);
fontRendererObj.drawString(String.format("%2.1f MJ", table.clientRequiredEnergy), x + 22, y + 32, textColour);
fontRendererObj.drawString(String.format("%d RF", table.clientRequiredEnergy), x + 22, y + 32, textColour);
fontRendererObj.drawStringWithShadow(StringUtils.localize("gui.stored") + ":", x + 22, y + 44, subheaderColour);
fontRendererObj.drawString(String.format("%2.1f MJ", table.getEnergy()), x + 22, y + 56, textColour);
fontRendererObj.drawString(String.format("%d RF", table.getEnergy()), x + 22, y + 56, textColour);
fontRendererObj.drawStringWithShadow(StringUtils.localize("gui.assemblyRate") + ":", x + 22, y + 68, subheaderColour);
fontRendererObj.drawString(String.format("%3.2f MJ/t", table.getRecentEnergyAverage() / 100.0f), x + 22, y + 80, textColour);
fontRendererObj.drawString(String.format("%.1f RF/t", table.getRecentEnergyAverage() / 100.0f), x + 22, y + 80, textColour);
}
@Override
public String getTooltip() {
return String.format("%3.2f MJ/t", table.getRecentEnergyAverage() / 100.0f);
return String.format("%.1f RF/t", table.getRecentEnergyAverage() / 100.0f);
}
}
private final TileAssemblyTable table;

View file

@ -50,17 +50,17 @@ public abstract class GuiLaserTable extends GuiBuildCraft {
fontRendererObj.drawStringWithShadow(StringUtils.localize("gui.energy"), x + 22, y + 8, headerColour);
fontRendererObj.drawStringWithShadow(StringUtils.localize("gui.assemblyCurrentRequired") + ":", x + 22, y + 20, subheaderColour);
fontRendererObj.drawString(String.format("%2.1f MJ", table.clientRequiredEnergy), x + 22, y + 32, textColour);
fontRendererObj.drawString(String.format("%d RF", table.clientRequiredEnergy), x + 22, y + 32, textColour);
fontRendererObj.drawStringWithShadow(StringUtils.localize("gui.stored") + ":", x + 22, y + 44, subheaderColour);
fontRendererObj.drawString(String.format("%2.1f MJ", table.getEnergy()), x + 22, y + 56, textColour);
fontRendererObj.drawString(String.format("%d RF", table.getEnergy()), x + 22, y + 56, textColour);
fontRendererObj.drawStringWithShadow(StringUtils.localize("gui.assemblyRate") + ":", x + 22, y + 68, subheaderColour);
fontRendererObj.drawString(String.format("%3.2f MJ/t", table.getRecentEnergyAverage() / 100.0f), x + 22, y + 80, textColour);
fontRendererObj.drawString(String.format("%.1f RF/t", table.getRecentEnergyAverage() / 100.0f), x + 22, y + 80, textColour);
}
@Override
public String getTooltip() {
return String.format("%3.2f MJ/t", table.getRecentEnergyAverage() / 100.0f);
return String.format("%.1f RF/t", table.getRecentEnergyAverage() / 100.0f);
}
}
protected final TileLaserTableBase table;

View file

@ -24,7 +24,7 @@ import buildcraft.transport.ItemPipeWire;
public class AdvancedFacadeRecipe extends IntegrationTableRecipe {
public AdvancedFacadeRecipe(String id) {
setContents(id, new ItemFacade(), 5000, 0,
setContents(id, new ItemFacade(), 50000, 0,
new ItemStack(BuildCraftTransport.pipeWire, 1, OreDictionary.WILDCARD_VALUE),
ItemRedstoneChipset.Chipset.RED.getStack());
}
@ -74,14 +74,14 @@ public class AdvancedFacadeRecipe extends IntegrationTableRecipe {
if (states[i].wire == wire) {
states[i] = additionalState;
result.energyCost = 2000;
result.energyCost = 20000;
result.crafted = ItemFacade.getFacade(states);
return result;
}
}
result.energyCost = 5000;
result.energyCost = 50000;
result.crafted = ItemFacade.getFacade(JavaTools.concat(states,
new ItemFacade.FacadeState[] {additionalState}));

View file

@ -26,7 +26,7 @@ public class GateExpansionRecipe extends IntegrationTableRecipe {
this.expansion = expansion;
this.chipset = chipset.copy();
setContents(id, BuildCraftTransport.pipeGate, 10000, 0);
setContents(id, BuildCraftTransport.pipeGate, 100000, 0);
}
@Override

View file

@ -22,7 +22,7 @@ import buildcraft.transport.gates.ItemGate;
public class GateLogicSwapRecipe extends IntegrationTableRecipe {
public GateLogicSwapRecipe(String id) {
setContents(id, BuildCraftTransport.pipeGate, 2000, 0);
setContents(id, BuildCraftTransport.pipeGate, 20000, 0);
}
@Override

View file

@ -783,7 +783,7 @@ public class BlockGenericPipe extends BlockBuildCraft {
EntityRobot robot = ((ItemRobot) currentItem.getItem())
.createRobot(currentItem, world);
robot.setUniqueRobotId(robot.getRegistry().getNextRobotId());
robot.setEnergy(EntityRobot.MAX_ENERGY);
robot.getBattery().setEnergy(EntityRobot.MAX_ENERGY);
float px = x + 0.5F + rayTraceResult.sideHit.offsetX * 0.5F;
float py = y + 0.5F + rayTraceResult.sideHit.offsetY * 0.5F;

View file

@ -17,10 +17,10 @@ public interface IPipeTransportPowerHook {
*
* @return The amount of power used, or -1 for default behavior.
*/
double receiveEnergy(ForgeDirection from, double val);
int receiveEnergy(ForgeDirection from, int val);
/**
* Override default requested power.
*/
double requestEnergy(ForgeDirection from, double amount);
int requestEnergy(ForgeDirection from, int amount);
}

View file

@ -22,6 +22,7 @@ import buildcraft.transport.pipes.PipeItemsObsidian;
import buildcraft.transport.pipes.PipeItemsQuartz;
import buildcraft.transport.pipes.PipeItemsStone;
import buildcraft.transport.pipes.PipeItemsWood;
import buildcraft.transport.pipes.PipePowerEmerald;
import buildcraft.transport.pipes.PipePowerWood;
/**
@ -49,6 +50,7 @@ public final class PipeConnectionBans {
// Power Pipes
banConnection(PipePowerWood.class);
banConnection(PipePowerEmerald.class);
}
private PipeConnectionBans() {

View file

@ -104,6 +104,7 @@ public class PipeIconProvider implements IIconProvider {
PipePowerStone("pipePowerStone"),
PipePowerCobblestone("pipePowerCobblestone"),
PipePowerWood_Standard("pipePowerWood_standard"),
PipePowerEmerald_Standard("pipePowerEmerald_standard"),
//
PipePowerIronM2("pipePowerIronM2"),
PipePowerIronM4("pipePowerIronM4"),

View file

@ -12,17 +12,14 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import cofh.api.energy.IEnergyHandler;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftCore;
import buildcraft.BuildCraftTransport;
import buildcraft.api.core.SafeTimeTracker;
import buildcraft.api.gates.ITrigger;
import buildcraft.api.mj.IBatteryObject;
import buildcraft.api.mj.MjAPI;
import buildcraft.api.power.IPowerEmitter;
import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerHandler.PowerReceiver;
@ -32,6 +29,7 @@ import buildcraft.core.DefaultProps;
import buildcraft.transport.network.PacketPowerUpdate;
import buildcraft.transport.pipes.PipePowerCobblestone;
import buildcraft.transport.pipes.PipePowerDiamond;
import buildcraft.transport.pipes.PipePowerEmerald;
import buildcraft.transport.pipes.PipePowerGold;
import buildcraft.transport.pipes.PipePowerIron;
import buildcraft.transport.pipes.PipePowerQuartz;
@ -42,30 +40,28 @@ public class PipeTransportPower extends PipeTransport {
public static final Map<Class<? extends Pipe<?>>, Integer> powerCapacities = new HashMap<Class<? extends Pipe<?>>, Integer>();
private static final short MAX_DISPLAY = 100;
private static final int DISPLAY_SMOOTHING = 10;
private static final int OVERLOAD_TICKS = 60;
public float[] displayPower = new float[6];
public short[] clientDisplayPower = new short[6];
public short[] displayPower = new short[6];
public int overload;
public double[] nextPowerQuery = new double[6];
public double[] internalNextPower = new double[6];
public double maxPower = 8;
public int[] nextPowerQuery = new int[6];
public int[] internalNextPower = new int[6];
public int maxPower = 80;
public float[] movementStage = new float[] {0, 0, 0};
private boolean needsInit = true;
private TileEntity[] tiles = new TileEntity[6];
private float[] prevDisplayPower = new float[6];
private short[] prevDisplayPower = new short[6];
private double[] powerQuery = new double[6];
private int[] powerQuery = new int[6];
private long currentDate;
private double[] internalPower = new double[6];
private double[] externalPower = new double[6];
private int[] internalPower = new int[6];
private int[] externalPower = new int[6];
private double highestPower;
private int highestPower;
private SafeTimeTracker tracker = new SafeTimeTracker(2 * BuildCraftCore.updateFactor);
public PipeTransportPower() {
@ -105,6 +101,13 @@ public class PipeTransportPower extends PipeTransport {
}
}
if (tile instanceof IEnergyHandler) {
IEnergyHandler handler = (IEnergyHandler)tile;
if (handler != null && handler.canConnectEnergy(side.getOpposite())) {
return true;
}
}
if (container.pipe instanceof PipePowerWood && tile instanceof IPowerEmitter) {
IPowerEmitter emitter = (IPowerEmitter) tile;
if (emitter.canEmitPowerFrom(side.getOpposite())) {
@ -112,10 +115,6 @@ public class PipeTransportPower extends PipeTransport {
}
}
if (MjAPI.canReceive(MjAPI.getMjBattery(tile, MjAPI.DEFAULT_POWER_FRAMEWORK, side.getOpposite()))) {
return true;
}
return false;
}
@ -166,18 +165,18 @@ public class PipeTransportPower extends PipeTransport {
// Send the power to nearby pipes who requested it
System.arraycopy(displayPower, 0, prevDisplayPower, 0, 6);
Arrays.fill(displayPower, 0.0F);
Arrays.fill(displayPower, (short)0);
// STEP 1 - computes the total amount of power contained and total
// amount of power queried
double totalPowerContained = 0;
int totalPowerContained = 0;
for (int in = 0; in < 6; ++in) {
totalPowerContained += internalPower[in];
}
double totalPowerQuery = 0;
int totalPowerQuery = 0;
for (int out = 0; out < 6; ++out) {
if (internalPower[out] == 0) {
@ -188,14 +187,14 @@ public class PipeTransportPower extends PipeTransport {
// STEP 2 - sends the power to all directions and computes the actual
// amount of power that was consumed
double totalPowerConsumed = 0;
int totalPowerConsumed = 0;
if (totalPowerContained > 0) {
for (int out = 0; out < 6; ++out) {
externalPower[out] = 0;
if (powerQuery[out] > 0 && internalPower[out] == 0) {
double powerConsumed = powerQuery[out] / totalPowerQuery * totalPowerContained;
int powerConsumed = (int)Math.floor((double)(powerQuery[out] * totalPowerContained) / totalPowerQuery);
boolean tilePowered = false;
if (tiles[out] instanceof TileGenericPipe) {
@ -207,24 +206,25 @@ public class PipeTransportPower extends PipeTransport {
ForgeDirection.VALID_DIRECTIONS[out].getOpposite(),
powerConsumed);
tilePowered = true;
} else {
IBatteryObject battery = MjAPI.getMjBattery(tiles[out], MjAPI.DEFAULT_POWER_FRAMEWORK,
ForgeDirection.VALID_DIRECTIONS[out].getOpposite());
} else if (tiles[out] instanceof IEnergyHandler) {
IEnergyHandler handler = (IEnergyHandler)tiles[out];
if (battery != null) {
// Transmit power to the simplified power framework
powerConsumed = battery.addEnergy(powerConsumed);
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 {
PowerReceiver prov = getReceiverOnSide(ForgeDirection.VALID_DIRECTIONS[out]);
}
} else {
PowerReceiver prov = getReceiverOnSide(ForgeDirection.VALID_DIRECTIONS[out]);
if (prov != null) {
// Transmit power to the legacy power framework
if (prov != null) {
// Transmit power to the legacy power framework
powerConsumed = prov.receiveEnergy(Type.PIPE, powerConsumed,
ForgeDirection.VALID_DIRECTIONS[out].getOpposite());
tilePowered = true;
}
powerConsumed = (int)Math.ceil(prov.receiveEnergy(Type.PIPE, (double)powerConsumed / 10.0,
ForgeDirection.VALID_DIRECTIONS[out].getOpposite()) * 10);
tilePowered = true;
}
}
@ -243,7 +243,7 @@ public class PipeTransportPower extends PipeTransport {
if (totalPowerConsumed > 0) {
for (int in = 0; in < 6; ++in) {
double powerConsumed = internalPower[in] / totalPowerContained * totalPowerConsumed;
int powerConsumed = (int)Math.floor(internalPower[in] / totalPowerContained * totalPowerConsumed);
displayPower[in] += powerConsumed;
}
}
@ -252,7 +252,7 @@ public class PipeTransportPower extends PipeTransport {
highestPower = 0;
for (int i = 0; i < 6; i++) {
displayPower[i] = (prevDisplayPower[i] * (DISPLAY_SMOOTHING - 1.0F) + displayPower[i]) / DISPLAY_SMOOTHING;
displayPower[i] = (short)((prevDisplayPower[i] * (DISPLAY_SMOOTHING - 1.0F) + displayPower[i]) / DISPLAY_SMOOTHING);
if (displayPower[i] > highestPower) {
highestPower = displayPower[i];
@ -275,22 +275,22 @@ public class PipeTransportPower extends PipeTransport {
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
TileEntity tile = tiles [dir.ordinal()];
if (!(tile instanceof TileGenericPipe && ((TileGenericPipe) tile).pipe.transport instanceof PipeTransportPower)) {
PowerReceiver prov = getReceiverOnSide(dir);
if (prov != null) {
double request = prov.powerRequest();
if (tile instanceof IEnergyHandler) {
IEnergyHandler handler = (IEnergyHandler)tile;
if(handler.canConnectEnergy(dir.getOpposite())) {
int request = handler.receiveEnergy(dir.getOpposite(), this.maxPower, true);
if (request > 0) {
requestEnergy(dir, request);
}
}
} else if (!(tile instanceof TileGenericPipe && ((TileGenericPipe) tile).pipe.transport instanceof PipeTransportPower)) {
PowerReceiver prov = getReceiverOnSide(dir);
if (prov != null) {
int request = (int)Math.floor(prov.powerRequest() * 10);
if (tile != null) {
IBatteryObject battery = MjAPI.getMjBattery(tile, MjAPI.DEFAULT_POWER_FRAMEWORK, dir.getOpposite());
if (battery != null) {
requestEnergy(dir, battery.getEnergyRequested());
if (request > 0) {
requestEnergy(dir, request);
}
}
}
@ -298,7 +298,7 @@ public class PipeTransportPower extends PipeTransport {
// Sum the amount of energy requested on each side
double[] transferQuery = new double[6];
int[] transferQuery = new int[6];
for (int i = 0; i < 6; ++i) {
transferQuery[i] = 0;
@ -336,12 +336,7 @@ public class PipeTransportPower extends PipeTransport {
if (tracker.markTimeIfDelay(container.getWorldObj())) {
PacketPowerUpdate packet = new PacketPowerUpdate(container.xCoord, container.yCoord, container.zCoord);
double displayFactor = MAX_DISPLAY / 1024.0;
for (int i = 0; i < clientDisplayPower.length; i++) {
clientDisplayPower[i] = (short) (Math.ceil(displayPower[i] * displayFactor));
}
packet.displayPower = clientDisplayPower;
packet.displayPower = displayPower;
packet.overload = isOverloaded();
BuildCraftTransport.instance.sendToPlayers(packet, container.getWorldObj(), container.xCoord, container.yCoord, container.zCoord, DefaultProps.PIPE_CONTENTS_RENDER_DIST);
}
@ -373,10 +368,10 @@ public class PipeTransportPower extends PipeTransport {
currentDate = container.getWorldObj().getTotalWorldTime();
powerQuery = nextPowerQuery;
nextPowerQuery = new double[6];
nextPowerQuery = new int[6];
internalPower = internalNextPower;
internalNextPower = new double[6];
internalNextPower = new int[6];
for (int i = 0; i < internalNextPower.length; ++i) {
internalNextPower[i] = 0;
@ -390,11 +385,11 @@ public class PipeTransportPower extends PipeTransport {
* All power input MUST go through designated input pipes, such as Wooden
* Power Pipes or a subclass thereof.
*/
public double receiveEnergy(ForgeDirection from, double valI) {
double val = valI;
public int receiveEnergy(ForgeDirection from, int valI) {
int val = valI;
step();
if (this.container.pipe instanceof IPipeTransportPowerHook) {
double ret = ((IPipeTransportPowerHook) this.container.pipe).receiveEnergy(from, val);
int ret = ((IPipeTransportPowerHook) this.container.pipe).receiveEnergy(from, val);
if (ret >= 0) {
return ret;
}
@ -417,7 +412,7 @@ public class PipeTransportPower extends PipeTransport {
return val;
}
public void requestEnergy(ForgeDirection from, double amount) {
public void requestEnergy(ForgeDirection from, int amount) {
step();
if (!container.pipe.isClosed()) {
@ -440,10 +435,10 @@ public class PipeTransportPower extends PipeTransport {
super.readFromNBT(nbttagcompound);
for (int i = 0; i < 6; ++i) {
powerQuery[i] = nbttagcompound.getDouble("powerQuery[" + i + "]");
nextPowerQuery[i] = nbttagcompound.getDouble("nextPowerQuery[" + i + "]");
internalPower[i] = (float) nbttagcompound.getDouble("internalPower[" + i + "]");
internalNextPower[i] = (float) nbttagcompound.getDouble("internalNextPower[" + i + "]");
powerQuery[i] = nbttagcompound.getInteger("powerQuery[" + i + "]");
nextPowerQuery[i] = nbttagcompound.getInteger("nextPowerQuery[" + i + "]");
internalPower[i] = nbttagcompound.getInteger("internalPower[" + i + "]");
internalNextPower[i] = nbttagcompound.getInteger("internalNextPower[" + i + "]");
}
}
@ -453,10 +448,10 @@ public class PipeTransportPower extends PipeTransport {
super.writeToNBT(nbttagcompound);
for (int i = 0; i < 6; ++i) {
nbttagcompound.setDouble("powerQuery[" + i + "]", powerQuery[i]);
nbttagcompound.setDouble("nextPowerQuery[" + i + "]", nextPowerQuery[i]);
nbttagcompound.setDouble("internalPower[" + i + "]", internalPower[i]);
nbttagcompound.setDouble("internalNextPower[" + i + "]", internalNextPower[i]);
nbttagcompound.setInteger("powerQuery[" + i + "]", powerQuery[i]);
nbttagcompound.setInteger("nextPowerQuery[" + i + "]", nextPowerQuery[i]);
nbttagcompound.setInteger("internalPower[" + i + "]", internalPower[i]);
nbttagcompound.setInteger("internalNextPower[" + i + "]", internalNextPower[i]);
}
}
@ -470,34 +465,34 @@ public class PipeTransportPower extends PipeTransport {
* @param packetPower
*/
public void handlePowerPacket(PacketPowerUpdate packetPower) {
clientDisplayPower = packetPower.displayPower;
displayPower = packetPower.displayPower;
overload = packetPower.overload ? OVERLOAD_TICKS : 0;
}
/**
* This can be use to provide a rough estimate of how much power is flowing
* through a pipe. Measured in MJ/t.
* through a pipe. Measured in RF/t.
*
* @return MJ/t
* @return RF/t
*/
public double getCurrentPowerTransferRate() {
public int getCurrentPowerTransferRate() {
return highestPower;
}
/**
* This can be use to provide a rough estimate of how much power is
* contained in a pipe. Measured in MJ.
* contained in a pipe. Measured in RF.
*
* Max should be around (throughput * internalPower.length * 2), ie 112 MJ for a Cobblestone Pipe.
*
* @return MJ
* @return RF
*/
public double getCurrentPowerAmount() {
double amount = 0.0;
for (double d : internalPower) {
public int getCurrentPowerAmount() {
int amount = 0;
for (int d : internalPower) {
amount += d;
}
for (double d : internalNextPower) {
for (int d : internalNextPower) {
amount += d;
}
return amount;
@ -511,8 +506,8 @@ public class PipeTransportPower extends PipeTransport {
}
}
public double clearInstantPower() {
double amount = 0.0;
public int clearInstantPower() {
int amount = 0;
for (int i = 0; i < internalPower.length; ++i) {
amount += internalPower [i];
@ -522,8 +517,8 @@ public class PipeTransportPower extends PipeTransport {
return amount;
}
public double consumePower(ForgeDirection dir, double max) {
double result;
public int consumePower(ForgeDirection dir, int max) {
int result;
if (externalPower[dir.ordinal()] < max) {
result = externalPower[dir.ordinal()];
@ -536,8 +531,8 @@ public class PipeTransportPower extends PipeTransport {
}
public boolean isQueryingPower() {
for (double d : powerQuery) {
if (d > 1e-4) {
for (int d : powerQuery) {
if (d > 0) {
return true;
}
}
@ -546,12 +541,13 @@ public class PipeTransportPower extends PipeTransport {
}
static {
powerCapacities.put(PipePowerCobblestone.class, 8);
powerCapacities.put(PipePowerStone.class, 16);
powerCapacities.put(PipePowerWood.class, 32);
powerCapacities.put(PipePowerQuartz.class, 64);
powerCapacities.put(PipePowerIron.class, 128);
powerCapacities.put(PipePowerGold.class, 256);
powerCapacities.put(PipePowerDiamond.class, 1024);
powerCapacities.put(PipePowerCobblestone.class, 80);
powerCapacities.put(PipePowerStone.class, 160);
powerCapacities.put(PipePowerWood.class, 320);
powerCapacities.put(PipePowerQuartz.class, 640);
powerCapacities.put(PipePowerIron.class, 1280);
powerCapacities.put(PipePowerGold.class, 2560);
powerCapacities.put(PipePowerEmerald.class, 2560);
powerCapacities.put(PipePowerDiamond.class, 10240);
}
}

View file

@ -10,15 +10,14 @@ package buildcraft.transport;
import java.util.LinkedList;
import cofh.api.energy.IEnergyHandler;
import net.minecraft.block.Block;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftCore;
import buildcraft.api.gates.IOverrideDefaultTriggers;
import buildcraft.api.gates.ITrigger;
import buildcraft.api.gates.ITriggerProvider;
import buildcraft.api.mj.IBatteryObject;
import buildcraft.api.mj.MjAPI;
import buildcraft.api.transport.IPipeTile;
import buildcraft.transport.triggers.TriggerPipeContents;
@ -64,9 +63,7 @@ public class PipeTriggerProvider implements ITriggerProvider {
break;
}
IBatteryObject battery = MjAPI.getMjBattery(tile);
if (battery != null && battery.maxCapacity() > 0) {
if (tile instanceof IEnergyHandler && ((IEnergyHandler)tile).getMaxEnergyStored(ForgeDirection.UNKNOWN) > 0) {
result.add(BuildCraftCore.triggerEnergyHigh);
result.add(BuildCraftCore.triggerEnergyLow);
}

Some files were not shown because too many files have changed in this diff Show more