Update lots of APIs, most notably BC and an actual 1.7 version of CC
This commit is contained in:
parent
e2e3e1017f
commit
4d1c1285b2
108 changed files with 1676 additions and 2403 deletions
|
@ -1,6 +1,6 @@
|
|||
minecraft_version=1.7.10
|
||||
forge_version=10.13.0.1180
|
||||
FMP_version=1.1.0.297
|
||||
CCLIB_version=1.1.1.93
|
||||
NEI_version=1.0.2.15
|
||||
forge_version=10.13.0.1208
|
||||
FMP_version=1.1.0.314
|
||||
CCLIB_version=1.1.1.106
|
||||
NEI_version=1.0.3.67
|
||||
mod_version=7.1.1
|
||||
|
|
|
@ -9,12 +9,14 @@
|
|||
package buildcraft.api.core;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public final class BCLog {
|
||||
|
||||
public static final Logger logger = Logger.getLogger("Buildcraft");
|
||||
public static final Logger logger = LogManager.getLogger("BuildCraft");
|
||||
|
||||
/**
|
||||
* Deactivate constructor
|
||||
|
@ -23,11 +25,9 @@ public final class 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("Copyright (c) SpaceToad, 2011-2014");
|
||||
logger.info("http://www.mod-buildcraft.com");
|
||||
}
|
||||
|
||||
|
@ -39,12 +39,12 @@ public final class BCLog {
|
|||
msg.append(", ").append(stackTrace[0]);
|
||||
}
|
||||
|
||||
logger.log(Level.SEVERE, msg.toString());
|
||||
logger.log(Level.ERROR, 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());
|
||||
logger.log(Level.ERROR, msg.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ package buildcraft.api.core;
|
|||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
|
@ -48,6 +49,10 @@ public class BlockIndex implements Comparable<BlockIndex> {
|
|||
z = (int) Math.floor(entity.posZ);
|
||||
}
|
||||
|
||||
public BlockIndex(TileEntity entity) {
|
||||
this(entity.xCoord, entity.yCoord, entity.zCoord);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a deterministic and complete ordering of block positions.
|
||||
*/
|
||||
|
@ -101,4 +106,10 @@ public class BlockIndex implements Comparable<BlockIndex> {
|
|||
public int hashCode() {
|
||||
return (x * 37 + y) * 37 + z;
|
||||
}
|
||||
|
||||
public boolean nextTo(BlockIndex blockIndex) {
|
||||
return (Math.abs(blockIndex.x - x) <= 1 && blockIndex.y == y && blockIndex.z == z)
|
||||
|| (blockIndex.x == x && Math.abs(blockIndex.y - y) <= 1 && blockIndex.z == z)
|
||||
|| (blockIndex.x == x && blockIndex.y == y && Math.abs(blockIndex.z - z) <= 1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,12 +23,12 @@ public final class BuildCraftAPI {
|
|||
public static IWorldProperty isSoftProperty;
|
||||
public static IWorldProperty isWoodProperty;
|
||||
public static IWorldProperty isLeavesProperty;
|
||||
public static IWorldProperty isBasicOreProperty;
|
||||
public static IWorldProperty isExtendedOreProperty;
|
||||
public static IWorldProperty[] isOreProperty;
|
||||
public static IWorldProperty isHarvestableProperty;
|
||||
public static IWorldProperty isFarmlandProperty;
|
||||
public static IWorldProperty isDirtProperty;
|
||||
public static IWorldProperty isShoveled;
|
||||
public static IWorldProperty isFluidSource;
|
||||
|
||||
/**
|
||||
* Deactivate constructor
|
||||
|
|
207
src/api/java/buildcraft/api/core/EnumColor.java
Normal file
207
src/api/java/buildcraft/api/core/EnumColor.java
Normal file
|
@ -0,0 +1,207 @@
|
|||
/**
|
||||
* 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.Locale;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.StatCollector;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public enum EnumColor {
|
||||
|
||||
BLACK,
|
||||
RED,
|
||||
GREEN,
|
||||
BROWN,
|
||||
BLUE,
|
||||
PURPLE,
|
||||
CYAN,
|
||||
LIGHT_GRAY,
|
||||
GRAY,
|
||||
PINK,
|
||||
LIME,
|
||||
YELLOW,
|
||||
LIGHT_BLUE,
|
||||
MAGENTA,
|
||||
ORANGE,
|
||||
WHITE;
|
||||
public static final EnumColor[] VALUES = values();
|
||||
public static final String[] DYES = {
|
||||
"dyeBlack",
|
||||
"dyeRed",
|
||||
"dyeGreen",
|
||||
"dyeBrown",
|
||||
"dyeBlue",
|
||||
"dyePurple",
|
||||
"dyeCyan",
|
||||
"dyeLightGray",
|
||||
"dyeGray",
|
||||
"dyePink",
|
||||
"dyeLime",
|
||||
"dyeYellow",
|
||||
"dyeLightBlue",
|
||||
"dyeMagenta",
|
||||
"dyeOrange",
|
||||
"dyeWhite"};
|
||||
public static final String[] NAMES = {
|
||||
"Black",
|
||||
"Red",
|
||||
"Green",
|
||||
"Brown",
|
||||
"Blue",
|
||||
"Purple",
|
||||
"Cyan",
|
||||
"LightGray",
|
||||
"Gray",
|
||||
"Pink",
|
||||
"Lime",
|
||||
"Yellow",
|
||||
"LightBlue",
|
||||
"Magenta",
|
||||
"Orange",
|
||||
"White"};
|
||||
public static final int[] DARK_HEX = {
|
||||
0x2D2D2D,
|
||||
0xA33835,
|
||||
0x394C1E,
|
||||
0x5C3A24,
|
||||
0x3441A2,
|
||||
0x843FBF,
|
||||
0x36809E,
|
||||
0x888888,
|
||||
0x444444,
|
||||
0xE585A0,
|
||||
0x3FAA36,
|
||||
0xCFC231,
|
||||
0x7F9AD1,
|
||||
0xFF64FF,
|
||||
0xFF6A00,
|
||||
0xFFFFFF};
|
||||
public static final int[] LIGHT_HEX = {
|
||||
0x181414,
|
||||
0xBE2B27,
|
||||
0x007F0E,
|
||||
0x89502D,
|
||||
0x253193,
|
||||
0x7e34bf,
|
||||
0x299799,
|
||||
0xa0a7a7,
|
||||
0x7A7A7A,
|
||||
0xD97199,
|
||||
0x39D52E,
|
||||
0xFFD91C,
|
||||
0x66AAFF,
|
||||
0xD943C6,
|
||||
0xEA7835,
|
||||
0xe4e4e4};
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private static IIcon[] brushIcons;
|
||||
|
||||
public int getDarkHex() {
|
||||
return DARK_HEX[ordinal()];
|
||||
}
|
||||
|
||||
public int getLightHex() {
|
||||
return LIGHT_HEX[ordinal()];
|
||||
}
|
||||
|
||||
public static EnumColor fromId(int id) {
|
||||
if (id < 0 || id >= VALUES.length) {
|
||||
return WHITE;
|
||||
}
|
||||
return VALUES[id];
|
||||
}
|
||||
|
||||
public static EnumColor fromDye(String dyeTag) {
|
||||
for (int id = 0; id < DYES.length; id++) {
|
||||
if (DYES[id].equals(dyeTag)) {
|
||||
return VALUES[id];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static EnumColor fromName(String name) {
|
||||
for (int id = 0; id < NAMES.length; id++) {
|
||||
if (NAMES[id].equals(name)) {
|
||||
return VALUES[id];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static EnumColor getRand() {
|
||||
return VALUES[new Random().nextInt(VALUES.length)];
|
||||
}
|
||||
|
||||
public EnumColor getNext() {
|
||||
EnumColor next = VALUES[(ordinal() + 1) % VALUES.length];
|
||||
return next;
|
||||
}
|
||||
|
||||
public EnumColor getPrevious() {
|
||||
EnumColor previous = VALUES[(ordinal() + VALUES.length - 1) % VALUES.length];
|
||||
return previous;
|
||||
}
|
||||
|
||||
public EnumColor inverse() {
|
||||
return EnumColor.VALUES[15 - ordinal()];
|
||||
}
|
||||
|
||||
public String getTag() {
|
||||
return "color." + name().replace("_", ".").toLowerCase(Locale.ENGLISH);
|
||||
}
|
||||
|
||||
public String getBasicTag() {
|
||||
return name().replace("_", ".").toLowerCase(Locale.ENGLISH);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return NAMES[ordinal()];
|
||||
}
|
||||
|
||||
public String getLocalizedName() {
|
||||
return StatCollector.translateToLocal(getTag());
|
||||
}
|
||||
|
||||
public String getDye() {
|
||||
return DYES[ordinal()];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String s = name().replace("_", " ");
|
||||
String[] words = s.split(" ");
|
||||
StringBuilder b = new StringBuilder();
|
||||
for (String word : words) {
|
||||
b.append(word.charAt(0)).append(word.substring(1).toLowerCase(Locale.ENGLISH)).append(" ");
|
||||
}
|
||||
return b.toString().trim();
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void registerIcons(IIconRegister iconRegister) {
|
||||
brushIcons = new IIcon[16];
|
||||
for (EnumColor c : values()) {
|
||||
brushIcons[c.ordinal()] = iconRegister.registerIcon("buildcraft:triggers/color_"
|
||||
+ c.name().toLowerCase(Locale.ENGLISH));
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getIcon() {
|
||||
return brushIcons [ordinal()];
|
||||
}
|
||||
}
|
|
@ -8,14 +8,12 @@
|
|||
*/
|
||||
package buildcraft.api.core;
|
||||
|
||||
public interface IBox {
|
||||
public interface IBox extends IZone {
|
||||
|
||||
IBox expand(int amount);
|
||||
|
||||
IBox contract(int amount);
|
||||
|
||||
boolean contains(double x, double y, double z);
|
||||
|
||||
Position pMin();
|
||||
|
||||
Position pMax();
|
||||
|
|
21
src/api/java/buildcraft/api/core/IZone.java
Executable file
21
src/api/java/buildcraft/api/core/IZone.java
Executable file
|
@ -0,0 +1,21 @@
|
|||
/**
|
||||
* 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.Random;
|
||||
|
||||
public interface IZone {
|
||||
|
||||
double distanceTo(BlockIndex index);
|
||||
|
||||
boolean contains(double x, double y, double z);
|
||||
|
||||
BlockIndex getRandomBlockIndex(Random rand);
|
||||
|
||||
}
|
|
@ -64,6 +64,13 @@ public class Position {
|
|||
orientation = ForgeDirection.UNKNOWN;
|
||||
}
|
||||
|
||||
public Position(BlockIndex index) {
|
||||
x = index.x;
|
||||
y = index.y;
|
||||
z = index.z;
|
||||
orientation = ForgeDirection.UNKNOWN;
|
||||
}
|
||||
|
||||
public void moveRight(double step) {
|
||||
switch (orientation) {
|
||||
case SOUTH:
|
||||
|
@ -171,5 +178,4 @@ public class Position {
|
|||
|
||||
return !(sqrDis > f * f);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,49 +8,127 @@
|
|||
*/
|
||||
package buildcraft.api.core;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
/**
|
||||
* This class is used whenever stacks needs to be stored as keys.
|
||||
*/
|
||||
public class StackKey {
|
||||
|
||||
public final class StackKey {
|
||||
public final ItemStack stack;
|
||||
public final FluidStack fluidStack;
|
||||
|
||||
public StackKey(FluidStack fluidStack) {
|
||||
this(null, fluidStack);
|
||||
}
|
||||
|
||||
public StackKey(ItemStack stack) {
|
||||
this(stack, null);
|
||||
}
|
||||
|
||||
public StackKey(ItemStack stack, FluidStack fluidStack) {
|
||||
this.stack = stack;
|
||||
this.fluidStack = fluidStack;
|
||||
}
|
||||
|
||||
public static StackKey stack(Item item, int amount, int damage) {
|
||||
return new StackKey(new ItemStack(item, amount, damage));
|
||||
}
|
||||
|
||||
public static StackKey stack(Block block, int amount, int damage) {
|
||||
return new StackKey(new ItemStack(block, amount, damage));
|
||||
}
|
||||
|
||||
public static StackKey stack(Item item) {
|
||||
return new StackKey(new ItemStack(item, 1, 0));
|
||||
}
|
||||
|
||||
public static StackKey stack(Block block) {
|
||||
return new StackKey(new ItemStack(block, 1, 0));
|
||||
}
|
||||
|
||||
public static StackKey stack(ItemStack itemStack) {
|
||||
return new StackKey(itemStack);
|
||||
}
|
||||
|
||||
public static StackKey fluid(Fluid fluid, int amount) {
|
||||
return new StackKey(new FluidStack(fluid, amount));
|
||||
}
|
||||
|
||||
public static StackKey fluid(Fluid fluid) {
|
||||
return new StackKey(new FluidStack(fluid, FluidContainerRegistry.BUCKET_VOLUME));
|
||||
}
|
||||
|
||||
public static StackKey fluid(FluidStack fluidStack) {
|
||||
return new StackKey(fluidStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || o.getClass() != StackKey.class) {
|
||||
return false;
|
||||
}
|
||||
StackKey k = (StackKey) o;
|
||||
if ((stack == null ^ k.stack == null) || (fluidStack == null ^ k.fluidStack == null)) {
|
||||
return false;
|
||||
}
|
||||
if (stack != null) {
|
||||
if (stack.getItem() != k.stack.getItem() ||
|
||||
stack.getHasSubtypes() && stack.getItemDamage() != k.stack.getItemDamage() ||
|
||||
!objectsEqual(stack.getTagCompound(), k.stack.getTagCompound())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (fluidStack != null) {
|
||||
if (fluidStack.fluidID != k.fluidStack.fluidID ||
|
||||
fluidStack.amount != k.fluidStack.amount ||
|
||||
!objectsEqual(fluidStack.tag, k.fluidStack.tag)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@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();
|
||||
int result = 7;
|
||||
if (stack != null) {
|
||||
result = 31 * result + stack.getItem().hashCode();
|
||||
result = 31 * result + stack.getItemDamage();
|
||||
result = 31 * result + objectHashCode(stack.getTagCompound());
|
||||
}
|
||||
result = 31 * result + 7;
|
||||
if (fluidStack != null) {
|
||||
result = 31 * result + fluidStack.fluidID;
|
||||
result = 31 * result + fluidStack.amount;
|
||||
result = 31 * result + objectHashCode(fluidStack.tag);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
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()) {
|
||||
private boolean objectsEqual(Object o1, Object o2) {
|
||||
if (o1 == null && o2 == null) {
|
||||
return true;
|
||||
} else if (o1 == null || o2 == null) {
|
||||
return false;
|
||||
} else {
|
||||
return !(stack.stackTagCompound != null && !stack.stackTagCompound.equals(other.stack.stackTagCompound));
|
||||
return o1.equals(o2);
|
||||
}
|
||||
}
|
||||
|
||||
private int objectHashCode(Object o) {
|
||||
return o != null ? o.hashCode() : 0;
|
||||
}
|
||||
|
||||
public StackKey copy() {
|
||||
return new StackKey(stack != null ? stack.copy() : null,
|
||||
fluidStack != null ? fluidStack.copy() : null);
|
||||
}
|
||||
}
|
||||
|
|
108
src/api/java/buildcraft/api/core/WorldBlockIndex.java
Executable file
108
src/api/java/buildcraft/api/core/WorldBlockIndex.java
Executable file
|
@ -0,0 +1,108 @@
|
|||
/**
|
||||
* 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<WorldBlockIndex> {
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -6,6 +6,12 @@
|
|||
* 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;
|
||||
package buildcraft.api.fuels;
|
||||
|
||||
public final class BuildcraftFuelRegistry {
|
||||
public static IFuelManager fuel;
|
||||
public static ICoolantManager coolant;
|
||||
|
||||
private BuildcraftFuelRegistry() {
|
||||
}
|
||||
}
|
|
@ -6,8 +6,12 @@
|
|||
* 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;
|
||||
package buildcraft.api.fuels;
|
||||
|
||||
public interface IBatteryProvider {
|
||||
IBatteryObject getMjBattery(String kind);
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
|
||||
public interface ICoolant {
|
||||
Fluid getFluid();
|
||||
|
||||
float getDegreesCoolingPerMB(float heat);
|
||||
}
|
33
src/api/java/buildcraft/api/fuels/ICoolantManager.java
Normal file
33
src/api/java/buildcraft/api/fuels/ICoolantManager.java
Normal file
|
@ -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.fuels;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
|
||||
import buildcraft.api.core.StackKey;
|
||||
|
||||
public interface ICoolantManager {
|
||||
ICoolant addCoolant(ICoolant coolant);
|
||||
|
||||
ICoolant addCoolant(Fluid fluid, float degreesCoolingPerMB);
|
||||
|
||||
ISolidCoolant addSolidCoolant(ISolidCoolant solidCoolant);
|
||||
|
||||
ISolidCoolant addSolidCoolant(StackKey solid, StackKey liquid, float multiplier);
|
||||
|
||||
Collection<ICoolant> getCoolants();
|
||||
|
||||
Collection<ISolidCoolant> getSolidCoolants();
|
||||
|
||||
ICoolant getCoolant(Fluid fluid);
|
||||
|
||||
ISolidCoolant getSolidCoolant(StackKey solid);
|
||||
}
|
|
@ -6,6 +6,14 @@
|
|||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
@API(apiVersion = "1.1", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|mj")
|
||||
package buildcraft.api.mj;
|
||||
import cpw.mods.fml.common.API;
|
||||
package buildcraft.api.fuels;
|
||||
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
|
||||
public interface IFuel {
|
||||
Fluid getFluid();
|
||||
|
||||
int getTotalBurningTime();
|
||||
|
||||
int getPowerPerCycle();
|
||||
}
|
23
src/api/java/buildcraft/api/fuels/IFuelManager.java
Normal file
23
src/api/java/buildcraft/api/fuels/IFuelManager.java
Normal file
|
@ -0,0 +1,23 @@
|
|||
/**
|
||||
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
|
||||
* http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
package buildcraft.api.fuels;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
|
||||
public interface IFuelManager {
|
||||
IFuel addFuel(IFuel fuel);
|
||||
|
||||
IFuel addFuel(Fluid fluid, int powerPerCycle, int totalBurningTime);
|
||||
|
||||
Collection<IFuel> getFuels();
|
||||
|
||||
IFuel getFuel(Fluid fluid);
|
||||
}
|
16
src/api/java/buildcraft/api/fuels/ISolidCoolant.java
Normal file
16
src/api/java/buildcraft/api/fuels/ISolidCoolant.java
Normal file
|
@ -0,0 +1,16 @@
|
|||
/**
|
||||
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
|
||||
* http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
package buildcraft.api.fuels;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
public interface ISolidCoolant {
|
||||
FluidStack getFluidFromSolidCoolant(ItemStack stack);
|
||||
}
|
|
@ -1,92 +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.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<String, Coolant> liquidCoolants = new HashMap<String, Coolant>();
|
||||
public static Map<StackKey, FluidStack> solidCoolants = new HashMap<StackKey, FluidStack>();
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
|
@ -1,52 +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.fuels;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
|
||||
public final class IronEngineFuel {
|
||||
|
||||
public static Map<String, Fuel> fuels = new HashMap<String, Fuel>();
|
||||
|
||||
private IronEngineFuel() {
|
||||
}
|
||||
|
||||
public static Fuel getFuelForFluid(Fluid liquid) {
|
||||
return liquid == null ? null : fuels.get(liquid.getName());
|
||||
}
|
||||
|
||||
public static final class Fuel {
|
||||
|
||||
public final Fluid liquid;
|
||||
public final float powerPerCycle;
|
||||
public final int totalBurningTime;
|
||||
|
||||
private Fuel(String fluidName, float powerPerCycle, int totalBurningTime) {
|
||||
this(FluidRegistry.getFluid(fluidName), powerPerCycle, totalBurningTime);
|
||||
}
|
||||
|
||||
private Fuel(Fluid liquid, float powerPerCycle, int totalBurningTime) {
|
||||
this.liquid = liquid;
|
||||
this.powerPerCycle = powerPerCycle;
|
||||
this.totalBurningTime = totalBurningTime;
|
||||
}
|
||||
}
|
||||
|
||||
public static void addFuel(Fluid fluid, float powerPerCycle, int totalBurningTime) {
|
||||
fuels.put(fluid.getName(), new Fuel(fluid, powerPerCycle, totalBurningTime));
|
||||
}
|
||||
|
||||
public static void addFuel(String fluidName, float powerPerCycle, int totalBurningTime) {
|
||||
fuels.put(fluidName, new Fuel(fluidName, powerPerCycle, totalBurningTime));
|
||||
}
|
||||
}
|
|
@ -6,6 +6,6 @@
|
|||
* 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")
|
||||
@API(apiVersion = "2.0", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|fuels")
|
||||
package buildcraft.api.fuels;
|
||||
import cpw.mods.fml.common.API;
|
||||
|
|
|
@ -6,10 +6,17 @@
|
|||
* 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;
|
||||
package buildcraft.api.gates;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public interface ISidedBatteryProvider {
|
||||
IBatteryObject getMjBattery(String kind, ForgeDirection direction);
|
||||
import buildcraft.api.transport.IPipe;
|
||||
|
||||
public interface IGate {
|
||||
@Deprecated
|
||||
void setPulsing(boolean pulse);
|
||||
|
||||
ForgeDirection getSide();
|
||||
|
||||
IPipe getPipe();
|
||||
}
|
|
@ -1,199 +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.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;
|
||||
}
|
||||
}
|
|
@ -1,27 +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.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();
|
||||
}
|
|
@ -1,77 +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.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);
|
||||
}
|
|
@ -1,30 +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.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;
|
||||
}
|
||||
}
|
|
@ -1,439 +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.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<BatteryHolder, BatteryField> mjBatteryFields = new HashMap<BatteryHolder, BatteryField>();
|
||||
private static Map<String, Class<? extends IBatteryObject>> mjBatteryKinds = new HashMap<String, Class<? extends IBatteryObject>>();
|
||||
private static final BatteryField invalidBatteryField = new BatteryField();
|
||||
private static final MjReconfigurator reconfigurator = new MjReconfigurator();
|
||||
private static final Map<Object, BatteryCache> mjBatteryCache = new WeakHashMap<Object, BatteryCache>();
|
||||
|
||||
/**
|
||||
* 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<? extends IBatteryObject> 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:<br />
|
||||
* <code>
|
||||
* MjAPI.reconfigure().maxCapacity(battery, 15000);
|
||||
* </code>
|
||||
* @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<IBatteryObject> cache = new TIntObjectHashMap<IBatteryObject>();
|
||||
|
||||
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<? extends Object> 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 <T> boolean contains(T[] array, T value) {
|
||||
for (T t : array) {
|
||||
if (t == value) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static {
|
||||
registerMJBatteryKind(DEFAULT_POWER_FRAMEWORK, BatteryObject.class);
|
||||
}
|
||||
}
|
|
@ -1,60 +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.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;
|
||||
}
|
||||
}
|
|
@ -1,86 +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.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;
|
||||
}
|
|
@ -1,183 +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.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<? extends Annotation> 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<ForgeDirection> newSides = new ArrayList<ForgeDirection>(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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,41 +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.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();
|
||||
}
|
|
@ -1,21 +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.power;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
/**
|
||||
* Essentially only used for Wooden Power Pipe connection rules.
|
||||
*
|
||||
* This Tile Entity interface allows you to indicate that a block can emit power
|
||||
* from a specific side.
|
||||
*/
|
||||
public interface IPowerEmitter {
|
||||
boolean canEmitPowerFrom(ForgeDirection side);
|
||||
}
|
|
@ -1,45 +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.power;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
/**
|
||||
* This interface should be implemented by any Tile Entity that wishes to be
|
||||
* able to receive power.
|
||||
*/
|
||||
public interface IPowerReceptor {
|
||||
|
||||
/**
|
||||
* Get the PowerReceiver for this side of the block. You can return the same
|
||||
* PowerReceiver for all sides or one for each side.
|
||||
*
|
||||
* You should NOT return null to this method unless you mean to NEVER
|
||||
* receive power from that side. Returning null, after previous returning a
|
||||
* PowerReceiver, will most likely cause pipe connections to derp out and
|
||||
* engines to eventually explode.
|
||||
*
|
||||
* @param side
|
||||
*/
|
||||
PowerHandler.PowerReceiver getPowerReceiver(ForgeDirection side);
|
||||
|
||||
/**
|
||||
* Call back from the PowerHandler that is called when the stored power
|
||||
* exceeds the activation power.
|
||||
*
|
||||
* It can be triggered by update() calls or power modification calls.
|
||||
*
|
||||
* @param workProvider
|
||||
*/
|
||||
void doWork(PowerHandler workProvider);
|
||||
|
||||
World getWorld();
|
||||
}
|
|
@ -1,516 +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.power;
|
||||
|
||||
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.
|
||||
* <p/>
|
||||
* To receive power to your machine you needs create an instance of PowerHandler
|
||||
* and implement IPowerReceptor on the TileEntity.
|
||||
* <p/>
|
||||
* 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.
|
||||
* <p/>
|
||||
* See TileRefinery for a simple example of a power using machine.
|
||||
*
|
||||
* @see IPowerReceptor
|
||||
* @see IPowerEmitter
|
||||
*/
|
||||
public final class PowerHandler implements IBatteryProvider {
|
||||
|
||||
public static enum Type {
|
||||
|
||||
ENGINE, GATE, MACHINE, PIPE, STORAGE;
|
||||
|
||||
public boolean canReceiveFromPipes() {
|
||||
switch (this) {
|
||||
case MACHINE:
|
||||
case STORAGE:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean eatsEngineExcess() {
|
||||
switch (this) {
|
||||
case MACHINE:
|
||||
case STORAGE:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extend this class to create custom Perdition algorithms (its not final).
|
||||
* <p/>
|
||||
* NOTE: It is not possible to create a Zero perdition algorithm.
|
||||
*/
|
||||
public static class PerditionCalculator {
|
||||
|
||||
public static final float DEFAULT_POWERLOSS = 1F;
|
||||
public static final float MIN_POWERLOSS = 0.01F;
|
||||
private final double powerLoss;
|
||||
|
||||
public PerditionCalculator() {
|
||||
powerLoss = DEFAULT_POWERLOSS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple constructor for simple Perdition per tick.
|
||||
*
|
||||
* @param powerLoss power loss per tick
|
||||
*/
|
||||
public PerditionCalculator(double powerLoss) {
|
||||
this.powerLoss = powerLoss;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the perdition algorithm to the current stored energy. This
|
||||
* function can only be called once per tick, but it might not be called
|
||||
* every tick. It is triggered by any manipulation of the stored energy.
|
||||
*
|
||||
* @param powerHandler the PowerHandler requesting the perdition update
|
||||
* @param current the current stored energy
|
||||
* @param ticksPassed ticks since the last time this function was called
|
||||
*/
|
||||
public double applyPerdition(PowerHandler powerHandler, double current, long ticksPassed) {
|
||||
double newPower = current - powerLoss * ticksPassed;
|
||||
|
||||
if (newPower < 0) {
|
||||
newPower = 0;
|
||||
}
|
||||
|
||||
return newPower;
|
||||
}
|
||||
|
||||
/**
|
||||
* Taxes a flat rate on all incoming power.
|
||||
* <p/>
|
||||
* Defaults to 0% tax rate.
|
||||
*
|
||||
* @return percent of input to tax
|
||||
*/
|
||||
public double getTaxPercent() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static final PerditionCalculator DEFAULT_PERDITION = new PerditionCalculator();
|
||||
public static final double ROLLING_AVERAGE_WEIGHT = 100.0;
|
||||
public static final double ROLLING_AVERAGE_NUMERATOR = ROLLING_AVERAGE_WEIGHT - 1;
|
||||
public static final double ROLLING_AVERAGE_DENOMINATOR = 1.0 / ROLLING_AVERAGE_WEIGHT;
|
||||
public final int[] powerSources = new int[6];
|
||||
public final IPowerReceptor receptor;
|
||||
|
||||
private double 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() {
|
||||
return receiver;
|
||||
}
|
||||
|
||||
public double getMinEnergyReceived() {
|
||||
return battery.minimumConsumption();
|
||||
}
|
||||
|
||||
public double getMaxEnergyReceived() {
|
||||
return battery.getEnergyRequested();
|
||||
}
|
||||
|
||||
public double getMaxEnergyStored() {
|
||||
return battery.maxCapacity();
|
||||
}
|
||||
|
||||
public double getActivationEnergy() {
|
||||
return activationEnergy;
|
||||
}
|
||||
|
||||
public double getEnergyStored() {
|
||||
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.
|
||||
*/
|
||||
public void configure(double minEnergyReceived, double maxEnergyReceived, double activationEnergy,
|
||||
double maxStoredEnergy) {
|
||||
double localMaxEnergyReceived = maxEnergyReceived;
|
||||
|
||||
if (minEnergyReceived > localMaxEnergyReceived) {
|
||||
localMaxEnergyReceived = minEnergyReceived;
|
||||
}
|
||||
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.
|
||||
* <p/>
|
||||
* This function is mostly for legacy implementations. See
|
||||
* PerditionCalculator for more complex perdition formulas.
|
||||
*
|
||||
* @param powerLoss
|
||||
* @param powerLossRegularity
|
||||
* @see PerditionCalculator
|
||||
*/
|
||||
public void configurePowerPerdition(int powerLoss, int powerLossRegularity) {
|
||||
if (powerLoss == 0 || powerLossRegularity == 0) {
|
||||
perdition = new PerditionCalculator(0);
|
||||
return;
|
||||
}
|
||||
perdition = new PerditionCalculator((float) powerLoss / (float) powerLossRegularity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows you to define a new PerditionCalculator class to handler perdition
|
||||
* calculations.
|
||||
* <p/>
|
||||
* For example if you want exponentially increasing loss based on amount
|
||||
* stored.
|
||||
*
|
||||
* @param perdition
|
||||
*/
|
||||
public void setPerdition(PerditionCalculator perdition) {
|
||||
if (perdition == null) {
|
||||
this.perdition = DEFAULT_PERDITION;
|
||||
} else {
|
||||
this.perdition = perdition;
|
||||
}
|
||||
}
|
||||
|
||||
public PerditionCalculator getPerdition() {
|
||||
if (perdition == null) {
|
||||
return DEFAULT_PERDITION;
|
||||
} else {
|
||||
return perdition;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ticks the power handler. You should call this if you can, but its not
|
||||
* required.
|
||||
* <p/>
|
||||
* If you don't call it, the possibility exists for some weirdness with the
|
||||
* perdition algorithm and work callback as its possible they will not be
|
||||
* called on every tick they otherwise would be. You should be able to
|
||||
* design around this though if you are aware of the limitations.
|
||||
*/
|
||||
public void update() {
|
||||
applyPerdition();
|
||||
applyWork();
|
||||
validateEnergy();
|
||||
}
|
||||
|
||||
private void applyPerdition() {
|
||||
double energyStored = getEnergyStored();
|
||||
if (perditionTracker.markTimeIfDelay(receptor.getWorld()) && energyStored > 0) {
|
||||
double newEnergy = getPerdition().applyPerdition(this, energyStored, perditionTracker.durationOfLastDelay());
|
||||
if (newEnergy != energyStored) {
|
||||
battery.setEnergyStored(energyStored = newEnergy);
|
||||
}
|
||||
validateEnergy();
|
||||
|
||||
averageLostPower = (averageLostPower * ROLLING_AVERAGE_NUMERATOR + (getEnergyStored() - energyStored)) * ROLLING_AVERAGE_DENOMINATOR;
|
||||
}
|
||||
}
|
||||
|
||||
private void applyWork() {
|
||||
if (getEnergyStored() >= activationEnergy) {
|
||||
if (doWorkTracker.markTimeIfDelay(receptor.getWorld())) {
|
||||
receptor.doWork(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateSources(ForgeDirection source) {
|
||||
if (sourcesTracker.markTimeIfDelay(receptor.getWorld())) {
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
powerSources[i] -= sourcesTracker.durationOfLastDelay();
|
||||
if (powerSources[i] < 0) {
|
||||
powerSources[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (source != null) {
|
||||
powerSources[source.ordinal()] = 10;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract energy from the PowerHandler. You must call this even if doWork()
|
||||
* triggers.
|
||||
*
|
||||
* @param min
|
||||
* @param max
|
||||
* @param doUse
|
||||
* @return amount used
|
||||
*/
|
||||
public double useEnergy(double min, double max, boolean doUse) {
|
||||
applyPerdition();
|
||||
|
||||
double result = 0;
|
||||
|
||||
double energyStored = getEnergyStored();
|
||||
if (energyStored >= min) {
|
||||
if (energyStored <= max) {
|
||||
result = energyStored;
|
||||
if (doUse) {
|
||||
energyStored = 0;
|
||||
}
|
||||
} else {
|
||||
result = max;
|
||||
if (doUse) {
|
||||
energyStored -= max;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (energyStored != getEnergyStored()) {
|
||||
battery.setEnergyStored(energyStored);
|
||||
}
|
||||
|
||||
validateEnergy();
|
||||
|
||||
if (doUse) {
|
||||
averageUsedPower = (averageUsedPower * ROLLING_AVERAGE_NUMERATOR + result) * ROLLING_AVERAGE_DENOMINATOR;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound data) {
|
||||
readFromNBT(data, "powerProvider");
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound data, String tag) {
|
||||
NBTTagCompound nbt = data.getCompoundTag(tag);
|
||||
battery.setEnergyStored(nbt.getDouble("energyStored"));
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound data) {
|
||||
writeToNBT(data, "powerProvider");
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound data, String tag) {
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
nbt.setDouble("energyStored", battery.getEnergyStored());
|
||||
data.setTag(tag, nbt);
|
||||
}
|
||||
|
||||
public final class PowerReceiver {
|
||||
|
||||
private PowerReceiver() {
|
||||
}
|
||||
|
||||
public double getMinEnergyReceived() {
|
||||
return PowerHandler.this.getMinEnergyReceived();
|
||||
}
|
||||
|
||||
public double getMaxEnergyReceived() {
|
||||
return PowerHandler.this.getMaxEnergyReceived();
|
||||
}
|
||||
|
||||
public double getMaxEnergyStored() {
|
||||
return PowerHandler.this.getMaxEnergyStored();
|
||||
}
|
||||
|
||||
public double getActivationEnergy() {
|
||||
return activationEnergy;
|
||||
}
|
||||
|
||||
public double getEnergyStored() {
|
||||
return PowerHandler.this.getEnergyStored();
|
||||
}
|
||||
|
||||
public double getAveragePowerReceived() {
|
||||
return averageReceivedPower;
|
||||
}
|
||||
|
||||
public double getAveragePowerUsed() {
|
||||
return averageUsedPower;
|
||||
}
|
||||
|
||||
public double getAveragePowerLost() {
|
||||
return averageLostPower;
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void update() {
|
||||
PowerHandler.this.update();
|
||||
}
|
||||
|
||||
/**
|
||||
* The amount of power that this PowerHandler currently needs.
|
||||
*/
|
||||
public double powerRequest() {
|
||||
update();
|
||||
return battery.getEnergyRequested();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add power to the PowerReceiver from an external source.
|
||||
* <p/>
|
||||
* IPowerEmitters are responsible for calling this themselves.
|
||||
*
|
||||
* @param quantity
|
||||
* @param from
|
||||
* @return the amount of power used
|
||||
*/
|
||||
public double receiveEnergy(Type source, final double quantity, ForgeDirection from) {
|
||||
double used = quantity;
|
||||
if (source == Type.ENGINE) {
|
||||
if (used < getMinEnergyReceived()) {
|
||||
return 0;
|
||||
} else if (used > getMaxEnergyReceived()) {
|
||||
used = getMaxEnergyReceived();
|
||||
}
|
||||
}
|
||||
|
||||
updateSources(from);
|
||||
|
||||
used -= used * getPerdition().getTaxPercent();
|
||||
|
||||
used = addEnergy(used);
|
||||
|
||||
applyWork();
|
||||
|
||||
if (source == Type.ENGINE && type.eatsEngineExcess()) {
|
||||
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) {
|
||||
final double used = battery.addEnergy(quantity);
|
||||
applyPerdition();
|
||||
return used;
|
||||
}
|
||||
|
||||
public void setEnergy(double quantity) {
|
||||
battery.setEnergyStored(quantity);
|
||||
validateEnergy();
|
||||
}
|
||||
|
||||
public boolean isPowerSource(ForgeDirection from) {
|
||||
return powerSources[from.ordinal()] != 0;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -19,7 +19,7 @@ public class CraftingResult<T> {
|
|||
public T crafted = null;
|
||||
public ArrayList<ItemStack> usedItems = new ArrayList<ItemStack>();
|
||||
public ArrayList<FluidStack> usedFluids = new ArrayList<FluidStack>();
|
||||
public double energyCost = 0;
|
||||
public int energyCost = 0;
|
||||
public long craftingTime = 0;
|
||||
public IFlexibleRecipe<?> recipe;
|
||||
public IFlexibleRecipe<T> recipe;
|
||||
}
|
||||
|
|
|
@ -21,13 +21,17 @@ public interface IAssemblyRecipeManager {
|
|||
* Object... containing either an ItemStack, or a paired string
|
||||
* and integer(ex: "dyeBlue", 1)
|
||||
* @param energyCost
|
||||
* MJ cost to produce
|
||||
* RF cost to produce
|
||||
* @param output
|
||||
* resulting ItemStack
|
||||
*/
|
||||
void addRecipe(String id, double energyCost, ItemStack output, Object... input);
|
||||
void addRecipe(String id, int energyCost, ItemStack output, Object... input);
|
||||
|
||||
void addRecipe(IFlexibleRecipe<ItemStack> recipe);
|
||||
|
||||
void removeRecipe(String id);
|
||||
|
||||
void removeRecipe(IFlexibleRecipe<ItemStack> recipe);
|
||||
|
||||
Collection<IFlexibleRecipe<ItemStack>> getRecipes();
|
||||
}
|
||||
|
|
|
@ -8,11 +8,15 @@
|
|||
*/
|
||||
package buildcraft.api.recipes;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IFlexibleRecipe<T> {
|
||||
|
||||
boolean canBeCrafted(IFlexibleCrafter crafter);
|
||||
|
||||
CraftingResult<T> craft(IFlexibleCrafter crafter, boolean preview);
|
||||
|
||||
CraftingResult<T> canCraft(ItemStack expectedOutput);
|
||||
|
||||
String getId();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package buildcraft.api.recipes;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* This class is intended for mods such as Not Enough Items
|
||||
* in order for them to be able to look inside a recipe.
|
||||
*
|
||||
* It is intentionally left as a separate interface, so that
|
||||
* it remains possible to register a "dynamic" flexible
|
||||
* recipe which does not have static inputs and outputs.
|
||||
*
|
||||
* @author asie
|
||||
*/
|
||||
public interface IFlexibleRecipeViewable {
|
||||
Object getOutput();
|
||||
|
||||
/**
|
||||
* With BuildCraft's implementation (as of 6.1.3), this might
|
||||
* contain either an ItemStack, a List<ItemStack> or a FluidStack.
|
||||
*/
|
||||
Collection<Object> getInputs();
|
||||
|
||||
long getCraftingTime();
|
||||
|
||||
int getEnergyCost();
|
||||
}
|
|
@ -18,6 +18,10 @@ public interface IRefineryRecipeManager {
|
|||
|
||||
void addRecipe(String id, FluidStack ingredient1, FluidStack ingredient2, FluidStack result, int energy, int delay);
|
||||
|
||||
void removeRecipe(String id);
|
||||
|
||||
void removeRecipe(IFlexibleRecipe<FluidStack> recipe);
|
||||
|
||||
Collection<IFlexibleRecipe<FluidStack>> getRecipes();
|
||||
|
||||
IFlexibleRecipe<FluidStack> getRecipe(String currentRecipeId);
|
||||
|
|
|
@ -8,9 +8,8 @@
|
|||
*/
|
||||
package buildcraft.api.transport;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import buildcraft.api.gates.IGate;
|
||||
|
||||
public interface IPipe {
|
||||
|
||||
|
@ -22,5 +21,11 @@ public interface IPipe {
|
|||
|
||||
IPipeTile getTile();
|
||||
|
||||
TileEntity getAdjacentTile(ForgeDirection dir);
|
||||
IGate getGate(ForgeDirection side);
|
||||
|
||||
boolean hasGate(ForgeDirection side);
|
||||
|
||||
boolean isWired(PipeWire wire);
|
||||
|
||||
boolean isWireActive(PipeWire wire);
|
||||
}
|
||||
|
|
|
@ -9,8 +9,9 @@
|
|||
package buildcraft.api.transport;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import buildcraft.api.core.EnumColor;
|
||||
|
||||
public interface IPipeTile {
|
||||
|
||||
|
@ -29,8 +30,16 @@ public interface IPipeTile {
|
|||
* @param doAdd If false no actual addition should take place. Implementors
|
||||
* should simulate.
|
||||
* @param from Orientation the ItemStack is offered from.
|
||||
* @param color The color of the item to be added to the pipe, or null for no color.
|
||||
* @return Amount of items used from the passed stack.
|
||||
*/
|
||||
int injectItem(ItemStack stack, boolean doAdd, ForgeDirection from, EnumColor color);
|
||||
|
||||
/**
|
||||
* Same as
|
||||
* {@link #injectItem(ItemStack, boolean, ForgeDirection, EnumColor)}
|
||||
* but with no color attribute.
|
||||
*/
|
||||
int injectItem(ItemStack stack, boolean doAdd, ForgeDirection from);
|
||||
|
||||
/**
|
||||
|
@ -41,11 +50,7 @@ public interface IPipeTile {
|
|||
*/
|
||||
boolean isPipeConnected(ForgeDirection with);
|
||||
|
||||
/**
|
||||
* True if the pipe has a powered wire of the specified color.
|
||||
*
|
||||
* @param wire
|
||||
* @return true if powered
|
||||
*/
|
||||
boolean isWireActive(PipeWire wire);
|
||||
TileEntity getAdjacentTile(ForgeDirection dir);
|
||||
|
||||
IPipe getPipe();
|
||||
}
|
||||
|
|
20
src/api/java/buildcraft/api/transport/IStripesHandler.java
Normal file
20
src/api/java/buildcraft/api/transport/IStripesHandler.java
Normal file
|
@ -0,0 +1,20 @@
|
|||
package buildcraft.api.transport;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public interface IStripesHandler {
|
||||
public static enum StripesHandlerType {
|
||||
ITEM_USE,
|
||||
BLOCK_BREAK
|
||||
}
|
||||
|
||||
StripesHandlerType getType();
|
||||
|
||||
boolean shouldHandle(ItemStack stack);
|
||||
|
||||
boolean handle(World world, int x, int y, int z, ForgeDirection direction,
|
||||
ItemStack stack, EntityPlayer player, IStripesPipe pipe);
|
||||
}
|
9
src/api/java/buildcraft/api/transport/IStripesPipe.java
Normal file
9
src/api/java/buildcraft/api/transport/IStripesPipe.java
Normal file
|
@ -0,0 +1,9 @@
|
|||
package buildcraft.api.transport;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public interface IStripesPipe extends IPipe {
|
||||
void sendItem(ItemStack itemStack, ForgeDirection direction);
|
||||
void dropItem(ItemStack itemStack, ForgeDirection direction);
|
||||
}
|
|
@ -15,12 +15,17 @@ import net.minecraft.world.World;
|
|||
|
||||
public abstract class PipeManager {
|
||||
|
||||
public static List<IStripesHandler> stripesHandlers = new ArrayList<IStripesHandler>();
|
||||
public static List<IExtractionHandler> extractionHandlers = new ArrayList<IExtractionHandler>();
|
||||
|
||||
public static void registerExtractionHandler(IExtractionHandler handler) {
|
||||
extractionHandlers.add(handler);
|
||||
}
|
||||
|
||||
public static void registerStripesHandler(IStripesHandler handler) {
|
||||
stripesHandlers.add(handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* param extractor can be null
|
||||
*/
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
@API(apiVersion = "2.0", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|transport")
|
||||
@API(apiVersion = "2.1", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|transport")
|
||||
package buildcraft.api.transport;
|
||||
import cpw.mods.fml.common.API;
|
||||
|
||||
|
|
11
src/api/java/cofh/api/CoFHAPIProps.java
Normal file
11
src/api/java/cofh/api/CoFHAPIProps.java
Normal file
|
@ -0,0 +1,11 @@
|
|||
package cofh.api;
|
||||
|
||||
public class CoFHAPIProps {
|
||||
|
||||
private CoFHAPIProps() {
|
||||
|
||||
}
|
||||
|
||||
public static final String VERSION = "1.7.10R1.0.1";
|
||||
|
||||
}
|
158
src/api/java/cofh/api/energy/EnergyStorage.java
Normal file
158
src/api/java/cofh/api/energy/EnergyStorage.java
Normal file
|
@ -0,0 +1,158 @@
|
|||
package cofh.api.energy;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
/**
|
||||
* Reference implementation of {@link IEnergyStorage}. Use/extend this or implement your own.
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public class EnergyStorage implements IEnergyStorage {
|
||||
|
||||
protected int energy;
|
||||
protected int capacity;
|
||||
protected int maxReceive;
|
||||
protected int maxExtract;
|
||||
|
||||
public EnergyStorage(int capacity) {
|
||||
|
||||
this(capacity, capacity, capacity);
|
||||
}
|
||||
|
||||
public EnergyStorage(int capacity, int maxTransfer) {
|
||||
|
||||
this(capacity, maxTransfer, maxTransfer);
|
||||
}
|
||||
|
||||
public EnergyStorage(int capacity, int maxReceive, int maxExtract) {
|
||||
|
||||
this.capacity = capacity;
|
||||
this.maxReceive = maxReceive;
|
||||
this.maxExtract = maxExtract;
|
||||
}
|
||||
|
||||
public EnergyStorage readFromNBT(NBTTagCompound nbt) {
|
||||
|
||||
this.energy = nbt.getInteger("Energy");
|
||||
|
||||
if (energy > capacity) {
|
||||
energy = capacity;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
|
||||
|
||||
if (energy < 0) {
|
||||
energy = 0;
|
||||
}
|
||||
nbt.setInteger("Energy", energy);
|
||||
return nbt;
|
||||
}
|
||||
|
||||
public void setCapacity(int capacity) {
|
||||
|
||||
this.capacity = capacity;
|
||||
|
||||
if (energy > capacity) {
|
||||
energy = capacity;
|
||||
}
|
||||
}
|
||||
|
||||
public void setMaxTransfer(int maxTransfer) {
|
||||
|
||||
setMaxReceive(maxTransfer);
|
||||
setMaxExtract(maxTransfer);
|
||||
}
|
||||
|
||||
public void setMaxReceive(int maxReceive) {
|
||||
|
||||
this.maxReceive = maxReceive;
|
||||
}
|
||||
|
||||
public void setMaxExtract(int maxExtract) {
|
||||
|
||||
this.maxExtract = maxExtract;
|
||||
}
|
||||
|
||||
public int getMaxReceive() {
|
||||
|
||||
return maxReceive;
|
||||
}
|
||||
|
||||
public int getMaxExtract() {
|
||||
|
||||
return maxExtract;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is included to allow for server -> client sync. Do not call this externally to the containing Tile Entity, as not all IEnergyHandlers
|
||||
* are guaranteed to have it.
|
||||
*
|
||||
* @param energy
|
||||
*/
|
||||
public void setEnergyStored(int energy) {
|
||||
|
||||
this.energy = energy;
|
||||
|
||||
if (this.energy > capacity) {
|
||||
this.energy = capacity;
|
||||
} else if (this.energy < 0) {
|
||||
this.energy = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is included to allow the containing tile to directly and efficiently modify the energy contained in the EnergyStorage. Do not rely on this
|
||||
* externally, as not all IEnergyHandlers are guaranteed to have it.
|
||||
*
|
||||
* @param energy
|
||||
*/
|
||||
public void modifyEnergyStored(int energy) {
|
||||
|
||||
this.energy += energy;
|
||||
|
||||
if (this.energy > capacity) {
|
||||
this.energy = capacity;
|
||||
} else if (this.energy < 0) {
|
||||
this.energy = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* IEnergyStorage */
|
||||
@Override
|
||||
public int receiveEnergy(int maxReceive, boolean simulate) {
|
||||
|
||||
int energyReceived = Math.min(capacity - energy, Math.min(this.maxReceive, maxReceive));
|
||||
|
||||
if (!simulate) {
|
||||
energy += energyReceived;
|
||||
}
|
||||
return energyReceived;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int extractEnergy(int maxExtract, boolean simulate) {
|
||||
|
||||
int energyExtracted = Math.min(energy, Math.min(this.maxExtract, maxExtract));
|
||||
|
||||
if (!simulate) {
|
||||
energy -= energyExtracted;
|
||||
}
|
||||
return energyExtracted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyStored() {
|
||||
|
||||
return energy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored() {
|
||||
|
||||
return capacity;
|
||||
}
|
||||
|
||||
}
|
|
@ -5,7 +5,7 @@ import net.minecraftforge.common.util.ForgeDirection;
|
|||
/**
|
||||
* Implement this interface on TileEntities which should connect to energy transportation blocks. This is intended for blocks which generate energy but do not
|
||||
* accept it; otherwise just use IEnergyHandler.
|
||||
*
|
||||
* <p>
|
||||
* Note that {@link IEnergyHandler} is an extension of this.
|
||||
*
|
||||
* @author King Lemming
|
||||
|
|
|
@ -4,7 +4,7 @@ import net.minecraft.item.ItemStack;
|
|||
|
||||
/**
|
||||
* Implement this interface on Item classes that support external manipulation of their internal energy storages.
|
||||
*
|
||||
* <p>
|
||||
* A reference implementation is provided {@link ItemEnergyContainer}.
|
||||
*
|
||||
* @author King Lemming
|
||||
|
|
|
@ -4,16 +4,18 @@ import net.minecraftforge.common.util.ForgeDirection;
|
|||
|
||||
/**
|
||||
* Implement this interface on Tile Entities which should handle energy, generally storing it in one or more internal {@link IEnergyStorage} objects.
|
||||
*
|
||||
* <p>
|
||||
* A reference implementation is provided {@link TileEnergyHandler}.
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public interface IEnergyHandler extends IEnergyConnection {
|
||||
public interface IEnergyHandler extends IEnergyProvider, IEnergyReceiver {
|
||||
|
||||
// merely a convenience interface (remove these methods in 1.8; provided here for back-compat via compiler doing things)
|
||||
|
||||
/**
|
||||
* Add energy to an IEnergyHandler, internal distribution is left entirely to the IEnergyHandler.
|
||||
* Add energy to an IEnergyReceiver, internal distribution is left entirely to the IEnergyReceiver.
|
||||
*
|
||||
* @param from
|
||||
* Orientation the energy is received from.
|
||||
|
@ -23,10 +25,11 @@ public interface IEnergyHandler extends IEnergyConnection {
|
|||
* If TRUE, the charge will only be simulated.
|
||||
* @return Amount of energy that was (or would have been, if simulated) received.
|
||||
*/
|
||||
@Override
|
||||
int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate);
|
||||
|
||||
/**
|
||||
* Remove energy from an IEnergyHandler, internal distribution is left entirely to the IEnergyHandler.
|
||||
* Remove energy from an IEnergyProvider, internal distribution is left entirely to the IEnergyProvider.
|
||||
*
|
||||
* @param from
|
||||
* Orientation the energy is extracted from.
|
||||
|
@ -36,16 +39,20 @@ public interface IEnergyHandler extends IEnergyConnection {
|
|||
* If TRUE, the extraction will only be simulated.
|
||||
* @return Amount of energy that was (or would have been, if simulated) extracted.
|
||||
*/
|
||||
@Override
|
||||
int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the amount of energy currently stored.
|
||||
*/
|
||||
@Override
|
||||
int getEnergyStored(ForgeDirection from);
|
||||
|
||||
/**
|
||||
* Returns the maximum amount of energy that can be stored.
|
||||
*/
|
||||
@Override
|
||||
int getMaxEnergyStored(ForgeDirection from);
|
||||
|
||||
}
|
||||
|
|
38
src/api/java/cofh/api/energy/IEnergyProvider.java
Normal file
38
src/api/java/cofh/api/energy/IEnergyProvider.java
Normal file
|
@ -0,0 +1,38 @@
|
|||
package cofh.api.energy;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
/**
|
||||
* Implement this interface on Tile Entities which should provide energy, generally storing it in one or more internal {@link IEnergyStorage} objects.
|
||||
* <p>
|
||||
* A reference implementation is provided {@link TileEnergyHandler}.
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public interface IEnergyProvider extends IEnergyConnection {
|
||||
|
||||
/**
|
||||
* Remove energy from an IEnergyProvider, internal distribution is left entirely to the IEnergyProvider.
|
||||
*
|
||||
* @param from
|
||||
* Orientation the energy is extracted from.
|
||||
* @param maxExtract
|
||||
* Maximum amount of energy to extract.
|
||||
* @param simulate
|
||||
* If TRUE, the extraction will only be simulated.
|
||||
* @return Amount of energy that was (or would have been, if simulated) extracted.
|
||||
*/
|
||||
int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate);
|
||||
|
||||
/**
|
||||
* Returns the amount of energy currently stored.
|
||||
*/
|
||||
int getEnergyStored(ForgeDirection from);
|
||||
|
||||
/**
|
||||
* Returns the maximum amount of energy that can be stored.
|
||||
*/
|
||||
int getMaxEnergyStored(ForgeDirection from);
|
||||
|
||||
}
|
38
src/api/java/cofh/api/energy/IEnergyReceiver.java
Normal file
38
src/api/java/cofh/api/energy/IEnergyReceiver.java
Normal file
|
@ -0,0 +1,38 @@
|
|||
package cofh.api.energy;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
/**
|
||||
* Implement this interface on Tile Entities which should receive energy, generally storing it in one or more internal {@link IEnergyStorage} objects.
|
||||
* <p>
|
||||
* A reference implementation is provided {@link TileEnergyHandler}.
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public interface IEnergyReceiver extends IEnergyConnection {
|
||||
|
||||
/**
|
||||
* Add energy to an IEnergyReceiver, internal distribution is left entirely to the IEnergyReceiver.
|
||||
*
|
||||
* @param from
|
||||
* Orientation the energy is received from.
|
||||
* @param maxReceive
|
||||
* Maximum amount of energy to receive.
|
||||
* @param simulate
|
||||
* If TRUE, the charge will only be simulated.
|
||||
* @return Amount of energy that was (or would have been, if simulated) received.
|
||||
*/
|
||||
int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate);
|
||||
|
||||
/**
|
||||
* Returns the amount of energy currently stored.
|
||||
*/
|
||||
int getEnergyStored(ForgeDirection from);
|
||||
|
||||
/**
|
||||
* Returns the maximum amount of energy that can be stored.
|
||||
*/
|
||||
int getMaxEnergyStored(ForgeDirection from);
|
||||
|
||||
}
|
46
src/api/java/cofh/api/energy/IEnergyStorage.java
Normal file
46
src/api/java/cofh/api/energy/IEnergyStorage.java
Normal file
|
@ -0,0 +1,46 @@
|
|||
package cofh.api.energy;
|
||||
|
||||
/**
|
||||
* An energy storage is the unit of interaction with Energy inventories.<br>
|
||||
* This is not to be implemented on TileEntities. This is for internal use only.
|
||||
* <p>
|
||||
* A reference implementation can be found at {@link EnergyStorage}.
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public interface IEnergyStorage {
|
||||
|
||||
/**
|
||||
* Adds energy to the storage. Returns quantity of energy that was accepted.
|
||||
*
|
||||
* @param maxReceive
|
||||
* Maximum amount of energy to be inserted.
|
||||
* @param simulate
|
||||
* If TRUE, the insertion will only be simulated.
|
||||
* @return Amount of energy that was (or would have been, if simulated) accepted by the storage.
|
||||
*/
|
||||
int receiveEnergy(int maxReceive, boolean simulate);
|
||||
|
||||
/**
|
||||
* Removes energy from the storage. Returns quantity of energy that was removed.
|
||||
*
|
||||
* @param maxExtract
|
||||
* Maximum amount of energy to be extracted.
|
||||
* @param simulate
|
||||
* If TRUE, the extraction will only be simulated.
|
||||
* @return Amount of energy that was (or would have been, if simulated) extracted from the storage.
|
||||
*/
|
||||
int extractEnergy(int maxExtract, boolean simulate);
|
||||
|
||||
/**
|
||||
* Returns the amount of energy currently stored.
|
||||
*/
|
||||
int getEnergyStored();
|
||||
|
||||
/**
|
||||
* Returns the maximum amount of energy that can be stored.
|
||||
*/
|
||||
int getMaxEnergyStored();
|
||||
|
||||
}
|
110
src/api/java/cofh/api/energy/ItemEnergyContainer.java
Normal file
110
src/api/java/cofh/api/energy/ItemEnergyContainer.java
Normal file
|
@ -0,0 +1,110 @@
|
|||
package cofh.api.energy;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
/**
|
||||
* Reference implementation of {@link IEnergyContainerItem}. Use/extend this or implement your own.
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public class ItemEnergyContainer extends Item implements IEnergyContainerItem {
|
||||
|
||||
protected int capacity;
|
||||
protected int maxReceive;
|
||||
protected int maxExtract;
|
||||
|
||||
public ItemEnergyContainer() {
|
||||
|
||||
}
|
||||
|
||||
public ItemEnergyContainer(int capacity) {
|
||||
|
||||
this(capacity, capacity, capacity);
|
||||
}
|
||||
|
||||
public ItemEnergyContainer(int capacity, int maxTransfer) {
|
||||
|
||||
this(capacity, maxTransfer, maxTransfer);
|
||||
}
|
||||
|
||||
public ItemEnergyContainer(int capacity, int maxReceive, int maxExtract) {
|
||||
|
||||
this.capacity = capacity;
|
||||
this.maxReceive = maxReceive;
|
||||
this.maxExtract = maxExtract;
|
||||
}
|
||||
|
||||
public ItemEnergyContainer setCapacity(int capacity) {
|
||||
|
||||
this.capacity = capacity;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setMaxTransfer(int maxTransfer) {
|
||||
|
||||
setMaxReceive(maxTransfer);
|
||||
setMaxExtract(maxTransfer);
|
||||
}
|
||||
|
||||
public void setMaxReceive(int maxReceive) {
|
||||
|
||||
this.maxReceive = maxReceive;
|
||||
}
|
||||
|
||||
public void setMaxExtract(int maxExtract) {
|
||||
|
||||
this.maxExtract = maxExtract;
|
||||
}
|
||||
|
||||
/* IEnergyContainerItem */
|
||||
@Override
|
||||
public int receiveEnergy(ItemStack container, int maxReceive, boolean simulate) {
|
||||
|
||||
if (container.stackTagCompound == null) {
|
||||
container.stackTagCompound = new NBTTagCompound();
|
||||
}
|
||||
int energy = container.stackTagCompound.getInteger("Energy");
|
||||
int energyReceived = Math.min(capacity - energy, Math.min(this.maxReceive, maxReceive));
|
||||
|
||||
if (!simulate) {
|
||||
energy += energyReceived;
|
||||
container.stackTagCompound.setInteger("Energy", energy);
|
||||
}
|
||||
return energyReceived;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int extractEnergy(ItemStack container, int maxExtract, boolean simulate) {
|
||||
|
||||
if (container.stackTagCompound == null || !container.stackTagCompound.hasKey("Energy")) {
|
||||
return 0;
|
||||
}
|
||||
int energy = container.stackTagCompound.getInteger("Energy");
|
||||
int energyExtracted = Math.min(energy, Math.min(this.maxExtract, maxExtract));
|
||||
|
||||
if (!simulate) {
|
||||
energy -= energyExtracted;
|
||||
container.stackTagCompound.setInteger("Energy", energy);
|
||||
}
|
||||
return energyExtracted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyStored(ItemStack container) {
|
||||
|
||||
if (container.stackTagCompound == null || !container.stackTagCompound.hasKey("Energy")) {
|
||||
return 0;
|
||||
}
|
||||
return container.stackTagCompound.getInteger("Energy");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored(ItemStack container) {
|
||||
|
||||
return capacity;
|
||||
}
|
||||
|
||||
}
|
65
src/api/java/cofh/api/energy/TileEnergyHandler.java
Normal file
65
src/api/java/cofh/api/energy/TileEnergyHandler.java
Normal file
|
@ -0,0 +1,65 @@
|
|||
package cofh.api.energy;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
/**
|
||||
* Reference implementation of {@link IEnergyHandler}. Use/extend this or implement your own.
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public class TileEnergyHandler extends TileEntity implements IEnergyHandler {
|
||||
|
||||
protected EnergyStorage storage = new EnergyStorage(32000);
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
|
||||
super.readFromNBT(nbt);
|
||||
storage.readFromNBT(nbt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
|
||||
super.writeToNBT(nbt);
|
||||
storage.writeToNBT(nbt);
|
||||
}
|
||||
|
||||
/* IEnergyConnection */
|
||||
@Override
|
||||
public boolean canConnectEnergy(ForgeDirection from) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* IEnergyReceiver */
|
||||
@Override
|
||||
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate) {
|
||||
|
||||
return storage.receiveEnergy(maxReceive, simulate);
|
||||
}
|
||||
|
||||
/* IEnergyProvider */
|
||||
@Override
|
||||
public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate) {
|
||||
|
||||
return storage.extractEnergy(maxExtract, simulate);
|
||||
}
|
||||
|
||||
/* IEnergyReceiver and IEnergyProvider */
|
||||
@Override
|
||||
public int getEnergyStored(ForgeDirection from) {
|
||||
|
||||
return storage.getEnergyStored();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored(ForgeDirection from) {
|
||||
|
||||
return storage.getMaxEnergyStored();
|
||||
}
|
||||
|
||||
}
|
|
@ -2,8 +2,9 @@
|
|||
* (C) 2014 Team CoFH / CoFH / Cult of the Full Hub
|
||||
* http://www.teamcofh.com
|
||||
*/
|
||||
@API(apiVersion = "1.7.10R1.0.0", owner = "CoFHAPI", provides = "CoFHAPI|energy")
|
||||
@API(apiVersion = CoFHAPIProps.VERSION, owner = "CoFHAPI", provides = "CoFHAPI|energy")
|
||||
package cofh.api.energy;
|
||||
|
||||
import cofh.api.CoFHAPIProps;
|
||||
import cpw.mods.fml.common.API;
|
||||
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
/**
|
||||
* (C) 2014 Team CoFH / CoFH / Cult of the Full Hub
|
||||
* http://www.teamcofh.com
|
||||
*/
|
||||
@API(apiVersion = "1.0", owner = "CoFHLib", provides = "CoFHAPI")
|
||||
package cofh.api;
|
||||
|
||||
import cpw.mods.fml.common.API;
|
||||
|
|
@ -154,7 +154,7 @@ public final class ComputerCraftAPI
|
|||
{
|
||||
try {
|
||||
computerCraft_registerBundledRedstoneProvider.invoke( null, handler );
|
||||
} catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
// It failed
|
||||
}
|
||||
}
|
||||
|
@ -241,7 +241,11 @@ public final class ComputerCraftAPI
|
|||
private static Method findCCMethod( String name, Class[] args )
|
||||
{
|
||||
try {
|
||||
if( computerCraft != null )
|
||||
{
|
||||
return computerCraft.getMethod( name, args );
|
||||
}
|
||||
return null;
|
||||
} catch( NoSuchMethodException e ) {
|
||||
System.out.println( "ComputerCraftAPI: ComputerCraft method " + name + " not found." );
|
||||
return null;
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
/**
|
||||
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
@API( owner="ComputerCraft", provides="ComputerCraft|API|FileSystem", apiVersion="1.65" )
|
||||
package dan200.computercraft.api.filesystem;
|
||||
|
||||
import cpw.mods.fml.common.API;
|
|
@ -22,7 +22,7 @@ public interface ILuaContext
|
|||
* Do not attempt to common this exception, unless you wish to prevent termination, which is not recommended.
|
||||
* @throws InterruptedException If the user shuts down or reboots the computercraft while pullEvent() is waiting for an event, InterruptedException will be thrown. This exception must not be caught or intercepted, or the computercraft will leak memory and end up in a broken state.
|
||||
*/
|
||||
public Object[] pullEvent( String filter ) throws Exception, InterruptedException;
|
||||
public Object[] pullEvent( String filter ) throws LuaException, InterruptedException;
|
||||
|
||||
/**
|
||||
* The same as pullEvent(), except "terminated" events are ignored. Only use this if you want to prevent program termination, which is not recommended. This method is exactly equivalent to os.pullEventRaw() in lua.
|
||||
|
@ -33,7 +33,6 @@ public interface ILuaContext
|
|||
*/
|
||||
public Object[] pullEventRaw( String filter ) throws InterruptedException;
|
||||
|
||||
|
||||
/**
|
||||
* Yield the current coroutine with some arguments until it is resumed. This method is exactly equivalent to coroutine.yield() in lua. Use pullEvent() if you wish to wait for events.
|
||||
* @param arguments An object array containing the arguments to pass to coroutine.yield()
|
||||
|
|
|
@ -22,5 +22,5 @@ public interface ILuaObject
|
|||
* Called when a user calls one of the methods that this object implements. This works the same as IPeripheral.callMethod(). See that method for detailed documentation.
|
||||
* @see dan200.computercraft.api.peripheral.IPeripheral#callMethod(dan200.computercraft.api.peripheral.IComputerAccess, ILuaContext, int, Object[])
|
||||
*/
|
||||
public Object[] callMethod( ILuaContext context, int method, Object[] arguments ) throws Exception;
|
||||
public Object[] callMethod( ILuaContext context, int method, Object[] arguments ) throws LuaException, InterruptedException;
|
||||
}
|
||||
|
|
31
src/api/java/dan200/computercraft/api/lua/LuaException.java
Normal file
31
src/api/java/dan200/computercraft/api/lua/LuaException.java
Normal file
|
@ -0,0 +1,31 @@
|
|||
/**
|
||||
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
package dan200.computercraft.api.lua;
|
||||
|
||||
/**
|
||||
* An exception representing an error in Lua, like that raised by the error() function
|
||||
*/
|
||||
public class LuaException extends Exception
|
||||
{
|
||||
private final int m_level;
|
||||
|
||||
public LuaException( String message )
|
||||
{
|
||||
this( message, 1 );
|
||||
}
|
||||
|
||||
public LuaException( String message, int level )
|
||||
{
|
||||
super( message );
|
||||
m_level = level;
|
||||
}
|
||||
|
||||
public int getLevel()
|
||||
{
|
||||
return m_level;
|
||||
}
|
||||
}
|
10
src/api/java/dan200/computercraft/api/lua/package-info.java
Normal file
10
src/api/java/dan200/computercraft/api/lua/package-info.java
Normal file
|
@ -0,0 +1,10 @@
|
|||
/**
|
||||
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
@API( owner="ComputerCraft", provides="ComputerCraft|API|Lua", apiVersion="1.65" )
|
||||
package dan200.computercraft.api.lua;
|
||||
|
||||
import cpw.mods.fml.common.API;
|
|
@ -0,0 +1,10 @@
|
|||
/**
|
||||
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
@API( owner="ComputerCraft", provides="ComputerCraft|API|Media", apiVersion="1.65" )
|
||||
package dan200.computercraft.api.media;
|
||||
|
||||
import cpw.mods.fml.common.API;
|
10
src/api/java/dan200/computercraft/api/package-info.java
Normal file
10
src/api/java/dan200/computercraft/api/package-info.java
Normal file
|
@ -0,0 +1,10 @@
|
|||
/**
|
||||
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
@API( owner="ComputerCraft", provides="ComputerCraft|API", apiVersion="1.65" )
|
||||
package dan200.computercraft.api;
|
||||
|
||||
import cpw.mods.fml.common.API;
|
|
@ -29,6 +29,11 @@ public interface IComputerAccess
|
|||
*/
|
||||
public String mount( String desiredLocation, IMount mount );
|
||||
|
||||
/**
|
||||
* TODO: Document me
|
||||
*/
|
||||
public String mount( String desiredLocation, IMount mount, String driveName );
|
||||
|
||||
/**
|
||||
* Mount a mount onto the computers' file system in a writable mode.<br>
|
||||
* @param desiredLocation The location on the computercraft's file system where you would like the mount to be mounted.
|
||||
|
@ -42,6 +47,11 @@ public interface IComputerAccess
|
|||
*/
|
||||
public String mountWritable( String desiredLocation, IWritableMount mount );
|
||||
|
||||
/**
|
||||
* TODO: Document me
|
||||
*/
|
||||
public String mountWritable( String desiredLocation, IWritableMount mount, String driveName );
|
||||
|
||||
/**
|
||||
* Unmounts a directory previously mounted onto the computers file system by mount() or mountWritable().<br>
|
||||
* When a directory is unmounted, it will disappear from the computers file system, and the user will no longer be able to
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
package dan200.computercraft.api.peripheral;
|
||||
|
||||
import dan200.computercraft.api.lua.ILuaContext;
|
||||
import dan200.computercraft.api.lua.LuaException;
|
||||
|
||||
/**
|
||||
* The interface that defines a peripheral. This should be implemented by the
|
||||
|
@ -59,7 +60,7 @@ public interface IPeripheral
|
|||
* arguments are supplied to your method.
|
||||
* @see #getMethodNames
|
||||
*/
|
||||
public Object[] callMethod( IComputerAccess computer, ILuaContext context, int method, Object[] arguments ) throws Exception;
|
||||
public Object[] callMethod( IComputerAccess computer, ILuaContext context, int method, Object[] arguments ) throws LuaException, InterruptedException;
|
||||
|
||||
/**
|
||||
* Is called when canAttachToSide has returned true, and a computercraft is attaching to the peripheral.
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
/**
|
||||
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
@API( owner="ComputerCraft", provides="ComputerCraft|API|Peripheral", apiVersion="1.65" )
|
||||
package dan200.computercraft.api.peripheral;
|
||||
|
||||
import cpw.mods.fml.common.API;
|
|
@ -0,0 +1,10 @@
|
|||
/**
|
||||
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
@API( owner="ComputerCraft", provides="ComputerCraft|API|Redstone", apiVersion="1.65" )
|
||||
package dan200.computercraft.api.redstone;
|
||||
|
||||
import cpw.mods.fml.common.API;
|
|
@ -7,6 +7,7 @@
|
|||
package dan200.computercraft.api.turtle;
|
||||
|
||||
import dan200.computercraft.api.lua.ILuaContext;
|
||||
import dan200.computercraft.api.lua.LuaException;
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
@ -119,7 +120,7 @@ public interface ITurtleAccess
|
|||
* unchanged if called from a peripheral method.
|
||||
* @see ITurtleCommand
|
||||
*/
|
||||
public Object[] executeCommand( ILuaContext context, ITurtleCommand command ) throws Exception;
|
||||
public Object[] executeCommand( ILuaContext context, ITurtleCommand command ) throws LuaException, InterruptedException;
|
||||
|
||||
/**
|
||||
* TODO: Document me
|
||||
|
|
|
@ -8,7 +8,7 @@ package dan200.computercraft.api.turtle;
|
|||
|
||||
/**
|
||||
* An interface for objects executing custom turtle commands, used with ITurtleAccess.issueCommand
|
||||
* @see ITurtleAccess#issueCommand(ITurtleCommand)
|
||||
* @see ITurtleAccess#executeCommand(dan200.computercraft.api.lua.ILuaContext,ITurtleCommand)
|
||||
*/
|
||||
public interface ITurtleCommand
|
||||
{
|
||||
|
@ -18,7 +18,7 @@ public interface ITurtleCommand
|
|||
* failure with an error message to indicate the command cannot be executed at this time.
|
||||
* @param turtle access to the turtle for whom the command was issued
|
||||
* @return TurtleCommandResult.success() or TurtleCommandResult.failure( errorMessage )
|
||||
* @see ITurtleAccess#issueCommand(ITurtleCommand)
|
||||
* @see ITurtleAccess#executeCommand(dan200.computercraft.api.lua.ILuaContext,ITurtleCommand)
|
||||
* @see dan200.computercraft.api.turtle.TurtleCommandResult
|
||||
*/
|
||||
public TurtleCommandResult execute( ITurtleAccess turtle );
|
||||
|
|
|
@ -13,7 +13,7 @@ import net.minecraft.util.IIcon;
|
|||
/**
|
||||
* The primary interface for defining an turtle for Turtles. A turtle turtle
|
||||
* can either be a new tool, or a new peripheral.
|
||||
* @see dan200.computercraft.api.ComputerCraftAPI#registerUpgrade( ITurtleUpgrade )
|
||||
* @see dan200.computercraft.api.ComputerCraftAPI#registerTurtleUpgrade( dan200.computercraft.api.turtle.ITurtleUpgrade )
|
||||
*/
|
||||
public interface ITurtleUpgrade
|
||||
{
|
||||
|
@ -24,7 +24,7 @@ public interface ITurtleUpgrade
|
|||
* The ID must be in the range 64 to 255, as the ID is stored as an 8-bit value,
|
||||
* and 0-64 is reserved for future use by ComputerCraft. The turtle will
|
||||
* fail registration if an already used ID is specified.
|
||||
* @see dan200.computercraft.api.ComputerCraftAPI#registerUpgrade( ITurtleUpgrade )
|
||||
* @see dan200.computercraft.api.ComputerCraftAPI#registerTurtleUpgrade( dan200.computercraft.api.turtle.ITurtleUpgrade )
|
||||
*/
|
||||
public int getUpgradeID();
|
||||
|
||||
|
@ -32,7 +32,7 @@ public interface ITurtleUpgrade
|
|||
* Return a String to describe this type of turtle in turtle item names.
|
||||
* Examples of built-in adjectives are "Wireless", "Mining" and "Crafty".
|
||||
*/
|
||||
public String getAdjective();
|
||||
public String getUnlocalisedAdjective();
|
||||
|
||||
/**
|
||||
* Return whether this turtle adds a tool or a peripheral to the turtle.
|
||||
|
@ -78,12 +78,12 @@ public interface ITurtleUpgrade
|
|||
public TurtleCommandResult useTool( ITurtleAccess turtle, TurtleSide side, TurtleVerb verb, int direction );
|
||||
|
||||
/**
|
||||
* Called to obtain the Icon to be used when rendering a turtle peripheral. Needs to be a "common"
|
||||
* type Icon for now, as there is no way to determine which texture sheet an Icon is from by the
|
||||
* Icon itself.
|
||||
* Called to obtain the IIcon to be used when rendering a turtle peripheral. Needs to be a "common"
|
||||
* type IIcon for now, as there is no way to determine which texture sheet an IIcon is from by the
|
||||
* IIcon itself.
|
||||
* @param turtle Access to the turtle that the peripheral resides on.
|
||||
* @param side Which side of the turtle (left or right) the peripheral resides on.
|
||||
* @return The Icon that you wish to be used to render your turtle peripheral.
|
||||
* @return The IIcon that you wish to be used to render your turtle peripheral.
|
||||
*/
|
||||
public IIcon getIcon( ITurtleAccess turtle, TurtleSide side );
|
||||
|
||||
|
|
|
@ -8,13 +8,25 @@ package dan200.computercraft.api.turtle;
|
|||
|
||||
public final class TurtleCommandResult
|
||||
{
|
||||
private static final TurtleCommandResult s_success = new TurtleCommandResult( true, null );
|
||||
private static final TurtleCommandResult s_emptyFailure = new TurtleCommandResult( false, null );
|
||||
private static final TurtleCommandResult s_success = new TurtleCommandResult( true, null, null );
|
||||
private static final TurtleCommandResult s_emptyFailure = new TurtleCommandResult( false, null, null );
|
||||
|
||||
public static TurtleCommandResult success()
|
||||
{
|
||||
return success( null );
|
||||
}
|
||||
|
||||
public static TurtleCommandResult success( Object[] results )
|
||||
{
|
||||
if( results == null || results.length == 0 )
|
||||
{
|
||||
return s_success;
|
||||
}
|
||||
else
|
||||
{
|
||||
return new TurtleCommandResult( true, null, results );
|
||||
}
|
||||
}
|
||||
|
||||
public static TurtleCommandResult failure()
|
||||
{
|
||||
|
@ -23,23 +35,25 @@ public final class TurtleCommandResult
|
|||
|
||||
public static TurtleCommandResult failure( String errorMessage )
|
||||
{
|
||||
if( errorMessage != null )
|
||||
if( errorMessage == null )
|
||||
{
|
||||
return new TurtleCommandResult( false, errorMessage );
|
||||
return s_emptyFailure;
|
||||
}
|
||||
else
|
||||
{
|
||||
return s_emptyFailure;
|
||||
return new TurtleCommandResult( false, errorMessage, null );
|
||||
}
|
||||
}
|
||||
|
||||
private final boolean m_success;
|
||||
private final String m_errorMessage;
|
||||
private final Object[] m_results;
|
||||
|
||||
private TurtleCommandResult( boolean success, String errorMessage )
|
||||
private TurtleCommandResult( boolean success, String errorMessage, Object[] results )
|
||||
{
|
||||
m_success = success;
|
||||
m_errorMessage = errorMessage;
|
||||
m_results = results;
|
||||
}
|
||||
|
||||
public boolean isSuccess()
|
||||
|
@ -51,4 +65,9 @@ public final class TurtleCommandResult
|
|||
{
|
||||
return m_errorMessage;
|
||||
}
|
||||
|
||||
public Object[] getResults()
|
||||
{
|
||||
return m_results;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
@API( owner="ComputerCraft", provides="ComputerCraft|API|Turtle", apiVersion="1.65" )
|
||||
package dan200.computercraft.api.turtle;
|
||||
|
||||
import cpw.mods.fml.common.API;
|
23
src/api/java/ic2/api/energy/tile/IHeatSource.java
Normal file
23
src/api/java/ic2/api/energy/tile/IHeatSource.java
Normal file
|
@ -0,0 +1,23 @@
|
|||
package ic2.api.energy.tile;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public interface IHeatSource {
|
||||
|
||||
/*
|
||||
* Return max heat transmission peer Tick (only theoretical bandwidth not available amount)
|
||||
*/
|
||||
int maxrequestHeatTick(ForgeDirection directionFrom);
|
||||
|
||||
/*
|
||||
* @param requested amount of heat to transfer
|
||||
*
|
||||
* @return transmitted amount of heat
|
||||
*
|
||||
* example: You Request 100 units of heat but the Source have only 50 units left
|
||||
*
|
||||
* requestHeat(100) : return 50 : so 50 units of heat remove from HeatSource
|
||||
*/
|
||||
|
||||
int requestHeat(ForgeDirection directionFrom, int requestheat);
|
||||
}
|
22
src/api/java/ic2/api/energy/tile/IKineticSource.java
Normal file
22
src/api/java/ic2/api/energy/tile/IKineticSource.java
Normal file
|
@ -0,0 +1,22 @@
|
|||
package ic2.api.energy.tile;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public interface IKineticSource {
|
||||
/*
|
||||
* Return max kinetic energy transmission peer Tick (only theoretical bandwidth not available amount)
|
||||
*/
|
||||
int maxrequestkineticenergyTick(ForgeDirection directionFrom);
|
||||
|
||||
/*
|
||||
* @param requested amount of kinetic energy to transfer
|
||||
*
|
||||
* @return transmitted amount of kineticenergy
|
||||
*
|
||||
* example: You Request 100 units of kinetic energy but the Source have only 50 units left
|
||||
*
|
||||
* requestkineticenergy(100) : return 50 : so 50 units of kinetic energy remove from KineticSource
|
||||
*/
|
||||
|
||||
int requestkineticenergy(ForgeDirection directionFrom, int requestkineticenergy);
|
||||
}
|
36
src/api/java/ic2/api/energy/tile/IMetaDelegate.java
Normal file
36
src/api/java/ic2/api/energy/tile/IMetaDelegate.java
Normal file
|
@ -0,0 +1,36 @@
|
|||
package ic2.api.energy.tile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
/**
|
||||
* Interface for grouping multi-block structures to a single energy net delegate.
|
||||
*
|
||||
* The energy net uses TileEntity to refer to a specific xyz+world position. If multiple of those
|
||||
* positions should belong to the same functional structure, i.e. they consume or produce energy
|
||||
* only once for the whole multi-block instead of once per every single block, this interface
|
||||
* allows to do so.
|
||||
*
|
||||
* The tile entity implementing IMetaDelegate has to be added/removed to/from the energy net
|
||||
* instead of every single sub-TileEntity. The energy net interaction will be handled by the
|
||||
* IMetaDelegate TileEntity as well.
|
||||
*
|
||||
* The sub tile array TileEntity[] just provides optional connectivity (IEnergyAcceptor,
|
||||
* IEnergyEmitter) and mandatory position (x, y, z, World) data.
|
||||
* If the connectivity data on the sub tile is missing, the meta delegate is queried instead.
|
||||
*
|
||||
* See ic2/api/energy/usage.txt for an overall description of the energy net api.
|
||||
*/
|
||||
public interface IMetaDelegate extends IEnergyTile {
|
||||
/**
|
||||
* Get the sub-TileEntities belonging to this Meta TileEntity.
|
||||
*
|
||||
* @note The list has to be consistent between the EnergyNet Load and Unload events.
|
||||
* @note The list must have at least 1 element.
|
||||
* @note The parent te implementing IMetaDelegate isn't automatically included.
|
||||
*
|
||||
* @return sub-TileEntity array
|
||||
*/
|
||||
List<TileEntity> getSubTiles();
|
||||
}
|
|
@ -2,13 +2,13 @@ package micdoodle8.mods.galacticraft.api.world;
|
|||
|
||||
/**
|
||||
* Used to change the solar multiplier of certain world providers
|
||||
*
|
||||
* <p/>
|
||||
* If you have a solar feature in your mod, check whether the world's provider
|
||||
* inherits this class and multiply the solar generation by the solar multiplier
|
||||
* double
|
||||
*
|
||||
* <p/>
|
||||
* for example:
|
||||
*
|
||||
* <p/>
|
||||
* if (worldObj.provider instanceof ISolarLevel) solarStrength *= ((ISolarLevel)
|
||||
* worldObj.provider).getSolarEnergyMultiplier();
|
||||
*/
|
||||
|
|
|
@ -76,6 +76,7 @@ import mekanism.common.tile.TileEntityRotaryCondensentrator;
|
|||
import mekanism.common.tile.TileEntitySalinationController;
|
||||
import mekanism.common.tile.TileEntitySeismicVibrator;
|
||||
import mekanism.common.tile.TileEntityTeleporter;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.init.Blocks;
|
||||
|
@ -200,8 +201,8 @@ public class CommonProxy
|
|||
Mekanism.userWorldGenVersion = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "WorldRegenVersion", 0).getInt();
|
||||
Mekanism.FROM_IC2 = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "JoulesToEU", 10D).getDouble(10D);
|
||||
Mekanism.TO_IC2 = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "EUToJoules", .1D).getDouble(.1D);
|
||||
Mekanism.FROM_BC = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "JoulesToMJ", 25D).getDouble(25D);
|
||||
Mekanism.TO_BC = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "MJToJoules", .04D).getDouble(.04D);
|
||||
Mekanism.FROM_TE = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "JoulesToRF", 2.5D).getDouble(25D);
|
||||
Mekanism.TO_TE = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "RFToJoules", .4D).getDouble(.04D);
|
||||
Mekanism.FROM_H2 = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "HydrogenEnergyDensity", 200D, "THIS DETERMINES ELECTROLYTIC SEPARATOR USAGE").getDouble(200D);
|
||||
Mekanism.ENERGY_PER_REDSTONE = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "EnergyPerRedstone", 10000D).getDouble(10000D);
|
||||
Mekanism.VOICE_PORT = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "VoicePort", 36123, null, 1, 65535).getInt();
|
||||
|
@ -231,10 +232,6 @@ public class CommonProxy
|
|||
}
|
||||
}
|
||||
|
||||
Mekanism.TO_TE = Mekanism.TO_BC*10;
|
||||
Mekanism.FROM_TE = Mekanism.FROM_BC/10;
|
||||
|
||||
Mekanism.blacklistBC = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "BlacklistBuildCraftPower", false).getBoolean();
|
||||
Mekanism.blacklistIC2 = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "BlacklistIC2Power", false).getBoolean();
|
||||
Mekanism.blacklistRF = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "BlacklistRFPower", false).getBoolean();
|
||||
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
package mekanism.common;
|
||||
|
||||
import ic2.api.energy.EnergyNet;
|
||||
import ic2.api.energy.tile.IEnergySink;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
@ -20,15 +17,17 @@ import mekanism.api.transmitters.IGridTransmitter;
|
|||
import mekanism.api.transmitters.TransmissionType;
|
||||
import mekanism.common.util.CableUtils;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import buildcraft.api.mj.IBatteryObject;
|
||||
import buildcraft.api.mj.MjAPI;
|
||||
import cofh.api.energy.IEnergyHandler;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
|
||||
import cofh.api.energy.IEnergyReceiver;
|
||||
import ic2.api.energy.EnergyNet;
|
||||
import ic2.api.energy.tile.IEnergySink;
|
||||
|
||||
public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
|
||||
{
|
||||
private double lastPowerScale = 0;
|
||||
|
@ -154,10 +153,13 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
|
|||
return sent;
|
||||
}
|
||||
|
||||
public synchronized double emit(double energyToSend)
|
||||
public synchronized double emit(double energyToSend, boolean doEmit)
|
||||
{
|
||||
double toUse = Math.min(getEnergyNeeded(), energyToSend);
|
||||
if(doEmit)
|
||||
{
|
||||
electricityStored += toUse;
|
||||
}
|
||||
return energyToSend-toUse;
|
||||
}
|
||||
|
||||
|
@ -197,11 +199,11 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
|
|||
{
|
||||
sent += ((IStrictEnergyAcceptor)acceptor).transferEnergyToAcceptor(side.getOpposite(), currentSending);
|
||||
}
|
||||
else if(MekanismUtils.useRF() && acceptor instanceof IEnergyHandler)
|
||||
else if(MekanismUtils.useRF() && acceptor instanceof IEnergyReceiver)
|
||||
{
|
||||
IEnergyHandler handler = (IEnergyHandler)acceptor;
|
||||
int used = handler.receiveEnergy(side.getOpposite(), (int)Math.round(currentSending*Mekanism.TO_TE), false);
|
||||
sent += used*Mekanism.FROM_TE;
|
||||
IEnergyReceiver handler = (IEnergyReceiver)acceptor;
|
||||
int used = handler.receiveEnergy(side.getOpposite(), (int) Math.round(currentSending * Mekanism.TO_TE), false);
|
||||
sent += used * Mekanism.FROM_TE;
|
||||
}
|
||||
else if(MekanismUtils.useIC2() && acceptor instanceof IEnergySink)
|
||||
{
|
||||
|
@ -209,12 +211,6 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
|
|||
toSend = Math.min(toSend, ((IEnergySink)acceptor).getDemandedEnergy()*Mekanism.FROM_IC2);
|
||||
sent += (toSend - (((IEnergySink)acceptor).injectEnergy(side.getOpposite(), toSend*Mekanism.TO_IC2, 0)*Mekanism.FROM_IC2));
|
||||
}
|
||||
else if(MekanismUtils.useBuildCraft() && MjAPI.getMjBattery(acceptor, MjAPI.DEFAULT_POWER_FRAMEWORK, side.getOpposite()) != null && !tryAgain)
|
||||
{
|
||||
IBatteryObject battery = MjAPI.getMjBattery(acceptor, MjAPI.DEFAULT_POWER_FRAMEWORK, side.getOpposite());
|
||||
double toSend = battery.addEnergy(Math.min(battery.getEnergyRequested(), currentSending*Mekanism.TO_BC));
|
||||
sent += toSend*Mekanism.FROM_BC;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -254,9 +250,9 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
|
|||
}
|
||||
}
|
||||
}
|
||||
else if(MekanismUtils.useRF() && acceptor instanceof IEnergyHandler)
|
||||
else if(MekanismUtils.useRF() && acceptor instanceof IEnergyReceiver)
|
||||
{
|
||||
IEnergyHandler handler = (IEnergyHandler)acceptor;
|
||||
IEnergyReceiver handler = (IEnergyReceiver)acceptor;
|
||||
|
||||
if(handler.canConnectEnergy(side.getOpposite()))
|
||||
{
|
||||
|
@ -284,16 +280,6 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
|
|||
}
|
||||
}
|
||||
}
|
||||
else if(MekanismUtils.useBuildCraft() && MjAPI.getMjBattery(acceptor, MjAPI.DEFAULT_POWER_FRAMEWORK, side.getOpposite()) != null)
|
||||
{
|
||||
IBatteryObject battery = MjAPI.getMjBattery(acceptor, MjAPI.DEFAULT_POWER_FRAMEWORK, side.getOpposite());
|
||||
|
||||
if(battery.getEnergyRequested() > 0)
|
||||
{
|
||||
toReturn.add(acceptor);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
|
|
|
@ -3,11 +3,13 @@ package mekanism.common;
|
|||
import java.util.HashMap;
|
||||
|
||||
import mekanism.api.gas.Gas;
|
||||
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
import buildcraft.api.fuels.IronEngineFuel;
|
||||
import buildcraft.api.fuels.IronEngineFuel.Fuel;
|
||||
import cpw.mods.fml.common.ModAPIManager;
|
||||
|
||||
import buildcraft.api.fuels.BuildcraftFuelRegistry;
|
||||
import buildcraft.api.fuels.IFuel;
|
||||
|
||||
public class FuelHandler
|
||||
{
|
||||
public static HashMap<String, FuelGas> fuels = new HashMap<String, FuelGas>();
|
||||
|
@ -26,7 +28,7 @@ public class FuelHandler
|
|||
|
||||
if(ModAPIManager.INSTANCE.hasAPI("BuildCraftAPI|fuels") && gas.hasFluid())
|
||||
{
|
||||
Fuel bcFuel = IronEngineFuel.getFuelForFluid(gas.getFluid());
|
||||
IFuel bcFuel = BuildcraftFuelRegistry.fuel.getFuel(gas.getFluid());
|
||||
|
||||
if(bcFuel != null)
|
||||
{
|
||||
|
@ -51,10 +53,10 @@ public class FuelHandler
|
|||
energyPerTick = energyDensity / duration;
|
||||
}
|
||||
|
||||
public FuelGas(Fuel bcFuel)
|
||||
public FuelGas(IFuel bcFuel)
|
||||
{
|
||||
burnTicks = bcFuel.totalBurningTime / FluidContainerRegistry.BUCKET_VOLUME;
|
||||
energyPerTick = bcFuel.powerPerCycle * Mekanism.FROM_BC;
|
||||
burnTicks = bcFuel.getTotalBurningTime() / FluidContainerRegistry.BUCKET_VOLUME;
|
||||
energyPerTick = bcFuel.getPowerPerCycle() * Mekanism.FROM_TE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,26 +1,25 @@
|
|||
package mekanism.common;
|
||||
|
||||
import ic2.api.energy.tile.IEnergySink;
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.IFilterAccess;
|
||||
import mekanism.api.energy.IStrictEnergyAcceptor;
|
||||
import mekanism.api.energy.IStrictEnergyStorage;
|
||||
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import cpw.mods.fml.common.Optional.Interface;
|
||||
import cpw.mods.fml.common.Optional.InterfaceList;
|
||||
|
||||
import buildcraft.api.power.IPowerReceptor;
|
||||
import cofh.api.energy.IEnergyHandler;
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
import ic2.api.energy.tile.IEnergySink;
|
||||
|
||||
@InterfaceList({
|
||||
@Interface(iface = "buildcraft.api.power.IPowerReceptor", modid = "BuildCraftAPI|power"),
|
||||
@Interface(iface = "ic2.api.energy.tile.IEnergySink", modid = "IC2"),
|
||||
@Interface(iface = "cofh.api.energy.IEnergyHandler", modid = "CoFHAPI|energy"),
|
||||
@Interface(iface = "dan200.computercraft.api.peripheral.IPeripheral", modid = "ComputerCraft")
|
||||
})
|
||||
public interface IAdvancedBoundingBlock extends IBoundingBlock, ISidedInventory, IEnergySink, IStrictEnergyAcceptor, IPowerReceptor, IStrictEnergyStorage, IEnergyHandler, IPeripheral, IFilterAccess
|
||||
public interface IAdvancedBoundingBlock extends IBoundingBlock, ISidedInventory, IEnergySink, IStrictEnergyAcceptor, IStrictEnergyStorage, IEnergyHandler, IPeripheral, IFilterAccess
|
||||
{
|
||||
public int[] getBoundSlots(Coord4D location, int side);
|
||||
|
||||
|
|
|
@ -109,6 +109,7 @@ import mekanism.common.util.MekanismUtils;
|
|||
import mekanism.common.util.MekanismUtils.ResourceType;
|
||||
import mekanism.common.voice.VoiceServerManager;
|
||||
import mekanism.common.world.GenHandler;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
|
@ -130,13 +131,6 @@ import net.minecraftforge.oredict.OreDictionary;
|
|||
import net.minecraftforge.oredict.RecipeSorter;
|
||||
import net.minecraftforge.oredict.RecipeSorter.Category;
|
||||
import net.minecraftforge.oredict.ShapelessOreRecipe;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import rebelkeithy.mods.metallurgy.api.IOreInfo;
|
||||
import rebelkeithy.mods.metallurgy.api.MetallurgyAPI;
|
||||
import codechicken.multipart.handler.MultipartProxy;
|
||||
import cpw.mods.fml.client.event.ConfigChangedEvent;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.IFuelHandler;
|
||||
|
@ -154,6 +148,12 @@ import cpw.mods.fml.common.network.NetworkRegistry;
|
|||
import cpw.mods.fml.common.registry.EntityRegistry;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
|
||||
import codechicken.multipart.handler.MultipartProxy;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import rebelkeithy.mods.metallurgy.api.IOreInfo;
|
||||
import rebelkeithy.mods.metallurgy.api.MetallurgyAPI;
|
||||
|
||||
/**
|
||||
* Mekanism - a Minecraft mod
|
||||
* @author AidanBrady
|
||||
|
@ -322,12 +322,10 @@ public class Mekanism
|
|||
public static EnergyType activeType = EnergyType.J;
|
||||
|
||||
public static double TO_IC2;
|
||||
public static double TO_BC;
|
||||
public static double TO_TE;
|
||||
public static double TO_UE = .001;
|
||||
public static double FROM_H2;
|
||||
public static double FROM_IC2;
|
||||
public static double FROM_BC;
|
||||
public static double FROM_TE;
|
||||
public static double FROM_UE = 1/TO_UE;
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package mekanism.common.multipart;
|
||||
|
||||
import mekanism.common.Tier;
|
||||
|
||||
import codechicken.multipart.MultiPartRegistry;
|
||||
import codechicken.multipart.MultiPartRegistry.IPartFactory;
|
||||
import codechicken.multipart.MultipartGenerator;
|
||||
|
@ -28,7 +29,6 @@ public class MultipartMekanism implements IPartFactory
|
|||
MultipartGenerator.registerPassThroughInterface("mekanism.api.energy.IStrictEnergyAcceptor");
|
||||
MultipartGenerator.registerPassThroughInterface("mekanism.api.transmitters.IGridTransmitter");
|
||||
MultipartGenerator.registerPassThroughInterface("mekanism.common.ILogisticalTransporter");
|
||||
MultipartGenerator.registerPassThroughInterface("buildcraft.api.power.IPowerReceptor");
|
||||
MultipartGenerator.registerPassThroughInterface("cofh.api.energy.IEnergyHandler");
|
||||
MultipartGenerator.registerPassThroughInterface("mekanism.api.IConfigurable");
|
||||
MultipartGenerator.registerPassThroughInterface("mekanism.common.ITileNetwork");
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package mekanism.common.multipart;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
@ -24,6 +22,7 @@ import mekanism.common.transporter.TransporterStack.Path;
|
|||
import mekanism.common.util.InventoryUtils;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import mekanism.common.util.TransporterUtils;
|
||||
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
|
@ -35,14 +34,19 @@ import net.minecraft.util.ChatComponentText;
|
|||
import net.minecraft.util.IIcon;
|
||||
import net.minecraftforge.common.util.Constants.NBT;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import buildcraft.api.transport.IPipeTile;
|
||||
import buildcraft.api.transport.PipeWire;
|
||||
import codechicken.lib.vec.Vector3;
|
||||
import cpw.mods.fml.common.Optional.Interface;
|
||||
import cpw.mods.fml.common.Optional.Method;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import buildcraft.api.gates.IGate;
|
||||
import buildcraft.api.transport.IPipe;
|
||||
import buildcraft.api.transport.IPipeTile;
|
||||
import buildcraft.api.transport.PipeWire;
|
||||
import codechicken.lib.vec.Vector3;
|
||||
|
||||
@Interface(iface = "buildcraft.api.transport.IPipeTile", modid = "BuildCraftAPI|transport")
|
||||
public class PartLogisticalTransporter extends PartSidedPipe implements ILogisticalTransporter, IPipeTile
|
||||
{
|
||||
|
@ -58,6 +62,8 @@ public class PartLogisticalTransporter extends PartSidedPipe implements ILogisti
|
|||
|
||||
public Set<TransporterStack> needsSync = new HashSet<TransporterStack>();
|
||||
|
||||
public TransporterPipeProxy pipe = new TransporterPipeProxy();
|
||||
|
||||
@Override
|
||||
public String getType()
|
||||
{
|
||||
|
@ -667,6 +673,11 @@ public class PartLogisticalTransporter extends PartSidedPipe implements ILogisti
|
|||
return PipeType.ITEM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int injectItem(ItemStack stack, boolean doAdd, ForgeDirection from, buildcraft.api.core.EnumColor color) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int injectItem(ItemStack stack, boolean doAdd, ForgeDirection from)
|
||||
{
|
||||
|
@ -681,12 +692,6 @@ public class PartLogisticalTransporter extends PartSidedPipe implements ILogisti
|
|||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPipeConnected(ForgeDirection with)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onConfigure(EntityPlayer player, int part, int side)
|
||||
{
|
||||
|
@ -775,8 +780,64 @@ public class PartLogisticalTransporter extends PartSidedPipe implements ILogisti
|
|||
|
||||
@Override
|
||||
@Method(modid = "BuildCraftAPI|transport")
|
||||
public boolean isWireActive(PipeWire wire)
|
||||
public boolean isPipeConnected(ForgeDirection with)
|
||||
{
|
||||
return connectionMapContainsSide(getAllCurrentConnections(), with);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Method(modid = "BuildCraftAPI|transport")
|
||||
public TileEntity getAdjacentTile(ForgeDirection dir) {
|
||||
return Coord4D.get(tile()).getFromSide(dir).getTileEntity(world());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Method(modid = "BuildCraftAPI|transport")
|
||||
public IPipe getPipe() {
|
||||
return pipe;
|
||||
}
|
||||
|
||||
public class TransporterPipeProxy implements IPipe
|
||||
{
|
||||
|
||||
@Override
|
||||
public int x() {
|
||||
return PartLogisticalTransporter.this.x();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int y() {
|
||||
return PartLogisticalTransporter.this.y();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int z() {
|
||||
return PartLogisticalTransporter.this.y();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPipeTile getTile() {
|
||||
return (IPipeTile)tile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGate getGate(ForgeDirection side) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasGate(ForgeDirection side) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWired(PipeWire wire) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWireActive(PipeWire wire) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package mekanism.common.multipart;
|
||||
|
||||
import ic2.api.energy.tile.IEnergySource;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -15,35 +13,29 @@ import mekanism.common.Mekanism;
|
|||
import mekanism.common.Tier;
|
||||
import mekanism.common.util.CableUtils;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import buildcraft.api.power.IPowerReceptor;
|
||||
import buildcraft.api.power.PowerHandler;
|
||||
import buildcraft.api.power.PowerHandler.PowerReceiver;
|
||||
import codechicken.lib.vec.Vector3;
|
||||
import cofh.api.energy.IEnergyHandler;
|
||||
|
||||
import cpw.mods.fml.common.Optional.Interface;
|
||||
import cpw.mods.fml.common.Optional.InterfaceList;
|
||||
import cpw.mods.fml.common.Optional.Method;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import codechicken.lib.vec.Vector3;
|
||||
import cofh.api.energy.IEnergyHandler;
|
||||
import ic2.api.energy.tile.IEnergySource;
|
||||
|
||||
@InterfaceList({
|
||||
@Interface(iface = "cofh.api.energy.IEnergyHandler", modid = "CoFHAPI|energy"),
|
||||
@Interface(iface = "buildcraft.api.power.IPowerReceptor", modid = "BuildCraftAPI|power"),
|
||||
})
|
||||
public class PartUniversalCable extends PartTransmitter<EnergyNetwork> implements IStrictEnergyAcceptor, IEnergyHandler, IPowerReceptor
|
||||
public class PartUniversalCable extends PartTransmitter<EnergyNetwork> implements IStrictEnergyAcceptor, IEnergyHandler
|
||||
{
|
||||
public Tier.CableTier tier;
|
||||
|
||||
/** A fake power handler used to initiate energy transfer calculations. */
|
||||
public PowerHandler powerHandler;
|
||||
|
||||
public static TransmitterIcons cableIcons = new TransmitterIcons(4, 1);
|
||||
|
||||
public double currentPower = 0;
|
||||
|
@ -54,11 +46,6 @@ public class PartUniversalCable extends PartTransmitter<EnergyNetwork> implement
|
|||
public PartUniversalCable(Tier.CableTier cableTier)
|
||||
{
|
||||
tier = cableTier;
|
||||
|
||||
if(MekanismUtils.useBuildCraft())
|
||||
{
|
||||
configure();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -110,7 +97,7 @@ public class PartUniversalCable extends PartTransmitter<EnergyNetwork> implement
|
|||
|
||||
if(received > 0)
|
||||
{
|
||||
toDraw -= getTransmitterNetwork().emit(received);
|
||||
toDraw -= getTransmitterNetwork().emit(received, true);
|
||||
}
|
||||
((IEnergySource) acceptor).drawEnergy(toDraw * Mekanism.TO_IC2);
|
||||
}
|
||||
|
@ -128,17 +115,6 @@ public class PartUniversalCable extends PartTransmitter<EnergyNetwork> implement
|
|||
return EnergyNetwork.round(getTransmitterNetwork().electricityStored*(1F/getTransmitterNetwork().transmitters.size()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshTransmitterNetwork()
|
||||
{
|
||||
super.refreshTransmitterNetwork();
|
||||
|
||||
if(MekanismUtils.useBuildCraft())
|
||||
{
|
||||
reconfigure();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransmitterType getTransmitter()
|
||||
{
|
||||
|
@ -271,12 +247,7 @@ public class PartUniversalCable extends PartTransmitter<EnergyNetwork> implement
|
|||
@Method(modid = "CoFHAPI|energy")
|
||||
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate)
|
||||
{
|
||||
if(!simulate)
|
||||
{
|
||||
return maxReceive - (int)Math.round(getTransmitterNetwork().emit(maxReceive*Mekanism.FROM_TE)*Mekanism.TO_TE);
|
||||
}
|
||||
|
||||
return 0;
|
||||
return maxReceive - (int)Math.round(getTransmitterNetwork().emit(maxReceive*Mekanism.FROM_TE, !simulate)*Mekanism.TO_TE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -290,7 +261,7 @@ public class PartUniversalCable extends PartTransmitter<EnergyNetwork> implement
|
|||
@Method(modid = "CoFHAPI|energy")
|
||||
public boolean canConnectEnergy(ForgeDirection from)
|
||||
{
|
||||
return canReceiveEnergy(from);
|
||||
return canConnect(from);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -350,51 +321,4 @@ public class PartUniversalCable extends PartTransmitter<EnergyNetwork> implement
|
|||
{
|
||||
getTransmitterNetwork().electricityStored = energy;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Method(modid = "BuildCraftAPI|power")
|
||||
public PowerReceiver getPowerReceiver(ForgeDirection side)
|
||||
{
|
||||
if(getTransmitterNetwork().getEnergyNeeded() == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return powerHandler.getPowerReceiver();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Method(modid = "BuildCraftAPI|power")
|
||||
public World getWorld()
|
||||
{
|
||||
return world();
|
||||
}
|
||||
|
||||
@Method(modid = "BuildCraftAPI|power")
|
||||
private void configure()
|
||||
{
|
||||
powerHandler = new PowerHandler(this, PowerHandler.Type.STORAGE);
|
||||
powerHandler.configurePowerPerdition(0, 0);
|
||||
powerHandler.configure(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
@Method(modid = "BuildCraftAPI|power")
|
||||
private void reconfigure()
|
||||
{
|
||||
float needed = (float)(getTransmitterNetwork().getEnergyNeeded()*Mekanism.TO_BC);
|
||||
powerHandler.configure(1, needed, 0, needed);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Method(modid = "BuildCraftAPI|power")
|
||||
public void doWork(PowerHandler workProvider)
|
||||
{
|
||||
if(powerHandler.getEnergyStored() > 0)
|
||||
{
|
||||
getTransmitterNetwork().emit(powerHandler.getEnergyStored()*Mekanism.FROM_BC);
|
||||
}
|
||||
|
||||
powerHandler.setEnergy(0);
|
||||
reconfigure();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,16 @@
|
|||
package mekanism.common.network;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import mekanism.common.EnergyDisplay.EnergyType;
|
||||
import mekanism.common.IModule;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.network.PacketConfigSync.ConfigSyncMessage;
|
||||
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class PacketConfigSync implements IMessageHandler<ConfigSyncMessage, IMessage>
|
||||
{
|
||||
@Override
|
||||
|
@ -36,8 +38,8 @@ public class PacketConfigSync implements IMessageHandler<ConfigSyncMessage, IMes
|
|||
dataStream.writeInt(Mekanism.UPDATE_DELAY);
|
||||
dataStream.writeDouble(Mekanism.FROM_IC2);
|
||||
dataStream.writeDouble(Mekanism.TO_IC2);
|
||||
dataStream.writeDouble(Mekanism.FROM_BC);
|
||||
dataStream.writeDouble(Mekanism.TO_BC);
|
||||
dataStream.writeDouble(Mekanism.FROM_TE);
|
||||
dataStream.writeDouble(Mekanism.TO_TE);
|
||||
dataStream.writeDouble(Mekanism.FROM_H2);
|
||||
dataStream.writeDouble(Mekanism.ENERGY_PER_REDSTONE);
|
||||
dataStream.writeInt(Mekanism.VOICE_PORT);
|
||||
|
@ -90,17 +92,14 @@ public class PacketConfigSync implements IMessageHandler<ConfigSyncMessage, IMes
|
|||
Mekanism.UPDATE_DELAY = dataStream.readInt();
|
||||
Mekanism.FROM_IC2 = dataStream.readDouble();
|
||||
Mekanism.TO_IC2 = dataStream.readDouble();
|
||||
Mekanism.FROM_BC = dataStream.readDouble();
|
||||
Mekanism.TO_BC = dataStream.readDouble();
|
||||
Mekanism.FROM_TE = dataStream.readDouble();
|
||||
Mekanism.TO_TE = dataStream.readDouble();
|
||||
Mekanism.FROM_H2 = dataStream.readDouble();
|
||||
Mekanism.ENERGY_PER_REDSTONE = dataStream.readDouble();
|
||||
Mekanism.VOICE_PORT = dataStream.readInt();
|
||||
Mekanism.maxUpgradeMultiplier = dataStream.readInt();
|
||||
Mekanism.activeType = EnergyType.values()[dataStream.readInt()];
|
||||
|
||||
Mekanism.TO_TE = Mekanism.TO_BC*10;
|
||||
Mekanism.FROM_TE = Mekanism.FROM_BC/10;
|
||||
|
||||
Mekanism.enrichmentChamberUsage = dataStream.readDouble();
|
||||
Mekanism.osmiumCompressorUsage = dataStream.readDouble();
|
||||
Mekanism.combinerUsage = dataStream.readDouble();
|
||||
|
|
|
@ -1,37 +1,34 @@
|
|||
package mekanism.common.tile;
|
||||
|
||||
import ic2.api.energy.tile.IEnergySink;
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.IFilterAccess;
|
||||
import mekanism.api.energy.IStrictEnergyAcceptor;
|
||||
import mekanism.common.IAdvancedBoundingBlock;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.util.InventoryUtils;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
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;
|
||||
import buildcraft.api.power.PowerHandler.PowerReceiver;
|
||||
import cofh.api.energy.IEnergyHandler;
|
||||
import cpw.mods.fml.common.Optional.Interface;
|
||||
import cpw.mods.fml.common.Optional.InterfaceList;
|
||||
import cpw.mods.fml.common.Optional.Method;
|
||||
|
||||
import cofh.api.energy.IEnergyHandler;
|
||||
import dan200.computercraft.api.lua.ILuaContext;
|
||||
import dan200.computercraft.api.lua.LuaException;
|
||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
import ic2.api.energy.tile.IEnergySink;
|
||||
|
||||
@InterfaceList({
|
||||
@Interface(iface = "buildcraft.api.power.IPowerReceptor", modid = "BuildCraftAPI|power"),
|
||||
@Interface(iface = "ic2.api.energy.tile.IEnergySink", modid = "IC2"),
|
||||
@Interface(iface = "cofh.api.energy.IEnergyHandler", modid = "CoFHAPI|energy"),
|
||||
@Interface(iface = "dan200.computercraft.api.peripheral.IPeripheral", modid = "ComputerCraft")
|
||||
})
|
||||
public class TileEntityAdvancedBoundingBlock extends TileEntityBoundingBlock implements ISidedInventory, IEnergySink, IPowerReceptor, IStrictEnergyAcceptor, IEnergyHandler, IPeripheral, IFilterAccess
|
||||
public class TileEntityAdvancedBoundingBlock extends TileEntityBoundingBlock implements ISidedInventory, IEnergySink, IStrictEnergyAcceptor, IEnergyHandler, IPeripheral, IFilterAccess
|
||||
{
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
|
@ -298,42 +295,6 @@ public class TileEntityAdvancedBoundingBlock extends TileEntityBoundingBlock imp
|
|||
return getInv().getMaxEnergy();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Method(modid = "BuildCraftAPI|power")
|
||||
public PowerReceiver getPowerReceiver(ForgeDirection side)
|
||||
{
|
||||
if(getInv() == null)
|
||||
{
|
||||
return new PowerHandler(this, PowerHandler.Type.STORAGE).getPowerReceiver();
|
||||
}
|
||||
|
||||
return getInv().getPowerReceiver(side);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Method(modid = "BuildCraftAPI|power")
|
||||
public void doWork(PowerHandler workProvider)
|
||||
{
|
||||
if(getInv() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
getInv().doWork(workProvider);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Method(modid = "BuildCraftAPI|power")
|
||||
public World getWorld()
|
||||
{
|
||||
if(getInv() == null)
|
||||
{
|
||||
return worldObj;
|
||||
}
|
||||
|
||||
return getInv().getWorld();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double transferEnergyToAcceptor(ForgeDirection side, double amount)
|
||||
{
|
||||
|
@ -458,7 +419,7 @@ public class TileEntityAdvancedBoundingBlock extends TileEntityBoundingBlock imp
|
|||
|
||||
@Override
|
||||
@Method(modid = "ComputerCraft")
|
||||
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception
|
||||
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws LuaException, InterruptedException
|
||||
{
|
||||
if(getInv() == null)
|
||||
{
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
package mekanism.common.tile;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
import mekanism.api.AdvancedInput;
|
||||
import mekanism.api.EnumColor;
|
||||
import mekanism.api.StackUtils;
|
||||
import mekanism.api.gas.Gas;
|
||||
import mekanism.api.gas.GasStack;
|
||||
import mekanism.api.gas.GasTank;
|
||||
|
@ -21,13 +20,16 @@ import mekanism.common.util.ChargeUtils;
|
|||
import mekanism.common.util.InventoryUtils;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import mekanism.common.util.MekanismUtils.ResourceType;
|
||||
import mekanism.api.StackUtils;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import cpw.mods.fml.common.Optional.Method;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import dan200.computercraft.api.lua.ILuaContext;
|
||||
import dan200.computercraft.api.lua.LuaException;
|
||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||
|
||||
public abstract class TileEntityAdvancedElectricMachine extends TileEntityBasicMachine implements IGasHandler, ITubeConnection
|
||||
|
@ -365,7 +367,7 @@ public abstract class TileEntityAdvancedElectricMachine extends TileEntityBasicM
|
|||
|
||||
@Override
|
||||
@Method(modid = "ComputerCraft")
|
||||
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception
|
||||
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws LuaException, InterruptedException
|
||||
{
|
||||
switch(method)
|
||||
{
|
||||
|
|
|
@ -12,11 +12,13 @@ import mekanism.common.tile.component.TileComponentUpgrade;
|
|||
import mekanism.common.util.ChargeUtils;
|
||||
import mekanism.common.util.InventoryUtils;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import cpw.mods.fml.common.Optional.Method;
|
||||
|
||||
import dan200.computercraft.api.lua.ILuaContext;
|
||||
import dan200.computercraft.api.lua.LuaException;
|
||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||
|
||||
|
||||
|
@ -219,7 +221,7 @@ public abstract class TileEntityChanceMachine extends TileEntityBasicMachine
|
|||
|
||||
@Override
|
||||
@Method(modid = "ComputerCraft")
|
||||
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception
|
||||
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws LuaException, InterruptedException
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package mekanism.common.tile;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.BitSet;
|
||||
import java.util.HashSet;
|
||||
|
@ -36,6 +34,7 @@ import mekanism.common.util.InventoryUtils;
|
|||
import mekanism.common.util.MekanismUtils;
|
||||
import mekanism.common.util.MinerUtils;
|
||||
import mekanism.common.util.TransporterUtils;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
|
@ -52,7 +51,11 @@ import cpw.mods.fml.common.Optional.Interface;
|
|||
import cpw.mods.fml.common.Optional.Method;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import dan200.computercraft.api.lua.ILuaContext;
|
||||
import dan200.computercraft.api.lua.LuaException;
|
||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
|
||||
|
@ -1159,7 +1162,7 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I
|
|||
|
||||
@Override
|
||||
@Method(modid = "ComputerCraft")
|
||||
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception
|
||||
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws LuaException, InterruptedException
|
||||
{
|
||||
if(arguments.length > 0)
|
||||
{
|
||||
|
|
|
@ -1,15 +1,5 @@
|
|||
package mekanism.common.tile;
|
||||
|
||||
import ic2.api.energy.EnergyNet;
|
||||
import ic2.api.energy.event.EnergyTileLoadEvent;
|
||||
import ic2.api.energy.event.EnergyTileUnloadEvent;
|
||||
import ic2.api.energy.tile.IEnergyConductor;
|
||||
import ic2.api.energy.tile.IEnergySink;
|
||||
import ic2.api.energy.tile.IEnergySource;
|
||||
import ic2.api.energy.tile.IEnergyTile;
|
||||
import ic2.api.tile.IEnergyStorage;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
|
||||
|
@ -21,29 +11,33 @@ import mekanism.api.transmitters.IGridTransmitter;
|
|||
import mekanism.common.ITileNetwork;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import cpw.mods.fml.common.Optional.Interface;
|
||||
import cpw.mods.fml.common.Optional.InterfaceList;
|
||||
import cpw.mods.fml.common.Optional.Method;
|
||||
|
||||
import buildcraft.api.power.IPowerEmitter;
|
||||
import buildcraft.api.power.IPowerReceptor;
|
||||
import buildcraft.api.power.PowerHandler;
|
||||
import buildcraft.api.power.PowerHandler.PowerReceiver;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import cofh.api.energy.IEnergyHandler;
|
||||
import ic2.api.energy.EnergyNet;
|
||||
import ic2.api.energy.event.EnergyTileLoadEvent;
|
||||
import ic2.api.energy.event.EnergyTileUnloadEvent;
|
||||
import ic2.api.energy.tile.IEnergyConductor;
|
||||
import ic2.api.energy.tile.IEnergySink;
|
||||
import ic2.api.energy.tile.IEnergySource;
|
||||
import ic2.api.energy.tile.IEnergyTile;
|
||||
import ic2.api.tile.IEnergyStorage;
|
||||
|
||||
@InterfaceList({
|
||||
@Interface(iface = "ic2.api.energy.tile.IEnergySink", modid = "IC2"),
|
||||
@Interface(iface = "ic2.api.tile.IEnergyStorage", modid = "IC2"),
|
||||
@Interface(iface = "cofh.api.energy.IEnergyHandler", modid = "CoFHAPI|energy"),
|
||||
@Interface(iface = "buildcraft.api.power.IPowerReceptor", modid = "BuildCraftAPI|power"),
|
||||
@Interface(iface = "buildcraft.api.power.IPowerEmitter", modid = "BuildCraftAPI|power")
|
||||
})
|
||||
public abstract class TileEntityElectricBlock extends TileEntityContainerBlock implements ITileNetwork, IPowerEmitter, IPowerReceptor, IStrictEnergyStorage, IEnergyHandler, IEnergySink, IEnergySource, IEnergyStorage, IStrictEnergyAcceptor, ICableOutputter
|
||||
public abstract class TileEntityElectricBlock extends TileEntityContainerBlock implements ITileNetwork, IStrictEnergyStorage, IEnergyHandler, IEnergySink, IEnergySource, IEnergyStorage, IStrictEnergyAcceptor, ICableOutputter
|
||||
{
|
||||
/** How much energy is stored in this block. */
|
||||
public double electricityStored;
|
||||
|
@ -51,9 +45,6 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
|
|||
/** Maximum amount of energy this machine can hold. */
|
||||
public double MAX_ELECTRICITY;
|
||||
|
||||
/** BuildCraft power handler. */
|
||||
public PowerHandler powerHandler;
|
||||
|
||||
/** Is this registered with IC2 */
|
||||
public boolean ic2Registered = false;
|
||||
|
||||
|
@ -67,20 +58,8 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
|
|||
{
|
||||
super(name);
|
||||
MAX_ELECTRICITY = maxEnergy;
|
||||
|
||||
if(MekanismUtils.useBuildCraft())
|
||||
configure();
|
||||
}
|
||||
|
||||
@Method(modid = "BuildCraftAPI|power")
|
||||
public void configure()
|
||||
{
|
||||
powerHandler = new PowerHandler(this, PowerHandler.Type.STORAGE);
|
||||
powerHandler.configurePowerPerdition(0, 0);
|
||||
powerHandler.configure(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
@Method(modid = "IC2")
|
||||
public void register()
|
||||
{
|
||||
|
@ -118,8 +97,6 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
|
|||
@Override
|
||||
public void onUpdate()
|
||||
{
|
||||
if(MekanismUtils.useBuildCraft())
|
||||
reconfigure();
|
||||
if(!ic2Registered && MekanismUtils.useIC2())
|
||||
register();
|
||||
}
|
||||
|
@ -199,9 +176,6 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
|
|||
super.readFromNBT(nbtTags);
|
||||
|
||||
electricityStored = nbtTags.getDouble("electricityStored");
|
||||
|
||||
if(MekanismUtils.useBuildCraft())
|
||||
reconfigure();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -212,48 +186,6 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
|
|||
nbtTags.setDouble("electricityStored", getEnergy());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Method(modid = "BuildCraftAPI|power")
|
||||
public PowerReceiver getPowerReceiver(ForgeDirection side)
|
||||
{
|
||||
if(getConsumingSides().contains(side))
|
||||
{
|
||||
return powerHandler.getPowerReceiver();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Method(modid = "BuildCraftAPI|power")
|
||||
protected void reconfigure()
|
||||
{
|
||||
powerHandler.configure(0, (float)((getMaxEnergy() - getEnergy()) * Mekanism.TO_BC), 0, (float)(getMaxEnergy() * Mekanism.TO_BC));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Method(modid = "BuildCraftAPI|power")
|
||||
public void doWork(PowerHandler workProvider)
|
||||
{
|
||||
if(powerHandler.getEnergyStored() > 0)
|
||||
{
|
||||
if(getEnergy() < getMaxEnergy())
|
||||
{
|
||||
setEnergy(getEnergy() + powerHandler.useEnergy(0, (float)((getMaxEnergy()-getEnergy())*Mekanism.TO_BC), true)*Mekanism.FROM_BC);
|
||||
}
|
||||
|
||||
powerHandler.setEnergy(0);
|
||||
}
|
||||
|
||||
reconfigure();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Method(modid = "BuildCraftAPI|power")
|
||||
public World getWorld()
|
||||
{
|
||||
return worldObj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the scaled energy level for the GUI.
|
||||
* @param i - multiplier
|
||||
|
@ -459,11 +391,4 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
|
|||
|
||||
return toUse;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Method(modid = "BuildCraftAPI|power")
|
||||
public boolean canEmitPowerFrom(ForgeDirection side)
|
||||
{
|
||||
return getOutputtingSides().contains(side);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,12 +10,12 @@ import mekanism.common.util.ChargeUtils;
|
|||
import mekanism.common.util.InventoryUtils;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import mekanism.common.util.MekanismUtils.ResourceType;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import cpw.mods.fml.common.Optional.Interface;
|
||||
import cpw.mods.fml.common.Optional.InterfaceList;
|
||||
import cpw.mods.fml.common.Optional.Method;
|
||||
|
||||
import dan200.computercraft.api.lua.ILuaContext;
|
||||
import dan200.computercraft.api.lua.LuaException;
|
||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||
|
||||
public abstract class TileEntityElectricMachine extends TileEntityBasicMachine
|
||||
|
@ -188,7 +188,7 @@ public abstract class TileEntityElectricMachine extends TileEntityBasicMachine
|
|||
|
||||
@Override
|
||||
@Method(modid = "ComputerCraft")
|
||||
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception
|
||||
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws LuaException, InterruptedException
|
||||
{
|
||||
switch(method)
|
||||
{
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package mekanism.common.tile;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import mekanism.api.ChemicalPair;
|
||||
|
@ -25,6 +23,7 @@ import mekanism.common.util.ChargeUtils;
|
|||
import mekanism.common.util.FluidContainerUtils;
|
||||
import mekanism.common.util.InventoryUtils;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
@ -39,7 +38,11 @@ import net.minecraftforge.fluids.IFluidContainerItem;
|
|||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
import cpw.mods.fml.common.Optional.Interface;
|
||||
import cpw.mods.fml.common.Optional.Method;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import dan200.computercraft.api.lua.ILuaContext;
|
||||
import dan200.computercraft.api.lua.LuaException;
|
||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
|
||||
|
@ -524,7 +527,7 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
|
|||
|
||||
@Override
|
||||
@Method(modid = "ComputerCraft")
|
||||
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception
|
||||
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws LuaException, InterruptedException
|
||||
{
|
||||
switch(method)
|
||||
{
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package mekanism.common.tile;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
|
||||
|
@ -15,13 +13,18 @@ import mekanism.common.network.PacketTileEntity.TileEntityMessage;
|
|||
import mekanism.common.util.CableUtils;
|
||||
import mekanism.common.util.ChargeUtils;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import cpw.mods.fml.common.Optional.Interface;
|
||||
import cpw.mods.fml.common.Optional.Method;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import dan200.computercraft.api.lua.ILuaContext;
|
||||
import dan200.computercraft.api.lua.LuaException;
|
||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
|
||||
|
@ -168,7 +171,7 @@ public class TileEntityEnergyCube extends TileEntityElectricBlock implements IPe
|
|||
|
||||
@Override
|
||||
@Method(modid = "ComputerCraft")
|
||||
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception
|
||||
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws LuaException, InterruptedException
|
||||
{
|
||||
switch(method)
|
||||
{
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
package mekanism.common.tile;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.EnumColor;
|
||||
import mekanism.api.Range4D;
|
||||
import mekanism.api.StackUtils;
|
||||
import mekanism.api.gas.Gas;
|
||||
import mekanism.api.gas.GasStack;
|
||||
import mekanism.api.gas.GasTank;
|
||||
|
@ -33,14 +32,18 @@ import mekanism.common.tile.component.TileComponentUpgrade;
|
|||
import mekanism.common.util.ChargeUtils;
|
||||
import mekanism.common.util.InventoryUtils;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import mekanism.api.StackUtils;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import cpw.mods.fml.common.Optional.Interface;
|
||||
import cpw.mods.fml.common.Optional.Method;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import dan200.computercraft.api.lua.ILuaContext;
|
||||
import dan200.computercraft.api.lua.LuaException;
|
||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
|
||||
|
@ -700,7 +703,7 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IPerip
|
|||
|
||||
@Override
|
||||
@Method(modid = "ComputerCraft")
|
||||
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception
|
||||
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws LuaException, InterruptedException
|
||||
{
|
||||
switch(method)
|
||||
{
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package mekanism.common.tile;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import mekanism.api.Coord4D;
|
||||
|
@ -30,11 +28,16 @@ import mekanism.common.tile.component.TileComponentUpgrade;
|
|||
import mekanism.common.util.ChargeUtils;
|
||||
import mekanism.common.util.InventoryUtils;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import cpw.mods.fml.common.Optional.Interface;
|
||||
import cpw.mods.fml.common.Optional.Method;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import dan200.computercraft.api.lua.ILuaContext;
|
||||
import dan200.computercraft.api.lua.LuaException;
|
||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
|
||||
|
@ -448,7 +451,7 @@ public class TileEntityMetallurgicInfuser extends TileEntityElectricBlock implem
|
|||
|
||||
@Override
|
||||
@Method(modid = "ComputerCraft")
|
||||
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception
|
||||
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws LuaException, InterruptedException
|
||||
{
|
||||
switch(method)
|
||||
{
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package mekanism.common.tile;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -27,6 +25,7 @@ import mekanism.common.util.ChargeUtils;
|
|||
import mekanism.common.util.InventoryUtils;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import mekanism.common.util.PipeUtils;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
@ -39,7 +38,11 @@ import net.minecraftforge.fluids.FluidTank;
|
|||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
import cpw.mods.fml.common.Optional.Method;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import dan200.computercraft.api.lua.ILuaContext;
|
||||
import dan200.computercraft.api.lua.LuaException;
|
||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||
|
||||
public class TileEntityPRC extends TileEntityBasicMachine implements IFluidHandler, IGasHandler, ITubeConnection, ISustainedData
|
||||
|
@ -344,7 +347,7 @@ public class TileEntityPRC extends TileEntityBasicMachine implements IFluidHandl
|
|||
|
||||
@Override
|
||||
@Method(modid = "ComputerCraft")
|
||||
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception
|
||||
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws LuaException, InterruptedException
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package mekanism.common.tile;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
|
@ -18,6 +16,7 @@ import mekanism.common.network.PacketPortalFX.PortalFXMessage;
|
|||
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
|
||||
import mekanism.common.util.ChargeUtils;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityList;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
|
@ -35,7 +34,11 @@ import cpw.mods.fml.common.Optional.Interface;
|
|||
import cpw.mods.fml.common.Optional.Method;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import dan200.computercraft.api.lua.ILuaContext;
|
||||
import dan200.computercraft.api.lua.LuaException;
|
||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
|
||||
|
@ -539,7 +542,7 @@ public class TileEntityTeleporter extends TileEntityElectricBlock implements IPe
|
|||
|
||||
@Override
|
||||
@Method(modid = "ComputerCraft")
|
||||
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception
|
||||
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws LuaException, InterruptedException
|
||||
{
|
||||
switch(method)
|
||||
{
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
package mekanism.common.util;
|
||||
|
||||
import ic2.api.energy.EnergyNet;
|
||||
import ic2.api.energy.tile.IEnergyAcceptor;
|
||||
import ic2.api.energy.tile.IEnergySink;
|
||||
import ic2.api.energy.tile.IEnergySource;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
@ -17,13 +12,17 @@ import mekanism.api.transmitters.IGridTransmitter;
|
|||
import mekanism.api.transmitters.TransmissionType;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.tile.TileEntityElectricBlock;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import buildcraft.api.mj.IBatteryObject;
|
||||
import buildcraft.api.mj.MjAPI;
|
||||
import buildcraft.api.power.IPowerEmitter;
|
||||
|
||||
import cofh.api.energy.IEnergyConnection;
|
||||
import cofh.api.energy.IEnergyHandler;
|
||||
import cofh.api.energy.IEnergyProvider;
|
||||
import cofh.api.energy.IEnergyReceiver;
|
||||
import ic2.api.energy.EnergyNet;
|
||||
import ic2.api.energy.tile.IEnergyAcceptor;
|
||||
import ic2.api.energy.tile.IEnergySink;
|
||||
import ic2.api.energy.tile.IEnergySource;
|
||||
|
||||
public final class CableUtils
|
||||
{
|
||||
|
@ -55,8 +54,7 @@ public final class CableUtils
|
|||
{
|
||||
return (tileEntity instanceof IStrictEnergyAcceptor ||
|
||||
(MekanismUtils.useIC2() && tileEntity instanceof IEnergySink) ||
|
||||
(MekanismUtils.useBuildCraft() && MjAPI.getMjBattery(tileEntity) != null && !(tileEntity instanceof IGridTransmitter)) ||
|
||||
(MekanismUtils.useRF() && tileEntity instanceof IEnergyHandler));
|
||||
(MekanismUtils.useRF() && tileEntity instanceof IEnergyReceiver));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -145,9 +143,7 @@ public final class CableUtils
|
|||
{
|
||||
return (tileEntity instanceof ICableOutputter && ((ICableOutputter)tileEntity).canOutputTo(side.getOpposite())) ||
|
||||
(MekanismUtils.useIC2() && tileEntity instanceof IEnergySource && ((IEnergySource)tileEntity).emitsEnergyTo(null, side.getOpposite())) ||
|
||||
(MekanismUtils.useRF() && tileEntity instanceof IEnergyHandler && ((IEnergyHandler)tileEntity).canConnectEnergy(side.getOpposite())) ||
|
||||
(MekanismUtils.useRF() && tileEntity instanceof IEnergyConnection && ((IEnergyConnection)tileEntity).canConnectEnergy(side.getOpposite())) ||
|
||||
(MekanismUtils.useBuildCraft() && tileEntity instanceof IPowerEmitter && ((IPowerEmitter)tileEntity).canEmitPowerFrom(side.getOpposite()));
|
||||
(MekanismUtils.useRF() && tileEntity instanceof IEnergyProvider && ((IEnergyConnection)tileEntity).canConnectEnergy(side.getOpposite()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -196,16 +192,9 @@ public final class CableUtils
|
|||
return true;
|
||||
}
|
||||
}
|
||||
else if(MekanismUtils.useRF() && tileEntity instanceof IEnergyHandler)
|
||||
else if(MekanismUtils.useRF() && tileEntity instanceof IEnergyConnection)
|
||||
{
|
||||
if(((IEnergyHandler)tileEntity).canConnectEnergy(side.getOpposite()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if(MekanismUtils.useBuildCraft())
|
||||
{
|
||||
if(MjAPI.getMjBattery(tileEntity, MjAPI.DEFAULT_POWER_FRAMEWORK, side.getOpposite()) != null)
|
||||
if(((IEnergyConnection)tileEntity).canConnectEnergy(side.getOpposite()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -298,9 +287,9 @@ public final class CableUtils
|
|||
sent += acceptor.transferEnergyToAcceptor(side.getOpposite(), currentSending);
|
||||
}
|
||||
}
|
||||
else if(MekanismUtils.useRF() && tileEntity instanceof IEnergyHandler)
|
||||
else if(MekanismUtils.useRF() && tileEntity instanceof IEnergyReceiver)
|
||||
{
|
||||
IEnergyHandler handler = (IEnergyHandler)tileEntity;
|
||||
IEnergyReceiver handler = (IEnergyReceiver)tileEntity;
|
||||
|
||||
if(handler.canConnectEnergy(side.getOpposite()))
|
||||
{
|
||||
|
@ -317,12 +306,6 @@ public final class CableUtils
|
|||
sent += (toSend - (((IEnergySink)tileEntity).injectEnergy(side.getOpposite(), toSend*Mekanism.TO_IC2, 0)*Mekanism.FROM_IC2));
|
||||
}
|
||||
}
|
||||
else if(MekanismUtils.useBuildCraft() && MjAPI.getMjBattery(tileEntity, MjAPI.DEFAULT_POWER_FRAMEWORK, side.getOpposite()) != null && !tryAgain)
|
||||
{
|
||||
IBatteryObject battery = MjAPI.getMjBattery(tileEntity, MjAPI.DEFAULT_POWER_FRAMEWORK, side.getOpposite());
|
||||
double toSend = battery.addEnergy(Math.min(battery.getEnergyRequested(), currentSending*Mekanism.TO_BC));
|
||||
sent += toSend*Mekanism.FROM_BC;
|
||||
}
|
||||
|
||||
return sent;
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@ import mekanism.common.tile.TileEntityAdvancedBoundingBlock;
|
|||
import mekanism.common.tile.TileEntityBoundingBlock;
|
||||
import mekanism.common.tile.TileEntityDynamicTank;
|
||||
import mekanism.common.tile.TileEntityElectricChest;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
|
@ -1176,7 +1177,7 @@ public final class MekanismUtils
|
|||
case EU:
|
||||
return Math.round(energy*Mekanism.TO_IC2) + " EU";
|
||||
case MJ:
|
||||
return (Math.round((energy*Mekanism.TO_BC)*100)/100) + " MJ";
|
||||
return (Math.round((energy*Mekanism.TO_TE)*10)/100) + " MJ";
|
||||
}
|
||||
|
||||
return "error";
|
||||
|
|
|
@ -11,6 +11,7 @@ import mekanism.common.ILogisticalTransporter;
|
|||
import mekanism.common.tile.TileEntityLogisticalSorter;
|
||||
import mekanism.common.transporter.TransporterManager;
|
||||
import mekanism.common.transporter.TransporterStack;
|
||||
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
|
@ -18,8 +19,6 @@ import net.minecraft.item.ItemBlock;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import buildcraft.api.power.IPowerReceptor;
|
||||
import buildcraft.api.power.PowerHandler.Type;
|
||||
|
||||
public final class TransporterUtils
|
||||
{
|
||||
|
@ -78,16 +77,6 @@ public final class TransporterUtils
|
|||
|
||||
ForgeDirection forgeSide = ForgeDirection.getOrientation(side).getOpposite();
|
||||
|
||||
//Immature BuildCraft inv check
|
||||
if(MekanismUtils.useBuildCraft() && inventory instanceof IPowerReceptor)
|
||||
{
|
||||
if(((IPowerReceptor)inventory).getPowerReceiver(forgeSide) != null && ((IPowerReceptor)inventory).getPowerReceiver(forgeSide).getType() == Type.MACHINE)
|
||||
{
|
||||
connectable[side] = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if(inventory.getSizeInventory() > 0)
|
||||
{
|
||||
if(inventory instanceof ISidedInventory)
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue