Fixed OpenComputers support

Fixed Transporter, ChunkLoader, EnergyBank, EnanReactorCore and
LaserTreeFarm crahsing OC computer when CC isn't loaded
Added OpenComputers callbacks to Enantiomorphic reactor
This commit is contained in:
LemADEC 2015-09-05 00:43:35 +02:00
parent 940c803e8a
commit 71006f32b7
6 changed files with 112 additions and 43 deletions

View file

@ -2,6 +2,7 @@ package cr0s.warpdrive.block;
import java.util.Map; import java.util.Map;
import cpw.mods.fml.common.Optional;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.ChunkCoordIntPair; import net.minecraft.world.ChunkCoordIntPair;
import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.Chunk;
@ -144,6 +145,7 @@ public class TileEntityChunkLoader extends TileEntityAbstractChunkLoading implem
} }
@Override @Override
@Optional.Method(modid = "ComputerCraft")
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) { public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) {
String meth = methodsArray[method]; String meth = methodsArray[method];

View file

@ -2,6 +2,7 @@ package cr0s.warpdrive.block.collection;
import java.util.LinkedList; import java.util.LinkedList;
import cpw.mods.fml.common.Optional;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
@ -243,6 +244,7 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
// ComputerCraft IPeripheral methods implementation // ComputerCraft IPeripheral methods implementation
@Override @Override
@Optional.Method(modid = "ComputerCraft")
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) { public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) {
String methodName = methodsArray[method]; String methodName = methodsArray[method];
if (methodName.equals("start")) { if (methodName.equals("start")) {

View file

@ -2,11 +2,15 @@ package cr0s.warpdrive.block.energy;
import java.util.Arrays; import java.util.Arrays;
import li.cil.oc.api.machine.Arguments;
import li.cil.oc.api.machine.Callback;
import li.cil.oc.api.machine.Context;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Optional;
import cr0s.warpdrive.WarpDrive; import cr0s.warpdrive.WarpDrive;
import cr0s.warpdrive.api.IBlockUpdateDetector; import cr0s.warpdrive.api.IBlockUpdateDetector;
import cr0s.warpdrive.block.TileEntityAbstractEnergy; import cr0s.warpdrive.block.TileEntityAbstractEnergy;
@ -16,33 +20,33 @@ import dan200.computercraft.api.peripheral.IComputerAccess;
public class TileEntityEnanReactorCore extends TileEntityAbstractEnergy implements IBlockUpdateDetector { public class TileEntityEnanReactorCore extends TileEntityAbstractEnergy implements IBlockUpdateDetector {
private int containedEnergy = 0; private int containedEnergy = 0;
// generation & instability is 'per tick' // generation & instability is 'per tick'
private static final int PR_MIN_GENERATION = 4; private static final int PR_MIN_GENERATION = 4;
private static final int PR_MAX_GENERATION = 64000; private static final int PR_MAX_GENERATION = 64000;
private static final double PR_MIN_INSTABILITY = 0.004D; private static final double PR_MIN_INSTABILITY = 0.004D;
private static final double PR_MAX_INSTABILITY = 0.060D; private static final double PR_MAX_INSTABILITY = 0.060D;
// explosion parameters // explosion parameters
private static final int PR_MAX_EXPLOSION_RADIUS = 6; private static final int PR_MAX_EXPLOSION_RADIUS = 6;
private static final double PR_MAX_EXPLOSION_REMOVAL_CHANCE = 0.1D; private static final double PR_MAX_EXPLOSION_REMOVAL_CHANCE = 0.1D;
// laser stabilization is per shot // laser stabilization is per shot
// target is to consume 10% max output power every second, hence 2.5% per side // target is to consume 10% max output power every second, hence 2.5% per side
// laser efficiency is 33% at 16% power (target spot), 50% at 24% power, 84% at 50% power, etc. // laser efficiency is 33% at 16% power (target spot), 50% at 24% power, 84% at 50% power, etc.
// 10% * 20 * PR_MAX_GENERATION / (4 * 0.16) => ~200kRF => ~ max laser energy // 10% * 20 * PR_MAX_GENERATION / (4 * 0.16) => ~200kRF => ~ max laser energy
private static final double PR_MAX_LASER_ENERGY = 200000.0D; private static final double PR_MAX_LASER_ENERGY = 200000.0D;
private static final double PR_MAX_LASER_EFFECT = PR_MAX_INSTABILITY * 20 / 0.33D; private static final double PR_MAX_LASER_EFFECT = PR_MAX_INSTABILITY * 20 / 0.33D;
private int tickCount = 0; private int tickCount = 0;
private double[] instabilityValues = { 0.0D, 0.0D, 0.0D, 0.0D }; // no instability = 0, explosion = 100 private double[] instabilityValues = { 0.0D, 0.0D, 0.0D, 0.0D }; // no instability = 0, explosion = 100
private float lasersReceived = 0; private float lasersReceived = 0;
private int lastGenerationRate = 0; private int lastGenerationRate = 0;
private int releasedThisTick = 0; // amount of energy released during current tick update private int releasedThisTick = 0; // amount of energy released during current tick update
private int releasedThisCycle = 0; // amount of energy released during current cycle private int releasedThisCycle = 0; // amount of energy released during current cycle
private int releasedLastCycle = 0; private int releasedLastCycle = 0;
private boolean hold = true; // hold updates and power output until reactor is controlled (i.e. don't explode on chunk-loading while computer is booting) private boolean hold = true; // hold updates and power output until reactor is controlled (i.e. don't explode on chunk-loading while computer is booting)
private boolean active = false; private boolean active = false;
private static final int MODE_DONT_RELEASE = 0; private static final int MODE_DONT_RELEASE = 0;
@ -53,9 +57,9 @@ public class TileEntityEnanReactorCore extends TileEntityAbstractEnergy implemen
private int releaseMode = 0; private int releaseMode = 0;
private int releaseRate = 0; private int releaseRate = 0;
private int releaseAbove = 0; private int releaseAbove = 0;
private boolean init = false; private boolean init = false;
public TileEntityEnanReactorCore() { public TileEntityEnanReactorCore() {
super(); super();
peripheralName = "warpdriveEnanReactorCore"; peripheralName = "warpdriveEnanReactorCore";
@ -70,12 +74,12 @@ public class TileEntityEnanReactorCore extends TileEntityAbstractEnergy implemen
}; };
CC_scripts = Arrays.asList("startup"); CC_scripts = Arrays.asList("startup");
} }
private void increaseInstability(ForgeDirection from, boolean isNatural) { private void increaseInstability(ForgeDirection from, boolean isNatural) {
if (canOutputEnergy(from) || hold) { if (canOutputEnergy(from) || hold) {
return; return;
} }
int side = from.ordinal() - 2; int side = from.ordinal() - 2;
if (containedEnergy > WarpDriveConfig.ENAN_REACTOR_UPDATE_INTERVAL_TICKS * PR_MIN_GENERATION * 100) { if (containedEnergy > WarpDriveConfig.ENAN_REACTOR_UPDATE_INTERVAL_TICKS * PR_MIN_GENERATION * 100) {
double amountToIncrease = WarpDriveConfig.ENAN_REACTOR_UPDATE_INTERVAL_TICKS double amountToIncrease = WarpDriveConfig.ENAN_REACTOR_UPDATE_INTERVAL_TICKS
@ -89,27 +93,27 @@ public class TileEntityEnanReactorCore extends TileEntityAbstractEnergy implemen
instabilityValues[side] = Math.max(0.0D, instabilityValues[side] - amountToDecrease); instabilityValues[side] = Math.max(0.0D, instabilityValues[side] - amountToDecrease);
} }
} }
private void increaseInstability(boolean isNatural) { private void increaseInstability(boolean isNatural) {
increaseInstability(ForgeDirection.NORTH, isNatural); increaseInstability(ForgeDirection.NORTH, isNatural);
increaseInstability(ForgeDirection.SOUTH, isNatural); increaseInstability(ForgeDirection.SOUTH, isNatural);
increaseInstability(ForgeDirection.EAST, isNatural); increaseInstability(ForgeDirection.EAST, isNatural);
increaseInstability(ForgeDirection.WEST, isNatural); increaseInstability(ForgeDirection.WEST, isNatural);
} }
public void decreaseInstability(ForgeDirection from, int energy) { public void decreaseInstability(ForgeDirection from, int energy) {
if (canOutputEnergy(from)) { if (canOutputEnergy(from)) {
return; return;
} }
// laser is active => start updating reactor // laser is active => start updating reactor
hold = false; hold = false;
int amount = convertInternalToRF(energy); int amount = convertInternalToRF(energy);
if (amount <= 1) { if (amount <= 1) {
return; return;
} }
lasersReceived = Math.min(10.0F, lasersReceived + 1F / WarpDriveConfig.ENAN_REACTOR_MAX_LASERS_PER_SECOND); lasersReceived = Math.min(10.0F, lasersReceived + 1F / WarpDriveConfig.ENAN_REACTOR_MAX_LASERS_PER_SECOND);
double nospamFactor = 1.0; double nospamFactor = 1.0;
if (lasersReceived > 1.0F) { if (lasersReceived > 1.0F) {
@ -122,9 +126,9 @@ public class TileEntityEnanReactorCore extends TileEntityAbstractEnergy implemen
double baseLaserEffect = 0.5D + 0.5D * Math.cos(Math.PI - (1.0D + Math.log10(0.1D + 0.9D * normalisedAmount)) * Math.PI); // 0.0 to 1.0 double baseLaserEffect = 0.5D + 0.5D * Math.cos(Math.PI - (1.0D + Math.log10(0.1D + 0.9D * normalisedAmount)) * Math.PI); // 0.0 to 1.0
double randomVariation = 0.8D + 0.4D * worldObj.rand.nextDouble(); // ~1.0 double randomVariation = 0.8D + 0.4D * worldObj.rand.nextDouble(); // ~1.0
double amountToRemove = PR_MAX_LASER_EFFECT * baseLaserEffect * randomVariation * nospamFactor; double amountToRemove = PR_MAX_LASER_EFFECT * baseLaserEffect * randomVariation * nospamFactor;
int side = from.ordinal() - 2; int side = from.ordinal() - 2;
if (WarpDriveConfig.LOGGING_ENERGY) { if (WarpDriveConfig.LOGGING_ENERGY) {
if (side == 3) { if (side == 3) {
WarpDrive.logger.info("Instability on " + from.toString() WarpDrive.logger.info("Instability on " + from.toString()
@ -132,18 +136,18 @@ public class TileEntityEnanReactorCore extends TileEntityAbstractEnergy implemen
+ " after consuming " + amount + "/" + PR_MAX_LASER_ENERGY + " lasersReceived is " + String.format("%.1f", lasersReceived) + " hence nospamFactor is " + nospamFactor); + " after consuming " + amount + "/" + PR_MAX_LASER_ENERGY + " lasersReceived is " + String.format("%.1f", lasersReceived) + " hence nospamFactor is " + nospamFactor);
} }
} }
instabilityValues[side] = Math.max(0, instabilityValues[side] - amountToRemove); instabilityValues[side] = Math.max(0, instabilityValues[side] - amountToRemove);
updateSideTextures(); updateSideTextures();
} }
private void generateEnergy() { private void generateEnergy() {
double stabilityOffset = 0.5; double stabilityOffset = 0.5;
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
stabilityOffset *= Math.max(0.01D, instabilityValues[i] / 100.0D); stabilityOffset *= Math.max(0.01D, instabilityValues[i] / 100.0D);
} }
if (active) {// producing, instability increase output, you want to take the risk if (active) {// producing, instability increase output, you want to take the risk
int amountToGenerate = (int) Math.ceil(WarpDriveConfig.ENAN_REACTOR_UPDATE_INTERVAL_TICKS * (0.5D + stabilityOffset) int amountToGenerate = (int) Math.ceil(WarpDriveConfig.ENAN_REACTOR_UPDATE_INTERVAL_TICKS * (0.5D + stabilityOffset)
* (PR_MIN_GENERATION + PR_MAX_GENERATION * Math.pow(containedEnergy / (double) WarpDriveConfig.ENAN_REACTOR_MAX_ENERGY_STORED, 0.6D))); * (PR_MIN_GENERATION + PR_MAX_GENERATION * Math.pow(containedEnergy / (double) WarpDriveConfig.ENAN_REACTOR_MAX_ENERGY_STORED, 0.6D)));
@ -162,21 +166,21 @@ public class TileEntityEnanReactorCore extends TileEntityAbstractEnergy implemen
} }
} }
} }
@Override @Override
public void updateEntity() { public void updateEntity() {
super.updateEntity(); super.updateEntity();
if (FMLCommonHandler.instance().getEffectiveSide().isClient()) { if (FMLCommonHandler.instance().getEffectiveSide().isClient()) {
return; return;
} }
if (WarpDriveConfig.LOGGING_ENERGY) { if (WarpDriveConfig.LOGGING_ENERGY) {
WarpDrive.logger.info("tickCount " + tickCount + " releasedThisTick " + releasedThisTick + " lasersReceived " + lasersReceived WarpDrive.logger.info("tickCount " + tickCount + " releasedThisTick " + releasedThisTick + " lasersReceived " + lasersReceived
+ " releasedThisCycle " + releasedThisCycle + " containedEnergy " + containedEnergy); + " releasedThisCycle " + releasedThisCycle + " containedEnergy " + containedEnergy);
} }
releasedThisTick = 0; releasedThisTick = 0;
lasersReceived = Math.max(0.0F, lasersReceived - 0.05F); lasersReceived = Math.max(0.0F, lasersReceived - 0.05F);
tickCount++; tickCount++;
if (tickCount < WarpDriveConfig.ENAN_REACTOR_UPDATE_INTERVAL_TICKS) { if (tickCount < WarpDriveConfig.ENAN_REACTOR_UPDATE_INTERVAL_TICKS) {
@ -185,25 +189,25 @@ public class TileEntityEnanReactorCore extends TileEntityAbstractEnergy implemen
tickCount = 0; tickCount = 0;
releasedLastCycle = releasedThisCycle; releasedLastCycle = releasedThisCycle;
releasedThisCycle = 0; releasedThisCycle = 0;
if (!init) { if (!init) {
init = true; init = true;
updatedNeighbours(); updatedNeighbours();
} }
updateSideTextures(); updateSideTextures();
// unstable at all time // unstable at all time
if (shouldExplode()) { if (shouldExplode()) {
explode(); explode();
} }
increaseInstability(true); increaseInstability(true);
generateEnergy(); generateEnergy();
sendEvent("reactorPulse", new Object[] { lastGenerationRate }); sendEvent("reactorPulse", new Object[] { lastGenerationRate });
} }
private void explode() { private void explode() {
// remove blocks randomly up to x blocks around (breaking whatever protection is there) // remove blocks randomly up to x blocks around (breaking whatever protection is there)
double normalizedEnergy = containedEnergy / (double) WarpDriveConfig.ENAN_REACTOR_MAX_ENERGY_STORED; double normalizedEnergy = containedEnergy / (double) WarpDriveConfig.ENAN_REACTOR_MAX_ENERGY_STORED;
@ -236,7 +240,7 @@ public class TileEntityEnanReactorCore extends TileEntityAbstractEnergy implemen
4.0F + worldObj.rand.nextInt(3), true, true); 4.0F + worldObj.rand.nextInt(3), true, true);
} }
} }
private void updateSideTextures() { private void updateSideTextures() {
double maxInstability = 0.0D; double maxInstability = 0.0D;
for (Double ins : instabilityValues) { for (Double ins : instabilityValues) {
@ -246,20 +250,20 @@ public class TileEntityEnanReactorCore extends TileEntityAbstractEnergy implemen
} }
int instabilityNibble = (int) Math.max(0, Math.min(3, Math.round(maxInstability / 25.0D))); int instabilityNibble = (int) Math.max(0, Math.min(3, Math.round(maxInstability / 25.0D)));
int energyNibble = (int) Math.max(0, Math.min(3, Math.round(4.0D * containedEnergy / WarpDriveConfig.ENAN_REACTOR_MAX_ENERGY_STORED))); int energyNibble = (int) Math.max(0, Math.min(3, Math.round(4.0D * containedEnergy / WarpDriveConfig.ENAN_REACTOR_MAX_ENERGY_STORED)));
int metadata = 4 * instabilityNibble + energyNibble; int metadata = 4 * instabilityNibble + energyNibble;
if (getBlockMetadata() != metadata) { if (getBlockMetadata() != metadata) {
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, metadata, 3); worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, metadata, 3);
} }
} }
private boolean shouldExplode() { private boolean shouldExplode() {
boolean exploding = false; boolean exploding = false;
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
exploding = exploding || (instabilityValues[i] >= 100); exploding = exploding || (instabilityValues[i] >= 100);
} }
exploding &= (worldObj.rand.nextInt(4) == 2); exploding &= (worldObj.rand.nextInt(4) == 2);
if (exploding) { if (exploding) {
WarpDrive.logger.info(this WarpDrive.logger.info(this
+ String.format(" Explosion trigerred, Instability is [%.2f, %.2f, %.2f, %.2f], Energy stored is %d, Laser received is %.2f, %s", + String.format(" Explosion trigerred, Instability is [%.2f, %.2f, %.2f, %.2f], Energy stored is %d, Laser received is %.2f, %s",
@ -289,13 +293,19 @@ public class TileEntityEnanReactorCore extends TileEntityAbstractEnergy implemen
// OpenComputer callback methods // OpenComputer callback methods
// FIXME: implement OpenComputers... // FIXME: implement OpenComputers...
@Callback
@Optional.Method(modid = "OpenComputers")
public Object[] active(Context context, Arguments arguments) throws Exception {
return active(argumentsOCtoCC(arguments));
}
public Object[] active(Object[] arguments) throws Exception { public Object[] active(Object[] arguments) throws Exception {
if (arguments.length == 1) { if (arguments.length == 1) {
boolean activate = false; boolean activate = false;
try { try {
activate = toBool(arguments[0]); activate = toBool(arguments[0]);
} catch (Exception e) { } catch (Exception e) {
throw new Exception("Function expects an boolean value"); throw new Exception("Function expects a boolean value");
} }
if (active && !activate) { if (active && !activate) {
sendEvent("reactorDeactivation", null); sendEvent("reactorDeactivation", null);
@ -313,13 +323,19 @@ public class TileEntityEnanReactorCore extends TileEntityAbstractEnergy implemen
} }
} }
@Callback
@Optional.Method(modid = "OpenComputers")
public Object[] release(Context context, Arguments arguments) throws Exception {
return release(argumentsOCtoCC(arguments));
}
private Object[] release(Object[] arguments) throws Exception { private Object[] release(Object[] arguments) throws Exception {
boolean doRelease = false; boolean doRelease = false;
if (arguments.length > 0) { if (arguments.length > 0) {
try { try {
doRelease = toBool(arguments[0]); doRelease = toBool(arguments[0]);
} catch (Exception e) { } catch (Exception e) {
throw new Exception("Function expects an boolean value"); throw new Exception("Function expects a boolean value");
} }
releaseMode = doRelease ? MODE_MANUAL_RELEASE : MODE_DONT_RELEASE; releaseMode = doRelease ? MODE_MANUAL_RELEASE : MODE_DONT_RELEASE;
@ -329,6 +345,12 @@ public class TileEntityEnanReactorCore extends TileEntityAbstractEnergy implemen
return new Object[] { releaseMode != MODE_DONT_RELEASE }; return new Object[] { releaseMode != MODE_DONT_RELEASE };
} }
@Callback
@Optional.Method(modid = "OpenComputers")
public Object[] releaseRate(Context context, Arguments arguments) throws Exception {
return releaseRate(argumentsOCtoCC(arguments));
}
private Object[] releaseRate(Object[] arguments) throws Exception { private Object[] releaseRate(Object[] arguments) throws Exception {
int rate = -1; int rate = -1;
try { try {
@ -349,6 +371,12 @@ public class TileEntityEnanReactorCore extends TileEntityAbstractEnergy implemen
return new Object[] { MODE_STRING[releaseMode], releaseRate }; return new Object[] { MODE_STRING[releaseMode], releaseRate };
} }
@Callback
@Optional.Method(modid = "OpenComputers")
public Object[] releaseAbove(Context context, Arguments arguments) throws Exception {
return releaseAbove(argumentsOCtoCC(arguments));
}
private Object[] releaseAbove(Object[] arguments) throws Exception { private Object[] releaseAbove(Object[] arguments) throws Exception {
int above = -1; int above = -1;
try { try {
@ -368,8 +396,15 @@ public class TileEntityEnanReactorCore extends TileEntityAbstractEnergy implemen
return new Object[] { MODE_STRING[releaseMode], releaseAbove }; return new Object[] { MODE_STRING[releaseMode], releaseAbove };
} }
@Callback
@Optional.Method(modid = "OpenComputers")
public Object[] instability(Context context, Arguments arguments) throws Exception {
return new Double[] { instabilityValues[0], instabilityValues[1], instabilityValues[2], instabilityValues[3] };
}
// ComputerCraft IPeripheral methods implementation // ComputerCraft IPeripheral methods implementation
@Override @Override
@Optional.Method(modid = "ComputerCraft")
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) { public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) {
// computer is alive => start updating reactor // computer is alive => start updating reactor
hold = false; hold = false;
@ -441,7 +476,7 @@ public class TileEntityEnanReactorCore extends TileEntityAbstractEnergy implemen
} }
return false; return false;
} }
@Override @Override
protected void energyOutputDone(int energyOutput_internal) { protected void energyOutputDone(int energyOutput_internal) {
int energyOutput_RF = convertInternalToRF(energyOutput_internal); int energyOutput_RF = convertInternalToRF(energyOutput_internal);
@ -455,17 +490,17 @@ public class TileEntityEnanReactorCore extends TileEntityAbstractEnergy implemen
WarpDrive.logger.info("OutputDone " + energyOutput_internal + " (" + energyOutput_RF + " RF)"); WarpDrive.logger.info("OutputDone " + energyOutput_internal + " (" + energyOutput_RF + " RF)");
} }
} }
@Override @Override
public int getEnergyStored() { public int getEnergyStored() {
return convertRFtoInternal(containedEnergy); return convertRFtoInternal(containedEnergy);
} }
@Override @Override
public int getMaxEnergyStored() { public int getMaxEnergyStored() {
return convertRFtoInternal(WarpDriveConfig.ENAN_REACTOR_MAX_ENERGY_STORED); return convertRFtoInternal(WarpDriveConfig.ENAN_REACTOR_MAX_ENERGY_STORED);
} }
// Forge overrides // Forge overrides
@Override @Override
public void writeToNBT(NBTTagCompound nbt) { public void writeToNBT(NBTTagCompound nbt) {
@ -480,7 +515,7 @@ public class TileEntityEnanReactorCore extends TileEntityAbstractEnergy implemen
nbt.setDouble("i3", instabilityValues[3]); nbt.setDouble("i3", instabilityValues[3]);
nbt.setBoolean("active", active); nbt.setBoolean("active", active);
} }
@Override @Override
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt); super.readFromNBT(nbt);
@ -494,7 +529,7 @@ public class TileEntityEnanReactorCore extends TileEntityAbstractEnergy implemen
instabilityValues[3] = nbt.getDouble("i3"); instabilityValues[3] = nbt.getDouble("i3");
active = nbt.getBoolean("active"); active = nbt.getBoolean("active");
} }
@Override @Override
public String toString() { public String toString() {
return String.format("%s \'%s\' @ \'%s\' %.2f, %.2f, %.2f", new Object[] { return String.format("%s \'%s\' @ \'%s\' %.2f, %.2f, %.2f", new Object[] {

View file

@ -1,5 +1,8 @@
package cr0s.warpdrive.block.energy; package cr0s.warpdrive.block.energy;
import li.cil.oc.api.machine.Arguments;
import li.cil.oc.api.machine.Callback;
import li.cil.oc.api.machine.Context;
import cpw.mods.fml.common.Optional; import cpw.mods.fml.common.Optional;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
@ -148,6 +151,29 @@ public class TileEntityEnanReactorLaser extends TileEntityAbstractLaser implemen
super.readFromNBT(nbt); super.readFromNBT(nbt);
} }
// OpenComputers callback methods
@Callback
@Optional.Method(modid = "OpenComputers")
public Object[] hasReactor(Context context, Arguments arguments) {
return new Object[] { scanForReactor() != null };
}
@Callback
@Optional.Method(modid = "OpenComputers")
public Object[] sendLaser(Context context, Arguments arguments) {
if (arguments.count() >= 1) {
laserReactor(arguments.checkInteger(0));
}
return null;
}
@Callback
@Optional.Method(modid = "OpenComputers")
public Object[] side(Context context, Arguments arguments) {
return new Object[] { side.ordinal() - 2 };
}
// ComputerCraft methods // ComputerCraft methods
@Override @Override
@Optional.Method(modid = "ComputerCraft") @Optional.Method(modid = "ComputerCraft")

View file

@ -1,5 +1,6 @@
package cr0s.warpdrive.block.energy; package cr0s.warpdrive.block.energy;
import cpw.mods.fml.common.Optional;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import cr0s.warpdrive.block.TileEntityAbstractEnergy; import cr0s.warpdrive.block.TileEntityAbstractEnergy;
import cr0s.warpdrive.config.WarpDriveConfig; import cr0s.warpdrive.config.WarpDriveConfig;
@ -45,6 +46,7 @@ public class TileEntityEnergyBank extends TileEntityAbstractEnergy {
// ComputerCraft IPeripheral methods implementation // ComputerCraft IPeripheral methods implementation
@Override @Override
@Optional.Method(modid = "ComputerCraft")
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) { public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) {
String methodName = methodsArray[method]; String methodName = methodsArray[method];
if (methodName == "getEnergyLevel") { if (methodName == "getEnergyLevel") {

View file

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import cpw.mods.fml.common.Optional;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
@ -138,6 +139,7 @@ public class TileEntityTransporter extends TileEntityAbstractEnergy implements I
} }
@Override @Override
@Optional.Method(modid = "ComputerCraft")
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) { public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) {
String methodName = methodsArray[method]; String methodName = methodsArray[method];
if (methodName.equals("getEnergyLevel")) { if (methodName.equals("getEnergyLevel")) {