In my GUI actionPerformed method:
MusicboxCore.network.sendToServer(new MusicBoxMessage(this.tileEntity.xCoord,this.tileEntity.yCoord,this.tileEntity.zCoord, this.nameField.getText(), this.tileEntity.unsavedSong[0], this.tileEntity.unsavedSong[1], this.tileEntity.unsavedSong[2], this.tileEntity.unsavedSong[3]));
Here is the packet to be sent:
package neuro.musicbox.main;
import io.netty.buffer.ByteBuf;
import net.minecraft.nbt.NBTTagCompound;
import neuro.musicbox.gui.TileEntityMusicDesk;
import cpw.mods.fml.common.network.ByteBufUtils;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
public class MusicBoxMessage implements IMessage {
int x, y, z;
public String song1,song2,song3,song4;
public String name;
public MusicBoxMessage(int i, int j, int k, String name, String... song)
{
x = i;
y = j;
z = k;
song1 = song[0];
song2 = song[1];
song3 = song[2];
song4 = song[3];
this.name = name;
}
@Override
public void fromBytes(ByteBuf buf)
{
//Reads the data in the same order it was written. x, y, z, song1-4, then name
x = buf.readInt();
y = buf.readInt();
z = buf.readInt();
song1 = ByteBufUtils.readUTF8String(buf);
song2 = ByteBufUtils.readUTF8String(buf);
song3 = ByteBufUtils.readUTF8String(buf);
song4 = ByteBufUtils.readUTF8String(buf);
name = ByteBufUtils.readUTF8String(buf);
}
@Override
public void toBytes(ByteBuf buf) {
buf.writeInt(x);
buf.writeInt(y);
buf.writeInt(z);
ByteBufUtils.writeUTF8String(buf, song1);
ByteBufUtils.writeUTF8String(buf, song2);
ByteBufUtils.writeUTF8String(buf, song3);
ByteBufUtils.writeUTF8String(buf, song4);
ByteBufUtils.writeUTF8String(buf, name);
}
public static class Handler implements IMessageHandler<MusicBoxMessage, IMessage> {
@Override
public IMessage onMessage(MusicBoxMessage message, MessageContext ctx) {
//Get the tileentity at the correct coordinates server-side:
TileEntityMusicDesk te = ((TileEntityMusicDesk)ctx.getServerHandler().playerEntity.worldObj.getTileEntity(message.x, message.y, message.z));
//Call the method server-side:
te.createSongReel(ctx.getServerHandler().playerEntity, new String[] {message.song1,message.song2,message.song3,message.song4,message.song2,message.song3,message.song4}, message.name);
}
}
}