• Docs >
  • Spawn Agents in The Nether and The End
Shortcuts

Spawn Agents in The Nether and The End

The Nether and The End are two dimensions in Minecraft, orthogonal to Overworld. We cannot directly spawn agents inside them like what we did to spawn agents in other biomes. We go through some “preprocessing” to fix this issue. We provide two examples below to demonstrate how we manage to spawn agents inside The Nether and The End.

Spawn Agents in The Nether

The idea is to first spawn a Nether Portal frame around the agent, then light up the portal, and finally enter the Nether.

The code block below creates a minimal example of an environment with a Nether Portal frame around the agent.

env = minedojo.make(
    "open-ended",
    image_size=image_size,
    drawing_str="""
    <DrawCuboid x1="-262" y1="86" z1="175" x2="-258" y2="86" z2="175" type="obsidian"/>
    <DrawCuboid x1="-262" y1="86" z1="175" x2="-262" y2="91" z2="175" type="obsidian"/>
    <DrawCuboid x1="-258" y1="86" z1="175" x2="-258" y2="91" z2="175" type="obsidian"/>
    <DrawCuboid x1="-262" y1="91" z1="175" x2="-258" y2="91" z2="175" type="obsidian"/>
    """,
    world_seed="Enter the Nether",
    initial_inventory=[
        InventoryItem(slot=0, name="flint_and_steel", variant=None, quantity=1)
    ],
    
)

Then we hard-code a trajectory such that the agent lights up the portal and enters it.

env.teleport_agent(-260, 86, 174, 0, 45)
for _ in range(3):
    env.step(env.action_space.no_op())
# use the flint and steel to light up the portal
action = env.action_space.no_op()
action[5] = 1
obs, reward, done, info = env.step(action)
# teleport inside the portal
env.teleport_agent(-260, 87, 175, 0, 0)
# wait several frames until the agent completely enters the Nether
while True:
    obs, reward, done, info = env.step(env.action_space.no_op())
    if info["biome_id"] == 8:
        break

Now the agent is inside The Nether and ready to explore!

Spawn Agents in The End

Spawning agents in The End is easier than spawning into The Nether. The idea is to set an end portal just above the agent. The agent will then be automatically absorbed into The End.

Let’s first create a minimal example of environment:

env = minedojo.make(
    "open-ended",
    image_size=image_size
)

Then we can spawn the agents inside The End through

# set an End portal just above the agent
env.execute_cmd("/setblock ~ ~1 ~ end_portal")
# wait several frames until the agent completely enters the End
while True:
    obs, reward, done, info = env.step(env.action_space.no_op())
    if info["biome_id"] == 9:
        break

Now the agent is inside The End and ready to explore!