Adding OpenComputer support & API cleanup
Adding OpenComputer callbacks Removed unused scanRay method in Radar API Updated CloakingDeviceCore API: - "enable" replaces enableCloakingField, disableCloakingField and isEnabled Updated Controller API: - dim_positive replaces dim_getp and dim_setp - dim_negative replaces dim_getn and dim_setn - mode replaces set_mode - distance replaces set_distance - direction replaces set_direction - getAttachedPlayers replaces get_attached_players with string and list - summon now returns true on sucess instead of null, false on failure instead of -1 - pos replaces get_x, get_y, get_z - getEnergyLevel replaces get_energy_level and get_energy_max - getEnergyRequired replaces get_energy_required - jump replaces do_jump - getShipSize replaces get_ship_size - beaconFrequency replaces set_beacon_frequency - getOrientation replaces get_dx and get_dz - coreFrequency replaces set_core_frequency - isInSpace replaces is_in_space - isInHyperspace replaces is_in_hyperspace - targetJumpgate replaces set_target_jumpgate Renamed setFieldTier to tier in CloakingDeviceCore API Renamed energy to getEnergyLevel in Lift and ShipScanner APIs Updated all APIs to return current and max energy from getEnergyLevel method Added state to ShipScanner API
This commit is contained in:
parent
e01d4c9d05
commit
0dbe78e797
16 changed files with 827 additions and 437 deletions
|
@ -18,8 +18,8 @@ if warp == nil then
|
|||
term.setTextColor(colors.white)
|
||||
term.write("No cloak core detected")
|
||||
else
|
||||
warp.setFieldTier(0)
|
||||
warp.enableCloakingField()
|
||||
warp.tier(1)
|
||||
warp.enable(true)
|
||||
if warp.isAssemblyValid() then
|
||||
term.setBackgroundColor(colors.lime)
|
||||
term.setTextColor(colors.blue)
|
||||
|
|
|
@ -18,8 +18,8 @@ if warp == nil then
|
|||
term.setTextColor(colors.white)
|
||||
term.write("No cloak core detected")
|
||||
else
|
||||
warp.setFieldTier(2)
|
||||
warp.enableCloakingField()
|
||||
warp.tier(2)
|
||||
warp.enable(true)
|
||||
if warp.isAssemblyValid() then
|
||||
term.setBackgroundColor(colors.lime)
|
||||
term.setTextColor(colors.red)
|
||||
|
|
|
@ -18,7 +18,7 @@ if warp == nil then
|
|||
term.setTextColor(colors.white)
|
||||
term.write("No cloak core detected")
|
||||
else
|
||||
warp.disableCloakingField()
|
||||
warp.enable(false)
|
||||
term.setBackgroundColor(colors.lightGray)
|
||||
term.setTextColor(colors.black)
|
||||
term.write("Cloak disabled")
|
||||
|
|
|
@ -25,7 +25,8 @@ if radius < 1 or radius > 9999 then
|
|||
return
|
||||
end
|
||||
|
||||
if radar.getEnergyLevel() < radius * radius then
|
||||
energy, energyMax = radar.getEnergyLevel()
|
||||
if energy < radius * radius then
|
||||
print("Low energy level...")
|
||||
return
|
||||
end
|
||||
|
|
|
@ -60,7 +60,8 @@ function drawContact(x, y, z, name, color)
|
|||
end
|
||||
|
||||
function scanAndDraw()
|
||||
if (radar.getEnergyLevel() < radius*radius) then
|
||||
local energy, energyMax = radar.getEnergyLevel()
|
||||
if (energy < radius*radius) then
|
||||
hh = math.floor(h / 2);
|
||||
hw = math.floor(w / 2);
|
||||
|
||||
|
@ -101,7 +102,8 @@ function redraw()
|
|||
textOut(w - 3, 1, "[X]", colors.white, colors.red)
|
||||
|
||||
paintutils.drawLine(1, h, w, h, colors.black);
|
||||
textOut(4, h, "Energy: " .. radar.getEnergyLevel() .. " Eu | Scan radius: " .. radius, colors.white, colors.black)
|
||||
local energy, energyMax = radar.getEnergyLevel()
|
||||
textOut(4, h, "Energy: " .. energy .. " EU | Scan radius: " .. radius, colors.white, colors.black)
|
||||
end
|
||||
|
||||
mrun = true
|
||||
|
|
|
@ -139,8 +139,7 @@ function CalcNewCoords(cx, cy, cz)
|
|||
elseif SData.Direction == 2 then
|
||||
res.y = res.y - RealDistance
|
||||
end
|
||||
local dx = warp.get_dx()
|
||||
local dz = warp.get_dz()
|
||||
local dx, dy, dz = warp.getOrientation()
|
||||
if dx ~= 0 then
|
||||
if SData.Direction == 0 then
|
||||
res.x = res.x + (RealDistance * dx)
|
||||
|
@ -169,14 +168,10 @@ function ShowInfo()
|
|||
ShowTitle(Title)
|
||||
Show("Core:")
|
||||
Show(" x, y, z = "..X..", "..Y..", "..Z)
|
||||
local energy = warp.get_energy_level()
|
||||
local energyMax = 100000000
|
||||
if warp.get_energy_max ~= nil then
|
||||
energyMax = warp.get_energy_max()
|
||||
if energyMax == nil then energyMax = 1 end
|
||||
end
|
||||
Show(" Energy = "..math.floor(100 * energy / energyMax).." % ("..energy.."EU)")
|
||||
Show(" Attached players = "..warp.get_attached_players())
|
||||
local energy, energyMax = warp.getEnergyLevel()
|
||||
Show(" Energy = " .. math.floor(100 * energy / energyMax) .. " % (" .. energy .. "EU)")
|
||||
local playersString, playersArray = warp.getAttachedPlayers()
|
||||
Show(" Attached players = " .. playersString)
|
||||
Show("Dimensions:")
|
||||
Show(" Front, Right, Up = "..GFront..", "..GRight..", "..GUp)
|
||||
Show(" Back, Left, Down = "..GBack..", "..GLeft..", "..GDown)
|
||||
|
@ -206,13 +201,13 @@ end
|
|||
function Warp()
|
||||
rs.setOutput(Alarm, false)
|
||||
sleep(1)
|
||||
warp.set_direction(SData.Direction)
|
||||
warp.direction(SData.Direction)
|
||||
if IsInHyper then
|
||||
warp.set_mode(2)
|
||||
warp.mode(2)
|
||||
else
|
||||
warp.set_mode(1)
|
||||
warp.mode(1)
|
||||
end
|
||||
warp.do_jump()
|
||||
warp.jump()
|
||||
end
|
||||
|
||||
function SetDistance()
|
||||
|
@ -238,7 +233,7 @@ function SetDistance()
|
|||
if not IsInHyper then
|
||||
SData.Distance = SData.Distance - RealDistance
|
||||
end
|
||||
warp.set_distance(SData.Distance)
|
||||
warp.distance(SData.Distance)
|
||||
CalcRealDistance()
|
||||
end
|
||||
end
|
||||
|
@ -291,17 +286,17 @@ function SetDimensions()
|
|||
term.write(" Down ("..GDown..") : ")
|
||||
GDown = tonumber(read())
|
||||
term.write("Setting dimensions...")
|
||||
warp.dim_setp(GFront, GRight, GUp)
|
||||
warp.dim_setn(GBack, GLeft, GDown)
|
||||
Weight = warp.get_ship_size()
|
||||
warp.dim_positive(GFront, GRight, GUp)
|
||||
warp.dim_negative(GBack, GLeft, GDown)
|
||||
Weight = warp.getShipSize()
|
||||
end
|
||||
|
||||
function Summon()
|
||||
Clear()
|
||||
ShowTitle("<==== Summon players ====>")
|
||||
local players = Explode(",", warp.get_attached_players())
|
||||
for i = 1, #players do
|
||||
Show(i..". "..players[i])
|
||||
local playersString, playersArray = warp.getAttachedPlayers()
|
||||
for i = 1, #playersArray do
|
||||
Show(i..". "..playersArray[i])
|
||||
end
|
||||
SetColorTitle()
|
||||
ShowMenu("Enter player number")
|
||||
|
@ -311,7 +306,7 @@ function Summon()
|
|||
term.write(":")
|
||||
local input = read()
|
||||
if input == "" then
|
||||
warp.summon_all()
|
||||
warp.summonAll()
|
||||
else
|
||||
input = tonumber(input)
|
||||
warp.summon(input - 1)
|
||||
|
@ -327,9 +322,9 @@ function JumpToBeacon()
|
|||
rs.setOutput(Alarm, true)
|
||||
if Confirm() then
|
||||
rs.setOutput(Alarm, false)
|
||||
warp.set_mode(4)
|
||||
warp.set_beacon_frequency(freq)
|
||||
warp.do_jump()
|
||||
warp.mode(4)
|
||||
warp.beaconFrequency(freq)
|
||||
warp.jump()
|
||||
end
|
||||
rs.setOutput(Alarm, false)
|
||||
end
|
||||
|
@ -343,9 +338,9 @@ function JumpToGate()
|
|||
rs.setOutput(Alarm, true)
|
||||
if Confirm() then
|
||||
rs.setOutput(Alarm, false)
|
||||
warp.set_mode(6)
|
||||
warp.set_target_jumpgate(name)
|
||||
warp.do_jump()
|
||||
warp.mode(6)
|
||||
warp.targetJumpgate(name)
|
||||
warp.jump()
|
||||
end
|
||||
rs.setOutput(Alarm, false)
|
||||
end
|
||||
|
@ -357,7 +352,7 @@ function SetShipName()
|
|||
term.write("Enter ship name: ")
|
||||
SData.Shipname = tostring(read())
|
||||
os.setComputerLabel(SData.Shipname)
|
||||
warp.set_core_frequency(SData.Shipname)
|
||||
warp.coreFrequency(SData.Shipname)
|
||||
SaveData()
|
||||
os.reboot()
|
||||
end
|
||||
|
@ -398,31 +393,30 @@ end
|
|||
Title = "<JumpShip \""..SData.Shipname.."\">"
|
||||
|
||||
if SData.Summon then
|
||||
warp.summon_all()
|
||||
warp.summonAll()
|
||||
end
|
||||
|
||||
GFront, GRight, GUp = warp.dim_getp()
|
||||
GBack, GLeft, GDown = warp.dim_getn()
|
||||
IsInHyper = warp.is_in_hyperspace()
|
||||
GFront, GRight, GUp = warp.dim_positive()
|
||||
GBack, GLeft, GDown = warp.dim_negative()
|
||||
IsInHyper = warp.isInHyperspace()
|
||||
repeat
|
||||
X = warp.get_x()
|
||||
pos = warp.pos()
|
||||
sleep(0.3)
|
||||
until X ~= nil
|
||||
Y = warp.get_y()
|
||||
Z = warp.get_z()
|
||||
until pos ~= nil
|
||||
X, Y, Z = warp.pos()
|
||||
repeat
|
||||
isAttached = warp.isAttached()
|
||||
sleep(0.3)
|
||||
until isAttached ~= false
|
||||
|
||||
repeat
|
||||
Weight = warp.get_ship_size()
|
||||
Weight = warp.getShipSize()
|
||||
sleep(0.3)
|
||||
until Weight ~= nil
|
||||
|
||||
CalcRealDistance()
|
||||
|
||||
warp.set_mode(1)
|
||||
warp.mode(1)
|
||||
|
||||
mainloop = true
|
||||
while(mainloop) do
|
||||
|
@ -466,8 +460,8 @@ while(mainloop) do
|
|||
rs.setOutput(Alarm, true)
|
||||
if Confirm() then
|
||||
rs.setOutput(Alarm, false)
|
||||
warp.set_mode(5)
|
||||
warp.do_jump()
|
||||
warp.mode(5)
|
||||
warp.jump()
|
||||
end
|
||||
rs.setOutput(Alarm, false)
|
||||
elseif keycode == 45 then
|
||||
|
@ -483,6 +477,6 @@ if SData.Summon then
|
|||
end
|
||||
Clear()
|
||||
print("wish you good")
|
||||
warp.set_mode(0)
|
||||
warp.mode(0)
|
||||
sleep(0.5)
|
||||
os.shutdown()
|
|
@ -120,7 +120,7 @@ public class WarpDrive implements LoadingCallback {
|
|||
public static WarpDrivePeripheralHandler peripheralHandler = new WarpDrivePeripheralHandler();
|
||||
|
||||
public static String defHelpStr = "help(\"functionName\"): returns help for the function specified";
|
||||
public static String defEnergyStr = "energy(): returns currently contained energy, max contained energy";
|
||||
public static String defEnergyStr = "getEnergyLevel(): returns currently contained energy, max contained energy";
|
||||
public static String defUpgradeStr = "upgrades(): returns a list of currently installed upgrades";
|
||||
|
||||
@EventHandler
|
||||
|
|
|
@ -9,6 +9,9 @@ import dan200.computercraft.api.lua.ILuaContext;
|
|||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
|
||||
import li.cil.oc.api.network.Arguments;
|
||||
import li.cil.oc.api.network.Callback;
|
||||
import li.cil.oc.api.network.Context;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
@ -92,6 +95,16 @@ public class TileEntityCamera extends WarpInterfacedTE {
|
|||
// WarpDrive.debugPrint("" + this + " writeToNBT");
|
||||
}
|
||||
|
||||
// OpenComputer callback methods
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
private Object[] freq(Context context, Arguments arguments) {
|
||||
if (arguments.count() == 1) {
|
||||
setFrequency(arguments.checkInteger(0));
|
||||
}
|
||||
return new Integer[] { frequency };
|
||||
}
|
||||
|
||||
// ComputerCraft IPeripheral methods implementation
|
||||
@Override
|
||||
@Optional.Method(modid = "ComputerCraft")
|
||||
|
|
|
@ -13,6 +13,9 @@ import java.io.ByteArrayOutputStream;
|
|||
import java.io.DataOutputStream;
|
||||
import java.util.List;
|
||||
|
||||
import li.cil.oc.api.network.Arguments;
|
||||
import li.cil.oc.api.network.Callback;
|
||||
import li.cil.oc.api.network.Context;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
@ -44,12 +47,10 @@ public class TileEntityCloakingDeviceCore extends WarpEnergyTE {
|
|||
public TileEntityCloakingDeviceCore() {
|
||||
peripheralName = "cloakingdevicecore";
|
||||
methodsArray = new String[] {
|
||||
"setFieldTier", // 0 setFieldTier(1 or 2)
|
||||
"isAssemblyValid", // 1 - returns true or false
|
||||
"getEnergyLevel", // 2
|
||||
"enableCloakingField", // 3 enables field if assembled right
|
||||
"disableCloakingField", // 4 disables cloaking field
|
||||
"isEnabled" // 5 return true if currently enabled
|
||||
"tier", // set field tier to 1 or 2, return field tier
|
||||
"isAssemblyValid", // returns true or false
|
||||
"getEnergyLevel",
|
||||
"enable" // set field enable state (true or false), return true if enabled
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -398,6 +399,35 @@ public class TileEntityCloakingDeviceCore extends WarpEnergyTE {
|
|||
return true;
|
||||
}
|
||||
|
||||
// OpenComputer callback methods
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
private Object[] tier(Context context, Arguments arguments) {
|
||||
if (arguments.count() == 1) {
|
||||
if (arguments.checkInteger(0) == 2) {
|
||||
tier = 2;
|
||||
} else {
|
||||
tier = 1;
|
||||
}
|
||||
}
|
||||
return new Integer[] { (int)tier };
|
||||
}
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
private Object[] isAssemblyValid(Context context, Arguments arguments) {
|
||||
return new Object[] { (boolean)validateAssembly() };
|
||||
}
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
private Object[] enable(Context context, Arguments arguments) {
|
||||
if (arguments.count() == 1) {
|
||||
isEnabled = arguments.checkBoolean(0);
|
||||
}
|
||||
return new Object[] { isEnabled };
|
||||
}
|
||||
|
||||
// ComputerCraft IPeripheral methods implementation
|
||||
@Override
|
||||
@Optional.Method(modid = "ComputerCraft")
|
||||
|
@ -418,7 +448,7 @@ public class TileEntityCloakingDeviceCore extends WarpEnergyTE {
|
|||
@Optional.Method(modid = "ComputerCraft")
|
||||
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception {
|
||||
String methodName = methodsArray[method];
|
||||
if (methodName.equals("setFieldTier")) { // setFieldTier(1 or 2)
|
||||
if (methodName.equals("tier")) {
|
||||
if (arguments.length == 1) {
|
||||
if (toInt(arguments[0]) == 2) {
|
||||
tier = 2;
|
||||
|
@ -426,16 +456,19 @@ public class TileEntityCloakingDeviceCore extends WarpEnergyTE {
|
|||
tier = 1;
|
||||
}
|
||||
}
|
||||
return new Integer[] { (int)tier };
|
||||
|
||||
} else if (methodName.equals("isAssemblyValid")) {
|
||||
return new Object[] { (boolean)validateAssembly() };
|
||||
|
||||
} else if (methodName.equals("getEnergyLevel")) {
|
||||
return new Object[] { getEnergyStored() };
|
||||
} else if (methodName.equals("enableCloakingField")) {
|
||||
isEnabled = true;
|
||||
} else if (methodName.equals("disableCloakingField")) {
|
||||
isEnabled = false;
|
||||
} else if (methodName.equals("isEnabled")) {
|
||||
return new Object[] { this.isEnabled };
|
||||
return getEnergyLevel();
|
||||
|
||||
} else if (methodName.equals("enable")) {
|
||||
if (arguments.length == 1) {
|
||||
isEnabled = toBool(arguments[0]);
|
||||
}
|
||||
return new Object[] { isEnabled };
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
|
@ -5,6 +5,9 @@ import cpw.mods.fml.common.Optional;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import li.cil.oc.api.network.Arguments;
|
||||
import li.cil.oc.api.network.Callback;
|
||||
import li.cil.oc.api.network.Context;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
|
@ -31,7 +34,7 @@ public class TileEntityLift extends WarpEnergyTE {
|
|||
public TileEntityLift() {
|
||||
peripheralName = "warpdriveLaserLift";
|
||||
methodsArray = new String[] {
|
||||
"energy",
|
||||
"getEnergyLevel",
|
||||
"mode",
|
||||
"active",
|
||||
"help"
|
||||
|
@ -162,10 +165,47 @@ public class TileEntityLift extends WarpEnergyTE {
|
|||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
// OpenComputer callback methods
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
private Object[] mode(Context context, Arguments arguments) {
|
||||
return mode(argumentsOCtoCC(arguments));
|
||||
}
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
private Object[] active(Context context, Arguments arguments) {
|
||||
if (arguments.count() == 1) {
|
||||
computerEnabled = arguments.checkBoolean(0);
|
||||
}
|
||||
return new Object[] { computerEnabled ? false : isEnabled };
|
||||
}
|
||||
|
||||
private Object[] mode(Object[] arguments) {
|
||||
if (arguments.length == 1) {
|
||||
if (arguments[0].toString().equals("up")) {
|
||||
computerMode = MODE_UP;
|
||||
} else if(arguments[0].toString().equals("down")) {
|
||||
computerMode = MODE_DOWN;
|
||||
} else {
|
||||
computerMode = MODE_REDSTONE;
|
||||
}
|
||||
}
|
||||
switch (computerMode) {
|
||||
case -1:
|
||||
return new Object[] { "redstone" };
|
||||
case 1:
|
||||
return new Object[] { "up" };
|
||||
case 2:
|
||||
return new Object[] { "down" };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String helpStr(Object[] args) {
|
||||
if (args.length == 1) {
|
||||
String methodName = args[0].toString().toLowerCase();
|
||||
if (methodName.equals("energy")) {
|
||||
if (methodName.equals("getEnergyLevel")) {
|
||||
return WarpDrive.defEnergyStr;
|
||||
} else if (methodName.equals("mode")) {
|
||||
return "mode(\"up\" or \"down\" or \"redstone\"): sets the mode\nmode(): returns the current mode";
|
||||
|
@ -181,31 +221,18 @@ public class TileEntityLift extends WarpEnergyTE {
|
|||
@Optional.Method(modid = "ComputerCraft")
|
||||
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] args) throws Exception {
|
||||
String methodName = methodsArray[method];
|
||||
if (methodName.equals("energy")) {
|
||||
return getEnergyObject();
|
||||
if (methodName.equals("getEnergyLevel")) {
|
||||
return getEnergyLevel();
|
||||
|
||||
} else if (methodName.equals("mode")) {
|
||||
if (args.length == 1) {
|
||||
if (args[0].toString().equals("up")) {
|
||||
computerMode = MODE_UP;
|
||||
} else if(args[0].toString().equals("down")) {
|
||||
computerMode = MODE_DOWN;
|
||||
} else {
|
||||
computerMode = MODE_REDSTONE;
|
||||
}
|
||||
}
|
||||
switch (computerMode) {
|
||||
case -1:
|
||||
return new Object[] { "redstone" };
|
||||
case 1:
|
||||
return new Object[] { "up" };
|
||||
case 2:
|
||||
return new Object[] { "down" };
|
||||
}
|
||||
return mode(args);
|
||||
|
||||
} else if (methodName.equals("active")) {
|
||||
if (args.length == 1) {
|
||||
computerEnabled = toBool(args[0]);
|
||||
}
|
||||
return new Object[] { computerEnabled ? false : isEnabled };
|
||||
|
||||
} else if (methodName.equals("help")) {
|
||||
return new Object[] { helpStr(args) };
|
||||
}
|
||||
|
|
|
@ -9,6 +9,9 @@ import dan200.computercraft.api.lua.ILuaContext;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import li.cil.oc.api.network.Arguments;
|
||||
import li.cil.oc.api.network.Callback;
|
||||
import li.cil.oc.api.network.Context;
|
||||
import cofh.api.transport.IItemConduit;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockFluid;
|
||||
|
@ -650,6 +653,94 @@ public class TileEntityMiningLaser extends WarpInterfacedTE implements IGridMach
|
|||
tag.setInteger("currentLayer", currentLayer);
|
||||
tag.setBoolean("enableSilktouch", enableSilktouch);
|
||||
}
|
||||
|
||||
// OpenComputer callback methods
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
private Object[] mine(Context context, Arguments arguments) {
|
||||
return mine(argumentsOCtoCC(arguments));
|
||||
}
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
private Object[] stop(Context context, Arguments arguments) {
|
||||
stop();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
private Object[] isMining(Context context, Arguments arguments) {
|
||||
return new Boolean[] { isMining() };
|
||||
}
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
private Object[] quarry(Context context, Arguments arguments) {
|
||||
return quarry(argumentsOCtoCC(arguments));
|
||||
}
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
private Object[] state(Context context, Arguments arguments) {
|
||||
return state(argumentsOCtoCC(arguments));
|
||||
}
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
private Object[] offset(Context context, Arguments arguments) {
|
||||
return offset(argumentsOCtoCC(arguments));
|
||||
}
|
||||
|
||||
private Object[] mine(Object[] arguments) {
|
||||
if (isMining()) {
|
||||
return new Boolean[] { false };
|
||||
}
|
||||
|
||||
isQuarry = false;
|
||||
delayTicksWarmup = 0;
|
||||
currentState = STATE_WARMUP;
|
||||
currentLayer = yCoord - layerOffset - 1;
|
||||
enableSilktouch = (arguments.length == 1 && (WarpDriveConfig.ML_DEUTERIUM_MUL_SILKTOUCH <= 0 || FluidRegistry.isFluidRegistered("deuterium")));
|
||||
return new Boolean[] { true };
|
||||
}
|
||||
|
||||
private Object[] quarry(Object[] arguments) {
|
||||
if (isMining()) {
|
||||
return new Boolean[] { false };
|
||||
}
|
||||
|
||||
isQuarry = true;
|
||||
delayTicksScan = 0;
|
||||
currentState = STATE_WARMUP;
|
||||
currentLayer = yCoord - layerOffset - 1;
|
||||
enableSilktouch = (arguments.length == 1 && (WarpDriveConfig.ML_DEUTERIUM_MUL_SILKTOUCH <= 0 || FluidRegistry.isFluidRegistered("deuterium")));
|
||||
return new Boolean[] { true };
|
||||
}
|
||||
|
||||
private Object[] state(Object[] arguments) {
|
||||
int energy = getEnergyLevel();
|
||||
String status = getStatus();
|
||||
Integer retValuablesInLayer, retValuablesMined;
|
||||
if (isMining()) {
|
||||
retValuablesInLayer = valuablesInLayer.size();
|
||||
retValuablesMined = valuableIndex;
|
||||
|
||||
return new Object[] {status, energy, currentLayer, retValuablesMined, retValuablesInLayer};
|
||||
}
|
||||
return new Object[] {status, energy, currentLayer, 0, 0};
|
||||
}
|
||||
|
||||
private Object[] offset(Object[] arguments) {
|
||||
if (arguments.length == 1) {
|
||||
try {
|
||||
layerOffset = Math.min(256, Math.abs(toInt(arguments[0])));
|
||||
} catch(Exception e) {
|
||||
return new Integer[] { layerOffset };
|
||||
}
|
||||
}
|
||||
return new Integer[] { layerOffset };
|
||||
}
|
||||
|
||||
// ComputerCraft IPeripheral methods implementation
|
||||
@Override
|
||||
|
@ -669,16 +760,7 @@ public class TileEntityMiningLaser extends WarpInterfacedTE implements IGridMach
|
|||
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception {
|
||||
String methodName = methodsArray[method];
|
||||
if (methodName.equals("mine")) {
|
||||
if (isMining()) {
|
||||
return new Boolean[] { false };
|
||||
}
|
||||
|
||||
isQuarry = false;
|
||||
delayTicksWarmup = 0;
|
||||
currentState = STATE_WARMUP;
|
||||
currentLayer = yCoord - layerOffset - 1;
|
||||
enableSilktouch = (arguments.length == 1 && (WarpDriveConfig.ML_DEUTERIUM_MUL_SILKTOUCH <= 0 || FluidRegistry.isFluidRegistered("deuterium")));
|
||||
return new Boolean[] { true };
|
||||
return mine(arguments);
|
||||
|
||||
} else if (methodName.equals("stop")) {
|
||||
stop();
|
||||
|
@ -687,38 +769,13 @@ public class TileEntityMiningLaser extends WarpInterfacedTE implements IGridMach
|
|||
return new Boolean[] { isMining() };
|
||||
|
||||
} else if (methodName.equals("quarry")) {
|
||||
if (isMining()) {
|
||||
return new Boolean[] { false };
|
||||
}
|
||||
return quarry(arguments);
|
||||
|
||||
isQuarry = true;
|
||||
delayTicksScan = 0;
|
||||
currentState = STATE_WARMUP;
|
||||
currentLayer = yCoord - layerOffset - 1;
|
||||
enableSilktouch = (arguments.length == 1 && (WarpDriveConfig.ML_DEUTERIUM_MUL_SILKTOUCH <= 0 || FluidRegistry.isFluidRegistered("deuterium")));
|
||||
return new Boolean[] { true };
|
||||
|
||||
} else if (methodName.equals("state")) { // State is: state, energy, currentLayer, valuablesMined, valuablesInLayer = getMinerState()
|
||||
int energy = getEnergyLevel();
|
||||
String status = getStatus();
|
||||
Integer retValuablesInLayer, retValuablesMined;
|
||||
if (isMining()) {
|
||||
retValuablesInLayer = valuablesInLayer.size();
|
||||
retValuablesMined = valuableIndex;
|
||||
|
||||
return new Object[] {status, energy, currentLayer, retValuablesMined, retValuablesInLayer};
|
||||
}
|
||||
return new Object[] {status, energy, currentLayer, 0, 0};
|
||||
return state(arguments);
|
||||
|
||||
} else if (methodName.equals("offset")) {
|
||||
if (arguments.length == 1) {
|
||||
try {
|
||||
layerOffset = Math.min(256, Math.abs(toInt(arguments[0])));
|
||||
} catch(Exception e) {
|
||||
return new Integer[] { layerOffset };
|
||||
}
|
||||
}
|
||||
return new Integer[] { layerOffset };
|
||||
return offset(arguments);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -10,6 +10,9 @@ import dan200.computercraft.api.lua.ILuaContext;
|
|||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
|
||||
import li.cil.oc.api.network.Arguments;
|
||||
import li.cil.oc.api.network.Callback;
|
||||
import li.cil.oc.api.network.Context;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
@ -65,6 +68,16 @@ public class TileEntityMonitor extends WarpInterfacedTE {
|
|||
tag.setInteger("frequency", frequency);
|
||||
}
|
||||
|
||||
// OpenComputer callback methods
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
private Object[] freq(Context context, Arguments arguments) {
|
||||
if (arguments.count() == 1) {
|
||||
setFrequency(arguments.checkInteger(0));
|
||||
}
|
||||
return new Integer[] { frequency };
|
||||
}
|
||||
|
||||
// ComputerCraft IPeripheral methods implementation
|
||||
@Override
|
||||
@Optional.Method(modid = "ComputerCraft")
|
||||
|
|
|
@ -8,6 +8,9 @@ import dan200.computercraft.api.lua.ILuaContext;
|
|||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import li.cil.oc.api.network.Arguments;
|
||||
import li.cil.oc.api.network.Callback;
|
||||
import li.cil.oc.api.network.Context;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
@ -236,7 +239,7 @@ public class TileEntityProtocol extends WarpInterfacedTE {
|
|||
* @param front new front size
|
||||
* @return front size
|
||||
*/
|
||||
public void setFront(int front) {
|
||||
private void setFront(int front) {
|
||||
this.front = front;
|
||||
}
|
||||
|
||||
|
@ -251,7 +254,7 @@ public class TileEntityProtocol extends WarpInterfacedTE {
|
|||
* @param right new right size
|
||||
* @return right size
|
||||
*/
|
||||
public void setRight(int right) {
|
||||
private void setRight(int right) {
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
|
@ -266,7 +269,7 @@ public class TileEntityProtocol extends WarpInterfacedTE {
|
|||
* @param up new up size
|
||||
* @return up size
|
||||
*/
|
||||
public void setUp(int up) {
|
||||
private void setUp(int up) {
|
||||
this.up = up;
|
||||
}
|
||||
|
||||
|
@ -281,7 +284,7 @@ public class TileEntityProtocol extends WarpInterfacedTE {
|
|||
* @param back new back size
|
||||
* @return back size
|
||||
*/
|
||||
public void setBack(int back) {
|
||||
private void setBack(int back) {
|
||||
this.back = back;
|
||||
}
|
||||
|
||||
|
@ -296,7 +299,7 @@ public class TileEntityProtocol extends WarpInterfacedTE {
|
|||
* @param left new left size
|
||||
* @return left size
|
||||
*/
|
||||
public void setLeft(int left) {
|
||||
private void setLeft(int left) {
|
||||
this.left = left;
|
||||
}
|
||||
|
||||
|
@ -311,11 +314,11 @@ public class TileEntityProtocol extends WarpInterfacedTE {
|
|||
* @param down new down size
|
||||
* @return down size
|
||||
*/
|
||||
public void setDown(int down) {
|
||||
private void setDown(int down) {
|
||||
this.down = down;
|
||||
}
|
||||
|
||||
public void setDistance(int distance) {
|
||||
private void setDistance(int distance) {
|
||||
this.distance = Math.max(1, Math.min(WarpDriveConfig.WC_MAX_JUMP_DISTANCE, distance));
|
||||
WarpDrive.debugPrint(this + " Jump distance set to " + distance);
|
||||
}
|
||||
|
@ -407,6 +410,314 @@ public class TileEntityProtocol extends WarpInterfacedTE {
|
|||
return null;
|
||||
}
|
||||
|
||||
// OpenComputer callback methods
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
private Object[] dim_positive(Context context, Arguments arguments) {
|
||||
return dim_positive(argumentsOCtoCC(arguments));
|
||||
}
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
private Object[] dim_negative(Context context, Arguments arguments) {
|
||||
return dim_negative(argumentsOCtoCC(arguments));
|
||||
}
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
private Object[] mode(Context context, Arguments arguments) {
|
||||
return mode(argumentsOCtoCC(arguments));
|
||||
}
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
private Object[] distance(Context context, Arguments arguments) {
|
||||
return distance(argumentsOCtoCC(arguments));
|
||||
}
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
private Object[] direction(Context context, Arguments arguments) {
|
||||
return direction(argumentsOCtoCC(arguments));
|
||||
}
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
private Object[] getAttachedPlayers(Context context, Arguments arguments) {
|
||||
return getAttachedPlayers(argumentsOCtoCC(arguments));
|
||||
}
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
private Object[] summon(Context context, Arguments arguments) {
|
||||
return summon(argumentsOCtoCC(arguments));
|
||||
}
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
private Object[] summon_all(Context context, Arguments arguments) {
|
||||
setSummonAllFlag(true);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
private Object[] pos(Context context, Arguments arguments) {
|
||||
if (core == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Object[] { core.xCoord, core.yCoord, core.zCoord };
|
||||
}
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
private Object[] getEnergyLevel(Context context, Arguments arguments) {
|
||||
if (core == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return core.getEnergyLevel();
|
||||
}
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
private Object[] getEnergyRequired(Context context, Arguments arguments) {
|
||||
if (core == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return core.getEnergyLevel();
|
||||
}
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
private Object[] jump(Context context, Arguments arguments) {
|
||||
doJump();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
private Object[] getShipSize(Context context, Arguments arguments) {
|
||||
return getShipSize(argumentsOCtoCC(arguments));
|
||||
}
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
private Object[] beaconFrequency(Context context, Arguments arguments) {
|
||||
return beaconFrequency(argumentsOCtoCC(arguments));
|
||||
}
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
private Object[] getOrientation(Context context, Arguments arguments) {
|
||||
if (core != null) {
|
||||
return new Object[] { core.dx, 0, core.dz };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
private Object[] coreFrequency(Context context, Arguments arguments) {
|
||||
return coreFrequency(argumentsOCtoCC(arguments));
|
||||
}
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
private Object[] isInSpace(Context context, Arguments arguments) {
|
||||
return new Boolean[] { worldObj.provider.dimensionId == WarpDriveConfig.G_SPACE_DIMENSION_ID };
|
||||
}
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
private Object[] isInHyperspace(Context context, Arguments arguments) {
|
||||
return new Boolean[] { worldObj.provider.dimensionId == WarpDriveConfig.G_HYPERSPACE_DIMENSION_ID };
|
||||
}
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
private Object[] targetJumpgate(Context context, Arguments arguments) {
|
||||
return targetJumpgate(argumentsOCtoCC(arguments));
|
||||
}
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
private Object[] isAttached(Context context, Arguments arguments) {
|
||||
if (core != null) {
|
||||
return new Object[] { (boolean) (core.controller != null) };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Object[] dim_positive(Object[] arguments) {
|
||||
try {
|
||||
if (arguments.length == 3) {
|
||||
int argInt0, argInt1, argInt2;
|
||||
argInt0 = toInt(arguments[0]);
|
||||
argInt1 = toInt(arguments[1]);
|
||||
argInt2 = toInt(arguments[2]);
|
||||
if (argInt0 < 0 || argInt1 < 0 || argInt2 < 0) {
|
||||
return new Integer[] { getFront(), getRight(), getUp() };
|
||||
}
|
||||
System.out.println("Setting positive gabarits: f: " + argInt0 + " r: " + argInt1 + " u: " + argInt2);
|
||||
setFront(argInt0);
|
||||
setRight(argInt1);
|
||||
setUp(argInt2);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return new Integer[] { getFront(), getRight(), getUp() };
|
||||
}
|
||||
|
||||
return new Integer[] { getFront(), getRight(), getUp() };
|
||||
}
|
||||
|
||||
private Object[] dim_negative(Object[] arguments) {
|
||||
try {
|
||||
if (arguments.length == 3) {
|
||||
int argInt0, argInt1, argInt2;
|
||||
argInt0 = toInt(arguments[0]);
|
||||
argInt1 = toInt(arguments[1]);
|
||||
argInt2 = toInt(arguments[2]);
|
||||
if (argInt0 < 0 || argInt1 < 0 || argInt2 < 0) {
|
||||
return new Integer[] { getBack(), getLeft(), getDown() };
|
||||
}
|
||||
System.out.println("Setting negative gabarits: b: " + argInt0 + " l: " + argInt1 + " d: " + argInt2);
|
||||
setBack(argInt0);
|
||||
setLeft(argInt1);
|
||||
setDown(argInt2);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return new Integer[] { getBack(), getLeft(), getDown() };
|
||||
}
|
||||
|
||||
return new Integer[] { getBack(), getLeft(), getDown() };
|
||||
}
|
||||
|
||||
private Object[] mode(Object[] arguments) {
|
||||
try {
|
||||
if (arguments.length == 1) {
|
||||
setMode(toInt(arguments[0]));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return new Integer[] { mode.getCode() };
|
||||
}
|
||||
|
||||
return new Integer[] { mode.getCode() };
|
||||
}
|
||||
|
||||
private Object[] distance(Object[] arguments) {
|
||||
try {
|
||||
if (arguments.length == 1) {
|
||||
setDistance(toInt(arguments[0]));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return new Integer[] { getDistance() };
|
||||
}
|
||||
|
||||
return new Integer[] { getDistance() };
|
||||
}
|
||||
|
||||
private Object[] direction(Object[] arguments) {
|
||||
try {
|
||||
if (arguments.length == 1) {
|
||||
setDirection(toInt(arguments[0]));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return new Integer[] { getDirection() };
|
||||
}
|
||||
|
||||
return new Integer[] { getDirection() };
|
||||
}
|
||||
|
||||
private Object[] getAttachedPlayers(Object[] arguments) {
|
||||
String list = "";
|
||||
|
||||
if (!players.isEmpty()) {
|
||||
for (int i = 0; i < players.size(); i++) {
|
||||
String nick = players.get(i);
|
||||
list += nick + ((i == players.size() - 1) ? "" : ",");
|
||||
}
|
||||
}
|
||||
|
||||
return new Object[] { list, players };
|
||||
}
|
||||
|
||||
private Object[] summon(Object[] arguments) {
|
||||
int playerIndex = -1;
|
||||
if (arguments.length != 1) {
|
||||
return new Object[] { false };
|
||||
}
|
||||
try {
|
||||
playerIndex = toInt(arguments[0]);
|
||||
} catch (Exception e) {
|
||||
return new Object[] { false };
|
||||
}
|
||||
|
||||
if (playerIndex >= 0 && playerIndex < players.size()) {
|
||||
setToSummon(players.get(playerIndex));
|
||||
return new Object[] { true };
|
||||
}
|
||||
return new Object[] { false };
|
||||
}
|
||||
|
||||
private Object[] getEnergyRequired(Object[] arguments) {
|
||||
try {
|
||||
if (arguments.length == 1 && core != null) {
|
||||
return new Object[] { (int) (core.calculateRequiredEnergy(getMode(), core.shipVolume, toInt(arguments[0]))) };
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return new Integer[] { -1 };
|
||||
}
|
||||
return new Integer[] { -1 };
|
||||
}
|
||||
|
||||
private Object[] getShipSize(Object[] arguments) {
|
||||
if (core == null) {
|
||||
return null;
|
||||
}
|
||||
StringBuilder reason = new StringBuilder();
|
||||
try {
|
||||
if (!core.validateShipSpatialParameters(reason)) {
|
||||
core.messageToAllPlayersOnShip(reason.toString());
|
||||
if (core.controller == null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return new Object[] { core.shipVolume };
|
||||
} catch (Exception e) {
|
||||
if (WarpDriveConfig.G_DEBUGMODE) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Object[] beaconFrequency(Object[] arguments) {
|
||||
if (arguments.length == 1) {
|
||||
setBeaconFrequency((String) arguments[0]);
|
||||
}
|
||||
return new Object[] { beaconFrequency };
|
||||
}
|
||||
|
||||
private Object[] coreFrequency(Object[] arguments) {
|
||||
if (core == null) {
|
||||
return null;
|
||||
}
|
||||
if (arguments.length == 1) {
|
||||
core.coreFrequency = ((String) arguments[0]).replace("/", "").replace(".", "").replace("\\", ".");
|
||||
}
|
||||
return new Object[] { core.coreFrequency };
|
||||
}
|
||||
|
||||
private Object[] targetJumpgate(Object[] arguments) {
|
||||
if (arguments.length == 1) {
|
||||
setTargetJumpgateName((String) arguments[0]);
|
||||
}
|
||||
return new Object[] { targetJumpgateName };
|
||||
}
|
||||
|
||||
// ComputerCraft IPeripheral methods implementation
|
||||
@Override
|
||||
@Optional.Method(modid = "ComputerCraft")
|
||||
|
@ -424,230 +735,75 @@ public class TileEntityProtocol extends WarpInterfacedTE {
|
|||
@Override
|
||||
@Optional.Method(modid = "ComputerCraft")
|
||||
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception {
|
||||
int argInt0, argInt1, argInt2;
|
||||
String methodName = methodsArray[method];
|
||||
|
||||
if (methodName.equals("dim_getp")) {
|
||||
return new Integer[] { getFront(), getRight(), getUp() };
|
||||
if (methodName.equals("dim_positive")) {// dim_positive (front, right, up)
|
||||
return dim_positive(arguments);
|
||||
|
||||
} else if (methodName.equals("dim_setp")) {// dim_setp (front, right, up)
|
||||
if (arguments.length != 3) {
|
||||
return new Integer[] { getFront(), getRight(), getUp() };
|
||||
}
|
||||
try {
|
||||
argInt0 = toInt(arguments[0]);
|
||||
argInt1 = toInt(arguments[1]);
|
||||
argInt2 = toInt(arguments[2]);
|
||||
} catch (Exception e) {
|
||||
return new Integer[] { getFront(), getRight(), getUp() };
|
||||
}
|
||||
if (argInt0 < 0 || argInt1 < 0 || argInt2 < 0) {
|
||||
return new Integer[] { getFront(), getRight(), getUp() };
|
||||
}
|
||||
} else if (methodName.equals("dim_negative")) {// dim_negative (back, left, down)
|
||||
return dim_negative(arguments);
|
||||
|
||||
System.out.println("Setting positive gabarits: f: " + argInt0 + " r: " + argInt1 + " u: " + argInt2);
|
||||
setFront(argInt0);
|
||||
setRight(argInt1);
|
||||
setUp(argInt2);
|
||||
} else if (methodName.equals("mode")) {// mode (mode)
|
||||
return mode(arguments);
|
||||
|
||||
return new Integer[] { getFront(), getRight(), getUp() };
|
||||
} else if (methodName.equals("distance")) {// distance (distance)
|
||||
return distance(arguments);
|
||||
|
||||
} else if (methodName.equals("dim_getn")) {
|
||||
return new Integer[] { getBack(), getLeft(), getDown() };
|
||||
} else if (methodName.equals("direction")) {// direction (direction)
|
||||
return direction(arguments);
|
||||
|
||||
} else if (methodName.equals("dim_setn")) {// dim_setn (back, left, down)
|
||||
if (arguments.length != 3) {
|
||||
return new Integer[] { -1 };
|
||||
}
|
||||
try {
|
||||
argInt0 = toInt(arguments[0]);
|
||||
argInt1 = toInt(arguments[1]);
|
||||
argInt2 = toInt(arguments[2]);
|
||||
} catch (Exception e) {
|
||||
return new Integer[] { getBack(), getLeft(), getDown() };
|
||||
}
|
||||
if (argInt0 < 0 || argInt1 < 0 || argInt2 < 0) {
|
||||
return new Integer[] { getBack(), getLeft(), getDown() };
|
||||
}
|
||||
} else if (methodName.equals("getAttachedPlayers")) {
|
||||
return getAttachedPlayers(arguments);
|
||||
|
||||
System.out.println("Setting negative gabarits: b: " + argInt0 + " l: " + argInt1 + " d: " + argInt2);
|
||||
setBack(argInt0);
|
||||
setLeft(argInt1);
|
||||
setDown(argInt2);
|
||||
} else if (methodName.equals("summon")) {
|
||||
return summon(arguments);
|
||||
|
||||
return new Integer[] { getBack(), getLeft(), getDown() };
|
||||
} else if (methodName.equals("summon_all")) {
|
||||
setSummonAllFlag(true);
|
||||
|
||||
} else if (methodName.equals("set_mode")) {// set_mode (mode)
|
||||
if (arguments.length != 1) {
|
||||
return new Integer[] { -1 };
|
||||
}
|
||||
try {
|
||||
argInt0 = toInt(arguments[0]);
|
||||
} catch (Exception e) {
|
||||
return new Integer[] { -1 };
|
||||
}
|
||||
|
||||
setMode(argInt0);
|
||||
|
||||
} else if (methodName.equals("set_distance")) {// set_distance (distance)
|
||||
if (arguments.length != 1) {
|
||||
return new Integer[] { -1 };
|
||||
}
|
||||
try {
|
||||
argInt0 = toInt(arguments[0]);
|
||||
} catch (Exception e) {
|
||||
return new Integer[] { -1 };
|
||||
}
|
||||
|
||||
setDistance(argInt0);
|
||||
|
||||
return new Integer[] { getDistance() };
|
||||
|
||||
} else if (methodName.equals("set_direction")) {// set_direction (dir)
|
||||
if (arguments.length != 1) {
|
||||
return new Integer[] { -1 };
|
||||
}
|
||||
try {
|
||||
argInt0 = toInt(arguments[0]);
|
||||
} catch (Exception e) {
|
||||
return new Integer[] { -1 };
|
||||
}
|
||||
|
||||
setDirection(argInt0);
|
||||
|
||||
} else if (methodName.equals("get_attached_players")) {// get_attached_players
|
||||
String list = "";
|
||||
|
||||
for (int i = 0; i < this.players.size(); i++) {
|
||||
String nick = this.players.get(i);
|
||||
list += nick + ((i == this.players.size() - 1) ? "" : ",");
|
||||
}
|
||||
|
||||
if (players.isEmpty()) {
|
||||
list = "";
|
||||
}
|
||||
|
||||
return new Object[] { list };
|
||||
|
||||
} else if (methodName.equals("summon")) {// summon
|
||||
if (arguments.length != 1) {
|
||||
return new Integer[] { -1 };
|
||||
}
|
||||
try {
|
||||
argInt0 = toInt(arguments[0]);
|
||||
} catch (Exception e) {
|
||||
return new Integer[] { -1 };
|
||||
}
|
||||
|
||||
if (argInt0 >= 0 && argInt0 < players.size()) {
|
||||
setToSummon(players.get(argInt0));
|
||||
}
|
||||
|
||||
} else if (methodName.equals("summon_all")) {// summon_all
|
||||
this.setSummonAllFlag(true);
|
||||
|
||||
} else if (methodName.equals("get_x")) {// get_x
|
||||
} else if (methodName.equals("pos")) {
|
||||
if (core == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Object[] { core.xCoord };
|
||||
return new Object[] { core.xCoord, core.yCoord, core.zCoord };
|
||||
|
||||
} else if (methodName.equals("get_y")) {// get_y
|
||||
} else if (methodName.equals("getEnergyLevel")) {
|
||||
if (core == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Object[] { core.yCoord };
|
||||
return core.getEnergyLevel();
|
||||
|
||||
} else if (methodName.equals("get_z")) {// get_z
|
||||
if (core == null) {
|
||||
return null;
|
||||
}
|
||||
} else if (methodName.equals("getEnergyRequired")) {// getEnergyRequired(distance)
|
||||
return getEnergyRequired(arguments);
|
||||
|
||||
return new Object[] { core.zCoord };
|
||||
|
||||
} else if (methodName.equals("get_energy_level")) {// get_energy_level
|
||||
if (core == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Object[] { core.getEnergyStored() };
|
||||
|
||||
} else if (methodName.equals("get_energy_max")) {// get_energy_max
|
||||
if (core == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Object[] { core.getMaxEnergyStored() };
|
||||
|
||||
} else if (methodName.equals("get_energy_required")) {// get_energy_required(distance)
|
||||
if (arguments.length != 1) {
|
||||
return new Integer[] { -1 };
|
||||
}
|
||||
try {
|
||||
argInt0 = toInt(arguments[0]);
|
||||
} catch (Exception e) {
|
||||
return new Integer[] { -1 };
|
||||
}
|
||||
if (core != null) {
|
||||
return new Object[] { (int) (core.calculateRequiredEnergy(getMode(), core.shipVolume, argInt0)) };
|
||||
}
|
||||
|
||||
} else if (methodName.equals("do_jump")) {// do_jump
|
||||
} else if (methodName.equals("jump")) {
|
||||
doJump();
|
||||
|
||||
} else if (methodName.equals("get_ship_size")) {// get_ship_size
|
||||
} else if (methodName.equals("getShipSize")) {
|
||||
return getShipSize(arguments);
|
||||
|
||||
} else if (methodName.equals("beaconFrequency")) {
|
||||
return beaconFrequency(arguments);
|
||||
|
||||
} else if (methodName.equals("getOrientation")) {
|
||||
if (core != null) {
|
||||
StringBuilder reason = new StringBuilder();
|
||||
try {
|
||||
if (!core.validateShipSpatialParameters(reason)) {
|
||||
core.messageToAllPlayersOnShip(reason.toString());
|
||||
if (core.controller == null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return new Object[] { core.shipVolume };
|
||||
} catch (Exception e) {
|
||||
if (WarpDriveConfig.G_DEBUGMODE) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return new Object[] { core.dx, 0, core.dz };
|
||||
}
|
||||
return null;
|
||||
|
||||
} else if (methodName.equals("set_beacon_frequency")) {// set_beacon_frequency
|
||||
if (arguments.length != 1) {
|
||||
return new Integer[] { -1 };
|
||||
}
|
||||
} else if (methodName.equals("coreFrequency")) {
|
||||
return coreFrequency(arguments);
|
||||
|
||||
setBeaconFrequency((String) arguments[0]);
|
||||
|
||||
} else if (methodName.equals("get_dx")) {// get_dx
|
||||
if (core != null) {
|
||||
return new Object[] { core.dx };
|
||||
}
|
||||
|
||||
} else if (methodName.equals("get_dz")) {// get_dz
|
||||
if (core != null) {
|
||||
return new Object[] { core.dz };
|
||||
}
|
||||
|
||||
} else if (methodName.equals("set_core_frequency")) {// set_core_frequency
|
||||
if (arguments.length == 1 && (core != null)) {
|
||||
core.coreFrequency = ((String) arguments[0]).replace("/", "").replace(".", "").replace("\\", ".");
|
||||
}
|
||||
|
||||
} else if (methodName.equals("is_in_space")) {// is_in_space
|
||||
} else if (methodName.equals("isInSpace")) {
|
||||
return new Boolean[] { worldObj.provider.dimensionId == WarpDriveConfig.G_SPACE_DIMENSION_ID };
|
||||
|
||||
} else if (methodName.equals("is_in_hyperspace")) {// is_in_hyperspace
|
||||
} else if (methodName.equals("isInHyperspace")) {
|
||||
return new Boolean[] { worldObj.provider.dimensionId == WarpDriveConfig.G_HYPERSPACE_DIMENSION_ID };
|
||||
|
||||
} else if (methodName.equals("set_target_jumpgate")) {// set_target_jumpgate
|
||||
if (arguments.length == 1) {
|
||||
setTargetJumpgateName((String) arguments[0]);
|
||||
}
|
||||
} else if (methodName.equals("targetJumpgate")) {
|
||||
return targetJumpgate(arguments);
|
||||
|
||||
} else if (methodName.equals("isAttached")) {// isAttached
|
||||
if (core != null) {
|
||||
|
@ -669,9 +825,8 @@ public class TileEntityProtocol extends WarpInterfacedTE {
|
|||
/**
|
||||
* @param targetJumpgateName the targetJumpgateName to set
|
||||
*/
|
||||
public void setTargetJumpgateName(String targetJumpgateName)
|
||||
{
|
||||
this.targetJumpgateName = targetJumpgateName;
|
||||
public void setTargetJumpgateName(String parTargetJumpgateName) {
|
||||
targetJumpgateName = parTargetJumpgateName;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -8,6 +8,9 @@ import dan200.computercraft.api.lua.ILuaContext;
|
|||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import li.cil.oc.api.network.Arguments;
|
||||
import li.cil.oc.api.network.Callback;
|
||||
import li.cil.oc.api.network.Context;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import cr0s.WarpDrive.*;
|
||||
|
@ -21,12 +24,11 @@ public class TileEntityRadar extends WarpEnergyTE {
|
|||
public TileEntityRadar() {
|
||||
peripheralName = "radar";
|
||||
methodsArray = new String[] {
|
||||
"scanRay", // 0
|
||||
"scanRadius", // 1
|
||||
"getResultsCount", // 2
|
||||
"getResult", // 3
|
||||
"getEnergyLevel", // 4
|
||||
"pos" // 5
|
||||
"scanRadius",
|
||||
"getResultsCount",
|
||||
"getResult",
|
||||
"getEnergyLevel",
|
||||
"pos"
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -63,6 +65,84 @@ public class TileEntityRadar extends WarpEnergyTE {
|
|||
super.writeToNBT(tag);
|
||||
}
|
||||
|
||||
// OpenComputer callback methods
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
private Object[] scanRadius(Context context, Arguments arguments) {
|
||||
return scanRadius(argumentsOCtoCC(arguments));
|
||||
}
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
private Object[] getResultsCount(Context context, Arguments arguments) {
|
||||
if (results != null) {
|
||||
return new Integer[] { results.size() };
|
||||
}
|
||||
return new Integer[] { -1 };
|
||||
}
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
private Object[] getResult(Context context, Arguments arguments) {
|
||||
return getResult(argumentsOCtoCC(arguments));
|
||||
}
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
private Object[] pos(Context context, Arguments arguments) {
|
||||
return new Integer[] { xCoord, yCoord, zCoord };
|
||||
}
|
||||
|
||||
private Object[] scanRadius(Object[] arguments) {
|
||||
// always clear results
|
||||
results = null;
|
||||
|
||||
// validate parameters
|
||||
if (arguments.length != 1) {
|
||||
return new Boolean[] { false };
|
||||
}
|
||||
int radius;
|
||||
try {
|
||||
radius = toInt(arguments[0]);
|
||||
} catch(Exception e) {
|
||||
return new Boolean[] { false };
|
||||
}
|
||||
if (radius <= 0 || radius > 10000) {
|
||||
scanRadius = 0;
|
||||
return new Boolean[] { false };
|
||||
}
|
||||
if (!consumeEnergy(Math.max(radius, 100) * Math.max(radius, 100), false)) {
|
||||
return new Boolean[] { false };
|
||||
}
|
||||
|
||||
// Begin searching
|
||||
scanRadius = radius;
|
||||
cooldownTime = 0;
|
||||
if (getBlockMetadata() != 2) {
|
||||
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 2, 1 + 2);
|
||||
}
|
||||
return new Boolean[] { true };
|
||||
}
|
||||
private Object[] getResult(Object[] arguments) {
|
||||
if (arguments.length == 1 && (results != null)) {
|
||||
int index;
|
||||
try {
|
||||
index = toInt(arguments[0]);
|
||||
} catch(Exception e) {
|
||||
return new Object[] { "FAIL", 0, 0, 0 };
|
||||
}
|
||||
if (index >= 0 && index < results.size()) {
|
||||
TileEntityReactor res = results.get(index);
|
||||
if (res != null)
|
||||
{
|
||||
int yAddition = (res.worldObj.provider.dimensionId == WarpDriveConfig.G_SPACE_DIMENSION_ID) ? 256 : (res.worldObj.provider.dimensionId == WarpDriveConfig.G_HYPERSPACE_DIMENSION_ID) ? 512 : 0;
|
||||
return new Object[] { res.coreFrequency, res.xCoord, res.yCoord + yAddition, res.zCoord };
|
||||
}
|
||||
}
|
||||
}
|
||||
return new Object[] { "FAIL", 0, 0, 0 };
|
||||
}
|
||||
|
||||
// ComputerCraft IPeripheral methods implementation
|
||||
@Override
|
||||
public void attach(IComputerAccess computer) {
|
||||
|
@ -90,38 +170,8 @@ public class TileEntityRadar extends WarpEnergyTE {
|
|||
@Optional.Method(modid = "ComputerCraft")
|
||||
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception {
|
||||
String methodName = methodsArray[method];
|
||||
if (methodName.equals("scanRay")) {// scanRay (toX, toY, toZ)
|
||||
return new Object[] { -1 };
|
||||
|
||||
} else if (methodName.equals("scanRadius")) {// scanRadius (radius)
|
||||
// always clear results
|
||||
results = null;
|
||||
|
||||
// validate parameters
|
||||
if (arguments.length != 1) {
|
||||
return new Boolean[] { false };
|
||||
}
|
||||
int radius;
|
||||
try {
|
||||
radius = toInt(arguments[0]);
|
||||
} catch(Exception e) {
|
||||
return new Boolean[] { false };
|
||||
}
|
||||
if (radius <= 0 || radius > 10000) {
|
||||
scanRadius = 0;
|
||||
return new Boolean[] { false };
|
||||
}
|
||||
if (!consumeEnergy(Math.max(radius, 100) * Math.max(radius, 100), false)) {
|
||||
return new Boolean[] { false };
|
||||
}
|
||||
|
||||
// Begin searching
|
||||
scanRadius = radius;
|
||||
cooldownTime = 0;
|
||||
if (getBlockMetadata() != 2) {
|
||||
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 2, 1 + 2);
|
||||
}
|
||||
return new Boolean[] { true };
|
||||
if (methodName.equals("scanRadius")) {// scanRadius (radius)
|
||||
return scanRadius(arguments);
|
||||
|
||||
} else if (methodName.equals("getResultsCount")) {
|
||||
if (results != null) {
|
||||
|
@ -130,26 +180,10 @@ public class TileEntityRadar extends WarpEnergyTE {
|
|||
return new Integer[] { -1 };
|
||||
|
||||
} else if (methodName.equals("getResult")) {
|
||||
if (arguments.length == 1 && (results != null)) {
|
||||
int index;
|
||||
try {
|
||||
index = toInt(arguments[0]);
|
||||
} catch(Exception e) {
|
||||
return new Object[] { "FAIL", 0, 0, 0 };
|
||||
}
|
||||
if (index >= 0 && index < results.size()) {
|
||||
TileEntityReactor res = results.get(index);
|
||||
if (res != null)
|
||||
{
|
||||
int yAddition = (res.worldObj.provider.dimensionId == WarpDriveConfig.G_SPACE_DIMENSION_ID) ? 256 : (res.worldObj.provider.dimensionId == WarpDriveConfig.G_HYPERSPACE_DIMENSION_ID) ? 512 : 0;
|
||||
return new Object[] { res.coreFrequency, res.xCoord, res.yCoord + yAddition, res.zCoord };
|
||||
}
|
||||
}
|
||||
}
|
||||
return new Object[] { "FAIL", 0, 0, 0 };
|
||||
return getResult(arguments);
|
||||
|
||||
} else if (methodName.equals("getEnergyLevel")) {
|
||||
return new Integer[] { getEnergyStored() };
|
||||
return getEnergyLevel();
|
||||
|
||||
} else if (methodName.equals("pos")) {
|
||||
return new Integer[] { xCoord, yCoord, zCoord };
|
||||
|
|
|
@ -13,6 +13,9 @@ import java.io.File;
|
|||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
import li.cil.oc.api.network.Arguments;
|
||||
import li.cil.oc.api.network.Callback;
|
||||
import li.cil.oc.api.network.Context;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
|
@ -26,7 +29,7 @@ import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
|
|||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
public class TileEntityShipScanner extends WarpEnergyTE {
|
||||
private int state = 0; // 0 - inactive, 1 - active
|
||||
private boolean isActive = false;
|
||||
private TileEntityReactor core = null;
|
||||
|
||||
int laserTicks = 0;
|
||||
|
@ -49,7 +52,7 @@ public class TileEntityShipScanner extends WarpEnergyTE {
|
|||
methodsArray = new String[] {
|
||||
"scan", // 0
|
||||
"fileName", // 1
|
||||
"energy", // 2
|
||||
"getEnergyLevel", // 2
|
||||
"deploy" // 3 deployShipFromSchematic(file, offsetX, offsetY, offsetZ)
|
||||
};
|
||||
}
|
||||
|
@ -68,18 +71,18 @@ public class TileEntityShipScanner extends WarpEnergyTE {
|
|||
|
||||
// Warp core is not found
|
||||
if (!isDeploying && core == null) {
|
||||
switchState(0); // disable scanner
|
||||
setActive(false); // disable scanner
|
||||
return;
|
||||
}
|
||||
|
||||
if (state == 0) { // inactive
|
||||
if (!isActive) {// inactive
|
||||
if (++laserTicks > 20) {
|
||||
PacketHandler.sendBeamPacket(worldObj,
|
||||
new Vector3(this).translate(0.5D), new Vector3(core.xCoord, core.yCoord, core.zCoord).translate(0.5D),
|
||||
0f, 1f, 0f, 40, 0, 100);
|
||||
laserTicks = 0;
|
||||
}
|
||||
} else if (state == 1 && !isDeploying) { // active: scanning
|
||||
} else if (!isDeploying) {// active and scanning
|
||||
if (++laserTicks > 5) {
|
||||
laserTicks = 0;
|
||||
|
||||
|
@ -127,10 +130,10 @@ public class TileEntityShipScanner extends WarpEnergyTE {
|
|||
}
|
||||
|
||||
if (++scanTicks > 20 * (1 + core.shipVolume / 10)) {
|
||||
switchState(0);
|
||||
setActive(false); // disable scanner
|
||||
scanTicks = 0;
|
||||
}
|
||||
} if (state == 1 && isDeploying) { // active: deploying
|
||||
} else {// active and deploying
|
||||
if (++deployDelayTicks < 20)
|
||||
return;
|
||||
|
||||
|
@ -140,7 +143,7 @@ public class TileEntityShipScanner extends WarpEnergyTE {
|
|||
|
||||
if (blocks == 0) {
|
||||
isDeploying = false;
|
||||
switchState(0);
|
||||
setActive(false); // disable scanner
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -149,7 +152,7 @@ public class TileEntityShipScanner extends WarpEnergyTE {
|
|||
if (currentDeployIndex >= blocksToDeployCount)
|
||||
{
|
||||
isDeploying = false;
|
||||
switchState(0);
|
||||
setActive(false); // disable scanner
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -177,10 +180,10 @@ public class TileEntityShipScanner extends WarpEnergyTE {
|
|||
}
|
||||
}
|
||||
|
||||
private void switchState(int newState) {
|
||||
this.state = newState;
|
||||
if (getBlockMetadata() != newState) {
|
||||
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, newState, 2);
|
||||
private void setActive(boolean newState) {
|
||||
isActive = newState;
|
||||
if ((getBlockMetadata() == 1) == newState) {
|
||||
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, isActive ? 1 : 0, 2);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -361,7 +364,7 @@ public class TileEntityShipScanner extends WarpEnergyTE {
|
|||
// Begins ship scan
|
||||
private boolean scanShip(StringBuilder reason) {
|
||||
// Enable scanner
|
||||
switchState(1);
|
||||
setActive(true);
|
||||
File f = new File(WarpDriveConfig.G_SCHEMALOCATION);
|
||||
if (!f.exists() || !f.isDirectory()) {
|
||||
f.mkdirs();
|
||||
|
@ -525,7 +528,7 @@ public class TileEntityShipScanner extends WarpEnergyTE {
|
|||
}
|
||||
}
|
||||
|
||||
switchState(1);
|
||||
setActive(true);
|
||||
reason.append("Ship deploying...");
|
||||
return 3;
|
||||
}
|
||||
|
@ -540,54 +543,102 @@ public class TileEntityShipScanner extends WarpEnergyTE {
|
|||
super.writeToNBT(tag);
|
||||
}
|
||||
|
||||
// OpenComputer callback methods
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
private Object[] scan(Context context, Arguments arguments) {
|
||||
return scan(argumentsOCtoCC(arguments));
|
||||
}
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
private Object[] filename(Context context, Arguments arguments) {
|
||||
return filename(argumentsOCtoCC(arguments));
|
||||
}
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
private Object[] deploy(Context context, Arguments arguments) {
|
||||
return deploy(argumentsOCtoCC(arguments));
|
||||
}
|
||||
|
||||
private Object[] scan(Object[] arguments) {
|
||||
// Already scanning?
|
||||
if (isActive) {
|
||||
return new Object[] { false, 0, "Already active" };
|
||||
}
|
||||
|
||||
if (core == null) {
|
||||
return new Object[] { false, 1, "Warp-Core not found" };
|
||||
} else if (!consumeEnergy(getScanningEnergyCost(core.shipVolume), true)) {
|
||||
return new Object[] { false, 2, "Not enough energy!" };
|
||||
} else {
|
||||
StringBuilder reason = new StringBuilder();
|
||||
boolean success = scanShip(reason);
|
||||
return new Object[] { success, 3, reason.toString() };
|
||||
}
|
||||
}
|
||||
|
||||
private Object[] filename(Object[] arguments) {
|
||||
if (isActive && !schematicFileName.isEmpty()) {
|
||||
if (isDeploying) {
|
||||
return new Object[] { "Deployment in progress. Please wait..." };
|
||||
} else {
|
||||
return new Object[] { "Scan in progress. Please wait..." };
|
||||
}
|
||||
}
|
||||
|
||||
return new Object[] { schematicFileName };
|
||||
}
|
||||
|
||||
private Object[] deploy(Object[] arguments) {
|
||||
if (arguments.length == 4) {
|
||||
String fileName = (String)arguments[0];
|
||||
int x = toInt(arguments[1]);
|
||||
int y = toInt(arguments[2]);
|
||||
int z = toInt(arguments[3]);
|
||||
|
||||
if (!new File(WarpDriveConfig.G_SCHEMALOCATION + "/" + fileName).exists()) {
|
||||
return new Object[] { 0, "Specified .schematic file was not found!" };
|
||||
} else {
|
||||
StringBuilder reason = new StringBuilder();
|
||||
int result = deployShip(fileName, x, y, z, reason);
|
||||
return new Object[] { result, reason.toString() };
|
||||
}
|
||||
} else {
|
||||
return new Object[] { 4, "Invalid arguments count, you need .schematic file name, offsetX, offsetY and offsetZ!" };
|
||||
}
|
||||
}
|
||||
|
||||
private Object[] state(Object[] arguments) {
|
||||
if (!isActive) {
|
||||
return new Object[] { false, "IDLE", 0, 0 };
|
||||
} else if (!isDeploying) {
|
||||
return new Object[] { true, "Scanning", 0, 0 };
|
||||
} else {
|
||||
return new Object[] { true, "Deploying", currentDeployIndex, blocksToDeployCount };
|
||||
}
|
||||
}
|
||||
|
||||
// ComputerCraft IPeripheral methods implementation
|
||||
@Override
|
||||
@Optional.Method(modid = "ComputerCraft")
|
||||
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception {
|
||||
String methodName = methodsArray[method];
|
||||
if (methodName.equals("scan")) {
|
||||
// Already scanning?
|
||||
if (this.state == 1) {
|
||||
return new Object[] { false, 0, "Already scanning" };
|
||||
}
|
||||
|
||||
if (core == null) {
|
||||
return new Object[] { false, 1, "Warp-Core not found" };
|
||||
} else if (!consumeEnergy(getScanningEnergyCost(core.shipVolume), true)) {
|
||||
return new Object[] { false, 2, "Not enough energy!" };
|
||||
} else {
|
||||
StringBuilder reason = new StringBuilder();
|
||||
boolean success = scanShip(reason);
|
||||
return new Object[] { success, 3, reason.toString() };
|
||||
}
|
||||
return scan(arguments);
|
||||
|
||||
} else if (methodName.equals("fileName")) {
|
||||
if (state != 0 && !schematicFileName.isEmpty()) {
|
||||
return new Object[] { "Scanning in process. Please wait..." };
|
||||
}
|
||||
return filename(arguments);
|
||||
|
||||
return new Object[] { schematicFileName };
|
||||
|
||||
} else if (methodName.equals("energy")) {
|
||||
return new Object[] { getEnergyStored() };
|
||||
} else if (methodName.equals("getEnergyLevel")) {
|
||||
return getEnergyLevel();
|
||||
|
||||
} else if (methodName.equals("deploy")) {// deploy(schematicFileName, offsetX, offsetY, offsetZ)
|
||||
if (arguments.length == 4) {
|
||||
String fileName = (String)arguments[0];
|
||||
int x = toInt(arguments[1]);
|
||||
int y = toInt(arguments[2]);
|
||||
int z = toInt(arguments[3]);
|
||||
|
||||
if (!new File(WarpDriveConfig.G_SCHEMALOCATION + "/" + fileName).exists()) {
|
||||
return new Object[] { 0, "Specified .schematic file was not found!" };
|
||||
} else {
|
||||
StringBuilder reason = new StringBuilder();
|
||||
int result = deployShip(fileName, x, y, z, reason);
|
||||
return new Object[] { result, reason.toString() };
|
||||
}
|
||||
} else {
|
||||
return new Object[] { 4, "Invalid arguments count, you need .schematic file name, offsetX, offsetY and offsetZ!" };
|
||||
}
|
||||
return deploy(arguments);
|
||||
|
||||
} else if (methodName.equals("state")) {
|
||||
return state(arguments);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
|
@ -2,12 +2,16 @@ package cr0s.WarpDrive.machines;
|
|||
|
||||
import java.util.HashMap;
|
||||
|
||||
import li.cil.oc.api.network.Arguments;
|
||||
import li.cil.oc.api.network.Callback;
|
||||
import li.cil.oc.api.network.Context;
|
||||
import ic2.api.energy.event.EnergyTileLoadEvent;
|
||||
import ic2.api.energy.event.EnergyTileUnloadEvent;
|
||||
import ic2.api.energy.tile.IEnergySink;
|
||||
import ic2.api.energy.tile.IEnergySource;
|
||||
import cofh.api.energy.IEnergyHandler;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.Optional;
|
||||
import cr0s.WarpDrive.WarpDrive;
|
||||
import cr0s.WarpDrive.api.IBlockUpdateDetector;
|
||||
import cr0s.WarpDrive.data.EnumUpgradeTypes;
|
||||
|
@ -139,7 +143,7 @@ public abstract class WarpEnergyTE extends WarpInterfacedTE implements IEnergyHa
|
|||
return temp;
|
||||
}
|
||||
|
||||
public Object[] getEnergyObject() {
|
||||
public Object[] getEnergyLevel() {
|
||||
return new Object[] { getEnergyStored(), getMaxEnergyStored() };
|
||||
}
|
||||
|
||||
|
@ -150,7 +154,13 @@ public abstract class WarpEnergyTE extends WarpInterfacedTE implements IEnergyHa
|
|||
return getBlockType().getLocalizedName();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// OpenComputer callback methods
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
private Object[] getEnergyLevel(Context context, Arguments arguments) {
|
||||
return getEnergyLevel();
|
||||
}
|
||||
|
||||
// Minecraft overrides
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue