Jump to content

Destroyed blocks wont disappear until I log out and back in


fitty_spenc

Recommended Posts

I am creating a mod that destroys blocks between two points, but when I use it in game, the blocks that get destroyed aren't actually disappearing until I log out and back in again. I am pretty new to modding but I believe it is caused by some disconnect between server and client. Anyone know how to fix this? I attached the whole file but here is the snippet where I am doing the destruction:

                int sX = 1, sY = 1, sZ = 1;

                if (((int)(posA[1].getX()) - (int)(posA[0].getX())) > 0)
                    sX = -1;
                if (((int)(posA[1].getY()) - (int)(posA[0].getY())) > 0)
                    sY = -1;
                if (((int)(posA[1].getZ()) - (int)(posA[0].getZ())) > 0)
                    sZ = -1;

                for (int i = 0; i <= Math.abs((int)(posA[1].getX()) - (int)(posA[0].getX())); i++ ){    
                    for (int j = 0; j <= Math.abs((int)(posA[1].getY()) - (int)(posA[0].getY())); j++ ){
                        for (int k = 0; k <= Math.abs((int)(posA[1].getZ()) - (int)(posA[0].getZ())); k++ ){
                                //somehow need to refresh client from server side for each block being destroyed

                                worldIn.destroyBlock(new BlockPos(i * sX + posA[1].getX(), j * sY + posA[1].getY(), k * sZ + posA[1].getZ()), true);
                                worldIn.scheduleBlockUpdate(new BlockPos(i * sX + posA[1].getX(), j * sY + posA[1].getY(), k * sZ + posA[1].getZ()), Blocks.AIR, Blocks.AIR.tickRate(worldIn), 0);
                                player.sendMessage(new TextComponentString("rm block " + (i * sX + posA[1].getX()) + " " + (j * sY + posA[1].getY()) + " " + (k * sZ + posA[1].getZ())));
                        }
                    }
                }

 

ItemMagicStick.java

Edited by fitty_spenc
Link to comment
Share on other sites

For starters, just to make your code more readable, try assigning your new BlockPos just once and then using it in each function call where needed.

 

Try setting a breakpoint on destroyBlock and then step through, both when you use your stick and when some vanilla action (such as an explosion) destroys a block. Does your usage look like the vanilla usage? Try to trace vanilla to where the server sends packets or marks chunks as needing to be updated to the client. When you see how vanilla handles things, your design should become clear.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Link to comment
Share on other sites

Uh. Your counter exists in two logical sides, too...

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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