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 "-"
end
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
-- Function removes the node from the techage lists.
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)
print("number2", number)
if number and tonumber(number) then
local key = minetest.hash_node_position(pos)
NumbersToBeRecycled[key] = number
NodeInfoCache[number] = nil
print("number3", number)
end
if oldnode and item_handling_node(oldnode.name) then
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_dig = function(pos, node, puncher, pointed_thing)
if minetest.is_protected(pos, puncher:get_player_name()) then
return
end
techage.remove_node(pos)
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)
end,
on_timer = on_timer,

View File

@ -222,16 +222,17 @@ minetest.register_node("techage:ta3_sequencer", {
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
return
return false
end
local nvm = techage.get_nvm(pos)
if not nvm.running then
techage.remove_node(pos)
minetest.node_dig(pos, node, puncher, pointed_thing)
techage.del_mem(pos)
end
return not nvm.running
end,
after_dig_node = function(pos, oldnode, oldmetadata)
techage.remove_node(pos, oldnode, oldmetadata)
techage.del_mem(pos)
end,
on_timer = check_rules,

View File

@ -541,13 +541,9 @@ minetest.register_node("techage:ta4_lua_controller", {
end
end,
on_dig = function(pos, node, puncher, pointed_thing)
if minetest.is_protected(pos, puncher:get_player_name()) then
return
end
techage.remove_node(pos)
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)
end,
on_timer = on_timer,

View File

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

View File

@ -106,7 +106,7 @@ class MyRenderer(mistune.Renderer):
##
def block_code(self, code, lang):
text = formspec_escape(code.strip())
lines = text.split("\n")
lines = text.split("\\n")
lines = [" " + item for item in lines]
self.TextChunck.extend(lines)
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
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.
* Reading data
_ident_ specifies the data to be read.
_add_data_ is for additional data and normally not needed.
The result is block dependent (see table below):
**Reading data**
- _ident_ specifies the data to be read.
- _add_data_ is for additional data and normally not needed.
- The result is block dependent (see table below)
| 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".
_cmnd_ is the command,
_data_ is additional data (see table below):
- _num_ is the number of the remote block, like "1234"
- _cmnd_ is the command
- _data_ is additional data (see table below)
| cmnd | data | comment |
| -------------------------------- | ------------ | ------------------------------------------------------------ |

Binary file not shown.