Jump to content
  • Home
  • Files
  • Docs
  • Merch
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.12.2] setBlockToAir(BlockPos) not registering on Client side
1.13 Update Notes for Mod Creators
Sign in to follow this  
Followers 1
Kekz

[1.12.2] setBlockToAir(BlockPos) not registering on Client side

By Kekz, October 10 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

Kekz    1

Kekz

Kekz    1

  • Tree Puncher
  • Kekz
  • Members
  • 1
  • 24 posts
Posted October 10 (edited)

I am trying to remove some blocks I placed with

worldIn.setBlockState(new BlockPos(pos.getX() + j, pos.getY() + 1, pos.getZ() + i), Blocks.BEDROCK.getDefaultState());

by using

worldIn.setBlockToAir(new BlockPos(px + j, py + 4, pz + i));

Both the building and removing processes happen in my onItemUse() method of my 2 custom items.

In MazeGenerator.java blocks are placed in the onItemUse() method, and in MazeScapeKey.java they are removed in onItemUse().

The removing process itself happens in a method in MazeGenerator.java

 

This rarely works, as only some of the blocks are removed, while other blocks are still there, but disappear as soon as i right click on them.

Sometimes all the blocks are removed correctly, sometimes only a few.

 

I have tried using worldIn.markBlockRangeForRenderUpdate() after setting all the blocks to air, but that doesn't seem to help.

 

What am I doing wrong? As far as I understand, this behaviour means that the Server has succesfully removed the blocks, but the Client is still rendering them.

How can I ensure that the Client realizes that those blocks are no longer there?

 

My whole code

 

I am grateful for any help,

Edited October 10 by Kekz
Added minecraft version in title
  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6692

diesieben07

diesieben07    6692

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6692
  • 45732 posts
Posted October 10
  • Why on earth are you using state IDs to compare blocks? Just compare the IBlockState.
  • You cannot store data like this in the Item class. There is only one instance of your Item class. If you want to store additional data, it needs to be stored in the ItemStack, either using NBT or capabilities.
    Even worse, in your case you are accessing these fields from both client server without any synchronization. This will lead to strange and hard to diagnose bugs, because your code will execute on both server and client thread.
    Same here.
  • Currently you are calling clearLabyrinth on client and server. Blocks must only be modified on the server.
  • Quote

Share this post


Link to post
Share on other sites

Kekz    1

Kekz

Kekz    1

  • Tree Puncher
  • Kekz
  • Members
  • 1
  • 24 posts
Posted October 10
6 minutes ago, diesieben07 said:
  • Why on earth are you using state IDs to compare blocks? Just compare the IBlockState.

Ok, thanks for the feedback I'll change that.

 

6 minutes ago, diesieben07 said:
  • Currently you are calling clearLabyrinth on client and server. Blocks must only be modified on the server.

Does this mean that I should also call buildLabyrinth only on the server side? because that method is not causing any problems

 

10 minutes ago, diesieben07 said:
  • You cannot store data like this in the Item class. There is only one instance of your Item class. If you want to store additional data, it needs to be stored in the ItemStack, either using NBT or capabilities.
  • Even worse, in your case you are accessing these fields from both client server without any synchronization. This will lead to strange and hard to diagnose bugs, because your code will execute on both server and client thread.
    Same here.

Thanks I'll look into that

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6692

diesieben07

diesieben07    6692

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6692
  • 45732 posts
Posted October 10
1 minute ago, Kekz said:

Does this mean that I should also call buildLabyrinth only on the server side? because that method is not causing any problems

Yes, you need to only place blocks on the server.

  • Thanks 1
  • Quote

Share this post


Link to post
Share on other sites

Kekz    1

Kekz

Kekz    1

  • Tree Puncher
  • Kekz
  • Members
  • 1
  • 24 posts
Posted October 10

I'm sorry, but how can I make sure that I only execute buildLabyrinth and clearLabyrinth on the server side?

I tried putting

if (!worldIn.isRemote) {
	// do building / removing
}

around the whole process in both methods, but that doesn't seem to work.

Building the maze doesn't work too now and clearing it still doesn't clear all blocks correctly as before.

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6692

diesieben07

diesieben07    6692

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6692
  • 45732 posts
Posted October 10

Yes, that's how you would usually do it, provided you are in a method which is actually called on both sides.

 

However you first need to fix this:

1 hour ago, diesieben07 said:

You cannot store data like this in the Item class. There is only one instance of your Item class. If you want to store additional data, it needs to be stored in the ItemStack, either using NBT or capabilities.
Even worse, in your case you are accessing these fields from both client server without any synchronization. This will lead to strange and hard to diagnose bugs, because your code will execute on both server and client thread.
Same here.

 

  • Sad 1
  • Quote

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

  • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 1
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • The_Unkown675
      Can't connect to own server; No syncable config

      By The_Unkown675 · Posted 8 minutes ago

      Server debug file - https://paste.gg/p/anonymous/0671148362b5476fbce55b8922262dad Latest log file -https://paste.gg/p/anonymous/bab7c2b3ca0947df9b10bce9c2632c22 Hope this helps! If you need anything else please let me know, I'll be happy to help, thank you for your help!
    • diesieben07
      Forge 1.12.2 crashes and wont load world!

      By diesieben07 · Posted 9 minutes ago

      In the future please always post the debug.log. From the excerpt you posted it looks like your world got corrupted. Restore from backup.
    • diesieben07
      Clean forge installer

      By diesieben07 · Posted 12 minutes ago

      Only ever download Forge from https://files.minecraftforge.net/. Any other site offering Forge downloads is illegitimate.   There is no Forge version for 1.15 at this time. Be patient.
    • DragonITA
      [1.14.4] How to get Minecraft Horse model/texture to make a custom unicorn?

      By DragonITA · Posted 16 minutes ago

      To extends the HorseModel i need replace the LivingEntity with the AbstractHorseEntity.
    • CrashDbo
      [1.12.2] Water Crafting with dropped items like AE2

      By CrashDbo · Posted 16 minutes ago

      Thanks for the Advise, I will look at both ways and see what will work best.
  • Topics

    • The_Unkown675
      2
      Can't connect to own server; No syncable config

      By The_Unkown675
      Started 18 hours ago

    • PolarBr0
      1
      Forge 1.12.2 crashes and wont load world!

      By PolarBr0
      Started 28 minutes ago

    • Rick57
      1
      Clean forge installer

      By Rick57
      Started 3 hours ago

    • DragonITA
      44
      [1.14.4] How to get Minecraft Horse model/texture to make a custom unicorn?

      By DragonITA
      Started Monday at 10:06 AM

    • CrashDbo
      3
      [1.12.2] Water Crafting with dropped items like AE2

      By CrashDbo
      Started 17 hours ago

  • Who's Online (See full list)

    • OxyWorlds
    • diesieben07
    • CrashDbo
    • ShetiPhian
    • PolarBr0
    • Redstoneguy129
    • lopiy
    • AmateurHalibut
    • AdieCraft
    • Draco18s
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.12.2] setBlockToAir(BlockPos) not registering on Client side
  • Theme
  • Contact Us
  • Discord

Copyright © 2019 ForgeDevelopment LLC · Ads by Curse Powered by Invision Community