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:
parent
940c803e8a
commit
71006f32b7
6 changed files with 112 additions and 43 deletions
|
@ -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];
|
||||||
|
|
||||||
|
|
|
@ -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")) {
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -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;
|
||||||
|
|
|
@ -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")
|
||||||
|
|
|
@ -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") {
|
||||||
|
|
|
@ -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")) {
|
||||||
|
|
Loading…
Reference in a new issue