Skip to main content

Grid Entities

Functions

convertXMLGridEntityType

convertXMLGridEntityType(gridEntityXMLType, gridEntityXMLVariant): [GridEntityType, int] | undefined

Helper function to convert the grid entity type found in a room XML file to the corresponding grid entity type and variant normally used by the game. For example, GridEntityXMLType.ROCK is 1000 (in a room XML file), but GridEntityType.ROCK is equal to 2 (in-game).

Parameters

NameType
gridEntityXMLTypeGridEntityXMLType
gridEntityXMLVariantint

Returns

[GridEntityType, int] | undefined

Defined in

packages/isaacscript-common/src/functions/gridEntities.ts:70


doesGridEntityExist

doesGridEntityExist(gridEntityType, variant?): boolean

Helper function to check if one or more of a specific kind of grid entity is present in the current room.

Parameters

NameTypeDefault valueDescription
gridEntityTypeGridEntityTypeundefinedThe grid entity type to match.
variantnumber-1Optional. Default is -1, which matches every variant.

Returns

boolean

Defined in

packages/isaacscript-common/src/functions/gridEntities.ts:97


getAllGridIndexes

getAllGridIndexes(): readonly int[]

Helper function to get every legal grid index for the current room.

Under the hood, this uses the Room.GetGridSize method.

Returns

readonly int[]

Defined in

packages/isaacscript-common/src/functions/gridEntities.ts:124


getCollidingEntitiesWithGridEntity

getCollidingEntitiesWithGridEntity(gridEntity): readonly Entity[]

Gets the entities that have a hitbox that overlaps with any part of the square that the grid entity is on.

This function is useful because the vanilla collision callbacks do not work with grid entities. This is used by POST_GRID_ENTITY_COLLISION custom callback.

Note that this function will not work properly in the POST_NEW_ROOM callback since entities do not have collision yet in that callback.

Parameters

NameType
gridEntityGridEntity

Returns

readonly Entity[]

Defined in

packages/isaacscript-common/src/functions/gridEntities.ts:141


getConstituentsFromGridEntityID

getConstituentsFromGridEntityID(gridEntityID): [gridEntityType: GridEntityType, variant: int]

Helper function to get the grid entity type and variant from a GridEntityID.

Parameters

NameType
gridEntityIDGridEntityID

Returns

[gridEntityType: GridEntityType, variant: int]

Defined in

packages/isaacscript-common/src/functions/gridEntities.ts:166


getGridEntities

getGridEntities(...gridEntityTypes): readonly GridEntity[]

Helper function to get every grid entity in the current room.

Use this function with no arguments to get every grid entity, or specify a variadic amount of arguments to match specific grid entity types.

For example:

for (const gridEntity of getGridEntities()) {
print(gridEntity.GetType())
}

For example:

const rocks = getGridEntities(
GridEntityType.ROCK,
GridEntityType.BLOCK,
GridEntityType.ROCK_TINTED,
);

Parameters

NameType
...gridEntityTypesreadonly GridEntityType[]

Returns

readonly GridEntity[]

Allow Empty Variadic

Defined in

packages/isaacscript-common/src/functions/gridEntities.ts:229


getGridEntitiesExcept

getGridEntitiesExcept(...gridEntityTypes): readonly GridEntity[]

Helper function to get every grid entity in the current room except for certain specific types.

This function is variadic, meaning that you can specify as many grid entity types as you want to exclude.

Parameters

NameType
...gridEntityTypesreadonly GridEntityType[]

Returns

readonly GridEntity[]

Defined in

packages/isaacscript-common/src/functions/gridEntities.ts:251


getGridEntitiesInRadius

getGridEntitiesInRadius(targetPosition, radius): readonly GridEntity[]

Helper function to get all grid entities in a given radius around a given point.

Parameters

NameType
targetPositionVector
radiusnumber

Returns

readonly GridEntity[]

Defined in

packages/isaacscript-common/src/functions/gridEntities.ts:282


getGridEntitiesMap

getGridEntitiesMap(...gridEntityTypes): ReadonlyMap<int, GridEntity>

Helper function to get a map of every grid entity in the current room. The indexes of the map are equal to the grid index. The values of the map are equal to the grid entities.

Use this function with no arguments to get every grid entity, or specify a variadic amount of arguments to match specific grid entity types.

Parameters

NameType
...gridEntityTypesreadonly GridEntityType[]

Returns

ReadonlyMap<int, GridEntity>

Allow Empty Variadic

Defined in

packages/isaacscript-common/src/functions/gridEntities.ts:337


getGridEntityANM2Path

getGridEntityANM2Path(gridEntityType): string | undefined

