Jump to content

[SOLVED]Ways to generate smth realtime on existing blocks


moonlyer

Recommended Posts

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
Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

  • 2 weeks later...

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());
			
			
		}
	}

 

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.