Jump to content

[1.8] [SOLVED]Client/server conflict when changing blocks? (checkerboard effect)


Recommended Posts

Posted

I'm trying to make an item that turns water in to ice underfoot. Whenever I try to do this, though, the block changes act a bit glitchy when the player is walking, and the blocks are just in a checkerboard when sprint-jumping. From what I can tell, it's to do with the client and the server having problems with each other. (world.isRemote fixes the glitch, but the blocks revert to water when updated.) Here's my code, can anyone tell me how I can fix it?

 

	public void onArmorTick(World world, EntityPlayer player, ItemStack itemStack)
{
	BlockPos pos = player.getPosition();

	if(world.getBlockState(pos.add(0, -1, 0)).getBlock().equals(Blocks.water))
		world.setBlockState(pos.add(0, -1, 0), Blocks.ice.getStateFromMeta(0));
	if(world.getBlockState(pos.add(1, -1, -1)).getBlock().equals(Blocks.water))
		world.setBlockState(pos.add(1, -1, -1), Blocks.ice.getStateFromMeta(0));
	if(world.getBlockState(pos.add(1, -1, 0)).getBlock().equals(Blocks.water))
		world.setBlockState(pos.add(1, -1, 0), Blocks.ice.getStateFromMeta(0));
	if(world.getBlockState(pos.add(1, -1, 1)).getBlock().equals(Blocks.water))
		world.setBlockState(pos.add(1, -1, 1), Blocks.ice.getStateFromMeta(0));
	if(world.getBlockState(pos.add(0, -1, -1)).getBlock().equals(Blocks.water))
		world.setBlockState(pos.add(0, -1, -1), Blocks.ice.getStateFromMeta(0));
	if(world.getBlockState(pos.add(0, -1, 1)).getBlock().equals(Blocks.water))
		world.setBlockState(pos.add(0, -1, 1), Blocks.ice.getStateFromMeta(0));
	if(world.getBlockState(pos.add(-1, -1, -1)).getBlock().equals(Blocks.water))
		world.setBlockState(pos.add(-1, -1, -1), Blocks.ice.getStateFromMeta(0));
	if(world.getBlockState(pos.add(-1, -1, 0)).getBlock().equals(Blocks.water))
		world.setBlockState(pos.add(-1, -1, 0), Blocks.ice.getStateFromMeta(0));
	if(world.getBlockState(pos.add(-1, -1, 1)).getBlock().equals(Blocks.water))
		world.setBlockState(pos.add(-1, -1, 1), Blocks.ice.getStateFromMeta(0));
}

Posted
BlockPos pos = player.getPosition();

	if(world.isRemote)
	{
		if(world.getBlockState(pos.add(0, -1, 0)).getBlock().equals(Blocks.water))
			world.setBlockState(pos.add(0, -1, 0), Blocks.ice.getStateFromMeta(0));
		if(world.getBlockState(pos.add(1, -1, -1)).getBlock().equals(Blocks.water))
			world.setBlockState(pos.add(1, -1, -1), Blocks.ice.getStateFromMeta(0));
		if(world.getBlockState(pos.add(1, -1, 0)).getBlock().equals(Blocks.water))
			world.setBlockState(pos.add(1, -1, 0), Blocks.ice.getStateFromMeta(0));
		if(world.getBlockState(pos.add(1, -1, 1)).getBlock().equals(Blocks.water))
			world.setBlockState(pos.add(1, -1, 1), Blocks.ice.getStateFromMeta(0));
		if(world.getBlockState(pos.add(0, -1, -1)).getBlock().equals(Blocks.water))
			world.setBlockState(pos.add(0, -1, -1), Blocks.ice.getStateFromMeta(0));
		if(world.getBlockState(pos.add(0, -1, 1)).getBlock().equals(Blocks.water))
			world.setBlockState(pos.add(0, -1, 1), Blocks.ice.getStateFromMeta(0));
		if(world.getBlockState(pos.add(-1, -1, -1)).getBlock().equals(Blocks.water))
			world.setBlockState(pos.add(-1, -1, -1), Blocks.ice.getStateFromMeta(0));
		if(world.getBlockState(pos.add(-1, -1, 0)).getBlock().equals(Blocks.water))
			world.setBlockState(pos.add(-1, -1, 0), Blocks.ice.getStateFromMeta(0));
		if(world.getBlockState(pos.add(-1, -1, 1)).getBlock().equals(Blocks.water))
			world.setBlockState(pos.add(-1, -1, 1), Blocks.ice.getStateFromMeta(0));
	}

Posted

Okay, I've changed it to !world.isRemote to correctly check if it's on the server, but now I'm getting the strange checkerboard effect again. (To reiterate, this is only while the player is sprint-jumping along the water. When the player is on the ground, there's a bit of delay on the block directly ahead of the player.)

Posted

Yes, but when they come back down it freezes the water in a checkerboard pattern. I'm wondering if there's any way to make it so that landing on the water and immediately going back up is enough to freeze every block.

Posted

Given the fact that when you were setting blocks client side you said that it resulted in the correct pattern, you could send a packet from the client to the server with the player's current client-side position information, then the server should be able to figure out what to do from there.

 

If that doesn't work, you could instead send the block position(s) that need to be changed, but it's not generally recommended to let the client dictate any sort of state, but if you really don't want a checkerboard pattern, it might be the only solution.

 

Also, when setting blocks, instead of using getStateFromMeta(0), you should use getDefaultState().

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.