Skip to content

Commit

Permalink
Merge pull request #61 from TheEt1234/master
Browse files Browse the repository at this point in the history
Add "see" command to lua builder and fix 2 bugs
  • Loading branch information
ChefZander authored Oct 19, 2024
2 parents 37fc521 + 1c2b099 commit e81c002
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 31 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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: ~
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
coverage/*
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.<br>

Expand Down
6 changes: 6 additions & 0 deletions local_test.sh
Original file line number Diff line number Diff line change
@@ -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
3 changes: 0 additions & 3 deletions mods/libox/env.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
local BYTECODE_CHAR = 27




local function wrap(f, obj)
return function(...)
return f(obj, ...)
Expand Down
4 changes: 2 additions & 2 deletions mods/libox/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 5 additions & 3 deletions mods/libox/normal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions mods/libox/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions mods/sbz_logic/help_pages/Lua Builder.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
})</mono>

<big>Seeing</big>
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)
<mono>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
})</mono>

The event that you receive will look something like this:
<mono>
$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}
</mono>
61 changes: 40 additions & 21 deletions mods/sbz_logic_devices/builder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 = {
Expand Down Expand Up @@ -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
Expand All @@ -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
})

0 comments on commit e81c002

Please sign in to comment.