I'm trying to figure out if there's a way to convert an IBlockState into some form that can be passed through a Packet to the server. I'd like to be able to update a certain position on a map with a specific block (in a specific orientation) whenever this is called. The position was easy enough, but I can't seem to find any way to get the block with all its orientation data converted into something that can be passed...
public class SetBlock implements IMessage, IMessageHandler<SetBlock, IMessage>
{
private int x;
private int y;
private int z;
private IBlockState blockState;
public SetBlock() {}
public SetBlock(int x, int y, int z, IBlockState blockState)
{
this.x = x;
this.y = y;
this.z = z;
this.blockState = blockState;
}
@Override
public void toBytes(ByteBuf buf)
{
buf.writeInt(x);
buf.writeInt(y);
buf.writeInt(z);
//blockState stuff
}
@Override
public void fromBytes(ByteBuf buf)
{
this.x = buf.readInt();
this.y = buf.readInt();
this.z = buf.readInt();
//blockState stuff
}
@Override
public IMessage onMessage(final SetBlock message, final MessageContext ctx)
{
World world = ctx.getServerHandler().playerEntity.worldObj;
world.setBlockState(new BlockPos(message.x,message.y,message.z),Blocks.dirt.getDefaultState());
return null;
}
}
The Dirt Block created was just a way for me to tell if the position was being passed correctly, and it is.
Any help would be fantastic...this is that last thing I need to figure out.
Thanks
P.S. Yes, I know this probably isn't an ideal way to do this, but this mod is just for my personal use so there's no worrying about others potentially abusing the placement system.