Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fluid Elements #30

Open
andrewgrider opened this issue Apr 7, 2018 · 1 comment
Open

Fluid Elements #30

andrewgrider opened this issue Apr 7, 2018 · 1 comment

Comments

@andrewgrider
Copy link

You can't walk through fluid elements, you just stand on them, and they expand till they cover the map or till they hit another block
alt text

@p3rlphr33k
Copy link

p3rlphr33k commented Apr 7, 2022

I have made adjustments to this recently when I started working on this again. I realize this is an old issue but i thought I would share.

I have added a stepping system into fluids to track increments and prevent flooding. You can adjust the maxStep variable to how many steps/size increases you want to allow water to spread.

in physics.js replace fluids section with this:

	// Fluids
	if ( step % 5 == 0 )
	{
		// Newly spawned fluid blocks are stored so that those aren't
		// updated in the same step, creating a simulation avalanche.
		var newFluidBlocks = {};
		var maxStep = 5;
		for ( var x = 0; x < world.sx; x++ ) {
			for ( var y = 0; y < world.sy; y++ ) {
				for ( var z = 0; z < world.sz; z++ ) {
					var material = blocks[x][y][z];
	
					if ( material.fluid && newFluidBlocks[x+","+y+","+z] == null && material.step < maxStep)
					{
						console.log('spread step: '+material.step);
						if ( x > 0 && blocks[x-1][y][z] == BLOCK.AIR ) {
							world.setBlock( x - 1, y, z, material );
							newFluidBlocks[(x-1)+","+y+","+z] = true;
						}
						if ( x < world.sx - 1 && blocks[x+1][y][z] == BLOCK.AIR ) {
							world.setBlock( x + 1, y, z, material );
							newFluidBlocks[(x+1)+","+y+","+z] = true;
						}
						if ( y > 0 && blocks[x][y-1][z] == BLOCK.AIR ) {
							world.setBlock( x, y - 1, z, material );
							newFluidBlocks[x+","+(y-1)+","+z] = true;
						}
						if ( y < world.sy - 1 && blocks[x][y+1][z] == BLOCK.AIR ) {
							world.setBlock( x, y + 1, z, material );
							newFluidBlocks[x+","+(y+1)+","+z] = true;
						}

						material.step++;
					}
				}
			}
		} 
	}

In block.js update BLOCK.WATER, BLOCK.LAVA, or any other liquids you might have so they have a step option:

// Water
BLOCK.WATER = {
	id: 19,
	strike: 1,
	spawnable: true,
	breakable: false,
	transparent: true,
	selflit: false,
	gravity: true,
	fluid: true,
	step: 1,
	fire: false,
	texture: function( world, lightmap, lit, x, y, z, dir ) {
              return [ 13/16, 12/16, 14/16, 13/16 ];
        },
	
	icon: "water.png"
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants