Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

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

Featured Replies

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));
}

  • Author

I tried that, and, although it corrected the block placement, block updates made the ice revert to water. (I mentioned this in my first post.)

  • Author
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));
	}

  • Author

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

  • Author

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.

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.