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:
DarkGuardsman 2013-11-30 05:47:27 -05:00
parent a3009a72a7
commit fad9b46b4d
12 changed files with 258 additions and 131 deletions

View file

@ -6,19 +6,19 @@ import java.util.List;
import java.util.Map.Entry;
/** Used to both register task and fake machines for the encoder to use to create new programs.
*
*
* @author DarkGuardsman */
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))
{
@ -72,7 +72,7 @@ public class TaskRegistry
}
/** Do not edit the return or you will change the behavior of all machine that use this list
*
*
* @return The list of registered sudo machines for the encoder to check against */
public static HashMap<String, IArmbot> getSudoMachines()
{

View file

@ -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
@ -112,7 +141,7 @@ public class AssemblyLine extends ModPrefab
FMLog.info("Loaded: " + TranslationHelper.loadLanguages(LANGUAGE_PATH, LANGUAGES_SUPPORTED) + " languages.");
DMCreativeTab.tabAutomation.setIconItemStack(new ItemStack(ALRecipeLoader.blockConveyorBelt));
}
@Override
@EventHandler
public void postInit(FMLPostInitializationEvent event)

View file

@ -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,30 +275,36 @@ public class Program implements IProgram
for (int s = 0; s < taskList.tagCount(); ++s)
{
NBTTagCompound tag = (NBTTagCompound) taskList.tagAt(s);
ITask task = TaskRegistry.getCommand(tag.getString("methodName"));
if (task != null)
if (tag.hasKey("methodName"))
{
task = task.clone();
ITask task = TaskRegistry.getCommand(tag.getString("methodName"));
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"))
task = task.clone();
if (task != null)
{
this.currentTask = task;
task.loadProgress(tag);
this.currentPos = new Vector2(task.getCol(), task.getRow());
}
if (task.getCol() > this.width)
{
this.width = task.getCol();
}
if (task.getRow() > this.hight)
{
this.hight = task.getRow();
task.load(tag);
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();
}
if (task.getRow() > this.hight)
{
this.hight = task.getRow();
}
}
}
else
{
System.out.println("[CoreMachine]Error: failed to load task " + tag.getString("methodName"));
}
}
}
taskList = nbt.getTagList("vars");

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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,20 +43,23 @@ public class GuiEncoderCoder extends GuiEncoderBase
protected void actionPerformed(GuiButton button)
{
super.actionPerformed(button);
switch (button.id)
if (((TileEntityEncoder) tileEntity).getProgram() != null)
{
case 3:
getTaskListElement().scrollSide(-1);
break;
case 4:
getTaskListElement().scrollSide(1);
break;
case 5:
getTaskListElement().scroll(-1);
break;
case 6:
getTaskListElement().scroll(1);
break;
switch (button.id)
{
case 3:
getTaskListElement().scrollSide(-1);
break;
case 4:
getTaskListElement().scrollSide(1);
break;
case 5:
getTaskListElement().scroll(-1);
break;
case 6:
getTaskListElement().scroll(1);
break;
}
}
}
@ -81,13 +85,16 @@ public class GuiEncoderCoder extends GuiEncoderBase
{
super.handleMouseInput();
int wheel = Mouse.getEventDWheel();
if (wheel > 0)
if (((TileEntityEncoder) tileEntity).getProgram() != null)
{
this.getTaskListElement().scroll(-2);
}
else if (wheel < 0)
{
this.getTaskListElement().scroll(2);
if (wheel > 0)
{
this.getTaskListElement().scroll(-2);
}
else if (wheel < 0)
{
this.getTaskListElement().scroll(2);
}
}
}
@ -98,23 +105,27 @@ 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)
{
this.getTaskListElement().scroll(-1);
}
else if (keycode == Keyboard.KEY_DOWN) // PAGE DOWN (no constant)
{
this.getTaskListElement().scroll(1);
}
else if (keycode == Keyboard.KEY_LEFT) // PAGE LEFT (no constant)
{
if (this.getTaskListElement().scrollX > -5)
this.getTaskListElement().scrollSide(-1);
}
else if (keycode == Keyboard.KEY_RIGHT) // PAGE RIGHT (no constant)
{
if (this.getTaskListElement().scrollX < ((TileEntityEncoder) tileEntity).getProgram().getSize().intX())
this.getTaskListElement().scrollSide(1);
if (keycode == Keyboard.KEY_UP) // PAGE UP (no constant)
{
this.getTaskListElement().scroll(-1);
}
else if (keycode == Keyboard.KEY_DOWN) // PAGE DOWN (no constant)
{
this.getTaskListElement().scroll(1);
}
else if (keycode == Keyboard.KEY_LEFT) // PAGE LEFT (no constant)
{
if (this.getTaskListElement().scrollX > -5)
this.getTaskListElement().scrollSide(-1);
}
else if (keycode == Keyboard.KEY_RIGHT) // PAGE RIGHT (no constant)
{
if (this.getTaskListElement().scrollX < ((TileEntityEncoder) tileEntity).getProgram().getSize().intX())
this.getTaskListElement().scrollSide(1);
}
}
}
@ -147,4 +158,10 @@ public class GuiEncoderCoder extends GuiEncoderBase
}
}
@Override
public TileEntityEncoder getTile()
{
return (TileEntityEncoder) this.tileEntity;
}
}

