mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-18 19:39:14 +00:00
60 lines
1.6 KiB
Java
60 lines
1.6 KiB
Java
package crazypants.enderio.machine;
|
|
|
|
import io.netty.buffer.ByteBuf;
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
import net.minecraft.tileentity.TileEntity;
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
|
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 PacketIoMode implements IMessage, IMessageHandler<PacketIoMode, IMessage> {
|
|
|
|
private int x;
|
|
private int y;
|
|
private int z;
|
|
private IoMode mode;
|
|
private ForgeDirection face;
|
|
|
|
public PacketIoMode() {
|
|
}
|
|
|
|
public PacketIoMode(IIoConfigurable cont, ForgeDirection face) {
|
|
this.x = cont.getLocation().x;
|
|
this.y = cont.getLocation().y;
|
|
this.z = cont.getLocation().z;
|
|
this.face = face;
|
|
mode = cont.getIoMode(face);
|
|
}
|
|
|
|
@Override
|
|
public void toBytes(ByteBuf buf) {
|
|
buf.writeInt(x);
|
|
buf.writeInt(y);
|
|
buf.writeInt(z);
|
|
buf.writeShort((short) mode.ordinal());
|
|
buf.writeShort((short) face.ordinal());
|
|
|
|
}
|
|
|
|
@Override
|
|
public void fromBytes(ByteBuf buf) {
|
|
x = buf.readInt();
|
|
y = buf.readInt();
|
|
z = buf.readInt();
|
|
mode = IoMode.values()[buf.readShort()];
|
|
face = ForgeDirection.values()[buf.readShort()];
|
|
}
|
|
|
|
@Override
|
|
public IMessage onMessage(PacketIoMode message, MessageContext ctx) {
|
|
EntityPlayer player = ctx.getServerHandler().playerEntity;
|
|
TileEntity te = player.worldObj.getTileEntity(message.x, message.y, message.z);
|
|
if(te instanceof IIoConfigurable) {
|
|
IIoConfigurable me = (IIoConfigurable) te;
|
|
me.setIoMode(message.face, message.mode);
|
|
}
|
|
return null;
|
|
}
|
|
}
|