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

I'm trying to make a simple block that just makes a pillar of itself when used. Everything is working when I run it, however problems arise when I save the world and reload it. All of the new blocks placed by the block disappear when the world is reloaded. I haven't been able to find much information on this and I'm relatively new to Minecraft modding and Java my background is in C/C++ for research and robotics.

        @Override
public boolean onBlockActivated(
            World world,
            BlockPos pos,
            IBlockState state,
            EntityPlayer player,
            EnumHand hand,
            @Nullable ItemStack heldItem,
            EnumFacing side,
            float hitX,
            float hitY,
            float hitZ) {
	if (!world.isRemote){
		return false;
	}
	Random rand = new Random();
	IBlockState block = world.getBlockState(pos);
	for(int i = 0; i < 7; i++){
		world.setBlockState(pos.add(0, i, 0), block);
	}
	for(int k = 0; k < 20; k++){
		int x, z;
		x= rand.nextInt(16)-8;
		z= rand.nextInt(16)-8;
		EntityLightningBolt lightning = new EntityLightningBolt(world, pos.getX()+x, pos.getY(), pos.getZ()+z, false);
		world.addWeatherEffect(lightning);
	}
	return true;
}

 

I'm working by deconstructing examples but I seem to be missing something. Any advice is appreciated, thanks in advance.

World#isRemote

is

true

on the client and

false

on the server, so you're doing everything on the client instead of the server. The server is in charge of the game state, so the changes you make disappear when the client next synchronises with the server.

 

You may want to use the

World#rand

field instead of creating your own

Random

each time.

 

Similarly, consider using the specialised methods like

BlockPos#up

instead of the more general

BlockPos#add

when only changing one coordinate of a

BlockPos

. There's no real performance difference, but your code will be a bit clearer.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

  • Author

Thank you very much! I removed the negation and it worked fine.

Thanks for the advice about cleaning up my code as well.

Cheers!

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.