private static void PlayerMoving(object sender, PlayerMovingEventArgs e) { if (_world != null && e.Player.World == _world) { if (_world.gameMode == GameMode.MineField && !Failed.Contains(e.Player)) { if (e.NewPosition != null) { Vector3I oldPos = new Vector3I(e.OldPosition.X / 32, e.OldPosition.Y / 32, e.OldPosition.Z / 32); Vector3I newPos = new Vector3I(e.NewPosition.X / 32, e.NewPosition.Y / 32, e.NewPosition.Z / 32); if (oldPos.X != newPos.X || oldPos.Y != newPos.Y || oldPos.Z != newPos.Z) { if (!_map.InBounds(newPos)) { e.Player.TeleportTo(_map.Spawn); newPos = ( Vector3I )_map.Spawn; } // Check if the player jumped, flew, whatevers if (newPos.Z > _ground + 2) { e.Player.TeleportTo(e.OldPosition); newPos = oldPos; } foreach (Vector3I pos in Mines.Values) { if (newPos == new Vector3I(pos.X, pos.Y, pos.Z + 2) || newPos == new Vector3I(pos.X, pos.Y, pos.Z + 1) || newPos == new Vector3I(pos.X, pos.Y, pos.Z)) { _world.Map.QueueUpdate(new BlockUpdate(null, pos, Block.TNT)); _world.AddPhysicsTask(new TNTTask(_world, pos, null, true, false), 0); Vector3I removed; Mines.TryRemove(pos.ToString(), out removed); } } if (_map.GetBlock(newPos.X, newPos.Y, newPos.Z - 2) == Block.Green && !_stopped) { _stopped = true; Stop(e.Player, true); } } } } } }
private static void DrawOneBlock(Player player, Map map, Block drawBlock, Vector3I coord, BlockChangeContext context, ref int blocks, ref int blocksDenied, fCraft.Drawing.UndoState undoState) { if (map == null) { return; } if (player == null) { throw new ArgumentNullException("player"); } if (!map.InBounds(coord)) { return; } Block block = map.GetBlock(coord); if (block == drawBlock) { return; } if (player.CanPlace(map, coord, drawBlock, context) != CanPlaceResult.Allowed) { blocksDenied++; return; } map.QueueUpdate(new BlockUpdate(null, coord, drawBlock)); Player.RaisePlayerPlacedBlockEvent(player, map, coord, block, drawBlock, context); if (!undoState.IsTooLargeToUndo) { if (!undoState.Add(coord, block)) { player.Message("NOTE: This draw command is too massive to undo."); player.LastDrawOp = null; } } blocks++; }
static int DistanceToBlock(Map map, Vector3F coord, Vector3F vec, Block blockType, bool invert) { coord += HalfBlock; int iterations = 0; while (map.InBounds(new Vector3I(coord))) { Block blockAtPos = map.GetBlock(new Vector3I(coord)); if ((blockAtPos == blockType && !invert) || (blockAtPos != blockType && invert)) { break; } else { coord += vec; iterations++; } } return(iterations); }
static int DistanceToBlock(Map map, Vector3f coord, Vector3f vec, Block blockType, bool invert) { coord += .5f; int iterations = 0; while (map.InBounds(new Vector3i(coord))) { byte blockAtPos = map.GetBlockByte(new Vector3i(coord)); if ((blockAtPos == (byte)blockType && !invert) || (blockAtPos != (byte)blockType && invert)) { break; } else { coord += vec; iterations++; } } return(iterations); }
//stolen from BuildingCommands #region DrawOneBlock static void DrawOneBlock ( Player player, Map map, Block drawBlock, Vector3I coord, BlockChangeContext context, ref int blocks, ref int blocksDenied, fCraft.Drawing.UndoState undoState ) { if ( map == null ) return; if ( player == null ) throw new ArgumentNullException( "player" ); if ( !map.InBounds( coord ) ) return; Block block = map.GetBlock( coord ); if ( block == drawBlock ) return; if ( player.CanPlace( map, coord, drawBlock, context ) != CanPlaceResult.Allowed ) { blocksDenied++; return; } map.QueueUpdate( new BlockUpdate( null, coord, drawBlock ) ); Player.RaisePlayerPlacedBlockEvent( player, map, coord, block, drawBlock, context ); if ( !undoState.IsTooLargeToUndo ) { if ( !undoState.Add( coord, block ) ) { player.Message( "NOTE: This draw command is too massive to undo." ); player.LastDrawOp = null; } } blocks++; }
static int DistanceToBlock( Map map, Vector3f coord, Vector3f vec, Block blockType, bool invert ) { coord += .5f; int iterations = 0; while( map.InBounds( new Vector3i( coord ) ) ) { byte blockAtPos = map.GetBlockByte( new Vector3i( coord ) ); if( (blockAtPos == (byte)blockType && !invert) || (blockAtPos != (byte)blockType && invert) ) { break; } else { coord += vec; iterations++; } } return iterations; }
static int DistanceToBlock( Map map, Vector3F coord, Vector3F vec, Block blockType, bool invert ) { coord += HalfBlock; int iterations = 0; while( map.InBounds( new Vector3I( coord ) ) ) { Block blockAtPos = map.GetBlock( new Vector3I( coord ) ); if( (blockAtPos == blockType && !invert) || (blockAtPos != blockType && invert) ) { break; } else { coord += vec; iterations++; } } return iterations; }