Skip to content

Class "Level"⚓︎

Functions⚓︎

CanPlaceRoom ()⚓︎

boolean CanPlaceRoom ( RoomConfigRoom RoomConfigToPlace, int GridIndex, Dimension Dimension = -1, bool AllowMultipleDoors = true, bool AllowSpecialNeighbors = false, bool AllowNoNeighbors = false )⚓︎

Returns true if the provided room could be successfully placed at this location using TryPlaceRoom.

See documentation for TryPlaceRoom for more information.


CanPlaceRoomAtDoor ()⚓︎

boolean CanPlaceRoomAtDoor ( RoomConfigRoom RoomConfigToPlace, RoomDescriptor NeighborRoomDescriptor, DoorSlot DoorSlot, bool AllowMultipleDoors = true, bool AllowSpecialNeighbors = false )⚓︎

Returns true if the provided room (the RoomConfigRoom) could be successfully placed as a neighbor of an existing room (the RoomDescriptor) at the specified DoorSlot, using TryPlaceRoomAtDoor.

See documentation for TryPlaceRoomAtDoor and TryPlaceRoom for more information.


CanSpawnDoorOutline ()⚓︎

boolean CanSpawnDoorOutline ( int RoomIdx, DoorSlot DoorSlot )⚓︎


FindValidRoomPlacementLocations ()⚓︎

int[] FindValidRoomPlacementLocations ( RoomConfigRoom RoomConfig, Dimension Dimension = -1, bool AllowMultipleDoors = true, bool AllowSpecialNeighbors = false )⚓︎

Returns a table of room grid indices that would be valid locations to place the specified room using TryPlaceRoom.

See TryPlaceRoom for more information on room placement and example code.


GetDimension ()⚓︎

Dimension GetDimension ( )⚓︎

Get's the current Dimension the player is in.


GetForceSpecialQuest ()⚓︎

SpecialQuest GetForceSpecialQuest ( )⚓︎

If set, the level will automatically attempt to place the Knife Piece puzzle door for this LevelStage.

Info

This is set to SpecialQuest.DEFAULT immediately before calling MC_PRE_LEVEL_INIT.


GetGreedWavesClearedWithoutRedHeartDamage ()⚓︎

int GetGreedWavesClearedWithoutRedHeartDamage ( )⚓︎


GetMyosotisPickups ()⚓︎

EntitiesSaveStateVector GetMyosotisPickups ( )⚓︎

Returns the pickups that will be transferred to the next floor by the Myosotis trinket effect.


GetNeighboringRooms ()⚓︎

table GetNeighboringRooms ( int GridIndex, RoomShape, Dimension Dimension = -1 )⚓︎

Returns a table that maps DoorSlot to RoomDescriptor for all of the neighbors that a room of the specified shape would have if placed at this location.

Don't use ipairs to iterate over this, use pairs!

Note that this does not give you any information on if a room would actually fit here, or if the neighbors would even allow the connection.

If you want to get the neighbors of an existing room, you can simply use RoomDescriptor:GetNeighboringRooms() instead.

Example Code
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
-- Returns true if a room placed at this GridIndex with this RoomShape would have a neighboring secret room.
local function WouldHaveSecretRoomNeighbor(gridIndex, roomShape)
    for doorSlot, neighborDesc in pairs(Game():GetLevel():GetNeighboringRooms(gridIndex, roomShape)) do
        local roomType = neighborDesc.Data.Type
        if roomType == RoomType.ROOM_SECRET or roomType == RoomType.ROOM_SUPERSECRET or roomType == RoomType.ROOM_ULTRASECRET then
            return true
        end
    end
    return false
end

HasAbandonedMineshaft ()⚓︎

boolean HasAbandonedMineshaft ( )⚓︎

Returns true if the floor has the mineshaft room used for the second Knife Piece puzzle.


HasMirrorDimension ()⚓︎

boolean HasMirrorDimension ( )⚓︎

Returns true if the floor has the mirror dimension used for the first Knife Piece puzzle.


HasPhotoDoor ()⚓︎

boolean HasPhotoDoor ( )⚓︎

Returns true if the floor has the photo door used to enter Mausoleum/Gehenna leading to the Ascent sequence.


IsStageAvailable ()⚓︎

void IsStageAvailable ( LevelStage Level, StageType Stage )⚓︎

Returns true if the provided Level and Stage combination is available to be generated in any given run. Returns false if locked behind an achievement.


PlaceRoom ()⚓︎

boolean PlaceRoom ( LevelGeneratorEntry Room, RoomConfigRoom RoomConfig, int Seed )⚓︎

Places a room into the game. Returns true if successful.

Note that this function does not really check if a room placement would be considered valid, nor does it create the doors necessary to connect the new room to its neighbors.

See TryPlaceRoom and related functions if you want to properly add new rooms to the floor after level generation, similarly to what Red Key does.


SetForceSpecialQuest ()⚓︎

void SetForceSpecialQuest ( SpecialQuest Quest )⚓︎

Sets whether the level should attempt to place the Knife Piece puzzle door for this LevelStage.

Info

This is set to SpecialQuest.DEFAULT immediately before calling MC_PRE_LEVEL_INIT.


