2014-04-30 03:46:59 +02:00
|
|
|
package com.pahimar.ee3.network.message;
|
|
|
|
|
|
|
|
import com.pahimar.ee3.tileentity.TileEntityGlassBell;
|
|
|
|
import cpw.mods.fml.client.FMLClientHandler;
|
2014-10-09 21:10:36 +02:00
|
|
|
import cpw.mods.fml.common.network.ByteBufUtils;
|
2014-04-30 03:46:59 +02:00
|
|
|
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
|
|
|
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
|
|
|
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
|
2015-02-05 05:48:07 +01:00
|
|
|
import java.util.UUID;
|
|
|
|
|
2014-04-30 03:46:59 +02:00
|
|
|
public class MessageTileEntityGlassBell implements IMessage, IMessageHandler<MessageTileEntityGlassBell, IMessage>
|
|
|
|
{
|
|
|
|
public int x, y, z;
|
|
|
|
public byte orientation;
|
|
|
|
public byte state;
|
2015-02-05 05:48:07 +01:00
|
|
|
public String customName;
|
|
|
|
public UUID ownerUUID;
|
2014-10-09 21:10:36 +02:00
|
|
|
public ItemStack outputItemStack;
|
2014-04-30 03:46:59 +02:00
|
|
|
|
|
|
|
public MessageTileEntityGlassBell()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public MessageTileEntityGlassBell(TileEntityGlassBell tileEntityGlassBell, ItemStack outputItemStack)
|
|
|
|
{
|
|
|
|
this.x = tileEntityGlassBell.xCoord;
|
|
|
|
this.y = tileEntityGlassBell.yCoord;
|
|
|
|
this.z = tileEntityGlassBell.zCoord;
|
|
|
|
this.orientation = (byte) tileEntityGlassBell.getOrientation().ordinal();
|
|
|
|
this.state = (byte) tileEntityGlassBell.getState();
|
|
|
|
this.customName = tileEntityGlassBell.getCustomName();
|
2015-02-05 05:48:07 +01:00
|
|
|
this.ownerUUID = tileEntityGlassBell.getOwnerUUID();
|
2014-10-09 21:10:36 +02:00
|
|
|
this.outputItemStack = outputItemStack;
|
2014-04-30 03:46:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void fromBytes(ByteBuf buf)
|
|
|
|
{
|
|
|
|
this.x = buf.readInt();
|
|
|
|
this.y = buf.readInt();
|
|
|
|
this.z = buf.readInt();
|
|
|
|
this.orientation = buf.readByte();
|
|
|
|
this.state = buf.readByte();
|
|
|
|
int customNameLength = buf.readInt();
|
|
|
|
this.customName = new String(buf.readBytes(customNameLength).array());
|
2015-02-05 22:52:29 +01:00
|
|
|
if (buf.readBoolean())
|
|
|
|
{
|
|
|
|
this.ownerUUID = new UUID(buf.readLong(), buf.readLong());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.ownerUUID = null;
|
|
|
|
}
|
2014-10-09 21:10:36 +02:00
|
|
|
outputItemStack = ByteBufUtils.readItemStack(buf);
|
2014-04-30 03:46:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void toBytes(ByteBuf buf)
|
|
|
|
{
|
|
|
|
buf.writeInt(x);
|
|
|
|
buf.writeInt(y);
|
|
|
|
buf.writeInt(z);
|
|
|
|
buf.writeByte(orientation);
|
|
|
|
buf.writeByte(state);
|
|
|
|
buf.writeInt(customName.length());
|
|
|
|
buf.writeBytes(customName.getBytes());
|
2015-02-05 22:52:29 +01:00
|
|
|
if (ownerUUID != null)
|
|
|
|
{
|
|
|
|
buf.writeBoolean(true);
|
|
|
|
buf.writeLong(ownerUUID.getMostSignificantBits());
|
|
|
|
buf.writeLong(ownerUUID.getLeastSignificantBits());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
buf.writeBoolean(false);
|
|
|
|
}
|
2014-10-09 21:10:36 +02:00
|
|
|
ByteBufUtils.writeItemStack(buf, outputItemStack);
|
2014-04-30 03:46:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IMessage onMessage(MessageTileEntityGlassBell message, MessageContext ctx)
|
|
|
|
{
|
|
|
|
TileEntity tileEntity = FMLClientHandler.instance().getClient().theWorld.getTileEntity(message.x, message.y, message.z);
|
|
|
|
|
|
|
|
if (tileEntity instanceof TileEntityGlassBell)
|
|
|
|
{
|
|
|
|
((TileEntityGlassBell) tileEntity).setOrientation(message.orientation);
|
|
|
|
((TileEntityGlassBell) tileEntity).setState(message.state);
|
|
|
|
((TileEntityGlassBell) tileEntity).setCustomName(message.customName);
|
2015-02-05 05:48:07 +01:00
|
|
|
((TileEntityGlassBell) tileEntity).setOwnerUUID(message.ownerUUID);
|
2014-10-09 21:10:36 +02:00
|
|
|
((TileEntityGlassBell) tileEntity).outputItemStack = message.outputItemStack;
|
2014-04-30 03:46:59 +02:00
|
|
|
|
|
|
|
//NAME UPDATE
|
|
|
|
FMLClientHandler.instance().getClient().theWorld.func_147451_t(message.x, message.y, message.z);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString()
|
|
|
|
{
|
2015-02-05 05:48:07 +01:00
|
|
|
return String.format("MessageTileEntityGlassBell - x:%s, y:%s, z:%s, orientation:%s, state:%s, customName:%s, ownerUUID:%s, outputItemStack: %s", x, y, z, orientation, state, customName, ownerUUID, outputItemStack.toString());
|
2014-04-30 03:46:59 +02:00
|
|
|
}
|
|
|
|
}
|