Jump to content

[1.9.4] World seem to lag using world.SetBlockState()


NeusAap

Recommended Posts

Hello,

Today I made a method that uses 2 for loops to change the floor in front of you to 5x5 square filled with my own block (ModBlocks.houseFundaments).

But whenever I rightclick with the item (which is the trigger event for my method), the world seems to jigger more than usual. Is this normal or am I doing something wrong?

 

	private EnumActionResult buildHouse(World w, EntityPlayer p, BlockPos pos, ItemStack s) {
		
		final int xRows = 5;
		final int zRows = 5;
		BlockPos negStartPos = new BlockPos(-1, 0, 0);
		BlockPos prevBlockPos = pos.add(negStartPos);
		
		for(int i=1; i<=xRows; i++){
			BlockPos newBlockPos = new BlockPos(prevBlockPos.getX()+ 1, prevBlockPos.getY(), prevBlockPos.getZ());
			w.setBlockState(newBlockPos, ModBlocks.houseFundaments.getDefaultState());
			for (int j=1; j<=zRows; j++) {
				BlockPos zAddPos = new BlockPos(newBlockPos.getX(), newBlockPos.getY(), newBlockPos.getZ()+ 1);
				w.setBlockState(zAddPos, ModBlocks.houseFundaments.getDefaultState());
			}
            prevBlockPos = newBlockPos;
       }
		
		//w.setBlockState(pos, ModBlocks.houseFundaments.getDefaultState());
		
		return EnumActionResult.PASS;
		
	}

 

 

P.S. Does any one know why this codes only places in a 5x2? I just don't understand.

 

Thanks in advance,

NeusAap

Link to comment
Share on other sites

Well...

 

1) Use BlockPos.allInBox(...) instead of new BlockPos(...); and iterate over the list it returns instead

2) The more blocks you change all in one go, the longer the hitch will be

3) Look at the flag parameter to setBlockState() and see if you can avoid doing lighting recalculations until you're done

  • Like 1

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.