Started implementing a Lua API to act as a "wrapper" for the ArmBot.
This commit is contained in:
parent
1fd05aade7
commit
5c5f4395bb
2 changed files with 102 additions and 16 deletions
|
@ -1,5 +1,11 @@
|
||||||
package assemblyline.common;
|
package assemblyline.common;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipInputStream;
|
||||||
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
@ -14,6 +20,7 @@ import assemblyline.common.machine.encoder.ContainerEncoder;
|
||||||
import assemblyline.common.machine.encoder.TileEntityEncoder;
|
import assemblyline.common.machine.encoder.TileEntityEncoder;
|
||||||
import assemblyline.common.machine.imprinter.ContainerImprinter;
|
import assemblyline.common.machine.imprinter.ContainerImprinter;
|
||||||
import assemblyline.common.machine.imprinter.TileEntityImprinter;
|
import assemblyline.common.machine.imprinter.TileEntityImprinter;
|
||||||
|
import cpw.mods.fml.common.FMLCommonHandler;
|
||||||
import cpw.mods.fml.common.network.IGuiHandler;
|
import cpw.mods.fml.common.network.IGuiHandler;
|
||||||
import cpw.mods.fml.common.registry.GameRegistry;
|
import cpw.mods.fml.common.registry.GameRegistry;
|
||||||
|
|
||||||
|
@ -40,6 +47,67 @@ public class CommonProxy implements IGuiHandler
|
||||||
GameRegistry.registerTileEntity(TileEntityMulti.class, "ALMulti");
|
GameRegistry.registerTileEntity(TileEntityMulti.class, "ALMulti");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void extractZipToLocation(File zipFile, String sourceFolder, String destFolder)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
File destFile = new File(FMLCommonHandler.instance().getMinecraftServerInstance().getFile("."), destFolder);
|
||||||
|
String destinationName = destFile.getAbsolutePath();
|
||||||
|
byte[] buf = new byte[1024];
|
||||||
|
ZipInputStream zipinputstream = null;
|
||||||
|
ZipEntry zipentry;
|
||||||
|
zipinputstream = new ZipInputStream(new FileInputStream(zipFile));
|
||||||
|
|
||||||
|
zipentry = zipinputstream.getNextEntry();
|
||||||
|
while (zipentry != null)
|
||||||
|
{
|
||||||
|
// for each entry to be extracted
|
||||||
|
String zipentryName = zipentry.getName();
|
||||||
|
if (!zipentryName.startsWith(sourceFolder))
|
||||||
|
{
|
||||||
|
zipentry = zipinputstream.getNextEntry();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
String entryName = destinationName + zipentryName.substring(Math.min(zipentryName.length(), sourceFolder.length() - 1));
|
||||||
|
entryName = entryName.replace('/', File.separatorChar);
|
||||||
|
entryName = entryName.replace('\\', File.separatorChar);
|
||||||
|
int n;
|
||||||
|
FileOutputStream fileoutputstream;
|
||||||
|
File newFile = new File(entryName);
|
||||||
|
if (zipentry.isDirectory())
|
||||||
|
{
|
||||||
|
if (!newFile.mkdirs())
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
zipentry = zipinputstream.getNextEntry();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
fileoutputstream = new FileOutputStream(entryName);
|
||||||
|
|
||||||
|
while ((n = zipinputstream.read(buf, 0, 1024)) > -1)
|
||||||
|
{
|
||||||
|
fileoutputstream.write(buf, 0, n);
|
||||||
|
}
|
||||||
|
|
||||||
|
fileoutputstream.close();
|
||||||
|
zipinputstream.closeEntry();
|
||||||
|
zipentry = zipinputstream.getNextEntry();
|
||||||
|
|
||||||
|
}// while
|
||||||
|
|
||||||
|
zipinputstream.close();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error while loading AssemblyLine Lua libraries: ");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
|
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
|
||||||
{
|
{
|
||||||
|
|
|
@ -59,6 +59,8 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
|
||||||
public double wattsReceived = 0;
|
public double wattsReceived = 0;
|
||||||
|
|
||||||
private int playerUsing = 0;
|
private int playerUsing = 0;
|
||||||
|
|
||||||
|
private int computersAttached = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The rotation of the arms. In Degrees.
|
* The rotation of the arms. In Degrees.
|
||||||
|
@ -115,7 +117,7 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.disk == null)
|
if (this.disk == null && this.computersAttached == 0)
|
||||||
{
|
{
|
||||||
this.commandManager.clear();
|
this.commandManager.clear();
|
||||||
|
|
||||||
|
@ -125,7 +127,9 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.commandManager.addCommand(this, CommandReturn.class);
|
if (!this.commandManager.hasTasks())
|
||||||
|
if (Math.abs(this.rotationYaw - CommandReturn.IDLE_ROTATION_YAW) > 0.01)
|
||||||
|
this.commandManager.addCommand(this, CommandReturn.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.commandManager.setCurrentTask(0);
|
this.commandManager.setCurrentTask(0);
|
||||||
|
@ -485,24 +489,25 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
|
||||||
@Override
|
@Override
|
||||||
public Object[] callMethod(IComputerAccess computer, int method, Object[] arguments) throws Exception
|
public Object[] callMethod(IComputerAccess computer, int method, Object[] arguments) throws Exception
|
||||||
{
|
{
|
||||||
System.out.println(getMethodNames()[method] + ": ");
|
|
||||||
for (Object o : arguments)
|
|
||||||
{
|
|
||||||
System.out.println(" " + o.toString());
|
|
||||||
}
|
|
||||||
switch (method)
|
switch (method)
|
||||||
{
|
{
|
||||||
case 0: // rotateBy: rotates by a certain amount
|
case 0: // rotateBy: rotates by a certain amount
|
||||||
{
|
{
|
||||||
if (arguments.length > 0)
|
if (arguments.length > 0)
|
||||||
{
|
{
|
||||||
if (arguments[0] instanceof Float)
|
try
|
||||||
|
// try to cast to Float
|
||||||
{
|
{
|
||||||
float angle = (Float) arguments[0];
|
double angle = (Double) arguments[0];
|
||||||
this.commandManager.addCommand(this, CommandRotate.class, new String[] { Float.toString(angle) });
|
this.commandManager.addCommand(this, CommandRotate.class, new String[] { Double.toString(angle) });
|
||||||
|
while(this.commandManager.hasTasks())
|
||||||
|
{
|
||||||
|
Thread.sleep(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
ex.printStackTrace();
|
||||||
throw new IllegalArgumentException("expected number");
|
throw new IllegalArgumentException("expected number");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -518,12 +523,17 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
float angle = (Float) arguments[0];
|
double angle = (Double) arguments[0];
|
||||||
float diff = angle - this.rotationYaw;
|
double diff = angle - this.rotationYaw;
|
||||||
this.commandManager.addCommand(this, CommandRotate.class, new String[] { Float.toString(diff) });
|
this.commandManager.addCommand(this, CommandRotate.class, new String[] { Double.toString(diff) });
|
||||||
|
while(this.commandManager.hasTasks())
|
||||||
|
{
|
||||||
|
Thread.sleep(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
ex.printStackTrace();
|
||||||
throw new IllegalArgumentException("expected number");
|
throw new IllegalArgumentException("expected number");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -536,11 +546,19 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
|
||||||
case 2: // grab: grabs an item
|
case 2: // grab: grabs an item
|
||||||
{
|
{
|
||||||
this.commandManager.addCommand(this, CommandGrab.class);
|
this.commandManager.addCommand(this, CommandGrab.class);
|
||||||
|
while(this.commandManager.hasTasks())
|
||||||
|
{
|
||||||
|
Thread.sleep(1);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 3: // drop: drops an item
|
case 3: // drop: drops an item
|
||||||
{
|
{
|
||||||
this.commandManager.addCommand(this, CommandDrop.class);
|
this.commandManager.addCommand(this, CommandDrop.class);
|
||||||
|
while(this.commandManager.hasTasks())
|
||||||
|
{
|
||||||
|
Thread.sleep(1);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 4: // reset: calls the RETURN command
|
case 4: // reset: calls the RETURN command
|
||||||
|
@ -565,13 +583,13 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
|
||||||
@Override
|
@Override
|
||||||
public void attach(IComputerAccess computer)
|
public void attach(IComputerAccess computer)
|
||||||
{
|
{
|
||||||
|
computersAttached++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void detach(IComputerAccess computer)
|
public void detach(IComputerAccess computer)
|
||||||
{
|
{
|
||||||
|
computersAttached--;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue