Starting on the encoder
Almost to the point were i can start testing all the changes. Though i still need to write a GUI, and finish the program handler.
This commit is contained in:
parent
5cc68a4720
commit
8b6b6f6399
32 changed files with 368 additions and 204 deletions
|
@ -1,8 +0,0 @@
|
|||
package dark.api.al;
|
||||
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
public interface ICraneConnectable
|
||||
{
|
||||
boolean canFrameConnectTo(ForgeDirection side);
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
package dark.api.al;
|
||||
|
||||
public interface ICraneStructure extends ICraneConnectable
|
||||
{
|
||||
|
||||
}
|
|
@ -2,8 +2,8 @@ package dark.api.al;
|
|||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/** Applied to TileEntities that can accept a filter.
|
||||
*
|
||||
/** Applied to TileEntities that can accept a filter.z
|
||||
*
|
||||
* @author Calclavia */
|
||||
public interface IFilterable
|
||||
{
|
||||
|
|
|
@ -6,7 +6,7 @@ import net.minecraftforge.common.ForgeDirection;
|
|||
import universalelectricity.core.vector.Vector2;
|
||||
|
||||
/** Should be used to interact with the armbot and not to create a new armbot */
|
||||
public interface IArmbot extends Cloneable, ILogicDevice
|
||||
public interface IArmbot extends Cloneable, IProgramableMachine
|
||||
{
|
||||
/** Location of the hand, or working location of the object */
|
||||
public universalelectricity.core.vector.Vector3 getHandPos();
|
||||
|
|
15
src/minecraft/dark/api/al/coding/IDataItem.java
Normal file
15
src/minecraft/dark/api/al/coding/IDataItem.java
Normal file
|
@ -0,0 +1,15 @@
|
|||
package dark.api.al.coding;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
/** Used to ID that an item can support saving data to it NBT
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public interface IDataItem
|
||||
{
|
||||
/** Saves the data to the item */
|
||||
public NBTTagCompound saveData(NBTTagCompound nbt);
|
||||
|
||||
/** Gets the data from the item */
|
||||
public NBTTagCompound getData();
|
||||
}
|
|
@ -20,7 +20,7 @@ import dark.api.al.coding.args.ArgumentData;
|
|||
* the task. That way it can save values after the task has been refreshed or even deleted.
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public interface IDeviceTask
|
||||
public interface IDeviceTask extends Cloneable
|
||||
{
|
||||
/** Location in the column and row format. */
|
||||
public Vector2 getPosition();
|
||||
|
@ -36,7 +36,7 @@ public interface IDeviceTask
|
|||
|
||||
/** Passed in from the device to the program manager then here after a Computer craft machine
|
||||
* calls a this commands method name. {@IPeripheral #callMethod()} */
|
||||
public Object[] onCCMethodCalled(World world, Vector3 location, ILogicDevice device, IComputerAccess computer, ILuaContext context) throws Exception;
|
||||
public Object[] onCCMethodCalled(World world, Vector3 location, IProgramableMachine device, IComputerAccess computer, ILuaContext context) throws Exception;
|
||||
|
||||
/** Called when the task is being run by the devices program manager. Used mainly to setup the
|
||||
* task before actually doing the task.
|
||||
|
@ -46,7 +46,7 @@ public interface IDeviceTask
|
|||
* @param armbot - armbot instance
|
||||
* @param arguments - arguments for command
|
||||
* @return false to stop the task here. */
|
||||
public ProcessReturn onMethodCalled(World world, Vector3 location, ILogicDevice device);
|
||||
public ProcessReturn onMethodCalled(World world, Vector3 location, IProgramableMachine device);
|
||||
|
||||
/** Update the current segment of the task */
|
||||
public ProcessReturn onUpdate();
|
||||
|
@ -70,7 +70,7 @@ public interface IDeviceTask
|
|||
public TaskType getType();
|
||||
|
||||
/** Can this task function for this machine */
|
||||
public boolean canUseTask(ILogicDevice device);
|
||||
public boolean canUseTask(IProgramableMachine device);
|
||||
|
||||
/** ArgumentData used to both restrict and set values into the argument hashmap */
|
||||
public List<ArgumentData> getEncoderParms();
|
||||
|
@ -112,4 +112,6 @@ public interface IDeviceTask
|
|||
this.userOutput = userOutput;
|
||||
}
|
||||
}
|
||||
|
||||
public IDeviceTask clone();
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package dark.api.al.coding;
|
|||
|
||||
import java.util.HashMap;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import universalelectricity.core.vector.Vector2;
|
||||
|
||||
/** Flow chart style program. Each command in the program needs to have a stored location so it can
|
||||
|
@ -24,6 +25,20 @@ public interface IProgram
|
|||
/** Gets a task at the given x y location in the program */
|
||||
public IDeviceTask getTaskAt(Vector2 vector2);
|
||||
|
||||
/** Return this program to its starting conditions */
|
||||
public void reset();
|
||||
public void setTaskAt(Vector2 vector2, IDeviceTask task);
|
||||
|
||||
/** Return this program to its starting conditions
|
||||
*
|
||||
* @full - means full reset including memory clean */
|
||||
public void reset(boolean full);
|
||||
|
||||
/** Sets the declared variable */
|
||||
public void setVar(String name, Object object);
|
||||
|
||||
/** Gets a declared variable */
|
||||
public Object getVar(String name);
|
||||
|
||||
public NBTTagCompound save(NBTTagCompound nbt);
|
||||
|
||||
public void load(NBTTagCompound nbt);
|
||||
}
|
||||
|
|
13
src/minecraft/dark/api/al/coding/IProgramItem.java
Normal file
13
src/minecraft/dark/api/al/coding/IProgramItem.java
Normal file
|
@ -0,0 +1,13 @@
|
|||
package dark.api.al.coding;
|
||||
|
||||
/** IDs that an item can load/save a program
|
||||
*
|
||||
* @author Darkguardsman */
|
||||
public interface IProgramItem
|
||||
{
|
||||
/** Sets the program into the item */
|
||||
public void setProgram(IProgram program);
|
||||
|
||||
/** Gets the program from the item */
|
||||
public IProgram getProgram();
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package dark.api.al.coding;
|
||||
|
||||
public interface ILogicDevice
|
||||
public interface IProgramableMachine
|
||||
{
|
||||
public IProgram getCurrentProgram();
|
||||
|
16
src/minecraft/dark/api/al/coding/IServo.java
Normal file
16
src/minecraft/dark/api/al/coding/IServo.java
Normal file
|
@ -0,0 +1,16 @@
|
|||
package dark.api.al.coding;
|
||||
|
||||
import universalelectricity.core.vector.Vector2;
|
||||
/**
|
||||
* Class used in the creation of servo based object
|
||||
* @author Rseifert
|
||||
*
|
||||
*/
|
||||
public interface IServo
|
||||
{
|
||||
/** Gets the rotation as a Vector2 (X - Yaw, Y - pitch) */
|
||||
public Vector2 getRotation();
|
||||
|
||||
/** Forces the rotation to the two angles */
|
||||
public void setRotation(float yaw, float pitch);
|
||||
}
|
21
src/minecraft/dark/api/al/coding/IServoHandler.java
Normal file
21
src/minecraft/dark/api/al/coding/IServoHandler.java
Normal file
|
@ -0,0 +1,21 @@
|
|||
package dark.api.al.coding;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/** Container like class to handle several servos in an object.
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public interface IServoHandler
|
||||
{
|
||||
/** Gets a map of the handler's server with a string to ID them by. Mainly will only be used by
|
||||
* advanced encoders to change the handlers servos in code */
|
||||
public HashMap<String, IServo> getServos();
|
||||
|
||||
/** Ask the handler to rotation the servo.
|
||||
*
|
||||
* @return true if the handler will rotate the servo */
|
||||
public boolean updateRotation(String servo, float rotation);
|
||||
|
||||
/** Forces the rotation angle of a servo. */
|
||||
public void setRotation(String servo, float rotation);
|
||||
}
|
|
@ -4,6 +4,7 @@ import java.util.HashMap;
|
|||
|
||||
import dark.api.al.coding.IDeviceTask.ProcessReturn;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
|
@ -15,7 +16,7 @@ public class ProgramHelper
|
|||
{
|
||||
/** Current Program */
|
||||
protected IProgram program;
|
||||
protected ILogicDevice bot;
|
||||
protected IProgramableMachine bot;
|
||||
/** Current task in program */
|
||||
protected IDeviceTask currentTask;
|
||||
/** Do we have a memory to store values */
|
||||
|
@ -26,7 +27,7 @@ public class ProgramHelper
|
|||
/** Array of values to remember between commands */
|
||||
protected HashMap<String, Object> taskMemory = new HashMap<String, Object>();
|
||||
|
||||
public ProgramHelper(ILogicDevice bot)
|
||||
public ProgramHelper(IProgramableMachine bot)
|
||||
{
|
||||
this.bot = bot;
|
||||
}
|
||||
|
@ -153,4 +154,14 @@ public class ProgramHelper
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public NBTTagCompound save(NBTTagCompound nbt)
|
||||
{
|
||||
return nbt;
|
||||
}
|
||||
|
||||
public void load(NBTTagCompound nbt)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,37 +4,46 @@ import java.util.ArrayList;
|
|||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
/** Used to both register task and fake machines for the encoder to use to create new programs.
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public class ArmbotTaskManager
|
||||
public class TaskRegistry
|
||||
{
|
||||
/** A class of all available commands.
|
||||
*
|
||||
* String - Command name. Command - The actual command class. */
|
||||
private static final Set<IDeviceTask> COMMANDS = new HashSet<IDeviceTask>();
|
||||
private static final HashMap<String, IDeviceTask> COMMANDS = new HashMap();
|
||||
|
||||
private static final HashMap<String, IArmbot> SUDO_BOTS = new HashMap<String, IArmbot>();
|
||||
|
||||
/** Registers a command and tells armbots that it exists */
|
||||
public static void registerCommand(IDeviceTask task)
|
||||
{
|
||||
if (!COMMANDS.contains(task))
|
||||
if (!COMMANDS.containsKey(task.getMethodName()))
|
||||
{
|
||||
COMMANDS.add(task);
|
||||
COMMANDS.put(task.getMethodName(), task);
|
||||
}
|
||||
}
|
||||
|
||||
public static void registerCommand(String registryName, IDeviceTask task)
|
||||
{
|
||||
if (!COMMANDS.containsKey(registryName))
|
||||
{
|
||||
COMMANDS.put(registryName, task);
|
||||
}
|
||||
}
|
||||
|
||||
/** returns the first command with the same name */
|
||||
public static IDeviceTask getCommand(String name)
|
||||
{
|
||||
for (IDeviceTask command : COMMANDS)
|
||||
for (Entry<String, IDeviceTask> command : COMMANDS.entrySet())
|
||||
{
|
||||
if (command.getMethodName().equalsIgnoreCase(name))
|
||||
if (command.getKey().equalsIgnoreCase(name))
|
||||
{
|
||||
return command;
|
||||
return command.getValue();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -44,11 +53,11 @@ public class ArmbotTaskManager
|
|||
public static List<IDeviceTask> getCommands(String name)
|
||||
{
|
||||
List<IDeviceTask> tasks = new ArrayList<IDeviceTask>();
|
||||
for (IDeviceTask command : COMMANDS)
|
||||
for (Entry<String, IDeviceTask> command : COMMANDS.entrySet())
|
||||
{
|
||||
if (command.getMethodName().equalsIgnoreCase(name))
|
||||
if (command.getValue().getMethodName().equalsIgnoreCase(name))
|
||||
{
|
||||
tasks.add(command);
|
||||
tasks.add(command.getValue());
|
||||
}
|
||||
}
|
||||
return tasks;
|
|
@ -54,7 +54,7 @@ public class RenderArmbot extends TileEntitySpecialRenderer
|
|||
GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);
|
||||
GL11.glScalef(1.0F, -1F, -1F);
|
||||
|
||||
MODEL.render(0.0625f, ((TileEntityArmbot) tileEntity).actualYaw, ((TileEntityArmbot) tileEntity).actualPitch);
|
||||
MODEL.render(0.0625f, (float)((TileEntityArmbot) tileEntity).getRotation().x, (float)((TileEntityArmbot) tileEntity).getRotation().y);
|
||||
|
||||
GL11.glPopMatrix();
|
||||
|
||||
|
|
|
@ -1,6 +1,126 @@
|
|||
package dark.assembly.common.armbot;
|
||||
|
||||
public class Program
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import universalelectricity.core.vector.Vector2;
|
||||
import dark.api.al.coding.IDeviceTask;
|
||||
import dark.api.al.coding.IProgram;
|
||||
import dark.api.al.coding.TaskRegistry;
|
||||
|
||||
public class Program implements IProgram
|
||||
{
|
||||
protected Vector2 currentPos = new Vector2(0, 0);
|
||||
protected IDeviceTask currentTask;
|
||||
protected HashMap<Vector2, IDeviceTask> tasks = new HashMap();
|
||||
|
||||
@Override
|
||||
public void init()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<String, Object> getDeclairedVarables()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IDeviceTask getNextTask()
|
||||
{
|
||||
this.currentTask = this.getTaskAt(currentPos);
|
||||
this.currentPos.add(new Vector2(1, 0));
|
||||
return this.currentTask;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IDeviceTask getTaskAt(Vector2 vector2)
|
||||
{
|
||||
if (vector2 != null)
|
||||
{
|
||||
return this.tasks.get(new Vector2(vector2.intX(), vector2.intY()));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTaskAt(Vector2 vector2, IDeviceTask task)
|
||||
{
|
||||
if (vector2 != null)
|
||||
{
|
||||
if (task != null)
|
||||
{
|
||||
this.tasks.put(new Vector2(vector2.intX(), vector2.intY()), task);
|
||||
}
|
||||
else if (this.tasks.containsKey(vector2))
|
||||
{
|
||||
this.tasks.remove(vector2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset(boolean full)
|
||||
{
|
||||
this.currentTask = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVar(String name, Object object)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getVar(String name)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound save(NBTTagCompound nbt)
|
||||
{
|
||||
NBTTagList taskList = new NBTTagList();
|
||||
for (Entry<Vector2, IDeviceTask> entry : this.tasks.entrySet())
|
||||
{
|
||||
entry.getValue().setPosition(entry.getKey());
|
||||
NBTTagCompound task = entry.getValue().save(new NBTTagCompound());
|
||||
task.setString("methodName", entry.getValue().getMethodName());
|
||||
task.setInteger("positionX", entry.getKey().intX());
|
||||
task.setInteger("positionY", entry.getKey().intY());
|
||||
taskList.appendTag(task);
|
||||
}
|
||||
nbt.setTag("tasks", taskList);
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(NBTTagCompound nbt)
|
||||
{
|
||||
NBTTagList taskList = nbt.getTagList("tasks");
|
||||
for (int s = 0; s < taskList.tagCount(); ++s)
|
||||
{
|
||||
NBTTagCompound tag = (NBTTagCompound) taskList.tagAt(s);
|
||||
IDeviceTask task = TaskRegistry.getCommand(tag.getString("methodName"));
|
||||
if (task != null)
|
||||
{
|
||||
task = task.clone();
|
||||
if (task != null)
|
||||
{
|
||||
task.load(tag);
|
||||
task.setPosition(new Vector2(nbt.getInteger("positionX"), nbt.getInteger("positionY")));
|
||||
this.tasks.put(task.getPosition(), task);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import universalelectricity.core.vector.Vector3;
|
|||
import dan200.computer.api.IComputerAccess;
|
||||
import dan200.computer.api.ILuaContext;
|
||||
import dark.api.al.coding.IArmbot;
|
||||
import dark.api.al.coding.ILogicDevice;
|
||||
import dark.api.al.coding.IProgramableMachine;
|
||||
|
||||
public abstract class TaskArmbot extends TaskBase
|
||||
{
|
||||
|
@ -18,7 +18,7 @@ public abstract class TaskArmbot extends TaskBase
|
|||
}
|
||||
|
||||
@Override
|
||||
public ProcessReturn onMethodCalled(World world, Vector3 location, ILogicDevice armbot)
|
||||
public ProcessReturn onMethodCalled(World world, Vector3 location, IProgramableMachine armbot)
|
||||
{
|
||||
super.onMethodCalled(world, location, armbot);
|
||||
if (armbot instanceof IArmbot)
|
||||
|
@ -31,7 +31,7 @@ public abstract class TaskArmbot extends TaskBase
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object[] onCCMethodCalled(World world, Vector3 location, ILogicDevice armbot, IComputerAccess computer, ILuaContext context) throws Exception
|
||||
public Object[] onCCMethodCalled(World world, Vector3 location, IProgramableMachine armbot, IComputerAccess computer, ILuaContext context) throws Exception
|
||||
{
|
||||
super.onCCMethodCalled(world, location, armbot, computer, context);
|
||||
if (armbot instanceof IArmbot)
|
||||
|
@ -43,7 +43,7 @@ public abstract class TaskArmbot extends TaskBase
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean canUseTask(ILogicDevice device)
|
||||
public boolean canUseTask(IProgramableMachine device)
|
||||
{
|
||||
return device instanceof IArmbot;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ import dan200.computer.api.IComputerAccess;
|
|||
import dan200.computer.api.ILuaContext;
|
||||
import dark.api.al.coding.IArmbot;
|
||||
import dark.api.al.coding.IDeviceTask;
|
||||
import dark.api.al.coding.ILogicDevice;
|
||||
import dark.api.al.coding.IProgramableMachine;
|
||||
import dark.api.al.coding.IMemoryTask;
|
||||
import dark.api.al.coding.IProgram;
|
||||
import dark.api.al.coding.IDeviceTask.TaskType;
|
||||
|
@ -27,7 +27,7 @@ import dark.core.prefab.helpers.NBTFileLoader;
|
|||
|
||||
/** Basic command prefab used by machines like an armbot. You are not required to use this in order
|
||||
* to make armbot commands but it does help. Delete this if you don't plan to use it. */
|
||||
public abstract class TaskBase implements IDeviceTask, Cloneable, IMemoryTask
|
||||
public abstract class TaskBase implements IDeviceTask, IMemoryTask
|
||||
{
|
||||
/** Program this is part of. Can be null while stores as a prefab waiting to be copied */
|
||||
protected IProgram program;
|
||||
|
@ -67,7 +67,7 @@ public abstract class TaskBase implements IDeviceTask, Cloneable, IMemoryTask
|
|||
}
|
||||
|
||||
@Override
|
||||
public ProcessReturn onMethodCalled(World world, Vector3 location, ILogicDevice armbot)
|
||||
public ProcessReturn onMethodCalled(World world, Vector3 location, IProgramableMachine armbot)
|
||||
{
|
||||
if (location != null && devicePos != null)
|
||||
{
|
||||
|
@ -80,7 +80,7 @@ public abstract class TaskBase implements IDeviceTask, Cloneable, IMemoryTask
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object[] onCCMethodCalled(World world, Vector3 location, ILogicDevice armbot, IComputerAccess computer, ILuaContext context) throws Exception
|
||||
public Object[] onCCMethodCalled(World world, Vector3 location, IProgramableMachine armbot, IComputerAccess computer, ILuaContext context) throws Exception
|
||||
{
|
||||
this.worldObj = world;
|
||||
this.devicePos = location;
|
||||
|
|
|
@ -58,6 +58,8 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
|
|||
|
||||
protected ProgramHelper programHelper;
|
||||
|
||||
public EntityItem renderEntityItem;
|
||||
|
||||
public TileEntityArmbot()
|
||||
{
|
||||
super(.02f);
|
||||
|
|
|
@ -6,7 +6,7 @@ import java.util.Random;
|
|||
import com.builtbroken.common.science.units.UnitHelper;
|
||||
|
||||
import dark.api.al.coding.IArmbot;
|
||||
import dark.api.al.coding.ILogicDevice;
|
||||
import dark.api.al.coding.IProgramableMachine;
|
||||
import dark.api.al.coding.IDeviceTask.TaskType;
|
||||
import dark.api.al.coding.args.ArgumentData;
|
||||
import dark.api.al.coding.args.ArgumentFloatData;
|
||||
|
@ -40,7 +40,7 @@ public class CommandFire extends TaskArmbot
|
|||
}
|
||||
|
||||
@Override
|
||||
public ProcessReturn onMethodCalled(World world, Vector3 location, ILogicDevice armbot)
|
||||
public ProcessReturn onMethodCalled(World world, Vector3 location, IProgramableMachine armbot)
|
||||
{
|
||||
super.onMethodCalled(world, location, armbot);
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ import universalelectricity.core.vector.Vector3;
|
|||
|
||||
import com.builtbroken.common.science.units.UnitHelper;
|
||||
|
||||
import dark.api.al.coding.ILogicDevice;
|
||||
import dark.api.al.coding.IProgramableMachine;
|
||||
import dark.api.al.coding.args.ArgumentIntData;
|
||||
import dark.assembly.common.armbot.TaskArmbot;
|
||||
import dark.assembly.common.armbot.TaskBase;
|
||||
|
@ -36,7 +36,7 @@ public class CommandGive extends TaskArmbot
|
|||
}
|
||||
|
||||
@Override
|
||||
public ProcessReturn onMethodCalled(World world, Vector3 location, ILogicDevice armbot)
|
||||
public ProcessReturn onMethodCalled(World world, Vector3 location, IProgramableMachine armbot)
|
||||
{
|
||||
super.onMethodCalled(world, location, armbot);
|
||||
|
||||
|
@ -111,7 +111,7 @@ public class CommandGive extends TaskArmbot
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean canUseTask(ILogicDevice device)
|
||||
public boolean canUseTask(IProgramableMachine device)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
|
|
|
@ -10,7 +10,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.world.World;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import dark.api.al.coding.ILogicDevice;
|
||||
import dark.api.al.coding.IProgramableMachine;
|
||||
import dark.api.al.coding.args.ArgumentData;
|
||||
import dark.api.al.coding.args.ArgumentListData;
|
||||
import dark.assembly.common.armbot.GrabDictionary;
|
||||
|
@ -33,7 +33,7 @@ public class CommandGrabEntity extends CommandGrabPrefab
|
|||
}
|
||||
|
||||
@Override
|
||||
public ProcessReturn onMethodCalled(World world, Vector3 location, ILogicDevice armbot)
|
||||
public ProcessReturn onMethodCalled(World world, Vector3 location, IProgramableMachine armbot)
|
||||
{
|
||||
super.onMethodCalled(world, location, armbot);
|
||||
this.entityToInclude = Entity.class;
|
||||
|
|
|
@ -11,7 +11,7 @@ import universalelectricity.core.vector.Vector3;
|
|||
|
||||
import com.builtbroken.common.science.units.UnitHelper;
|
||||
|
||||
import dark.api.al.coding.ILogicDevice;
|
||||
import dark.api.al.coding.IProgramableMachine;
|
||||
import dark.api.al.coding.args.ArgumentIntData;
|
||||
import dark.assembly.common.armbot.TaskBase;
|
||||
|
||||
|
@ -28,7 +28,7 @@ public class CommandGrabItem extends CommandGrabPrefab
|
|||
}
|
||||
|
||||
@Override
|
||||
public ProcessReturn onMethodCalled(World world, Vector3 location, ILogicDevice armbot)
|
||||
public ProcessReturn onMethodCalled(World world, Vector3 location, IProgramableMachine armbot)
|
||||
{
|
||||
super.onMethodCalled(world, location, armbot);
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ import net.minecraft.world.World;
|
|||
import net.minecraftforge.common.ForgeDirection;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import dark.api.al.IBelt;
|
||||
import dark.api.al.coding.ILogicDevice;
|
||||
import dark.api.al.coding.IProgramableMachine;
|
||||
import dark.assembly.common.armbot.GrabDictionary;
|
||||
import dark.assembly.common.armbot.TaskArmbot;
|
||||
import dark.assembly.common.armbot.TaskBase;
|
||||
|
@ -35,7 +35,7 @@ public abstract class CommandGrabPrefab extends TaskArmbot
|
|||
}
|
||||
|
||||
@Override
|
||||
public ProcessReturn onMethodCalled(World world, Vector3 location, ILogicDevice armbot)
|
||||
public ProcessReturn onMethodCalled(World world, Vector3 location, IProgramableMachine armbot)
|
||||
{
|
||||
ProcessReturn re = super.onMethodCalled(world, location, armbot);
|
||||
if (re == ProcessReturn.CONTINUE)
|
||||
|
|
|
@ -3,7 +3,7 @@ package dark.assembly.common.armbot.command;
|
|||
import net.minecraft.world.World;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import dark.api.al.coding.IArmbot;
|
||||
import dark.api.al.coding.ILogicDevice;
|
||||
import dark.api.al.coding.IProgramableMachine;
|
||||
import dark.api.al.coding.IDeviceTask.TaskType;
|
||||
|
||||
/** Used by arms to break a specific block in a position.
|
||||
|
@ -18,7 +18,7 @@ public class CommandHarvest extends CommandBreak
|
|||
}
|
||||
|
||||
@Override
|
||||
public ProcessReturn onMethodCalled(World world, Vector3 location, ILogicDevice armbot)
|
||||
public ProcessReturn onMethodCalled(World world, Vector3 location, IProgramableMachine armbot)
|
||||
{
|
||||
this.keep = true;
|
||||
return super.onMethodCalled(world, location, armbot);
|
||||
|
|
|
@ -4,7 +4,7 @@ import com.builtbroken.common.science.units.UnitHelper;
|
|||
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import dark.api.al.coding.IArmbot;
|
||||
import dark.api.al.coding.ILogicDevice;
|
||||
import dark.api.al.coding.IProgramableMachine;
|
||||
import dark.api.al.coding.IDeviceTask.TaskType;
|
||||
import dark.api.al.coding.args.ArgumentData;
|
||||
import dark.assembly.common.armbot.TaskBase;
|
||||
|
@ -25,7 +25,7 @@ public class CommandIdle extends TaskBase
|
|||
}
|
||||
|
||||
@Override
|
||||
public ProcessReturn onMethodCalled(World world, Vector3 location, ILogicDevice armbot)
|
||||
public ProcessReturn onMethodCalled(World world, Vector3 location, IProgramableMachine armbot)
|
||||
{
|
||||
super.onMethodCalled(world, location, armbot);
|
||||
|
||||
|
@ -79,7 +79,7 @@ public class CommandIdle extends TaskBase
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean canUseTask(ILogicDevice device)
|
||||
public boolean canUseTask(IProgramableMachine device)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package dark.assembly.common.armbot.command;
|
|||
import com.builtbroken.common.science.units.UnitHelper;
|
||||
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import dark.api.al.coding.ILogicDevice;
|
||||
import dark.api.al.coding.IProgramableMachine;
|
||||
import dark.api.al.coding.IDeviceTask.ProcessReturn;
|
||||
import dark.api.al.coding.IDeviceTask.TaskType;
|
||||
import dark.api.al.coding.args.ArgumentIntData;
|
||||
|
@ -31,7 +31,7 @@ public class CommandRotateBy extends TaskArmbot
|
|||
}
|
||||
|
||||
@Override
|
||||
public ProcessReturn onMethodCalled(World world, Vector3 location, ILogicDevice armbot)
|
||||
public ProcessReturn onMethodCalled(World world, Vector3 location, IProgramableMachine armbot)
|
||||
{
|
||||
super.onMethodCalled(world, location, armbot);
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import universalelectricity.core.vector.Vector3;
|
|||
import com.builtbroken.common.science.units.UnitHelper;
|
||||
|
||||
import dark.api.al.coding.IArmbot;
|
||||
import dark.api.al.coding.ILogicDevice;
|
||||
import dark.api.al.coding.IProgramableMachine;
|
||||
import dark.api.al.coding.IDeviceTask.TaskType;
|
||||
import dark.api.al.coding.args.ArgumentIntData;
|
||||
import dark.assembly.common.armbot.TaskBase;
|
||||
|
@ -36,7 +36,7 @@ public class CommandRotateTo extends TaskArmbot
|
|||
}
|
||||
|
||||
@Override
|
||||
public ProcessReturn onMethodCalled(World world, Vector3 location, ILogicDevice device)
|
||||
public ProcessReturn onMethodCalled(World world, Vector3 location, IProgramableMachine device)
|
||||
{
|
||||
super.onMethodCalled(world, location, device);
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ import universalelectricity.core.vector.Vector3;
|
|||
|
||||
import com.builtbroken.common.science.units.UnitHelper;
|
||||
|
||||
import dark.api.al.coding.ILogicDevice;
|
||||
import dark.api.al.coding.IProgramableMachine;
|
||||
import dark.api.al.coding.IDeviceTask.ProcessReturn;
|
||||
import dark.api.al.coding.args.ArgumentIntData;
|
||||
import dark.assembly.common.armbot.TaskArmbot;
|
||||
|
@ -36,7 +36,7 @@ public class CommandTake extends TaskArmbot
|
|||
}
|
||||
|
||||
@Override
|
||||
public ProcessReturn onMethodCalled(World world, Vector3 location, ILogicDevice armbot)
|
||||
public ProcessReturn onMethodCalled(World world, Vector3 location, IProgramableMachine armbot)
|
||||
{
|
||||
super.onMethodCalled(world, location, armbot);
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ import net.minecraft.tileentity.TileEntity;
|
|||
import net.minecraft.world.World;
|
||||
import dark.api.al.coding.IArmbotUseable;
|
||||
import dark.api.al.coding.IDeviceTask;
|
||||
import dark.api.al.coding.ILogicDevice;
|
||||
import dark.api.al.coding.IProgramableMachine;
|
||||
import dark.api.al.coding.IDeviceTask.ProcessReturn;
|
||||
import dark.api.al.coding.IDeviceTask.TaskType;
|
||||
import dark.api.al.coding.args.ArgumentData;
|
||||
|
@ -29,7 +29,7 @@ public class CommandUse extends TaskArmbot
|
|||
}
|
||||
|
||||
@Override
|
||||
public ProcessReturn onMethodCalled(World world, Vector3 location, ILogicDevice armbot)
|
||||
public ProcessReturn onMethodCalled(World world, Vector3 location, IProgramableMachine armbot)
|
||||
{
|
||||
super.onMethodCalled(world, location, armbot);
|
||||
this.curTimes = 0;
|
||||
|
|
|
@ -3,7 +3,7 @@ package dark.assembly.common.armbot.command;
|
|||
import universalelectricity.core.vector.Vector2;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import dark.api.al.coding.IDeviceTask;
|
||||
import dark.api.al.coding.ILogicDevice;
|
||||
import dark.api.al.coding.IProgramableMachine;
|
||||
import dark.api.al.coding.ISplitArmbotTask;
|
||||
import dark.assembly.common.armbot.TaskBase;
|
||||
|
||||
|
@ -103,7 +103,7 @@ public class TaskIF extends TaskBase implements ISplitArmbotTask
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean canUseTask(ILogicDevice device)
|
||||
public boolean canUseTask(IProgramableMachine device)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import com.builtbroken.common.science.units.UnitHelper;
|
|||
import universalelectricity.core.vector.Vector2;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import dark.api.al.coding.IDeviceTask;
|
||||
import dark.api.al.coding.ILogicDevice;
|
||||
import dark.api.al.coding.IProgramableMachine;
|
||||
import dark.api.al.coding.ISplitArmbotTask;
|
||||
import dark.api.al.coding.IDeviceTask.TaskType;
|
||||
import dark.api.al.coding.args.ArgumentIntData;
|
||||
|
@ -35,7 +35,7 @@ public class TaskLoop extends TaskBase implements ISplitArmbotTask
|
|||
}
|
||||
|
||||
@Override
|
||||
public ProcessReturn onMethodCalled(World world, Vector3 location, ILogicDevice armbot)
|
||||
public ProcessReturn onMethodCalled(World world, Vector3 location, IProgramableMachine armbot)
|
||||
{
|
||||
super.onMethodCalled(world, location, armbot);
|
||||
this.numReps = UnitHelper.tryToParseInt(this.getArg("loop"), 1);
|
||||
|
@ -43,7 +43,7 @@ public class TaskLoop extends TaskBase implements ISplitArmbotTask
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean canUseTask(ILogicDevice device)
|
||||
public boolean canUseTask(IProgramableMachine device)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1,82 +1,32 @@
|
|||
package dark.assembly.common.machine.encoder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.INetworkManager;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
import universalelectricity.prefab.network.IPacketReceiver;
|
||||
import universalelectricity.prefab.tile.TileEntityAdvanced;
|
||||
import universalelectricity.core.vector.Vector2;
|
||||
import universalelectricity.prefab.network.PacketManager;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import dark.assembly.common.armbot.TaskBase;
|
||||
import cpw.mods.fml.common.network.PacketDispatcher;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import dark.api.al.coding.IDeviceTask;
|
||||
import dark.api.al.coding.IProgram;
|
||||
import dark.api.al.coding.TaskRegistry;
|
||||
import dark.assembly.common.armbot.Program;
|
||||
import dark.core.common.DarkMain;
|
||||
import dark.core.network.PacketHandler;
|
||||
import dark.core.prefab.machine.TileEntityMachine;
|
||||
|
||||
public class TileEntityEncoder extends TileEntityAdvanced implements IPacketReceiver, ISidedInventory
|
||||
public class TileEntityEncoder extends TileEntityMachine implements ISidedInventory
|
||||
{
|
||||
private ItemStack disk;
|
||||
private IInventoryWatcher watcher;
|
||||
|
||||
public TileEntityEncoder()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slot)
|
||||
{
|
||||
if (slot == 0)
|
||||
return disk;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int slot, int amount)
|
||||
{
|
||||
if (slot == 0)
|
||||
{
|
||||
if (amount >= 1)
|
||||
{
|
||||
ItemStack ret = disk.copy();
|
||||
disk = null;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int slot)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int slot, ItemStack stack)
|
||||
{
|
||||
if (slot == 0)
|
||||
{
|
||||
if (stack != null)
|
||||
{
|
||||
if (stack.stackSize > 1)
|
||||
{
|
||||
stack.stackSize = 1;
|
||||
}
|
||||
}
|
||||
disk = stack;
|
||||
}
|
||||
}
|
||||
public static final String PROGRAM_ID = "program", PROGRAM_CHANGE = "programChange", REMOVE_TASK = "removeTask";
|
||||
protected IProgram program;
|
||||
|
||||
@Override
|
||||
public void onInventoryChanged()
|
||||
|
@ -98,22 +48,6 @@ public class TileEntityEncoder extends TileEntityAdvanced implements IPacketRece
|
|||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer player)
|
||||
{
|
||||
return this.worldObj.getBlockTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : player.getDistanceSq(this.xCoord + 0.5D, this.yCoord + 0.5D, this.zCoord + 0.5D) <= 64.0D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openChest()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeChest()
|
||||
{
|
||||
}
|
||||
|
||||
public void setWatcher(IInventoryWatcher watcher)
|
||||
{
|
||||
this.watcher = watcher;
|
||||
|
@ -152,39 +86,88 @@ public class TileEntityEncoder extends TileEntityAdvanced implements IPacketRece
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream)
|
||||
public boolean simplePacket(String id, ByteArrayDataInput dis, Player player)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER)
|
||||
boolean su = super.simplePacket(id, dis, player);
|
||||
if (!su)
|
||||
{
|
||||
if (this.disk != null)
|
||||
if (this.worldObj.isRemote)
|
||||
{
|
||||
ArrayList<String> tempCmds = ItemDisk.getCommands(this.disk);
|
||||
|
||||
if (dataStream.readBoolean())
|
||||
if (id.equalsIgnoreCase(TileEntityEncoder.PROGRAM_ID))
|
||||
{
|
||||
String newCommand = dataStream.readUTF();
|
||||
|
||||
// Split commands that contains parameters
|
||||
String commandName = newCommand.split(" ")[0];
|
||||
|
||||
if (TaskBase.getCommand(commandName) != null)
|
||||
tempCmds.add(newCommand);
|
||||
if (dis.readBoolean())
|
||||
{
|
||||
Program program = new Program();
|
||||
program.load(PacketManager.readNBTTagCompound(dis));
|
||||
this.program = program;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.program = null;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
if (id.equalsIgnoreCase(TileEntityEncoder.PROGRAM_CHANGE))
|
||||
{
|
||||
int commandToRemove = dataStream.readInt();
|
||||
tempCmds.remove(commandToRemove);
|
||||
}
|
||||
|
||||
ItemDisk.setCommands(this.disk, tempCmds);
|
||||
IDeviceTask task = TaskRegistry.getCommand(dis.readUTF());
|
||||
task.setPosition(new Vector2(dis.readInt(), dis.readInt()));
|
||||
task.load(PacketManager.readNBTTagCompound(dis));
|
||||
this.program.setTaskAt(task.getPosition(), task);
|
||||
this.sendGUIPacket();
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (id.equalsIgnoreCase(TileEntityEncoder.REMOVE_TASK))
|
||||
{
|
||||
this.program.setTaskAt(new Vector2(dis.readInt(), dis.readInt()), null);
|
||||
this.sendGUIPacket();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return su;
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/** Sends a gui packet only to the given player */
|
||||
public void sendGUIPacket(EntityPlayer entity)
|
||||
{
|
||||
if (entity != null)
|
||||
{
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
boolean exists = this.program != null;
|
||||
if (exists)
|
||||
{
|
||||
this.program.save(tag);
|
||||
}
|
||||
PacketDispatcher.sendPacketToPlayer(PacketHandler.instance().getPacket(DarkMain.CHANNEL, this, this.program, exists, tag), (Player) entity);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeTask(Vector2 vec)
|
||||
{
|
||||
if (vec != null)
|
||||
{
|
||||
PacketDispatcher.sendPacketToServer(PacketHandler.instance().getPacket(DarkMain.CHANNEL, this, vec.intX(), vec.intY()));
|
||||
}
|
||||
}
|
||||
|
||||
public void updateTask(IDeviceTask task)
|
||||
{
|
||||
if (task != null)
|
||||
{
|
||||
PacketDispatcher.sendPacketToServer(PacketHandler.instance().getPacket(DarkMain.CHANNEL, this, task.getPosition().intX(), task.getPosition().intY(), task.save(new NBTTagCompound())));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -194,33 +177,4 @@ public class TileEntityEncoder extends TileEntityAdvanced implements IPacketRece
|
|||
//TODO ?
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide(int var1)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsertItem(int i, ItemStack itemstack, int j)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem(int i, ItemStack itemstack, int j)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue