Posted February 16, 201510 yr hello, I can not figure out how this code (server side) always return "false": PacketBlockState; player.worldObj.setBlock(xHit, yHit, zHit, Blocks.torch, 5, 2); with the result that it doesnt creates the block ... without show up no errors!!!! Client side code: PacketDispatcher.sendToServer(new PacketBlockState(2, xHit, yHit, zHit)); event.entityPlayer.worldObj.setBlock(xHit, yHit, zHit, Blocks.torch, 5, 2)); The torch seems placed but when exit and reload the world, it's disappeared. Please help...
February 16, 201510 yr Author Show your whole packet and the whole method where you send it. PacketBlockState: public class PacketBlockState implements IMessage, IMessageHandler<PacketBlockState, IMessage> { int state = 0; int xHit = 0; int yHit = 0; int zHit = 0; public PacketBlockState() { } public PacketBlockState(int state, int xHit, int yHit, int zHit) { this.state = state; this.xHit = xHit; this.yHit = yHit; this.zHit = zHit; } public IMessage onMessage(PacketBlockState message, MessageContext ctx) { //EntityPlayer player = NetUtils.getPlayerFromContext(ctx); EntityPlayer player = ctx.getServerHandler().playerEntity; System.out.println("setBlock-SERVER = " + player.worldObj.setBlock(xHit, yHit, zHit, Blocks.torch, 5, 2)); break; } return null; } public void fromBytes(ByteBuf buf) { this.state = buf.readInt(); this.xHit = buf.readInt(); this.yHit = buf.readInt(); this.zHit = buf.readInt(); } public void toBytes(ByteBuf buf) { buf.writeInt(this.state); buf.writeInt(this.xHit); buf.writeInt(this.yHit); buf.writeInt(this.zHit); } } Ok, I know, I shouldn't implement IMessage & IMessageHandler in the same class (I'll fix it...) ForgeEvent handler: @SubscribeEvent public void continueUsing (PlayerUseItemEvent.Tick event){ if (event.entityPlayer.worldObj.isRemote && event.entityPlayer.getCurrentEquippedItem() != null){ int xHit = event.entityPlayer.posX; int yHit = event.entityPlayer.posY; int zHit = event.entityPlayer.posZ; int light = event.entityPlayer.worldObj.getFullBlockLightValue(xHit, yHit - 1, zHit); if (light > 0 && light < { PacketDispatcher.sendToServer(new PacketBlockState(2, xHit, yHit - 1, zHit)); System.out.println("setBlock-CLIENT = " + event.entityPlayer.worldObj.setBlock(xHit, yHit - 1, zHit, Blocks.torch, 5, 2)); } } } I tried to use "Flag" = 1 but nothing to do...
February 16, 201510 yr Author Your message handler will always set the Block at 0, 0, 0. Why? You implemented IMessageHandler and IMessage on the same class, which makes this error even possible in the first place. You don't need a packet for this though at all... the event you are using is fired on the server, too. Just check with world.isRemote. I checked. The coordinates are correctly sended ... and the registration packets force me to implement IMessage and IMessageHandler into the same class: PacketDispatcher class: public class PacketDispatcher { private static byte packetId = 0; private static final SimpleNetworkWrapper dispatcher = NetworkRegistry.INSTANCE.newSimpleChannel(Properties.modid); public static final void registerPackets() { PacketDispatcher.dispatcher.registerMessage(PacketBlockState.class, PacketBlockState.class, packetId++, Side.SERVER); } } SimpleNetworkWrapper required that ...
February 16, 201510 yr I tried to use "Flag" = 1 but nothing to do... You don't even know what the flag does, do you? Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
February 16, 201510 yr Author I tried to use "Flag" = 1 but nothing to do... You don't even know what the flag does, do you? I think you know very well, right?
February 16, 201510 yr Not if you're throwing random values like '5' and '1' in there. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
February 16, 201510 yr Its really easy. Flag 1 will cause a block update. Flag 2 will send the change to clients (you almost always want this). Flag 4 prevents the block from being re-rendered, if this is a client world. Flags can be added together. Flag 3 will cause a block update and send the change to the client. Flag 5 will cause a block update and prevent the block from being re-rendered. Etc. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
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.