From f7d12dd79a6eba0271067559da87d009149d4c86 Mon Sep 17 00:00:00 2001 From: Joachim Stolberg Date: Fri, 10 Jun 2022 10:59:59 +0200 Subject: [PATCH] Implement fly/door controller improvements --- basis/fly_lib.lua | 37 +++++++++++++++++++++++++++-- move_controller/doorcontroller2.lua | 6 +++-- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/basis/fly_lib.lua b/basis/fly_lib.lua index a219463..49c9076 100644 --- a/basis/fly_lib.lua +++ b/basis/fly_lib.lua @@ -292,7 +292,7 @@ local function entity_to_node(pos, obj) local nvm = techage.get_nvm(self.base_pos) nvm.running = nil end - obj:remove() + minetest.after(0.2, obj.remove, obj) local node = minetest.get_node(pos) local ndef1 = minetest.registered_nodes[name] @@ -330,7 +330,7 @@ local function node_to_entity(start_pos) -- Block with other metadata node = minetest.get_node(start_pos) metadata = meta:to_table() - minetest.remove_node(start_pos) + minetest.after(0.2, minetest.remove_node, start_pos) end local obj = minetest.add_entity(start_pos, "techage:move_item") if obj then @@ -714,6 +714,39 @@ function flylib.rotate_nodes(pos, posses1, rot) return posses2 end +function flylib.exchange_node(pos, name, param2) + local meta = M(pos) + local move_block + + -- consider stored "objects" + if meta:contains("ta_move_block") then + move_block = meta:get_string("ta_move_block") + end + + minetest.swap_node(pos, {name = name, param2 = param2}) + + if move_block then + meta:set_string("ta_move_block", move_block) + end +end + +function flylib.remove_node(pos) + local meta = M(pos) + local move_block + + -- consider stored "objects" + if meta:contains("ta_move_block") then + move_block = meta:get_string("ta_move_block") + end + + minetest.remove_node(pos) + + if move_block then + local node = minetest.deserialize(move_block) + minetest.add_node(pos, node) + meta:set_string("ta_move_block", "") + end +end minetest.register_on_joinplayer(function(player) unlock_player(player) diff --git a/move_controller/doorcontroller2.lua b/move_controller/doorcontroller2.lua index 86b8399..1b7cef2 100644 --- a/move_controller/doorcontroller2.lua +++ b/move_controller/doorcontroller2.lua @@ -17,6 +17,8 @@ local M = minetest.get_meta local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end local S = techage.S +local MP = minetest.get_modpath("techage") +local flylib = dofile(MP .. "/basis/fly_lib.lua") local logic = techage.logic local MarkedNodes = {} -- t[player] = {{entity, pos},...} @@ -154,9 +156,9 @@ local function exchange_node(pos, item, param2) local node = minetest.get_node_or_nil(pos) if node and is_simple_node(node.name) then if item and item:get_name() ~= "" and minetest.registered_nodes[item:get_name()] then - minetest.swap_node(pos, {name = item:get_name(), param2 = param2}) + flylib.exchange_node(pos, item:get_name(), param2) else - minetest.remove_node(pos) + flylib.remove_node(pos) end if node.name ~= "air" then return ItemStack(node.name), node.param2