On a Normal or Hard world, a player hurt too badly in survival drops everything they carry in a pack where they fell: go back and use the pack to take it all back (anyone can, so be quick). On Peaceful and Gentle worlds you keep what you carry. What you wear stays on.
| 1 | --!strict |
| 2 | local test = require("@potluck/test@0.7") |
| 3 | local world = require("@potluck/world@0.21") |
| 4 | |
| 5 | local CARRY = { Cobblestone = 10, Planks = 3 } |
| 6 | |
| 7 | test.case("on a Gentle world you keep what you carry", function() |
| 8 | local p = test.player("Ada", { survival = true, carrying = CARRY }) |
| 9 | world.hurt(p, 20) |
| 10 | test.wait(0.5) |
| 11 | test.same(world.has(p, "Cobblestone"), 10, "still carried") |
| 12 | test.same(world.find_block(p.position, 4, "Lost pack"), nil, "no pack") |
| 13 | end) |
| 14 | |
| 15 | test.case("on a Normal world what you carried waits in a pack where you fell", function() |
| 16 | test.danger("normal") |
| 17 | local p = test.player("Ada", { survival = true, carrying = CARRY }) |
| 18 | world.hurt(p, 20) |
| 19 | test.wait(0.5) |
| 20 | test.same(world.has(p, "Cobblestone"), 0, "dropped") |
| 21 | local pack = world.find_block(p.position, 4, "Lost pack") |
| 22 | test.check(pack ~= nil, "a pack where they fell") |
| 23 | test.use_block(p, pack :: vector) |
| 24 | test.same(world.has(p, "Cobblestone"), 10, "the stone back") |
| 25 | test.same(world.has(p, "Planks"), 3, "the planks back") |
| 26 | test.same(world.block(pack :: vector), "Air", "the pack's gone") |
| 27 | end) |
| 28 | |
| 29 | test.case("anyone can open a pack, but not from creative", function() |
| 30 | test.danger("hard") |
| 31 | local p = test.player("Ada", { survival = true, carrying = CARRY }) |
| 32 | world.hurt(p, 20) |
| 33 | test.wait(0.5) |
| 34 | local pack = world.find_block(p.position, 4, "Lost pack") :: vector |
| 35 | test.check(pack ~= nil, "a pack") |
| 36 | local c = test.player("Cy") |
| 37 | test.dig(c, pack) |
| 38 | test.same(world.block(pack), "Lost pack", "still there after a creative player broke it") |
| 39 | local b = test.player("Bo", { survival = true }) |
| 40 | test.dig(b, pack) |
| 41 | test.same(world.has(b, "Cobblestone"), 10, "Bo has the stone") |
| 42 | test.same(world.block(pack), "Air", "and the pack's gone") |
| 43 | end) |
| 44 | |
| 45 | test.case("Peaceful keeps what you carry too", function() |
| 46 | test.danger("peaceful") |
| 47 | local p = test.player("Ada", { survival = true, carrying = CARRY }) |
| 48 | world.hurt(p, 20) |
| 49 | test.wait(0.5) |
| 50 | test.same(world.has(p, "Planks"), 3, "kept") |
| 51 | end) |