Aquarium

Introduction

Let’s build a nice, cozy aquarium for our marine friends!

Aquarium

Swing the trident

We’ll make it so our aquarium is built when we swing a TRIDENT! From the Toolbox, drag a ||player:run code on item used|| code snippet into the editor, or type the code below.

def on_item_interacted():
    pass
player.on_item_interacted(TRIDENT, on_item_interacted)

Build a glass block

Inside the on_item_interacted function, replace the pass placeholder with the ||blocks:blocks.fill|| function to create a giant block of GLASS_PANE as the structure for the aquarium.

def on_item_interacted():
    # @highlight
    blocks.fill(GLASS_PANE, pos(0, 0, 0), pos(0, 0, 0), FillOperation.REPLACE)
player.on_item_interacted(TRIDENT, on_item_interacted)

Set the coordinates

A size of 8 x 8 x 20 should hold enough fish. Change the from position to (5, 0, -10) and the to position to (12, 7, 10). We use 5 and 12 as the first coordinates, otherwise we’ll end up swimming with the fish!

def on_item_interacted():
    # @highlight
    blocks.fill(GLASS_PANE, pos(5, 0, -10), pos(12, 7, 10), FillOperation.REPLACE)
player.on_item_interacted(TRIDENT, on_item_interacted)

Fill with water

Next, let’s fill the aquarium with water. Add another ||blocks:blocks.fill|| function on the next line to fill in blocks of WATER. We only want to fill the inside of the aquarium, so set the from position to (6, 0, -9) and the to position to (11, 6, 9).

def on_item_interacted():
    blocks.fill(GLASS_PANE, pos(5, 0, -10), pos(12, 7, 10), FillOperation.REPLACE)
    # @highlight
    blocks.fill(WATER, pos(6, 0, -9), pos(11, 6, 9), FillOperation.REPLACE)
player.on_item_interacted(TRIDENT, on_item_interacted)

Add a loop

The aquarium is ready to be populated! We’ll want multiple fish and coral living inside it, so we’ll need a ||loops:for|| loop to create them all. Let’s create 4 of each type of creature.

def on_item_interacted():
    blocks.fill(GLASS_PANE, pos(5, 0, -10), pos(12, 7, 10), FillOperation.REPLACE)
    blocks.fill(WATER, pos(6, 0, -9), pos(11, 6, 9), FillOperation.REPLACE)
    # @highlight
    for i in range(4):
        pass
player.on_item_interacted(TRIDENT, on_item_interacted)

Spawn some fish

Inside the for loop, replace the pass placeholder with a ||mobs:mobs.spawn|| function and type TROPICAL_FISH as the mob to spawn.

def on_item_interacted():
    blocks.fill(GLASS_PANE, pos(5, 0, -10), pos(12, 7, 10), FillOperation.REPLACE)
    blocks.fill(WATER, pos(6, 0, -9), pos(11, 6, 9), FillOperation.REPLACE)
    for i in range(4):
        # @highlight
        mobs.spawn(TROPICAL_FISH, pos(0, 0, 0))
player.on_item_interacted(TRIDENT, on_item_interacted)

Set the spawn location

In the ||mobs(noclick):mobs.spawn|| parameter, use a random position function ||positions:randpos|| and set the from and to coordinates to the same as the water: (6, 0, -9) and (11, 6, 9).

def on_item_interacted():
    blocks.fill(GLASS_PANE, pos(5, 0, -10), pos(12, 7, 10), FillOperation.REPLACE)
    blocks.fill(WATER, pos(6, 0, -9), pos(11, 6, 9), FillOperation.REPLACE)
    for i in range(4):
        # @highlight
        mobs.spawn(TROPICAL_FISH, randpos(pos(6, 0, -9), pos(11, 6, 9)))
player.on_item_interacted(TRIDENT, on_item_interacted)

Decorate the aquarium!

Time to decorate! After ||mobs(noclick):mobs.spawn|| line of code, use ||blocks:blocks.place|| with some coral or other sea plants. Set the same random position coordinates as before.

def on_item_interacted():
    blocks.fill(GLASS_PANE, pos(5, 0, -10), pos(12, 7, 10), FillOperation.REPLACE)
    blocks.fill(WATER, pos(6, 0, -9), pos(11, 6, 9), FillOperation.REPLACE)
    for i in range(4):
        mobs.spawn(TROPICAL_FISH, randpos(pos(6, 0, -9), pos(11, 6, 9)))
        # @highlight
        blocks.place(BUBBLE_CORAL, randpos(pos(6, 0, -9), pos(11, 0, 9)))
player.on_item_interacted(TRIDENT, on_item_interacted)

Add more aquatic life

Bring your aquarium to life by adding more fish and coral inside the for loop! To speed up the process, copy and paste the code for placing coral and spawning fish. When you’re done, press the green Play button and swing a trident to see your aquarium take shape!

def on_item_interacted():
    blocks.fill(GLASS_PANE, pos(5, 0, -10), pos(12, 7, 10), FillOperation.REPLACE)
    blocks.fill(WATER, pos(6, 0, -9), pos(11, 6, 9), FillOperation.REPLACE)
    for i in range(4):
        mobs.spawn(TROPICAL_FISH, randpos(pos(6, 0, -9), pos(11, 6, 9)))
        blocks.place(BUBBLE_CORAL, randpos(pos(6, 0, -9), pos(11, 0, 9)))
        mobs.spawn(PUFFERFISH, randpos(pos(6, 0, -9), pos(11, 6, 9)))
        mobs.spawn(DOLPHIN, randpos(pos(6, 0, -9), pos(11, 6, 9)))
        blocks.place(SEAGRASS, randpos(pos(6, 0, -9), pos(11, 0, 9)))
player.on_item_interacted(TRIDENT, on_item_interacted)