updated bc and ic2 apis -> working power from those two in 1.7; fixed sound in obf'ed mc

This commit is contained in:
Florian Nücke 2014-03-14 06:04:03 +01:00
parent 259aae00c3
commit 415602a604
17 changed files with 175 additions and 290 deletions

View File

@ -1,8 +1,9 @@
/** /**
* Copyright (c) SpaceToad, 2011 http://www.mod-buildcraft.com * 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 * BuildCraft is distributed under the terms of the Minecraft Mod Public
* 1.0, or MMPL. Please check the contents of the license located in * License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt * http://www.mod-buildcraft.com/MMPL-1.0.txt
*/ */
package buildcraft.api.core; package buildcraft.api.core;
@ -13,10 +14,45 @@ public class SafeTimeTracker {
private long lastMark = Long.MIN_VALUE; private long lastMark = Long.MIN_VALUE;
private long duration = -1; private long duration = -1;
private long randomRange = 0;
private long lastRandomDelay = 0;
private long internalDelay = 1;
/**
* @deprecated should use constructors with parameters instead
*/
public SafeTimeTracker () {
}
public SafeTimeTracker (long delay) {
internalDelay = delay;
}
/**
* In many situations, it is a bad idea to have all objects of the same
* kind to be waiting for the exact same amount of time, as that can lead
* to some situation where they're all synchronized and got to work all
* at the same time. When created with a random range, the mark that is set
* when reaching the expect delay will be added with a random number
* between [0, range[, meaning that the event will take between 0 and range
* more tick to run.
*/
public SafeTimeTracker (long delay, long random) {
internalDelay = delay;
randomRange = random;
}
public boolean markTimeIfDelay(World world) {
return markTimeIfDelay(world, internalDelay);
}
/** /**
* Return true if a given delay has passed since last time marked was called * Return true if a given delay has passed since last time marked was called
* successfully. * successfully.
*
* @deprecated should use the constructor with a delay instead, and call
* this function without a parameter
*/ */
public boolean markTimeIfDelay(World world, long delay) { public boolean markTimeIfDelay(World world, long delay) {
if (world == null) if (world == null)
@ -27,13 +63,15 @@ public class SafeTimeTracker {
if (currentTime < lastMark) { if (currentTime < lastMark) {
lastMark = currentTime; lastMark = currentTime;
return false; return false;
} else if (lastMark + delay <= currentTime) { } else if (lastMark + delay + lastRandomDelay <= currentTime) {
duration = currentTime - lastMark; duration = currentTime - lastMark;
lastMark = currentTime; lastMark = currentTime;
return true; lastRandomDelay = (int) (Math.random() * randomRange);
} else
return false;
return true;
} else {
return false;
}
} }
public long durationOfLastDelay() { public long durationOfLastDelay() {

View File

@ -1,5 +1,5 @@
/* /**
* Copyright (c) SpaceToad, 2011-2012 * Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com * http://www.mod-buildcraft.com
* *
* BuildCraft is distributed under the terms of the Minecraft Mod Public * BuildCraft is distributed under the terms of the Minecraft Mod Public
@ -8,15 +8,13 @@
*/ */
package buildcraft.api.power; package buildcraft.api.power;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
/** /**
* Essentially only used for Wooden Power Pipe connection rules. * Essentially only used for Wooden Power Pipe connection rules.
* *
* This Tile Entity interface allows you to indicate that a block can emit power * This Tile Entity interface allows you to indicate that a block can emit power
* from a specific side. * from a specific side.
*
* @author CovertJaguar <http://www.railcraft.info/>
*/ */
public interface IPowerEmitter { public interface IPowerEmitter {

View File

@ -1,20 +1,19 @@
/** /**
* Copyright (c) SpaceToad, 2011 http://www.mod-buildcraft.com * 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 * BuildCraft is distributed under the terms of the Minecraft Mod Public
* 1.0, or MMPL. Please check the contents of the license located in * License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt * http://www.mod-buildcraft.com/MMPL-1.0.txt
*/ */
package buildcraft.api.power; package buildcraft.api.power;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
/** /**
* This interface should be implemented by any Tile Entity that wishes to be * This interface should be implemented by any Tile Entity that wishes to be
* able to receive power. * able to receive power.
*
* @author CovertJaguar <http://www.railcraft.info/>
*/ */
public interface IPowerReceptor { public interface IPowerReceptor {

View File

@ -1,15 +1,16 @@
/** /**
* Copyright (c) SpaceToad, 2011 http://www.mod-buildcraft.com * 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 * BuildCraft is distributed under the terms of the Minecraft Mod Public
* 1.0, or MMPL. Please check the contents of the license located in * License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt * http://www.mod-buildcraft.com/MMPL-1.0.txt
*/ */
package buildcraft.api.power; package buildcraft.api.power;
import buildcraft.api.core.SafeTimeTracker; import buildcraft.api.core.SafeTimeTracker;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
/** /**
* The PowerHandler is similar to FluidTank in that it holds your power and * The PowerHandler is similar to FluidTank in that it holds your power and
@ -26,8 +27,6 @@ import net.minecraftforge.common.ForgeDirection;
* *
* @see IPowerReceptor * @see IPowerReceptor
* @see IPowerEmitter * @see IPowerEmitter
*
* @author CovertJaguar <http://www.railcraft.info/>
*/ */
public final class PowerHandler { public final class PowerHandler {
@ -65,7 +64,7 @@ public final class PowerHandler {
public static final float DEFAULT_POWERLOSS = 1F; public static final float DEFAULT_POWERLOSS = 1F;
public static final float MIN_POWERLOSS = 0.01F; public static final float MIN_POWERLOSS = 0.01F;
private final float powerLoss; private final double powerLoss;
public PerditionCalculator() { public PerditionCalculator() {
powerLoss = DEFAULT_POWERLOSS; powerLoss = DEFAULT_POWERLOSS;
@ -76,7 +75,7 @@ public final class PowerHandler {
* *
* @param powerLoss power loss per tick * @param powerLoss power loss per tick
*/ */
public PerditionCalculator(float powerLoss) { public PerditionCalculator(double powerLoss) {
if (powerLoss < MIN_POWERLOSS) { if (powerLoss < MIN_POWERLOSS) {
powerLoss = MIN_POWERLOSS; powerLoss = MIN_POWERLOSS;
} }
@ -93,13 +92,11 @@ public final class PowerHandler {
* @param ticksPassed ticks since the last time this function was called * @param ticksPassed ticks since the last time this function was called
* @return * @return
*/ */
public float applyPerdition(PowerHandler powerHandler, float current, long ticksPassed) { public double applyPerdition(PowerHandler powerHandler, double current, long ticksPassed) {
// float prev = current;
current -= powerLoss * ticksPassed; current -= powerLoss * ticksPassed;
if (current < 0) { if (current < 0) {
current = 0; current = 0;
} }
// powerHandler.totalLostPower += prev - current;
return current; return current;
} }
@ -110,16 +107,19 @@ public final class PowerHandler {
* *
* @return percent of input to tax * @return percent of input to tax
*/ */
public float getTaxPercent() { public double getTaxPercent() {
return 0; return 0;
} }
} }
public static final PerditionCalculator DEFAULT_PERDITION = new PerditionCalculator(); public static final PerditionCalculator DEFAULT_PERDITION = new PerditionCalculator();
private float minEnergyReceived; public static final double ROLLING_AVERAGE_WEIGHT = 100.0;
private float maxEnergyReceived; public static final double ROLLING_AVERAGE_NUMERATOR = ROLLING_AVERAGE_WEIGHT - 1;
private float maxEnergyStored; public static final double ROLLING_AVERAGE_DENOMINATOR = 1.0 / ROLLING_AVERAGE_WEIGHT;
private float activationEnergy; private double minEnergyReceived;
private float energyStored = 0; private double maxEnergyReceived;
private double maxEnergyStored;
private double activationEnergy;
private double energyStored = 0;
private final SafeTimeTracker doWorkTracker = new SafeTimeTracker(); private final SafeTimeTracker doWorkTracker = new SafeTimeTracker();
private final SafeTimeTracker sourcesTracker = new SafeTimeTracker(); private final SafeTimeTracker sourcesTracker = new SafeTimeTracker();
private final SafeTimeTracker perditionTracker = new SafeTimeTracker(); private final SafeTimeTracker perditionTracker = new SafeTimeTracker();
@ -128,11 +128,10 @@ public final class PowerHandler {
private PerditionCalculator perdition; private PerditionCalculator perdition;
private final PowerReceiver receiver; private final PowerReceiver receiver;
private final Type type; private final Type type;
// Debug // Tracking
// private double totalLostPower = 0; private double averageLostPower = 0;
// private double totalReceivedPower = 0; private double averageReceivedPower = 0;
// private double totalUsedPower = 0; private double averageUsedPower = 0;
// private long startTime = -1;
public PowerHandler(IPowerReceptor receptor, Type type) { public PowerHandler(IPowerReceptor receptor, Type type) {
this.receptor = receptor; this.receptor = receptor;
@ -145,23 +144,23 @@ public final class PowerHandler {
return receiver; return receiver;
} }
public float getMinEnergyReceived() { public double getMinEnergyReceived() {
return minEnergyReceived; return minEnergyReceived;
} }
public float getMaxEnergyReceived() { public double getMaxEnergyReceived() {
return maxEnergyReceived; return maxEnergyReceived;
} }
public float getMaxEnergyStored() { public double getMaxEnergyStored() {
return maxEnergyStored; return maxEnergyStored;
} }
public float getActivationEnergy() { public double getActivationEnergy() {
return activationEnergy; return activationEnergy;
} }
public float getEnergyStored() { public double getEnergyStored() {
return energyStored; return energyStored;
} }
@ -183,7 +182,7 @@ public final class PowerHandler {
* store. Values tend to range between 100 and 5000. With 1000 and 1500 * store. Values tend to range between 100 and 5000. With 1000 and 1500
* being common. * being common.
*/ */
public void configure(float minEnergyReceived, float maxEnergyReceived, float activationEnergy, float maxStoredEnergy) { public void configure(double minEnergyReceived, double maxEnergyReceived, double activationEnergy, double maxStoredEnergy) {
if (minEnergyReceived > maxEnergyReceived) { if (minEnergyReceived > maxEnergyReceived) {
maxEnergyReceived = minEnergyReceived; maxEnergyReceived = minEnergyReceived;
} }
@ -242,13 +241,6 @@ public final class PowerHandler {
* design around this though if you are aware of the limitations. * design around this though if you are aware of the limitations.
*/ */
public void update() { public void update() {
// if (startTime == -1)
// startTime = receptor.getWorld().getTotalWorldTime();
// else {
// long duration = receptor.getWorld().getTotalWorldTime() - startTime;
// System.out.printf("Power Stats: %s - Stored: %.2f Gained: %.2f - %.2f/t Lost: %.2f - %.2f/t Used: %.2f - %.2f/t%n", receptor.getClass().getSimpleName(), energyStored, totalReceivedPower, totalReceivedPower / duration, totalLostPower, totalLostPower / duration, totalUsedPower, totalUsedPower / duration);
// }
applyPerdition(); applyPerdition();
applyWork(); applyWork();
validateEnergy(); validateEnergy();
@ -256,12 +248,15 @@ public final class PowerHandler {
private void applyPerdition() { private void applyPerdition() {
if (perditionTracker.markTimeIfDelay(receptor.getWorld(), 1) && energyStored > 0) { if (perditionTracker.markTimeIfDelay(receptor.getWorld(), 1) && energyStored > 0) {
float newEnergy = getPerdition().applyPerdition(this, energyStored, perditionTracker.durationOfLastDelay()); double prev = energyStored;
double newEnergy = getPerdition().applyPerdition(this, energyStored, perditionTracker.durationOfLastDelay());
if (newEnergy == 0 || newEnergy < energyStored) if (newEnergy == 0 || newEnergy < energyStored)
energyStored = newEnergy; energyStored = newEnergy;
else else
energyStored = DEFAULT_PERDITION.applyPerdition(this, energyStored, perditionTracker.durationOfLastDelay()); energyStored = DEFAULT_PERDITION.applyPerdition(this, energyStored, perditionTracker.durationOfLastDelay());
validateEnergy(); validateEnergy();
averageLostPower = (averageLostPower * ROLLING_AVERAGE_NUMERATOR + (prev - energyStored)) * ROLLING_AVERAGE_DENOMINATOR;
} }
} }
@ -296,10 +291,10 @@ public final class PowerHandler {
* @param doUse * @param doUse
* @return amount used * @return amount used
*/ */
public float useEnergy(float min, float max, boolean doUse) { public double useEnergy(double min, double max, boolean doUse) {
applyPerdition(); applyPerdition();
float result = 0; double result = 0;
if (energyStored >= min) { if (energyStored >= min) {
if (energyStored <= max) { if (energyStored <= max) {
@ -317,8 +312,8 @@ public final class PowerHandler {
validateEnergy(); validateEnergy();
// if (doUse) if (doUse)
// totalUsedPower += result; averageUsedPower = (averageUsedPower * ROLLING_AVERAGE_NUMERATOR + result) * ROLLING_AVERAGE_DENOMINATOR;
return result; return result;
} }
@ -329,7 +324,7 @@ public final class PowerHandler {
public void readFromNBT(NBTTagCompound data, String tag) { public void readFromNBT(NBTTagCompound data, String tag) {
NBTTagCompound nbt = data.getCompoundTag(tag); NBTTagCompound nbt = data.getCompoundTag(tag);
energyStored = nbt.getFloat("storedEnergy"); energyStored = nbt.getDouble("energyStored");
} }
public void writeToNBT(NBTTagCompound data) { public void writeToNBT(NBTTagCompound data) {
@ -338,8 +333,8 @@ public final class PowerHandler {
public void writeToNBT(NBTTagCompound data, String tag) { public void writeToNBT(NBTTagCompound data, String tag) {
NBTTagCompound nbt = new NBTTagCompound(); NBTTagCompound nbt = new NBTTagCompound();
nbt.setFloat("storedEnergy", energyStored); nbt.setDouble("energyStored", energyStored);
data.setCompoundTag(tag, nbt); data.setTag(tag, nbt);
} }
public final class PowerReceiver { public final class PowerReceiver {
@ -347,26 +342,38 @@ public final class PowerHandler {
private PowerReceiver() { private PowerReceiver() {
} }
public float getMinEnergyReceived() { public double getMinEnergyReceived() {
return minEnergyReceived; return minEnergyReceived;
} }
public float getMaxEnergyReceived() { public double getMaxEnergyReceived() {
return maxEnergyReceived; return maxEnergyReceived;
} }
public float getMaxEnergyStored() { public double getMaxEnergyStored() {
return maxEnergyStored; return maxEnergyStored;
} }
public float getActivationEnergy() { public double getActivationEnergy() {
return activationEnergy; return activationEnergy;
} }
public float getEnergyStored() { public double getEnergyStored() {
return energyStored; return energyStored;
} }
public double getAveragePowerReceived() {
return averageReceivedPower;
}
public double getAveragePowerUsed() {
return averageUsedPower;
}
public double getAveragePowerLost() {
return averageLostPower;
}
public Type getType() { public Type getType() {
return type; return type;
} }
@ -380,7 +387,7 @@ public final class PowerHandler {
* *
* @return * @return
*/ */
public float powerRequest() { public double powerRequest() {
update(); update();
return Math.min(maxEnergyReceived, maxEnergyStored - energyStored); return Math.min(maxEnergyReceived, maxEnergyStored - energyStored);
} }
@ -394,8 +401,8 @@ public final class PowerHandler {
* @param from * @param from
* @return the amount of power used * @return the amount of power used
*/ */
public float receiveEnergy(Type source, final float quantity, ForgeDirection from) { public double receiveEnergy(Type source, final double quantity, ForgeDirection from) {
float used = quantity; double used = quantity;
if (source == Type.ENGINE) { if (source == Type.ENGINE) {
if (used < minEnergyReceived) { if (used < minEnergyReceived) {
return 0; return 0;
@ -416,7 +423,7 @@ public final class PowerHandler {
used = Math.min(quantity, maxEnergyReceived); used = Math.min(quantity, maxEnergyReceived);
} }
// totalReceivedPower += used; averageReceivedPower = (averageReceivedPower * ROLLING_AVERAGE_NUMERATOR + used) * ROLLING_AVERAGE_DENOMINATOR;
return used; return used;
} }
@ -426,7 +433,7 @@ public final class PowerHandler {
* *
* @return the amount the power changed by * @return the amount the power changed by
*/ */
public float addEnergy(float quantity) { public double addEnergy(double quantity) {
energyStored += quantity; energyStored += quantity;
if (energyStored > maxEnergyStored) { if (energyStored > maxEnergyStored) {
@ -442,7 +449,7 @@ public final class PowerHandler {
return quantity; return quantity;
} }
public void setEnergy(float quantity) { public void setEnergy(double quantity) {
this.energyStored = quantity; this.energyStored = quantity;
validateEnergy(); validateEnergy();
} }

View File

@ -1,3 +1,3 @@
@API(apiVersion="1.0",owner="BuildCraftAPI|core",provides="BuildCraftAPI|power") @API(apiVersion="1.1",owner="BuildCraftAPI|core",provides="BuildCraftAPI|power")
package buildcraft.api.power; package buildcraft.api.power;
import cpw.mods.fml.common.API; import cpw.mods.fml.common.API;

View File

@ -1,3 +1,11 @@
/**
* 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.tools; package buildcraft.api.tools;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;

View File

@ -1,56 +0,0 @@
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

@ -1,61 +0,0 @@
package cofh.api.energy;
import net.minecraftforge.common.ForgeDirection;
/**
* Implement this interface on TileEntities 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
{
/**
* 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 received.
* @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 to.
* @param maxExtract
* Maximum amount of energy to extract.
* @param simulate
* If TRUE, the discharge 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 true if the Handler functions on a given side - if a Tile Entity can receive and/or
* send energy from a given side, this should return true.
*/
boolean canInterface(ForgeDirection from);
/**
* Returns the amount of energy currently stored.
*/
int getEnergyStored(ForgeDirection from);
/**
* Returns the maximum amount of energy that can be stored.
*/
int getMaxEnergyStored(ForgeDirection from);
}

View File

@ -1,47 +0,0 @@
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

@ -11,14 +11,13 @@ import ic2.api.energy.tile.IEnergyTile;
* *
* See ic2/api/energy/usage.txt for an overall description of the energy net api. * See ic2/api/energy/usage.txt for an overall description of the energy net api.
*/ */
public class EnergyTileEvent extends WorldEvent public class EnergyTileEvent extends WorldEvent {
{
public final IEnergyTile energyTile; public final IEnergyTile energyTile;
public EnergyTileEvent(IEnergyTile energyTile1) public EnergyTileEvent(IEnergyTile energyTile1) {
{
super(((TileEntity) energyTile1).getWorldObj()); super(((TileEntity) energyTile1).getWorldObj());
this.energyTile = energyTile1; this.energyTile = energyTile1;
} }
} }

View File

@ -18,10 +18,9 @@ import ic2.api.energy.tile.IEnergyTile;
* *
* See ic2/api/energy/usage.txt for an overall description of the energy net api. * See ic2/api/energy/usage.txt for an overall description of the energy net api.
*/ */
public class EnergyTileLoadEvent extends EnergyTileEvent public class EnergyTileLoadEvent extends EnergyTileEvent {
{ public EnergyTileLoadEvent(IEnergyTile energyTile1) {
public EnergyTileLoadEvent(IEnergyTile energyTile1)
{
super(energyTile1); super(energyTile1);
} }
} }

View File

@ -19,10 +19,9 @@ import ic2.api.energy.tile.IEnergyTile;
* *
* See ic2/api/energy/usage.txt for an overall description of the energy net api. * See ic2/api/energy/usage.txt for an overall description of the energy net api.
*/ */
public class EnergyTileUnloadEvent extends EnergyTileEvent public class EnergyTileUnloadEvent extends EnergyTileEvent {
{ public EnergyTileUnloadEvent(IEnergyTile energyTile1) {
public EnergyTileUnloadEvent(IEnergyTile energyTile1)
{
super(energyTile1); super(energyTile1);
} }
} }

View File

@ -2,7 +2,7 @@ package ic2.api.energy.tile;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
/** /**
* For internal/multi-block usage only. * For internal/multi-block usage only.
@ -12,16 +12,16 @@ import net.minecraftforge.common.ForgeDirection;
* *
* See ic2/api/energy/usage.txt for an overall description of the energy net api. * See ic2/api/energy/usage.txt for an overall description of the energy net api.
*/ */
public interface IEnergyAcceptor extends IEnergyTile public interface IEnergyAcceptor extends IEnergyTile {
{
/** /**
* Determine if this acceptor can accept current from an adjacent emitter in a direction. * Determine if this acceptor can accept current from an adjacent emitter in a direction.
* *
* The TileEntity in the emitter parameter is what was originally added to the energy net, * The TileEntity in the emitter parameter is what was originally added to the energy net,
* which may be normal in-world TileEntity, a delegate or an IMetaDelegate. * which may be normal in-world TileEntity, a delegate or an IMetaDelegate.
* *
* @param emitter energy emitter * @param emitter energy emitter, may also be null or an IMetaDelegate
* @param direction direction the energy is being received from * @param direction direction the energy is being received from
*/ */
boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction); boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction);
} }

View File

@ -1,14 +1,13 @@
package ic2.api.energy.tile; package ic2.api.energy.tile;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
/** /**
* Allows a tile entity (mostly a machine) to receive energy. * Allows a tile entity (mostly a machine) to receive energy.
* *
* See ic2/api/energy/usage.txt for an overall description of the energy net api. * See ic2/api/energy/usage.txt for an overall description of the energy net api.
*/ */
public interface IEnergySink extends IEnergyAcceptor public interface IEnergySink extends IEnergyAcceptor {
{
/** /**
* Determine how much energy the sink accepts. * Determine how much energy the sink accepts.
* *
@ -16,6 +15,8 @@ public interface IEnergySink extends IEnergyAcceptor
* *
* Make sure that injectEnergy() does accepts energy if demandsEnergy() returns anything > 0. * Make sure that injectEnergy() does accepts energy if demandsEnergy() returns anything > 0.
* *
* @note Modifying the energy net from this method is disallowed.
*
* @return max accepted input in eu * @return max accepted input in eu
*/ */
double demandedEnergyUnits(); double demandedEnergyUnits();
@ -33,16 +34,17 @@ public interface IEnergySink extends IEnergyAcceptor
double injectEnergyUnits(ForgeDirection directionFrom, double amount); double injectEnergyUnits(ForgeDirection directionFrom, double amount);
/** /**
* Determine the amount of eu which can be safely injected into the specific energy sink without * Determine the amount of eu which can be safely injected into the specific energy sink without exploding.
* exploding.
* *
* Typical values are 32 for LV, 128 for MV, 512 for HV and 2048 for EV. A value of * Typical values are 32 for LV, 128 for MV, 512 for HV and 2048 for EV. A value of Integer.MAX_VALUE indicates no
* Integer.MAX_VALUE indicates no
* limit. * limit.
* *
* This value is unrelated to demandsEnergy(). * This value is unrelated to demandsEnergy().
* *
* @note Modifying the energy net from this method is disallowed.
*
* @return max safe input in eu * @return max safe input in eu
*/ */
int getMaxSafeInput(); int getMaxSafeInput();
} }

View File

@ -9,7 +9,7 @@ package ic2.api.energy.tile;
* *
* See ic2/api/energy/usage.txt for an overall description of the energy net api. * See ic2/api/energy/usage.txt for an overall description of the energy net api.
*/ */
public interface IEnergyTile public interface IEnergyTile {
{
// //
} }

View File

@ -38,7 +38,7 @@ object Sound {
// Set in init event. // Set in init event.
var manager: SoundManager = _ var manager: SoundManager = _
def soundSystem: SoundSystem = ReflectionHelper.getPrivateValue(classOf[SoundManager], manager, "sndSystem") def soundSystem: SoundSystem = ReflectionHelper.getPrivateValue(classOf[SoundManager], manager, "sndSystem", "field_148620_e", "e")
private def updateVolume() { private def updateVolume() {
val volume = FMLClientHandler.instance.getClient.gameSettings.getSoundLevel(SoundCategory.BLOCKS) val volume = FMLClientHandler.instance.getClient.gameSettings.getSoundLevel(SoundCategory.BLOCKS)

View File

@ -1,7 +1,7 @@
package li.cil.oc.common.tileentity package li.cil.oc.common.tileentity
import buildcraft.api.power.{IPowerReceptor, PowerHandler} import buildcraft.api.power.{IPowerReceptor, PowerHandler}
import cofh.api.energy.IEnergyHandler //import cofh.api.energy.IEnergyHandler
import cpw.mods.fml.common.{ModAPIManager, Loader, Optional} import cpw.mods.fml.common.{ModAPIManager, Loader, Optional}
import cpw.mods.fml.relauncher.{Side, SideOnly} import cpw.mods.fml.relauncher.{Side, SideOnly}
import ic2.api.energy.event.{EnergyTileUnloadEvent, EnergyTileLoadEvent} import ic2.api.energy.event.{EnergyTileUnloadEvent, EnergyTileLoadEvent}
@ -14,12 +14,12 @@ import net.minecraftforge.common.util.ForgeDirection
@Optional.InterfaceList(Array( @Optional.InterfaceList(Array(
new Optional.Interface(iface = "buildcraft.api.power.IPowerReceptor", modid = "BuildCraftAPI|power"), new Optional.Interface(iface = "buildcraft.api.power.IPowerReceptor", modid = "BuildCraftAPI|power"),
new Optional.Interface(iface = "ic2.api.energy.tile.IEnergySink", modid = "IC2"), new Optional.Interface(iface = "ic2.api.energy.tile.IEnergySink", modid = "IC2")
new Optional.Interface(iface = "cofh.api.energy.IEnergyHandler", modid = "ThermalExpansion"), // new Optional.Interface(iface = "cofh.api.energy.IEnergyHandler", modid = "ThermalExpansion"),
new Optional.Interface(iface = "universalelectricity.api.energy.IEnergyInterface", modid = "UniversalElectricity"), // new Optional.Interface(iface = "universalelectricity.api.energy.IEnergyInterface", modid = "UniversalElectricity"),
new Optional.Interface(iface = "universalelectricity.api.energy.IEnergyContainer", modid = "UniversalElectricity") // new Optional.Interface(iface = "universalelectricity.api.energy.IEnergyContainer", modid = "UniversalElectricity")
)) ))
abstract class PowerAcceptor extends TileEntity with IPowerReceptor with IEnergySink with IEnergyHandler with IEnergyInterface with IEnergyContainer { abstract class PowerAcceptor extends TileEntity with IPowerReceptor with IEnergySink /* with IEnergyHandler with IEnergyInterface with IEnergyContainer */ {
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
protected def hasConnector(side: ForgeDirection) = false protected def hasConnector(side: ForgeDirection) = false
@ -165,11 +165,11 @@ abstract class PowerAcceptor extends TileEntity with IPowerReceptor with IEnergy
// ----------------------------------------------------------------------- // // ----------------------------------------------------------------------- //
// Universal Electricity // Universal Electricity
override def canConnect(direction: ForgeDirection, source: AnyRef) = def canConnect(direction: ForgeDirection, source: AnyRef) =
!Settings.get.ignorePower && direction != null && direction != ForgeDirection.UNKNOWN && !Settings.get.ignorePower && direction != null && direction != ForgeDirection.UNKNOWN &&
(if (isClient) hasConnector(direction) else connector(direction).isDefined) (if (isClient) hasConnector(direction) else connector(direction).isDefined)
override def onReceiveEnergy(from: ForgeDirection, receive: Long, doReceive: Boolean) = def onReceiveEnergy(from: ForgeDirection, receive: Long, doReceive: Boolean) =
if (isClient || Settings.get.ignorePower) 0 if (isClient || Settings.get.ignorePower) 0
else connector(from) match { else connector(from) match {
case Some(node) => case Some(node) =>
@ -185,18 +185,18 @@ abstract class PowerAcceptor extends TileEntity with IPowerReceptor with IEnergy
case _ => 0 case _ => 0
} }
override def onExtractEnergy(from: ForgeDirection, extract: Long, doExtract: Boolean) = 0 def onExtractEnergy(from: ForgeDirection, extract: Long, doExtract: Boolean) = 0
override def setEnergy(from: ForgeDirection, energy: Long) {} def setEnergy(from: ForgeDirection, energy: Long) {}
override def getEnergy(from: ForgeDirection) = def getEnergy(from: ForgeDirection) =
if (isClient) 0 if (isClient) 0
else connector(from) match { else connector(from) match {
case Some(node) => (node.globalBuffer * Settings.ratioBC).toLong case Some(node) => (node.globalBuffer * Settings.ratioBC).toLong
case _ => 0 case _ => 0
} }
override def getEnergyCapacity(from: ForgeDirection) = def getEnergyCapacity(from: ForgeDirection) =
if (isClient) 0 if (isClient) 0
else connector(from) match { else connector(from) match {
case Some(node) => (node.globalBufferSize * Settings.ratioBC).toLong case Some(node) => (node.globalBufferSize * Settings.ratioBC).toLong