Jump to content

Recommended Posts

Posted (edited)

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
Posted (edited)

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...

×   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.