Jump to content

Recommended Posts

Posted (edited)

I feel like this must be something really obvious, because it seems very basic. I've got a custom door (which does not subclass vanilla BlockDoor - I'm adding and changing a lot of functionality so it's easiest to do from scratch), which opens and closes on right-click (as vanilla). In singleplayer this works fine, but in multiplayer there is a weird syncing problem. Visually, the door appears not to change its state - the model and the highlight bounding box stay the same. But the state does change on the server - if you try to walk through the door after 'closing' it (even though it still looks open), you bump into it (in a glitchy, jerky way), and can't get through.

 

Here is my onBlockActivated.

Spoiler

@Override
public boolean onBlockActivated(World world, BlockPos thisPos,
    	IBlockState thisState, EntityPlayer player, EnumHand hand,
        EnumFacing side, float x, float y, float z) {

    BlockPos otherPos = thisState.getValue(TOP) ?
      thisPos.down() : thisPos.up();
    IBlockState otherState = world.getBlockState(otherPos);

    if (otherState.getBlock() != this || world.isRemote) {

      return false;
    }

    thisState = thisState.cycleProperty(OPEN);
    world.setBlockState(thisPos, thisState);
    world.setBlockState(otherPos, otherState
                        .withProperty(OPEN, thisState.getValue(OPEN)));
    world.playEvent(player, thisState.getValue(OPEN) ?
                    1006 : 1012, thisPos, 0);

    return true;
}

 

I was under the impression that setBlockState by default synchronises the state change with the client - and I've stepped through in the debugger and seen that it does reach notifyBlockUpdate. So I don't understand why it doesn't seem to be updating properly? The whole class is here (along with the rest of my code).

Edited by Jay Avery
Posted

Well, I found the foolishly obvious solution. I had screwed up my getMetaFromState/getStateFromMeta so the state wasn't being stored or sent server->client correctly.

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.