mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-17 19:15:09 +00:00
68 lines
1.7 KiB
Java
68 lines
1.7 KiB
Java
package crazypants.enderio.machine;
|
|
|
|
import io.netty.buffer.ByteBuf;
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
import net.minecraft.tileentity.TileEntity;
|
|
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 PacketRedstoneMode implements IMessage, IMessageHandler<PacketRedstoneMode, IMessage> {
|
|
|
|
private int x;
|
|
private int y;
|
|
private int z;
|
|
private RedstoneControlMode mode;
|
|
|
|
public PacketRedstoneMode() {
|
|
}
|
|
|
|
public PacketRedstoneMode(IRedstoneModeControlable cont, int x, int y, int z) {
|
|
this.x = x;
|
|
this.y = y;
|
|
this.z = z;
|
|
mode = cont.getRedstoneControlMode();
|
|
}
|
|
|
|
public PacketRedstoneMode(AbstractMachineEntity ent) {
|
|
x = ent.xCoord;
|
|
y = ent.yCoord;
|
|
z = ent.zCoord;
|
|
mode = ent.getRedstoneControlMode();
|
|
}
|
|
|
|
@Override
|
|
public void toBytes(ByteBuf buf) {
|
|
buf.writeInt(x);
|
|
buf.writeInt(y);
|
|
buf.writeInt(z);
|
|
buf.writeShort((short) mode.ordinal());
|
|
}
|
|
|
|
@Override
|
|
public void fromBytes(ByteBuf buf) {
|
|
x = buf.readInt();
|
|
y = buf.readInt();
|
|
z = buf.readInt();
|
|
short ordinal = buf.readShort();
|
|
mode = RedstoneControlMode.values()[ordinal];
|
|
}
|
|
|
|
@Override
|
|
public IMessage onMessage(PacketRedstoneMode message, MessageContext ctx)
|
|
{
|
|
handle(ctx.getServerHandler().playerEntity);
|
|
return null;
|
|
}
|
|
|
|
private void handle(EntityPlayer player) {
|
|
TileEntity te = player.worldObj.getTileEntity(x, y, z);
|
|
if(te instanceof IRedstoneModeControlable) {
|
|
IRedstoneModeControlable me = (IRedstoneModeControlable) te;
|
|
me.setRedstoneControlMode(mode);
|
|
player.worldObj.markBlockForUpdate(x, y, z);
|
|
}
|
|
}
|
|
|
|
}
|