Fixed oversized Gui and made packets work

This commit is contained in:
Henry Mao 2013-01-05 00:05:19 +08:00
parent f2e0290c14
commit f9ed7dbf60
7 changed files with 61 additions and 33 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 49 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

View file

@ -27,6 +27,7 @@ import universalelectricity.core.vector.Vector3;
import universalelectricity.prefab.TranslationHelper;
import universalelectricity.prefab.network.PacketManager;
import assemblyline.common.AssemblyLine;
import assemblyline.common.machine.armbot.Command;
import assemblyline.common.machine.encoder.ContainerEncoder;
import assemblyline.common.machine.encoder.IInventoryWatcher;
import assemblyline.common.machine.encoder.ItemDisk;
@ -62,22 +63,22 @@ public class GuiEncoder extends GuiContainer implements IInventoryWatcher
this.allowUserInput = true;
containerWidth = (this.width - this.xSize) / 2;
containerHeight = (this.height - this.ySize) / 2;
this.containerWidth = (this.width - this.xSize) / 2;
this.containerHeight = (this.height - this.ySize) / 2;
addButton = new GuiButton(0, containerWidth + (xSize - 25), containerHeight + 148, 18, 20, "+");
delButton = new GuiButton(1, containerWidth + (xSize - 43), containerHeight + 148, 18, 20, "-");
pUpButton = new GuiButton(2, containerWidth + (xSize - 25), containerHeight + 48, 18, 20, "");
pDnButton = new GuiButton(3, containerWidth + (xSize - 25), containerHeight + 128, 18, 20, "");
commandField = new GuiTextField(fontRenderer, 8, 149, xSize - 52, 18);
this.addButton = new GuiButton(0, containerWidth + (xSize - 25), containerHeight + 128, 18, 20, "+");
this.delButton = new GuiButton(1, containerWidth + (xSize - 43), containerHeight + 128, 18, 20, "-");
this.pUpButton = new GuiButton(2, containerWidth + (xSize - 25), containerHeight + 48, 18, 20, "");
this.pDnButton = new GuiButton(3, containerWidth + (xSize - 25), containerHeight + 108, 18, 20, "");
this.commandField = new GuiTextField(fontRenderer, 8, 129, xSize - 52, 18);
// commandList = new GuiCommandList(mc, xSize - 7, 128, 7, 120, 170, 20);
controlList.add(addButton);
controlList.add(delButton);
controlList.add(pUpButton);
controlList.add(pDnButton);
this.controlList.add(addButton);
this.controlList.add(delButton);
this.controlList.add(pUpButton);
this.controlList.add(pDnButton);
minCommand = 0;
this.minCommand = 0;
}
@Override
@ -92,15 +93,14 @@ public class GuiEncoder extends GuiContainer implements IInventoryWatcher
if (this.tileEntity != null)
{
ItemStack disk = this.tileEntity.getStackInSlot(0);
if (disk != null)
if (disk != null && Command.getCommand(this.commandField.getText()) != null)
{
ArrayList<String> tempCmds = ItemDisk.getCommands(disk);
tempCmds.add(commandField.getText());
ItemDisk.setCommands(disk, tempCmds);
this.tileEntity.setInventorySlotContents(0, disk);
// TODO: Change command ID to corresponding ones.
int commandID = 0;
PacketDispatcher.sendPacketToServer(PacketManager.getPacket(AssemblyLine.CHANNEL, this.tileEntity, (int) commandID));
PacketDispatcher.sendPacketToServer(PacketManager.getPacket(AssemblyLine.CHANNEL, this.tileEntity, (String) this.commandField.getText()));
}
}
@ -193,7 +193,7 @@ public class GuiEncoder extends GuiContainer implements IInventoryWatcher
this.mc.renderEngine.bindTexture(var4);
this.drawTexturedModalRect(containerWidth, containerHeight, 0, 0, this.xSize, this.ySize);
drawOutlineRect(containerWidth + 7, containerHeight + 48, containerWidth + (xSize - 25), containerHeight + 48 + 100, 0, 0, 0, 0.5f, 0.5f, 0.5f);
drawOutlineRect(containerWidth + 7, containerHeight + 48, containerWidth + (xSize - 25), containerHeight + 48 + 80, 0, 0, 0, 0.5f, 0.5f, 0.5f);
}
public static void drawOutlineRect(int x1, int y1, int x2, int y2, float rR, float rG, float rB, float lR, float lG, float lB)

View file

