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 modders,

My goal is to make some block generate on the surface realtime with some probability, just like tall grass on dirt block. 

 

For example, make dead bush appear on sand. Vanilla minecraft does this generation on tick, when block's random tick is set to true. But for sand it is false.

I could override vanilla sand block and make it randomly tick, but it seems this way would have compatibility issues (if some other mod overrides basic sand too).

 

Another option that I see - is to listen to some chunk event (for example load chunk), get access to that chunk, check if surface block is sand and with some probability - generate dead bush.

This way I do not need to override any blocks, but I'm not sure about perfomance.

 

Is there a better way to achieve my goal, or I should stick to my options?

 

Edited by moonlyer

  • Author
17 minutes ago, diesieben07 said:

From your post it is not clear if you are talking about a world-generation feature or something like crops growing.

Please clarify.

It's something like crops growing.

To be precise i want to do exactly the same like tall grass and flowers spawning randomly on the grass while the game is running, but on other already existing blocks too (vanilla or other mods). The most obvious way for me is too override existing blocks in the registry with my custom class.

public class CustomBlockSand extends BlockSand
{
	CustomBlockSand()
	{
		super();
		this.setTickRandomly(true);
		this.setRegistryName("minecraft:sand");
		this.setUnlocalizedName("sand");
	}
	
	@Override
	 public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
	 {
		//My tallgrass/flower spawning code
	 }
}

 

But I feel overriding existing blocks will ruin compatibility with other mods, so I'm looking for a better way to do this. 

  • Author

Thanks, I thought so. Well, time to do some code shenanigans then :ph34r:, maybe it will get me somewhere.

  • 2 weeks later...
  • Author

If someone interested, I managed to generate tall grass realtime without overriding vanilla blocks by accesing chunk in ChunkEvent.Load event, and generating needed blocks, like worldgen does. I haven't noticed much perfomance drops.

	@SubscribeEvent
	public void onChunkLoad (ChunkEvent.Load event)
	{
		
		if (!event.getWorld().isRemote)
		{
		
			
			//Get random x,z in chunk; Search for surface y; Check if possible to place; Places block	
			Elcraft.elcraftRealtimeGenerator.GenDustInChunk(event.getChunk());
			
			
		}
	}

 

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.