Posted July 18, 201510 yr 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)); }
July 18, 201510 yr 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.)
July 18, 201510 yr 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)); }
July 19, 201510 yr 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.)
July 19, 201510 yr 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.
July 19, 201510 yr 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(). http://i.imgur.com/NdrFdld.png[/img]
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.