Deleting sponge should active neighouring water, partially addresses #205. (Thanks andreja6)

This commit is contained in:
UnknownShadow200 2016-05-21 16:11:17 +10:00
parent fba550f3c2
commit 30f39a90fb
2 changed files with 32 additions and 3 deletions

View File

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

View File

@ -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,12 +88,18 @@ 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;
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 ) {
falling.ResetMap();