Hedgehogs snuffle about the hill, and come trotting after anyone holding carrots. Their body is a Blockbench model: open hedgehog.bbmodel in Blockbench to change it.
| 1 | --!strict |
| 2 | -- The hedgehog's own tests: `potluck-server --test=hedgehog`, or the dev |
| 3 | -- bridge's test tool. |
| 4 | |
| 5 | local test = require("@potluck/test@0.2") |
| 6 | local world = require("@potluck/world@0.11") |
| 7 | |
| 8 | local function hedgehogs(): { any } |
| 9 | local all = {} |
| 10 | for _, id in world.creatures(test.kind("Hedgehog")) do |
| 11 | table.insert(all, test.creature(id)) |
| 12 | end |
| 13 | return all |
| 14 | end |
| 15 | |
| 16 | local function far(a: vector, b: vector): number |
| 17 | return vector.magnitude(vector.create(a.x - b.x, 0, a.z - b.z)) |
| 18 | end |
| 19 | |
| 20 | test.case("its body comes from the Blockbench model", function() |
| 21 | local body = world.model("hedgehog.bbmodel") |
| 22 | test.same(#body, 15, "cubes") |
| 23 | local by: { [string]: any } = {} |
| 24 | for _, part in body do |
| 25 | by[part[1]] = part |
| 26 | end |
| 27 | test.check(by.face.head and by.nose.head and by.eye_left.head, "the head group's cubes turn with the head") |
| 28 | test.check(by.leg_front_left.leg and not by.face.leg, "the legs group's cubes walk") |
| 29 | test.same(by.nose.color, "#1d1916", "the nose's color, from the texture") |
| 30 | -- 16 pixels to a block: the snout is 2 wide, 1.5 high, 2 deep |
| 31 | test.check(math.abs(by.snout.size.x - 0.125) < 0.001 and math.abs(by.snout.size.z - 0.125) < 0.001, "the snout's size") |
| 32 | test.check(by.snout.at.z < by.spines.at.z, "it faces negative z") |
| 33 | test.same(#hedgehogs(), 3, "hedgehogs") |
| 34 | end) |
| 35 | |
| 36 | test.case("holding carrots, they come trotting", function() |
| 37 | local p = test.player("Ada") |
| 38 | local h = hedgehogs()[1] |
| 39 | local x, z = h.position.x + 7, h.position.z |
| 40 | test.move(p, vector.create(x, world.top(x, z) + 1, z)) |
| 41 | test.hold(p, "Carrots") |
| 42 | test.wait(8) |
| 43 | test.check(far(test.creature(h.id).position, p.position) < 3.5, "it came for the carrots") |
| 44 | end) |
| 45 | |
| 46 | test.case("bopped, one snuffles and runs off", function() |
| 47 | local p = test.player("Ada") |
| 48 | local h = hedgehogs()[1] |
| 49 | test.move(p, h.position + vector.create(1.5, 0, 0)) |
| 50 | test.hit(p, h) |
| 51 | test.wait(4) |
| 52 | test.check(test.heard("snuffle") >= 1, "it snuffled") |
| 53 | test.check(far(test.creature(h.id).position, p.position) > 4, "it ran off") |
| 54 | end) |