Merging OpenComputer support and API cleanup

Renamed energy to getEnergyLevel in ChunkLoader, Transporter and
PowerStore API
Updated PowerReactor API:
- active replaces getActive and setActive
This commit is contained in:
LemADEC 2014-10-05 19:33:50 +02:00
parent 17da2fb627
commit 9a8b4818b5
6 changed files with 218 additions and 299 deletions

View file

@ -447,8 +447,8 @@ function cloaking_page()
SetColorDefault()
Write("Cloaking core " .. cloaking_currentKey .. " of " .. #cloakingcores)
local isAssemblyValid = cloakingcore.isAssemblyValid()
local energy = cloakingcore.getEnergyLevel()
local isEnabled = true -- cloakingcore.isEnabled()
local energy, energyMax = cloakingcore.getEnergyLevel()
local isEnabled = cloakingcore.enable()
if not isAssemblyValid then
SetColorWarning()
@ -508,19 +508,19 @@ end
function cloaking_start()
for key,cloakingcore in pairs(cloakingcores) do
cloakingcore.disableCloakingField()
cloakingcore.enable(false)
if cloaking_highTier then
cloakingcore.setFieldTier(2)
cloakingcore.tier(2)
else
cloakingcore.setFieldTier(1)
cloakingcore.tier(1)
end
cloakingcore.enableCloakingField()
cloakingcore.enable(true)
end
end
function cloaking_stop()
for key,cloakingcore in pairs(cloakingcores) do
cloakingcore.disableCloakingField()
cloakingcore.enable(false)
end
end
@ -720,7 +720,7 @@ function data_setName()
label = readInputText(label)
os.setComputerLabel(label)
if warpcore ~= nil then
warpcore.set_core_frequency(label)
warpcore.coreFrequency(label)
end
os.reboot()
end
@ -753,15 +753,14 @@ function core_boot()
Write(".")
core_front, core_right, core_up = warpcore.dim_getp()
core_back, core_left, core_down = warpcore.dim_getn()
core_isInHyper = warpcore.is_in_hyperspace()
core_isInHyper = warpcore.isInHyperspace()
Write(".")
repeat
X = warpcore.get_x()
pos = warpcore.pos()
sleep(0.3)
until X ~= nil
Y = warpcore.get_y()
Z = warpcore.get_z()
until pos ~= nil
X, Y, Z = warpcore.pos()
Write(".")
repeat
isAttached = warpcore.isAttached()
@ -770,7 +769,7 @@ function core_boot()
Write(".")
repeat
core_shipSize = warpcore.get_ship_size()
core_shipSize = warpcore.getShipSize()
sleep(0.3)
until core_shipSize ~= nil
@ -778,7 +777,7 @@ function core_boot()
core_computeRealDistance()
Write(".")
warpcore.set_mode(1)
warpcore.mode(1)
WriteLn("")
end
@ -823,8 +822,7 @@ function core_computeNewCoordinates(cx, cy, cz)
elseif data.core_direction == 2 then
res.y = res.y - core_realDistance
end
local dx = warpcore.get_dx()
local dz = warpcore.get_dz()
local dx, dy, dz = warpcore.getOrientation()
if dx ~= 0 then
if data.core_direction == 0 then
res.x = res.x + (core_realDistance * dx)
@ -853,14 +851,14 @@ function core_warp()
rs.setOutput(alarm_side, true)
if readConfirmation() then
rs.setOutput(alarm_side, false)
warpcore.set_direction(data.core_direction)
warpcore.set_distance(data.core_distance)
warpcore.direction(data.core_direction)
warpcore.distance(data.core_distance)
if core_isInHyper then
warpcore.set_mode(2)
warpcore.mode(2)
else
warpcore.set_mode(1)
warpcore.mode(1)
end
warpcore.do_jump()
warpcore.jump()
end
rs.setOutput(alarm_side, false)
end
@ -936,17 +934,17 @@ function core_page_setDimensions()
Write(" Down (".. core_down ..") : ")
core_down = readInputNumber(core_down)
Write("Setting dimensions...")
warpcore.dim_setp(core_front, core_right, core_up)
warpcore.dim_setn(core_back, core_left, core_down)
core_shipSize = warpcore.get_ship_size()
warpcore.dim_positive(core_front, core_right, core_up)
warpcore.dim_negative(core_back, core_left, core_down)
core_shipSize = warpcore.getShipSize()
if core_shipSize == nil then core_shipSize = 0 end
end
function core_page_summon()
ShowTitle("<==== Summon players ====>")
local players = Explode(",", warpcore.get_attached_players())
for i = 1, #players do
Show(i..". "..players[i])
local playersString, playersArray = warpcore.getAttachedPlayers()
for i = 1, #playersArray do
Show(i..". "..playersArray[i])
end
SetColorTitle()
ShowMenu("Enter player number")
@ -971,9 +969,9 @@ function core_page_jumpToBeacon()
rs.setOutput(alarm_side, true)
if readConfirmation() then
rs.setOutput(alarm_side, false)
warpcore.set_mode(4)
warpcore.set_beacon_frequency(freq)
warpcore.do_jump()
warpcore.mode(4)
warpcore.beaconFrequency(freq)
warpcore.jump()
end
rs.setOutput(alarm_side, false)
end
@ -986,9 +984,9 @@ function core_page_jumpToGate()
rs.setOutput(alarm_side, true)
if readConfirmation() then
rs.setOutput(alarm_side, false)
warpcore.set_mode(6)
warpcore.set_target_jumpgate(name)
warpcore.do_jump()
warpcore.mode(6)
warpcore.targetJumpgate(name)
warpcore.jump()
end
rs.setOutput(alarm_side, false)
end
@ -998,17 +996,13 @@ function core_page()
if warpcore ~= nil then
WriteLn("Core:")
WriteLn(" x, y, z = " .. X .. ", " .. Y .. ", " .. Z)
local energy = warpcore.get_energy_level()
local energy, energyMax = warpcore.getEnergyLevel()
if energy == nil then energy = 0 end
local energyMax = 100000000
if warpcore.get_energy_max ~= nil then
energyMax = warpcore.get_energy_max()
if energyMax == nil then energyMax = 1 end
end
if energyMax == nil then energyMax = 1 end
WriteLn(" Energy = " .. math.floor(energy / energyMax * 100) .. " % (" .. energy .. "EU)")
local players = warpcore.get_attached_players()
if players == nil then players = "-" end
WriteLn(" Attached players = " .. players)
local playersString, playersArray = warpcore.getAttachedPlayers()
if playersString == "" then players = "-" end
WriteLn(" Attached players = " .. playersString)
WriteLn("Dimensions:")
WriteLn(" Front, Right, Up = " .. FormatInteger(core_front) .. ", " .. FormatInteger(core_right) .. ", " .. FormatInteger(core_up))
WriteLn(" Back, Left, Down = " .. FormatInteger(core_back) .. ", " .. FormatInteger(core_left) .. ", " .. FormatInteger(core_down))
@ -1069,8 +1063,8 @@ function core_key(keycode)
rs.setOutput(alarm_side, true)
if readConfirmation() then
rs.setOutput(alarm_side, false)
warpcore.set_mode(5)
warpcore.do_jump()
warpcore.mode(5)
warpcore.jump()
end
rs.setOutput(alarm_side, false)
return true
@ -1088,7 +1082,7 @@ reactor_output = 0
function reactor_boot()
if reactor ~= nil then
WriteLn("Booting Reactor...")
local isActive, strMode, releaseRate = reactor.getActive()
local isActive, strMode, releaseRate = reactor.active()
if strMode == "OFF" then
data.reactor_mode = 0
elseif strMode == "MANUAL" then
@ -1199,7 +1193,7 @@ function reactor_page()
SetColorDefault()
SetCursorPos(1, 9)
Write("Activated: ")
isActive = reactor.getActive()
isActive = reactor.active()
if isActive then SetColorSuccess() else SetColorDefault() end
Write(boolToYesNo(isActive))
end
@ -1304,13 +1298,13 @@ end
function reactor_start()
if reactor ~= nil then
reactor_setMode()
reactor.setActive(true)
reactor.active(true)
end
end
function reactor_stop()
if reactor ~= nil then
reactor.setActive(false)
reactor.active(false)
end
end

View file

@ -11,9 +11,8 @@ import cr0s.WarpDrive.WarpDriveConfig;
import cr0s.WarpDrive.api.IUpgradable;
import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.peripheral.IComputerAccess;
import dan200.computercraft.api.peripheral.IPeripheral;
public class TileEntityChunkLoader extends WarpChunkTE implements IPeripheral, IUpgradable
public class TileEntityChunkLoader extends WarpChunkTE implements IUpgradable
{
private boolean canLoad = false;
private boolean shouldLoad = false;
@ -24,25 +23,25 @@ public class TileEntityChunkLoader extends WarpChunkTE implements IPeripheral, I
int negDX, posDX, negDZ, posDZ;
int area = 1;
private String[] methodArray = {
"energy",
public TileEntityChunkLoader() {
super();
negDX = 0;
negDZ = 0;
posDX = 0;
posDZ = 0;
peripheralName = "warpdriveChunkloader";
methodsArray = new String[] {
"getEnergyLevel",
"radius",
"bounds",
"active",
"upgrades",
"help"
};
{
negDX = 0;
negDZ = 0;
posDX = 0;
posDZ = 0;
};
}
@Override
public int getMaxEnergyStored()
{
public int getMaxEnergyStored() {
return WarpDriveConfig.CL_MAX_ENERGY;
}
@ -123,19 +122,11 @@ public class TileEntityChunkLoader extends WarpChunkTE implements IPeripheral, I
nbt.setInteger("posDX", posDX);
nbt.setInteger("posDZ", posDZ);
}
@Override
public String getType()
{
return "warpdriveChunkloader";
}
@Override
public String[] getMethodNames()
{
return methodArray;
}
// OpenComputer callback methods
// FIXME: implement OpenComputers...
// ComputerCraft IPeripheral methods implementation
private String helpStr(Object[] args)
{
if(args.length == 1)
@ -156,13 +147,12 @@ public class TileEntityChunkLoader extends WarpChunkTE implements IPeripheral, I
}
@Override
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception
{
String meth = methodArray[method];
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception {
String meth = methodsArray[method];
if(meth.equals("energy"))
return getEnergyObject();
else if(meth.equals("radius"))
if(meth.equals("getEnergyLevel")) {
return getEnergyLevel();
} else if(meth.equals("radius"))
{
if(arguments.length == 1)
{
@ -205,23 +195,7 @@ public class TileEntityChunkLoader extends WarpChunkTE implements IPeripheral, I
return null;
}
@Override
public void attach(IComputerAccess computer)
{
}
@Override
public void detach(IComputerAccess computer)
{
}
@Override
public boolean equals(IPeripheral other)
{
return false;
}
@Override
public boolean takeUpgrade(EnumUpgradeTypes upgradeType, boolean simulate)
{

View file

@ -9,9 +9,8 @@ import cr0s.WarpDrive.WarpDrive;
import cr0s.WarpDrive.WarpDriveConfig;
import dan200.computercraft.api.peripheral.IComputerAccess;
import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.peripheral.IPeripheral;
public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner implements IPeripheral {
public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
Boolean active = false;
private int mode = 0;
@ -26,14 +25,17 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner implements
private int totalHarvested=0;
private int scan=0;
private int scan = 0;
private int xSize = defSize;
private int zSize = defSize;
LinkedList<Vector3> logs;
private int logIndex = 0;
private String[] methodsArray = {
public TileEntityLaserTreeFarm() {
super();
peripheralName = "treefarmLaser";
methodsArray = new String[] {
"start",
"stop",
"area",
@ -42,10 +44,7 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner implements
"silkTouchLeaves",
"treetap",
"state"
};
public TileEntityLaserTreeFarm() {
super();
};
}
@Override
@ -233,16 +232,10 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner implements
return active;
}
@Override
public String getType() {
return "treefarmLaser";
}
@Override
public String[] getMethodNames() {
return methodsArray;
}
// OpenComputer callback methods
// FIXME: implement OpenComputers...
// ComputerCraft IPeripheral methods implementation
@Override
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception {
String methodName = methodsArray[method];
@ -311,14 +304,6 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner implements
return null;
}
@Override
public void attach(IComputerAccess computer) {
}
@Override
public void detach(IComputerAccess computer) {
}
//ABSTRACT LASER IMPLEMENTATION
@Override
protected boolean silkTouch(int blockID) {
@ -362,9 +347,4 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner implements
protected float getColorB() {
return 0.4f;
}
@Override
public boolean equals(IPeripheral other) {
return other == this;
}
}

View file

@ -11,13 +11,12 @@ import cr0s.WarpDrive.api.IBlockUpdateDetector;
import dan200.computercraft.api.ComputerCraftAPI;
import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.peripheral.IComputerAccess;
import dan200.computercraft.api.peripheral.IPeripheral;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
public class TileEntityPowerReactor extends WarpEnergyTE implements IPeripheral, IBlockUpdateDetector {
public class TileEntityPowerReactor extends WarpEnergyTE implements IBlockUpdateDetector {
private int containedEnergy = 0;
// generation & instability is 'per tick'
@ -58,18 +57,20 @@ public class TileEntityPowerReactor extends WarpEnergyTE implements IPeripheral,
private int releaseAbove = 0;
private boolean init = false;
private String[] methodArray = {
"getActive",
"setActive", // boolean
"energy", // returns energy, maxenergy
public TileEntityPowerReactor() {
super();
peripheralName = "warpdriveReactor";
methodsArray = new String[] {
"active",
"energy", // returns energy, max energy, energy rate
"instability", // returns ins0,1,2,3
"release", // releases all energy
"releaseRate", // releases energy when more than arg0 is produced
"releaseAbove", // releases any energy above arg0 amount
"help" // returns help on arg0 function
};
private HashMap<Integer,IComputerAccess> connectedComputers = new HashMap<Integer,IComputerAccess>();
};
}
private void increaseInstability(ForgeDirection from, boolean isNatural) {
if (canOutputEnergy(from) || hold) {
@ -293,59 +294,11 @@ public class TileEntityPowerReactor extends WarpEnergyTE implements IPeripheral,
}
}
//COMPUTER INTERFACES
@Override
public String getType() {
return "warpdriveReactor";
}
// OpenComputer callback methods
// FIXME: implement OpenComputers...
@Override
public String[] getMethodNames() {
return methodArray;
}
@Override
public void attach(IComputerAccess computer) {
int id = computer.getID();
connectedComputers.put(id, computer);
if (WarpDriveConfig.G_LUA_SCRIPTS != WarpDriveConfig.LUA_SCRIPTS_NONE) {
computer.mount("/power", ComputerCraftAPI.createResourceMount(WarpDrive.class, "warpdrive", "lua/power"));
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/power/startup"));
}
}
}
@Override
public void detach(IComputerAccess computer) {
int id = computer.getID();
if (connectedComputers.containsKey(id)) {
connectedComputers.remove(id);
}
}
@Override
public boolean equals(IPeripheral other) {
return other == this;
}
@Override
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception {
// computer is alive => start updating reactor
hold = false;
String methodName = methodArray[method];
if (methodName.equals("getActive")) {
if (releaseMode == MODE_DONT_RELEASE || releaseMode == MODE_MANUAL_RELEASE) {
return new Object[] { active, MODE_STRING[releaseMode], 0 };
} else if (releaseMode == MODE_RELEASE_ABOVE) {
return new Object[] { active, MODE_STRING[releaseMode], releaseAbove };
} else {
return new Object[] { active, MODE_STRING[releaseMode], releaseRate };
}
} else if (methodName.equals("setActive")) {
public Object[] active(Object[] arguments) throws Exception {
if (arguments.length == 1) {
boolean activate = false;
try {
activate = toBool(arguments[0]);
@ -358,82 +311,125 @@ public class TileEntityPowerReactor extends WarpEnergyTE implements IPeripheral,
sendEvent("reactorActivation", null);
}
active = activate;
}
if (releaseMode == MODE_DONT_RELEASE || releaseMode == MODE_MANUAL_RELEASE) {
return new Object[] { active, MODE_STRING[releaseMode], 0 };
} else if (releaseMode == MODE_RELEASE_ABOVE) {
return new Object[] { active, MODE_STRING[releaseMode], releaseAbove };
} else {
return new Object[] { active, MODE_STRING[releaseMode], releaseRate };
}
}
private Object[] release(Object[] arguments) throws Exception {
boolean doRelease = false;
if (arguments.length > 0) {
try {
doRelease = toBool(arguments[0]);
} catch(Exception e) {
throw new Exception("Function expects an boolean value");
}
releaseMode = doRelease ? MODE_MANUAL_RELEASE : MODE_DONT_RELEASE;
releaseAbove = 0;
releaseRate = 0;
}
return new Object[] { releaseMode != MODE_DONT_RELEASE };
}
private Object[] releaseRate(Object[] arguments) throws Exception {
int rate = -1;
try {
rate = toInt(arguments[0]);
} catch(Exception e) {
throw new Exception("Function expects an integer value");
}
if (rate <= 0) {
releaseMode = MODE_DONT_RELEASE;
releaseRate = 0;
} else {
/* releaseAbove = (int)Math.ceil(Math.pow(rate, 1.0 / 0.6));
WarpDrive.debugPrint("releaseAbove " + releaseAbove);
releaseMode = MODE_RELEASE_ABOVE;/**/
// player has to adjust it
releaseRate = rate;
releaseMode = MODE_RELEASE_AT_RATE;
}
return new Object[] { MODE_STRING[releaseMode], releaseRate };
}
private Object[] releaseAbove(Object[] arguments) throws Exception {
int above = -1;
try {
above = toInt(arguments[0]);
} catch(Exception e) {
throw new Exception("Function expects an integer value");
}
if (above <= 0) {
releaseMode = 0;
releaseAbove = MODE_DONT_RELEASE;
} else {
releaseMode = MODE_RELEASE_ABOVE;
releaseAbove = above;
}
return new Object[] { MODE_STRING[releaseMode], releaseAbove };
}
// ComputerCraft IPeripheral methods implementation
@Override
public void attach(IComputerAccess computer) {
super.attach(computer);
int id = computer.getID();
connectedComputers.put(id, computer);
if (WarpDriveConfig.G_LUA_SCRIPTS != WarpDriveConfig.LUA_SCRIPTS_NONE) {
computer.mount("/power", ComputerCraftAPI.createResourceMount(WarpDrive.class, "warpdrive", "lua/power"));
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/power/startup"));
}
}
}
@Override
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception {
// computer is alive => start updating reactor
hold = false;
String methodName = methodsArray[method];
if (methodName.equals("active")) {
return active(arguments);
} else if (methodName.equals("energy")) {
return new Object[] { containedEnergy, WarpDriveConfig.PR_MAX_ENERGY, releasedLastCycle / WarpDriveConfig.PR_TICK_TIME };
} else if (methodName.equals("instability")) {
Object[] retVal = new Object[4];
for(int i = 0; i < 4; i++) {
retVal[i] = instabilityValues[i];
}
return retVal;
} else if(methodName.equals("release")) {
boolean doRelease = false;
if (arguments.length > 0) {
try {
doRelease = toBool(arguments[0]);
} catch(Exception e) {
throw new Exception("Function expects an boolean value");
}
releaseMode = doRelease ? MODE_MANUAL_RELEASE : MODE_DONT_RELEASE;
releaseAbove = 0;
releaseRate = 0;
}
return new Object[] { releaseMode != MODE_DONT_RELEASE };
} else if(methodName.equals("releaseRate")) {
int rate = -1;
try {
rate = toInt(arguments[0]);
} catch(Exception e) {
throw new Exception("Function expects an integer value");
}
if (rate <= 0) {
releaseMode = MODE_DONT_RELEASE;
releaseRate = 0;
} else {
/* releaseAbove = (int)Math.ceil(Math.pow(rate, 1.0 / 0.6));
WarpDrive.debugPrint("releaseAbove " + releaseAbove);
releaseMode = MODE_RELEASE_ABOVE;/**/
// player has to adjust it
releaseRate = rate;
releaseMode = MODE_RELEASE_AT_RATE;
}
} else if (methodName.equals("release")) {
return release(arguments);
return new Object[] { MODE_STRING[releaseMode], releaseRate };
} else if(methodName.equals("releaseAbove")) {
int above = -1;
try {
above = toInt(arguments[0]);
} catch(Exception e) {
throw new Exception("Function expects an integer value");
}
} else if (methodName.equals("releaseRate")) {
return releaseRate(arguments);
if (above <= 0) {
releaseMode = 0;
releaseAbove = MODE_DONT_RELEASE;
} else {
releaseMode = MODE_RELEASE_ABOVE;
releaseAbove = above;
}
} else if (methodName.equals("releaseAbove")) {
return releaseAbove(arguments);
return new Object[] { MODE_STRING[releaseMode], releaseAbove };
} else if (methodName.equals("help")) {
return new Object[] { helpStr(arguments) };
}
return null;
}
private void sendEvent(String eventName, Object[] arguments) {
// WarpDrive.debugPrint("" + this + " Sending event '" + eventName + "'");
Set<Integer> keys = connectedComputers.keySet();
for(Integer key:keys) {
IComputerAccess comp = connectedComputers.get(key);
comp.queueEvent(eventName, arguments);
}
}
// POWER INTERFACES
@Override
public int getPotentialEnergyOutput() {

View file

@ -1,15 +1,20 @@
package cr0s.WarpDrive.machines;
import cpw.mods.fml.common.Optional;
import cr0s.WarpDrive.WarpDriveConfig;
import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.peripheral.IComputerAccess;
import dan200.computercraft.api.peripheral.IPeripheral;
import net.minecraftforge.common.ForgeDirection;
public class TileEntityPowerStore extends WarpEnergyTE implements IPeripheral {
private String[] methodArray = {
"energy"
};
public class TileEntityPowerStore extends WarpEnergyTE {
public TileEntityPowerStore() {
super();
peripheralName = "warpdrivePowerStore";
methodsArray = new String[] {
"getEnergyLevel"
};
}
@Override
public int getPotentialEnergyOutput() {
@ -36,22 +41,12 @@ public class TileEntityPowerStore extends WarpEnergyTE implements IPeripheral {
return true;
}
// ComputerCraft
@Override
public String getType() {
return "warpdrivePowerStore";
}
@Override
public String[] getMethodNames() {
return methodArray;
}
// ComputerCraft IPeripheral methods implementation
@Override
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception {
String methodName = methodArray[method];
if (methodName == "energy") {
return getEnergyObject();
String methodName = methodsArray[method];
if (methodName == "getEnergyLevel") {
return getEnergyLevel();
}
return null;
}
@ -65,9 +60,4 @@ public class TileEntityPowerStore extends WarpEnergyTE implements IPeripheral {
public void detach(IComputerAccess computer) {
// nothing to see here
}
@Override
public boolean equals(IPeripheral other) {
return this == other;
}
}

View file

@ -21,9 +21,8 @@ import net.minecraft.util.DamageSource;
import net.minecraftforge.common.ForgeDirection;
import dan200.computercraft.api.peripheral.IComputerAccess;
import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.peripheral.IPeripheral;
public class TileEntityTransporter extends WarpEnergyTE implements IPeripheral, IUpgradable
public class TileEntityTransporter extends WarpEnergyTE implements IUpgradable
{
private double scanRange=2;
@ -41,18 +40,22 @@ public class TileEntityTransporter extends WarpEnergyTE implements IPeripheral,
private TeleporterDamage teleDam = new TeleporterDamage("teleporter");
private String[] methodArray = {
public TileEntityTransporter() {
super();
peripheralName = "transporter";
methodsArray = new String[] {
"source",
"dest",
"lock",
"release",
"lockStrength",
"energize",
"energy",
"getEnergyLevel",
"powerBoost",
"energyCost",
"upgrades",
"help" };
}
@Override
public void updateEntity() {
@ -67,12 +70,10 @@ public class TileEntityTransporter extends WarpEnergyTE implements IPeripheral,
}
}
// IPeripheral overrides
@Override
public String getType() {
return "transporter";
}
// OpenComputer callback methods
// FIXME: implement OpenComputers...
// ComputerCraft IPeripheral methods implementation
private static String helpStr(Object[] function) {
if (function != null && function.length > 0) {
String fun = function[0].toString().toLowerCase();
@ -102,17 +103,12 @@ public class TileEntityTransporter extends WarpEnergyTE implements IPeripheral,
return "energyCost(): returns the amount of energy it will take for a single entity to transport with the current settings";
} else if(fun.equals("upgrades")) {
return WarpDrive.defUpgradeStr;
} else if(fun.equals("energy")) {
} else if(fun.equals("getEnergyLevel")) {
return WarpDrive.defEnergyStr;
}
}
return WarpDrive.defHelpStr;
}
@Override
public String[] getMethodNames() {
return methodArray;
}
private Object[] setVec3(boolean src,Object... arguments) {
Vector3 vec = src ? sourceVec : destVec;
@ -152,8 +148,8 @@ public class TileEntityTransporter extends WarpEnergyTE implements IPeripheral,
@Override
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception {
String methodName = methodArray[method];
if (methodName.equals("energy")) {
String methodName = methodsArray[method];
if (methodName.equals("getEnergyLevel")) {
return new Object[] { getEnergyStored(), getMaxEnergyStored() };
} else if (methodName.equals("source")) {
return setVec3(true,arguments);
@ -396,12 +392,6 @@ public class TileEntityTransporter extends WarpEnergyTE implements IPeripheral,
}
return output;
}
@Override
public void attach(IComputerAccess computer) {}
@Override
public void detach(IComputerAccess computer) {}
@Override
public int getMaxEnergyStored() {
@ -456,11 +446,6 @@ public class TileEntityTransporter extends WarpEnergyTE implements IPeripheral,
}
}
@Override
public boolean equals(IPeripheral other) {
return other == this;
}
@Override
public boolean takeUpgrade(EnumUpgradeTypes upgradeType, boolean simulate)
{