Fixed up BC API
This commit is contained in:
parent
2507bd3ecb
commit
e6838c613c
41 changed files with 1409 additions and 165 deletions
|
@ -31,7 +31,7 @@ public final class BCLog {
|
|||
logger.info("http://www.mod-buildcraft.com");
|
||||
}
|
||||
|
||||
public static void logErrorAPI(String mod, Throwable error, Class classFile) {
|
||||
public static void logErrorAPI(String mod, Throwable error, Class<?> classFile) {
|
||||
StringBuilder msg = new StringBuilder(mod);
|
||||
msg.append(" API error, please update your mods. Error: ").append(error);
|
||||
StackTraceElement[] stackTrace = error.getStackTrace();
|
||||
|
|
0
src/api/java/buildcraft/api/core/ICoreProxy.java
Executable file → Normal file
0
src/api/java/buildcraft/api/core/ICoreProxy.java
Executable file → Normal file
|
@ -22,7 +22,7 @@ public interface IInvSlot {
|
|||
|
||||
boolean canTakeStackFromSlot(ItemStack stack);
|
||||
|
||||
ItemStack decreaseStackInSlot();
|
||||
ItemStack decreaseStackInSlot(int amount);
|
||||
|
||||
ItemStack getStackInSlot();
|
||||
|
||||
|
|
|
@ -6,14 +6,13 @@
|
|||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
package buildcraft.api.recipes;
|
||||
package buildcraft.api.core;
|
||||
|
||||
public final class BuildcraftRecipes {
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public static IAssemblyRecipeManager assemblyTable;
|
||||
public static IIntegrationRecipeManager integrationTable;
|
||||
public static IRefineryRecipeManager refinery;
|
||||
public interface IWorldProperty {
|
||||
|
||||
private BuildcraftRecipes() {
|
||||
}
|
||||
boolean get(World world, int x, int y, int z);
|
||||
|
||||
void clear();
|
||||
}
|
0
src/api/java/buildcraft/api/core/IZone.java
Executable file → Normal file
0
src/api/java/buildcraft/api/core/IZone.java
Executable file → Normal file
8
src/api/java/buildcraft/api/core/JavaTools.java
Executable file → Normal file
8
src/api/java/buildcraft/api/core/JavaTools.java
Executable file → Normal file
|
@ -50,10 +50,10 @@ public class JavaTools {
|
|||
return c;
|
||||
}
|
||||
|
||||
public static List<Field> getAllFields(Class clas) {
|
||||
public static List<Field> getAllFields(Class<?> clas) {
|
||||
List<Field> result = new ArrayList<Field>();
|
||||
|
||||
Class current = clas;
|
||||
Class<?> current = clas;
|
||||
|
||||
while (current != null && current != Object.class) {
|
||||
for (Field f : current.getDeclaredFields()) {
|
||||
|
@ -66,10 +66,10 @@ public class JavaTools {
|
|||
return result;
|
||||
}
|
||||
|
||||
public static List<Method> getAllMethods(Class clas) {
|
||||
public static List<Method> getAllMethods(Class<?> clas) {
|
||||
List<Method> result = new ArrayList<Method>();
|
||||
|
||||
Class current = clas;
|
||||
Class<?> current = clas;
|
||||
|
||||
while (current != null && current != Object.class) {
|
||||
for (Method m : current.getDeclaredMethods()) {
|
||||
|
|
0
src/api/java/buildcraft/api/core/WorldBlockIndex.java
Executable file → Normal file
0
src/api/java/buildcraft/api/core/WorldBlockIndex.java
Executable file → Normal file
|
@ -0,0 +1,64 @@
|
|||
/**
|
||||
* 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.gates;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import buildcraft.api.statements.IActionInternal;
|
||||
import buildcraft.api.statements.IStatement;
|
||||
import buildcraft.api.statements.IStatementParameter;
|
||||
import buildcraft.api.statements.ITriggerInternal;
|
||||
|
||||
public abstract class GateExpansionController {
|
||||
|
||||
public final IGateExpansion type;
|
||||
public final TileEntity pipeTile;
|
||||
|
||||
public GateExpansionController(IGateExpansion type, TileEntity pipeTile) {
|
||||
this.pipeTile = pipeTile;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public IGateExpansion getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void tick(IGate gate) {
|
||||
}
|
||||
|
||||
public void startResolution() {
|
||||
}
|
||||
|
||||
public boolean resolveAction(IStatement action) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isTriggerActive(IStatement trigger, IStatementParameter[] parameters) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void addTriggers(List<ITriggerInternal> list) {
|
||||
}
|
||||
|
||||
public void addActions(List<IActionInternal> list) {
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
}
|
||||
}
|
53
src/api/java/buildcraft/api/gates/GateExpansions.java
Normal file
53
src/api/java/buildcraft/api/gates/GateExpansions.java
Normal file
|
@ -0,0 +1,53 @@
|
|||
/**
|
||||
* 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.gates;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public final class GateExpansions {
|
||||
|
||||
private static final Map<String, IGateExpansion> expansions = new HashMap<String, IGateExpansion>();
|
||||
private static final ArrayList<IGateExpansion> expansionIDs = new ArrayList<IGateExpansion>();
|
||||
|
||||
private GateExpansions() {
|
||||
}
|
||||
|
||||
public static void registerExpansion(IGateExpansion expansion) {
|
||||
registerExpansion(expansion.getUniqueIdentifier(), expansion);
|
||||
}
|
||||
|
||||
public static void registerExpansion(String identifier, IGateExpansion expansion) {
|
||||
expansions.put(identifier, expansion);
|
||||
expansionIDs.add(expansion);
|
||||
}
|
||||
|
||||
public static IGateExpansion getExpansion(String identifier) {
|
||||
return expansions.get(identifier);
|
||||
}
|
||||
|
||||
public static Set<IGateExpansion> getExpansions() {
|
||||
Set<IGateExpansion> set = new HashSet<IGateExpansion>();
|
||||
set.addAll(expansionIDs);
|
||||
return set;
|
||||
}
|
||||
|
||||
// The code below is used by networking.
|
||||
|
||||
public static IGateExpansion getExpansionByID(int id) {
|
||||
return expansionIDs.get(id);
|
||||
}
|
||||
|
||||
public static int getExpansionID(IGateExpansion expansion) {
|
||||
return expansionIDs.indexOf(expansion);
|
||||
}
|
||||
}
|
30
src/api/java/buildcraft/api/gates/IGateExpansion.java
Normal file
30
src/api/java/buildcraft/api/gates/IGateExpansion.java
Normal file
|
@ -0,0 +1,30 @@
|
|||
/**
|
||||
* 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.gates;
|
||||
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
|
||||
public interface IGateExpansion {
|
||||
|
||||
String getUniqueIdentifier();
|
||||
|
||||
String getDisplayName();
|
||||
|
||||
GateExpansionController makeController(TileEntity pipeTile);
|
||||
|
||||
void registerBlockOverlay(IIconRegister iconRegister);
|
||||
|
||||
void registerItemOverlay(IIconRegister iconRegister);
|
||||
|
||||
IIcon getOverlayBlock();
|
||||
|
||||
IIcon getOverlayItem();
|
||||
}
|
|
@ -6,7 +6,7 @@
|
|||
* 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 = "2.0", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|recipes")
|
||||
package buildcraft.api.recipes;
|
||||
@API(apiVersion = "3.0", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|gates")
|
||||
package buildcraft.api.gates;
|
||||
import cpw.mods.fml.common.API;
|
||||
|
41
src/api/java/buildcraft/api/power/ILaserTarget.java
Normal file
41
src/api/java/buildcraft/api/power/ILaserTarget.java
Normal file
|
@ -0,0 +1,41 @@
|
|||
/**
|
||||
* 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;
|
||||
|
||||
public interface ILaserTarget {
|
||||
|
||||
/**
|
||||
* Returns true if the target currently needs power. For example, if the Advanced
|
||||
* Crafting Table has work to do.
|
||||
*
|
||||
* @return true if needs power
|
||||
*/
|
||||
boolean requiresLaserEnergy();
|
||||
|
||||
/**
|
||||
* Transfers energy from the laser to the target.
|
||||
*
|
||||
* @param energy
|
||||
*/
|
||||
void receiveLaserEnergy(int energy);
|
||||
|
||||
/**
|
||||
* Return true if the Tile Entity object is no longer a valid target. For
|
||||
* example, if its been invalidated.
|
||||
*
|
||||
* @return true if no longer a valid target object
|
||||
*/
|
||||
boolean isInvalidTarget();
|
||||
|
||||
double getXCoord();
|
||||
|
||||
double getYCoord();
|
||||
|
||||
double getZCoord();
|
||||
}
|
13
src/api/java/buildcraft/api/power/ILaserTargetBlock.java
Normal file
13
src/api/java/buildcraft/api/power/ILaserTargetBlock.java
Normal file
|
@ -0,0 +1,13 @@
|
|||
/**
|
||||
* 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;
|
||||
|
||||
public interface ILaserTargetBlock {
|
||||
|
||||
}
|
23
src/api/java/buildcraft/api/power/IPowerEmitter.java
Normal file
23
src/api/java/buildcraft/api/power/IPowerEmitter.java
Normal file
|
@ -0,0 +1,23 @@
|
|||
/**
|
||||
* 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.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.
|
||||
*/
|
||||
@Deprecated
|
||||
public interface IPowerEmitter {
|
||||
|
||||
boolean canEmitPowerFrom(ForgeDirection side);
|
||||
}
|
47
src/api/java/buildcraft/api/power/IPowerReceptor.java
Normal file
47
src/api/java/buildcraft/api/power/IPowerReceptor.java
Normal file
|
@ -0,0 +1,47 @@
|
|||
/**
|
||||
* 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.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
/**
|
||||
* This interface should be implemented by any Tile Entity that wishes to be
|
||||
* able to receive power.
|
||||
*/
|
||||
@Deprecated
|
||||
public interface IPowerReceptor {
|
||||
|
||||
/**
|
||||
* Get the PowerReceiver for this side of the block. You can return the same
|
||||
* PowerReceiver for all sides or one for each side.
|
||||
*
|
||||
* You should NOT return null to this method unless you mean to NEVER
|
||||
* receive power from that side. Returning null, after previous returning a
|
||||
* PowerReceiver, will most likely cause pipe connections to derp out and
|
||||
* engines to eventually explode.
|
||||
*
|
||||
* @param side
|
||||
* @return
|
||||
*/
|
||||
PowerHandler.PowerReceiver getPowerReceiver(ForgeDirection side);
|
||||
|
||||
/**
|
||||
* Call back from the PowerHandler that is called when the stored power
|
||||
* exceeds the activation power.
|
||||
*
|
||||
* It can be triggered by update() calls or power modification calls.
|
||||
*
|
||||
* @param workProvider
|
||||
*/
|
||||
void doWork(PowerHandler workProvider);
|
||||
|
||||
World getWorld();
|
||||
}
|
493
src/api/java/buildcraft/api/power/PowerHandler.java
Normal file
493
src/api/java/buildcraft/api/power/PowerHandler.java
Normal file
|
@ -0,0 +1,493 @@
|
|||
/**
|
||||
* 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.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import buildcraft.api.core.SafeTimeTracker;
|
||||
|
||||
/**
|
||||
* The PowerHandler is similar to FluidTank in that it holds your power and
|
||||
* allows standardized interaction between machines.
|
||||
*
|
||||
* To receive power to your machine you needs create an instance of PowerHandler
|
||||
* and implement IPowerReceptor on the TileEntity.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
@Deprecated
|
||||
public final class PowerHandler {
|
||||
|
||||
public static enum Type {
|
||||
|
||||
ENGINE, GATE, MACHINE, PIPE, STORAGE;
|
||||
|
||||
public boolean canReceiveFromPipes() {
|
||||
switch (this) {
|
||||
case MACHINE:
|
||||
case STORAGE:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean eatsEngineExcess() {
|
||||
switch (this) {
|
||||
case MACHINE:
|
||||
case STORAGE:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extend this class to create custom Perdition algorithms (its not final).
|
||||
*
|
||||
* NOTE: It is not possible to create a Zero perdition algorithm.
|
||||
*/
|
||||
public static class PerditionCalculator {
|
||||
|
||||
public static final float DEFAULT_POWERLOSS = 1F;
|
||||
public static final float MIN_POWERLOSS = 0.01F;
|
||||
private final double powerLoss;
|
||||
|
||||
public PerditionCalculator() {
|
||||
powerLoss = DEFAULT_POWERLOSS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple constructor for simple Perdition per tick.
|
||||
*
|
||||
* @param powerLoss power loss per tick
|
||||
*/
|
||||
public PerditionCalculator(double iPowerLoss) {
|
||||
if (iPowerLoss < MIN_POWERLOSS) {
|
||||
powerLoss = iPowerLoss;
|
||||
} else {
|
||||
powerLoss = MIN_POWERLOSS;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the perdition algorithm to the current stored energy. This
|
||||
* function can only be called once per tick, but it might not be called
|
||||
* 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
|
||||
* @return
|
||||
*/
|
||||
public double applyPerdition(PowerHandler powerHandler, double current, long ticksPassed) {
|
||||
double result = current;
|
||||
|
||||
result -= powerLoss * ticksPassed;
|
||||
if (result < 0) {
|
||||
result = 0;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Taxes a flat rate on all incoming power.
|
||||
*
|
||||
* Defaults to 0% tax rate.
|
||||
*
|
||||
* @return percent of input to tax
|
||||
*/
|
||||
public double getTaxPercent() {
|
||||
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 final int[] powerSources = new int[6];
|
||||
public final IPowerReceptor receptor;
|
||||
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();
|
||||
private PerditionCalculator perdition;
|
||||
private final PowerReceiver receiver;
|
||||
private final Type type;
|
||||
// Tracking
|
||||
private double averageLostPower = 0;
|
||||
private double averageReceivedPower = 0;
|
||||
private double averageUsedPower = 0;
|
||||
|
||||
public PowerHandler(IPowerReceptor receptor, Type type) {
|
||||
this.receptor = receptor;
|
||||
this.type = type;
|
||||
this.receiver = new PowerReceiver();
|
||||
this.perdition = DEFAULT_PERDITION;
|
||||
}
|
||||
|
||||
public PowerReceiver getPowerReceiver() {
|
||||
return receiver;
|
||||
}
|
||||
|
||||
public double getMinEnergyReceived() {
|
||||
return minEnergyReceived;
|
||||
}
|
||||
|
||||
public double getMaxEnergyReceived() {
|
||||
return maxEnergyReceived;
|
||||
}
|
||||
|
||||
public double getMaxEnergyStored() {
|
||||
return maxEnergyStored;
|
||||
}
|
||||
|
||||
public double getActivationEnergy() {
|
||||
return activationEnergy;
|
||||
}
|
||||
|
||||
public double getEnergyStored() {
|
||||
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 iMaxEnergyReceived
|
||||
* 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 iMinEnergyReceived, double iMaxEnergyReceived, double iActivationEnergy,
|
||||
double iMaxStoredEnergy) {
|
||||
|
||||
if (iMinEnergyReceived > maxEnergyReceived) {
|
||||
maxEnergyReceived = iMinEnergyReceived;
|
||||
} else {
|
||||
maxEnergyReceived = iMaxEnergyReceived;
|
||||
}
|
||||
|
||||
minEnergyReceived = iMinEnergyReceived;
|
||||
maxEnergyStored = iMaxStoredEnergy;
|
||||
activationEnergy = iActivationEnergy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows you define perdition in terms of loss/ticks.
|
||||
*
|
||||
* This function is mostly for legacy implementations. See
|
||||
* PerditionCalculator for more complex perdition formulas.
|
||||
*
|
||||
* @param powerLoss
|
||||
* @param powerLossRegularity
|
||||
* @see PerditionCalculator
|
||||
*/
|
||||
public void configurePowerPerdition(int powerLoss, int powerLossRegularity) {
|
||||
if (powerLoss == 0 || powerLossRegularity == 0) {
|
||||
perdition = new PerditionCalculator(0);
|
||||
return;
|
||||
}
|
||||
perdition = new PerditionCalculator((float) powerLoss / (float) powerLossRegularity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows you to define a new PerditionCalculator class to handler perdition
|
||||
* calculations.
|
||||
*
|
||||
* For example if you want exponentially increasing loss based on amount
|
||||
* stored.
|
||||
*
|
||||
* @param iPerdition
|
||||
*/
|
||||
public void setPerdition(PerditionCalculator iPerdition) {
|
||||
if (iPerdition == null) {
|
||||
perdition = DEFAULT_PERDITION;
|
||||
} else {
|
||||
perdition = iPerdition;
|
||||
}
|
||||
}
|
||||
|
||||
public PerditionCalculator getPerdition() {
|
||||
if (perdition == null) {
|
||||
return DEFAULT_PERDITION;
|
||||
}
|
||||
return perdition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ticks the power handler. You should call this if you can, but its not
|
||||
* required.
|
||||
*
|
||||
* 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
|
||||
* design around this though if you are aware of the limitations.
|
||||
*/
|
||||
public void update() {
|
||||
applyPerdition();
|
||||
applyWork();
|
||||
validateEnergy();
|
||||
}
|
||||
|
||||
private void applyPerdition() {
|
||||
if (perditionTracker.markTimeIfDelay(receptor.getWorld(), 1) && energyStored > 0) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
private void applyWork() {
|
||||
if (energyStored >= activationEnergy) {
|
||||
if (doWorkTracker.markTimeIfDelay(receptor.getWorld(), 1)) {
|
||||
receptor.doWork(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateSources(ForgeDirection source) {
|
||||
if (sourcesTracker.markTimeIfDelay(receptor.getWorld(), 1)) {
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
powerSources[i] -= sourcesTracker.durationOfLastDelay();
|
||||
if (powerSources[i] < 0) {
|
||||
powerSources[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (source != null) {
|
||||
powerSources[source.ordinal()] = 10;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract energy from the PowerHandler. You must call this even if doWork()
|
||||
* triggers.
|
||||
*
|
||||
* @param min
|
||||
* @param max
|
||||
* @param doUse
|
||||
* @return amount used
|
||||
*/
|
||||
public double useEnergy(double min, double max, boolean doUse) {
|
||||
applyPerdition();
|
||||
|
||||
double result = 0;
|
||||
|
||||
if (energyStored >= min) {
|
||||
if (energyStored <= max) {
|
||||
result = energyStored;
|
||||
if (doUse) {
|
||||
energyStored = 0;
|
||||
}
|
||||
} else {
|
||||
result = max;
|
||||
if (doUse) {
|
||||
energyStored -= max;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
validateEnergy();
|
||||
|
||||
if (doUse) {
|
||||
averageUsedPower = (averageUsedPower * ROLLING_AVERAGE_NUMERATOR + result) * ROLLING_AVERAGE_DENOMINATOR;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound data) {
|
||||
readFromNBT(data, "powerProvider");
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound data, String tag) {
|
||||
NBTTagCompound nbt = data.getCompoundTag(tag);
|
||||
energyStored = nbt.getDouble("energyStored");
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound data) {
|
||||
writeToNBT(data, "powerProvider");
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound data, String tag) {
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
nbt.setDouble("energyStored", energyStored);
|
||||
data.setTag(tag, nbt);
|
||||
}
|
||||
|
||||
public final class PowerReceiver {
|
||||
|
||||
private PowerReceiver() {
|
||||
}
|
||||
|
||||
public double getMinEnergyReceived() {
|
||||
return minEnergyReceived;
|
||||
}
|
||||
|
||||
public double getMaxEnergyReceived() {
|
||||
return maxEnergyReceived;
|
||||
}
|
||||
|
||||
public double getMaxEnergyStored() {
|
||||
return maxEnergyStored;
|
||||
}
|
||||
|
||||
public double getActivationEnergy() {
|
||||
return activationEnergy;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public void update() {
|
||||
PowerHandler.this.update();
|
||||
}
|
||||
|
||||
/**
|
||||
* The amount of power that this PowerHandler currently needs.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public double powerRequest() {
|
||||
update();
|
||||
return Math.min(maxEnergyReceived, maxEnergyStored - energyStored);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add power to the PowerReceiver from an external source.
|
||||
*
|
||||
* IPowerEmitters are responsible for calling this themselves.
|
||||
*
|
||||
* @param quantity
|
||||
* @param from
|
||||
* @return the amount of power used
|
||||
*/
|
||||
public double receiveEnergy(Type source, final double quantity, ForgeDirection from) {
|
||||
double used = quantity;
|
||||
if (source == Type.ENGINE) {
|
||||
if (used < minEnergyReceived) {
|
||||
return 0;
|
||||
} else if (used > maxEnergyReceived) {
|
||||
used = maxEnergyReceived;
|
||||
}
|
||||
}
|
||||
|
||||
updateSources(from);
|
||||
|
||||
used -= used * getPerdition().getTaxPercent();
|
||||
|
||||
used = addEnergy(used);
|
||||
|
||||
applyWork();
|
||||
|
||||
if (source == Type.ENGINE && type.eatsEngineExcess()) {
|
||||
used = Math.min(quantity, maxEnergyReceived);
|
||||
}
|
||||
|
||||
averageReceivedPower = (averageReceivedPower * ROLLING_AVERAGE_NUMERATOR + used) * ROLLING_AVERAGE_DENOMINATOR;
|
||||
|
||||
return used;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the amount the power changed by
|
||||
*/
|
||||
public double addEnergy(double iQuantity) {
|
||||
energyStored += iQuantity;
|
||||
|
||||
double added = iQuantity;
|
||||
|
||||
if (energyStored > maxEnergyStored) {
|
||||
added -= energyStored - maxEnergyStored;
|
||||
energyStored = maxEnergyStored;
|
||||
} else if (energyStored < 0) {
|
||||
added -= energyStored;
|
||||
energyStored = 0;
|
||||
}
|
||||
|
||||
applyPerdition();
|
||||
|
||||
return added;
|
||||
}
|
||||
|
||||
public void setEnergy(double quantity) {
|
||||
this.energyStored = quantity;
|
||||
validateEnergy();
|
||||
}
|
||||
|
||||
public boolean isPowerSource(ForgeDirection from) {
|
||||
return powerSources[from.ordinal()] != 0;
|
||||
}
|
||||
|
||||
private void validateEnergy() {
|
||||
if (energyStored < 0) {
|
||||
energyStored = 0;
|
||||
}
|
||||
if (energyStored > maxEnergyStored) {
|
||||
energyStored = maxEnergyStored;
|
||||
}
|
||||
}
|
||||
}
|
3
src/api/java/buildcraft/api/power/package-info.java
Normal file
3
src/api/java/buildcraft/api/power/package-info.java
Normal file
|
@ -0,0 +1,3 @@
|
|||
@API(apiVersion = "1.1", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|power")
|
||||
package buildcraft.api.power;
|
||||
import cpw.mods.fml.common.API;
|
|
@ -1,37 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
|
||||
* http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
package buildcraft.api.recipes;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IAssemblyRecipeManager {
|
||||
|
||||
/**
|
||||
* Add an Assembly Table recipe.
|
||||
*
|
||||
* @param input
|
||||
* Object... containing either an ItemStack, or a paired string
|
||||
* and integer(ex: "dyeBlue", 1)
|
||||
* @param energyCost
|
||||
* RF cost to produce
|
||||
* @param output
|
||||
* resulting ItemStack
|
||||
*/
|
||||
void addRecipe(String id, int energyCost, ItemStack output, Object... input);
|
||||
|
||||
void addRecipe(IFlexibleRecipe<ItemStack> recipe);
|
||||
|
||||
void removeRecipe(String id);
|
||||
|
||||
void removeRecipe(IFlexibleRecipe<ItemStack> recipe);
|
||||
|
||||
Collection<IFlexibleRecipe<ItemStack>> getRecipes();
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package buildcraft.api.recipes;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* This class is intended for mods such as Not Enough Items
|
||||
* in order for them to be able to look inside a recipe.
|
||||
*
|
||||
* It is intentionally left as a separate interface, so that
|
||||
* it remains possible to register a "dynamic" flexible
|
||||
* recipe which does not have static inputs and outputs.
|
||||
*
|
||||
* @author asie
|
||||
*/
|
||||
public interface IFlexibleRecipeViewable {
|
||||
Object getOutput();
|
||||
|
||||
/**
|
||||
* With BuildCraft's implementation (as of 6.1.3), this might
|
||||
* contain either an ItemStack, a List<ItemStack> or a FluidStack.
|
||||
*/
|
||||
Collection<Object> getInputs();
|
||||
|
||||
long getCraftingTime();
|
||||
|
||||
int getEnergyCost();
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
|
||||
* http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
package buildcraft.api.recipes;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* The Integration Table's primary purpose is to modify an input item's NBT
|
||||
* data. As such its not a "traditional" type of recipe. Rather than predefined
|
||||
* inputs and outputs, it takes an input and transforms it.
|
||||
*/
|
||||
public interface IIntegrationRecipeManager {
|
||||
|
||||
public interface IIntegrationRecipe {
|
||||
|
||||
double getEnergyCost();
|
||||
|
||||
boolean isValidInputA(ItemStack inputA);
|
||||
|
||||
boolean isValidInputB(ItemStack inputB);
|
||||
|
||||
ItemStack getOutputForInputs(ItemStack inputA, ItemStack inputB, ItemStack[] components);
|
||||
|
||||
ItemStack[] getComponents();
|
||||
|
||||
ItemStack[] getExampleInputsA();
|
||||
|
||||
ItemStack[] getExampleInputsB();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an Integration Table recipe.
|
||||
*
|
||||
*/
|
||||
void addRecipe(IIntegrationRecipe recipe);
|
||||
|
||||
List<? extends IIntegrationRecipe> getRecipes();
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
|
||||
* http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
package buildcraft.api.recipes;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
public interface IRefineryRecipeManager {
|
||||
|
||||
void addRecipe(String id, FluidStack ingredient, FluidStack result, int energy, int delay);
|
||||
|
||||
void addRecipe(String id, FluidStack ingredient1, FluidStack ingredient2, FluidStack result, int energy, int delay);
|
||||
|
||||
void removeRecipe(String id);
|
||||
|
||||
void removeRecipe(IFlexibleRecipe<FluidStack> recipe);
|
||||
|
||||
Collection<IFlexibleRecipe<FluidStack>> getRecipes();
|
||||
|
||||
IFlexibleRecipe<FluidStack> getRecipe(String currentRecipeId);
|
||||
|
||||
}
|
13
src/api/java/buildcraft/api/statements/ActionState.java
Normal file
13
src/api/java/buildcraft/api/statements/ActionState.java
Normal file
|
@ -0,0 +1,13 @@
|
|||
/**
|
||||
* 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.statements;
|
||||
|
||||
public class ActionState {
|
||||
|
||||
}
|
18
src/api/java/buildcraft/api/statements/IActionExternal.java
Normal file
18
src/api/java/buildcraft/api/statements/IActionExternal.java
Normal file
|
@ -0,0 +1,18 @@
|
|||
/**
|
||||
* 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.statements;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public interface IActionExternal extends IStatement {
|
||||
|
||||
void actionActivate(TileEntity target, ForgeDirection side, IStatementContainer source, IStatementParameter[] parameters);
|
||||
|
||||
}
|
15
src/api/java/buildcraft/api/statements/IActionInternal.java
Normal file
15
src/api/java/buildcraft/api/statements/IActionInternal.java
Normal file
|
@ -0,0 +1,15 @@
|
|||
/**
|
||||
* 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.statements;
|
||||
|
||||
public interface IActionInternal extends IStatement {
|
||||
|
||||
void actionActivate(IStatementContainer source, IStatementParameter[] parameters);
|
||||
|
||||
}
|
28
src/api/java/buildcraft/api/statements/IActionProvider.java
Normal file
28
src/api/java/buildcraft/api/statements/IActionProvider.java
Normal file
|
@ -0,0 +1,28 @@
|
|||
/**
|
||||
* 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.statements;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public interface IActionProvider {
|
||||
|
||||
/**
|
||||
* Returns the list of actions that are available from the statement container holding the
|
||||
* gate.
|
||||
*/
|
||||
Collection<IActionInternal> getInternalActions(IStatementContainer container);
|
||||
|
||||
/**
|
||||
* Returns the list of actions available to a gate next to the given block.
|
||||
*/
|
||||
Collection<IActionExternal> getExternalActions(ForgeDirection side, TileEntity tile);
|
||||
}
|
13
src/api/java/buildcraft/api/statements/IActionReceptor.java
Normal file
13
src/api/java/buildcraft/api/statements/IActionReceptor.java
Normal file
|
@ -0,0 +1,13 @@
|
|||
/**
|
||||
* 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.statements;
|
||||
|
||||
public interface IActionReceptor {
|
||||
void actionActivated(IStatement statement, IStatementParameter[] parameters);
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
/**
|
||||
* 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.statements;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IOverrideDefaultStatements {
|
||||
List<ITriggerExternal> overrideTriggers();
|
||||
List<IActionExternal> overrideActions();
|
||||
}
|
58
src/api/java/buildcraft/api/statements/IStatement.java
Normal file
58
src/api/java/buildcraft/api/statements/IStatement.java
Normal file
|
@ -0,0 +1,58 @@
|
|||
/**
|
||||
* 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.statements;
|
||||
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.util.IIcon;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public interface IStatement {
|
||||
|
||||
/**
|
||||
* Every trigger needs a unique tag, it should be in the format of
|
||||
* "<modid>:<name>".
|
||||
*
|
||||
* @return the unique id
|
||||
*/
|
||||
String getUniqueTag();
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
IIcon getIcon();
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
void registerIcons(IIconRegister iconRegister);
|
||||
|
||||
/**
|
||||
* Return the maximum number of parameter this trigger can have, 0 if none.
|
||||
*/
|
||||
int maxParameters();
|
||||
|
||||
/**
|
||||
* Return the minimum number of parameter this trigger can have, 0 if none.
|
||||
*/
|
||||
int minParameters();
|
||||
|
||||
/**
|
||||
* Return the trigger description in the UI
|
||||
*/
|
||||
String getDescription();
|
||||
|
||||
/**
|
||||
* Create parameters for the trigger.
|
||||
*/
|
||||
IStatementParameter createParameter(int index);
|
||||
|
||||
/**
|
||||
* This returns the trigger after a left rotation. Used in particular in
|
||||
* blueprints orientation.
|
||||
*/
|
||||
IStatement rotateLeft();
|
||||
}
|
19
src/api/java/buildcraft/api/recipes/IFlexibleRecipe.java → src/api/java/buildcraft/api/statements/IStatementContainer.java
Executable file → Normal file
19
src/api/java/buildcraft/api/recipes/IFlexibleRecipe.java → src/api/java/buildcraft/api/statements/IStatementContainer.java
Executable file → Normal file
|
@ -6,17 +6,14 @@
|
|||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
package buildcraft.api.recipes;
|
||||
package buildcraft.api.statements;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
public interface IFlexibleRecipe<T> {
|
||||
|
||||
boolean canBeCrafted(IFlexibleCrafter crafter);
|
||||
|
||||
CraftingResult<T> craft(IFlexibleCrafter crafter, boolean preview);
|
||||
|
||||
CraftingResult<T> canCraft(ItemStack expectedOutput);
|
||||
|
||||
String getId();
|
||||
/**
|
||||
* This is implemented by objects containing Statements, such as
|
||||
* Gates and TileEntities.
|
||||
*/
|
||||
public interface IStatementContainer {
|
||||
TileEntity getTile();
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/**
|
||||
* 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.statements;
|
||||
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.IIcon;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public interface IStatementParameter {
|
||||
|
||||
/**
|
||||
* Every parameter needs a unique tag, it should be in the format of
|
||||
* "<modid>:<name>".
|
||||
*
|
||||
* @return the unique id
|
||||
*/
|
||||
String getUniqueTag();
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
IIcon getIcon();
|
||||
|
||||
ItemStack getItemStack();
|
||||
|
||||
/**
|
||||
* Something that is initially unintuitive: you HAVE to
|
||||
* keep your icons as static variables, due to the fact
|
||||
* that every IStatementParameter is instantiated upon creation,
|
||||
* in opposition to IStatements which are singletons (due to the
|
||||
* fact that they, unlike Parameters, store no additional data)
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
void registerIcons(IIconRegister iconRegister);
|
||||
|
||||
/**
|
||||
* Return the parameter description in the UI
|
||||
*/
|
||||
String getDescription();
|
||||
|
||||
void onClick(IStatementContainer source, IStatement stmt, ItemStack stack, StatementMouseClick mouse);
|
||||
|
||||
void readFromNBT(NBTTagCompound compound);
|
||||
|
||||
void writeToNBT(NBTTagCompound compound);
|
||||
|
||||
/**
|
||||
* This returns the parameter after a left rotation. Used in particular in
|
||||
* blueprints orientation.
|
||||
*/
|
||||
IStatementParameter rotateLeft();
|
||||
}
|
18
src/api/java/buildcraft/api/statements/ITriggerExternal.java
Normal file
18
src/api/java/buildcraft/api/statements/ITriggerExternal.java
Normal file
|
@ -0,0 +1,18 @@
|
|||
/**
|
||||
* 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.statements;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public interface ITriggerExternal extends IStatement {
|
||||
|
||||
boolean isTriggerActive(TileEntity target, ForgeDirection side, IStatementContainer source, IStatementParameter[] parameters);
|
||||
|
||||
}
|
15
src/api/java/buildcraft/api/statements/ITriggerInternal.java
Normal file
15
src/api/java/buildcraft/api/statements/ITriggerInternal.java
Normal file
|
@ -0,0 +1,15 @@
|
|||
/**
|
||||
* 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.statements;
|
||||
|
||||
public interface ITriggerInternal extends IStatement {
|
||||
|
||||
boolean isTriggerActive(IStatementContainer source, IStatementParameter[] parameters);
|
||||
|
||||
}
|
28
src/api/java/buildcraft/api/statements/ITriggerProvider.java
Normal file
28
src/api/java/buildcraft/api/statements/ITriggerProvider.java
Normal file
|
@ -0,0 +1,28 @@
|
|||
/**
|
||||
* 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.statements;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public interface ITriggerProvider {
|
||||
|
||||
/**
|
||||
* Returns the list of triggers that are available from the object holding the gate.
|
||||
*/
|
||||
Collection<ITriggerInternal> getInternalTriggers(IStatementContainer container);
|
||||
|
||||
/**
|
||||
* Returns the list of triggers available to a gate next to the given block.
|
||||
*/
|
||||
Collection<ITriggerExternal> getExternalTriggers(ForgeDirection side, TileEntity tile);
|
||||
|
||||
}
|
180
src/api/java/buildcraft/api/statements/StatementManager.java
Normal file
180
src/api/java/buildcraft/api/statements/StatementManager.java
Normal file
|
@ -0,0 +1,180 @@
|
|||
/**
|
||||
* 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.statements;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public final class StatementManager {
|
||||
|
||||
public static Map<String, IStatement> statements = new HashMap<String, IStatement>();
|
||||
public static Map<String, Class<? extends IStatementParameter>> parameters = new HashMap<String, Class<? extends IStatementParameter>>();
|
||||
private static List<ITriggerProvider> triggerProviders = new LinkedList<ITriggerProvider>();
|
||||
private static List<IActionProvider> actionProviders = new LinkedList<IActionProvider>();
|
||||
|
||||
/**
|
||||
* Deactivate constructor
|
||||
*/
|
||||
private StatementManager() {
|
||||
}
|
||||
|
||||
public static void registerTriggerProvider(ITriggerProvider provider) {
|
||||
if (provider != null && !triggerProviders.contains(provider)) {
|
||||
triggerProviders.add(provider);
|
||||
}
|
||||
}
|
||||
|
||||
public static void registerActionProvider(IActionProvider provider) {
|
||||
if (provider != null && !actionProviders.contains(provider)) {
|
||||
actionProviders.add(provider);
|
||||
}
|
||||
}
|
||||
|
||||
public static void registerStatement(IStatement statement) {
|
||||
statements.put(statement.getUniqueTag(), statement);
|
||||
}
|
||||
|
||||
public static void registerParameterClass(Class<? extends IStatementParameter> param) {
|
||||
parameters.put(createParameter(param).getUniqueTag(), param);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void registerParameterClass(String name, Class<? extends IStatementParameter> param) {
|
||||
parameters.put(name, param);
|
||||
}
|
||||
|
||||
public static List<ITriggerExternal> getExternalTriggers(ForgeDirection side, TileEntity entity) {
|
||||
List<ITriggerExternal> result;
|
||||
|
||||
if (entity instanceof IOverrideDefaultStatements) {
|
||||
result = ((IOverrideDefaultStatements) entity).overrideTriggers();
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
result = new LinkedList<ITriggerExternal>();
|
||||
|
||||
for (ITriggerProvider provider : triggerProviders) {
|
||||
Collection<ITriggerExternal> toAdd = provider.getExternalTriggers(side, entity);
|
||||
|
||||
if (toAdd != null) {
|
||||
for (ITriggerExternal t : toAdd) {
|
||||
if (!result.contains(t)) {
|
||||
result.add(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<IActionExternal> getExternalActions(ForgeDirection side, TileEntity entity) {
|
||||
List<IActionExternal> result = new LinkedList<IActionExternal>();
|
||||
|
||||
if (entity instanceof IOverrideDefaultStatements) {
|
||||
result = ((IOverrideDefaultStatements) entity).overrideActions();
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
for (IActionProvider provider : actionProviders) {
|
||||
Collection<IActionExternal> toAdd = provider.getExternalActions(side, entity);
|
||||
|
||||
if (toAdd != null) {
|
||||
for (IActionExternal t : toAdd) {
|
||||
if (!result.contains(t)) {
|
||||
result.add(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<ITriggerInternal> getInternalTriggers(IStatementContainer container) {
|
||||
List<ITriggerInternal> result = new LinkedList<ITriggerInternal>();
|
||||
|
||||
for (ITriggerProvider provider : triggerProviders) {
|
||||
Collection<ITriggerInternal> toAdd = provider.getInternalTriggers(container);
|
||||
|
||||
if (toAdd != null) {
|
||||
for (ITriggerInternal t : toAdd) {
|
||||
if (!result.contains(t)) {
|
||||
result.add(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<IActionInternal> getInternalActions(IStatementContainer container) {
|
||||
List<IActionInternal> result = new LinkedList<IActionInternal>();
|
||||
|
||||
for (IActionProvider provider : actionProviders) {
|
||||
Collection<IActionInternal> toAdd = provider.getInternalActions(container);
|
||||
|
||||
if (toAdd != null) {
|
||||
for (IActionInternal t : toAdd) {
|
||||
if (!result.contains(t)) {
|
||||
result.add(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static IStatementParameter createParameter(String kind) {
|
||||
return createParameter(parameters.get(kind));
|
||||
}
|
||||
|
||||
private static IStatementParameter createParameter(Class<? extends IStatementParameter> param) {
|
||||
try {
|
||||
return param.newInstance();
|
||||
} catch (InstantiationException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generally, this function should be called by every mod implementing
|
||||
* the Statements API ***as a container*** (that is, adding its own gates)
|
||||
* on the client side from a given Item of choice.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void registerIcons(IIconRegister register) {
|
||||
for (IStatement statement : statements.values()) {
|
||||
statement.registerIcons(register);
|
||||
}
|
||||
|
||||
for (Class<? extends IStatementParameter> parameter : parameters.values()) {
|
||||
createParameter(parameter).registerIcons(register);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
/**
|
||||
* 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.statements;
|
||||
|
||||
public final class StatementMouseClick {
|
||||
private int button;
|
||||
private boolean shift;
|
||||
|
||||
public StatementMouseClick(int button, boolean shift) {
|
||||
this.button = button;
|
||||
this.shift = shift;
|
||||
}
|
||||
|
||||
public boolean isShift() {
|
||||
return shift;
|
||||
}
|
||||
|
||||
public int getButton() {
|
||||
return button;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
/**
|
||||
* 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.statements;
|
||||
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.IIcon;
|
||||
|
||||
public class StatementParameterItemStack implements IStatementParameter {
|
||||
|
||||
protected ItemStack stack;
|
||||
|
||||
@Override
|
||||
public IIcon getIcon() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemStack() {
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(IStatementContainer source, IStatement stmt, ItemStack stack, StatementMouseClick mouse) {
|
||||
if (stack != null) {
|
||||
this.stack = stack.copy();
|
||||
this.stack.stackSize = 1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound compound) {
|
||||
if (stack != null) {
|
||||
NBTTagCompound tagCompound = new NBTTagCompound();
|
||||
stack.writeToNBT(tagCompound);
|
||||
compound.setTag("stack", tagCompound);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
stack = ItemStack.loadItemStackFromNBT(compound.getCompoundTag("stack"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
if (object instanceof StatementParameterItemStack) {
|
||||
StatementParameterItemStack param = (StatementParameterItemStack) object;
|
||||
|
||||
return ItemStack.areItemStacksEqual(stack, param.stack)
|
||||
&& ItemStack.areItemStackTagsEqual(stack, param.stack);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
if (stack != null) {
|
||||
return stack.getDisplayName();
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUniqueTag() {
|
||||
return "buildcraft:stack";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerIcons(IIconRegister iconRegister) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStatementParameter rotateLeft() {
|
||||
return this;
|
||||
}
|
||||
}
|
12
src/api/java/buildcraft/api/statements/package-info.java
Normal file
12
src/api/java/buildcraft/api/statements/package-info.java
Normal file
|
@ -0,0 +1,12 @@
|
|||
/**
|
||||
* 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.0", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|statements")
|
||||
package buildcraft.api.statements;
|
||||
import cpw.mods.fml.common.API;
|
||||
|
0
src/api/java/buildcraft/api/transport/IExtractionHandler.java
Executable file → Normal file
0
src/api/java/buildcraft/api/transport/IExtractionHandler.java
Executable file → Normal file
0
src/api/java/buildcraft/api/transport/IPipe.java
Executable file → Normal file
0
src/api/java/buildcraft/api/transport/IPipe.java
Executable file → Normal file
32
src/api/java/buildcraft/api/transport/IPipePluggable.java
Normal file
32
src/api/java/buildcraft/api/transport/IPipePluggable.java
Normal file
|
@ -0,0 +1,32 @@
|
|||
/**
|
||||
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
|
||||
* http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
package buildcraft.api.transport;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public interface IPipePluggable {
|
||||
void writeToNBT(NBTTagCompound nbt);
|
||||
|
||||
void readFromNBT(NBTTagCompound nbt);
|
||||
|
||||
ItemStack[] getDropItems(IPipeTile pipe);
|
||||
|
||||
void onAttachedPipe(IPipeTile pipe, ForgeDirection direction);
|
||||
|
||||
void onDetachedPipe(IPipeTile pipe, ForgeDirection direction);
|
||||
|
||||
boolean blocking(IPipeTile pipe, ForgeDirection direction);
|
||||
|
||||
void invalidate();
|
||||
|
||||
void validate(IPipeTile pipe, ForgeDirection direction);
|
||||
}
|
0
src/api/java/buildcraft/api/transport/PipeManager.java
Executable file → Normal file
0
src/api/java/buildcraft/api/transport/PipeManager.java
Executable file → Normal file
Loading…
Reference in a new issue