View file

@ -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,27 +99,30 @@ 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();
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
{
FMLClientHandler.instance().getClient().renderEngine.bindTexture(ITask.TaskType.TEXTURE);
this.drawTexturedModalRect(xPos + (20 * colume), yPos + (20 * row), 0, 40, 20, 20);
}
}
if (!drawnButton)
{
FMLClientHandler.instance().getClient().renderEngine.bindTexture(ITask.TaskType.TEXTURE);
this.drawTexturedModalRect(xPos + (20 * colume), yPos + (20 * row), 0, 40, 20, 20);
}
}

View file

@ -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,29 +29,40 @@ 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();
program = new Program();
program.setTaskAt(0, 0, new TaskRotateTo());
program.setTaskAt(0, 1, new TaskDrop());
program.setTaskAt(0, 2, new TaskRotateTo());
program.setTaskAt(0, 3, new TaskGrabItem());
program.setTaskAt(0, 4, new TaskIF());
program.setTaskAt(0, 5, new TaskRotateTo());
program.setTaskAt(0, 6, new TaskGive());
this.hasGUI = true;
}
program.setTaskAt(1, 4, new TaskRotateTo());
program.setTaskAt(1, 5, new TaskGive());
program.setTaskAt(1, 6, new TaskGOTO(0, 6));
@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());
program.setTaskAt(0, 2, new TaskRotateTo());
program.setTaskAt(0, 3, new TaskGrabItem());
program.setTaskAt(0, 4, new TaskIF());
program.setTaskAt(0, 5, new TaskRotateTo());
program.setTaskAt(0, 6, new TaskGive());
program.setTaskAt(1, 4, new TaskRotateTo());
program.setTaskAt(1, 5, new TaskGive());
program.setTaskAt(1, 6, new TaskGOTO(0, 6));
}
}
@Override
@ -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();
@ -171,30 +186,52 @@ public class TileEntityEncoder extends TileEntityMachine implements ISidedInvent
{
if (entity != null)
{
NBTTagCompound tag = new NBTTagCompound();
boolean exists = this.program != null;
if (exists)
{
this.program.save(tag);
}
PacketDispatcher.sendPacketToPlayer(PacketHandler.instance().getTilePacket(DarkMain.CHANNEL, this, this.program, exists, tag), (Player) entity);
PacketDispatcher.sendPacketToPlayer(this.getDescriptionPacket(), (Player) entity);
}
}
@Override
public Packet getDescriptionPacket()
{
NBTTagCompound tag = new NBTTagCompound();
boolean exists = this.program != null;
if (exists)
{
this.program.save(tag);
}
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;
}
}