Leaping Salmon

Introduction

Look out, salmon are leaping dangerously high! We must create ponds for them to land in!

Leaping Salmon

Swing the trident

Add an event to run code when the player swings a trident. From the Toolbox, drag a ||player:run code on item used|| code snippet into the editor and change the item to TRIDENT, or type the code below.

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

Add a loop

We want multiple salmon to leap each time we swing the Trident. In the on_item_interacted function, replace the pass placeholder by typing a ||loops:for|| loop or dragging a code snippet from the Toolbox, and set the range to 6.

def on_item_interacted():
    # @highlight
    for i in range(6):
        pass
player.on_item_interacted(TRIDENT, on_item_interacted)

Spawn some salmon

Now it’s time to spawn the salmon! Inside the the ||loops:for|| loop, replace the pass placeholder by adding a ||mobs:mobs.spawn|| line of code to spawn a SALMON at the player’s current position.

def on_item_interacted():
    for i in range(6):
        # @highlight
        mobs.spawn(SALMON, pos(0, 0, 0))
player.on_item_interacted(TRIDENT, on_item_interacted)

Set random spawn locations

We’ll make it so the salmon spawn at random locations so it’s harder to catch them! In ||mobs(noclick):mobs.spawn||, use the ||positions:randpos|| function and set the from coordinate to (-6, 60, -6) and the to coordinate to (6, 60, 6). That’ll make them spawn high in the sky!

def on_item_interacted():
    for i in range(6):
        # @highlight
        mobs.spawn(SALMON, randpos(pos(-6, 60, -6), pos(6, 60, 6)))
player.on_item_interacted(TRIDENT, on_item_interacted)

Use some kelp

We’ve just made it so the salmon leap extremely high! We should create a pond to catch them so they don’t get injured when they land. From the Toolbox, drag another ||player:run code on item used|| code snippet into the editor at the bottom of your program and change the item to KELP.

def on_item_interacted():
    for i in range(6):
        mobs.spawn(SALMON, randpos(pos(-6, 60, -6), pos(6, 60, 6)))
player.on_item_interacted(TRIDENT, on_item_interacted)
# @highlight
def on_item_interacted2():
    # @highlight
    pass
# @highlight
player.on_item_interacted(KELP, on_item_interacted2)

Make a water pond

In the on_item_interacted2 function, replace the pass placeholder by adding a ||blocks:blocks.fill|| command using WATER.

def on_item_interacted2():
    # @highlight
    blocks.fill(WATER, pos(0, 0, 0), pos(0, 0, 0), FillOperation.REPLACE)
player.on_item_interacted(KELP, on_item_interacted2)

Set the pond size

Finally, we must change the size of our pond so the fish can land right into it. In ||blocks:blocks.fill||, set the from position to (-2, -1, -2) and the to position to (2, -1, 2). This creates a 5 x 5 shallow pool of water around the player.

def on_item_interacted2():
    # @highlight
    blocks.fill(WATER, pos(-2, -1, -2), pos(2, -1, 2), FillOperation.REPLACE)
player.on_item_interacted(KELP, on_item_interacted2)

Run your code!

You’re all done! Press the green Play button to run your code, then use a Trident and Kelp to make salmon leap high in the sky and create a pond to catch them!