Jump to content

[1.7.10] setBlock cant works


deenkayros

Recommended Posts

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...

Link to comment
Share on other sites

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...

 

 

 

 

Link to comment
Share on other sites

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 ...

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.