Helper function to get the ANM2 path for a grid entity type.

Parameters

NameType
gridEntityTypeGridEntityType

Returns

string | undefined

Defined in

packages/isaacscript-common/src/functions/gridEntities.ts:352


getGridEntityCollisionPoints

getGridEntityCollisionPoints(gridEntity): Object

Helper function to get the top left and bottom right corners of a given grid entity.

Parameters

NameType
gridEntityGridEntity

Returns

Object

NameType
topLeftVector
bottomRightVector

Defined in

packages/isaacscript-common/src/functions/gridEntities.ts:488


getGridEntityID

getGridEntityID(gridEntity): GridEntityID

Helper function to get a string containing the grid entity's type and variant.

Parameters

NameType
gridEntityGridEntity

Returns

GridEntityID

Defined in

packages/isaacscript-common/src/functions/gridEntities.ts:505


getGridEntityIDFromConstituents

getGridEntityIDFromConstituents(gridEntityType, variant): GridEntityID

Helper function to get a formatted string in the format returned by the getGridEntityID function.

Parameters

NameType
gridEntityTypeGridEntityType
variantint

Returns

GridEntityID

Defined in

packages/isaacscript-common/src/functions/gridEntities.ts:515


getMatchingGridEntities

getMatchingGridEntities(gridEntityType, variant): readonly GridEntity[]

Helper function to get all of the grid entities in the room that specifically match the type and variant provided.

If you want to match every variant, use the getGridEntities function instead.

Parameters

NameType
gridEntityTypeGridEntityType
variantint

Returns

readonly GridEntity[]

Defined in

packages/isaacscript-common/src/functions/gridEntities.ts:528


getRockPNGPath

getRockPNGPath(): string

Helper function to get the PNG path for a rock. This depends on the current room's backdrop. The values are taken from the "backdrops.xml" file.

All of the rock PNGs are in the "gfx/grid" directory.

Returns

string

Defined in

packages/isaacscript-common/src/functions/gridEntities.ts:544


getSurroundingGridEntities

getSurroundingGridEntities(gridEntity): readonly GridEntity[]

Helper function to get the grid entities on the surrounding tiles from the provided grid entity.

For example, if a rock was surrounded by rocks on all sides, this would return an array of 8 rocks (e.g. top-left + top + top-right + left + right + bottom-left + bottom + right).

Parameters

NameType
gridEntityGridEntity

Returns

readonly GridEntity[]

Defined in

packages/isaacscript-common/src/functions/gridEntities.ts:699


getSurroundingGridIndexes

getSurroundingGridIndexes(gridIndex): [topLeft: int, top: int, topRight: int, left: int, right: int, bottomLeft: int, bottom: int, bottomRight: int]

Helper function to get the grid indexes on the surrounding tiles from the provided grid index.

There are always 8 grid indexes returned (e.g. top-left + top + top-right + left + right + bottom-left + bottom + right), even if the computed values would be negative or otherwise invalid.

Parameters

NameType
gridIndexint

Returns

[topLeft: int, top: int, topRight: int, left: int, right: int, bottomLeft: int, bottom: int, bottomRight: int]

Defined in

packages/isaacscript-common/src/functions/gridEntities.ts:725


getTopLeftWall

getTopLeftWall(): GridEntity | undefined

Helper function to get the top left wall in the current room.

This function can be useful in certain situations to determine if the room is currently loaded.

Returns

GridEntity | undefined

Defined in

packages/isaacscript-common/src/functions/gridEntities.ts:759


getTopLeftWallGridIndex

getTopLeftWallGridIndex(): int

Helper function to get the grid index of the top left wall. (This will depend on what the current room shape is.)

This function can be useful in certain situations to determine if the room is currently loaded.

Returns

int

Defined in

packages/isaacscript-common/src/functions/gridEntities.ts:771


isGridEntityBreakableByExplosion

isGridEntityBreakableByExplosion(gridEntity): boolean

Helper function to detect if a particular grid entity would "break" if it was touched by an explosion.

For example, rocks and pots are breakable by explosions, but blocks are not.

Parameters

NameType
gridEntityGridEntity

Returns

boolean

Defined in

packages/isaacscript-common/src/functions/gridEntities.ts:786


isGridEntityBroken

isGridEntityBroken(gridEntity): boolean

Helper function to see if the provided grid entity is in its respective broken state. See the GRID_ENTITY_TYPE_TO_BROKEN_STATE_MAP constant for more details.

Note that in the case of GridEntityType.LOCK (11), the state will turn to being broken before the actual collision for the entity is removed.

Parameters

