diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
new file mode 100644
index 00000000..b2431553
--- /dev/null
+++ b/.github/workflows/test.yml
@@ -0,0 +1,19 @@
+name: test
+on: [push, pull_request]
+jobs:
+ test:
+ timeout-minutes: 3
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v2
+ - uses: buckaroobanzay/mtt@main
+ with:
+ test_mode: game
+ enable_coverage: "true"
+ mapgen: v7
+ additional_config: secure.trusted_mods = mtt, libox
+ - name: Coveralls
+ uses: coverallsapp/github-action@v1
+ with:
+ debug: true
+ base-path: ~
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 00000000..22f348a1
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+coverage/*
\ No newline at end of file
diff --git a/README.md b/README.md
index f214d13b..b319f644 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,4 @@
+[![Coverage Status](https://coveralls.io/repos/github/TheEt1234/skyblock_zero/badge.svg?branch=master)](https://coveralls.io/github/TheEt1234/skyblock_zero?branch=master)
# Skyblock: Zero
Start from absolutely nothing in a skyblock world. Time is your resource. Get lost in the ambiance. Space is your canvas.
diff --git a/local_test.sh b/local_test.sh
new file mode 100755
index 00000000..3937bcc5
--- /dev/null
+++ b/local_test.sh
@@ -0,0 +1,6 @@
+docker run --rm -it -v $(pwd):/github/workspace \
+ -e INPUT_TEST_MODE=game \
+ -e INPUT_MAPGEN=v7 \
+ -e INPUT_ENABLE_COVERAGE=true \
+ -e INPUT_ADDITIONAL_CONFIG="secure.trusted_mods=mtt,libox"\
+ ghcr.io/buckaroobanzay/mtt
\ No newline at end of file
diff --git a/mods/libox/env.lua b/mods/libox/env.lua
index 94eb20c4..cd381de4 100644
--- a/mods/libox/env.lua
+++ b/mods/libox/env.lua
@@ -1,8 +1,5 @@
local BYTECODE_CHAR = 27
-
-
-
local function wrap(f, obj)
return function(...)
return f(obj, ...)
diff --git a/mods/libox/main.lua b/mods/libox/main.lua
index 4d630cae..55973730 100644
--- a/mods/libox/main.lua
+++ b/mods/libox/main.lua
@@ -2,10 +2,10 @@ libox = {
safe = {},
supply_additional_environment = function(...) return ... end, -- for other mods to do their stuff
default_hook_time = 20,
- disabled = false
+ disabled = false,
+ in_sandbox = false,
}
-
local MP = minetest.get_modpath("libox")
dofile(MP .. "/env.lua")
dofile(MP .. "/utils.lua")
diff --git a/mods/libox/normal.lua b/mods/libox/normal.lua
index d6b46863..88b5e550 100644
--- a/mods/libox/normal.lua
+++ b/mods/libox/normal.lua
@@ -12,8 +12,6 @@ function libox.normal_sandbox(def)
local in_hook = def.in_hook or libox.get_default_hook(def.max_time)
local function_wrap = def.function_wrap or function(f) return f end
-
-
if code:byte(1) == BYTECODE_CHAR then
return false, "Bytecode is not allowed." -- mod security prevents it anyway, just making sure
end
@@ -33,9 +31,13 @@ function libox.normal_sandbox(def)
debug.sethook(in_hook, "", def.hook_time or libox.default_hook_time)
getmetatable("").__index = env.string
- local ok, ret = xpcall(f, error_handler)
+ local ok, ret = xpcall(f, function(...)
+ debug.sethook() -- fix a potential bug where someone can trigger a debug hook at just the right time for luanti to crash
+ return error_handler(...)
+ end)
debug.sethook(unpack(old_hook))
+
getmetatable("").__index = string
if not ok then
return false, ret
diff --git a/mods/libox/utils.lua b/mods/libox/utils.lua
index 1cf8d8d7..929c5d30 100644
--- a/mods/libox/utils.lua
+++ b/mods/libox/utils.lua
@@ -5,8 +5,8 @@ function libox.get_default_hook(max_time)
return function()
if time() - start_time > max_time then
debug.sethook()
- error(
- "Code timed out! Reason: Time limit exceeded, the limit:" ..
+
+ error("Code timed out! Reason: Time limit exceeded, the limit:" ..
tostring(max_time / 1000) .. "ms, the program took:" .. ((time() - start_time) / 1000), 2)
end
end
diff --git a/mods/sbz_logic/help_pages/Lua Builder.txt b/mods/sbz_logic/help_pages/Lua Builder.txt
index 172a8590..a7047ddc 100644
--- a/mods/sbz_logic/help_pages/Lua Builder.txt
+++ b/mods/sbz_logic/help_pages/Lua Builder.txt
@@ -38,3 +38,19 @@ $C1 type = "use",
$C1 pos = {x = 0, y = 1, z = 0}, -- needs to be a vector, that is relative to THE BUILDER
$C1 item = "sbz_resources:robotic_arm" -- needs to be an item that is inside the builder's inventory
})
+
+Seeing
+So, if you want to see inside, for example, a container, you can yea, do this: (warning: can be an absurd amount of data if there are data disks in there)
+send_to(links.builder,{
+$C1 type = "see",
+$C1 pos = {x = 0, y = 1, z = 0}, -- needs to be a vector, that is relative to THE BUILDER
+})
+
+The event that you receive will look something like this:
+
+$C1... = {
+$C1 node = { name = "any node name", param2 = 0-255, param1 = 0-255 },
+$C1 fields = { --[[ node meta fields as described in minetest documentation, this one may hold insane amounts of data, be aware ]] },
+$C1 inventory = {some_epic_list = { stack_in_table_form1, stack_in_table_form2, ... }}
+$C1}
+
\ No newline at end of file
diff --git a/mods/sbz_logic_devices/builder.lua b/mods/sbz_logic_devices/builder.lua
index 26a5a5c4..6064c9fe 100644
--- a/mods/sbz_logic_devices/builder.lua
+++ b/mods/sbz_logic_devices/builder.lua
@@ -108,7 +108,7 @@ end
-local function use(pos, owner, def_item, inv, index)
+local function use(pos, owner, item_def, inv, index)
if not item_def.on_use then return end
local player = fakelib.create_player {
name = owner,
@@ -132,6 +132,19 @@ local function use(pos, owner, def_item, inv, index)
dont_wear_out(stack, old_stack, player.def_item)
end
+local function see(pos, lc_from_pos, builder_from_pos)
+ local result = {}
+ local node = sbz_api.get_node_force(pos)
+ result.node = node
+
+ local meta = minetest.get_meta(pos):to_table()
+
+ result.fields = meta.fields
+ result.inventory = sbz_logic.kill_itemstacks(meta.inventory)
+
+ sbz_logic.send(lc_from_pos, result, builder_from_pos)
+end
+
sbz_api.register_machine("sbz_logic_devices:builder", {
description = "Lua Builder",
info_extra = {
@@ -183,37 +196,42 @@ listring[]
local ok = libox.type_check(e, {
type = libox.type("string"),
pos = libox.type_vector,
- item = libox.type("string"),
- param2 = function(x) return x == nil and true or libox.type("number")(x) end
+ item = function(x) return x == nil or libox.type("string")(x) end,
+ param2 = function(x) return x == nil and true or libox.type("number")(x) end,
+ from_pos = libox.type_vector
})
if not ok then return end -- ha see, continue statement, lua has continue statements...!!!!
-
+ e.item = e.item or ""
local item = ItemStack(e.item)
-- prepare for comparing
item:set_count(1)
item:set_wear(1)
local index = get_index(inv, item)
- if not index then return end
+ if not index and e.type ~= "see" then return end
local abs_pos = vector.add(e.pos, pos)
if not sbz_api.logic.in_square_radius(pos, abs_pos, range) then return end
if minetest.is_protected(abs_pos, owner) then return end
- local node_at_pos = sbz_api.get_node_force(abs_pos)
- if node_at_pos == nil then return end
- local def_node = ndef[node_at_pos.name]
- if def_node == nil then return end
-
- local def_item = idef[item:get_name()]
- if def_item == nil then return end
-
- if e.type == "build" then
- build(abs_pos, owner, item_def, e.param2, inv, index)
- elseif e.type == "dig" then
- dig(abs_pos, owner, def_node, def_item, inv, index, node_at_pos)
- elseif e.type == "punch" then
- punch(abs_pos, owner, def_node, inv, index, node_at_pos)
- elseif e.type == "use" then
- use(abs_pos, owner, def_item, inv, index)
+ if e.type ~= "see" then
+ local node_at_pos = sbz_api.get_node_force(abs_pos)
+ if node_at_pos == nil then return end
+ local def_node = ndef[node_at_pos.name]
+ if def_node == nil then return end
+
+ local def_item = idef[item:get_name()]
+ if def_item == nil then return end
+
+ if e.type == "build" then
+ build(abs_pos, owner, def_item, e.param2, inv, index)
+ elseif e.type == "dig" then
+ dig(abs_pos, owner, def_node, def_item, inv, index, node_at_pos)
+ elseif e.type == "punch" then
+ punch(abs_pos, owner, def_node, inv, index, node_at_pos)
+ elseif e.type == "use" then
+ use(abs_pos, owner, def_item, inv, index)
+ end
+ else
+ see(abs_pos, e.from_pos, pos)
end
end
for i = 1, queue_can_handle do
@@ -230,6 +248,7 @@ listring[]
local meta = minetest.get_meta(pos)
local queued_events = minetest.deserialize(meta:get_string("queued_events")) or {}
queued_events[#queued_events + 1] = msg
+ msg.from_pos = from_pos
meta:set_string("queued_events", minetest.serialize(queued_events))
end
})