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.

Featured Replies

Posted

Hi

 

I have this tool that when I right click, it fills a flat area with Blocks. The problem is, the blocks sometimes get placed on the server and client side correctly,

but when the amount of blocks that are changing is too large, they only get placed on the client side.

 

Here's my code:

@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
{


	matToReplace = world.getBlockState(pos);
	positions.add(pos);
	for(int i = 0; i < 80; i++) {

		for(int j = 0; j < positions.size(); j++) {

			if(side == EnumFacing.NORTH || side == EnumFacing.SOUTH) {
				addPositionsNorth(j,world);
			}
			if(side == EnumFacing.EAST || side == EnumFacing.WEST) {
				addPositionsEast(j,world);
			}	
			if(side == EnumFacing.DOWN || side == EnumFacing.UP) {
				addPositionsDown(j,world);
			}

		}

		positions.addAll(tempPositions);

		tempPositions.clear();
	} 


	for(int k = 0; k < positions.size(); k++) {

		world.setBlockState(positions.get(k), Block.getBlockFromName(stack.getTagCompound().getString("material")).getStateFromMeta(stack.getTagCompound().getInteger("damage")));
		world.scheduleBlockUpdate(positions.get(k), world.getBlockState(positions.get(k)).getBlock(), 1, 1);

	}


	positions.clear();
	tempPositions.clear();




	return EnumActionResult.PASS;
}

 

Any help would be apprechiated

  • Author

They are fields in my Item class... So how should I do it differently? Forge Events? Packets?

  • Author

They store the values for BlockPos so that they can get placed by the Item.

Items are singletons (only one instance of them ever exists), so instance fields can't be used to store per-stack data. The ItemStack's NBTTagCompound should be used to store data that is per-stack.

Don't make mods if you don't know Java.

Check out my website: http://shadowfacts.net

Developer of many mods

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.