equivalent-exchange-3/src/main/java/com/pahimar/ee3/network/message/MessageTileCalcinator.java

117 lines
4.3 KiB
Java
Raw Normal View History

2014-04-29 03:24:31 +02:00
package com.pahimar.ee3.network.message;
2014-04-30 03:46:59 +02:00
import com.pahimar.ee3.tileentity.TileEntityCalcinator;
import com.pahimar.ee3.tileentity.TileEntityEE;
import cpw.mods.fml.client.FMLClientHandler;
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.tileentity.TileEntity;
import java.util.UUID;
2014-04-30 03:46:59 +02:00
public class MessageTileCalcinator implements IMessage, IMessageHandler<MessageTileCalcinator, IMessage>
2014-04-29 03:24:31 +02:00
{
2014-04-30 03:46:59 +02:00
public int x, y, z;
public byte orientation, state;
public String customName;
public UUID ownerUUID;
2014-04-30 03:46:59 +02:00
public byte leftStackSize, leftStackMeta, rightStackSize, rightStackMeta;
public MessageTileCalcinator()
{
}
public MessageTileCalcinator(TileEntityCalcinator tileEntityCalcinator)
{
this.x = tileEntityCalcinator.xCoord;
this.y = tileEntityCalcinator.yCoord;
this.z = tileEntityCalcinator.zCoord;
this.orientation = (byte) tileEntityCalcinator.getOrientation().ordinal();
this.state = (byte) tileEntityCalcinator.getState();
this.customName = tileEntityCalcinator.getCustomName();
this.ownerUUID = tileEntityCalcinator.getOwnerUUID();
2014-04-30 03:46:59 +02:00
this.leftStackSize = tileEntityCalcinator.leftStackSize;
this.leftStackMeta = tileEntityCalcinator.leftStackMeta;
this.rightStackSize = tileEntityCalcinator.rightStackSize;
this.rightStackMeta = tileEntityCalcinator.rightStackMeta;
}
@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-04-30 03:46:59 +02:00
this.leftStackSize = buf.readByte();
this.leftStackMeta = buf.readByte();
this.rightStackSize = buf.readByte();
this.rightStackMeta = buf.readByte();
}
@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-04-30 03:46:59 +02:00
buf.writeByte(leftStackSize);
buf.writeByte(leftStackMeta);
buf.writeByte(rightStackSize);
buf.writeByte(rightStackMeta);
}
@Override
public IMessage onMessage(MessageTileCalcinator message, MessageContext ctx)
{
TileEntity tileEntity = FMLClientHandler.instance().getClient().theWorld.getTileEntity(message.x, message.y, message.z);
if (tileEntity instanceof TileEntityCalcinator)
{
((TileEntityEE) tileEntity).setOrientation(message.orientation);
((TileEntityEE) tileEntity).setState(message.state);
((TileEntityEE) tileEntity).setCustomName(message.customName);
((TileEntityEE) tileEntity).setOwnerUUID(message.ownerUUID);
2014-04-30 03:46:59 +02:00
((TileEntityCalcinator) tileEntity).leftStackSize = message.leftStackSize;
((TileEntityCalcinator) tileEntity).leftStackMeta = message.leftStackMeta;
((TileEntityCalcinator) tileEntity).rightStackSize = message.rightStackSize;
((TileEntityCalcinator) tileEntity).rightStackMeta = message.rightStackMeta;
}
return null;
}
@Override
public String toString()
{
return String.format("MessageTileEntityCalcinator - x:%s, y:%s, z:%s, orientation:%s, state:%s, customName:%s, ownerUUID:%s, leftStackSize: %s, leftStackMeta: %s, rightStackSize: %s, rightStackMeta: %s", x, y, z, orientation, state, customName, ownerUUID, leftStackSize, leftStackMeta, rightStackSize, rightStackMeta);
2014-04-30 03:46:59 +02:00
}
2014-04-29 03:24:31 +02:00
}