Got encoder working
Well not fully but it can send the program to the client. The client can remove and edit parts of the program. Though some changes don't save due to the task not being fully setup yet.
This commit is contained in:
parent
a3009a72a7
commit
fad9b46b4d
12 changed files with 258 additions and 131 deletions
|
@ -13,12 +13,12 @@ public class TaskRegistry
|
|||
/** A class of all available commands.
|
||||
*
|
||||
* String - Command name. Command - The actual command class. */
|
||||
private static final HashMap<String, IProcessTask> COMMANDS = new HashMap();
|
||||
private static final HashMap<String, ITask> 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(IProcessTask task)
|
||||
public static void registerCommand(ITask task)
|
||||
{
|
||||
if (!COMMANDS.containsKey(task.getMethodName()))
|
||||
{
|
||||
|
@ -35,9 +35,9 @@ public class TaskRegistry
|
|||
}
|
||||
|
||||
/** returns the first command with the same name */
|
||||
public static IProcessTask getCommand(String name)
|
||||
public static ITask getCommand(String name)
|
||||
{
|
||||
for (Entry<String, IProcessTask> command : COMMANDS.entrySet())
|
||||
for (Entry<String, ITask> command : COMMANDS.entrySet())
|
||||
{
|
||||
if (command.getKey().equalsIgnoreCase(name))
|
||||
{
|
||||
|
@ -48,10 +48,10 @@ public class TaskRegistry
|
|||
}
|
||||
|
||||
/** Gets all commands with the given name though there should only be one */
|
||||
public static List<IProcessTask> getCommands(String name)
|
||||
public static List<ITask> getCommands(String name)
|
||||
{
|
||||
List<IProcessTask> tasks = new ArrayList<IProcessTask>();
|
||||
for (Entry<String, IProcessTask> command : COMMANDS.entrySet())
|
||||
List<ITask> tasks = new ArrayList<ITask>();
|
||||
for (Entry<String, ITask> command : COMMANDS.entrySet())
|
||||
{
|
||||
if (command.getValue().getMethodName().equalsIgnoreCase(name))
|
||||
{
|
||||
|
|
|
@ -23,12 +23,28 @@ import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
|||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import cpw.mods.fml.common.network.NetworkMod;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import dark.api.al.coding.TaskRegistry;
|
||||
import dark.assembly.armbot.BlockArmbot;
|
||||
import dark.assembly.armbot.TileEntityArmbot;
|
||||
import dark.assembly.armbot.command.TaskBreak;
|
||||
import dark.assembly.armbot.command.TaskDrop;
|
||||
import dark.assembly.armbot.command.TaskEnd;
|
||||
import dark.assembly.armbot.command.TaskFire;
|
||||
import dark.assembly.armbot.command.TaskGOTO;
|
||||
import dark.assembly.armbot.command.TaskGive;
|
||||
import dark.assembly.armbot.command.TaskGrabEntity;
|
||||
import dark.assembly.armbot.command.TaskGrabItem;
|
||||
import dark.assembly.armbot.command.TaskHarvest;
|
||||
import dark.assembly.armbot.command.TaskIF;
|
||||
import dark.assembly.armbot.command.TaskIdle;
|
||||
import dark.assembly.armbot.command.TaskPlace;
|
||||
import dark.assembly.armbot.command.TaskReturn;
|
||||
import dark.assembly.armbot.command.TaskRotateBy;
|
||||
import dark.assembly.armbot.command.TaskRotateTo;
|
||||
import dark.assembly.armbot.command.TaskStart;
|
||||
import dark.assembly.armbot.command.TaskTake;
|
||||
import dark.assembly.armbot.command.TaskUse;
|
||||
import dark.assembly.imprinter.BlockImprinter;
|
||||
import dark.assembly.imprinter.ItemImprinter;
|
||||
import dark.assembly.imprinter.TileEntityImprinter;
|
||||
import dark.assembly.machine.BlockCrate;
|
||||
import dark.assembly.machine.BlockDetector;
|
||||
import dark.assembly.machine.BlockManipulator;
|
||||
|
@ -36,15 +52,9 @@ import dark.assembly.machine.BlockRejector;
|
|||
import dark.assembly.machine.BlockTurntable;
|
||||
import dark.assembly.machine.ItemBlockCrate;
|
||||
import dark.assembly.machine.TileEntityAssembly;
|
||||
import dark.assembly.machine.TileEntityCrate;
|
||||
import dark.assembly.machine.TileEntityDetector;
|
||||
import dark.assembly.machine.TileEntityManipulator;
|
||||
import dark.assembly.machine.TileEntityRejector;
|
||||
import dark.assembly.machine.belt.BlockConveyorBelt;
|
||||
import dark.assembly.machine.belt.TileEntityConveyorBelt;
|
||||
import dark.assembly.machine.encoder.BlockEncoder;
|
||||
import dark.assembly.machine.encoder.ItemDisk;
|
||||
import dark.assembly.machine.encoder.TileEntityEncoder;
|
||||
import dark.assembly.machine.processor.BlockProcessor;
|
||||
import dark.assembly.machine.red.BlockAdvancedHopper;
|
||||
import dark.core.common.DMCreativeTab;
|
||||
|
@ -100,6 +110,25 @@ public class AssemblyLine extends ModPrefab
|
|||
NetworkRegistry.instance().registerGuiHandler(this, proxy);
|
||||
|
||||
proxy.preInit();
|
||||
|
||||
TaskRegistry.registerCommand(new TaskDrop());
|
||||
TaskRegistry.registerCommand(new TaskGive());
|
||||
TaskRegistry.registerCommand(new TaskTake());
|
||||
TaskRegistry.registerCommand(new TaskGrabItem());
|
||||
TaskRegistry.registerCommand(new TaskGrabEntity());
|
||||
TaskRegistry.registerCommand(new TaskRotateBy());
|
||||
TaskRegistry.registerCommand(new TaskRotateTo());
|
||||
TaskRegistry.registerCommand(new TaskUse());
|
||||
TaskRegistry.registerCommand(new TaskIF());
|
||||
TaskRegistry.registerCommand(new TaskGOTO());
|
||||
TaskRegistry.registerCommand(new TaskReturn());
|
||||
TaskRegistry.registerCommand(new TaskEnd());
|
||||
TaskRegistry.registerCommand(new TaskFire());
|
||||
TaskRegistry.registerCommand(new TaskHarvest());
|
||||
TaskRegistry.registerCommand(new TaskPlace());
|
||||
TaskRegistry.registerCommand(new TaskBreak());
|
||||
TaskRegistry.registerCommand(new TaskStart());
|
||||
TaskRegistry.registerCommand(new TaskIdle());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -248,14 +248,12 @@ public class Program implements IProgram
|
|||
{
|
||||
entry.getValue().setPosition(entry.getKey().intX(), entry.getKey().intY());
|
||||
NBTTagCompound task = entry.getValue().save(new NBTTagCompound());
|
||||
if (entry.getKey().equals(new Vector2(this.currentTask.getCol(), this.currentTask.getRow())))
|
||||
if (this.currentTask != null && entry.getKey().equals(new Vector2(this.currentTask.getCol(), this.currentTask.getRow())))
|
||||
{
|
||||
task.setBoolean("currentTask", true);
|
||||
entry.getValue().saveProgress(task);
|
||||
}
|
||||
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);
|
||||
|
@ -277,6 +275,8 @@ public class Program implements IProgram
|
|||
for (int s = 0; s < taskList.tagCount(); ++s)
|
||||
{
|
||||
NBTTagCompound tag = (NBTTagCompound) taskList.tagAt(s);
|
||||
if (tag.hasKey("methodName"))
|
||||
{
|
||||
ITask task = TaskRegistry.getCommand(tag.getString("methodName"));
|
||||
if (task != null)
|
||||
{
|
||||
|
@ -284,14 +284,13 @@ public class Program implements IProgram
|
|||
if (task != null)
|
||||
{
|
||||
task.load(tag);
|
||||
task.setPosition(nbt.getInteger("positionX"), nbt.getInteger("positionY"));
|
||||
this.tasks.put(new Vector2(task.getCol(), task.getRow()), task);
|
||||
if (tag.getBoolean("currentTask"))
|
||||
{
|
||||
this.currentTask = task;
|
||||
task.loadProgress(tag);
|
||||
this.currentPos = new Vector2(task.getCol(), task.getRow());
|
||||
}
|
||||
this.tasks.put(new Vector2(task.getCol(), task.getRow()), task);
|
||||
if (task.getCol() > this.width)
|
||||
{
|
||||
this.width = task.getCol();
|
||||
|
@ -302,6 +301,11 @@ public class Program implements IProgram
|
|||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("[CoreMachine]Error: failed to load task " + tag.getString("methodName"));
|
||||
}
|
||||
}
|
||||
}
|
||||
taskList = nbt.getTagList("vars");
|
||||
for (int s = 0; s < taskList.tagCount(); ++s)
|
||||
|
|
|
@ -27,7 +27,7 @@ public class TaskGrabEntity extends TaskGrabPrefab
|
|||
{
|
||||
super("Grab-Entity");
|
||||
this.defautlArguments.add(new ArgumentData("child", false));
|
||||
this.defautlArguments.add(new ArgumentListData<Class<? extends Entity>>("Entity", Entity.class, (Class<? extends Entity>[]) EntityDictionary.getList().toArray(new Object[1])));
|
||||
//this.defautlArguments.add(new ArgumentListData<Class<? extends Entity>>("Entity", Entity.class, (Class<? extends Entity>[]) EntityDictionary.getList().toArray(new Object[1])));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -51,12 +51,27 @@ public class TaskIdle extends TaskBaseProcess
|
|||
return ProcessReturn.DONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskBaseProcess load(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.load(taskCompound);
|
||||
this.totalIdleTime = taskCompound.getInteger("idleTotal");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound save(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.save(taskCompound);
|
||||
taskCompound.setInteger("idleTotal", this.totalIdleTime);
|
||||
return taskCompound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskBaseProcess loadProgress(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.loadProgress(taskCompound);
|
||||
this.idleTime = taskCompound.getInteger("idleTime");
|
||||
this.totalIdleTime = taskCompound.getInteger("idleTotal");
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -65,7 +80,6 @@ public class TaskIdle extends TaskBaseProcess
|
|||
{
|
||||
super.saveProgress(taskCompound);
|
||||
taskCompound.setInteger("idleTime", this.idleTime);
|
||||
taskCompound.setInteger("idleTotal", this.totalIdleTime);
|
||||
return taskCompound;
|
||||
}
|
||||
|
||||
|
|
|
@ -72,7 +72,7 @@ public class TaskRotateTo extends TaskBaseArmbot
|
|||
@Override
|
||||
public TaskRotateTo load(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.loadProgress(taskCompound);
|
||||
super.load(taskCompound);
|
||||
this.targetRotationPitch = taskCompound.getInteger("rotPitch");
|
||||
this.targetRotationYaw = taskCompound.getInteger("rotYaw");
|
||||
return this;
|
||||
|
@ -81,7 +81,7 @@ public class TaskRotateTo extends TaskBaseArmbot
|
|||
@Override
|
||||
public NBTTagCompound save(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.saveProgress(taskCompound);
|
||||
super.save(taskCompound);
|
||||
taskCompound.setInteger("rotPitch", this.targetRotationPitch);
|
||||
taskCompound.setInteger("rotYaw", this.targetRotationYaw);
|
||||
return taskCompound;
|
||||
|
|
|
@ -88,7 +88,7 @@ public class TaskTake extends TaskBaseArmbot
|
|||
@Override
|
||||
public TaskTake load(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.loadProgress(taskCompound);
|
||||
super.load(taskCompound);
|
||||
this.stack = ItemStack.loadItemStackFromNBT(taskCompound.getCompoundTag("item"));
|
||||
return this;
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ public class TaskTake extends TaskBaseArmbot
|
|||
@Override
|
||||
public NBTTagCompound save(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.saveProgress(taskCompound);
|
||||
super.save(taskCompound);
|
||||
if (stack != null)
|
||||
{
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
|
|
|
@ -89,7 +89,7 @@ public class TaskUse extends TaskBaseArmbot
|
|||
@Override
|
||||
public TaskUse load(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.loadProgress(taskCompound);
|
||||
super.load(taskCompound);
|
||||
this.times = taskCompound.getInteger("useTimes");
|
||||
|
||||
return this;
|
||||
|
@ -98,7 +98,7 @@ public class TaskUse extends TaskBaseArmbot
|
|||
@Override
|
||||
public NBTTagCompound save(NBTTagCompound taskCompound)
|
||||
{
|
||||
super.saveProgress(taskCompound);
|
||||
super.save(taskCompound);
|
||||
taskCompound.setInteger("useTimes", this.times);
|
||||
|
||||
return taskCompound;
|
||||
|
|
|
@ -11,14 +11,17 @@ import net.minecraft.util.ResourceLocation;
|
|||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import universalelectricity.core.vector.Vector2;
|
||||
import cpw.mods.fml.client.FMLClientHandler;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import dark.api.al.coding.ITask;
|
||||
import dark.api.al.coding.args.ArgumentData;
|
||||
import dark.assembly.AssemblyLine;
|
||||
import dark.core.prefab.invgui.GuiBase;
|
||||
import dark.core.prefab.invgui.GuiMessageBox;
|
||||
import dark.core.prefab.invgui.IMessageBoxDialog;
|
||||
|
||||
public class GuiEditTask extends GuiBase
|
||||
public class GuiEditTask extends GuiBase implements IMessageBoxDialog
|
||||
{
|
||||
public static final ResourceLocation TEXTURE = new ResourceLocation(AssemblyLine.instance.DOMAIN, AssemblyLine.GUI_DIRECTORY + "gui_task_edit.png");
|
||||
|
||||
|
@ -38,7 +41,6 @@ public class GuiEditTask extends GuiBase
|
|||
this.editTask.load(task.save(new NBTTagCompound()));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void initGui()
|
||||
{
|
||||
|
@ -47,6 +49,7 @@ public class GuiEditTask extends GuiBase
|
|||
Keyboard.enableRepeatEvents(true);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void drawButtons()
|
||||
{
|
||||
this.buttonList.clear();
|
||||
|
@ -151,17 +154,16 @@ public class GuiEditTask extends GuiBase
|
|||
{
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
|
||||
if (button.id == 0)
|
||||
{
|
||||
//TODO save task
|
||||
}
|
||||
else if (button.id == 2)
|
||||
{
|
||||
//TODO del task, first open a yes/no gui
|
||||
this.gui.getTile().updateTask(this.editTask);
|
||||
}
|
||||
FMLCommonHandler.instance().showGuiScreen(this.gui);
|
||||
break;
|
||||
case 2:
|
||||
new GuiMessageBox(this, 0, "Remove Task", "Are you sure?").show();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -169,7 +171,6 @@ public class GuiEditTask extends GuiBase
|
|||
@Override
|
||||
protected void drawBackgroundLayer(int x, int y, float var1)
|
||||
{
|
||||
this.drawButtons();
|
||||
FMLClientHandler.instance().getClient().renderEngine.bindTexture(TEXTURE);
|
||||
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
|
@ -217,4 +218,14 @@ public class GuiEditTask extends GuiBase
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageBoxClosed(int id, boolean yes)
|
||||
{
|
||||
if (id == 0 && yes)
|
||||
{
|
||||
this.gui.getTile().removeTask(new Vector2(this.editTask.getCol(), this.editTask.getRow()));
|
||||
FMLCommonHandler.instance().showGuiScreen(this.gui);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import org.lwjgl.input.Mouse;
|
|||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import dark.assembly.AssemblyLine;
|
||||
import dark.assembly.machine.encoder.TileEntityEncoder;
|
||||
|
@ -42,6 +43,8 @@ public class GuiEncoderCoder extends GuiEncoderBase
|
|||
protected void actionPerformed(GuiButton button)
|
||||
{
|
||||
super.actionPerformed(button);
|
||||
if (((TileEntityEncoder) tileEntity).getProgram() != null)
|
||||
{
|
||||
switch (button.id)
|
||||
{
|
||||
case 3:
|
||||
|
@ -58,6 +61,7 @@ public class GuiEncoderCoder extends GuiEncoderBase
|
|||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected GuiTaskList getTaskListElement(boolean renew)
|
||||
{
|
||||
|
@ -81,6 +85,8 @@ public class GuiEncoderCoder extends GuiEncoderBase
|
|||
{
|
||||
super.handleMouseInput();
|
||||
int wheel = Mouse.getEventDWheel();
|
||||
if (((TileEntityEncoder) tileEntity).getProgram() != null)
|
||||
{
|
||||
if (wheel > 0)
|
||||
{
|
||||
this.getTaskListElement().scroll(-2);
|
||||
|
@ -90,6 +96,7 @@ public class GuiEncoderCoder extends GuiEncoderBase
|
|||
this.getTaskListElement().scroll(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char character, int keycode)
|
||||
|
@ -98,7 +105,10 @@ public class GuiEncoderCoder extends GuiEncoderBase
|
|||
{
|
||||
this.mc.thePlayer.closeScreen();
|
||||
}
|
||||
else if (keycode == Keyboard.KEY_UP) // PAGE UP (no constant)
|
||||
else if (((TileEntityEncoder) tileEntity).getProgram() != null)
|
||||
{
|
||||
|
||||
if (keycode == Keyboard.KEY_UP) // PAGE UP (no constant)
|
||||
{
|
||||
this.getTaskListElement().scroll(-1);
|
||||
}
|
||||
|
@ -117,6 +127,7 @@ public class GuiEncoderCoder extends GuiEncoderBase
|
|||
this.getTaskListElement().scrollSide(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected GuiTaskList getTaskListElement()
|
||||
{
|
||||
|
@ -147,4 +158,10 @@ public class GuiEncoderCoder extends GuiEncoderBase
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntityEncoder getTile()
|
||||
{
|
||||
return (TileEntityEncoder) this.tileEntity;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -37,10 +37,11 @@ public class GuiTaskList extends Gui implements IScroll
|
|||
this.xPos = x;
|
||||
this.yPos = y;
|
||||
this.coder = coder;
|
||||
this.entity = entity;
|
||||
|
||||
if (entity instanceof TileEntityEncoder && ((TileEntityEncoder) entity).getProgram() != null)
|
||||
if (this.getProgram() != null)
|
||||
{
|
||||
if (((TileEntityEncoder) entity).getProgram().getSize().intX() < (this.countX / 2))
|
||||
if (this.getProgram().getSize().intX() < (this.countX / 2))
|
||||
{
|
||||
this.scrollX = -2;
|
||||
}
|
||||
|
@ -49,6 +50,11 @@ public class GuiTaskList extends Gui implements IScroll
|
|||
this.scrollX = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.scrollX = 0;
|
||||
this.scrollY = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -93,29 +99,32 @@ public class GuiTaskList extends Gui implements IScroll
|
|||
for (int row = 0; row < countY; row++)
|
||||
{
|
||||
int actualRow = row + this.scrollY - 1;
|
||||
if (actualRow <= this.getProgram().getSize().intY() + 1 && actualRow >= -1)
|
||||
boolean drawnButton = false;
|
||||
|
||||
if (this.getProgram() != null)
|
||||
{
|
||||
ITask task = this.getProgram().getTaskAt(actualCol, actualRow);
|
||||
if (actualRow == -1 && colume + this.scrollX - 1 == -1)
|
||||
{
|
||||
task = new TaskStart();
|
||||
}
|
||||
if (actualRow == this.getProgram().getSize().intY() + 1 && colume + this.scrollX - 1 == -1)
|
||||
else if (actualRow == this.getProgram().getSize().intY() + 1 && colume + this.scrollX - 1 == -1)
|
||||
{
|
||||
task = new TaskEnd();
|
||||
}
|
||||
if (task != null && (!(task instanceof IRedirectTask) || task instanceof IRedirectTask && ((IRedirectTask) task).render()))
|
||||
{
|
||||
drawnButton = true;
|
||||
FMLClientHandler.instance().getClient().renderEngine.bindTexture(task.getTextureSheet());
|
||||
this.drawTexturedModalRect(xPos + (20 * colume), yPos + (20 * row), task.getTextureUV().intX(), task.getTextureUV().intY(), 20, 20);
|
||||
}
|
||||
else
|
||||
}
|
||||
if (!drawnButton)
|
||||
{
|
||||
FMLClientHandler.instance().getClient().renderEngine.bindTexture(ITask.TaskType.TEXTURE);
|
||||
this.drawTexturedModalRect(xPos + (20 * colume), yPos + (20 * row), 0, 40, 20, 20);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,9 +3,11 @@ package dark.assembly.machine.encoder;
|
|||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.packet.Packet;
|
||||
import universalelectricity.core.vector.Vector2;
|
||||
import universalelectricity.prefab.network.PacketManager;
|
||||
|
||||
|
@ -15,6 +17,7 @@ import cpw.mods.fml.common.network.PacketDispatcher;
|
|||
import cpw.mods.fml.common.network.Player;
|
||||
import dark.api.al.coding.IProcessTask;
|
||||
import dark.api.al.coding.IProgram;
|
||||
import dark.api.al.coding.ITask;
|
||||
import dark.api.al.coding.TaskRegistry;
|
||||
import dark.assembly.armbot.Program;
|
||||
import dark.assembly.armbot.command.TaskDrop;
|
||||
|
@ -26,17 +29,27 @@ import dark.assembly.armbot.command.TaskRotateTo;
|
|||
import dark.core.common.DarkMain;
|
||||
import dark.core.network.PacketHandler;
|
||||
import dark.core.prefab.machine.TileEntityMachine;
|
||||
import dark.core.prefab.machine.TileEntityMachine.SimplePacketTypes;
|
||||
|
||||
public class TileEntityEncoder extends TileEntityMachine implements ISidedInventory
|
||||
{
|
||||
private ItemStack disk;
|
||||
private IInventoryWatcher watcher;
|
||||
public static final String PROGRAM_ID = "program", PROGRAM_CHANGE = "programChange", REMOVE_TASK = "removeTask";
|
||||
public static final String PROGRAM_PACKET_ID = "program", PROGRAM_CHANGE_PACKET_ID = "programChange", REMOVE_TASK_PACKET_ID = "removeTask";
|
||||
protected IProgram program;
|
||||
|
||||
public TileEntityEncoder()
|
||||
{
|
||||
super();
|
||||
this.hasGUI = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initiate()
|
||||
{
|
||||
super.initiate();
|
||||
if (!this.worldObj.isRemote)
|
||||
{
|
||||
program = new Program();
|
||||
program.setTaskAt(0, 0, new TaskRotateTo());
|
||||
program.setTaskAt(0, 1, new TaskDrop());
|
||||
|
@ -50,6 +63,7 @@ public class TileEntityEncoder extends TileEntityMachine implements ISidedInvent
|
|||
program.setTaskAt(1, 5, new TaskGive());
|
||||
program.setTaskAt(1, 6, new TaskGOTO(0, 6));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInventoryChanged()
|
||||
|
@ -120,8 +134,9 @@ public class TileEntityEncoder extends TileEntityMachine implements ISidedInvent
|
|||
{
|
||||
if (this.worldObj.isRemote)
|
||||
{
|
||||
if (id.equalsIgnoreCase(TileEntityEncoder.PROGRAM_ID))
|
||||
if (id.equalsIgnoreCase(TileEntityEncoder.PROGRAM_PACKET_ID))
|
||||
{
|
||||
|
||||
if (dis.readBoolean())
|
||||
{
|
||||
Program program = new Program();
|
||||
|
@ -137,10 +152,10 @@ public class TileEntityEncoder extends TileEntityMachine implements ISidedInvent
|
|||
}
|
||||
else
|
||||
{
|
||||
if (id.equalsIgnoreCase(TileEntityEncoder.PROGRAM_CHANGE))
|
||||
if (id.equalsIgnoreCase(TileEntityEncoder.PROGRAM_CHANGE_PACKET_ID))
|
||||
{
|
||||
|
||||
IProcessTask task = TaskRegistry.getCommand(dis.readUTF());
|
||||
ITask task = TaskRegistry.getCommand(dis.readUTF());
|
||||
task.setPosition(dis.readInt(), dis.readInt());
|
||||
task.load(PacketManager.readNBTTagCompound(dis));
|
||||
this.program.setTaskAt(task.getCol(), task.getRow(), task);
|
||||
|
@ -148,7 +163,7 @@ public class TileEntityEncoder extends TileEntityMachine implements ISidedInvent
|
|||
|
||||
return true;
|
||||
}
|
||||
else if (id.equalsIgnoreCase(TileEntityEncoder.REMOVE_TASK))
|
||||
else if (id.equalsIgnoreCase(TileEntityEncoder.REMOVE_TASK_PACKET_ID))
|
||||
{
|
||||
this.program.setTaskAt(dis.readInt(), dis.readInt(), null);
|
||||
this.sendGUIPacket();
|
||||
|
@ -170,6 +185,13 @@ public class TileEntityEncoder extends TileEntityMachine implements ISidedInvent
|
|||
public void sendGUIPacket(EntityPlayer entity)
|
||||
{
|
||||
if (entity != null)
|
||||
{
|
||||
PacketDispatcher.sendPacketToPlayer(this.getDescriptionPacket(), (Player) entity);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet getDescriptionPacket()
|
||||
{
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
boolean exists = this.program != null;
|
||||
|
@ -177,24 +199,39 @@ public class TileEntityEncoder extends TileEntityMachine implements ISidedInvent
|
|||
{
|
||||
this.program.save(tag);
|
||||
}
|
||||
PacketDispatcher.sendPacketToPlayer(PacketHandler.instance().getTilePacket(DarkMain.CHANNEL, this, this.program, exists, tag), (Player) entity);
|
||||
}
|
||||
return PacketHandler.instance().getTilePacket(DarkMain.CHANNEL, this, TileEntityEncoder.PROGRAM_PACKET_ID, exists, tag);
|
||||
|
||||
}
|
||||
|
||||
public void removeTask(Vector2 vec)
|
||||
{
|
||||
if (vec != null)
|
||||
{
|
||||
PacketDispatcher.sendPacketToServer(PacketHandler.instance().getTilePacket(DarkMain.CHANNEL, this, vec.intX(), vec.intY()));
|
||||
if (this.worldObj.isRemote)
|
||||
{
|
||||
PacketDispatcher.sendPacketToServer(PacketHandler.instance().getTilePacket(DarkMain.CHANNEL, this, TileEntityEncoder.REMOVE_TASK_PACKET_ID, vec.intX(), vec.intY()));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.program.setTaskAt(vec.intX(), vec.intY(), null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateTask(IProcessTask task)
|
||||
public void updateTask(ITask editTask)
|
||||
{
|
||||
if (task != null)
|
||||
if (editTask != null)
|
||||
{
|
||||
PacketDispatcher.sendPacketToServer(PacketHandler.instance().getTilePacket(DarkMain.CHANNEL, this, task.getCol(), task.getRow(), task.save(new NBTTagCompound())));
|
||||
if (this.worldObj.isRemote)
|
||||
{
|
||||
PacketDispatcher.sendPacketToServer(PacketHandler.instance().getTilePacket(DarkMain.CHANNEL, this, TileEntityEncoder.PROGRAM_CHANGE_PACKET_ID, editTask.getMethodName(), editTask.getCol(), editTask.getRow(), editTask.save(new NBTTagCompound())));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.program.setTaskAt(editTask.getCol(), editTask.getRow(), editTask);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -208,4 +245,10 @@ public class TileEntityEncoder extends TileEntityMachine implements ISidedInvent
|
|||
{
|
||||
return this.program;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends Container> getContainer()
|
||||
{
|
||||
return ContainerEncoder.class;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue