Add function to allow to disable a block from being removed by the assembly tool

This commit is contained in:
Joachim Stolberg 2023-09-29 19:40:25 +02:00
parent a347405150
commit 7a99d7c0ad
2 changed files with 20 additions and 1 deletions

9
api.md
View File

@ -214,3 +214,12 @@ techage.furnace.register_recipe({
``` ```
## Assembly Tool
Disable a block from being removed by the assembly tool:
```lua
techage.disable_block_for_assembly_tool(block_name)
```

View File

@ -15,6 +15,8 @@ local M = minetest.get_meta
local S = techage.S local S = techage.S
local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end
local InvalidBlocks = {}
local function base_checks(user, pointed_thing, place) local function base_checks(user, pointed_thing, place)
if pointed_thing.type ~= "node" then if pointed_thing.type ~= "node" then
return false return false
@ -67,6 +69,10 @@ local function remove_node(pos, digger)
local ndef = minetest.registered_nodes[node.name] local ndef = minetest.registered_nodes[node.name]
local oldmetadata = minetest.get_meta(pos):to_table() local oldmetadata = minetest.get_meta(pos):to_table()
if InvalidBlocks[node.name] then
return
end
if number ~= "" and ndef and ndef.after_dig_node then if number ~= "" and ndef and ndef.after_dig_node then
minetest.remove_node(pos) minetest.remove_node(pos)
ndef.after_dig_node(pos, node, oldmetadata, digger) ndef.after_dig_node(pos, node, oldmetadata, digger)
@ -158,4 +164,8 @@ minetest.register_craft({
}, },
}) })
minetest.register_alias("techage:repairkit", "techage:assembly_tool") minetest.register_alias("techage:repairkit", "techage:assembly_tool")
function techage.disable_block_for_assembly_tool(block_name)
InvalidBlocks[block_name] = true
end