Aquarium
Introduction
Let’s build a nice, cozy aquarium for our marine friends!
Swing the trident
We’ll make it so our aquarium is built when we swing a Trident!.
def item_interacted_trident():
pass
player.on_item_interacted(TRIDENT, item_interacted_trident)
Build a glass layer
When the Trident swings, fill in a glass pane block to build the glass structure of the aquarium.
def item_interacted_trident():
# @highlight
blocks.fill(GLASS_PANE,
pos(0, 0, 0),
pos(0, 0, 0),
FillOperation.REPLACE)
player.on_item_interacted(TRIDENT, item_interacted_trident)
Enlarge the aquarium
A size of 8 x 8 x 20 should hold enough specimens. Change the from position to (5, 0, -10)
and the to position to (12, 7, 10)
in for the fill. We use 5 and 12 as the first coordinates, otherwise we’ll end up swimming with the fish!
def item_interacted_trident():
# @highlight
blocks.fill(GLASS_PANE,
pos(5, 0, -10),
pos(12, 7, 10),
FillOperation.REPLACE)
player.on_item_interacted(TRIDENT, item_interacted_trident)
Fill with water
Next, fill water into the aquarium. Add to your code 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 item_interacted_trident():
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, item_interacted_trident)
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 for loop to create them all. Add one to your code. Set the loop range count to
4
.
def item_interacted_trident():
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, item_interacted_trident)
Spawn some fish
Let’s start with the fish. Spawn a mob inside the for loop, and change the animal type to your favorite fish.
def item_interacted_trident():
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(DOLPHIN, pos(0, 0, 0))
player.on_item_interacted(TRIDENT, item_interacted_trident)
Spawn random fish
We’ll now make the fish spawn randomly inside the aquarium. Use a random position with the spawn for the fish. Change the from and to positions of the random range to the same volume as the water: (6, 0, -9)
and (11, 6, 9)
.
def item_interacted_trident():
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(DOLPHIN,
randpos(pos(6, 0, -9), pos(11, 6, 9)))
player.on_item_interacted(TRIDENT, item_interacted_trident)
Decorate the aquarium!
Time to decorate! Inside the for loop, fill in blocks of your favorite type of coral. Use another random position for the coral. Set the positions to (6, 0, -9)
and (11, 0, 9)
so the coral spawns on the floor.
def item_interacted_trident():
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(DOLPHIN,
randpos(pos(6, 0, -9), pos(11, 6, 9)))
# @highlight
blocks.place(BUBBLE_CORAL_FAN,
randpos(pos(6, 0, -9), pos(11, 0, 9)))
player.on_item_interacted(TRIDENT, item_interacted_trident)
Add more sea life
Bring your aquarium to life by adding more fish and coral in the for loop! To speed up the process, copy the code for filling coral and spawning fish. Duplicate it several times in the for loop to add more life! When you’re done, go in-game and use a trident to see your aquarium take shape!
def item_interacted_trident():
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(DOLPHIN,
randpos(pos(6, 0, -9), pos(11, 6, 9)))
# @highlight
mobs.spawn(PUFFERFISH,
randpos(pos(6, 0, -9), pos(11, 6, 9)))
mobs.spawn(SALMON,
randpos(pos(6, 0, -9), pos(11, 6, 9)))
mobs.spawn(TROPICAL_FISH,
randpos(pos(6, 0, -9), pos(11, 6, 9)))
mobs.spawn(COD,
randpos(pos(6, 0, -9), pos(11, 6, 9)))
blocks.place(BUBBLE_CORAL_FAN,
randpos(pos(6, 0, -9), pos(11, 0, 9)))
# @highlight
blocks.place(SEAGRASS,
randpos(pos(6, 0, -9), pos(11, 0, 9)))
blocks.place(KELP,
randpos(pos(6, 0, -9), pos(11, 0, 9)))
blocks.place(HORN_CORAL,
randpos(pos(6, 0, -9), pos(11, 0, 9)))
blocks.place(TUBE_CORAL,
randpos(pos(6, 0, -9), pos(11, 0, 9)))
player.on_item_interacted(TRIDENT, item_interacted_trident)