NameType
gridEntityGridEntity

Returns

boolean

Defined in

packages/isaacscript-common/src/functions/gridEntities.ts:808


isGridEntityXMLType

isGridEntityXMLType(num): num is GridEntityXMLType

Helper function to see if an arbitrary number is a valid GridEntityXMLType. This is useful in the PRE_ROOM_ENTITY_SPAWN callback for narrowing the type of the first argument.

Parameters

NameType
numnumber

Returns

num is GridEntityXMLType

Defined in

packages/isaacscript-common/src/functions/gridEntities.ts:818


isGridIndexAdjacentToDoor

isGridIndexAdjacentToDoor(gridIndex): boolean

Helper function to check if the provided grid index has a door on it or if the surrounding 8 grid indexes have a door on it.

Parameters

NameType
gridIndexint

Returns

boolean

Defined in

packages/isaacscript-common/src/functions/gridEntities.ts:826


isPoopGridEntityXMLType

isPoopGridEntityXMLType(gridEntityXMLType): boolean

Helper function to see if a GridEntityXMLType is some kind of poop.

Parameters

NameType
gridEntityXMLTypeGridEntityXMLType

Returns

boolean

Defined in

packages/isaacscript-common/src/functions/gridEntities.ts:845


isPostBossVoidPortal

isPostBossVoidPortal(gridEntity): boolean

Helper function to detect whether a given Void Portal is one that randomly spawns after a boss is defeated or is one that naturally spawns in the room after Hush.

Under the hood, this is determined by looking at the VarData of the entity:

  • The VarData of Void Portals that are spawned after bosses will be equal to 1.
  • The VarData of the Void Portal in the room after Hush is equal to 0.

Parameters

NameType
gridEntityGridEntity

Returns

boolean

Defined in

packages/isaacscript-common/src/functions/gridEntities.ts:859


removeAllGridEntitiesExcept

removeAllGridEntitiesExcept(...gridEntityTypes): readonly GridEntity[]

Helper function to all grid entities in the room except for ones matching the grid entity types provided.

Note that this function will automatically update the room. (This means that you can spawn new grid entities on the same tile on the same frame, if needed.)

For example:

removeAllGridEntitiesExcept(
GridEntityType.WALL,
GridEntityType.DOOR,
);

Parameters

NameType
...gridEntityTypesreadonly GridEntityType[]

Returns

readonly GridEntity[]

The grid entities that were removed.

Defined in

packages/isaacscript-common/src/functions/gridEntities.ts:887


removeAllMatchingGridEntities

removeAllMatchingGridEntities(...gridEntityType): readonly GridEntity[]

Helper function to remove all of the grid entities in the room that match the grid entity types provided.

Note that this function will automatically update the room. (This means that you can spawn new grid entities on the same tile on the same frame, if needed.)

For example:

removeAllMatchingGridEntities(
GridEntityType.ROCK,
GridEntityType.BLOCK,
GridEntityType.ROCK_TINTED,
);

Parameters

NameType
...gridEntityTypereadonly GridEntityType[]

Returns

readonly GridEntity[]

An array of the grid entities removed.

Defined in

packages/isaacscript-common/src/functions/gridEntities.ts:927


removeEntitiesSpawnedFromGridEntity

removeEntitiesSpawnedFromGridEntity(entities, gridEntity): void

Helper function to remove all entities that just spawned from a grid entity breaking. Specifically, this is any entities that overlap with the position of a grid entity and are on frame 0.

You must specify an array of entities to look through.

Parameters

NameType
entitiesreadonly Entity[]
gridEntityGridEntity

Returns

void

Defined in

packages/isaacscript-common/src/functions/gridEntities.ts:950


removeGridEntities

removeGridEntities<T>(gridEntities, updateRoom, cap?): readonly T[]

Helper function to remove all of the grid entities in the supplied array.

Type parameters

NameType
Textends AnyGridEntity

Parameters

NameTypeDescription
gridEntitiesreadonly T[]The array of grid entities to remove.
updateRoombooleanWhether to update the room after the grid entities are removed. This is generally a good idea because if the room is not updated, you will be unable to spawn another grid entity on the same tile until a frame has passed. However, doing this is expensive, since it involves a call to Isaac.GetRoomEntities, so set this to false if you need to run this function multiple times.
cap?intOptional. If specified, will only remove the given amount of entities.

Returns

readonly T[]

An array of the entities that were removed.

Defined in

packages/isaacscript-common/src/functions/gridEntities.ts:974


removeGridEntity

removeGridEntity(gridEntityOrGridIndex, updateRoom): void

Helper function to remove a grid entity by providing the grid entity object or the grid index inside of the room.

