You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
2.3 KiB
69 lines
2.3 KiB
1 year ago
|
local minetest, vector, nodecore, include
|
||
|
= minetest, vector, nodecore, include
|
||
|
|
||
|
local search = include("search")
|
||
|
local contraption = include("contraption")
|
||
|
|
||
|
local mod_name = minetest.get_current_modname()
|
||
|
|
||
|
local i_stick = "nc_tree:stick"
|
||
|
local i_staff = "nc_tree:staff"
|
||
|
local i_frame = "nc_woodwork:frame"
|
||
|
local i_form = "nc_woodwork:form"
|
||
|
local i_plank = "nc_woodwork:plank"
|
||
|
|
||
|
local t_plank = "nc_woodwork_plank.png"
|
||
|
local t_frame_log = "(nc_tree_tree_side.png^[mask:nc_api_storebox_frame.png^[opacity:127)"
|
||
|
|
||
|
-- Load and save contraptions.
|
||
|
contraption.on_startup()
|
||
|
minetest.register_on_shutdown(contraption.on_shutdown)
|
||
|
|
||
|
-- `on_global_step` updates and moves around active contraptions.
|
||
|
minetest.register_globalstep(contraption.on_global_step)
|
||
|
|
||
|
-- Punching a contraption applies some force to it.
|
||
|
-- Multiple players can push a contraption more effectively.
|
||
|
minetest.register_on_punchnode(function(pos, node, puncher, pointed_thing)
|
||
|
local contrap = contraption.find(pos)
|
||
|
if not contrap then return end
|
||
|
|
||
|
if (not pointed_thing.above) or (not pointed_thing.under) then return end
|
||
|
local dir = vector.subtract(pointed_thing.under, pointed_thing.above)
|
||
|
contrap:push(puncher, dir)
|
||
|
end)
|
||
|
|
||
|
-- TODO: Provide a method to register additional types of contraption blocks.
|
||
|
minetest.register_node(mod_name .. ":contraption_wood", {
|
||
|
description = "Wooden Contraption",
|
||
|
tiles = { t_plank .. "^" .. t_frame_log },
|
||
|
sounds = nodecore.sounds("nc_tree_woody"),
|
||
|
groups = {
|
||
|
choppy = 1,
|
||
|
flammable = 2,
|
||
|
fire_fuel = 5,
|
||
|
},
|
||
|
on_dig = function(pos, node, digger)
|
||
|
local contrap = contraption.find(pos)
|
||
|
if contrap then contrap:destroy()
|
||
|
else minetest.node_dig(pos, node, digger) end
|
||
|
end,
|
||
|
drop_in_place = "nc_woodwork:plank",
|
||
|
})
|
||
|
|
||
|
-- TODO: Take priority over or hook into frame-to-form recipe to do our thing instead.
|
||
|
nodecore.register_craft({
|
||
|
label = "assemble wooden contraption",
|
||
|
action = "pummel",
|
||
|
toolgroups = { scratchy = 3 },
|
||
|
indexkeys = { i_frame },
|
||
|
nodes = { { match = i_frame } },
|
||
|
check = function(pos, data)
|
||
|
data.found_square = search.find_rectangle(pos, i_frame)
|
||
|
return not not data.found_square
|
||
|
end,
|
||
|
after = function(pos, data)
|
||
|
contraption.create(data.found_square)
|
||
|
end,
|
||
|
})
|