Improve node number recycling

This commit is contained in:
Joachim Stolberg 2020-12-11 15:50:40 +01:00
parent dd462aa220
commit 7bf7ce09a3
8 changed files with 42 additions and 35 deletions

View File

@ -217,17 +217,26 @@ function techage.add_node(pos, name, is_ta2)
return "-" return "-"
end end
local key = minetest.hash_node_position(pos) local key = minetest.hash_node_position(pos)
return NumbersToBeRecycled[key] or get_number(pos, true) local num = NumbersToBeRecycled[key]
if num then
backend.set_nodepos(num, pos)
NumbersToBeRecycled[key] = nil
return num
end
return get_number(pos, true)
end end
-- Function removes the node from the techage lists. -- Function removes the node from the techage lists.
function techage.remove_node(pos, oldnode, oldmetadata) function techage.remove_node(pos, oldnode, oldmetadata)
local number = oldmetadata and oldmetadata.fields and oldmetadata.fields.node_number local number = oldmetadata and oldmetadata.fields and oldmetadata.fields.node_number or oldmetadata.fields.number
print("number1", dump(oldmetadata))
number = number or get_number(pos) number = number or get_number(pos)
print("number2", number)
if number and tonumber(number) then if number and tonumber(number) then
local key = minetest.hash_node_position(pos) local key = minetest.hash_node_position(pos)
NumbersToBeRecycled[key] = number NumbersToBeRecycled[key] = number
NodeInfoCache[number] = nil NodeInfoCache[number] = nil
print("number3", number)
end end
if oldnode and item_handling_node(oldnode.name) then if oldnode and item_handling_node(oldnode.name) then
Tube:after_dig_node(pos) Tube:after_dig_node(pos)

View File

@ -385,13 +385,9 @@ minetest.register_node("techage:ta4_icta_controller", {
on_receive_fields = on_receive_fields, on_receive_fields = on_receive_fields,
on_dig = function(pos, node, puncher, pointed_thing) after_dig_node = function(pos, oldnode, oldmetadata)
if minetest.is_protected(pos, puncher:get_player_name()) then techage.remove_node(pos, oldnode, oldmetadata)
return techage.del_mem(pos)
end
techage.remove_node(pos)
minetest.node_dig(pos, node, puncher, pointed_thing)
end, end,
on_timer = on_timer, on_timer = on_timer,

View File

@ -222,16 +222,17 @@ minetest.register_node("techage:ta3_sequencer", {
on_receive_fields = on_receive_fields, on_receive_fields = on_receive_fields,
on_dig = function(pos, node, puncher, pointed_thing) can_dig = function(pos, puncher)
if minetest.is_protected(pos, puncher:get_player_name()) then if minetest.is_protected(pos, puncher:get_player_name()) then
return return false
end end
local nvm = techage.get_nvm(pos) local nvm = techage.get_nvm(pos)
if not nvm.running then return not nvm.running
techage.remove_node(pos) end,
minetest.node_dig(pos, node, puncher, pointed_thing)
after_dig_node = function(pos, oldnode, oldmetadata)
techage.remove_node(pos, oldnode, oldmetadata)
techage.del_mem(pos) techage.del_mem(pos)
end
end, end,
on_timer = check_rules, on_timer = check_rules,

View File

@ -541,13 +541,9 @@ minetest.register_node("techage:ta4_lua_controller", {
end end
end, end,
on_dig = function(pos, node, puncher, pointed_thing) after_dig_node = function(pos, oldnode, oldmetadata)
if minetest.is_protected(pos, puncher:get_player_name()) then techage.remove_node(pos, oldnode, oldmetadata)
return techage.del_mem(pos)
end
techage.remove_node(pos)
minetest.node_dig(pos, node, puncher, pointed_thing)
end, end,
on_timer = on_timer, on_timer = on_timer,

View File

@ -86,10 +86,13 @@ minetest.register_node("techage:ta4_server", {
return return
end end
techage.del_mem(pos) techage.del_mem(pos)
techage.remove_node(pos)
minetest.node_dig(pos, node, puncher, pointed_thing) minetest.node_dig(pos, node, puncher, pointed_thing)
end, end,
after_dig_node = function(pos, oldnode, oldmetadata)
techage.remove_node(pos, oldnode, oldmetadata)
end,
on_timer = function(pos, elasped) on_timer = function(pos, elasped)
local meta = M(pos) local meta = M(pos)
local nvm = techage.get_nvm(pos) local nvm = techage.get_nvm(pos)

View File

@ -106,7 +106,7 @@ class MyRenderer(mistune.Renderer):
## ##
def block_code(self, code, lang): def block_code(self, code, lang):
text = formspec_escape(code.strip()) text = formspec_escape(code.strip())
lines = text.split("\n") lines = text.split("\\n")
lines = [" " + item for item in lines] lines = [" " + item for item in lines]
self.TextChunck.extend(lines) self.TextChunck.extend(lines)
self.TextChunck.append("") self.TextChunck.append("")

View File

@ -347,13 +347,15 @@ In addition to Lua standard function the Lua Controller provides the following f
### Techage Command Functions ### Techage Command Functions
With the `$send_cmnd(num, ident, add_data)` function, you can send commands to and retrieve data from another block with the given number _num_. With the `$send_cmnd(num, ident, add_data)` function, you can send commands to and retrieve data from another block with the given number _num_.
The possible commands can be classified in two groups: Commands for reading data and commands for causing an action. The possible commands can be classified in two groups: Commands for reading data and commands for triggering an action.
Please note, that this is not a technical distinction, only a logical. Please note, that this is not a technical distinction, only a logical.
* Reading data **Reading data**
_ident_ specifies the data to be read.
_add_data_ is for additional data and normally not needed. - _ident_ specifies the data to be read.
The result is block dependent (see table below): - _add_data_ is for additional data and normally not needed.
- The result is block dependent (see table below)
| ident | returned data | comment | | ident | returned data | comment |
| ------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | | ------------ | ------------------------------------------------------------ | ------------------------------------------------------------ |
@ -373,11 +375,11 @@ Please note, that this is not a technical distinction, only a logical.
**Trigger an action**
* Causing an action - _num_ is the number of the remote block, like "1234"
_num_ is the number of the remote block, like "1234". - _cmnd_ is the command
_cmnd_ is the command, - _data_ is additional data (see table below)
_data_ is additional data (see table below):
| cmnd | data | comment | | cmnd | data | comment |
| -------------------------------- | ------------ | ------------------------------------------------------------ | | -------------------------------- | ------------ | ------------------------------------------------------------ |

Binary file not shown.