mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-26 14:35:04 -04:00
updated bc and ic2 apis -> working power from those two in 1.7; fixed sound in obf'ed mc
This commit is contained in:
parent
259aae00c3
commit
415602a604
@ -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
|
||||
* 1.0, or MMPL. Please check the contents of the license located in
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
package buildcraft.api.core;
|
||||
@ -13,10 +14,45 @@ public class SafeTimeTracker {
|
||||
|
||||
private long lastMark = Long.MIN_VALUE;
|
||||
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
|
||||
* successfully.
|
||||
*
|
||||
* @deprecated should use the constructor with a delay instead, and call
|
||||
* this function without a parameter
|
||||
*/
|
||||
public boolean markTimeIfDelay(World world, long delay) {
|
||||
if (world == null)
|
||||
@ -27,13 +63,15 @@ public class SafeTimeTracker {
|
||||
if (currentTime < lastMark) {
|
||||
lastMark = currentTime;
|
||||
return false;
|
||||
} else if (lastMark + delay <= currentTime) {
|
||||
} else if (lastMark + delay + lastRandomDelay <= currentTime) {
|
||||
duration = currentTime - lastMark;
|
||||
lastMark = currentTime;
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
lastRandomDelay = (int) (Math.random() * randomRange);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public long durationOfLastDelay() {
|
||||
|
@ -1,22 +1,20 @@
|
||||
/*
|
||||
* Copyright (c) SpaceToad, 2011-2012
|
||||
/**
|
||||
* 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.power;
|
||||
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
/**
|
||||
* Essentially only used for Wooden Power Pipe connection rules.
|
||||
*
|
||||
* This Tile Entity interface allows you to indicate that a block can emit power
|
||||
* from a specific side.
|
||||
*
|
||||
* @author CovertJaguar <http://www.railcraft.info/>
|
||||
*/
|
||||
public interface IPowerEmitter {
|
||||
|
||||
|
@ -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
|
||||
* 1.0, or MMPL. Please check the contents of the license located in
|
||||
* 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.power;
|
||||
|
||||
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
|
||||
* able to receive power.
|
||||
*
|
||||
* @author CovertJaguar <http://www.railcraft.info/>
|
||||
*/
|
||||
public interface IPowerReceptor {
|
||||
|
||||
|
@ -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
|
||||
* 1.0, or MMPL. Please check the contents of the license located in
|
||||
* 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.power;
|
||||
|
||||
import buildcraft.api.core.SafeTimeTracker;
|
||||
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
|
||||
@ -21,13 +22,11 @@ import net.minecraftforge.common.ForgeDirection;
|
||||
* If you plan emit power, you need only implement IPowerEmitter. You do not
|
||||
* need a PowerHandler. Engines have a PowerHandler because they can also
|
||||
* receive power from other Engines.
|
||||
*
|
||||
*
|
||||
* See TileRefinery for a simple example of a power using machine.
|
||||
*
|
||||
* @see IPowerReceptor
|
||||
* @see IPowerEmitter
|
||||
*
|
||||
* @author CovertJaguar <http://www.railcraft.info/>
|
||||
*/
|
||||
public final class PowerHandler {
|
||||
|
||||
@ -65,7 +64,7 @@ public final class PowerHandler {
|
||||
|
||||
public static final float DEFAULT_POWERLOSS = 1F;
|
||||
public static final float MIN_POWERLOSS = 0.01F;
|
||||
private final float powerLoss;
|
||||
private final double powerLoss;
|
||||
|
||||
public PerditionCalculator() {
|
||||
powerLoss = DEFAULT_POWERLOSS;
|
||||
@ -76,7 +75,7 @@ public final class PowerHandler {
|
||||
*
|
||||
* @param powerLoss power loss per tick
|
||||
*/
|
||||
public PerditionCalculator(float powerLoss) {
|
||||
public PerditionCalculator(double powerLoss) {
|
||||
if (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
|
||||
* @return
|
||||
*/
|
||||
public float applyPerdition(PowerHandler powerHandler, float current, long ticksPassed) {
|
||||
// float prev = current;
|
||||
public double applyPerdition(PowerHandler powerHandler, double current, long ticksPassed) {
|
||||
current -= powerLoss * ticksPassed;
|
||||
if (current < 0) {
|
||||
current = 0;
|
||||
}
|
||||
// powerHandler.totalLostPower += prev - current;
|
||||
return current;
|
||||
}
|
||||
|
||||
@ -110,16 +107,19 @@ public final class PowerHandler {
|
||||
*
|
||||
* @return percent of input to tax
|
||||
*/
|
||||
public float getTaxPercent() {
|
||||
public double getTaxPercent() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
public static final PerditionCalculator DEFAULT_PERDITION = new PerditionCalculator();
|
||||
private float minEnergyReceived;
|
||||
private float maxEnergyReceived;
|
||||
private float maxEnergyStored;
|
||||
private float activationEnergy;
|
||||
private float energyStored = 0;
|
||||
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;
|
||||
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();
|
||||
@ -128,11 +128,10 @@ public final class PowerHandler {
|
||||
private PerditionCalculator perdition;
|
||||
private final PowerReceiver receiver;
|
||||
private final Type type;
|
||||
// Debug
|
||||
// private double totalLostPower = 0;
|
||||
// private double totalReceivedPower = 0;
|
||||
// private double totalUsedPower = 0;
|
||||
// private long startTime = -1;
|
||||
// Tracking
|
||||
private double averageLostPower = 0;
|
||||
private double averageReceivedPower = 0;
|
||||
private double averageUsedPower = 0;
|
||||
|
||||
public PowerHandler(IPowerReceptor receptor, Type type) {
|
||||
this.receptor = receptor;
|
||||
@ -145,23 +144,23 @@ public final class PowerHandler {
|
||||
return receiver;
|
||||
}
|
||||
|
||||
public float getMinEnergyReceived() {
|
||||
public double getMinEnergyReceived() {
|
||||
return minEnergyReceived;
|
||||
}
|
||||
|
||||
public float getMaxEnergyReceived() {
|
||||
public double getMaxEnergyReceived() {
|
||||
return maxEnergyReceived;
|
||||
}
|
||||
|
||||
public float getMaxEnergyStored() {
|
||||
public double getMaxEnergyStored() {
|
||||
return maxEnergyStored;
|
||||
}
|
||||
|
||||
public float getActivationEnergy() {
|
||||
public double getActivationEnergy() {
|
||||
return activationEnergy;
|
||||
}
|
||||
|
||||
public float getEnergyStored() {
|
||||
public double getEnergyStored() {
|
||||
return energyStored;
|
||||
}
|
||||
|
||||
@ -183,7 +182,7 @@ public final class PowerHandler {
|
||||
* store. Values tend to range between 100 and 5000. With 1000 and 1500
|
||||
* 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) {
|
||||
maxEnergyReceived = minEnergyReceived;
|
||||
}
|
||||
@ -242,13 +241,6 @@ public final class PowerHandler {
|
||||
* design around this though if you are aware of the limitations.
|
||||
*/
|
||||
public void update() {
|
||||
// if (startTime == -1)
|
||||
// startTime = receptor.getWorld().getTotalWorldTime();
|
||||
// else {
|
||||
// long duration = receptor.getWorld().getTotalWorldTime() - startTime;
|
||||
// System.out.printf("Power Stats: %s - Stored: %.2f Gained: %.2f - %.2f/t Lost: %.2f - %.2f/t Used: %.2f - %.2f/t%n", receptor.getClass().getSimpleName(), energyStored, totalReceivedPower, totalReceivedPower / duration, totalLostPower, totalLostPower / duration, totalUsedPower, totalUsedPower / duration);
|
||||
// }
|
||||
|
||||
applyPerdition();
|
||||
applyWork();
|
||||
validateEnergy();
|
||||
@ -256,12 +248,15 @@ public final class PowerHandler {
|
||||
|
||||
private void applyPerdition() {
|
||||
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)
|
||||
energyStored = newEnergy;
|
||||
else
|
||||
energyStored = DEFAULT_PERDITION.applyPerdition(this, energyStored, perditionTracker.durationOfLastDelay());
|
||||
validateEnergy();
|
||||
|
||||
averageLostPower = (averageLostPower * ROLLING_AVERAGE_NUMERATOR + (prev - energyStored)) * ROLLING_AVERAGE_DENOMINATOR;
|
||||
}
|
||||
}
|
||||
|
||||
@ -296,10 +291,10 @@ public final class PowerHandler {
|
||||
* @param doUse
|
||||
* @return amount used
|
||||
*/
|
||||
public float useEnergy(float min, float max, boolean doUse) {
|
||||
public double useEnergy(double min, double max, boolean doUse) {
|
||||
applyPerdition();
|
||||
|
||||
float result = 0;
|
||||
double result = 0;
|
||||
|
||||
if (energyStored >= min) {
|
||||
if (energyStored <= max) {
|
||||
@ -317,8 +312,8 @@ public final class PowerHandler {
|
||||
|
||||
validateEnergy();
|
||||
|
||||
// if (doUse)
|
||||
// totalUsedPower += result;
|
||||
if (doUse)
|
||||
averageUsedPower = (averageUsedPower * ROLLING_AVERAGE_NUMERATOR + result) * ROLLING_AVERAGE_DENOMINATOR;
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -329,7 +324,7 @@ public final class PowerHandler {
|
||||
|
||||
public void readFromNBT(NBTTagCompound data, String tag) {
|
||||
NBTTagCompound nbt = data.getCompoundTag(tag);
|
||||
energyStored = nbt.getFloat("storedEnergy");
|
||||
energyStored = nbt.getDouble("energyStored");
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound data) {
|
||||
@ -338,8 +333,8 @@ public final class PowerHandler {
|
||||
|
||||
public void writeToNBT(NBTTagCompound data, String tag) {
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
nbt.setFloat("storedEnergy", energyStored);
|
||||
data.setCompoundTag(tag, nbt);
|
||||
nbt.setDouble("energyStored", energyStored);
|
||||
data.setTag(tag, nbt);
|
||||
}
|
||||
|
||||
public final class PowerReceiver {
|
||||
@ -347,26 +342,38 @@ public final class PowerHandler {
|
||||
private PowerReceiver() {
|
||||
}
|
||||
|
||||
public float getMinEnergyReceived() {
|
||||
public double getMinEnergyReceived() {
|
||||
return minEnergyReceived;
|
||||
}
|
||||
|
||||
public float getMaxEnergyReceived() {
|
||||
public double getMaxEnergyReceived() {
|
||||
return maxEnergyReceived;
|
||||
}
|
||||
|
||||
public float getMaxEnergyStored() {
|
||||
public double getMaxEnergyStored() {
|
||||
return maxEnergyStored;
|
||||
}
|
||||
|
||||
public float getActivationEnergy() {
|
||||
public double getActivationEnergy() {
|
||||
return activationEnergy;
|
||||
}
|
||||
|
||||
public float getEnergyStored() {
|
||||
public double getEnergyStored() {
|
||||
return energyStored;
|
||||
}
|
||||
|
||||
public double getAveragePowerReceived() {
|
||||
return averageReceivedPower;
|
||||
}
|
||||
|
||||
public double getAveragePowerUsed() {
|
||||
return averageUsedPower;
|
||||
}
|
||||
|
||||
public double getAveragePowerLost() {
|
||||
return averageLostPower;
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
@ -380,7 +387,7 @@ public final class PowerHandler {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public float powerRequest() {
|
||||
public double powerRequest() {
|
||||
update();
|
||||
return Math.min(maxEnergyReceived, maxEnergyStored - energyStored);
|
||||
}
|
||||
@ -394,8 +401,8 @@ public final class PowerHandler {
|
||||
* @param from
|
||||
* @return the amount of power used
|
||||
*/
|
||||
public float receiveEnergy(Type source, final float quantity, ForgeDirection from) {
|
||||
float used = quantity;
|
||||
public double receiveEnergy(Type source, final double quantity, ForgeDirection from) {
|
||||
double used = quantity;
|
||||
if (source == Type.ENGINE) {
|
||||
if (used < minEnergyReceived) {
|
||||
return 0;
|
||||
@ -416,7 +423,7 @@ public final class PowerHandler {
|
||||
used = Math.min(quantity, maxEnergyReceived);
|
||||
}
|
||||
|
||||
// totalReceivedPower += used;
|
||||
averageReceivedPower = (averageReceivedPower * ROLLING_AVERAGE_NUMERATOR + used) * ROLLING_AVERAGE_DENOMINATOR;
|
||||
|
||||
return used;
|
||||
}
|
||||
@ -426,7 +433,7 @@ public final class PowerHandler {
|
||||
*
|
||||
* @return the amount the power changed by
|
||||
*/
|
||||
public float addEnergy(float quantity) {
|
||||
public double addEnergy(double quantity) {
|
||||
energyStored += quantity;
|
||||
|
||||
if (energyStored > maxEnergyStored) {
|
||||
@ -442,7 +449,7 @@ public final class PowerHandler {
|
||||
return quantity;
|
||||
}
|
||||
|
||||
public void setEnergy(float quantity) {
|
||||
public void setEnergy(double quantity) {
|
||||
this.energyStored = quantity;
|
||||
validateEnergy();
|
||||
}
|
||||
|
@ -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;
|
||||
import cpw.mods.fml.common.API;
|
@ -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;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
@ -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);
|
||||
|
||||
}
|
@ -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);
|
||||
|
||||
}
|
@ -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();
|
||||
|
||||
}
|
@ -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.
|
||||
*/
|
||||
public class EnergyTileEvent extends WorldEvent
|
||||
{
|
||||
public class EnergyTileEvent extends WorldEvent {
|
||||
public final IEnergyTile energyTile;
|
||||
|
||||
public EnergyTileEvent(IEnergyTile energyTile1)
|
||||
{
|
||||
public EnergyTileEvent(IEnergyTile energyTile1) {
|
||||
super(((TileEntity) energyTile1).getWorldObj());
|
||||
|
||||
this.energyTile = energyTile1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,24 +4,23 @@ import ic2.api.energy.tile.IEnergyTile;
|
||||
|
||||
/**
|
||||
* Event announcing new energy tiles.
|
||||
*
|
||||
*
|
||||
* This event notifies subscribers of loaded energy tiles, e.g. after getting
|
||||
* loaded through the chunk they are in or after being placed down by the
|
||||
* player or another deployer mechanism.
|
||||
*
|
||||
*
|
||||
* Every energy tile which wants to get connected to the IC2 Energy Network has
|
||||
* to either post this event or alternatively call EnergyNet.addTileEntity().
|
||||
*
|
||||
*
|
||||
* You may use this event to build a static representation of energy tiles for
|
||||
* your own energy grid implementation if you need to. It's not required if you
|
||||
* always lookup energy paths on demand.
|
||||
*
|
||||
* See ic2/api/energy/usage.txt for an overall description of the energy net api.
|
||||
*/
|
||||
public class EnergyTileLoadEvent extends EnergyTileEvent
|
||||
{
|
||||
public EnergyTileLoadEvent(IEnergyTile energyTile1)
|
||||
{
|
||||
public class EnergyTileLoadEvent extends EnergyTileEvent {
|
||||
public EnergyTileLoadEvent(IEnergyTile energyTile1) {
|
||||
super(energyTile1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,25 +4,24 @@ import ic2.api.energy.tile.IEnergyTile;
|
||||
|
||||
/**
|
||||
* Event announcing terminated energy tiles.
|
||||
*
|
||||
*
|
||||
* This event notifies subscribers of unloaded energy tiles, e.g. after getting
|
||||
* unloaded through the chunk they are in or after being destroyed by the
|
||||
* player or another block pick/destruction mechanism.
|
||||
*
|
||||
*
|
||||
* Every energy tile which wants to get disconnected from the IC2 Energy
|
||||
* Network has to either post this event or alternatively call
|
||||
* EnergyNet.removeTileEntity().
|
||||
*
|
||||
*
|
||||
* You may use this event to build a static representation of energy tiles for
|
||||
* your own energy grid implementation if you need to. It's not required if you
|
||||
* always lookup energy paths on demand.
|
||||
*
|
||||
* See ic2/api/energy/usage.txt for an overall description of the energy net api.
|
||||
*/
|
||||
public class EnergyTileUnloadEvent extends EnergyTileEvent
|
||||
{
|
||||
public EnergyTileUnloadEvent(IEnergyTile energyTile1)
|
||||
{
|
||||
public class EnergyTileUnloadEvent extends EnergyTileEvent {
|
||||
public EnergyTileUnloadEvent(IEnergyTile energyTile1) {
|
||||
super(energyTile1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,26 +2,26 @@ package ic2.api.energy.tile;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
/**
|
||||
* For internal/multi-block usage only.
|
||||
*
|
||||
*
|
||||
* @see IEnergySink
|
||||
* @see IEnergyConductor
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @param emitter energy emitter
|
||||
* @param emitter energy emitter, may also be null or an IMetaDelegate
|
||||
* @param direction direction the energy is being received from
|
||||
*/
|
||||
boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction);
|
||||
}
|
||||
|
||||
|
@ -1,21 +1,22 @@
|
||||
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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* This value is unrelated to getMaxSafeInput().
|
||||
*
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
double demandedEnergyUnits();
|
||||
@ -25,7 +26,7 @@ public interface IEnergySink extends IEnergyAcceptor
|
||||
*
|
||||
* It's highly recommended to accept all energy by letting the internal buffer overflow to
|
||||
* increase the performance and accuracy of the distribution simulation.
|
||||
*
|
||||
*
|
||||
* @param directionFrom direction from which the energy comes from
|
||||
* @param amount energy to be transferred
|
||||
* @return Energy not consumed (leftover)
|
||||
@ -33,16 +34,17 @@ public interface IEnergySink extends IEnergyAcceptor
|
||||
double injectEnergyUnits(ForgeDirection directionFrom, double amount);
|
||||
|
||||
/**
|
||||
* Determine the amount of eu which can be safely injected into the specific energy sink without
|
||||
* exploding.
|
||||
*
|
||||
* Typical values are 32 for LV, 128 for MV, 512 for HV and 2048 for EV. A value of
|
||||
* Integer.MAX_VALUE indicates no
|
||||
* Determine the amount of eu which can be safely injected into the specific energy sink without exploding.
|
||||
*
|
||||
* Typical values are 32 for LV, 128 for MV, 512 for HV and 2048 for EV. A value of Integer.MAX_VALUE indicates no
|
||||
* limit.
|
||||
*
|
||||
*
|
||||
* This value is unrelated to demandsEnergy().
|
||||
*
|
||||
* @note Modifying the energy net from this method is disallowed.
|
||||
*
|
||||
* @return max safe input in eu
|
||||
*/
|
||||
int getMaxSafeInput();
|
||||
}
|
||||
|
||||
|
@ -2,14 +2,14 @@ package ic2.api.energy.tile;
|
||||
|
||||
/**
|
||||
* For internal usage only, base class for all energy tiles.
|
||||
*
|
||||
*
|
||||
* @see IEnergySink
|
||||
* @see IEnergySource
|
||||
* @see IEnergyConductor
|
||||
*
|
||||
* See ic2/api/energy/usage.txt for an overall description of the energy net api.
|
||||
*/
|
||||
public interface IEnergyTile
|
||||
{
|
||||
public interface IEnergyTile {
|
||||
//
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ object Sound {
|
||||
// Set in init event.
|
||||
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() {
|
||||
val volume = FMLClientHandler.instance.getClient.gameSettings.getSoundLevel(SoundCategory.BLOCKS)
|
||||
|
@ -1,7 +1,7 @@
|
||||
package li.cil.oc.common.tileentity
|
||||
|
||||
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.relauncher.{Side, SideOnly}
|
||||
import ic2.api.energy.event.{EnergyTileUnloadEvent, EnergyTileLoadEvent}
|
||||
@ -14,12 +14,12 @@ import net.minecraftforge.common.util.ForgeDirection
|
||||
|
||||
@Optional.InterfaceList(Array(
|
||||
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 = "cofh.api.energy.IEnergyHandler", modid = "ThermalExpansion"),
|
||||
new Optional.Interface(iface = "universalelectricity.api.energy.IEnergyInterface", modid = "UniversalElectricity"),
|
||||
new Optional.Interface(iface = "universalelectricity.api.energy.IEnergyContainer", modid = "UniversalElectricity")
|
||||
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 = "universalelectricity.api.energy.IEnergyInterface", 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)
|
||||
protected def hasConnector(side: ForgeDirection) = false
|
||||
|
||||
@ -165,11 +165,11 @@ abstract class PowerAcceptor extends TileEntity with IPowerReceptor with IEnergy
|
||||
// ----------------------------------------------------------------------- //
|
||||
// Universal Electricity
|
||||
|
||||
override def canConnect(direction: ForgeDirection, source: AnyRef) =
|
||||
def canConnect(direction: ForgeDirection, source: AnyRef) =
|
||||
!Settings.get.ignorePower && direction != null && direction != ForgeDirection.UNKNOWN &&
|
||||
(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
|
||||
else connector(from) match {
|
||||
case Some(node) =>
|
||||
@ -185,18 +185,18 @@ abstract class PowerAcceptor extends TileEntity with IPowerReceptor with IEnergy
|
||||
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
|
||||
else connector(from) match {
|
||||
case Some(node) => (node.globalBuffer * Settings.ratioBC).toLong
|
||||
case _ => 0
|
||||
}
|
||||
|
||||
override def getEnergyCapacity(from: ForgeDirection) =
|
||||
def getEnergyCapacity(from: ForgeDirection) =
|
||||
if (isClient) 0
|
||||
else connector(from) match {
|
||||
case Some(node) => (node.globalBufferSize * Settings.ratioBC).toLong
|
||||
|
Loading…
x
Reference in New Issue
Block a user