Aquarium
Introduction
Let’s build a nice, cozy aquarium for our marine friends!
Step 1
We’ll make it so our aquarium is built when we swing a Trident! Add ||player:on item used||
to your code and set the item type to Trident.
player.onItemInteracted(TRIDENT, function () {
})
Step 2
Add a ||blocks:fill||
to your code to build the glass structure.
player.onItemInteracted(TRIDENT, function () {
blocks.fill(
GLASS,
pos(0, 0, 0),
pos(0, 0, 0),
FillOperation.Replace
)
})
Step 3
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 your ||blocks:fill||
. We use 5 and 12 as the first coordinates, otherwise we’ll end up swimming with the fish!
player.onItemInteracted(TRIDENT, function () {
blocks.fill(
GLASS,
pos(5, 0, -10),
pos(12, 7, 10),
FillOperation.Replace
)
})
Step 4
Next, we’ll use a ||blocks:fill||
for the water. Add one to your code and set the block type to Water. We only want to fill the inside of the aquarium, so set the from position to ~6 ~1 ~-9 and the to position to ~11 ~6 ~9.
player.onItemInteracted(TRIDENT, function () {
blocks.fill(
GLASS,
pos(5, 0, -10),
pos(12, 7, 10),
FillOperation.Replace
)
blocks.fill(
WATER,
pos(6, 1, -9),
pos(11, 6, 9),
FillOperation.Replace
)
})
Step 5
The aquarium is ready to be populated! We’ll want multiple fish and coral living inside it, so we’ll need a ||loops:repeat||
loop to create them all. Add one to your code.
player.onItemInteracted(TRIDENT, function () {
blocks.fill(
GLASS,
pos(5, 0, -10),
pos(12, 7, 10),
FillOperation.Replace
)
blocks.fill(
WATER,
pos(6, 1, -9),
pos(11, 6, 9),
FillOperation.Replace
)
for (let i = 0; i < 4; i++) {
}
})
Step 6
Let’s start with the fish. Put in a ||mobs:spawn||
inside the ||loops:repeat||
loop, and change the animal type to your favorite fish.
player.onItemInteracted(TRIDENT, function () {
blocks.fill(
GLASS,
pos(5, 0, -10),
pos(12, 7, 10),
FillOperation.Replace
)
blocks.fill(
WATER,
pos(6, 1, -9),
pos(11, 6, 9),
FillOperation.Replace
)
for (let i = 0; i < 4; i++) {
mobs.spawn(DOLPHIN, pos(0, 0, 0))
}
})
Step 7
We’ll now make the fish spawn randomly inside the aquarium. Set a ||positions:pick random position||
inside the ||mobs:spawn||
, and change the from and to positions to the same area as the water: ~6 ~1 ~-9 and ~11 ~6 ~9.
player.onItemInteracted(TRIDENT, function () {
blocks.fill(
GLASS,
pos(5, 0, -10),
pos(12, 7, 10),
FillOperation.Replace
)
blocks.fill(
WATER,
pos(6, 1, -9),
pos(11, 6, 9),
FillOperation.Replace
)
for (let i = 0; i < 4; i++) {
mobs.spawn(DOLPHIN, randpos(
pos(6, 1, -9),
pos(11, 6, 9)
))
}
})
Step 8
Time to decorate! Drag a ||blocks:place||
inside the ||loops:repeat||
loop and set the block type to your favorite coral. Drag a ||positions:pick random position||
inside it, and change the positions to ~6 ~1 ~-9 and ~11 ~0 ~9 so the coral spawns on the floor.
player.onItemInteracted(TRIDENT, function () {
blocks.fill(
GLASS,
pos(5, 0, -10),
pos(12, 7, 10),
FillOperation.Replace
)
blocks.fill(
WATER,
pos(6, 1, -9),
pos(11, 6, 9),
FillOperation.Replace
)
for (let i = 0; i < 4; i++) {
mobs.spawn(DOLPHIN, randpos(
pos(6, 1, -9),
pos(11, 6, 9)
))
blocks.place(BUBBLE_CORAL_FAN, randpos(
pos(6, 1, -9),
pos(11, 0, 9)
))
}
})
Step 9
Bring your aquarium to life by adding more fish and coral in the ||loops:repeat||
block! To speed up the process, copy ||blocks:place||
or ||mobs:spawn||
and insert. When you’re done, go in-game and use a trident to see your aquarium take shape!
player.onItemInteracted(TRIDENT, function () {
blocks.fill(
GLASS,
pos(5, 0, -10),
pos(12, 7, 10),
FillOperation.Replace
)
blocks.fill(
WATER,
pos(6, 1, -9),
pos(11, 6, 9),
FillOperation.Replace
)
for (let i = 0; i < 4; i++) {
mobs.spawn(DOLPHIN, randpos(
pos(6, 1, -9),
pos(11, 6, 9)
))
mobs.spawn(PUFFERFISH, randpos(
pos(6, 1, -9),
pos(11, 6, 9)
))
blocks.place(BUBBLE_CORAL_FAN, randpos(
pos(6, 1, -9),
pos(11, 0, 9)
))
blocks.place(SEAGRASS, randpos(
pos(6, 1, -9),
pos(11, 0, 9)
))
}
})