Added packet

This commit is contained in:
Henry Mao 2013-01-04 12:40:51 +08:00
parent 410e2c1c27
commit 6d8edae19f
2 changed files with 39 additions and 12 deletions

View file

@ -21,8 +21,11 @@ import net.minecraft.world.World;
import org.lwjgl.input.Keyboard; import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import cpw.mods.fml.common.network.PacketDispatcher;
import universalelectricity.core.vector.Vector3; import universalelectricity.core.vector.Vector3;
import universalelectricity.prefab.TranslationHelper; import universalelectricity.prefab.TranslationHelper;
import universalelectricity.prefab.network.PacketManager;
import assemblyline.common.AssemblyLine; import assemblyline.common.AssemblyLine;
import assemblyline.common.machine.encoder.ContainerEncoder; import assemblyline.common.machine.encoder.ContainerEncoder;
import assemblyline.common.machine.encoder.IInventoryWatcher; import assemblyline.common.machine.encoder.IInventoryWatcher;
@ -92,22 +95,24 @@ public class GuiEncoder extends GuiContainer implements IInventoryWatcher
{ {
case 0: // add case 0: // add
{ {
if (!commandField.getText().equals("")) if (!this.commandField.getText().equals(""))
{ {
if (tileEntity != null) if (this.tileEntity != null)
{ {
ItemStack disk = tileEntity.getStackInSlot(0); ItemStack disk = this.tileEntity.getStackInSlot(0);
if (disk != null) if (disk != null)
{ {
ArrayList<String> tempCmds = ItemDisk.getCommands(disk); ArrayList<String> tempCmds = ItemDisk.getCommands(disk);
tempCmds.add(commandField.getText()); tempCmds.add(commandField.getText());
ItemDisk.setCommands(disk, tempCmds); ItemDisk.setCommands(disk, tempCmds);
tileEntity.setInventorySlotContents(0, disk); this.tileEntity.setInventorySlotContents(0, disk);
// TODO: Make the client send the server the new command to be added // TODO: Change command ID to corresponding ones.
int commandID = 0;
PacketDispatcher.sendPacketToServer(PacketManager.getPacket(AssemblyLine.CHANNEL, this.tileEntity, (int) commandID));
} }
} }
commandField.setText(""); this.commandField.setText("");
} }
break; break;
} }

View file

@ -1,15 +1,19 @@
package assemblyline.common.machine.encoder; package assemblyline.common.machine.encoder;
import com.google.common.io.ByteArrayDataInput;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.common.ISidedInventory; import net.minecraftforge.common.ISidedInventory;
import universalelectricity.prefab.network.IPacketReceiver;
import universalelectricity.prefab.tile.TileEntityAdvanced; import universalelectricity.prefab.tile.TileEntityAdvanced;
public class TileEntityEncoder extends TileEntityAdvanced implements ISidedInventory public class TileEntityEncoder extends TileEntityAdvanced implements IPacketReceiver, ISidedInventory
{ {
private ItemStack disk; private ItemStack disk;
private IInventoryWatcher watcher; private IInventoryWatcher watcher;
@ -127,9 +131,12 @@ public class TileEntityEncoder extends TileEntityAdvanced implements ISidedInven
{ {
super.writeToNBT(nbt); super.writeToNBT(nbt);
NBTTagCompound diskNBT = new NBTTagCompound(); if (this.disk != null)
disk.writeToNBT(diskNBT); {
nbt.setCompoundTag("disk", diskNBT); NBTTagCompound diskNBT = new NBTTagCompound();
this.disk.writeToNBT(diskNBT);
nbt.setCompoundTag("disk", diskNBT);
}
} }
@Override @Override
@ -138,9 +145,24 @@ public class TileEntityEncoder extends TileEntityAdvanced implements ISidedInven
super.readFromNBT(nbt); super.readFromNBT(nbt);
NBTTagCompound diskNBT = nbt.getCompoundTag("disk"); NBTTagCompound diskNBT = nbt.getCompoundTag("disk");
if (diskNBT != null) if (diskNBT != null)
{ {
disk = ItemStack.loadItemStackFromNBT(diskNBT); this.disk = ItemStack.loadItemStackFromNBT(diskNBT);
}
}
@Override
public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream)
{
try
{
// TODO: Get this to work and add commands to the stack
int newAddCommandID = dataStream.readInt();
}
catch (Exception e)
{
e.printStackTrace();
} }
} }