Posted March 9, 20169 yr 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.
March 9, 20169 yr Minecraft does this using Block.BLOCK_STATE_IDS , which is the same map returned by GameData.getBlockStateIDMap . I would recommend against implementing IMessage and IMessageHandler in the same class, since it's easy to get confused and use values from this instead of the message argument in IMessageHandler#onMessage . Either move the handler to a separate class or a static inner class. It's not safe to interact with normal Minecraft classes directly in your IMessageHandler , since it's called from a separate thread to the main client/server thread. You need to schedule a task on the main thread using IThreadListener#addScheduledTask , this page explains how to do this. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
March 10, 20169 yr Author Thanks! I was able to get it to work finally. Now just to clean it up like you suggested and I should be good to go.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.