Skip to content

Commit

Permalink
add core:tests_util module & add base_entities test
Browse files Browse the repository at this point in the history
  • Loading branch information
MihailRis committed Dec 29, 2024
1 parent c33a92a commit 4d1f44a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
24 changes: 24 additions & 0 deletions dev/tests/base_entities.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
local util = require("core:tests_util")

-- Create world and prepare settings
util.create_demo_world("core:default")
app.set_setting("chunks.load-distance", 3)
app.set_setting("chunks.load-speed", 1)

-- Create player
local pid = player.create("Xerxes")
player.set_spawnpoint(pid, 0, 100, 0)
player.set_pos(pid, 0, 100, 0)

-- Wait for chunk to load
app.sleep_until(function () return block.get(0, 0, 0) ~= -1 end)

-- Place a falling block
block.place(0, 2, 0, block.index("base:sand"), 0, pid)
app.tick()

-- Check if the block is falling
assert(block.get(0, 100, 0) == 0)

-- Wait for the block to fall
app.sleep_until(function () return block.get(0, 1, 0) == block.index("base:sand") end, 100)
6 changes: 3 additions & 3 deletions dev/tests/chunks.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
local util = require("core:tests_util")
util.create_demo_world()

app.set_setting("chunks.load-distance", 3)
app.set_setting("chunks.load-speed", 1)

app.reconfig_packs({"base"}, {})
app.new_world("demo", "2019", "core:default")

local pid1 = player.create("Xerxes")
assert(player.get_name(pid1) == "Xerxes")

Expand Down
8 changes: 8 additions & 0 deletions res/modules/tests_util.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
local util = {}

function util.create_demo_world(generator)
app.reconfig_packs({"base"}, {})
app.new_world("demo", "2019", generator or "core:default")
end

return util

0 comments on commit 4d1f44a

Please sign in to comment.