Spleef

Let’s build a chat command that creates a Spleef arena.

Chat command

Add a chat command named "spleef".

def on_chat():
    pass
player.on_chat("spleef", on_chat)

Make a lava layer

Place a layer of lava in the ground between the player position of (0, -1, 0) and ten blocks away North and West (10, -1, 10).

def on_chat():
    # @highlight
    blocks.fill(LAVA, pos(0, -1, 0), pos(10, -1, 10))
player.on_chat("spleef", on_chat)

The fill action takes two locations in the world and fills that area with Lava. (0, -1, 0) means 0 blocks West, 1 block Down (-1 Up), 0 block North. (10, -1, 10) means 10 blocks West, 1 block Down (-1 up), 10 block North.

Make a snow layer

Place another layer of snow in the air between the player position (0, 4, 0) and ten blocks away North and West (10, 4 10).

def on_chat():
    blocks.fill(LAVA, pos(0, -1, 0), pos(10, -1, 10))
    # @highlight
    blocks.fill(SNOW, pos(0, 4, 0), pos(10, 4, 10))
player.on_chat("spleef", on_chat)

~0 ~4 ~0 means 0 blocks west, 4 block up, 0 block north. ~10 ~4 ~10 means 10 blocks west, 4 block up, 10 block north.

Try the command

Go to Minecraft, press t to open the chat and enter spleef.

GREIFING ALERT!!! This mod will grief your blocks. Ask your friends before griefing their worlds.

Add a parameter

Add a number parameter to the local on_chat() function by inserting num1 in between the ( ). This will create a new variable called num1. Replace the number 10 with the num1 variable.

# @highlight
def on_chat(num1):
    # @highlight
    blocks.fill(LAVA, pos(0, -1, 0), pos(num1, -1, num1))
    # @highlight
    blocks.fill(SNOW, pos(0, 4, 0), pos(num1, 4, num1))
player.on_chat("spleef", on_chat)

So far, the arena created is just 10x10… boring! By using the num1 variable instead, the user can select the size of every game.

Try the parameter

Got to Minecraft and enter spleef 25 in the chat.

Step 7

Teleport all players to a positon that is located at (num1 / 2, 5, num1 / 2).

def on_chat(num1):
    blocks.fill(LAVA, pos(0, -1, 0), pos(num1, -1, num1))
    blocks.fill(SNOW, pos(0, 4, 0), pos(num1, 4, num1))
    # @highlight
    mobs.teleport_to_position(mobs.target(ALL_PLAYERS), pos(num1 / 2, 5, num1 / 2))
player.on_chat("spleef", on_chat)

Set Survival Mode

Set the game mode to survival for all players.

def on_chat(num1):
    blocks.fill(LAVA, pos(0, -1, 0), pos(num1, -1, num1))
    blocks.fill(SNOW, pos(0, 4, 0), pos(num1, 4, num1))
    mobs.teleport_to_position(mobs.target(ALL_PLAYERS), pos(num1 / 2, 5, num1 / 2))
    # @highlight
    gameplay.set_game_mode(SURVIVAL, mobs.target(ALL_PLAYERS))
player.on_chat("spleef", on_chat)