From 5e0dc25e2bea7439be6dee10d544c2b36fbde22d Mon Sep 17 00:00:00 2001 From: Ben Spiers Date: Tue, 8 Jul 2014 01:51:23 +0100 Subject: [PATCH] Update BC and IC2 APIs. Not updated Mek code to match yet. --- src/api/java/buildcraft/api/core/BCLog.java | 60 +++ .../java/buildcraft/api/core/BlockIndex.java | 104 +++++ .../buildcraft/api/core/BuildCraftAPI.java | 42 ++ .../buildcraft/api/core/IAreaProvider.java | 33 ++ src/api/java/buildcraft/api/core/IBox.java | 25 + .../java/buildcraft/api/core/ICoreProxy.java | 18 + .../buildcraft/api/core/IIconProvider.java | 32 ++ .../java/buildcraft/api/core/IInvSlot.java | 30 ++ .../buildcraft/api/core/IWorldProperty.java | 18 + .../java/buildcraft/api/core/JavaTools.java | 92 ++++ .../java/buildcraft/api/core/NetworkData.java | 19 + .../java/buildcraft/api/core/Position.java | 175 +++++++ .../buildcraft/api/core/SafeTimeTracker.java | 3 +- .../java/buildcraft/api/core/StackKey.java | 56 +++ .../buildcraft/api/core/package-info.java | 11 + .../api/fuels/IronEngineCoolant.java | 92 ++++ .../buildcraft/api/fuels/IronEngineFuel.java | 11 +- .../buildcraft/api/fuels/package-info.java | 12 +- .../java/buildcraft/api/mj/BatteryObject.java | 199 ++++++++ .../buildcraft/api/mj/IBatteryIOObject.java | 27 ++ .../buildcraft/api/mj/IBatteryObject.java | 77 +++ .../buildcraft/api/mj/IBatteryProvider.java | 13 + src/api/java/buildcraft/api/mj/IOMode.java | 30 ++ .../api/mj/ISidedBatteryProvider.java | 15 + src/api/java/buildcraft/api/mj/MjAPI.java | 439 ++++++++++++++++++ .../java/buildcraft/api/mj/MjAPILegacy.java | 60 +++ src/api/java/buildcraft/api/mj/MjBattery.java | 86 ++++ .../buildcraft/api/mj/MjReconfigurator.java | 183 ++++++++ .../java/buildcraft/api/mj/package-info.java | 11 + src/api/java/buildcraft/api/package-info.java | 12 +- .../buildcraft/api/power/ILaserTarget.java | 41 ++ .../buildcraft/api/power/IPowerEmitter.java | 3 +- .../buildcraft/api/power/IPowerReceptor.java | 8 +- .../buildcraft/api/power/PowerHandler.java | 243 ++++++---- .../buildcraft/api/power/package-info.java | 12 +- .../api/recipes/BuildcraftRecipeRegistry.java | 19 + .../api/recipes/CraftingResult.java | 25 + .../api/recipes/IAssemblyRecipeManager.java | 33 ++ .../api/recipes/IFlexibleCrafter.java | 29 ++ .../api/recipes/IFlexibleRecipe.java | 18 + .../api/recipes/IIntegrationRecipe.java | 19 + .../recipes/IIntegrationRecipeManager.java | 25 + .../api/recipes/IRefineryRecipeManager.java | 25 + .../buildcraft/api/recipes/package-info.java | 12 + .../buildcraft/api/tools/IToolWrench.java | 10 +- .../buildcraft/api/tools/package-info.java | 12 +- .../api/transport/IExtractionHandler.java | 29 ++ .../java/buildcraft/api/transport/IPipe.java | 26 ++ .../api/transport/IPipeConnection.java | 31 ++ .../api/transport/IPipePluggable.java | 32 ++ .../buildcraft/api/transport/IPipeTile.java | 5 +- .../buildcraft/api/transport/PipeManager.java | 49 ++ .../buildcraft/api/transport/PipeWire.java | 27 +- .../api/transport/package-info.java | 13 +- .../java/ic2/api/energy/tile/IEnergySink.java | 30 +- .../ic2/api/energy/tile/IEnergySource.java | 10 + .../ic2/api/info/IEnergyValueProvider.java | 2 +- src/api/java/ic2/api/item/ElectricItem.java | 97 +--- .../api/item/IBackupElectricItemManager.java | 12 + src/api/java/ic2/api/item/IElectricItem.java | 4 +- .../ic2/api/item/IElectricItemManager.java | 21 +- .../ic2/api/recipe/IFluidHeatManager.java | 32 ++ src/api/java/ic2/api/recipe/Recipes.java | 3 +- 63 files changed, 2702 insertions(+), 240 deletions(-) create mode 100644 src/api/java/buildcraft/api/core/BCLog.java create mode 100644 src/api/java/buildcraft/api/core/BlockIndex.java create mode 100644 src/api/java/buildcraft/api/core/BuildCraftAPI.java create mode 100644 src/api/java/buildcraft/api/core/IAreaProvider.java create mode 100644 src/api/java/buildcraft/api/core/IBox.java create mode 100755 src/api/java/buildcraft/api/core/ICoreProxy.java create mode 100644 src/api/java/buildcraft/api/core/IIconProvider.java create mode 100644 src/api/java/buildcraft/api/core/IInvSlot.java create mode 100755 src/api/java/buildcraft/api/core/IWorldProperty.java create mode 100755 src/api/java/buildcraft/api/core/JavaTools.java create mode 100644 src/api/java/buildcraft/api/core/NetworkData.java create mode 100644 src/api/java/buildcraft/api/core/Position.java create mode 100644 src/api/java/buildcraft/api/core/StackKey.java create mode 100644 src/api/java/buildcraft/api/core/package-info.java create mode 100644 src/api/java/buildcraft/api/fuels/IronEngineCoolant.java create mode 100755 src/api/java/buildcraft/api/mj/BatteryObject.java create mode 100644 src/api/java/buildcraft/api/mj/IBatteryIOObject.java create mode 100644 src/api/java/buildcraft/api/mj/IBatteryObject.java create mode 100644 src/api/java/buildcraft/api/mj/IBatteryProvider.java create mode 100644 src/api/java/buildcraft/api/mj/IOMode.java create mode 100644 src/api/java/buildcraft/api/mj/ISidedBatteryProvider.java create mode 100755 src/api/java/buildcraft/api/mj/MjAPI.java create mode 100644 src/api/java/buildcraft/api/mj/MjAPILegacy.java create mode 100755 src/api/java/buildcraft/api/mj/MjBattery.java create mode 100644 src/api/java/buildcraft/api/mj/MjReconfigurator.java create mode 100644 src/api/java/buildcraft/api/mj/package-info.java create mode 100644 src/api/java/buildcraft/api/power/ILaserTarget.java create mode 100644 src/api/java/buildcraft/api/recipes/BuildcraftRecipeRegistry.java create mode 100755 src/api/java/buildcraft/api/recipes/CraftingResult.java create mode 100644 src/api/java/buildcraft/api/recipes/IAssemblyRecipeManager.java create mode 100755 src/api/java/buildcraft/api/recipes/IFlexibleCrafter.java create mode 100755 src/api/java/buildcraft/api/recipes/IFlexibleRecipe.java create mode 100644 src/api/java/buildcraft/api/recipes/IIntegrationRecipe.java create mode 100644 src/api/java/buildcraft/api/recipes/IIntegrationRecipeManager.java create mode 100644 src/api/java/buildcraft/api/recipes/IRefineryRecipeManager.java create mode 100644 src/api/java/buildcraft/api/recipes/package-info.java create mode 100755 src/api/java/buildcraft/api/transport/IExtractionHandler.java create mode 100755 src/api/java/buildcraft/api/transport/IPipe.java create mode 100644 src/api/java/buildcraft/api/transport/IPipeConnection.java create mode 100755 src/api/java/buildcraft/api/transport/IPipePluggable.java create mode 100755 src/api/java/buildcraft/api/transport/PipeManager.java create mode 100644 src/api/java/ic2/api/item/IBackupElectricItemManager.java create mode 100644 src/api/java/ic2/api/recipe/IFluidHeatManager.java diff --git a/src/api/java/buildcraft/api/core/BCLog.java b/src/api/java/buildcraft/api/core/BCLog.java new file mode 100644 index 000000000..3ccdac2e4 --- /dev/null +++ b/src/api/java/buildcraft/api/core/BCLog.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.core; + +import java.lang.reflect.Method; +import java.util.logging.Level; +import java.util.logging.Logger; + +public final class BCLog { + + public static final Logger logger = Logger.getLogger("Buildcraft"); + + /** + * Deactivate constructor + */ + private BCLog() { + } + + public static void initLog() { + // TODO: check if the code below is still useful and remove otherwise. + //logger.setParent(FMLLog.getLogger()); + + logger.info("Starting BuildCraft " + getVersion()); + logger.info("Copyright (c) SpaceToad, 2011"); + logger.info("http://www.mod-buildcraft.com"); + } + + 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(); + if (stackTrace.length > 0) { + msg.append(", ").append(stackTrace[0]); + } + + logger.log(Level.SEVERE, msg.toString()); + + if (classFile != null) { + msg = new StringBuilder(mod); + msg.append(" API error: ").append(classFile.getSimpleName()).append(" is loaded from ").append(classFile.getProtectionDomain().getCodeSource().getLocation()); + logger.log(Level.SEVERE, msg.toString()); + } + } + + public static String getVersion() { + try { + Class clazz = Class.forName("buildcraft.core.Version"); + Method method = clazz.getDeclaredMethod("getVersion"); + return String.valueOf(method.invoke(null)); + } catch (Exception e) { + return "UNKNOWN VERSION"; + } + } +} diff --git a/src/api/java/buildcraft/api/core/BlockIndex.java b/src/api/java/buildcraft/api/core/BlockIndex.java new file mode 100644 index 000000000..6024155da --- /dev/null +++ b/src/api/java/buildcraft/api/core/BlockIndex.java @@ -0,0 +1,104 @@ +/** + * 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.core; + +import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; + +/** + * This class is a comparable container for block positions. TODO: should this be merged with position? + */ +public class BlockIndex implements Comparable { + + public int x; + public int y; + public int z; + + public BlockIndex() { + + } + + /** + * Creates an index for a block located on x, y. z + */ + public BlockIndex(int x, int y, int z) { + + this.x = x; + this.y = y; + this.z = z; + } + + public BlockIndex(NBTTagCompound c) { + this.x = c.getInteger("i"); + this.y = c.getInteger("j"); + this.z = c.getInteger("k"); + } + + public BlockIndex(Entity entity) { + x = (int) Math.floor(entity.posX); + y = (int) Math.floor(entity.posY); + z = (int) Math.floor(entity.posZ); + } + + /** + * Provides a deterministic and complete ordering of block positions. + */ + @Override + public int compareTo(BlockIndex o) { + + if (o.x < x) { + return 1; + } else if (o.x > x) { + return -1; + } else if (o.z < z) { + return 1; + } else if (o.z > z) { + return -1; + } else if (o.y < y) { + return 1; + } else if (o.y > y) { + return -1; + } else { + return 0; + } + } + + public void writeTo(NBTTagCompound c) { + c.setInteger("i", x); + c.setInteger("j", y); + c.setInteger("k", z); + } + + public Block getBlock(World world) { + return world.getBlock(x, y, z); + } + + @Override + public String toString() { + return "{" + x + ", " + y + ", " + z + "}"; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof BlockIndex) { + BlockIndex b = (BlockIndex) obj; + + return b.x == x && b.y == y && b.z == z; + } + + return super.equals(obj); + } + + @Override + public int hashCode() { + return (x * 37 + y) * 37 + z; + } +} diff --git a/src/api/java/buildcraft/api/core/BuildCraftAPI.java b/src/api/java/buildcraft/api/core/BuildCraftAPI.java new file mode 100644 index 000000000..5b788a6e8 --- /dev/null +++ b/src/api/java/buildcraft/api/core/BuildCraftAPI.java @@ -0,0 +1,42 @@ +/** + * 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.core; + +import java.util.HashSet; +import java.util.Set; + +import net.minecraft.block.Block; +import net.minecraft.world.World; + +public final class BuildCraftAPI { + + public static ICoreProxy proxy; + + public static final Set softBlocks = new HashSet(); + + public static IWorldProperty isSoftProperty; + public static IWorldProperty isWoodProperty; + public static IWorldProperty isLeavesProperty; + public static IWorldProperty isBasicOreProperty; + public static IWorldProperty isExtendedOreProperty; + public static IWorldProperty isHarvestableProperty; + public static IWorldProperty isFarmlandProperty; + public static IWorldProperty isDirtProperty; + public static IWorldProperty isShoveled; + + /** + * Deactivate constructor + */ + private BuildCraftAPI() { + } + + public static boolean isSoftBlock(World world, int x, int y, int z) { + return isSoftProperty.get(world, x, y, z); + } +} diff --git a/src/api/java/buildcraft/api/core/IAreaProvider.java b/src/api/java/buildcraft/api/core/IAreaProvider.java new file mode 100644 index 000000000..c0179caa1 --- /dev/null +++ b/src/api/java/buildcraft/api/core/IAreaProvider.java @@ -0,0 +1,33 @@ +/** + * 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.core; + +/** + * To be implemented by TileEntities able to provide a square area on the world, typically BuildCraft markers. + */ +public interface IAreaProvider { + + int xMin(); + + int yMin(); + + int zMin(); + + int xMax(); + + int yMax(); + + int zMax(); + + /** + * Remove from the world all objects used to define the area. + */ + void removeFromWorld(); + +} diff --git a/src/api/java/buildcraft/api/core/IBox.java b/src/api/java/buildcraft/api/core/IBox.java new file mode 100644 index 000000000..a79c0a7d6 --- /dev/null +++ b/src/api/java/buildcraft/api/core/IBox.java @@ -0,0 +1,25 @@ +/** + * 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.core; + +public interface IBox { + + IBox expand(int amount); + + IBox contract(int amount); + + boolean contains(double x, double y, double z); + + Position pMin(); + + Position pMax(); + + void createLaserData(); + +} diff --git a/src/api/java/buildcraft/api/core/ICoreProxy.java b/src/api/java/buildcraft/api/core/ICoreProxy.java new file mode 100755 index 000000000..b5132df97 --- /dev/null +++ b/src/api/java/buildcraft/api/core/ICoreProxy.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.core; + +import java.lang.ref.WeakReference; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.WorldServer; + +public interface ICoreProxy { + WeakReference getBuildCraftPlayer(WorldServer world); +} diff --git a/src/api/java/buildcraft/api/core/IIconProvider.java b/src/api/java/buildcraft/api/core/IIconProvider.java new file mode 100644 index 000000000..2734415d8 --- /dev/null +++ b/src/api/java/buildcraft/api/core/IIconProvider.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.core; + +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 IIconProvider { + + /** + * @param iconIndex + */ + @SideOnly(Side.CLIENT) + IIcon getIcon(int iconIndex); + + /** + * A call for the provider to register its Icons. This may be called multiple times but should only be executed once per provider + * @param iconRegister + */ + @SideOnly(Side.CLIENT) + void registerIcons(IIconRegister iconRegister); + +} diff --git a/src/api/java/buildcraft/api/core/IInvSlot.java b/src/api/java/buildcraft/api/core/IInvSlot.java new file mode 100644 index 000000000..ec4918ce9 --- /dev/null +++ b/src/api/java/buildcraft/api/core/IInvSlot.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.core; + +import net.minecraft.item.ItemStack; + +public interface IInvSlot { + /** + * Returns the slot number of the underlying Inventory. + * + * @return the slot number + */ + int getIndex(); + + boolean canPutStackInSlot(ItemStack stack); + + boolean canTakeStackFromSlot(ItemStack stack); + + ItemStack decreaseStackInSlot(int amount); + + ItemStack getStackInSlot(); + + void setStackInSlot(ItemStack stack); +} diff --git a/src/api/java/buildcraft/api/core/IWorldProperty.java b/src/api/java/buildcraft/api/core/IWorldProperty.java new file mode 100755 index 000000000..4a900c621 --- /dev/null +++ b/src/api/java/buildcraft/api/core/IWorldProperty.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.core; + +import net.minecraft.world.World; + +public interface IWorldProperty { + + boolean get(World world, int x, int y, int z); + + void clear(); +} diff --git a/src/api/java/buildcraft/api/core/JavaTools.java b/src/api/java/buildcraft/api/core/JavaTools.java new file mode 100755 index 000000000..e83a717df --- /dev/null +++ b/src/api/java/buildcraft/api/core/JavaTools.java @@ -0,0 +1,92 @@ +/** + * 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.core; + +import java.lang.reflect.Array; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class JavaTools { + public static double bounds(double value, double min, double max) { + return Math.max(min, Math.min(value, max)); + } + + public static T[] concat(T[] first, T[] second) { + T[] result = Arrays.copyOf(first, first.length + second.length); + System.arraycopy(second, 0, result, first.length, second.length); + return result; + } + + public static int[] concat(int[] first, int[] second) { + int[] result = Arrays.copyOf(first, first.length + second.length); + System.arraycopy(second, 0, result, first.length, second.length); + return result; + } + + public static float[] concat(float[] first, float[] second) { + float[] result = Arrays.copyOf(first, first.length + second.length); + System.arraycopy(second, 0, result, first.length, second.length); + return result; + } + + public T[] concatenate (T[] a, T[] b) { + int aLen = a.length; + int bLen = b.length; + + @SuppressWarnings("unchecked") + T[] c = (T[]) Array.newInstance(a.getClass().getComponentType(), aLen + bLen); + System.arraycopy(a, 0, c, 0, aLen); + System.arraycopy(b, 0, c, aLen, bLen); + + return c; + } + + public static List getAllFields(Class clas) { + List result = new ArrayList(); + + Class current = clas; + + while (current != null && current != Object.class) { + for (Field f : current.getDeclaredFields()) { + result.add(f); + } + + current = current.getSuperclass(); + } + + return result; + } + + public static List getAllMethods(Class clas) { + List result = new ArrayList(); + + Class current = clas; + + while (current != null && current != Object.class) { + for (Method m : current.getDeclaredMethods()) { + result.add(m); + } + + current = current.getSuperclass(); + } + + return result; + } + + public static String surroundWithQuotes(String stringToSurroundWithQuotes) { + return String.format("\"%s\"", stringToSurroundWithQuotes); + } + + public static String stripSurroundingQuotes(String stringToStripQuotes) { + return stringToStripQuotes.replaceAll("^\"|\"$", ""); + } +} diff --git a/src/api/java/buildcraft/api/core/NetworkData.java b/src/api/java/buildcraft/api/core/NetworkData.java new file mode 100644 index 000000000..5198f36d3 --- /dev/null +++ b/src/api/java/buildcraft/api/core/NetworkData.java @@ -0,0 +1,19 @@ +/** + * 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.core; + +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +@Inherited +public @interface NetworkData { + +} diff --git a/src/api/java/buildcraft/api/core/Position.java b/src/api/java/buildcraft/api/core/Position.java new file mode 100644 index 000000000..84e58e2b4 --- /dev/null +++ b/src/api/java/buildcraft/api/core/Position.java @@ -0,0 +1,175 @@ +/** + * 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.core; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; + +import net.minecraftforge.common.util.ForgeDirection; + +public class Position { + + @NetworkData + public double x, y, z; + + @NetworkData + public ForgeDirection orientation; + + public Position() { + x = 0; + y = 0; + z = 0; + orientation = ForgeDirection.UNKNOWN; + } + + public Position(double ci, double cj, double ck) { + x = ci; + y = cj; + z = ck; + orientation = ForgeDirection.UNKNOWN; + } + + public Position(double ci, double cj, double ck, ForgeDirection corientation) { + x = ci; + y = cj; + z = ck; + orientation = corientation; + + if (orientation == null) { + orientation = ForgeDirection.UNKNOWN; + } + } + + public Position(Position p) { + x = p.x; + y = p.y; + z = p.z; + orientation = p.orientation; + } + + public Position(NBTTagCompound nbttagcompound) { + readFromNBT(nbttagcompound); + } + + public Position(TileEntity tile) { + x = tile.xCoord; + y = tile.yCoord; + z = tile.zCoord; + orientation = ForgeDirection.UNKNOWN; + } + + public void moveRight(double step) { + switch (orientation) { + case SOUTH: + x = x - step; + break; + case NORTH: + x = x + step; + break; + case EAST: + z = z + step; + break; + case WEST: + z = z - step; + break; + default: + } + } + + public void moveLeft(double step) { + moveRight(-step); + } + + public void moveForwards(double step) { + switch (orientation) { + case UP: + y = y + step; + break; + case DOWN: + y = y - step; + break; + case SOUTH: + z = z + step; + break; + case NORTH: + z = z - step; + break; + case EAST: + x = x + step; + break; + case WEST: + x = x - step; + break; + default: + } + } + + public void moveBackwards(double step) { + moveForwards(-step); + } + + public void moveUp(double step) { + switch (orientation) { + case SOUTH: + case NORTH: + case EAST: + case WEST: + y = y + step; + break; + default: + } + + } + + public void moveDown(double step) { + moveUp(-step); + } + + public void writeToNBT(NBTTagCompound nbttagcompound) { + if (orientation == null) { + orientation = ForgeDirection.UNKNOWN; + } + + nbttagcompound.setDouble("i", x); + nbttagcompound.setDouble("j", y); + nbttagcompound.setDouble("k", z); + nbttagcompound.setByte("orientation", (byte) orientation.ordinal()); + } + + public void readFromNBT(NBTTagCompound nbttagcompound) { + x = nbttagcompound.getDouble("i"); + y = nbttagcompound.getDouble("j"); + z = nbttagcompound.getDouble("k"); + orientation = ForgeDirection.values() [nbttagcompound.getByte("orientation")]; + } + + @Override + public String toString() { + return "{" + x + ", " + y + ", " + z + "}"; + } + + public Position min(Position p) { + return new Position(p.x > x ? x : p.x, p.y > y ? y : p.y, p.z > z ? z : p.z); + } + + public Position max(Position p) { + return new Position(p.x < x ? x : p.x, p.y < y ? y : p.y, p.z < z ? z : p.z); + } + + public boolean isClose(Position newPosition, float f) { + double dx = x - newPosition.x; + double dy = y - newPosition.y; + double dz = z - newPosition.z; + + double sqrDis = dx * dx + dy * dy + dz * dz; + + return !(sqrDis > f * f); + } + +} diff --git a/src/api/java/buildcraft/api/core/SafeTimeTracker.java b/src/api/java/buildcraft/api/core/SafeTimeTracker.java index 46ca28096..9b60b86ec 100644 --- a/src/api/java/buildcraft/api/core/SafeTimeTracker.java +++ b/src/api/java/buildcraft/api/core/SafeTimeTracker.java @@ -55,8 +55,9 @@ public class SafeTimeTracker { * this function without a parameter */ public boolean markTimeIfDelay(World world, long delay) { - if (world == null) + if (world == null) { return false; + } long currentTime = world.getTotalWorldTime(); diff --git a/src/api/java/buildcraft/api/core/StackKey.java b/src/api/java/buildcraft/api/core/StackKey.java new file mode 100644 index 000000000..c3cf4fd62 --- /dev/null +++ b/src/api/java/buildcraft/api/core/StackKey.java @@ -0,0 +1,56 @@ +/** + * 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.core; + +import net.minecraft.item.ItemStack; + +/** + * This class is used whenever stacks needs to be stored as keys. + */ +public class StackKey { + + public final ItemStack stack; + + public StackKey(ItemStack stack) { + this.stack = stack; + } + + @Override + public int hashCode() { + int hash = 5; + + hash = 67 * hash + stack.getItem().hashCode(); + hash = 67 * hash + stack.getItemDamage(); + + if (stack.stackTagCompound != null) { + hash = 67 * hash + stack.stackTagCompound.hashCode(); + } + + return hash; + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } else if (getClass() != obj.getClass()) { + return false; + } + + final StackKey other = (StackKey) obj; + + if (stack.getItem() != other.stack.getItem()) { + return false; + } else if (stack.getHasSubtypes() && stack.getItemDamage() != other.stack.getItemDamage()) { + return false; + } else { + return !(stack.stackTagCompound != null && !stack.stackTagCompound.equals(other.stack.stackTagCompound)); + } + } +} diff --git a/src/api/java/buildcraft/api/core/package-info.java b/src/api/java/buildcraft/api/core/package-info.java new file mode 100644 index 000000000..5bc4a2fa9 --- /dev/null +++ b/src/api/java/buildcraft/api/core/package-info.java @@ -0,0 +1,11 @@ +/** + * Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team + * http://www.mod-buildcraft.com + * + * BuildCraft is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * http://www.mod-buildcraft.com/MMPL-1.0.txt + */ +@API(apiVersion = "1.0", owner = "BuildCraft|Core", provides = "BuildCraftAPI|core") +package buildcraft.api.core; +import cpw.mods.fml.common.API; diff --git a/src/api/java/buildcraft/api/fuels/IronEngineCoolant.java b/src/api/java/buildcraft/api/fuels/IronEngineCoolant.java new file mode 100644 index 000000000..78cf315b1 --- /dev/null +++ b/src/api/java/buildcraft/api/fuels/IronEngineCoolant.java @@ -0,0 +1,92 @@ +/** + * 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.fuels; + +import java.util.HashMap; +import java.util.Map; + +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; + +import buildcraft.api.core.StackKey; + +public final class IronEngineCoolant { + + public static Map liquidCoolants = new HashMap(); + public static Map solidCoolants = new HashMap(); + + private IronEngineCoolant() { + } + + public static FluidStack getFluidCoolant(ItemStack stack) { + return solidCoolants.get(new StackKey(stack)); + } + + public static Coolant getCoolant(ItemStack stack) { + return getCoolant(getFluidCoolant(stack)); + } + + public static Coolant getCoolant(FluidStack fluidStack) { + return fluidStack != null && fluidStack.getFluid() != null ? liquidCoolants.get(fluidStack.getFluid().getName()) : null; + } + + public interface Coolant { + + float getDegreesCoolingPerMB(float currentHeat); + } + + public static void addCoolant(final Fluid fluid, final float degreesCoolingPerMB) { + if (fluid != null) { + liquidCoolants.put(fluid.getName(), new Coolant() { + @Override + public float getDegreesCoolingPerMB(float currentHeat) { + return degreesCoolingPerMB; + } + }); + } + } + + /** + * Adds a solid coolant like Ice Blocks. The FluidStack must contain a registered + * Coolant Fluid or nothing will happen. You do not need to call this for + * Fluid Containers. + * + * @param stack + * @param coolant + */ + public static void addCoolant(final ItemStack stack, final FluidStack coolant) { + if (stack != null && stack.getItem() != null && coolant != null) { + solidCoolants.put(new StackKey(stack), coolant); + } + } + + /** + * Adds a solid coolant like Ice Blocks. The FluidStack must contain a + * registered Coolant Fluid or nothing will happen. You do not need to call + * this for Fluid Containers. + * + * @param item + * @param coolant + */ + public static void addCoolant(final Item item, final int metadata, final FluidStack coolant) { + addCoolant(new ItemStack(item, 1, metadata), coolant); + } + + public static void addCoolant(final Block block, final int metadata, final FluidStack coolant) { + addCoolant(new ItemStack(block, 1, metadata), coolant); + } + + public static boolean isCoolant(Fluid fluid) { + return liquidCoolants.containsKey(fluid.getName()); + } +} diff --git a/src/api/java/buildcraft/api/fuels/IronEngineFuel.java b/src/api/java/buildcraft/api/fuels/IronEngineFuel.java index 20b14eb50..68b6653cc 100644 --- a/src/api/java/buildcraft/api/fuels/IronEngineFuel.java +++ b/src/api/java/buildcraft/api/fuels/IronEngineFuel.java @@ -10,21 +10,22 @@ package buildcraft.api.fuels; import java.util.HashMap; import java.util.Map; + import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidRegistry; -public class IronEngineFuel { +public final class IronEngineFuel { public static Map fuels = new HashMap(); + private IronEngineFuel() { + } + public static Fuel getFuelForFluid(Fluid liquid) { return liquid == null ? null : fuels.get(liquid.getName()); } - private IronEngineFuel() { - } - - public static class Fuel { + public static final class Fuel { public final Fluid liquid; public final float powerPerCycle; diff --git a/src/api/java/buildcraft/api/fuels/package-info.java b/src/api/java/buildcraft/api/fuels/package-info.java index 48ad9319d..67ca22bc6 100644 --- a/src/api/java/buildcraft/api/fuels/package-info.java +++ b/src/api/java/buildcraft/api/fuels/package-info.java @@ -1,3 +1,11 @@ -@API(apiVersion="1.0",owner="BuildCraftAPI|core",provides="BuildCraftAPI|fuels") +/** + * 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|fuels") package buildcraft.api.fuels; -import cpw.mods.fml.common.API; \ No newline at end of file +import cpw.mods.fml.common.API; diff --git a/src/api/java/buildcraft/api/mj/BatteryObject.java b/src/api/java/buildcraft/api/mj/BatteryObject.java new file mode 100755 index 000000000..f0dd5680d --- /dev/null +++ b/src/api/java/buildcraft/api/mj/BatteryObject.java @@ -0,0 +1,199 @@ +/** + * Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team + * http://www.mod-buildcraft.com + * + * BuildCraft is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * http://www.mod-buildcraft.com/MMPL-1.0.txt + */ +package buildcraft.api.mj; + +import java.lang.reflect.Field; +import java.util.logging.Level; + +import buildcraft.api.core.BCLog; +import buildcraft.api.core.JavaTools; + +/** + * A battery object is a wrapper around a battery field in an object. This + * battery field is of type double, and is the only piece of data specific to + * this object. Others are class-wide. + */ +public class BatteryObject implements IBatteryIOObject, MjReconfigurator.IConfigurableBatteryObject { + protected Field energyStored; + protected Object obj; + protected MjBattery batteryData; + + /** + * {@inheritDoc} + */ + @Override + public double getEnergyRequested() { + if (!batteryData.mode().canReceive) { + return 0; + } + try { + return JavaTools.bounds(batteryData.maxCapacity() - energyStored.getDouble(obj), + batteryData.minimumConsumption(), batteryData.maxReceivedPerCycle()); + } catch (IllegalAccessException e) { + BCLog.logger.log(Level.WARNING, "can't get energy requested", e); + } + return 0; + } + + /** + * {@inheritDoc} + */ + @Override + public double addEnergy(double mj) { + return addEnergy(mj, false); + } + + /** + * {@inheritDoc} + */ + @Override + public double addEnergy(double mj, boolean ignoreCycleLimit) { + try { + double contained = energyStored.getDouble(obj); + double maxAccepted = batteryData.maxCapacity() - contained + batteryData.minimumConsumption(); + if (!ignoreCycleLimit && maxAccepted > batteryData.maxReceivedPerCycle()) { + maxAccepted = batteryData.maxReceivedPerCycle(); + } + double used = Math.min(maxAccepted, mj); + if (used > 0) { + energyStored.setDouble(obj, Math.min(contained + used, batteryData.maxCapacity())); + return used; + } + } catch (IllegalAccessException e) { + BCLog.logger.log(Level.WARNING, "can't add energy", e); + } + return 0; + } + + @Override + public double extractEnergy(double mj) { + return extractEnergy(mj, false); + } + + @Override + public double extractEnergy(double mj, boolean ignoreCycleLimit) { + try { + double contained = energyStored.getDouble(obj); + double maxExtracted = contained; + if (!ignoreCycleLimit && maxExtracted > batteryData.maxSendedPerCycle()) { + maxExtracted = batteryData.maxSendedPerCycle(); + } + double used = Math.min(maxExtracted, mj); + if (used > 0) { + energyStored.setDouble(obj, Math.max(contained - used, 0)); + return used; + } + } catch (IllegalAccessException e) { + BCLog.logger.log(Level.WARNING, "can't extract energy", e); + } + return 0; + } + + /** + * {@inheritDoc} + */ + @Override + public double getEnergyStored() { + try { + return energyStored.getDouble(obj); + } catch (IllegalAccessException e) { + BCLog.logger.log(Level.WARNING, "can't get return energy stored", e); + return 0; + } + } + + /** + * {@inheritDoc} + */ + @Override + public void setEnergyStored(double mj) { + try { + energyStored.setDouble(obj, mj); + } catch (IllegalAccessException e) { + BCLog.logger.log(Level.WARNING, "can't set energy stored", e); + throw new RuntimeException(e); + } + } + + /** + * {@inheritDoc} + */ + @Override + public double maxCapacity() { + return batteryData.maxCapacity(); + } + + /** + * {@inheritDoc} + */ + @Override + public double minimumConsumption() { + return batteryData.minimumConsumption(); + } + + /** + * {@inheritDoc} + */ + @Override + public double maxReceivedPerCycle() { + return batteryData.maxReceivedPerCycle(); + } + + @Override + public String kind() { + return batteryData.kind(); + } + + @Override + public void init(Object object, Field storedField, MjBattery battery) { + this.obj = object; + this.energyStored = storedField; + this.batteryData = battery; + } + + @Override + public double maxSendedPerCycle() { + return batteryData.maxSendedPerCycle(); + } + + @Override + public IOMode mode() { + return batteryData.mode(); + } + + @Override + public boolean canSend() { + return batteryData.mode().canSend; + } + + @Override + public boolean canReceive() { + return batteryData.mode().canReceive; + } + + @Override + public boolean isActive() { + return batteryData.mode().active; + } + + @Override + public boolean isCacheable() { + return batteryData.cacheable(); + } + + @Override + public MjBattery getMjBattery() { + return batteryData; + } + + @Override + public void setMjBattery(MjBattery battery) { + batteryData = battery; + } +} \ No newline at end of file diff --git a/src/api/java/buildcraft/api/mj/IBatteryIOObject.java b/src/api/java/buildcraft/api/mj/IBatteryIOObject.java new file mode 100644 index 000000000..a2cfb768a --- /dev/null +++ b/src/api/java/buildcraft/api/mj/IBatteryIOObject.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.mj; + +public interface IBatteryIOObject extends IBatteryObject { + double maxSendedPerCycle(); + + double extractEnergy(double mj); + + double extractEnergy(double mj, boolean ignoreCycleLimit); + + IOMode mode(); + + boolean canSend(); + + boolean canReceive(); + + boolean isActive(); + + boolean isCacheable(); +} diff --git a/src/api/java/buildcraft/api/mj/IBatteryObject.java b/src/api/java/buildcraft/api/mj/IBatteryObject.java new file mode 100644 index 000000000..6bbd222d2 --- /dev/null +++ b/src/api/java/buildcraft/api/mj/IBatteryObject.java @@ -0,0 +1,77 @@ +/** + * Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team + * http://www.mod-buildcraft.com + * + * BuildCraft is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * http://www.mod-buildcraft.com/MMPL-1.0.txt + */ +package buildcraft.api.mj; + +import java.lang.reflect.Field; + +public interface IBatteryObject { + /** + * @return Current energy requirement for keeping machine state + */ + double getEnergyRequested(); + + /** + * Add energy to this battery + * + * @param mj Energy amount + * @return Used energy + */ + double addEnergy(double mj); + + /** + * Add energy to this battery + * + * @param mj Energy amount + * @param ignoreCycleLimit Force add all energy even if "maxReceivedPerCycle" limit is reached + * @return Used energy + */ + double addEnergy(double mj, boolean ignoreCycleLimit); + + /** + * @return Current stored energy amount in this battery + */ + double getEnergyStored(); + + /** + * Set current stored energy amount. + * Doesn't use it for your machines! Decrease your battery field directly. + * + * @param mj New energy amount + */ + void setEnergyStored(double mj); + + /** + * @return Maximal energy amount for this battery. + */ + double maxCapacity(); + + /** + * @return Minimal energy amount for keep your machine in active state + */ + double minimumConsumption(); + + /** + * @return Maximal energy received per one tick + */ + double maxReceivedPerCycle(); + + /** + * @return kind of this energy battery + */ + String kind(); + + /** + * Basic initialization method + * + * @param object Basic object which hold a battery field + * @param storedField Field for energy storing + * @param battery Battery data + */ + void init(Object object, Field storedField, MjBattery battery); +} diff --git a/src/api/java/buildcraft/api/mj/IBatteryProvider.java b/src/api/java/buildcraft/api/mj/IBatteryProvider.java new file mode 100644 index 000000000..95236d84b --- /dev/null +++ b/src/api/java/buildcraft/api/mj/IBatteryProvider.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.mj; + +public interface IBatteryProvider { + IBatteryObject getMjBattery(String kind); +} \ No newline at end of file diff --git a/src/api/java/buildcraft/api/mj/IOMode.java b/src/api/java/buildcraft/api/mj/IOMode.java new file mode 100644 index 000000000..8f15e840f --- /dev/null +++ b/src/api/java/buildcraft/api/mj/IOMode.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.mj; + +public enum IOMode { + Both(true, true, false), + BothActive(true, true, true), + + Receive(true, false, false), + ReceiveActive(true, false, true), + + Send(false, true, false), + SendActive(false, true, true), + + None(false, false, false); + + public final boolean canReceive, canSend, active; + + IOMode(boolean canReceive, boolean canSend, boolean active) { + this.canReceive = canReceive; + this.canSend = canSend; + this.active = active; + } +} diff --git a/src/api/java/buildcraft/api/mj/ISidedBatteryProvider.java b/src/api/java/buildcraft/api/mj/ISidedBatteryProvider.java new file mode 100644 index 000000000..46adb69d9 --- /dev/null +++ b/src/api/java/buildcraft/api/mj/ISidedBatteryProvider.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.mj; + +import net.minecraftforge.common.util.ForgeDirection; + +public interface ISidedBatteryProvider { + IBatteryObject getMjBattery(String kind, ForgeDirection direction); +} diff --git a/src/api/java/buildcraft/api/mj/MjAPI.java b/src/api/java/buildcraft/api/mj/MjAPI.java new file mode 100755 index 000000000..d8333e3a1 --- /dev/null +++ b/src/api/java/buildcraft/api/mj/MjAPI.java @@ -0,0 +1,439 @@ +/** + * Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team + * http://www.mod-buildcraft.com + * + * BuildCraft is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * http://www.mod-buildcraft.com/MMPL-1.0.txt + */ +package buildcraft.api.mj; + +import java.lang.reflect.Field; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.WeakHashMap; +import java.util.logging.Level; + +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; + +import buildcraft.api.core.BCLog; +import buildcraft.api.core.JavaTools; +import buildcraft.api.power.IPowerReceptor; +import buildcraft.api.power.PowerHandler; + +import gnu.trove.map.TIntObjectMap; +import gnu.trove.map.hash.TIntObjectHashMap; + +/** + * The class MjAPI provides services to the Minecraft Joules power framework. + * BuildCraft implements a default power model on top of this, the "kinesis" + * power model. Third party mods may provide they own version of Minecraft + * Joules batteries and provide different models. + */ +public final class MjAPI { + + public static final String DEFAULT_POWER_FRAMEWORK = "buildcraft.kinesis"; + private static Map mjBatteryFields = new HashMap(); + private static Map> mjBatteryKinds = new HashMap>(); + private static final BatteryField invalidBatteryField = new BatteryField(); + private static final MjReconfigurator reconfigurator = new MjReconfigurator(); + private static final Map mjBatteryCache = new WeakHashMap(); + + /** + * Deactivate constructor + */ + private MjAPI() { + } + + /** + * @see #getMjBattery(Object, String, ForgeDirection) + */ + public static IBatteryObject getMjBattery(Object o) { + return getMjBattery(o, null, null); + } + + /** + * @see #getMjBattery(Object, String, ForgeDirection) + */ + public static IBatteryObject getMjBattery(Object o, String kind) { + return getMjBattery(o, kind, null); + } + + /** + * @see #getMjBattery(Object, String, ForgeDirection) + */ + public static IBatteryObject getMjBattery(Object o, ForgeDirection side) { + return getMjBattery(o, null, side); + } + + /** + * Returns the battery related to the object given in parameter. + */ + public static IBatteryObject getMjBattery(Object o, String kindRaw, ForgeDirection sideRaw) { + if (o == null) { + return null; + } + String kind = kindRaw == null ? DEFAULT_POWER_FRAMEWORK : kindRaw; + ForgeDirection side = sideRaw == null ? ForgeDirection.UNKNOWN : sideRaw; + + IBatteryObject battery; + BatteryCache cache = mjBatteryCache.get(o); + if (cache == null) { + cache = new BatteryCache(); + mjBatteryCache.put(o, cache); + } else { + battery = cache.get(kind, side); + if (isCacheable(battery)) { + return battery; + } + } + if (o instanceof ISidedBatteryProvider) { + battery = ((ISidedBatteryProvider) o).getMjBattery(kind, side); + if (battery == null && side != ForgeDirection.UNKNOWN) { + battery = ((ISidedBatteryProvider) o).getMjBattery(kind, ForgeDirection.UNKNOWN); + } + } else if (o instanceof IBatteryProvider) { + battery = ((IBatteryProvider) o).getMjBattery(kind); + } else { + battery = createBattery(o, kind, side); + } + if (battery == null && o instanceof IPowerReceptor) { + PowerHandler.PowerReceiver receiver = ((IPowerReceptor) o).getPowerReceiver(side); + if (receiver == null && side != ForgeDirection.UNKNOWN) { + receiver = ((IPowerReceptor) o).getPowerReceiver(ForgeDirection.UNKNOWN); + } + if (receiver != null) { + battery = receiver.getMjBattery(); + } + } + cache.put(kind, side, battery); + return battery; + } + + /** + * Create new battery instance. + * This method ignore all providers/caches and only create battery for given kind/side. + * + * @param o Object which contains {@link MjBattery} + * @param kind Kind of power + * @param side Side of block + * @return New {@link IBatteryObject} implementation registered for given kind of power + */ + public static IBatteryObject createBattery(Object o, String kind, ForgeDirection side) { + if (o == null) { + return null; + } + BatteryField f = getMjBatteryField(o.getClass(), kind, side); + if (f == null && side != ForgeDirection.UNKNOWN) { + f = getMjBatteryField(o.getClass(), kind, ForgeDirection.UNKNOWN); + } + if (f == null) { + return null; + } else if (!mjBatteryKinds.containsKey(kind)) { + return null; + } else if (f.kind == BatteryKind.Value) { + try { + IBatteryObject obj = mjBatteryKinds.get(kind).newInstance(); + obj.init(o, f.field, f.battery); + return obj; + } catch (InstantiationException e) { + BCLog.logger.log(Level.WARNING, "can't instantiate class for energy kind \"" + kind + "\""); + return null; + } catch (IllegalAccessException e) { + BCLog.logger.log(Level.WARNING, "can't instantiate class for energy kind \"" + kind + "\""); + return null; + } + } else { + try { + return createBattery(f.field.get(o), kind, side); + } catch (IllegalAccessException e) { + e.printStackTrace(); + return null; + } + } + } + + /** + * @return All non-sided batteries for passed object + */ + public static IBatteryObject[] getAllMjBatteries(Object o) { + return getAllMjBatteries(o, ForgeDirection.UNKNOWN); + } + + /** + * @param direction Side of block + * @return All sided batteries for passed object + */ + public static IBatteryObject[] getAllMjBatteries(Object o, ForgeDirection direction) { + IBatteryObject[] result = new IBatteryObject[mjBatteryFields.size()]; + + int id = 0; + + for (String kind : mjBatteryKinds.keySet()) { + result[id] = getMjBattery(o, kind, direction); + if (result[id] != null) { + id++; + } + } + + return Arrays.copyOfRange(result, 0, id); + } + + /** + * Register new battery kind implementation. + * Allowing to have a custom power types alongside default "kinesis" kind + * @param kind Kind name + * @param clazz Battery implementation class + */ + public static void registerMJBatteryKind(String kind, Class clazz) { + if (!mjBatteryKinds.containsKey(kind)) { + mjBatteryKinds.put(kind, clazz); + } else { + BCLog.logger.log(Level.WARNING, + "energy kind \"" + kind + "\" already registered with " + clazz.getCanonicalName()); + } + } + + /** + * @see IOMode#canReceive + */ + public static boolean canReceive(IBatteryObject battery) { + return battery != null && (!(battery instanceof IBatteryIOObject) || ((IBatteryIOObject) battery).canReceive()); + } + + /** + * @see IOMode#canSend + */ + public static boolean canSend(IBatteryObject battery) { + return battery != null && battery instanceof IBatteryIOObject && ((IBatteryIOObject) battery).canSend(); + } + + /** + * @see IOMode#active + */ + public static boolean isActive(IBatteryObject battery) { + return battery != null && battery instanceof IBatteryIOObject && ((IBatteryIOObject) battery).isActive(); + } + + /** + * @see MjBattery#cacheable() + */ + public static boolean isCacheable(IBatteryObject battery) { + return battery != null && battery instanceof IBatteryIOObject && ((IBatteryIOObject) battery).isCacheable(); + } + + /** + * @see MjBattery#maxReceivedPerCycle() + * @see MjBattery#maxSendedPerCycle() + * @return Actual IO limit for passed mode (only send/receive supported) + */ + public static double getIOLimit(IBatteryObject batteryObject, IOMode mode) { + if (mode == IOMode.Receive && canReceive(batteryObject)) { + return batteryObject.maxReceivedPerCycle(); + } else if (mode == IOMode.Send && canSend(batteryObject)) { + return ((IBatteryIOObject) batteryObject).maxSendedPerCycle(); + } + return 0; + } + + /** + * Obtain battery parameters reconfigurator. + * Usage:
+ * + * MjAPI.reconfigure().maxCapacity(battery, 15000); + * + * @return Reconfigurator instance + */ + public static MjReconfigurator reconfigure() { + return reconfigurator; + } + + /** + * Transfer mj energy amount from battery "fromBattery" to "toBattery" + * @param fromBattery Source battery + * @param toBattery Target battery + * @param mj Amount of energy + * @return Transferred amount + */ + public static double transferEnergy(IBatteryObject fromBattery, IBatteryObject toBattery, double mj) { + if (!canSend(fromBattery) || !canReceive(toBattery)) { + return 0; + } + IBatteryIOObject from = (IBatteryIOObject) fromBattery; + double attemptToTransfer = Math.min(getIOLimit(from, IOMode.Send), mj); + attemptToTransfer = Math.min(attemptToTransfer, getIOLimit(toBattery, IOMode.Receive)); + double extracted = from.extractEnergy(attemptToTransfer); + double received = toBattery.addEnergy(extracted); + if (extracted > received) { + from.addEnergy(extracted - received); + } + return received; + } + + /** + * Transfer maximal energy amount from battery "fromBattery" to "toBattery" + * @param fromBattery Source battery + * @param toBattery Target battery + * @return Transferred amount + */ + public static double transferEnergy(IBatteryObject fromBattery, IBatteryObject toBattery) { + return transferEnergy(fromBattery, toBattery, Math.min( + getIOLimit(fromBattery, IOMode.Send), + getIOLimit(toBattery, IOMode.Receive))); + } + + /** + * Helper method which you should invoke in every game tick for supporting Active IO modes + * @param tile Tile which contains active battery + */ + public static void updateEntity(TileEntity tile) { + for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) { + IBatteryObject batteryObject = getMjBattery(tile, direction); + TileEntity anotherTile = tile.getWorldObj().getTileEntity(tile.xCoord + direction.offsetX, tile.yCoord + direction.offsetY, tile.zCoord + direction.offsetZ); + IBatteryObject anotherBattery = getMjBattery(anotherTile, direction.getOpposite()); + if (batteryObject == null || anotherBattery == null) { + continue; + } + if (canSend(batteryObject) && canReceive(anotherBattery) && isActive(batteryObject)) { + transferEnergy(batteryObject, anotherBattery); + } + if (canReceive(batteryObject) && canSend(anotherBattery) && isActive(anotherBattery) && !isActive(batteryObject)) { + transferEnergy(anotherBattery, batteryObject); + } + } + } + + /** + * Reset all caches for passed tile + */ + public static void resetBatteriesCache(TileEntity tile) { + mjBatteryCache.remove(tile); + } + + /** + * Remove cached instance of passed battery + */ + public static void resetBatteriesCache(IBatteryObject battery) { + for (BatteryCache cache : mjBatteryCache.values()) { + cache.reset(battery); + } + } + + private enum BatteryKind { + Value, Container + } + + private static final class BatteryCache { + TIntObjectMap cache = new TIntObjectHashMap(); + + IBatteryObject get(String kind, ForgeDirection side) { + return cache.get(hash(kind, side)); + } + + void put(String kind, ForgeDirection side, IBatteryObject battery) { + cache.put(hash(kind, side), battery); + } + + void reset(IBatteryObject battery) { + for (int key : cache.keys()) { + if (cache.get(key) == battery) { + cache.remove(key); + } + } + } + + private int hash(String kind, ForgeDirection side) { + return kind.hashCode() * 31 + side.hashCode(); + } + } + + private static final class BatteryHolder { + private String kind; + private ForgeDirection side; + private Class clazz; + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + BatteryHolder that = (BatteryHolder) o; + + return kind.equals(that.kind) && clazz.equals(that.clazz) && side.equals(that.side); + } + + @Override + public int hashCode() { + int result = kind.hashCode(); + result = 31 * result + clazz.hashCode(); + result = 31 * result + side.hashCode(); + return result; + } + } + + private static class BatteryField { + public Field field; + public MjBattery battery; + public BatteryKind kind; + } + + private static BatteryField getMjBatteryField(Class c, String kind, ForgeDirection side) { + BatteryHolder holder = new BatteryHolder(); + holder.clazz = c; + holder.kind = kind; + holder.side = side; + + BatteryField bField = mjBatteryFields.get(holder); + + if (bField == null) { + for (Field f : JavaTools.getAllFields(c)) { + MjBattery battery = f.getAnnotation(MjBattery.class); + + if (battery != null && kind.equals(battery.kind())) { + if (!contains(battery.sides(), side) && !contains(battery.sides(), ForgeDirection.UNKNOWN)) { + continue; + } + f.setAccessible(true); + bField = new BatteryField(); + bField.field = f; + bField.battery = battery; + + if (double.class.equals(f.getType())) { + bField.kind = BatteryKind.Value; + } else if (f.getType().isPrimitive()) { + throw new RuntimeException( + "MJ battery needs to be object or double type"); + } else { + bField.kind = BatteryKind.Container; + } + + mjBatteryFields.put(holder, bField); + + return bField; + } + } + mjBatteryFields.put(holder, invalidBatteryField); + } + + return bField == invalidBatteryField ? null : bField; + } + + private static boolean contains(T[] array, T value) { + for (T t : array) { + if (t == value) { + return true; + } + } + return false; + } + + static { + registerMJBatteryKind(DEFAULT_POWER_FRAMEWORK, BatteryObject.class); + } +} diff --git a/src/api/java/buildcraft/api/mj/MjAPILegacy.java b/src/api/java/buildcraft/api/mj/MjAPILegacy.java new file mode 100644 index 000000000..55cf56a5b --- /dev/null +++ b/src/api/java/buildcraft/api/mj/MjAPILegacy.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.mj; + +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +import net.minecraftforge.common.util.ForgeDirection; + +import buildcraft.api.power.IPowerReceptor; +import buildcraft.api.power.PowerHandler; + +public class MjAPILegacy implements IPowerReceptor { + private final PowerHandler powerHandler; + private final World world; + + protected MjAPILegacy(World world, IBatteryObject battery, PowerHandler.Type type) { + if (battery == null) { + throw new NullPointerException(); + } + this.world = world; + this.powerHandler = new PowerHandler(this, type, battery); + } + + public static MjAPILegacy from(World world, IBatteryObject battery, PowerHandler.Type type) { + if (battery == null) { + return null; + } + return new MjAPILegacy(world, battery, type); + } + + public static MjAPILegacy from(World world, Object object, PowerHandler.Type type) { + return from(world, MjAPI.getMjBattery(object), type); + } + + public static MjAPILegacy from(TileEntity tileEntity, PowerHandler.Type type) { + return from(tileEntity.getWorldObj(), MjAPI.getMjBattery(tileEntity), type); + } + + @Override + public PowerHandler.PowerReceiver getPowerReceiver(ForgeDirection side) { + return powerHandler.getPowerReceiver(); + } + + @Override + public void doWork(PowerHandler workProvider) { + + } + + @Override + public World getWorld() { + return world; + } +} diff --git a/src/api/java/buildcraft/api/mj/MjBattery.java b/src/api/java/buildcraft/api/mj/MjBattery.java new file mode 100755 index 000000000..20ed8c715 --- /dev/null +++ b/src/api/java/buildcraft/api/mj/MjBattery.java @@ -0,0 +1,86 @@ +/** + * Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team + * http://www.mod-buildcraft.com + * + * BuildCraft is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * http://www.mod-buildcraft.com/MMPL-1.0.txt + */ +package buildcraft.api.mj; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import net.minecraftforge.common.util.ForgeDirection; + +/** + * This annotation is used for tiles that need to interface with BuildCraft + * energy framework, a.k.a MinecraftJoule or MJ. In order to receive power, + * tiles, need to declare a double field, with the annotation MjBattery. MJ + * provider machines able to provide power will then connect to these tiles, and + * feed energy up to max capacity. It's the responsibility of the implementer to + * manually decrease the value of the energy, as he simulates energy + * consumption. On each cycle, per power input, machines can receive up to + * "maxReceivedPerCycle" units of energy. As an optional behavior, the system + * can have a minimum amount of energy consumed even if the system is at max + * capacity, modelized by the "minimumConsumption" value. + * + * If the field designated by MjBattery is an object, then it will be considered + * as a nested battery, and will look for the field in the designated object. + * + * All the properties defined in this annotation are class wide. If you need to + * change them on a tile by tile basis, you will need to use interfaces, either + * {@link IBatteryProvider} or {@link ISidedBatteryProvider} + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +@Inherited +public @interface MjBattery { + /** + * @return Max energy capacity of battery + */ + double maxCapacity() default 100.0; + + /** + * @return Max energy received per one tick + */ + double maxReceivedPerCycle() default 10.0; + + /** + * @return Max energy received per one tick + */ + double maxSendedPerCycle() default 10.0; + + /** + * @return Minimal energy for keep machine is active + */ + double minimumConsumption() default 0.1; + + /** + * @return The kind of battery stored. Specific power systems can be created + * through this system, as several battery of different kind can + * coexist in the same tile. + */ + String kind() default MjAPI.DEFAULT_POWER_FRAMEWORK; + + /** + * @return Sides on which this battery should works. + */ + ForgeDirection[] sides() default {ForgeDirection.UNKNOWN}; + + /** + * @return Current battery input/output mode + */ + IOMode mode() default IOMode.Receive; + + /** + * @return Ability to cache this battery instance for performance reasons. Usual + * not required to modify it for every battery, you can dynamicaly reconfigure + * your batteries with {@link MjAPI#reconfigure()} and reset cache + * for tile with {@link MjAPI#resetBatteriesCache(IBatteryObject)} + */ + boolean cacheable() default true; +} \ No newline at end of file diff --git a/src/api/java/buildcraft/api/mj/MjReconfigurator.java b/src/api/java/buildcraft/api/mj/MjReconfigurator.java new file mode 100644 index 000000000..e5e81dcc6 --- /dev/null +++ b/src/api/java/buildcraft/api/mj/MjReconfigurator.java @@ -0,0 +1,183 @@ +/** + * Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team + * http://www.mod-buildcraft.com + * + * BuildCraft is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * http://www.mod-buildcraft.com/MMPL-1.0.txt + */ +package buildcraft.api.mj; + +import java.lang.annotation.Annotation; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import net.minecraftforge.common.util.ForgeDirection; + +import buildcraft.api.core.BCLog; + +/** + * Reconfiguration helper. + * Allow to change battery parameters in runtime. + */ +public class MjReconfigurator { + private static final class ConfigurableMjBattery implements MjBattery { + double maxCapacity, maxReceivedPerCycle, maxSendedPerCycle, minimumConsumption; + String kind; + ForgeDirection[] sides; + IOMode mode; + boolean cacheable; + + @Override + public double maxCapacity() { + return maxCapacity; + } + + @Override + public double maxReceivedPerCycle() { + return maxReceivedPerCycle; + } + + @Override + public double minimumConsumption() { + return minimumConsumption; + } + + @Override + public double maxSendedPerCycle() { + return maxSendedPerCycle; + } + + @Override + public String kind() { + return kind; + } + + @Override + public ForgeDirection[] sides() { + return sides; + } + + @Override + public IOMode mode() { + return mode; + } + + @Override + public boolean cacheable() { + return cacheable; + } + + @Override + public Class annotationType() { + return MjBattery.class; + } + } + + /** + * Helper interface which should implement all configurable batteries. + */ + public interface IConfigurableBatteryObject extends IBatteryObject { + MjBattery getMjBattery(); + + void setMjBattery(MjBattery battery); + } + + private ConfigurableMjBattery obtainConfigurableBattery(IBatteryObject battery) { + if (!(battery instanceof IConfigurableBatteryObject)) { + BCLog.logger.warning("Attempt to reconfigure unsupported battery: " + battery); + return null; + } + IConfigurableBatteryObject configurableBattery = (IConfigurableBatteryObject) battery; + MjBattery mjBattery = configurableBattery.getMjBattery(); + if (mjBattery instanceof ConfigurableMjBattery) { + return (ConfigurableMjBattery) mjBattery; + } + ConfigurableMjBattery configurableMjBattery = new ConfigurableMjBattery(); + configurableMjBattery.maxCapacity = mjBattery.maxCapacity(); + configurableMjBattery.maxReceivedPerCycle = mjBattery.maxReceivedPerCycle(); + configurableMjBattery.maxSendedPerCycle = mjBattery.maxSendedPerCycle(); + configurableMjBattery.minimumConsumption = mjBattery.minimumConsumption(); + configurableMjBattery.kind = mjBattery.kind(); + configurableMjBattery.sides = mjBattery.sides(); + configurableMjBattery.mode = mjBattery.mode(); + configurableMjBattery.cacheable = mjBattery.cacheable(); + configurableBattery.setMjBattery(configurableMjBattery); + return configurableMjBattery; + } + + public void maxCapacity(IBatteryObject batteryObject, double maxCapacity) { + ConfigurableMjBattery battery = obtainConfigurableBattery(batteryObject); + if (battery != null) { + battery.maxCapacity = maxCapacity; + } + } + + public void maxReceivedPerCycle(IBatteryObject batteryObject, double maxReceivedPerCycle) { + ConfigurableMjBattery battery = obtainConfigurableBattery(batteryObject); + if (battery != null) { + battery.maxReceivedPerCycle = maxReceivedPerCycle; + } + } + + public void maxSendedPerCycle(IBatteryObject batteryObject, double maxSendedPerCycle) { + ConfigurableMjBattery battery = obtainConfigurableBattery(batteryObject); + if (battery != null) { + battery.maxSendedPerCycle = maxSendedPerCycle; + } + } + + public void minimumConsumption(IBatteryObject batteryObject, double minimumConsumption) { + ConfigurableMjBattery battery = obtainConfigurableBattery(batteryObject); + if (battery != null) { + battery.minimumConsumption = minimumConsumption; + } + } + + public void kind(IBatteryObject batteryObject, String kind) { + ConfigurableMjBattery battery = obtainConfigurableBattery(batteryObject); + if (battery != null) { + battery.kind = kind; + MjAPI.resetBatteriesCache(batteryObject); + } + } + + /** + * Reconfigure passed battery instance for working with passed sides only + * @param sides Enabled sides + */ + public void sides(IBatteryObject batteryObject, ForgeDirection... sides) { + ConfigurableMjBattery battery = obtainConfigurableBattery(batteryObject); + if (battery != null) { + battery.sides = sides; + MjAPI.resetBatteriesCache(batteryObject); + } + } + + /** + * Reconfigure passed battery instance for working with all sides exclude passed + * @param sides Disabled sides + */ + public void sidesExclude(IBatteryObject batteryObject, ForgeDirection... sides) { + List newSides = new ArrayList(Arrays.asList(ForgeDirection.VALID_DIRECTIONS)); + for (ForgeDirection side : sides) { + newSides.remove(side); + } + sides(batteryObject, newSides.toArray(new ForgeDirection[newSides.size()])); + } + + public void mode(IBatteryObject batteryObject, IOMode mode) { + ConfigurableMjBattery battery = obtainConfigurableBattery(batteryObject); + if (battery != null) { + battery.mode = mode; + } + } + + public void cacheable(IBatteryObject batteryObject, boolean cacheable) { + ConfigurableMjBattery battery = obtainConfigurableBattery(batteryObject); + if (battery != null) { + battery.cacheable = cacheable; + } + } +} diff --git a/src/api/java/buildcraft/api/mj/package-info.java b/src/api/java/buildcraft/api/mj/package-info.java new file mode 100644 index 000000000..7ca45ce87 --- /dev/null +++ b/src/api/java/buildcraft/api/mj/package-info.java @@ -0,0 +1,11 @@ +/** + * Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team + * http://www.mod-buildcraft.com + * + * BuildCraft is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * http://www.mod-buildcraft.com/MMPL-1.0.txt + */ +@API(apiVersion = "1.1", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|mj") +package buildcraft.api.mj; +import cpw.mods.fml.common.API; diff --git a/src/api/java/buildcraft/api/package-info.java b/src/api/java/buildcraft/api/package-info.java index c1be5f463..d7f469fe9 100644 --- a/src/api/java/buildcraft/api/package-info.java +++ b/src/api/java/buildcraft/api/package-info.java @@ -1,3 +1,11 @@ -@API(apiVersion="1.0",owner="BuildCraft|Core",provides="BuildCraftAPI|core") +/** + * 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 = "BuildCraft|Core", provides = "BuildCraftAPI|core") package buildcraft.api; -import cpw.mods.fml.common.API; \ No newline at end of file +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..8f859158c --- /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(double 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(); + + int getXCoord(); + + int getYCoord(); + + int getZCoord(); +} diff --git a/src/api/java/buildcraft/api/power/IPowerEmitter.java b/src/api/java/buildcraft/api/power/IPowerEmitter.java index 4bb48497b..4a7115705 100644 --- a/src/api/java/buildcraft/api/power/IPowerEmitter.java +++ b/src/api/java/buildcraft/api/power/IPowerEmitter.java @@ -17,6 +17,5 @@ import net.minecraftforge.common.util.ForgeDirection; * from a specific side. */ public interface IPowerEmitter { - - public boolean canEmitPowerFrom(ForgeDirection side); + boolean canEmitPowerFrom(ForgeDirection side); } diff --git a/src/api/java/buildcraft/api/power/IPowerReceptor.java b/src/api/java/buildcraft/api/power/IPowerReceptor.java index 79586e9e1..17dca98cb 100644 --- a/src/api/java/buildcraft/api/power/IPowerReceptor.java +++ b/src/api/java/buildcraft/api/power/IPowerReceptor.java @@ -9,6 +9,7 @@ package buildcraft.api.power; import net.minecraft.world.World; + import net.minecraftforge.common.util.ForgeDirection; /** @@ -27,9 +28,8 @@ public interface IPowerReceptor { * engines to eventually explode. * * @param side - * @return */ - public PowerHandler.PowerReceiver getPowerReceiver(ForgeDirection side); + PowerHandler.PowerReceiver getPowerReceiver(ForgeDirection side); /** * Call back from the PowerHandler that is called when the stored power @@ -39,7 +39,7 @@ public interface IPowerReceptor { * * @param workProvider */ - public void doWork(PowerHandler workProvider); + void doWork(PowerHandler workProvider); - public World getWorld(); + World getWorld(); } diff --git a/src/api/java/buildcraft/api/power/PowerHandler.java b/src/api/java/buildcraft/api/power/PowerHandler.java index 8979086ea..bcf8bffb5 100644 --- a/src/api/java/buildcraft/api/power/PowerHandler.java +++ b/src/api/java/buildcraft/api/power/PowerHandler.java @@ -8,27 +8,35 @@ */ package buildcraft.api.power; -import buildcraft.api.core.SafeTimeTracker; import net.minecraft.nbt.NBTTagCompound; + import net.minecraftforge.common.util.ForgeDirection; +import buildcraft.api.core.SafeTimeTracker; +import buildcraft.api.mj.BatteryObject; +import buildcraft.api.mj.IBatteryObject; +import buildcraft.api.mj.IBatteryProvider; +import buildcraft.api.mj.IOMode; +import buildcraft.api.mj.MjAPI; +import buildcraft.api.mj.MjBattery; + /** * 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 */ -public final class PowerHandler { +public final class PowerHandler implements IBatteryProvider { public static enum Type { @@ -57,7 +65,7 @@ public final class PowerHandler { /** * 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 { @@ -76,9 +84,6 @@ public final class PowerHandler { * @param powerLoss power loss per tick */ public PerditionCalculator(double powerLoss) { - if (powerLoss < MIN_POWERLOSS) { - powerLoss = MIN_POWERLOSS; - } this.powerLoss = powerLoss; } @@ -88,21 +93,22 @@ public final class PowerHandler { * 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 + * @param current the current stored energy + * @param ticksPassed ticks since the last time this function was called */ public double applyPerdition(PowerHandler powerHandler, double current, long ticksPassed) { - current -= powerLoss * ticksPassed; - if (current < 0) { - current = 0; + double newPower = current - powerLoss * ticksPassed; + + if (newPower < 0) { + newPower = 0; } - return current; + + return newPower; } /** * Taxes a flat rate on all incoming power. - * + *

* Defaults to 0% tax rate. * * @return percent of input to tax @@ -111,33 +117,50 @@ public final class PowerHandler { 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; - private double minEnergyReceived; - private double maxEnergyReceived; - private double maxEnergyStored; - private double activationEnergy; - private double energyStored = 0; - private final SafeTimeTracker doWorkTracker = new SafeTimeTracker(); - private final SafeTimeTracker sourcesTracker = new SafeTimeTracker(); - private final SafeTimeTracker perditionTracker = new SafeTimeTracker(); + public static final double ROLLING_AVERAGE_DENOMINATOR = 1.0 / ROLLING_AVERAGE_WEIGHT; public final int[] powerSources = new int[6]; public final IPowerReceptor receptor; + + private double activationEnergy; + private final SafeTimeTracker doWorkTracker = new SafeTimeTracker(1); + private final SafeTimeTracker sourcesTracker = new SafeTimeTracker(1); + private final SafeTimeTracker perditionTracker = new SafeTimeTracker(1); private PerditionCalculator perdition; private final PowerReceiver receiver; private final Type type; + private IBatteryObject battery; // Tracking private double averageLostPower = 0; private double averageReceivedPower = 0; private double averageUsedPower = 0; public PowerHandler(IPowerReceptor receptor, Type type) { + this(receptor, type, null); + } + + public PowerHandler(IPowerReceptor receptor, Type type, Object battery) { this.receptor = receptor; this.type = type; this.receiver = new PowerReceiver(); this.perdition = DEFAULT_PERDITION; + + boolean created = false; + if (battery instanceof IBatteryObject) { + this.battery = (BatteryObject) battery; + } else if (battery != null) { + this.battery = MjAPI.createBattery(battery, MjAPI.DEFAULT_POWER_FRAMEWORK, ForgeDirection.UNKNOWN); + created = true; + } else { + this.battery = MjAPI.createBattery(new AnonymousBattery(), MjAPI.DEFAULT_POWER_FRAMEWORK, ForgeDirection.UNKNOWN); + created = true; + } + if (receptor instanceof IPowerEmitter && created) { + MjAPI.reconfigure().mode(this.battery, IOMode.Send); + } } public PowerReceiver getPowerReceiver() { @@ -145,15 +168,15 @@ public final class PowerHandler { } public double getMinEnergyReceived() { - return minEnergyReceived; + return battery.minimumConsumption(); } public double getMaxEnergyReceived() { - return maxEnergyReceived; + return battery.getEnergyRequested(); } public double getMaxEnergyStored() { - return maxEnergyStored; + return battery.maxCapacity(); } public double getActivationEnergy() { @@ -161,40 +184,54 @@ public final class PowerHandler { } public double getEnergyStored() { - return energyStored; + return battery.getEnergyStored(); + } + + @Override + public IBatteryObject getMjBattery(String kind) { + return battery.kind().equals(kind) ? battery : null; } /** * Setup your PowerHandler's settings. * - * @param minEnergyReceived This is the minimum about of power that will be - * accepted by the PowerHandler. This should generally be greater than the - * activationEnergy if you plan to use the doWork() callback. Anything - * greater than 1 will prevent Redstone Engines from powering this Provider. - * @param maxEnergyReceived The maximum amount of power accepted by the - * PowerHandler. This should generally be less than 500. Too low and larger - * engines will overheat while trying to power the machine. Too high, and - * the engines will never warm up. Greater values also place greater strain - * on the power net. - * @param activationEnergy If the stored energy is greater than this value, - * the doWork() callback is called (once per tick). - * @param maxStoredEnergy The maximum amount of power this PowerHandler can - * store. Values tend to range between 100 and 5000. With 1000 and 1500 - * being common. + * @param minEnergyReceived + * This is the minimum about of power that will be accepted by + * the PowerHandler. This should generally be greater than the + * activationEnergy if you plan to use the doWork() callback. + * Anything greater than 1 will prevent Redstone Engines from + * powering this Provider. + * @param maxEnergyReceived + * The maximum amount of power accepted by the PowerHandler. This + * should generally be less than 500. Too low and larger engines + * will overheat while trying to power the machine. Too high, and + * the engines will never warm up. Greater values also place + * greater strain on the power net. + * @param activationEnergy + * If the stored energy is greater than this value, the doWork() + * callback is called (once per tick). + * @param maxStoredEnergy + * The maximum amount of power this PowerHandler can store. + * Values tend to range between 100 and 5000. With 1000 and 1500 + * being common. */ - public void configure(double minEnergyReceived, double maxEnergyReceived, double activationEnergy, double maxStoredEnergy) { - if (minEnergyReceived > maxEnergyReceived) { - maxEnergyReceived = minEnergyReceived; + public void configure(double minEnergyReceived, double maxEnergyReceived, double activationEnergy, + double maxStoredEnergy) { + double localMaxEnergyReceived = maxEnergyReceived; + + if (minEnergyReceived > localMaxEnergyReceived) { + localMaxEnergyReceived = minEnergyReceived; } - this.minEnergyReceived = minEnergyReceived; - this.maxEnergyReceived = maxEnergyReceived; - this.maxEnergyStored = maxStoredEnergy; this.activationEnergy = activationEnergy; + + MjAPI.reconfigure().maxCapacity(battery, maxStoredEnergy); + MjAPI.reconfigure().maxReceivedPerCycle(battery, localMaxEnergyReceived); + MjAPI.reconfigure().minimumConsumption(battery, minEnergyReceived); } /** * Allows you define perdition in terms of loss/ticks. - * + *

* This function is mostly for legacy implementations. See * PerditionCalculator for more complex perdition formulas. * @@ -213,28 +250,32 @@ public final class PowerHandler { /** * 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 perdition */ public void setPerdition(PerditionCalculator perdition) { - if (perdition == null) - perdition = DEFAULT_PERDITION; - this.perdition = perdition; + if (perdition == null) { + this.perdition = DEFAULT_PERDITION; + } else { + this.perdition = perdition; + } } public PerditionCalculator getPerdition() { - if (perdition == null) + if (perdition == null) { return DEFAULT_PERDITION; - return perdition; + } else { + 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 @@ -247,29 +288,28 @@ public final class PowerHandler { } private void applyPerdition() { - if (perditionTracker.markTimeIfDelay(receptor.getWorld(), 1) && energyStored > 0) { - double prev = energyStored; + double energyStored = getEnergyStored(); + if (perditionTracker.markTimeIfDelay(receptor.getWorld()) && energyStored > 0) { double newEnergy = getPerdition().applyPerdition(this, energyStored, perditionTracker.durationOfLastDelay()); - if (newEnergy == 0 || newEnergy < energyStored) - energyStored = newEnergy; - else - energyStored = DEFAULT_PERDITION.applyPerdition(this, energyStored, perditionTracker.durationOfLastDelay()); + if (newEnergy != energyStored) { + battery.setEnergyStored(energyStored = newEnergy); + } validateEnergy(); - averageLostPower = (averageLostPower * ROLLING_AVERAGE_NUMERATOR + (prev - energyStored)) * ROLLING_AVERAGE_DENOMINATOR; + averageLostPower = (averageLostPower * ROLLING_AVERAGE_NUMERATOR + (getEnergyStored() - energyStored)) * ROLLING_AVERAGE_DENOMINATOR; } } private void applyWork() { - if (energyStored >= activationEnergy) { - if (doWorkTracker.markTimeIfDelay(receptor.getWorld(), 1)) { + if (getEnergyStored() >= activationEnergy) { + if (doWorkTracker.markTimeIfDelay(receptor.getWorld())) { receptor.doWork(this); } } } private void updateSources(ForgeDirection source) { - if (sourcesTracker.markTimeIfDelay(receptor.getWorld(), 1)) { + if (sourcesTracker.markTimeIfDelay(receptor.getWorld())) { for (int i = 0; i < 6; ++i) { powerSources[i] -= sourcesTracker.durationOfLastDelay(); if (powerSources[i] < 0) { @@ -278,8 +318,9 @@ public final class PowerHandler { } } - if (source != null) + if (source != null) { powerSources[source.ordinal()] = 10; + } } /** @@ -296,6 +337,7 @@ public final class PowerHandler { double result = 0; + double energyStored = getEnergyStored(); if (energyStored >= min) { if (energyStored <= max) { result = energyStored; @@ -309,11 +351,15 @@ public final class PowerHandler { } } } + if (energyStored != getEnergyStored()) { + battery.setEnergyStored(energyStored); + } validateEnergy(); - if (doUse) + if (doUse) { averageUsedPower = (averageUsedPower * ROLLING_AVERAGE_NUMERATOR + result) * ROLLING_AVERAGE_DENOMINATOR; + } return result; } @@ -324,7 +370,7 @@ public final class PowerHandler { public void readFromNBT(NBTTagCompound data, String tag) { NBTTagCompound nbt = data.getCompoundTag(tag); - energyStored = nbt.getDouble("energyStored"); + battery.setEnergyStored(nbt.getDouble("energyStored")); } public void writeToNBT(NBTTagCompound data) { @@ -333,7 +379,7 @@ public final class PowerHandler { public void writeToNBT(NBTTagCompound data, String tag) { NBTTagCompound nbt = new NBTTagCompound(); - nbt.setDouble("energyStored", energyStored); + nbt.setDouble("energyStored", battery.getEnergyStored()); data.setTag(tag, nbt); } @@ -343,15 +389,15 @@ public final class PowerHandler { } public double getMinEnergyReceived() { - return minEnergyReceived; + return PowerHandler.this.getMinEnergyReceived(); } public double getMaxEnergyReceived() { - return maxEnergyReceived; + return PowerHandler.this.getMaxEnergyReceived(); } public double getMaxEnergyStored() { - return maxEnergyStored; + return PowerHandler.this.getMaxEnergyStored(); } public double getActivationEnergy() { @@ -359,7 +405,7 @@ public final class PowerHandler { } public double getEnergyStored() { - return energyStored; + return PowerHandler.this.getEnergyStored(); } public double getAveragePowerReceived() { @@ -384,17 +430,15 @@ public final class PowerHandler { /** * The amount of power that this PowerHandler currently needs. - * - * @return */ public double powerRequest() { update(); - return Math.min(maxEnergyReceived, maxEnergyStored - energyStored); + return battery.getEnergyRequested(); } /** * Add power to the PowerReceiver from an external source. - * + *

* IPowerEmitters are responsible for calling this themselves. * * @param quantity @@ -404,10 +448,10 @@ public final class PowerHandler { public double receiveEnergy(Type source, final double quantity, ForgeDirection from) { double used = quantity; if (source == Type.ENGINE) { - if (used < minEnergyReceived) { + if (used < getMinEnergyReceived()) { return 0; - } else if (used > maxEnergyReceived) { - used = maxEnergyReceived; + } else if (used > getMaxEnergyReceived()) { + used = getMaxEnergyReceived(); } } @@ -420,37 +464,30 @@ public final class PowerHandler { applyWork(); if (source == Type.ENGINE && type.eatsEngineExcess()) { - used = Math.min(quantity, maxEnergyReceived); + used = Math.min(quantity, getMaxEnergyReceived()); } averageReceivedPower = (averageReceivedPower * ROLLING_AVERAGE_NUMERATOR + used) * ROLLING_AVERAGE_DENOMINATOR; return used; } + + public IBatteryObject getMjBattery() { + return battery; + } } /** - * * @return the amount the power changed by */ public double addEnergy(double quantity) { - energyStored += quantity; - - if (energyStored > maxEnergyStored) { - quantity -= energyStored - maxEnergyStored; - energyStored = maxEnergyStored; - } else if (energyStored < 0) { - quantity -= energyStored; - energyStored = 0; - } - + final double used = battery.addEnergy(quantity); applyPerdition(); - - return quantity; + return used; } public void setEnergy(double quantity) { - this.energyStored = quantity; + battery.setEnergyStored(quantity); validateEnergy(); } @@ -459,11 +496,21 @@ public final class PowerHandler { } private void validateEnergy() { + double energyStored = getEnergyStored(); + double maxEnergyStored = getMaxEnergyStored(); if (energyStored < 0) { energyStored = 0; } if (energyStored > maxEnergyStored) { energyStored = maxEnergyStored; } + if (energyStored != battery.getEnergyStored()) { + battery.setEnergyStored(energyStored); + } + } + + private static class AnonymousBattery { + @MjBattery + public double mjStored; } } diff --git a/src/api/java/buildcraft/api/power/package-info.java b/src/api/java/buildcraft/api/power/package-info.java index 4a98dbbea..03c457a8d 100644 --- a/src/api/java/buildcraft/api/power/package-info.java +++ b/src/api/java/buildcraft/api/power/package-info.java @@ -1,3 +1,11 @@ -@API(apiVersion="1.1",owner="BuildCraftAPI|core",provides="BuildCraftAPI|power") +/** + * Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team + * http://www.mod-buildcraft.com + * + * BuildCraft is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * http://www.mod-buildcraft.com/MMPL-1.0.txt + */ +@API(apiVersion = "1.1", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|power") package buildcraft.api.power; -import cpw.mods.fml.common.API; \ No newline at end of file +import cpw.mods.fml.common.API; diff --git a/src/api/java/buildcraft/api/recipes/BuildcraftRecipeRegistry.java b/src/api/java/buildcraft/api/recipes/BuildcraftRecipeRegistry.java new file mode 100644 index 000000000..64a392db0 --- /dev/null +++ b/src/api/java/buildcraft/api/recipes/BuildcraftRecipeRegistry.java @@ -0,0 +1,19 @@ +/** + * 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; + +public final class BuildcraftRecipeRegistry { + + public static IAssemblyRecipeManager assemblyTable; + public static IIntegrationRecipeManager integrationTable; + public static IRefineryRecipeManager refinery; + + private BuildcraftRecipeRegistry() { + } +} diff --git a/src/api/java/buildcraft/api/recipes/CraftingResult.java b/src/api/java/buildcraft/api/recipes/CraftingResult.java new file mode 100755 index 000000000..332c851f7 --- /dev/null +++ b/src/api/java/buildcraft/api/recipes/CraftingResult.java @@ -0,0 +1,25 @@ +/** + * 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.ArrayList; + +import net.minecraft.item.ItemStack; + +import net.minecraftforge.fluids.FluidStack; + +public class CraftingResult { + + public T crafted = null; + public ArrayList usedItems = new ArrayList(); + public ArrayList usedFluids = new ArrayList(); + public double energyCost = 0; + public long craftingTime = 0; + public IFlexibleRecipe recipe; +} diff --git a/src/api/java/buildcraft/api/recipes/IAssemblyRecipeManager.java b/src/api/java/buildcraft/api/recipes/IAssemblyRecipeManager.java new file mode 100644 index 000000000..450b91356 --- /dev/null +++ b/src/api/java/buildcraft/api/recipes/IAssemblyRecipeManager.java @@ -0,0 +1,33 @@ +/** + * 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 + * MJ cost to produce + * @param output + * resulting ItemStack + */ + void addRecipe(String id, double energyCost, ItemStack output, Object... input); + + void addRecipe(IFlexibleRecipe recipe); + + Collection> getRecipes(); +} diff --git a/src/api/java/buildcraft/api/recipes/IFlexibleCrafter.java b/src/api/java/buildcraft/api/recipes/IFlexibleCrafter.java new file mode 100755 index 000000000..53568caaf --- /dev/null +++ b/src/api/java/buildcraft/api/recipes/IFlexibleCrafter.java @@ -0,0 +1,29 @@ +/** + * 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 net.minecraft.item.ItemStack; + +import net.minecraftforge.fluids.FluidStack; + +public interface IFlexibleCrafter { + + int getCraftingItemStackSize(); + + ItemStack getCraftingItemStack(int slotid); + + ItemStack decrCraftingItemgStack(int slotid, int val); + + FluidStack getCraftingFluidStack(int tankid); + + FluidStack decrCraftingFluidStack(int tankid, int val); + + int getCraftingFluidStackSize(); + +} diff --git a/src/api/java/buildcraft/api/recipes/IFlexibleRecipe.java b/src/api/java/buildcraft/api/recipes/IFlexibleRecipe.java new file mode 100755 index 000000000..c87a8212d --- /dev/null +++ b/src/api/java/buildcraft/api/recipes/IFlexibleRecipe.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.recipes; + +public interface IFlexibleRecipe { + + boolean canBeCrafted(IFlexibleCrafter crafter); + + CraftingResult craft(IFlexibleCrafter crafter, boolean preview); + + String getId(); +} diff --git a/src/api/java/buildcraft/api/recipes/IIntegrationRecipe.java b/src/api/java/buildcraft/api/recipes/IIntegrationRecipe.java new file mode 100644 index 000000000..86dfaee5c --- /dev/null +++ b/src/api/java/buildcraft/api/recipes/IIntegrationRecipe.java @@ -0,0 +1,19 @@ +/** + * 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 net.minecraft.item.ItemStack; + +public interface IIntegrationRecipe extends IFlexibleRecipe { + + boolean isValidInputA(ItemStack inputA); + + boolean isValidInputB(ItemStack inputB); + +} \ No newline at end of file diff --git a/src/api/java/buildcraft/api/recipes/IIntegrationRecipeManager.java b/src/api/java/buildcraft/api/recipes/IIntegrationRecipeManager.java new file mode 100644 index 000000000..f18ae77b1 --- /dev/null +++ b/src/api/java/buildcraft/api/recipes/IIntegrationRecipeManager.java @@ -0,0 +1,25 @@ +/** + * 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; + +/** + * 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 { + /** + * 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 new file mode 100644 index 000000000..a20643341 --- /dev/null +++ b/src/api/java/buildcraft/api/recipes/IRefineryRecipeManager.java @@ -0,0 +1,25 @@ +/** + * 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); + + Collection> getRecipes(); + + IFlexibleRecipe getRecipe(String currentRecipeId); + +} diff --git a/src/api/java/buildcraft/api/recipes/package-info.java b/src/api/java/buildcraft/api/recipes/package-info.java new file mode 100644 index 000000000..e7b4a170b --- /dev/null +++ b/src/api/java/buildcraft/api/recipes/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 = "2.0", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|recipes") +package buildcraft.api.recipes; +import cpw.mods.fml.common.API; + diff --git a/src/api/java/buildcraft/api/tools/IToolWrench.java b/src/api/java/buildcraft/api/tools/IToolWrench.java index a6c56e8d3..3bd8dcea1 100644 --- a/src/api/java/buildcraft/api/tools/IToolWrench.java +++ b/src/api/java/buildcraft/api/tools/IToolWrench.java @@ -17,24 +17,24 @@ public interface IToolWrench { /*** * Called to ensure that the wrench can be used. To get the ItemStack that is used, check player.inventory.getCurrentItem() - * + * * @param player * - The player doing the wrenching * @param x * ,y,z - The coordinates for the block being wrenched - * + * * @return true if wrenching is allowed, false if not */ - public boolean canWrench(EntityPlayer player, int x, int y, int z); + boolean canWrench(EntityPlayer player, int x, int y, int z); /*** * Callback after the wrench has been used. This can be used to decrease durability or for other purposes. To get the ItemStack that was used, check * player.inventory.getCurrentItem() - * + * * @param player * - The player doing the wrenching * @param x * ,y,z - The coordinates of the block being wrenched */ - public void wrenchUsed(EntityPlayer player, int x, int y, int z); + void wrenchUsed(EntityPlayer player, int x, int y, int z); } diff --git a/src/api/java/buildcraft/api/tools/package-info.java b/src/api/java/buildcraft/api/tools/package-info.java index a5e03a062..6a2a363a9 100644 --- a/src/api/java/buildcraft/api/tools/package-info.java +++ b/src/api/java/buildcraft/api/tools/package-info.java @@ -1,3 +1,11 @@ -@API(apiVersion="1.0",owner="BuildCraftAPI|core",provides="BuildCraftAPI|tools") +/** + * 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|tools") package buildcraft.api.tools; -import cpw.mods.fml.common.API; \ No newline at end of file +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 new file mode 100755 index 000000000..4d56659ed --- /dev/null +++ b/src/api/java/buildcraft/api/transport/IExtractionHandler.java @@ -0,0 +1,29 @@ +/** + * 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.world.World; + +/** + * Implement and register with the PipeManager if you want to suppress connections from wooden pipes. + */ +public interface IExtractionHandler { + + /** + * Can this pipe extract items from the block located at these coordinates? + * param extractor can be null + */ + boolean canExtractItems(Object extractor, World world, int i, int j, int k); + + /** + * Can this pipe extract liquids from the block located at these coordinates? + * param extractor can be null + */ + boolean canExtractFluids(Object extractor, World world, int i, int j, int k); +} diff --git a/src/api/java/buildcraft/api/transport/IPipe.java b/src/api/java/buildcraft/api/transport/IPipe.java new file mode 100755 index 000000000..979f536af --- /dev/null +++ b/src/api/java/buildcraft/api/transport/IPipe.java @@ -0,0 +1,26 @@ +/** + * 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.tileentity.TileEntity; + +import net.minecraftforge.common.util.ForgeDirection; + +public interface IPipe { + + int x(); + + int y(); + + int z(); + + IPipeTile getTile(); + + TileEntity getAdjacentTile(ForgeDirection dir); +} diff --git a/src/api/java/buildcraft/api/transport/IPipeConnection.java b/src/api/java/buildcraft/api/transport/IPipeConnection.java new file mode 100644 index 000000000..27ca26ff5 --- /dev/null +++ b/src/api/java/buildcraft/api/transport/IPipeConnection.java @@ -0,0 +1,31 @@ +/** + * 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.minecraftforge.common.util.ForgeDirection; + +import buildcraft.api.transport.IPipeTile.PipeType; + +public interface IPipeConnection { + + enum ConnectOverride { + + CONNECT, DISCONNECT, DEFAULT + }; + + /** + * Allows you to override pipe connection logic. + * + * @param type + * @param with + * @return CONNECT to force a connection, DISCONNECT to force no connection, + * and DEFAULT to let the pipe decide. + */ + ConnectOverride overridePipeConnection(PipeType type, ForgeDirection with); +} diff --git a/src/api/java/buildcraft/api/transport/IPipePluggable.java b/src/api/java/buildcraft/api/transport/IPipePluggable.java new file mode 100755 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/IPipeTile.java b/src/api/java/buildcraft/api/transport/IPipeTile.java index 22f287f25..94516c8fc 100644 --- a/src/api/java/buildcraft/api/transport/IPipeTile.java +++ b/src/api/java/buildcraft/api/transport/IPipeTile.java @@ -9,6 +9,7 @@ package buildcraft.api.transport; import net.minecraft.item.ItemStack; + import net.minecraftforge.common.util.ForgeDirection; public interface IPipeTile { @@ -34,8 +35,8 @@ public interface IPipeTile { /** * True if the pipe is connected to the block/pipe in the specific direction - * - * @param wire + * + * @param with * @return true if connect */ boolean isPipeConnected(ForgeDirection with); diff --git a/src/api/java/buildcraft/api/transport/PipeManager.java b/src/api/java/buildcraft/api/transport/PipeManager.java new file mode 100755 index 000000000..f0e6e74c7 --- /dev/null +++ b/src/api/java/buildcraft/api/transport/PipeManager.java @@ -0,0 +1,49 @@ +/** + * 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 java.util.ArrayList; +import java.util.List; + +import net.minecraft.world.World; + +public abstract class PipeManager { + + public static List extractionHandlers = new ArrayList(); + + public static void registerExtractionHandler(IExtractionHandler handler) { + extractionHandlers.add(handler); + } + + /** + * param extractor can be null + */ + public static boolean canExtractItems(Object extractor, World world, int i, int j, int k) { + for (IExtractionHandler handler : extractionHandlers) { + if (!handler.canExtractItems(extractor, world, i, j, k)) { + return false; + } + } + + return true; + } + + /** + * param extractor can be null + */ + public static boolean canExtractFluids(Object extractor, World world, int i, int j, int k) { + for (IExtractionHandler handler : extractionHandlers) { + if (!handler.canExtractFluids(extractor, world, i, j, k)) { + return false; + } + } + + return true; + } +} diff --git a/src/api/java/buildcraft/api/transport/PipeWire.java b/src/api/java/buildcraft/api/transport/PipeWire.java index 8024e6bb7..e7551091a 100644 --- a/src/api/java/buildcraft/api/transport/PipeWire.java +++ b/src/api/java/buildcraft/api/transport/PipeWire.java @@ -9,6 +9,7 @@ package buildcraft.api.transport; import java.util.Locale; + import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -35,27 +36,39 @@ public enum PipeWire { return name().toLowerCase(Locale.ENGLISH) + "PipeWire"; } + public String getColor() { + String name = this.toString().toLowerCase(Locale.ENGLISH); + char first = Character.toUpperCase(name.charAt(0)); + return first + name.substring(1); + } + public ItemStack getStack() { return getStack(1); } public ItemStack getStack(int qty) { - if (item == null) + if (item == null) { return null; - return new ItemStack(item, qty, ordinal()); + } else { + return new ItemStack(item, qty, ordinal()); + } } public boolean isPipeWire(ItemStack stack) { - if (stack == null) + if (stack == null) { return false; - if (stack.getItem() != item) + } else if (stack.getItem() != item) { return false; - return stack.getItemDamage() == ordinal(); + } else { + return stack.getItemDamage() == ordinal(); + } } public static PipeWire fromOrdinal(int ordinal) { - if (ordinal < 0 || ordinal >= VALUES.length) + if (ordinal < 0 || ordinal >= VALUES.length) { return RED; - return VALUES[ordinal]; + } else { + return VALUES[ordinal]; + } } } diff --git a/src/api/java/buildcraft/api/transport/package-info.java b/src/api/java/buildcraft/api/transport/package-info.java index 612eeaaaf..210db5b4a 100644 --- a/src/api/java/buildcraft/api/transport/package-info.java +++ b/src/api/java/buildcraft/api/transport/package-info.java @@ -1,3 +1,12 @@ -@API(apiVersion="2.0",owner="BuildCraftAPI|core",provides="BuildCraftAPI|transport") +/** + * 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 = "2.0", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|transport") package buildcraft.api.transport; -import cpw.mods.fml.common.API; \ No newline at end of file +import cpw.mods.fml.common.API; + diff --git a/src/api/java/ic2/api/energy/tile/IEnergySink.java b/src/api/java/ic2/api/energy/tile/IEnergySink.java index fe305783b..9676bff1b 100644 --- a/src/api/java/ic2/api/energy/tile/IEnergySink.java +++ b/src/api/java/ic2/api/energy/tile/IEnergySink.java @@ -11,15 +11,23 @@ public interface IEnergySink extends IEnergyAcceptor { /** * Determine how much energy the sink accepts. * - * This value is unrelated to getMaxSafeInput(). - * * Make sure that injectEnergy() does accepts energy if demandsEnergy() returns anything > 0. * * @note Modifying the energy net from this method is disallowed. * * @return max accepted input in eu */ - double demandedEnergyUnits(); + double getDemandedEnergy(); + + /** + * Determine the tier of this energy sink. + * 1 = LV, 2 = MV, 3 = HV, 4 = EV etc. + * + * @note Modifying the energy net from this method is disallowed. + * + * @return tier of this energy sink + */ + int getSinkTier(); /** * Transfer energy to the sink. @@ -31,20 +39,6 @@ public interface IEnergySink extends IEnergyAcceptor { * @param amount energy to be transferred * @return Energy not consumed (leftover) */ - double injectEnergyUnits(ForgeDirection directionFrom, double amount); - - /** - * Determine the amount of eu which can be safely injected into the specific energy sink without exploding. - * - * Typical values are 32 for LV, 128 for MV, 512 for HV and 2048 for EV. A value of Integer.MAX_VALUE indicates no - * limit. - * - * This value is unrelated to demandsEnergy(). - * - * @note Modifying the energy net from this method is disallowed. - * - * @return max safe input in eu - */ - int getMaxSafeInput(); + double injectEnergy(ForgeDirection directionFrom, double amount, double voltage); } diff --git a/src/api/java/ic2/api/energy/tile/IEnergySource.java b/src/api/java/ic2/api/energy/tile/IEnergySource.java index b864d4534..44b952a56 100644 --- a/src/api/java/ic2/api/energy/tile/IEnergySource.java +++ b/src/api/java/ic2/api/energy/tile/IEnergySource.java @@ -24,5 +24,15 @@ public interface IEnergySource extends IEnergyEmitter { * @param amount amount of EU to draw, may be negative */ void drawEnergy(double amount); + + /** + * Determine the tier of this energy source. + * 1 = LV, 2 = MV, 3 = HV, 4 = EV etc. + * + * @note Modifying the energy net from this method is disallowed. + * + * @return tier of this energy source + */ + int getSourceTier(); } diff --git a/src/api/java/ic2/api/info/IEnergyValueProvider.java b/src/api/java/ic2/api/info/IEnergyValueProvider.java index 50e84e6e8..178a95431 100644 --- a/src/api/java/ic2/api/info/IEnergyValueProvider.java +++ b/src/api/java/ic2/api/info/IEnergyValueProvider.java @@ -10,5 +10,5 @@ public interface IEnergyValueProvider { * @param itemStack ItemStack containing the item to evaluate. * @return energy in EU */ - int getEnergyValue(ItemStack itemStack); + double getEnergyValue(ItemStack itemStack); } diff --git a/src/api/java/ic2/api/item/ElectricItem.java b/src/api/java/ic2/api/item/ElectricItem.java index 511220fd8..19e5fc1b9 100644 --- a/src/api/java/ic2/api/item/ElectricItem.java +++ b/src/api/java/ic2/api/item/ElectricItem.java @@ -1,13 +1,12 @@ package ic2.api.item; -import net.minecraft.entity.player.EntityPlayer; +import java.util.ArrayList; +import java.util.List; + import net.minecraft.item.ItemStack; /** * Allows for charging, discharging and using electric items (IElectricItem). - * - * The charge or remaining capacity of an item can be determined by calling charge/discharge with - * ignoreTransferLimit and simulate set to true. */ public final class ElectricItem { /** @@ -25,84 +24,36 @@ public final class ElectricItem { public static IElectricItemManager rawManager; /** - * Charge an item with a specified amount of energy - * - * @param itemStack electric item's stack - * @param amount amount of energy to charge in EU - * @param tier tier of the charging device, has to be at least as high as the item to charge - * @param ignoreTransferLimit ignore the transfer limit specified by getTransferLimit() - * @param simulate don't actually change the item, just determine the return value - * @return Energy transferred into the electric item + * Register an electric item manager for items not implementing IElectricItem. * - * @deprecated use manager.charge() instead + * This method is only designed for special purposes, implementing IElectricItem or + * ISpecialElectricItem instead of using this is faster. + * + * Managers used with ISpecialElectricItem shouldn't be registered. + * + * @param manager Manager to register. */ - @Deprecated - public static int charge(ItemStack itemStack, int amount, int tier, boolean ignoreTransferLimit, boolean simulate) { - return manager.charge(itemStack, amount, tier, ignoreTransferLimit, simulate); + public static void registerBackupManager(IBackupElectricItemManager manager) { + backupManagers.add(manager); } /** - * Discharge an item by a specified amount of energy - * - * @param itemStack electric item's stack - * @param amount amount of energy to charge in EU - * @param tier tier of the discharging device, has to be at least as high as the item to discharge - * @param ignoreTransferLimit ignore the transfer limit specified by getTransferLimit() - * @param simulate don't actually discharge the item, just determine the return value - * @return Energy retrieved from the electric item + * Get the electric item manager suitable for the supplied item stack. * - * @deprecated use manager.discharge() instead + * This method is for internal use only. + * + * @param stack ItemStack to be handled. + * @return First suitable electric item manager. */ - @Deprecated - public static int discharge(ItemStack itemStack, int amount, int tier, boolean ignoreTransferLimit, boolean simulate) { - return manager.discharge(itemStack, amount, tier, ignoreTransferLimit, simulate); + public static IBackupElectricItemManager getBackupManager(ItemStack stack) { + for (IBackupElectricItemManager manager : backupManagers) { + if (manager.handles(stack)) return manager; + } + + return null; } - /** - * Determine if the specified electric item has at least a specific amount of EU. - * This is supposed to be used in the item code during operation, for example if you want to implement your own electric item. - * BatPacks are not taken into account. - * - * @param itemStack electric item's stack - * @param amount minimum amount of energy required - * @return true if there's enough energy - * - * @deprecated use manager.canUse() instead - */ - @Deprecated - public static boolean canUse(ItemStack itemStack, int amount) { - return manager.canUse(itemStack, amount); - } - /** - * Try to retrieve a specific amount of energy from an Item, and if applicable, a BatPack. - * This is supposed to be used in the item code during operation, for example if you want to implement your own electric item. - * - * @param itemStack electric item's stack - * @param amount amount of energy to discharge in EU - * @param player player holding the item - * @return true if the operation succeeded - * - * @deprecated use manager.use() instead - */ - @Deprecated - public static boolean use(ItemStack itemStack, int amount, EntityPlayer player) { - return manager.use(itemStack, amount, player); - } - - /** - * Charge an item from the BatPack a player is wearing. - * This is supposed to be used in the item code during operation, for example if you want to implement your own electric item. - * use() already contains this functionality. - * - * @param itemStack electric item's stack - * @param player player holding the item - * - * @deprecated use manager.chargeFromArmor() instead - */ - @Deprecated - public static void chargeFromArmor(ItemStack itemStack, EntityPlayer player) { - manager.chargeFromArmor(itemStack, player); - } + private static final List backupManagers = new ArrayList(); } diff --git a/src/api/java/ic2/api/item/IBackupElectricItemManager.java b/src/api/java/ic2/api/item/IBackupElectricItemManager.java new file mode 100644 index 000000000..2ae254acd --- /dev/null +++ b/src/api/java/ic2/api/item/IBackupElectricItemManager.java @@ -0,0 +1,12 @@ +package ic2.api.item; + +import net.minecraft.item.ItemStack; + +/** + * This interface specifies a manager applicable to items not implementing IElectricItem. + * + * The manager implementing this has to be registered with ElectricItem.registerBackupManager(). + */ +public interface IBackupElectricItemManager extends IElectricItemManager { + boolean handles(ItemStack stack); +} diff --git a/src/api/java/ic2/api/item/IElectricItem.java b/src/api/java/ic2/api/item/IElectricItem.java index 2cba11e96..5525e00f6 100644 --- a/src/api/java/ic2/api/item/IElectricItem.java +++ b/src/api/java/ic2/api/item/IElectricItem.java @@ -35,7 +35,7 @@ public interface IElectricItem { * * @return Maximum charge energy */ - int getMaxCharge(ItemStack itemStack); + double getMaxCharge(ItemStack itemStack); /** * Get the item's tier, lower tiers can't send energy to higher ones. @@ -50,6 +50,6 @@ public interface IElectricItem { * * @return Transfer limit */ - int getTransferLimit(ItemStack itemStack); + double getTransferLimit(ItemStack itemStack); } diff --git a/src/api/java/ic2/api/item/IElectricItemManager.java b/src/api/java/ic2/api/item/IElectricItemManager.java index 88eab750b..dfadbb26c 100644 --- a/src/api/java/ic2/api/item/IElectricItemManager.java +++ b/src/api/java/ic2/api/item/IElectricItemManager.java @@ -19,7 +19,7 @@ import net.minecraft.item.ItemStack; */ public interface IElectricItemManager { /** - * Charge an item with a specified amount of energy + * Charge an item with a specified amount of energy. * * @param itemStack electric item's stack * @param amount amount of energy to charge in EU @@ -28,27 +28,28 @@ public interface IElectricItemManager { * @param simulate don't actually change the item, just determine the return value * @return Energy transferred into the electric item */ - int charge(ItemStack itemStack, int amount, int tier, boolean ignoreTransferLimit, boolean simulate); + double charge(ItemStack stack, double amount, int tier, boolean ignoreTransferLimit, boolean simulate); /** * Discharge an item by a specified amount of energy * * @param itemStack electric item's stack - * @param amount amount of energy to charge in EU + * @param amount amount of energy to discharge in EU * @param tier tier of the discharging device, has to be at least as high as the item to discharge * @param ignoreTransferLimit ignore the transfer limit specified by getTransferLimit() + * @param externally use the supplied item externally, i.e. to power something else as if it was a battery * @param simulate don't actually discharge the item, just determine the return value * @return Energy retrieved from the electric item */ - int discharge(ItemStack itemStack, int amount, int tier, boolean ignoreTransferLimit, boolean simulate); + double discharge(ItemStack stack, double amount, int tier, boolean ignoreTransferLimit, boolean externally, boolean simulate); /** - * Determine the charge level for the specified item + * Determine the charge level for the specified item. * * @param itemStack ItemStack containing the electric item * @return charge level in EU */ - int getCharge(ItemStack itemStack); + double getCharge(ItemStack stack); /** * Determine if the specified electric item has at least a specific amount of EU. @@ -59,7 +60,7 @@ public interface IElectricItemManager { * @param amount minimum amount of energy required * @return true if there's enough energy */ - boolean canUse(ItemStack itemStack, int amount); + boolean canUse(ItemStack stack, double amount); /** * Try to retrieve a specific amount of energy from an Item, and if applicable, a BatPack. @@ -70,7 +71,7 @@ public interface IElectricItemManager { * @param entity entity holding the item * @return true if the operation succeeded */ - boolean use(ItemStack itemStack, int amount, EntityLivingBase entity); + boolean use(ItemStack stack, double amount, EntityLivingBase entity); /** * Charge an item from the BatPack a player is wearing. @@ -80,7 +81,7 @@ public interface IElectricItemManager { * @param itemStack electric item's stack * @param entity entity holding the item */ - void chargeFromArmor(ItemStack itemStack, EntityLivingBase entity); + void chargeFromArmor(ItemStack stack, EntityLivingBase entity); /** * Get the tool tip to display for electric items. @@ -88,5 +89,5 @@ public interface IElectricItemManager { * @param itemStack ItemStack to determine the tooltip for * @return tool tip string or null for none */ - String getToolTip(ItemStack itemStack); + String getToolTip(ItemStack stack); } diff --git a/src/api/java/ic2/api/recipe/IFluidHeatManager.java b/src/api/java/ic2/api/recipe/IFluidHeatManager.java new file mode 100644 index 000000000..7ddecdce4 --- /dev/null +++ b/src/api/java/ic2/api/recipe/IFluidHeatManager.java @@ -0,0 +1,32 @@ +package ic2.api.recipe; + +import java.util.Map; + +import net.minecraftforge.fluids.Fluid; + + +public interface IFluidHeatManager extends ILiquidAcceptManager { + /** + * Add a new fluid to the Fluid Heat Generator. + * + * @param fluidName the fluid to burn + * @param amount amount of fluid to consume per tick + * @param heat amount of heat generated per tick + */ + void addFluid(String fluidName, int amount, int heat); + + BurnProperty getBurnProperty(Fluid fluid); + + Map getBurnProperties(); + + + public static class BurnProperty { + public BurnProperty(int amount1, int heat1) { + this.amount = amount1; + this.heat = heat1; + } + + public final int amount; + public final int heat; + } +} diff --git a/src/api/java/ic2/api/recipe/Recipes.java b/src/api/java/ic2/api/recipe/Recipes.java index 336bc078e..2ee76fc1b 100644 --- a/src/api/java/ic2/api/recipe/Recipes.java +++ b/src/api/java/ic2/api/recipe/Recipes.java @@ -1,7 +1,5 @@ package ic2.api.recipe; - - /** * General recipe registry. * @@ -55,5 +53,6 @@ public class Recipes { public static ICraftingRecipeManager advRecipes; public static ISemiFluidFuelManager semiFluidGenerator; + public static IFluidHeatManager FluidHeatGenerator; }