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 need a more efficient way to do something like this:

 

In a forest the ticks per second going down to ca. 6.

 

	@SubscribeEvent
	public void world_tick(WorldTickEvent event)
	{
		if(!event.world.isRemote)
		{
			WorldServer world = (WorldServer) event.world;
			
			if(!world.equals(DimensionManager.getWorld(SolarApocalypse.dimID)))
				return;
			
			int ticks = world.getGameRules().getInt("randomTickSpeed");
			int day = WorldProviderSolar.getDataFor(world).day;
			Chunk[] array = world.getChunkProvider().getLoadedChunks().toArray(new Chunk[world.getChunkProvider().getLoadedChunkCount()]);
			
			if(array.length>1)
			for(int i=0; i < ticks; i++)
			{
				Chunk chunk = array[rand.nextInt(array.length)];
			
				for (ExtendedBlockStorage extendedblockstorage : chunk.getBlockStorageArray())
                {
                    if(extendedblockstorage != Chunk.NULL_BLOCK_STORAGE && extendedblockstorage.getNeedsRandomTick())
                    {
                        for (int c = 0; c< ticks; c++)
                        {
                            int x = rand.nextInt(16) + chunk.xPosition*16;
                            int z = rand.nextInt(16) + chunk.zPosition*16;
                            BlockPos pos = world.getTopSolidOrLiquidBlock(new BlockPos(x, 0, z));
                            
                            this.change_block(world, pos, day, true);
                        }
                    }
                }
			}
		}
	}
	
	/*
	 * changes block beneath the BlockPos
	 */
	private void change_block(WorldServer world, BlockPos up, int day, boolean surface)
	{
    	boolean needs_clean_up = false;
		BlockPos down = up.down();
        
        Block block = world.getBlockState(down).getBlock();
        
        if(block.equals(Blocks.GRASS) || block.equals(Blocks.GRASS_PATH) || 
        		block.equals(Blocks.MYCELIUM) || block.equals(Blocks.DIRT))
        {
        	world.setBlockState(down, Blocks.DIRT.getStateFromMeta(1), 2);
        	needs_clean_up = true;
        }
        else if(surface && block.isFlammable(world, down, EnumFacing.UP) && 
        		!world.getBlockState(up).getBlock().equals(Blocks.FIRE))
        { 
        	world.setBlockState(down, Blocks.FIRE.getDefaultState(), 2);
        }
        else if(block.equals(Blocks.DIRT))
        {
        	world.setBlockState(down, Blocks.GRAVEL.getDefaultState(), 2);
        	needs_clean_up = true;
        }
        else if(block.equals(Blocks.GRAVEL))
        {
        	world.setBlockState(down, Blocks.SAND.getDefaultState(), 2);
        }
        else if(block.equals(Blocks.SAND))
        {
        	needs_clean_up = true;
        	this.change_block(world, down, day, false);
        }
        
        if(surface && needs_clean_up)
        {
        	world.setBlockState(up, Blocks.AIR.getDefaultState(), 2);
        }
	}

 

Edited by TheDav1311

  • Author

Thank you, that solves the problem.

 

And the extended block storage comes from the original code (Random Block Updates in the WorldServer.class), and I didn't remove them.....

Edited by TheDav1311

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.