mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-18 20:15:35 -04:00
Deleting sponge should active neighouring water, partially addresses #205. (Thanks andreja6)
This commit is contained in:
parent
fba550f3c2
commit
30f39a90fb
@ -24,6 +24,7 @@ namespace ClassicalSharp.Singleplayer {
|
||||
physics.OnPlace[(byte)Block.Water] =
|
||||
(index, b) => Water.Enqueue( defWaterTick | (uint)index );
|
||||
physics.OnPlace[(byte)Block.Sponge] = PlaceSponge;
|
||||
physics.OnDelete[(byte)Block.Sponge] = DeleteSponge;
|
||||
|
||||
physics.OnActivate[(byte)Block.Water] = ActivateWater;
|
||||
physics.OnActivate[(byte)Block.StillWater] = ActivateWater;
|
||||
@ -140,5 +141,26 @@ namespace ClassicalSharp.Singleplayer {
|
||||
game.UpdateBlock( xx, yy, zz, (byte)Block.Air );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DeleteSponge( int index, byte block ) {
|
||||
int x = index % width;
|
||||
int y = index / oneY; // posIndex / (width * length)
|
||||
int z = (index / width) % length;
|
||||
|
||||
for( int yy = y - 3; yy <= y + 3; yy++ )
|
||||
for( int zz = z - 3; zz <= z + 3; zz++ )
|
||||
for( int xx = x - 3; xx <= x + 3; xx++ )
|
||||
{
|
||||
if( Math.Abs( yy - y ) == 3 || Math.Abs( zz - z ) == 2 || Math.Abs( xx - x ) == 3 ) {
|
||||
if( !map.IsValidPos( x, y, z ) ) continue;
|
||||
|
||||
index = xx + width * (zz + yy * length);
|
||||
block = map.blocks[index];
|
||||
if( block == (byte)Block.Water || block == (byte)Block.StillWater )
|
||||
Water.Enqueue( (1u << Physics.tickShift) | (uint)index );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -29,6 +29,7 @@ namespace ClassicalSharp.Singleplayer {
|
||||
|
||||
public Action<int, byte>[] OnActivate = new Action<int, byte>[256];
|
||||
public Action<int, byte>[] OnPlace = new Action<int, byte>[256];
|
||||
public Action<int, byte>[] OnDelete = new Action<int, byte>[256];
|
||||
|
||||
public Physics( Game game ) {
|
||||
this.game = game;
|
||||
@ -87,11 +88,17 @@ namespace ClassicalSharp.Singleplayer {
|
||||
}
|
||||
|
||||
void BlockChanged( object sender, BlockChangedEventArgs e ) {
|
||||
if( !Enabled || e.Block == 0 ) return;
|
||||
if( !Enabled ) return;
|
||||
Vector3I p = e.Coords;
|
||||
int index = (p.Y * length + p.Z) * width + p.X;
|
||||
Action<int, byte> place = OnPlace[e.Block];
|
||||
if( place != null ) place( index, e.Block );
|
||||
|
||||
if( e.Block == 0 ) {
|
||||
Action<int, byte> delete = OnDelete[e.OldBlock];
|
||||
if( delete != null ) delete( index, e.OldBlock );
|
||||
} else {
|
||||
Action<int, byte> place = OnPlace[e.Block];
|
||||
if( place != null ) place( index, e.Block );
|
||||
}
|
||||
}
|
||||
|
||||
void ResetMap( object sender, EventArgs e ) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user