Merge remote-tracking branch 'origin/master' into TDK

This commit is contained in:
LemADEC 2014-10-05 18:11:41 +02:00
commit d7fd11f67c
20 changed files with 1088 additions and 822 deletions

View file

@ -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)

View file

@ -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)

View file

@ -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")

View file

@ -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

View file

@ -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

View file

@ -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
local energy, energyMax = warp.getEnergyLevel()
Show(" Energy = " .. math.floor(100 * energy / energyMax) .. " % (" .. energy .. "EU)")
Show(" Attached players = "..warp.get_attached_players())
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()

View file

@ -129,7 +129,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

View file

@ -9,8 +9,7 @@ import net.minecraft.nbt.NBTTagCompound;
* @author LemADEC
*/
public class TransitionPlane implements Cloneable
{
public class TransitionPlane implements Cloneable {
public int dimensionId;
public int dimensionCenterX, dimensionCenterZ;
public int borderSizeX, borderSizeZ;

View file

@ -1,33 +1,39 @@
package cr0s.WarpDrive.machines;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Optional;
import cr0s.WarpDrive.*;
import dan200.computercraft.api.peripheral.IComputerAccess;
import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.peripheral.IPeripheral;
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;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.ChunkPosition;
public class TileEntityCamera extends TileEntity implements IPeripheral {
public class TileEntityCamera extends WarpInterfacedTE {
private int frequency = -1; // beam frequency
private String[] methodsArray = {
"freq"
};
private final static int REGISTRY_UPDATE_INTERVAL_TICKS = 15 * 20;
private final static int PACKET_SEND_INTERVAL_TICKS = 60 * 20;
private int registryUpdateTicks = 20;
private int packetSendTicks = 20;
public TileEntityCamera() {
peripheralName = "camera";
methodsArray = new String[] {
"freq"
};
}
@Override
public void updateEntity() {
// Update frequency on clients (recovery mechanism, no need to go too fast)
@ -89,36 +95,28 @@ public class TileEntityCamera extends TileEntity implements IPeripheral {
// WarpDrive.debugPrint("" + this + " writeToNBT");
}
// IPeripheral methods implementation
@Override
public String getType() {
return "camera";
}
@Override
public String[] getMethodNames() {
return methodsArray;
}
@Override
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception {
if (arguments.length == 1) {
setFrequency(((Double)arguments[0]).intValue());
// 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
public void attach(IComputerAccess computer) {
@Optional.Method(modid = "ComputerCraft")
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception {
String methodName = methodsArray[method];
if (methodName.equals("freq")) {
if (arguments.length == 1) {
setFrequency(toInt(arguments[0]));
}
@Override
public void detach(IComputerAccess computer) {
return new Integer[] { frequency };
}
@Override
public boolean equals(IPeripheral other) {
return other == this;
return null;
}
@Override

View file

@ -1,18 +1,21 @@
package cr0s.WarpDrive.machines;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Optional;
import cpw.mods.fml.relauncher.Side;
import cr0s.WarpDrive.data.CloakedArea;
import cr0s.WarpDrive.data.Vector3;
import dan200.computercraft.api.ComputerCraftAPI;
import dan200.computercraft.api.peripheral.IComputerAccess;
import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.peripheral.IPeripheral;
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;
@ -22,18 +25,9 @@ import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraftforge.common.ForgeDirection;
import cr0s.WarpDrive.*;
public class TileEntityCloakingDeviceCore extends WarpEnergyTE implements IPeripheral {
public class TileEntityCloakingDeviceCore extends WarpEnergyTE {
private final int MAX_ENERGY_VALUE = 500000000; // 500kk EU
private String[] methodsArray = {
"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
};
public boolean isEnabled = false;
public byte tier = 1; // cloaking field tier, 1 or 2
@ -50,6 +44,16 @@ public class TileEntityCloakingDeviceCore extends WarpEnergyTE implements IPerip
private boolean soundPlayed = false;
private int soundTicks = 0;
public TileEntityCloakingDeviceCore() {
peripheralName = "cloakingdevicecore";
methodsArray = new String[] {
"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
};
}
@Override
public void updateEntity() {
super.updateEntity();
@ -238,6 +242,7 @@ public class TileEntityCloakingDeviceCore extends WarpEnergyTE implements IPerip
}
}
}
public boolean countBlocksAndConsumeEnergy() {
int x, y, z, energyToConsume = 0;
volume = 0;
@ -337,6 +342,7 @@ public class TileEntityCloakingDeviceCore extends WarpEnergyTE implements IPerip
return 0;
}
public boolean validateAssembly() {
final int START_LENGTH = 2; // Step length from core block to main coils
@ -393,54 +399,40 @@ public class TileEntityCloakingDeviceCore extends WarpEnergyTE implements IPerip
return true;
}
// CC
// IPeripheral methods implementation
@Override
public String getType() {
return "cloakingdevicecore";
}
@Override
public String[] getMethodNames() {
return methodsArray;
}
@Override
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception {
switch (method) {
case 0: // setFieldTier(1 or 2)
if (arguments.length == 1) {
if (((Double)arguments[0]).byteValue() != 1 && ((Double)arguments[0]).byteValue() != 2) {
this.tier = 1;
// 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 {
this.tier = ((Double)arguments[0]).byteValue();
tier = 1;
}
}
break;
return new Integer[] { (int)tier };
}
case 1: // isAssemblyValid()
@Callback
@Optional.Method(modid = "OpenComputers")
private Object[] isAssemblyValid(Context context, Arguments arguments) {
return new Object[] { (boolean)validateAssembly() };
case 2: // getEnergyLevel()
return new Object[] { getEnergyStored() };
case 3: // enableCloakingField()
this.isEnabled = true;
break;
case 4: // disableCloakingField()
this.isEnabled = false;
break;
case 5: // isEnabled()
return new Object[] { this.isEnabled };
}
return null;
@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")
public void attach(IComputerAccess computer) {
super.attach(computer);
if (WarpDriveConfig.G_LUA_SCRIPTS != WarpDriveConfig.LUA_SCRIPTS_NONE) {
computer.mount("/cloakingdevicecore", ComputerCraftAPI.createResourceMount(WarpDrive.class, "warpdrive", "lua/cloakingdevicecore"));
computer.mount("/warpupdater", ComputerCraftAPI.createResourceMount(WarpDrive.class, "warpdrive", "lua/common/updater"));
@ -453,7 +445,33 @@ public class TileEntityCloakingDeviceCore extends WarpEnergyTE implements IPerip
}
@Override
public void detach(IComputerAccess computer) {
@Optional.Method(modid = "ComputerCraft")
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception {
String methodName = methodsArray[method];
if (methodName.equals("tier")) {
if (arguments.length == 1) {
if (toInt(arguments[0]) == 2) {
tier = 2;
} else {
tier = 1;
}
}
return new Integer[] { (int)tier };
} else if (methodName.equals("isAssemblyValid")) {
return new Object[] { (boolean)validateAssembly() };
} else if (methodName.equals("getEnergyLevel")) {
return getEnergyLevel();
} else if (methodName.equals("enable")) {
if (arguments.length == 1) {
isEnabled = toBool(arguments[0]);
}
return new Object[] { isEnabled };
}
return null;
}
@Override
@ -470,9 +488,4 @@ public class TileEntityCloakingDeviceCore extends WarpEnergyTE implements IPerip
public boolean canInputEnergy(ForgeDirection from) {
return true;
}
@Override
public boolean equals(IPeripheral other) {
return other == this;
}
}

View file

@ -5,7 +5,6 @@ import cpw.mods.fml.common.Optional;
import cpw.mods.fml.common.FMLCommonHandler;
import dan200.computercraft.api.peripheral.IComputerAccess;
import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.peripheral.IPeripheral;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
@ -492,7 +491,7 @@ public class TileEntityLaser extends WarpInterfacedTE {
super.onChunkUnload();
}
// IPeripheral methods implementation
// OpenComputer callback methods
@Callback
@Optional.Method(modid = "OpenComputers")
private Object[] emitBeam(Context context, Arguments arguments) {
@ -580,33 +579,29 @@ public class TileEntityLaser extends WarpInterfacedTE {
}
}
// ComputerCraft IPeripheral methods implementation
@Override
@Optional.Method(modid = "ComputerCraft")
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception {
switch (method) {
case 0: // emitBeam(yaw, pitch) or emitBeam(deltaX, deltaY, deltaZ)
String methodName = methodsArray[method];
if (methodName.equals("emitBeam")) { // emitBeam(yaw, pitch) or emitBeam(deltaX, deltaY, deltaZ)
return emitBeam(arguments);
case 1: // pos
} else if (methodName.equals("pos")) {
return new Integer[] { xCoord, yCoord, zCoord };
case 2: // freq
} else if (methodName.equals("freq")) {
if (arguments.length == 1) {
setBeamFrequency(toInt(arguments[0]));
}
return new Integer[] { beamFrequency };
case 3: // getFirstHit()
} else if (methodName.equals("getFirstHit")) {
return getFirstHit();
case 4: // getBoosterDXDZ
} else if (methodName.equals("getBoosterDXDZ")) {
findFirstBooster();
return new Integer[] { dx, dz };
case 5: // camFreq (only for lasers with cam)
} else if (methodName.equals("camFreq")) { // camFreq (only for lasers with cam)
if (isWithCamera()) {
if (arguments.length == 1) {
setCameraFrequency(((Double)arguments[0]).intValue());
setCameraFrequency(toInt(arguments[0]));
}
return new Integer[] { cameraFrequency };
}

View file

@ -1,9 +1,13 @@
package cr0s.WarpDrive.machines;
import cpw.mods.fml.common.FMLCommonHandler;
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;
@ -12,9 +16,8 @@ import cr0s.WarpDrive.*;
import cr0s.WarpDrive.data.Vector3;
import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.peripheral.IComputerAccess;
import dan200.computercraft.api.peripheral.IPeripheral;
public class TileEntityLift extends WarpEnergyTE implements IPeripheral {
public class TileEntityLift extends WarpEnergyTE {
private static final int MODE_REDSTONE = -1;
private static final int MODE_INACTIVE = 0;
private static final int MODE_UP = 1;
@ -26,14 +29,17 @@ public class TileEntityLift extends WarpEnergyTE implements IPeripheral {
private boolean computerEnabled = true;
private int computerMode = MODE_REDSTONE;
private String[] methodsArray = {
"energy",
private int tickCount = 0;
public TileEntityLift() {
peripheralName = "warpdriveLaserLift";
methodsArray = new String[] {
"getEnergyLevel",
"mode",
"active",
"help"
};
int tickCount = 0;
}
@Override
public void updateEntity() {
@ -159,41 +165,27 @@ public class TileEntityLift extends WarpEnergyTE implements IPeripheral {
return Integer.MAX_VALUE;
}
@Override
public String getType() {
return "warpdriveLaserLift";
// OpenComputer callback methods
@Callback
@Optional.Method(modid = "OpenComputers")
private Object[] mode(Context context, Arguments arguments) {
return mode(argumentsOCtoCC(arguments));
}
@Override
public String[] getMethodNames() {
return methodsArray;
@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 };
}
public String helpStr(Object[] args) {
if (args.length == 1) {
String methodName = args[0].toString().toLowerCase();
if (methodName.equals("energy")) {
return WarpDrive.defEnergyStr;
} else if (methodName.equals("mode")) {
return "mode(\"up\" or \"down\" or \"redstone\"): sets the mode\nmode(): returns the current mode";
} else if (methodName.equals("active")) {
return "active(boolean): sets whether the laser is active\nactive(): returns whether the laser is active";
}
}
return WarpDrive.defHelpStr;
}
@Override
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] args) throws Exception {
String methodName = methodsArray[method];
if (methodName.equals("energy")) {
return getEnergyObject();
} else if (methodName.equals("mode")) {
if (args.length == 1) {
if (args[0].toString().equals("up")) {
private Object[] mode(Object[] arguments) {
if (arguments.length == 1) {
if (arguments[0].toString().equals("up")) {
computerMode = MODE_UP;
} else if(args[0].toString().equals("down")) {
} else if(arguments[0].toString().equals("down")) {
computerMode = MODE_DOWN;
} else {
computerMode = MODE_REDSTONE;
@ -207,34 +199,43 @@ public class TileEntityLift extends WarpEnergyTE implements IPeripheral {
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("getEnergyLevel")) {
return WarpDrive.defEnergyStr;
} else if (methodName.equals("mode")) {
return "mode(\"up\" or \"down\" or \"redstone\"): sets the mode\nmode(): returns the current mode";
} else if (methodName.equals("active")) {
return "active(boolean): sets whether the laser is active\nactive(): returns whether the laser is active";
}
}
return WarpDrive.defHelpStr;
}
// ComputerCraft IPeripheral methods implementation
@Override
@Optional.Method(modid = "ComputerCraft")
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] args) throws Exception {
String methodName = methodsArray[method];
if (methodName.equals("getEnergyLevel")) {
return getEnergyLevel();
} else if (methodName.equals("mode")) {
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) };
}
return null;
}
@Override
public void attach(IComputerAccess computer) {
}
@Override
public void detach(IComputerAccess computer) {
}
@Override
public int hashCode() {
return (((((super.hashCode() + worldObj.provider.dimensionId << 4) + xCoord) << 4) + yCoord) << 4) + zCoord;
}
@Override
public boolean equals(IPeripheral other) {
return other.hashCode() == hashCode();
}
}

View file

@ -1,14 +1,17 @@
package cr0s.WarpDrive.machines;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Optional;
import dan200.computercraft.api.ComputerCraftAPI;
import dan200.computercraft.api.peripheral.IComputerAccess;
import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.peripheral.IPeripheral;
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;
@ -33,7 +36,7 @@ import appeng.api.me.util.IMEInventoryHandler;
import cr0s.WarpDrive.*;
import cr0s.WarpDrive.data.Vector3;
public class TileEntityMiningLaser extends TileEntity implements IPeripheral, IGridMachine, ITileCable {
public class TileEntityMiningLaser extends WarpInterfacedTE implements IGridMachine, ITileCable {
private Boolean powerStatus = false;
private IGridInterface grid;
@ -45,15 +48,6 @@ public class TileEntityMiningLaser extends TileEntity implements IPeripheral, IG
private boolean enableSilktouch = false;
private boolean AENetworkReady = false;
private String[] methodsArray = {
"mine", //0
"stop", //1
"isMining", //2
"quarry", //3
"state", //4
"offset" //5
};
private int delayTicksWarmup = 0;
private int delayTicksScan = 0;
private int delayTicksMine = 0;
@ -70,6 +64,18 @@ public class TileEntityMiningLaser extends TileEntity implements IPeripheral, IG
private int layerOffset = 1;
public TileEntityMiningLaser() {
peripheralName = "mininglaser";
methodsArray = new String[] {
"mine", //0
"stop", //1
"isMining", //2
"quarry", //3
"state", //4
"offset" //5
};
}
@Override
public void updateEntity() {
if (FMLCommonHandler.instance().getEffectiveSide().isClient()) {
@ -572,7 +578,7 @@ public class TileEntityMiningLaser extends TileEntity implements IPeripheral, IG
}
}
private TileEntityParticleBooster findFirstBooster() {
private TileEntityParticleBooster findFirstBooster() {// FIXME: merge me...
TileEntity result;
result = worldObj.getBlockTileEntity(xCoord + 1, yCoord, zCoord);
@ -648,22 +654,45 @@ public class TileEntityMiningLaser extends TileEntity implements IPeripheral, IG
tag.setBoolean("enableSilktouch", enableSilktouch);
}
// ComputerCraft
// IPeripheral methods implementation
@Override
public String getType() {
return "mininglaser";
// OpenComputer callback methods
@Callback
@Optional.Method(modid = "OpenComputers")
private Object[] mine(Context context, Arguments arguments) {
return mine(argumentsOCtoCC(arguments));
}
@Override
public String[] getMethodNames() {
return methodsArray;
@Callback
@Optional.Method(modid = "OpenComputers")
private Object[] stop(Context context, Arguments arguments) {
stop();
return null;
}
@Override
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception {
switch (method) {
case 0: // Mine()
@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 };
}
@ -674,15 +703,9 @@ public class TileEntityMiningLaser extends TileEntity implements IPeripheral, IG
currentLayer = yCoord - layerOffset - 1;
enableSilktouch = (arguments.length == 1 && (WarpDriveConfig.ML_DEUTERIUM_MUL_SILKTOUCH <= 0 || FluidRegistry.isFluidRegistered("deuterium")));
return new Boolean[] { true };
}
case 1: // stop()
stop();
break;
case 2: // isMining()
return new Boolean[] { isMining() };
case 3: // Quarry()
private Object[] quarry(Object[] arguments) {
if (isMining()) {
return new Boolean[] { false };
}
@ -693,8 +716,9 @@ public class TileEntityMiningLaser extends TileEntity implements IPeripheral, IG
currentLayer = yCoord - layerOffset - 1;
enableSilktouch = (arguments.length == 1 && (WarpDriveConfig.ML_DEUTERIUM_MUL_SILKTOUCH <= 0 || FluidRegistry.isFluidRegistered("deuterium")));
return new Boolean[] { true };
}
case 4: // State is: state, energy, currentLayer, valuablesMined, valuablesInLayer = getMinerState()
private Object[] state(Object[] arguments) {
int energy = getEnergyLevel();
String status = getStatus();
Integer retValuablesInLayer, retValuablesMined;
@ -705,17 +729,54 @@ public class TileEntityMiningLaser extends TileEntity implements IPeripheral, IG
return new Object[] {status, energy, currentLayer, retValuablesMined, retValuablesInLayer};
}
return new Object[] {status, energy, currentLayer, 0, 0};
}
case 5: // Offset
private Object[] offset(Object[] arguments) {
if (arguments.length == 1) {
try {
layerOffset = Math.min(256, Math.abs(((Double)arguments[0]).intValue()));
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
public void attach(IComputerAccess computer) {
super.attach(computer);
if (WarpDriveConfig.G_LUA_SCRIPTS != WarpDriveConfig.LUA_SCRIPTS_NONE) {
computer.mount("/mininglaser", ComputerCraftAPI.createResourceMount(WarpDrive.class, "warpdrive", "lua/mininglaser"));
if (WarpDriveConfig.G_LUA_SCRIPTS == WarpDriveConfig.LUA_SCRIPTS_ALL) {
computer.mount("/mine", ComputerCraftAPI.createResourceMount(WarpDrive.class, "warpdrive", "lua/mininglaser/mine"));
computer.mount("/stop", ComputerCraftAPI.createResourceMount(WarpDrive.class, "warpdrive", "lua/mininglaser/stop"));
}
}
}
@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("mine")) {
return mine(arguments);
} else if (methodName.equals("stop")) {
stop();
} else if (methodName.equals("isMining")) {
return new Boolean[] { isMining() };
} else if (methodName.equals("quarry")) {
return quarry(arguments);
} else if (methodName.equals("state")) { // State is: state, energy, currentLayer, valuablesMined, valuablesInLayer = getMinerState()
return state(arguments);
} else if (methodName.equals("offset")) {
return offset(arguments);
}
return null;
}
@ -751,28 +812,7 @@ public class TileEntityMiningLaser extends TileEntity implements IPeripheral, IG
return state;
}
@Override
public void attach(IComputerAccess computer) {
if (WarpDriveConfig.G_LUA_SCRIPTS != WarpDriveConfig.LUA_SCRIPTS_NONE) {
computer.mount("/mininglaser", ComputerCraftAPI.createResourceMount(WarpDrive.class, "warpdrive", "lua/mininglaser"));
if (WarpDriveConfig.G_LUA_SCRIPTS == WarpDriveConfig.LUA_SCRIPTS_ALL) {
computer.mount("/mine", ComputerCraftAPI.createResourceMount(WarpDrive.class, "warpdrive", "lua/mininglaser/mine"));
computer.mount("/stop", ComputerCraftAPI.createResourceMount(WarpDrive.class, "warpdrive", "lua/mininglaser/stop"));
}
}
}
@Override
public void detach(IComputerAccess computer) {
}
@Override
public boolean equals(IPeripheral other) {
return other == this;
}
// Applied Energistics @Override
// Applied Energistics
@Override
public float getPowerDrainPerTick() {
return 1;

View file

@ -1,31 +1,36 @@
package cr0s.WarpDrive.machines;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Optional;
import cr0s.WarpDrive.PacketHandler;
import cr0s.WarpDrive.WarpDrive;
import dan200.computercraft.api.peripheral.IComputerAccess;
import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.peripheral.IPeripheral;
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;
import net.minecraft.tileentity.TileEntity;
public class TileEntityMonitor extends TileEntity implements IPeripheral {
public class TileEntityMonitor extends WarpInterfacedTE {
private int frequency = -1;
private String[] methodsArray =
{
"freq"
};
private final static int PACKET_SEND_INTERVAL_TICKS = 60 * 20;
private int packetSendTicks = 20;
public TileEntityMonitor() {
peripheralName = "monitor";
methodsArray = new String[] {
"freq"
};
}
@Override
public void updateEntity() {
if (FMLCommonHandler.instance().getEffectiveSide().isServer()) {
@ -63,36 +68,28 @@ public class TileEntityMonitor extends TileEntity implements IPeripheral {
tag.setInteger("frequency", frequency);
}
// IPeripheral methods implementation
@Override
public String getType() {
return "monitor";
}
@Override
public String[] getMethodNames() {
return methodsArray;
}
@Override
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception {
if (arguments.length == 1) {
setFrequency(((Double)arguments[0]).intValue());
// 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
public void attach(IComputerAccess computer) {
@Optional.Method(modid = "ComputerCraft")
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception {
String methodName = methodsArray[method];
if (methodName.equals("freq")) {
if (arguments.length == 1) {
setFrequency(toInt(arguments[0]));
}
@Override
public void detach(IComputerAccess computer) {
return new Integer[] { frequency };
}
@Override
public boolean equals(IPeripheral other) {
return other == this;
return null;
}
@Override

View file

@ -1,13 +1,16 @@
package cr0s.WarpDrive.machines;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Optional;
import dan200.computercraft.api.ComputerCraftAPI;
import dan200.computercraft.api.peripheral.IComputerAccess;
import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.peripheral.IPeripheral;
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;
@ -19,8 +22,7 @@ import cr0s.WarpDrive.machines.TileEntityReactor.ReactorMode;
* Protocol block tile entity
* @author Cr0s
*/
public class TileEntityProtocol extends TileEntity implements IPeripheral
{
public class TileEntityProtocol extends WarpInterfacedTE {
// Variables
private int distance = 0;
private int direction = 0;
@ -44,29 +46,37 @@ public class TileEntityProtocol extends TileEntity implements IPeripheral
boolean ready = false; // Ready to operate (valid assembly)
public String[] methodsArray = {
"dim_getp", "dim_setp",
"dim_getn", "dim_setn",
"set_mode",
"set_distance", "set_direction",
"get_attached_players", "summon", "summon_all",
"get_x", "get_y", "get_z",
"get_energy_level", /* "get_energy_max",/**/
"do_jump",
"get_ship_size",
"set_beacon_frequency",
"get_dx", "get_dz",
"set_core_frequency",
"is_in_space", "is_in_hyperspace",
"set_target_jumpgate",
"isAttached", "get_energy_required"
};
private int ticks = 0;
private final int BLOCK_UPDATE_INTERVAL = 20 * 3; // 3 seconds
private TileEntityReactor core = null;
public TileEntityProtocol() {
peripheralName = "warpcore";
methodsArray = new String[] {
"dim_positive",
"dim_negative",
"mode",
"distance",
"direction",
"getAttachedPlayers",
"summon",
"summonAll",
"pos",
"getEnergyLevel",
"jump",
"getShipSize",
"beaconFrequency",
"getOrientation",
"coreFrequency",
"isInSpace",
"isInHyperspace",
"targetJumpgate",
"isAttached",
"getEnergyRequired"
};
}
@Override
public void updateEntity() {
if (FMLCommonHandler.instance().getEffectiveSide().isClient()) {
@ -224,90 +234,96 @@ public class TileEntityProtocol extends TileEntity implements IPeripheral
}
/**
* @return the front
* @return front size
*/
public int getFront() {
return front;
}
/**
* @param front the front to set
* @param front new front size
* @return front size
*/
public void setFront(int front) {
private void setFront(int front) {
this.front = front;
}
/**
* @return the right
* @return right size
*/
public int getRight() {
return right;
}
/**
* @param right the right to set
* @param right new right size
* @return right size
*/
public void setRight(int right) {
private void setRight(int right) {
this.right = right;
}
/**
* @return the up
* @return up size
*/
public int getUp() {
return up;
}
/**
* @param up the up to set
* @param up new up size
* @return up size
*/
public void setUp(int up) {
private void setUp(int up) {
this.up = up;
}
/**
* @return the back
* @return back size
*/
public int getBack() {
return back;
}
/**
* @param back the back to set
* @param back new back size
* @return back size
*/
public void setBack(int back) {
private void setBack(int back) {
this.back = back;
}
/**
* @return the left
* @return left size
*/
public int getLeft() {
return left;
}
/**
* @param left the left to set
* @param left new left size
* @return left size
*/
public void setLeft(int left) {
private void setLeft(int left) {
this.left = left;
}
/**
* @return the down
* @return down size
*/
public int getDown() {
return down;
}
/**
* @param down the down to set
* @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);
}
@ -317,7 +333,7 @@ public class TileEntityProtocol extends TileEntity implements IPeripheral
}
/**
* @return the mode
* @return current reactor mode
*/
public ReactorMode getMode() {
return mode;
@ -338,37 +354,12 @@ public class TileEntityProtocol extends TileEntity implements IPeripheral
}
/**
* @param summonFlag the summonFlag to set
* @param summonFlag to set
*/
public void setSummonAllFlag(boolean summonFlag) {
this.summonFlag = summonFlag;
}
@Override
public String getType() {
return "warpcore";
}
@Override
public String[] getMethodNames() {
return methodsArray;
}
@Override
public void attach(IComputerAccess computer) {
if (WarpDriveConfig.G_LUA_SCRIPTS != WarpDriveConfig.LUA_SCRIPTS_NONE) {
computer.mount("/warpcontroller", ComputerCraftAPI.createResourceMount(WarpDrive.class, "warpdrive", "lua/warpcontroller"));
computer.mount("/warpupdater", ComputerCraftAPI.createResourceMount(WarpDrive.class, "warpdrive", "lua/common/updater"));
if (WarpDriveConfig.G_LUA_SCRIPTS == WarpDriveConfig.LUA_SCRIPTS_ALL) {
computer.mount("/startup", ComputerCraftAPI.createResourceMount(WarpDrive.class, "warpdrive", "lua/warpcontroller/startup"));
}
}
}
@Override
public void detach(IComputerAccess computer) {
}
/**
* @return the toSummon
*/
@ -424,188 +415,281 @@ public class TileEntityProtocol extends TileEntity implements IPeripheral
return null;
}
@Override
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception {
// 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;
String methodName = methodsArray[method];
if (methodName.equals("dim_getp")) {
return new Integer[] { getFront(), getRight(), getUp() };
} else if (methodName.equals("dim_setp")) {// dim_setp (front, right, up)
if (arguments.length != 3) {
return new Integer[] { getFront(), getRight(), getUp() };
}
try {
argInt0 = ((Double) arguments[0]).intValue();
argInt1 = ((Double) arguments[1]).intValue();
argInt2 = ((Double) arguments[2]).intValue();
} catch (Exception e) {
return new Integer[] { getFront(), getRight(), getUp() };
}
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(((Double) arguments[0]).intValue());
setRight(((Double) arguments[1]).intValue());
setUp(((Double) arguments[2]).intValue());
setFront(argInt0);
setRight(argInt1);
setUp(argInt2);
}
} catch (Exception e) {
return new Integer[] { getFront(), getRight(), getUp() };
}
return new Integer[] { getFront(), getRight(), getUp() };
} else if (methodName.equals("dim_getn")) {
return new Integer[] { getBack(), getLeft(), getDown() };
} else if (methodName.equals("dim_setn")) {// dim_setn (back, left, down)
if (arguments.length != 3) {
return new Integer[] { -1 };
}
private Object[] dim_negative(Object[] arguments) {
try {
argInt0 = ((Double) arguments[0]).intValue();
argInt1 = ((Double) arguments[1]).intValue();
argInt2 = ((Double) arguments[2]).intValue();
} catch (Exception e) {
return new Integer[] { getBack(), getLeft(), getDown() };
}
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() };
} else if (methodName.equals("set_mode")) {// set_mode (mode)
if (arguments.length != 1) {
return new Integer[] { -1 };
}
private Object[] mode(Object[] arguments) {
try {
argInt0 = ((Double) arguments[0]).intValue();
if (arguments.length == 1) {
setMode(toInt(arguments[0]));
}
} catch (Exception e) {
return new Integer[] { -1 };
return new Integer[] { mode.getCode() };
}
setMode(argInt0);
} else if (methodName.equals("set_distance")) {// set_distance (distance)
if (arguments.length != 1) {
return new Integer[] { -1 };
return new Integer[] { mode.getCode() };
}
private Object[] distance(Object[] arguments) {
try {
argInt0 = ((Double) arguments[0]).intValue();
} catch (Exception e) {
return new Integer[] { -1 };
if (arguments.length == 1) {
setDistance(toInt(arguments[0]));
}
} catch (Exception e) {
return new Integer[] { getDistance() };
}
setDistance(argInt0);
return new Integer[] { getDistance() };
} else if (methodName.equals("set_direction")) {// set_direction (dir)
if (arguments.length != 1) {
return new Integer[] { -1 };
}
private Object[] direction(Object[] arguments) {
try {
argInt0 = ((Double) arguments[0]).intValue();
if (arguments.length == 1) {
setDirection(toInt(arguments[0]));
}
} catch (Exception e) {
return new Integer[] { -1 };
return new Integer[] { getDirection() };
}
setDirection(argInt0);
return new Integer[] { getDirection() };
}
} else if (methodName.equals("get_attached_players")) {// get_attached_players
private Object[] getAttachedPlayers(Object[] arguments) {
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()) {
for (int i = 0; i < players.size(); i++) {
String nick = players.get(i);
list += nick + ((i == players.size() - 1) ? "" : ",");
}
}
if (players.isEmpty()) {
list = "";
return new Object[] { list, players };
}
return new Object[] { list };
} else if (methodName.equals("summon")) {// summon
private Object[] summon(Object[] arguments) {
int playerIndex = -1;
if (arguments.length != 1) {
return new Integer[] { -1 };
return new Object[] { false };
}
try {
argInt0 = ((Double) arguments[0]).intValue();
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 };
}
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
if (core == null) {
return null;
}
return new Object[] { core.xCoord };
} else if (methodName.equals("get_y")) {// get_y
if (core == null) {
return null;
}
return new Object[] { core.yCoord };
} else if (methodName.equals("get_z")) {// get_z
if (core == null) {
return null;
}
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 = ((Double) arguments[0]).intValue();
} 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
doJump();
} else if (methodName.equals("get_ship_size")) {// get_ship_size
if (core != null) {
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) {
@ -615,38 +699,116 @@ public class TileEntityProtocol extends TileEntity implements IPeripheral
}
}
} else if (methodName.equals("set_beacon_frequency")) {// set_beacon_frequency
if (arguments.length != 1) {
return new Integer[] { -1 };
}
private Object[] beaconFrequency(Object[] arguments) {
if (arguments.length == 1) {
setBeaconFrequency((String) arguments[0]);
} else if (methodName.equals("get_dx")) {// get_dx
if (core != null) {
return new Object[] { core.dx };
}
return new Object[] { beaconFrequency };
}
} else if (methodName.equals("get_dz")) {// get_dz
if (core != null) {
return new Object[] { core.dz };
private Object[] coreFrequency(Object[] arguments) {
if (core == null) {
return null;
}
} else if (methodName.equals("set_core_frequency")) {// set_core_frequency
if (arguments.length == 1 && (core != null)) {
if (arguments.length == 1) {
core.coreFrequency = ((String) arguments[0]).replace("/", "").replace(".", "").replace("\\", ".");
}
return new Object[] { core.coreFrequency };
}
} else if (methodName.equals("is_in_space")) {// is_in_space
return new Boolean[] { worldObj.provider.dimensionId == WarpDriveConfig.G_SPACE_DIMENSION_ID };
} else if (methodName.equals("is_in_hyperspace")) {// is_in_hyperspace
return new Boolean[] { worldObj.provider.dimensionId == WarpDriveConfig.G_HYPERSPACE_DIMENSION_ID };
} else if (methodName.equals("set_target_jumpgate")) {// set_target_jumpgate
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")
public void attach(IComputerAccess computer) {
super.attach(computer);
if (WarpDriveConfig.G_LUA_SCRIPTS != WarpDriveConfig.LUA_SCRIPTS_NONE) {
computer.mount("/warpcontroller", ComputerCraftAPI.createResourceMount(WarpDrive.class, "warpdrive", "lua/warpcontroller"));
computer.mount("/warpupdater", ComputerCraftAPI.createResourceMount(WarpDrive.class, "warpdrive", "lua/common/updater"));
if (WarpDriveConfig.G_LUA_SCRIPTS == WarpDriveConfig.LUA_SCRIPTS_ALL) {
computer.mount("/startup", ComputerCraftAPI.createResourceMount(WarpDrive.class, "warpdrive", "lua/warpcontroller/startup"));
}
}
}
@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("dim_positive")) {// dim_positive (front, right, up)
return dim_positive(arguments);
} else if (methodName.equals("dim_negative")) {// dim_negative (back, left, down)
return dim_negative(arguments);
} else if (methodName.equals("mode")) {// mode (mode)
return mode(arguments);
} else if (methodName.equals("distance")) {// distance (distance)
return distance(arguments);
} else if (methodName.equals("direction")) {// direction (direction)
return direction(arguments);
} else if (methodName.equals("getAttachedPlayers")) {
return getAttachedPlayers(arguments);
} else if (methodName.equals("summon")) {
return summon(arguments);
} else if (methodName.equals("summon_all")) {
setSummonAllFlag(true);
} else if (methodName.equals("pos")) {
if (core == null) {
return null;
}
return new Object[] { core.xCoord, core.yCoord, core.zCoord };
} else if (methodName.equals("getEnergyLevel")) {
if (core == null) {
return null;
}
return core.getEnergyLevel();
} else if (methodName.equals("getEnergyRequired")) {// getEnergyRequired(distance)
return getEnergyRequired(arguments);
} else if (methodName.equals("jump")) {
doJump();
} else if (methodName.equals("getShipSize")) {
return getShipSize(arguments);
} else if (methodName.equals("beaconFrequency")) {
return beaconFrequency(arguments);
} else if (methodName.equals("getOrientation")) {
if (core != null) {
return new Object[] { core.dx, 0, core.dz };
}
return null;
} else if (methodName.equals("coreFrequency")) {
return coreFrequency(arguments);
} else if (methodName.equals("isInSpace")) {
return new Boolean[] { worldObj.provider.dimensionId == WarpDriveConfig.G_SPACE_DIMENSION_ID };
} else if (methodName.equals("isInHyperspace")) {
return new Boolean[] { worldObj.provider.dimensionId == WarpDriveConfig.G_HYPERSPACE_DIMENSION_ID };
} else if (methodName.equals("targetJumpgate")) {
return targetJumpgate(arguments);
} else if (methodName.equals("isAttached")) {// isAttached
if (core != null) {
@ -668,14 +830,8 @@ public class TileEntityProtocol extends TileEntity implements IPeripheral
/**
* @param targetJumpgateName the targetJumpgateName to set
*/
public void setTargetJumpgateName(String targetJumpgateName)
{
this.targetJumpgateName = targetJumpgateName;
}
@Override
public boolean equals(IPeripheral other) {
return other == this;
public void setTargetJumpgateName(String parTargetJumpgateName) {
targetJumpgateName = parTargetJumpgateName;
}
@Override

View file

@ -1,33 +1,37 @@
package cr0s.WarpDrive.machines;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Optional;
import dan200.computercraft.api.ComputerCraftAPI;
import dan200.computercraft.api.peripheral.IComputerAccess;
import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.peripheral.IPeripheral;
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.*;
public class TileEntityRadar extends WarpEnergyTE implements IPeripheral {
private String[] methodsArray =
{
"scanRay", // 0
"scanRadius", // 1
"getResultsCount", // 2
"getResult", // 3
"getEnergyLevel", // 4
"pos" // 5
};
public class TileEntityRadar extends WarpEnergyTE {
private ArrayList<TileEntityReactor> results;
private int scanRadius = 0;
private int cooldownTime = 0;
public TileEntityRadar() {
peripheralName = "radar";
methodsArray = new String[] {
"scanRadius",
"getResultsCount",
"getResult",
"getEnergyLevel",
"pos"
};
}
@Override
public void updateEntity() {
if (FMLCommonHandler.instance().getEffectiveSide().isClient()) {
@ -61,24 +65,35 @@ public class TileEntityRadar extends WarpEnergyTE implements IPeripheral {
super.writeToNBT(tag);
}
// IPeripheral methods implementation
@Override
public String getType() {
return "radar";
// OpenComputer callback methods
@Callback
@Optional.Method(modid = "OpenComputers")
private Object[] scanRadius(Context context, Arguments arguments) {
return scanRadius(argumentsOCtoCC(arguments));
}
@Override
public String[] getMethodNames() {
return methodsArray;
@Callback
@Optional.Method(modid = "OpenComputers")
private Object[] getResultsCount(Context context, Arguments arguments) {
if (results != null) {
return new Integer[] { results.size() };
}
return new Integer[] { -1 };
}
@Override
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception {
switch (method) {
case 0: // scanRay (toX, toY, toZ)
return new Object[] { -1 };
@Callback
@Optional.Method(modid = "OpenComputers")
private Object[] getResult(Context context, Arguments arguments) {
return getResult(argumentsOCtoCC(arguments));
}
case 1: // scanRadius (radius)
@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;
@ -88,7 +103,7 @@ public class TileEntityRadar extends WarpEnergyTE implements IPeripheral {
}
int radius;
try {
radius = ((Double)arguments[0]).intValue();
radius = toInt(arguments[0]);
} catch(Exception e) {
return new Boolean[] { false };
}
@ -107,18 +122,12 @@ public class TileEntityRadar extends WarpEnergyTE implements IPeripheral {
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 2, 1 + 2);
}
return new Boolean[] { true };
case 2: // getResultsCount
if (results != null) {
return new Integer[] { results.size() };
}
return new Integer[] { -1 };
case 3: // getResult
private Object[] getResult(Object[] arguments) {
if (arguments.length == 1 && (results != null)) {
int index;
try {
index = ((Double)arguments[0]).intValue();
index = toInt(arguments[0]);
} catch(Exception e) {
return new Object[] { "FAIL", 0, 0, 0 };
}
@ -132,19 +141,12 @@ public class TileEntityRadar extends WarpEnergyTE implements IPeripheral {
}
}
return new Object[] { "FAIL", 0, 0, 0 };
case 4: // getEnergyLevel
return new Integer[] { getEnergyStored() };
case 5: // Pos
return new Integer[] { xCoord, yCoord, zCoord };
}
return null;
}
// ComputerCraft IPeripheral methods implementation
@Override
public void attach(IComputerAccess computer) {
super.attach(computer);
if (WarpDriveConfig.G_LUA_SCRIPTS != WarpDriveConfig.LUA_SCRIPTS_NONE) {
computer.mount("/radar", ComputerCraftAPI.createResourceMount(WarpDrive.class, "warpdrive", "lua/radar"));
computer.mount("/warpupdater", ComputerCraftAPI.createResourceMount(WarpDrive.class, "warpdrive", "lua/common/updater"));
@ -160,9 +162,36 @@ public class TileEntityRadar extends WarpEnergyTE implements IPeripheral {
@Override
public void detach(IComputerAccess computer) {
super.detach(computer);
// worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 0, 1 + 2);
}
@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("scanRadius")) {// scanRadius (radius)
return scanRadius(arguments);
} else if (methodName.equals("getResultsCount")) {
if (results != null) {
return new Integer[] { results.size() };
}
return new Integer[] { -1 };
} else if (methodName.equals("getResult")) {
return getResult(arguments);
} else if (methodName.equals("getEnergyLevel")) {
return getEnergyLevel();
} else if (methodName.equals("pos")) {
return new Integer[] { xCoord, yCoord, zCoord };
}
return null;
}
@Override
public int getMaxEnergyStored() {
return WarpDriveConfig.WR_MAX_ENERGY_VALUE;
@ -174,11 +203,6 @@ public class TileEntityRadar extends WarpEnergyTE implements IPeripheral {
return Integer.MAX_VALUE;
}
@Override
public boolean equals(IPeripheral other) {
return other == this;
}
@Override
public boolean canInputEnergy(ForgeDirection from) {
return true;

View file

@ -72,7 +72,7 @@ public class TileEntityReactor extends WarpEnergyTE
public int randomWarmupAddition = 0;
private int chestTeleportUpdateTicks = 0;
private int registryUpdateTicks = 0;
private int registryUpdateTicks = 15;
public String coreFrequency = "default";
public int isolationBlocksCount = 0;

View file

@ -1,18 +1,21 @@
package cr0s.WarpDrive.machines;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Optional;
import cr0s.WarpDrive.*;
import cr0s.WarpDrive.data.JumpBlock;
import cr0s.WarpDrive.data.Vector3;
import dan200.computercraft.api.peripheral.IComputerAccess;
import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.peripheral.IPeripheral;
import ic2.api.energy.tile.IEnergyTile;
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;
@ -25,8 +28,8 @@ import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
import net.minecraftforge.common.ForgeDirection;
public class TileEntityShipScanner extends WarpEnergyTE implements IPeripheral {
private int state = 0; // 0 - inactive, 1 - active
public class TileEntityShipScanner extends WarpEnergyTE {
private boolean isActive = false;
private TileEntityReactor core = null;
int laserTicks = 0;
@ -35,13 +38,6 @@ public class TileEntityShipScanner extends WarpEnergyTE implements IPeripheral {
int warpCoreSearchTicks = 0;
private String[] methodsArray = {
"scan", // 0
"fileName", // 1
"energy", // 2
"deploy" // 3 deployShipFromSchematic(file, offsetX, offsetY, offsetZ)
};
private String schematicFileName;
private JumpBlock[] blocksToDeploy; // JumpBlock class stores a basic information about block
@ -51,6 +47,16 @@ public class TileEntityShipScanner extends WarpEnergyTE implements IPeripheral {
private int targetX, targetY, targetZ;
public TileEntityShipScanner() {
peripheralName = "shipscanner";
methodsArray = new String[] {
"scan",
"fileName",
"getEnergyLevel",
"deploy",
"state"
};
}
@Override
public void updateEntity() {
@ -66,18 +72,18 @@ public class TileEntityShipScanner extends WarpEnergyTE implements IPeripheral {
// 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;
@ -125,10 +131,10 @@ public class TileEntityShipScanner extends WarpEnergyTE implements IPeripheral {
}
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;
@ -138,7 +144,7 @@ public class TileEntityShipScanner extends WarpEnergyTE implements IPeripheral {
if (blocks == 0) {
isDeploying = false;
switchState(0);
setActive(false); // disable scanner
return;
}
@ -147,7 +153,7 @@ public class TileEntityShipScanner extends WarpEnergyTE implements IPeripheral {
if (currentDeployIndex >= blocksToDeployCount)
{
isDeploying = false;
switchState(0);
setActive(false); // disable scanner
break;
}
@ -175,10 +181,10 @@ public class TileEntityShipScanner extends WarpEnergyTE implements IPeripheral {
}
}
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);
}
}
@ -359,7 +365,7 @@ public class TileEntityShipScanner extends WarpEnergyTE implements IPeripheral {
// 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();
@ -523,7 +529,7 @@ public class TileEntityShipScanner extends WarpEnergyTE implements IPeripheral {
}
}
switchState(1);
setActive(true);
reason.append("Ship deploying...");
return 3;
}
@ -538,25 +544,29 @@ public class TileEntityShipScanner extends WarpEnergyTE implements IPeripheral {
super.writeToNBT(tag);
}
// CC
// IPeripheral methods implementation
@Override
public String getType() {
return "shipscanner";
// OpenComputer callback methods
@Callback
@Optional.Method(modid = "OpenComputers")
private Object[] scan(Context context, Arguments arguments) {
return scan(argumentsOCtoCC(arguments));
}
@Override
public String[] getMethodNames() {
return methodsArray;
@Callback
@Optional.Method(modid = "OpenComputers")
private Object[] filename(Context context, Arguments arguments) {
return filename(argumentsOCtoCC(arguments));
}
@Override
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception {
switch (method) {
case 0: // scanShip()
@Callback
@Optional.Method(modid = "OpenComputers")
private Object[] deploy(Context context, Arguments arguments) {
return deploy(argumentsOCtoCC(arguments));
}
private Object[] scan(Object[] arguments) {
// Already scanning?
if (this.state == 1) {
return new Object[] { false, 0, "Already scanning" };
if (isActive) {
return new Object[] { false, 0, "Already active" };
}
if (core == null) {
@ -568,24 +578,26 @@ public class TileEntityShipScanner extends WarpEnergyTE implements IPeripheral {
boolean success = scanShip(reason);
return new Object[] { success, 3, reason.toString() };
}
// break;
}
case 1: // getSchematicFileName()
if (state != 0 && !schematicFileName.isEmpty()) {
return new Object[] { "Scanning in process. Please wait..." };
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 };
}
case 2: // getEnergyLevel()
return new Object[] { getEnergyStored() };
case 3: // deployShipFromSchematic(schematicFileName, offsetX, offsetY, offsetZ)
private Object[] deploy(Object[] arguments) {
if (arguments.length == 4) {
String fileName = (String)arguments[0];
int x = ((Double)arguments[1]).intValue();
int y = ((Double)arguments[2]).intValue();
int z = ((Double)arguments[3]).intValue();
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!" };
@ -599,17 +611,40 @@ public class TileEntityShipScanner extends WarpEnergyTE implements IPeripheral {
}
}
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")) {
return scan(arguments);
} else if (methodName.equals("fileName")) {
return filename(arguments);
} else if (methodName.equals("getEnergyLevel")) {
return getEnergyLevel();
} else if (methodName.equals("deploy")) {// deploy(schematicFileName, offsetX, offsetY, offsetZ)
return deploy(arguments);
} else if (methodName.equals("state")) {
return state(arguments);
}
return null;
}
@Override
public void attach(IComputerAccess computer) {
}
@Override
public void detach(IComputerAccess computer) {
}
// IEnergySink methods implementation
@Override
public int getMaxEnergyStored() {
@ -625,9 +660,4 @@ public class TileEntityShipScanner extends WarpEnergyTE implements IPeripheral {
public boolean canInputEnergy(ForgeDirection from) {
return true;
}
@Override
public boolean equals(IPeripheral other) {
return other == this;
}
}

View file

@ -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;
@ -16,7 +20,7 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.common.MinecraftForge;
public abstract class WarpEnergyTE extends WarpTE implements IEnergyHandler, IEnergySink, IEnergySource, IBlockUpdateDetector {
public abstract class WarpEnergyTE extends WarpInterfacedTE implements IEnergyHandler, IEnergySink, IEnergySource, IBlockUpdateDetector {
protected boolean addedToEnergyNet = false;
protected int energyStored_internal = 0;
private static final double EU_PER_INTERNAL = 1.0D;
@ -139,7 +143,7 @@ public abstract class WarpEnergyTE extends WarpTE implements IEnergyHandler, IEn
return temp;
}
public Object[] getEnergyObject() {
public Object[] getEnergyLevel() {
return new Object[] { getEnergyStored(), getMaxEnergyStored() };
}
@ -151,6 +155,12 @@ public abstract class WarpEnergyTE extends WarpTE implements IEnergyHandler, IEn
}
}
// OpenComputer callback methods
@Callback
@Optional.Method(modid = "OpenComputers")
private Object[] getEnergyLevel(Context context, Arguments arguments) {
return getEnergyLevel();
}
// Minecraft overrides
@Override

View file

@ -100,6 +100,11 @@ public abstract class WarpInterfacedTE extends WarpTE implements IPeripheral, En
}
}
@Override
public int hashCode() {
return (((((super.hashCode() + worldObj.provider.dimensionId << 4) + xCoord) << 4) + yCoord) << 4) + zCoord;
}
// Dirty cheap conversion methods
protected Object[] argumentsOCtoCC(Arguments args) {
Object[] arguments = new Object[args.count()];
@ -151,9 +156,10 @@ public abstract class WarpInterfacedTE extends WarpTE implements IPeripheral, En
@Optional.Method(modid = "ComputerCraft")
public boolean equals(IPeripheral other) {
// WarpDrive.debugPrint("WarpInterfacedTE.equals");
return other == this;
return other.hashCode() == hashCode();
}
// Computer abstraction methods
protected void sendEvent(String eventName, Object[] arguments) {
// WarpDrive.debugPrint("" + this + " Sending event '" + eventName + "'");
if (WarpDriveConfig.isCCLoaded) {