diff --git a/src/api/java/buildcraft/api/core/BCLog.java b/src/api/java/buildcraft/api/core/BCLog.java index 158515059..4e5eada55 100644 --- a/src/api/java/buildcraft/api/core/BCLog.java +++ b/src/api/java/buildcraft/api/core/BCLog.java @@ -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(); diff --git a/src/api/java/buildcraft/api/core/ICoreProxy.java b/src/api/java/buildcraft/api/core/ICoreProxy.java old mode 100755 new mode 100644 diff --git a/src/api/java/buildcraft/api/core/IInvSlot.java b/src/api/java/buildcraft/api/core/IInvSlot.java index b4520485c..ec4918ce9 100644 --- a/src/api/java/buildcraft/api/core/IInvSlot.java +++ b/src/api/java/buildcraft/api/core/IInvSlot.java @@ -22,7 +22,7 @@ public interface IInvSlot { boolean canTakeStackFromSlot(ItemStack stack); - ItemStack decreaseStackInSlot(); + ItemStack decreaseStackInSlot(int amount); ItemStack getStackInSlot(); diff --git a/src/api/java/buildcraft/api/recipes/BuildcraftRecipes.java b/src/api/java/buildcraft/api/core/IWorldProperty.java similarity index 53% rename from src/api/java/buildcraft/api/recipes/BuildcraftRecipes.java rename to src/api/java/buildcraft/api/core/IWorldProperty.java index 0454944d2..4a900c621 100644 --- a/src/api/java/buildcraft/api/recipes/BuildcraftRecipes.java +++ b/src/api/java/buildcraft/api/core/IWorldProperty.java @@ -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(); } diff --git a/src/api/java/buildcraft/api/core/IZone.java b/src/api/java/buildcraft/api/core/IZone.java old mode 100755 new mode 100644 diff --git a/src/api/java/buildcraft/api/core/JavaTools.java b/src/api/java/buildcraft/api/core/JavaTools.java old mode 100755 new mode 100644 index bf2214b9e..e83a717df --- a/src/api/java/buildcraft/api/core/JavaTools.java +++ b/src/api/java/buildcraft/api/core/JavaTools.java @@ -50,10 +50,10 @@ public class JavaTools { return c; } - public static List getAllFields(Class clas) { + public static List getAllFields(Class clas) { List result = new ArrayList(); - 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 getAllMethods(Class clas) { + public static List getAllMethods(Class clas) { List result = new ArrayList(); - Class current = clas; + Class current = clas; while (current != null && current != Object.class) { for (Method m : current.getDeclaredMethods()) { diff --git a/src/api/java/buildcraft/api/core/WorldBlockIndex.java b/src/api/java/buildcraft/api/core/WorldBlockIndex.java old mode 100755 new mode 100644 diff --git a/src/api/java/buildcraft/api/gates/GateExpansionController.java b/src/api/java/buildcraft/api/gates/GateExpansionController.java new file mode 100644 index 000000000..5a9eca25d --- /dev/null +++ b/src/api/java/buildcraft/api/gates/GateExpansionController.java @@ -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 list) { + } + + public void addActions(List list) { + } + + public void writeToNBT(NBTTagCompound nbt) { + } + + public void readFromNBT(NBTTagCompound nbt) { + } +} diff --git a/src/api/java/buildcraft/api/gates/GateExpansions.java b/src/api/java/buildcraft/api/gates/GateExpansions.java new file mode 100644 index 000000000..c94b9b729 --- /dev/null +++ b/src/api/java/buildcraft/api/gates/GateExpansions.java @@ -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 expansions = new HashMap(); + private static final ArrayList expansionIDs = new ArrayList(); + + 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 getExpansions() { + Set set = new HashSet(); + 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); + } +} diff --git a/src/api/java/buildcraft/api/gates/IGateExpansion.java b/src/api/java/buildcraft/api/gates/IGateExpansion.java new file mode 100644 index 000000000..361f0a4dd --- /dev/null +++ b/src/api/java/buildcraft/api/gates/IGateExpansion.java @@ -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(); +} diff --git a/src/api/java/buildcraft/api/recipes/package-info.java b/src/api/java/buildcraft/api/gates/package-info.java similarity index 73% rename from src/api/java/buildcraft/api/recipes/package-info.java rename to src/api/java/buildcraft/api/gates/package-info.java index e7b4a170b..067e6edcf 100644 --- a/src/api/java/buildcraft/api/recipes/package-info.java +++ b/src/api/java/buildcraft/api/gates/package-info.java @@ -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; diff --git a/src/api/java/buildcraft/api/power/ILaserTarget.java b/src/api/java/buildcraft/api/power/ILaserTarget.java new file mode 100644 index 000000000..8d896cb80 --- /dev/null +++ b/src/api/java/buildcraft/api/power/ILaserTarget.java @@ -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(); +} diff --git a/src/api/java/buildcraft/api/power/ILaserTargetBlock.java b/src/api/java/buildcraft/api/power/ILaserTargetBlock.java new file mode 100644 index 000000000..71298b14b --- /dev/null +++ b/src/api/java/buildcraft/api/power/ILaserTargetBlock.java @@ -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 { + +} diff --git a/src/api/java/buildcraft/api/power/IPowerEmitter.java b/src/api/java/buildcraft/api/power/IPowerEmitter.java new file mode 100644 index 000000000..bdac3e4b7 --- /dev/null +++ b/src/api/java/buildcraft/api/power/IPowerEmitter.java @@ -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); +} diff --git a/src/api/java/buildcraft/api/power/IPowerReceptor.java b/src/api/java/buildcraft/api/power/IPowerReceptor.java new file mode 100644 index 000000000..5240ef744 --- /dev/null +++ b/src/api/java/buildcraft/api/power/IPowerReceptor.java @@ -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(); +} diff --git a/src/api/java/buildcraft/api/power/PowerHandler.java b/src/api/java/buildcraft/api/power/PowerHandler.java new file mode 100644 index 000000000..8ae21ad51 --- /dev/null +++ b/src/api/java/buildcraft/api/power/PowerHandler.java @@ -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; + } + } +} diff --git a/src/api/java/buildcraft/api/power/package-info.java b/src/api/java/buildcraft/api/power/package-info.java new file mode 100644 index 000000000..0a95496b7 --- /dev/null +++ b/src/api/java/buildcraft/api/power/package-info.java @@ -0,0 +1,3 @@ +@API(apiVersion = "1.1", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|power") +package buildcraft.api.power; +import cpw.mods.fml.common.API; diff --git a/src/api/java/buildcraft/api/recipes/IAssemblyRecipeManager.java b/src/api/java/buildcraft/api/recipes/IAssemblyRecipeManager.java deleted file mode 100644 index 6e2ddf89f..000000000 --- a/src/api/java/buildcraft/api/recipes/IAssemblyRecipeManager.java +++ /dev/null @@ -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 recipe); - - void removeRecipe(String id); - - void removeRecipe(IFlexibleRecipe recipe); - - Collection> getRecipes(); -} diff --git a/src/api/java/buildcraft/api/recipes/IFlexibleRecipeViewable.java b/src/api/java/buildcraft/api/recipes/IFlexibleRecipeViewable.java deleted file mode 100644 index 92a765a06..000000000 --- a/src/api/java/buildcraft/api/recipes/IFlexibleRecipeViewable.java +++ /dev/null @@ -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 or a FluidStack. - */ - Collection getInputs(); - - long getCraftingTime(); - - int getEnergyCost(); -} diff --git a/src/api/java/buildcraft/api/recipes/IIntegrationRecipeManager.java b/src/api/java/buildcraft/api/recipes/IIntegrationRecipeManager.java deleted file mode 100644 index 842b4436a..000000000 --- a/src/api/java/buildcraft/api/recipes/IIntegrationRecipeManager.java +++ /dev/null @@ -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 getRecipes(); -} diff --git a/src/api/java/buildcraft/api/recipes/IRefineryRecipeManager.java b/src/api/java/buildcraft/api/recipes/IRefineryRecipeManager.java deleted file mode 100644 index 4af07f49d..000000000 --- a/src/api/java/buildcraft/api/recipes/IRefineryRecipeManager.java +++ /dev/null @@ -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 recipe); - - Collection> getRecipes(); - - IFlexibleRecipe getRecipe(String currentRecipeId); - -} diff --git a/src/api/java/buildcraft/api/statements/ActionState.java b/src/api/java/buildcraft/api/statements/ActionState.java new file mode 100644 index 000000000..1a30beb4e --- /dev/null +++ b/src/api/java/buildcraft/api/statements/ActionState.java @@ -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 { + +} diff --git a/src/api/java/buildcraft/api/statements/IActionExternal.java b/src/api/java/buildcraft/api/statements/IActionExternal.java new file mode 100644 index 000000000..6bb0ad1bf --- /dev/null +++ b/src/api/java/buildcraft/api/statements/IActionExternal.java @@ -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); + +} diff --git a/src/api/java/buildcraft/api/statements/IActionInternal.java b/src/api/java/buildcraft/api/statements/IActionInternal.java new file mode 100644 index 000000000..21f2c7f86 --- /dev/null +++ b/src/api/java/buildcraft/api/statements/IActionInternal.java @@ -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); + +} diff --git a/src/api/java/buildcraft/api/statements/IActionProvider.java b/src/api/java/buildcraft/api/statements/IActionProvider.java new file mode 100644 index 000000000..761156f80 --- /dev/null +++ b/src/api/java/buildcraft/api/statements/IActionProvider.java @@ -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 getInternalActions(IStatementContainer container); + + /** + * Returns the list of actions available to a gate next to the given block. + */ + Collection getExternalActions(ForgeDirection side, TileEntity tile); +} diff --git a/src/api/java/buildcraft/api/statements/IActionReceptor.java b/src/api/java/buildcraft/api/statements/IActionReceptor.java new file mode 100644 index 000000000..f4ef4968b --- /dev/null +++ b/src/api/java/buildcraft/api/statements/IActionReceptor.java @@ -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); +} diff --git a/src/api/java/buildcraft/api/statements/IOverrideDefaultStatements.java b/src/api/java/buildcraft/api/statements/IOverrideDefaultStatements.java new file mode 100644 index 000000000..22d86ebc6 --- /dev/null +++ b/src/api/java/buildcraft/api/statements/IOverrideDefaultStatements.java @@ -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 overrideTriggers(); + List overrideActions(); +} diff --git a/src/api/java/buildcraft/api/statements/IStatement.java b/src/api/java/buildcraft/api/statements/IStatement.java new file mode 100644 index 000000000..a05824d66 --- /dev/null +++ b/src/api/java/buildcraft/api/statements/IStatement.java @@ -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 + * ":". + * + * @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(); +} diff --git a/src/api/java/buildcraft/api/recipes/IFlexibleRecipe.java b/src/api/java/buildcraft/api/statements/IStatementContainer.java old mode 100755 new mode 100644 similarity index 50% rename from src/api/java/buildcraft/api/recipes/IFlexibleRecipe.java rename to src/api/java/buildcraft/api/statements/IStatementContainer.java index f1dfec236..f258b3416 --- a/src/api/java/buildcraft/api/recipes/IFlexibleRecipe.java +++ b/src/api/java/buildcraft/api/statements/IStatementContainer.java @@ -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 { - - boolean canBeCrafted(IFlexibleCrafter crafter); - - CraftingResult craft(IFlexibleCrafter crafter, boolean preview); - - CraftingResult canCraft(ItemStack expectedOutput); - - String getId(); +/** + * This is implemented by objects containing Statements, such as + * Gates and TileEntities. + */ +public interface IStatementContainer { + TileEntity getTile(); } diff --git a/src/api/java/buildcraft/api/statements/IStatementParameter.java b/src/api/java/buildcraft/api/statements/IStatementParameter.java new file mode 100644 index 000000000..0bbc3dcb0 --- /dev/null +++ b/src/api/java/buildcraft/api/statements/IStatementParameter.java @@ -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 + * ":". + * + * @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(); +} diff --git a/src/api/java/buildcraft/api/statements/ITriggerExternal.java b/src/api/java/buildcraft/api/statements/ITriggerExternal.java new file mode 100644 index 000000000..9167761c4 --- /dev/null +++ b/src/api/java/buildcraft/api/statements/ITriggerExternal.java @@ -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); + +} diff --git a/src/api/java/buildcraft/api/statements/ITriggerInternal.java b/src/api/java/buildcraft/api/statements/ITriggerInternal.java new file mode 100644 index 000000000..750331b5a --- /dev/null +++ b/src/api/java/buildcraft/api/statements/ITriggerInternal.java @@ -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); + +} diff --git a/src/api/java/buildcraft/api/statements/ITriggerProvider.java b/src/api/java/buildcraft/api/statements/ITriggerProvider.java new file mode 100644 index 000000000..92c154218 --- /dev/null +++ b/src/api/java/buildcraft/api/statements/ITriggerProvider.java @@ -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 getInternalTriggers(IStatementContainer container); + + /** + * Returns the list of triggers available to a gate next to the given block. + */ + Collection getExternalTriggers(ForgeDirection side, TileEntity tile); + +} diff --git a/src/api/java/buildcraft/api/statements/StatementManager.java b/src/api/java/buildcraft/api/statements/StatementManager.java new file mode 100644 index 000000000..5718dc3b1 --- /dev/null +++ b/src/api/java/buildcraft/api/statements/StatementManager.java @@ -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 statements = new HashMap(); + public static Map> parameters = new HashMap>(); + private static List triggerProviders = new LinkedList(); + private static List actionProviders = new LinkedList(); + + /** + * 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 param) { + parameters.put(createParameter(param).getUniqueTag(), param); + } + + @Deprecated + public static void registerParameterClass(String name, Class param) { + parameters.put(name, param); + } + + public static List getExternalTriggers(ForgeDirection side, TileEntity entity) { + List result; + + if (entity instanceof IOverrideDefaultStatements) { + result = ((IOverrideDefaultStatements) entity).overrideTriggers(); + if (result != null) { + return result; + } + } + + result = new LinkedList(); + + for (ITriggerProvider provider : triggerProviders) { + Collection toAdd = provider.getExternalTriggers(side, entity); + + if (toAdd != null) { + for (ITriggerExternal t : toAdd) { + if (!result.contains(t)) { + result.add(t); + } + } + } + } + + return result; + } + + public static List getExternalActions(ForgeDirection side, TileEntity entity) { + List result = new LinkedList(); + + if (entity instanceof IOverrideDefaultStatements) { + result = ((IOverrideDefaultStatements) entity).overrideActions(); + if (result != null) { + return result; + } + } + + for (IActionProvider provider : actionProviders) { + Collection toAdd = provider.getExternalActions(side, entity); + + if (toAdd != null) { + for (IActionExternal t : toAdd) { + if (!result.contains(t)) { + result.add(t); + } + } + } + } + + return result; + } + + public static List getInternalTriggers(IStatementContainer container) { + List result = new LinkedList(); + + for (ITriggerProvider provider : triggerProviders) { + Collection toAdd = provider.getInternalTriggers(container); + + if (toAdd != null) { + for (ITriggerInternal t : toAdd) { + if (!result.contains(t)) { + result.add(t); + } + } + } + } + + return result; + } + + public static List getInternalActions(IStatementContainer container) { + List result = new LinkedList(); + + for (IActionProvider provider : actionProviders) { + Collection 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 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 parameter : parameters.values()) { + createParameter(parameter).registerIcons(register); + } + } +} diff --git a/src/api/java/buildcraft/api/statements/StatementMouseClick.java b/src/api/java/buildcraft/api/statements/StatementMouseClick.java new file mode 100644 index 000000000..d48ade5cd --- /dev/null +++ b/src/api/java/buildcraft/api/statements/StatementMouseClick.java @@ -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; + } +} diff --git a/src/api/java/buildcraft/api/statements/StatementParameterItemStack.java b/src/api/java/buildcraft/api/statements/StatementParameterItemStack.java new file mode 100644 index 000000000..02c796dbe --- /dev/null +++ b/src/api/java/buildcraft/api/statements/StatementParameterItemStack.java @@ -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; + } +} diff --git a/src/api/java/buildcraft/api/statements/package-info.java b/src/api/java/buildcraft/api/statements/package-info.java new file mode 100644 index 000000000..94d36f68e --- /dev/null +++ b/src/api/java/buildcraft/api/statements/package-info.java @@ -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; + diff --git a/src/api/java/buildcraft/api/transport/IExtractionHandler.java b/src/api/java/buildcraft/api/transport/IExtractionHandler.java old mode 100755 new mode 100644 diff --git a/src/api/java/buildcraft/api/transport/IPipe.java b/src/api/java/buildcraft/api/transport/IPipe.java old mode 100755 new mode 100644 diff --git a/src/api/java/buildcraft/api/transport/IPipePluggable.java b/src/api/java/buildcraft/api/transport/IPipePluggable.java new file mode 100644 index 000000000..b299d07f1 --- /dev/null +++ b/src/api/java/buildcraft/api/transport/IPipePluggable.java @@ -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); +} diff --git a/src/api/java/buildcraft/api/transport/PipeManager.java b/src/api/java/buildcraft/api/transport/PipeManager.java old mode 100755 new mode 100644