@ -35,7 +35,7 @@ import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
@Mod(modid = AssemblyLine.CHANNEL, name = AssemblyLine.NAME, version = AssemblyLine.VERSION, dependencies = "required-after:BasicComponents")
@Mod(modid = AssemblyLine.CHANNEL, name = AssemblyLine.NAME, version = AssemblyLine.VERSION, dependencies = "after:BasicComponents")
@NetworkMod(channels = { AssemblyLine.CHANNEL }, clientSideRequired = true, serverSideRequired = false, packetHandler = PacketManager.class)
public class AssemblyLine
{
@ -84,8 +84,6 @@ public class AssemblyLine
CONFIGURATION.load();
blockConveyorBelt = new BlockConveyorBelt(CONFIGURATION.getBlock("Conveyor Belt", BLOCK_ID_PREFIX).getInt());
blockManipulator = new BlockManipulator(CONFIGURATION.getBlock("Manipulator", BLOCK_ID_PREFIX + 1).getInt());
// blockEncoder = new BlockEncoder2(CONFIGURATION.getBlock("Encoder", BLOCK_ID_PREFIX +
// 2).getInt());
blockCrate = new BlockCrate(CONFIGURATION.getBlock("Crate", BLOCK_ID_PREFIX + 3).getInt(), 0);
blockImprinter = new BlockImprinter(CONFIGURATION.getBlock("Imprinter", BLOCK_ID_PREFIX + 4).getInt(), 0);
blockDetector = new BlockDetector(CONFIGURATION.getBlock("Detector", BLOCK_ID_PREFIX + 5).getInt(), 1);

View file

@ -1,5 +1,7 @@
package assemblyline.common.machine.armbot;
import java.util.HashMap;
import assemblyline.common.machine.crafter.TileEntityArmbot;
/**
@ -11,9 +13,26 @@ import assemblyline.common.machine.crafter.TileEntityArmbot;
public abstract class Command
{
/**
* A class of all available commands. Command IDs are the indexes of the array.
* A class of all available commands.
*
* String - Command name. Command - The actual command class.
*/
public static Class[] COMMANDS = { CommandIdle.class };
private static final HashMap<String, Class> COMMANDS = new HashMap<String, Class>();
static
{
registerCommand("idle", CommandIdle.class);
}
public static void registerCommand(String command, Class<? extends Command> commandClass)
{
COMMANDS.put(command, commandClass);
}
public static Class<? extends Command> getCommand(String command)
{
return COMMANDS.get(command);
}
protected int ticks;
protected TileEntityArmbot tileEntity;

View file

@ -22,23 +22,21 @@ public class ContainerEncoder extends Container
this.encoder = encoder;
// Disk
this.addSlotToContainer(new Slot(encoder, 0, 80, 24));
// Output Disk
// this.addSlotToContainer(new SlotDiskResult(this, 2, 136, 24));
this.addSlotToContainer(new Slot(encoder, 0, 80, 17));
int var3;
for (var3 = 0; var3 < 3; ++var3)
{
for (int var4 = 0; var4 < 9; ++var4)
{
this.addSlotToContainer(new Slot(inventoryPlayer, var4 + var3 * 9 + 9, 8 + var4 * 18, 170 + var3 * 18));
this.addSlotToContainer(new Slot(inventoryPlayer, var4 + var3 * 9 + 9, 8 + var4 * 18, 155 + var3 * 18));
}
}
for (var3 = 0; var3 < 9; ++var3)
{
this.addSlotToContainer(new Slot(inventoryPlayer, var3, 8 + var3 * 18, 228));
this.addSlotToContainer(new Slot(inventoryPlayer, var3, 8 + var3 * 18, 213));
}
}

View file

@ -36,7 +36,12 @@ public class ItemDisk extends Item
if (commands.size() > 0)
{
list.add(commands.size() + " commands");
list.add(commands.size() + " command(s)");
for (String command : commands)
{
list.add(command);
}
}
else
{

View file

@ -1,6 +1,6 @@
package assemblyline.common.machine.encoder;
import com.google.common.io.ByteArrayDataInput;
import java.util.ArrayList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
@ -11,6 +11,9 @@ import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.common.ISidedInventory;
import universalelectricity.prefab.network.IPacketReceiver;
import universalelectricity.prefab.tile.TileEntityAdvanced;
import assemblyline.common.machine.armbot.Command;
import com.google.common.io.ByteArrayDataInput;
public class TileEntityEncoder extends TileEntityAdvanced implements IPacketReceiver, ISidedInventory
{
@ -160,9 +163,14 @@ public class TileEntityEncoder extends TileEntityAdvanced implements IPacketRece
/**
* Only the server receives this from the client's button click action.
*/
int newAddCommandID = dataStream.readInt();
String newCommand = dataStream.readUTF();
if (Command.getCommand(newCommand) != null && this.disk != null)
{
ArrayList<String> tempCmds = ItemDisk.getCommands(this.disk);
tempCmds.add(newCommand);
ItemDisk.setCommands(this.disk, tempCmds);
}
}
catch (Exception e)
{