From 695313802af7c6f30e170b6d4d22bf16bcfa64b7 Mon Sep 17 00:00:00 2001 From: asiekierka Date: Sun, 30 Nov 2014 10:07:20 +0100 Subject: [PATCH] API: cleanup, remove unused functions, improve documentation --- api/buildcraft/api/core/IWorldProperty.java | 1 - api/buildcraft/api/core/JavaTools.java | 44 ------- api/buildcraft/api/core/SafeTimeTracker.java | 2 +- api/buildcraft/api/core/WorldBlockIndex.java | 108 ------------------ api/buildcraft/api/power/IEngine.java | 15 +++ api/buildcraft/api/power/ILaserTarget.java | 18 +++ .../api/power/ILaserTargetBlock.java | 6 + api/buildcraft/api/tiles/IControllable.java | 22 ++++ api/buildcraft/api/tiles/IHasWork.java | 8 ++ api/buildcraft/api/tiles/IHeatable.java | 24 ++++ 10 files changed, 94 insertions(+), 154 deletions(-) delete mode 100755 api/buildcraft/api/core/WorldBlockIndex.java diff --git a/api/buildcraft/api/core/IWorldProperty.java b/api/buildcraft/api/core/IWorldProperty.java index 4a900c62..9da1a7f1 100755 --- a/api/buildcraft/api/core/IWorldProperty.java +++ b/api/buildcraft/api/core/IWorldProperty.java @@ -11,7 +11,6 @@ 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/api/buildcraft/api/core/JavaTools.java b/api/buildcraft/api/core/JavaTools.java index 1566951b..9d727115 100755 --- a/api/buildcraft/api/core/JavaTools.java +++ b/api/buildcraft/api/core/JavaTools.java @@ -17,10 +17,6 @@ import java.util.Collections; 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); @@ -39,46 +35,6 @@ public class JavaTools { 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) { - Collections.addAll(result, current.getDeclaredFields()); - - current = current.getSuperclass(); - } - - return result; - } - - public static List getAllMethods(Class clas) { - List result = new ArrayList(); - - Class current = clas; - - while (current != null && current != Object.class) { - Collections.addAll(result, current.getDeclaredMethods()); - - current = current.getSuperclass(); - } - - return result; - } - public static String surroundWithQuotes(String stringToSurroundWithQuotes) { return String.format("\"%s\"", stringToSurroundWithQuotes); } diff --git a/api/buildcraft/api/core/SafeTimeTracker.java b/api/buildcraft/api/core/SafeTimeTracker.java index 9b60b86e..ef804f3b 100644 --- a/api/buildcraft/api/core/SafeTimeTracker.java +++ b/api/buildcraft/api/core/SafeTimeTracker.java @@ -82,4 +82,4 @@ public class SafeTimeTracker { public void markTime(World world) { lastMark = world.getTotalWorldTime(); } -} +} \ No newline at end of file diff --git a/api/buildcraft/api/core/WorldBlockIndex.java b/api/buildcraft/api/core/WorldBlockIndex.java deleted file mode 100755 index aedbeaf5..00000000 --- a/api/buildcraft/api/core/WorldBlockIndex.java +++ /dev/null @@ -1,108 +0,0 @@ -/** - * Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team - * http://www.mod-buildcraft.com - * - * BuildCraft is distributed under the terms of the Minecraft Mod Public - * License 1.0, or MMPL. Please check the contents of the license located in - * http://www.mod-buildcraft.com/MMPL-1.0.txt - */ -package buildcraft.api.core; - -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 WorldBlockIndex implements Comparable { - - public int x; - public int y; - public int z; - public int dimension; - - public WorldBlockIndex() { - - } - - /** - * Creates an index for a block located on x, y. z - */ - public WorldBlockIndex(World world, int x, int y, int z) { - - dimension = world.provider.dimensionId; - this.x = x; - this.y = y; - this.z = z; - } - - public WorldBlockIndex(NBTTagCompound c) { - dimension = c.getInteger("dimension"); - x = c.getInteger("x"); - y = c.getInteger("y"); - z = c.getInteger("z"); - } - - public WorldBlockIndex(Entity entity) { - dimension = entity.worldObj.provider.dimensionId; - 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(WorldBlockIndex o) { - - if (o.dimension < dimension) { - return 1; - } else if (o.dimension > dimension) { - return -1; - } else 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("dimension", dimension); - c.setInteger("x", x); - c.setInteger("y", y); - c.setInteger("z", z); - } - - @Override - public String toString() { - return "{" + dimension + ":" + x + ", " + y + ", " + z + "}"; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof WorldBlockIndex) { - WorldBlockIndex b = (WorldBlockIndex) obj; - - return b.dimension == dimension && b.x == x && b.y == y && b.z == z; - } - - return super.equals(obj); - } - - @Override - public int hashCode() { - return (dimension * 37 + (x * 37 + y)) * 37 + z; - } -} diff --git a/api/buildcraft/api/power/IEngine.java b/api/buildcraft/api/power/IEngine.java index 406a8d4d..4b694765 100644 --- a/api/buildcraft/api/power/IEngine.java +++ b/api/buildcraft/api/power/IEngine.java @@ -16,6 +16,21 @@ import net.minecraftforge.common.util.ForgeDirection; * without using receiveEnergy() (which has other issues). */ public interface IEngine { + /** + * Returns true if the engine wants to receive power from + * another engine on this side. + * @param side + * @return + */ boolean canReceiveFromEngine(ForgeDirection side); + + /** + * Receives energy from an engine. + * See {@link cofh.api.energy.IEnergyHandler#receiveEnergy(ForgeDirection, int, boolean)} + * @param side The side the engine is receiving energy from. + * @param energy The amount of energy given to the engine. + * @param simulate True if the energy should not actually be added. + * @return The amount of energy used by the engine. + */ int receiveEnergyFromEngine(ForgeDirection side, int energy, boolean simulate); } diff --git a/api/buildcraft/api/power/ILaserTarget.java b/api/buildcraft/api/power/ILaserTarget.java index 8d896cb8..39b04f01 100644 --- a/api/buildcraft/api/power/ILaserTarget.java +++ b/api/buildcraft/api/power/ILaserTarget.java @@ -8,6 +8,12 @@ */ package buildcraft.api.power; +/** + * This interface should be defined by any Tile which wants + * to receive energy from BuildCraft lasers. + * + * The respective Block MUST implement ILaserTargetBlock! + */ public interface ILaserTarget { /** @@ -33,9 +39,21 @@ public interface ILaserTarget { */ boolean isInvalidTarget(); + /** + * Get the X coordinate of the laser stream. + * @return + */ double getXCoord(); + /** + * Get the Y coordinate of the laser stream. + * @return + */ double getYCoord(); + /** + * Get the Z coordinate of the laser stream. + * @return + */ double getZCoord(); } diff --git a/api/buildcraft/api/power/ILaserTargetBlock.java b/api/buildcraft/api/power/ILaserTargetBlock.java index 71298b14..6534ca85 100644 --- a/api/buildcraft/api/power/ILaserTargetBlock.java +++ b/api/buildcraft/api/power/ILaserTargetBlock.java @@ -8,6 +8,12 @@ */ package buildcraft.api.power; +/** + * This is a marker interface for laser targets. Implement it on + * your Block. + * + * It is used by BuildCraft Lasers for optimization purposes. + */ public interface ILaserTargetBlock { } diff --git a/api/buildcraft/api/tiles/IControllable.java b/api/buildcraft/api/tiles/IControllable.java index b2739fa3..f3a737e3 100644 --- a/api/buildcraft/api/tiles/IControllable.java +++ b/api/buildcraft/api/tiles/IControllable.java @@ -8,12 +8,34 @@ */ package buildcraft.api.tiles; +/** + * This interface should be implemented by any Tile Entity which wishes to + * have non-redstone automation (for example, BuildCraft Gates, but also + * other mods which implement it, e.g. OpenComputers). + */ public interface IControllable { public enum Mode { Unknown, On, Off, Loop } + /** + * Get the current control mode of the Tile Entity. + * @return + */ Mode getControlMode(); + + /** + * Set the mode of the Tile Entity. + * @param mode + */ void setControlMode(Mode mode); + + /** + * Check if a given control mode is accepted. + * If you query IControllable tiles, you MUST check with + * acceptsControlMode first. + * @param mode + * @return True if this control mode is accepted. + */ boolean acceptsControlMode(Mode mode); } diff --git a/api/buildcraft/api/tiles/IHasWork.java b/api/buildcraft/api/tiles/IHasWork.java index 6eff8f5b..f95c7e56 100644 --- a/api/buildcraft/api/tiles/IHasWork.java +++ b/api/buildcraft/api/tiles/IHasWork.java @@ -8,6 +8,14 @@ */ package buildcraft.api.tiles; +/** + * This interface should be implemented by any Tile Entity which carries out + * work (crafting, ore processing, mining, et cetera). + */ public interface IHasWork { + /** + * Check if the Tile Entity is currently doing any work. + * @return True if the Tile Entity is doing work. + */ boolean hasWork(); } diff --git a/api/buildcraft/api/tiles/IHeatable.java b/api/buildcraft/api/tiles/IHeatable.java index 7e825178..f507047f 100644 --- a/api/buildcraft/api/tiles/IHeatable.java +++ b/api/buildcraft/api/tiles/IHeatable.java @@ -8,11 +8,35 @@ */ package buildcraft.api.tiles; +/** + * This interface should be implemented by Tile Entities + * which have an internal heat value. + */ public interface IHeatable { + /** + * @return The minimum heat value, in degrees. + */ double getMinHeatValue(); + + /** + * @return The preferred heat value, in degrees. + */ double getIdealHeatValue(); + + /** + * @return The maxmimum heat value, in degrees. + */ double getMaxHeatValue(); + /** + * @return The current heat value, in degrees. + */ double getCurrentHeatValue(); + + /** + * Set the heat of the tile. + * @param value Heat value, in degrees. + * @return The heat the tile has after the set. + */ double setHeatValue(double value); }