If removing a Devil Statue or an Angel Statue, this will also remove the associated effect (EffectVariant.DEVIL (6) or EffectVariant.ANGEL (9), respectively.)

Parameters

NameTypeDescription
gridEntityOrGridIndexint | GridEntityThe grid entity or grid index to remove.
updateRoombooleanWhether to update the room after the grid entity is removed. This is generally a good idea because if the room is not updated, you will be unable to spawn another grid entity on the same tile until a frame has passed. However, doing this is expensive, since it involves a call to Isaac.GetRoomEntities, so set this to false if you need to run this function multiple times.

Returns

void

Defined in

packages/isaacscript-common/src/functions/gridEntities.ts:1014


setGridEntityInvisible

setGridEntityInvisible(gridEntity): void

Helper function to make a grid entity invisible. This is accomplished by resetting the sprite.

Note that this function is destructive such that once you make a grid entity invisible, it can no longer become visible. (This is because the information about the sprite is lost when it is reset.)

Parameters

NameType
gridEntityGridEntity

Returns

void

Defined in

packages/isaacscript-common/src/functions/gridEntities.ts:1063


setGridEntityType

setGridEntityType(gridEntity, gridEntityType): void

Helper function to change the type of a grid entity to another type. Use this instead of the GridEntity.SetType method since that does not properly handle updating the sprite of the grid entity after the type is changed.

Setting the new type to GridEntityType.NULL (0) will have no effect.

Parameters

NameType
gridEntityGridEntity
gridEntityTypeGridEntityType

Returns

void

Defined in

packages/isaacscript-common/src/functions/gridEntities.ts:1075


spawnGiantPoop

spawnGiantPoop(topLeftGridIndex): boolean

Helper function to spawn a giant poop. This is performed by spawning each of the four quadrant grid entities in the appropriate positions.

Parameters

NameType
topLeftGridIndexint

Returns

boolean

Whether spawning the four quadrants was successful.

Defined in

packages/isaacscript-common/src/functions/gridEntities.ts:1105


spawnGridEntity

spawnGridEntity(gridEntityType, gridIndexOrPosition, removeExistingGridEntity?): GridEntity | undefined

Helper function to spawn a grid entity with a specific type.

This function assumes you want to give the grid entity a variant of 0. If you want to specify a variant, use the spawnGridEntityWithVariant helper function instead.

Use this instead of the Isaac.GridSpawn method since it:

  • handles giving pits collision
  • removes existing grid entities on the same tile, if any
  • allows you to specify either the grid index or the position

Parameters

NameTypeDefault valueDescription
gridEntityTypeGridEntityTypeundefinedThe GridEntityType to use.
gridIndexOrPositionint | VectorundefinedThe grid index or position in the room that you want to spawn the grid entity at. If a position is specified, the closest grid index will be used.
removeExistingGridEntitybooleantrueOptional. Whether to remove the existing grid entity on the same tile, if it exists. Defaults to true. If false, this function will do nothing, since spawning a grid entity on top of another grid entity will not replace it.

Returns

GridEntity | undefined

Defined in

packages/isaacscript-common/src/functions/gridEntities.ts:1183


spawnGridEntityWithVariant

spawnGridEntityWithVariant(gridEntityType, variant, gridIndexOrPosition, removeExistingGridEntity?): GridEntity | undefined

Helper function to spawn a grid entity with a specific variant.

Use this instead of the Isaac.GridSpawn method since it:

  • handles giving pits collision
  • removes existing grid entities on the same tile, if any
  • allows you to specify the grid index or the position

Parameters

NameTypeDefault valueDescription
gridEntityTypeGridEntityTypeundefinedThe GridEntityType to use.
variantintundefinedThe variant to use.
gridIndexOrPositionint | VectorundefinedThe grid index or position in the room that you want to spawn the grid entity at. If a position is specified, the closest grid index will be used.
removeExistingGridEntitybooleantrueOptional. Whether to remove the existing grid entity on the same tile, if it exists. Defaults to true. If false, this function will do nothing, since spawning a grid entity on top of another grid entity will not replace it.

Returns

GridEntity | undefined

Defined in

packages/isaacscript-common/src/functions/gridEntities.ts:1214


spawnVoidPortal

spawnVoidPortal(gridIndex): GridEntity | undefined

Helper function to spawn a Void Portal. This is more complicated than simply spawning a trapdoor with the appropriate variant, as the game does not give it the correct sprite automatically.

Parameters

NameType
gridIndexint

Returns

GridEntity | undefined

Defined in

packages/isaacscript-common/src/functions/gridEntities.ts:1273