SetGreedWavesClearedWithoutRedHeartDamage ()⚓︎

void SetGreedWavesClearedWithoutRedHeartDamage ( int WavesCleared )⚓︎


SetName ()⚓︎

void SetName ( string Name )⚓︎


TryPlaceRoom ()⚓︎

RoomDescriptor TryPlaceRoom ( RoomConfigRoom RoomConfigToPlace, int GridIndex, Dimension Dimension = -1, int Seed = 0, bool AllowMultipleDoors = true, bool AllowSpecialNeighbors = false, bool AllowNoNeighbors = false )⚓︎

Attempts to place the provided room at the specified location.

If successful, returns the newly initialized RoomDescriptor. Otherwise, returns nil.

This function will ONLY place the room if it fits (does not overlap any other existing rooms, and can mutually connect to all neighboring room with doors).

If a seed of 0 or nil is provided, a deterministic seed with be auto-generated based on the location, room shape, and level seed.

The boolean parameters enable or disable additional restrictions/safeties for room placement:

  • AllowMultipleDoors: Set to false to only allow placement if the room would only have one door (useful for placing special rooms).
  • AllowSpecialNeighbors: Set to true to allow connections to existing special rooms (note that secret rooms are always permitted, but boss rooms never are).
  • AllowNoNeighbors: Set to true to permit room placements out in the void with no neighbors at all.
Example Code
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
-- Adds another treasure room to the floor at a random valid location.
local function AddAnotherTreasureRoomToTheFloorAtARandomValidLocation()
    local level = game:GetLevel()

    local dimension = -1  -- current dimension
    local seed = level:GetDungeonPlacementSeed()

    -- Fetch a random RoomConfig for a new treasure room.
    local roomConfig = RoomConfigHolder.GetRandomRoom(seed, true, StbType.SPECIAL_ROOMS, RoomType.ROOM_TREASURE, RoomShape.ROOMSHAPE_1x1)

    -- Disallow placements with multiple doors, or placements that connect to other special rooms.
    local allowMultipleDoors = false
    local allowSpecialNeighbors = false

    -- Fetch all valid locations.
    local options = level:FindValidRoomPlacementLocations(roomConfig, dimension, allowMultipleDoors, allowSpecialNeighbors)

    for _, gridIndex in pairs(options) do
        -- You may have additional conditions or priorities when it comes to where you would prefer to place your room.
        -- For the purposes of this example we arbitarily forbid the new room from being connected to the starting room,
        -- and otherwise just place the room at the first place we check.

        -- Get the RoomDescriptors of all rooms that would be neighboring the room if placed here.
        local neighbors = level:GetNeighboringRooms(gridIndex, roomConfig.Shape)

        local connectsToStartingRoom = false

        for doorSlot, neighborDesc in pairs(neighbors) do
            if neighborDesc.GridIndex == level:GetStartingRoomIndex() then
                connectsToStartingRoom = true
            end
        end

        if not connectsToStartingRoom then
            -- Try to place the room.
            local room = level:TryPlaceRoom(roomConfig, gridIndex, dimension, seed, allowMultipleDoors, allowSpecialNeighbors)
            if room then
                -- The room was placed successfully!
                return
            end
        end
    end
end

TryPlaceRoomAtDoor ()⚓︎

RoomDescriptor TryPlaceRoomAtDoor ( RoomConfigRoom RoomConfigToPlace, RoomDescriptor NeighborRoomDescriptor, DoorSlot DoorSlot, int Seed = 0, bool AllowMultipleDoors = true, bool AllowSpecialNeighbors = false )⚓︎

Similar to TryPlaceRoom, but attempts to place the provided room (the RoomConfigRoom) as a neighbor of an existing room (the RoomDescriptor) at the specified DoorSlot.

Otherwise, the details are the same as for TryPlaceRoom.

Example Code
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
-- Example code for an active item that creates a new 1x1 room at every doorslot available in the current room.
mod:AddCallback(ModCallbacks.MC_USE_ITEM, function(_, id, rng, player, flags, slot)
    local level = game:GetLevel()
    local room = game:GetRoom()
    local roomDesc = level:GetCurrentRoomDesc()

    local success = false

    for doorSlot=0, 7 do
        -- Bitmask check to identify if the current room would even allow a door to be placed here.
        local doorSlotAllowed = roomDesc.Data.Doors & (1 << doorSlot) ~= 0
        if doorSlotAllowed and not room:GetDoor(doorSlot) then
            local seed = rng:Next()
            local requiredDoors = 15  -- Bitmask value that requires the new 1x1 room to have all 4 doorslots available, just so we're sure it fits.
            local roomConfig = RoomConfigHolder.GetRandomRoom(seed, true, Isaac.GetCurrentStageConfigId(), RoomType.ROOM_DEFAULT, RoomShape.ROOMSHAPE_1x1, nil, nil, nil, nil, requiredDoors)
            if roomConfig then
                local newRoom = level:TryPlaceRoomAtDoor(roomConfig, roomDesc, nearestDoorSlot, seed, true, false)
                if newRoom then
                    success = true
                end
            end
        end
    end

    if success then
        return {ShowAnim=true}
    else
        return {Discharge=false}
    end
end, MY_ACTIVE_ITEM_ID)