Leaping Salmon

Introduction

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

Swing the trident

We’ll use a Trident to cause salmon to make giant leaps into the sky. Put in an on item used event. Set the item type to a trident.

def on_item_interacted_trident():
    pass
# @highlight
player.on_item_interacted(TRIDENT, on_item_interacted_trident)

Add a loop

We want multiple fish to spawn for each Trident use, so insert a for loop and set the repeat count to 6. This will spawn fish 6 times.

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

Spawn some salmon

Now it’s time to spawn the salmon. In the the for loop, spawn a salmon at the player’s current position.

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

Spawn random salmon

We’ll make it so the salmon spawn into a random location so that it’s harder to catch them. Replace the relative position in the spawn with a random position. The random position uses a range of two relative positions, from and to. Set the from position to (-6, 60, -6) and the to positon to (6, 60, 6). That’ll make them spawn high in the sky!

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

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.

Use another on item used event to run code when kelp is used.

# @highlight
def item_interacted_kelp():
    # @highlight
    pass
# @highlight
player.on_item_interacted(KELP, item_interacted_kelp)

Make a water pond

In the kelp event, fill in water. Set both the from and to positions for the fill to (0, 0, 0). The falling fish need water to fall into.

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

Enlarge the pond

Finally, we must change the size of our pond so the fish can land right into it. For the water, 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 item_interacted_kelp():
    # @highlight
    blocks.fill(WATER, pos(-2, -1, -2), pos(2, -1, 2))
player.on_item_interacted(KELP, item_interacted_kelp)

Run your program!

You’re all done! Go in-game and add a Trident and some Kelp to your equipment. Use the Trident to make salmon leap high in the sky. Then, quickly equip the Kelp and use it to create a pond underneath the fish so they can land safely. You’ll have to react quickly!