2021-11-15 21:26:59 +03:00
|
|
|
--[[
|
|
|
|
|
|
|
|
TechAge
|
|
|
|
=======
|
|
|
|
|
2023-02-04 17:32:05 +03:00
|
|
|
Copyright (C) 2020-2023 Joachim Stolberg
|
2021-11-15 21:26:59 +03:00
|
|
|
|
|
|
|
AGPL v3
|
|
|
|
See LICENSE.txt for more information
|
|
|
|
|
|
|
|
Block fly/move library
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2021-11-15 21:26:59 +03:00
|
|
|
]]--
|
|
|
|
|
|
|
|
-- for lazy programmers
|
|
|
|
local M = minetest.get_meta
|
|
|
|
local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end
|
|
|
|
local S2P = minetest.string_to_pos
|
|
|
|
local S = techage.S
|
|
|
|
|
|
|
|
local flylib = {}
|
|
|
|
|
2021-11-28 16:42:18 +03:00
|
|
|
local function lvect_add_vec(lvect1, offs)
|
|
|
|
if not lvect1 or not offs then return end
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2021-11-28 16:42:18 +03:00
|
|
|
local lvect2 = {}
|
|
|
|
for _, v in ipairs(lvect1) do
|
|
|
|
lvect2[#lvect2 + 1] = vector.add(v, offs)
|
|
|
|
end
|
|
|
|
return lvect2
|
|
|
|
end
|
|
|
|
|
2021-12-24 18:05:04 +03:00
|
|
|
-- yaw in radiant
|
|
|
|
local function rotate(v, yaw)
|
2021-12-25 18:12:09 +03:00
|
|
|
local sinyaw = math.sin(yaw)
|
|
|
|
local cosyaw = math.cos(yaw)
|
2021-12-24 18:05:04 +03:00
|
|
|
return {x = v.x * cosyaw - v.z * sinyaw, y = v.y, z = v.x * sinyaw + v.z * cosyaw}
|
|
|
|
end
|
|
|
|
|
2023-02-05 20:14:01 +03:00
|
|
|
-- playername is needed for carts, to attach the player to the cart entity
|
|
|
|
local function set_node(item, playername)
|
2022-12-06 20:43:10 +03:00
|
|
|
local dest_pos = item.dest_pos
|
|
|
|
local name = item.name or "air"
|
|
|
|
local param2 = item.param2 or 0
|
|
|
|
local nvm = techage.get_nvm(item.base_pos)
|
|
|
|
local node = techage.get_node_lvm(dest_pos)
|
|
|
|
local ndef1 = minetest.registered_nodes[name]
|
|
|
|
local ndef2 = minetest.registered_nodes[node.name]
|
|
|
|
|
|
|
|
nvm.running = false
|
|
|
|
M(item.base_pos):set_string("status", S("Stopped"))
|
|
|
|
if ndef1 and ndef2 then
|
2023-02-06 19:42:25 +03:00
|
|
|
if minecart.is_cart(name) and (minecart.is_rail(dest_pos, node.name) or minecart.is_cart(name)) then
|
2023-02-05 20:14:01 +03:00
|
|
|
local player = playername and minetest.get_player_by_name(playername)
|
|
|
|
minecart.place_and_start_cart(dest_pos, {name = name, param2 = param2}, item.cartdef, player)
|
|
|
|
return
|
|
|
|
elseif ndef2.buildable_to then
|
2022-12-06 20:43:10 +03:00
|
|
|
local meta = M(dest_pos)
|
2023-02-11 20:00:27 +03:00
|
|
|
if name ~= "techage:moveblock" then
|
|
|
|
minetest.set_node(dest_pos, {name=name, param2=param2})
|
|
|
|
meta:from_table(item.metadata or {})
|
|
|
|
meta:set_string("ta_move_block", "")
|
|
|
|
meta:set_int("ta_door_locked", 1)
|
|
|
|
end
|
2022-12-06 20:43:10 +03:00
|
|
|
return
|
|
|
|
end
|
|
|
|
local meta = M(dest_pos)
|
|
|
|
if not meta:contains("ta_move_block") then
|
|
|
|
meta:set_string("ta_move_block", minetest.serialize({name=name, param2=param2}))
|
|
|
|
return
|
|
|
|
end
|
|
|
|
elseif ndef1 then
|
2023-02-11 20:00:27 +03:00
|
|
|
if name ~= "techage:moveblock" then
|
|
|
|
minetest.add_item(dest_pos, ItemStack(name))
|
|
|
|
end
|
2022-12-06 20:43:10 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
-- Entity monitoring
|
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
local queue = {}
|
|
|
|
local first = 0
|
|
|
|
local last = -1
|
|
|
|
|
|
|
|
local function push(item)
|
|
|
|
last = last + 1
|
|
|
|
queue[last] = item
|
|
|
|
end
|
|
|
|
|
2023-02-04 17:32:05 +03:00
|
|
|
local function pop()
|
2022-12-06 20:43:10 +03:00
|
|
|
if first > last then return end
|
|
|
|
local item = queue[first]
|
|
|
|
queue[first] = nil -- to allow garbage collection
|
|
|
|
first = first + 1
|
|
|
|
return item
|
|
|
|
end
|
|
|
|
|
|
|
|
local function monitoring()
|
|
|
|
local num = last - first + 1
|
|
|
|
for _ = 1, num do
|
|
|
|
local item = pop()
|
|
|
|
if item.ttl >= techage.SystemTime then
|
|
|
|
-- still valud
|
|
|
|
push(item)
|
|
|
|
elseif item.ttl ~= 0 then
|
|
|
|
set_node(item)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
minetest.after(1, monitoring)
|
|
|
|
end
|
|
|
|
minetest.after(1, monitoring)
|
|
|
|
|
|
|
|
minetest.register_on_shutdown(function()
|
|
|
|
local num = last - first + 1
|
|
|
|
for _ = 1, num do
|
|
|
|
local item = pop()
|
|
|
|
if item.ttl ~= 0 then
|
|
|
|
set_node(item)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
local function monitoring_add_entity(item)
|
|
|
|
item.ttl = techage.SystemTime + 1
|
|
|
|
push(item)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function monitoring_del_entity(item)
|
|
|
|
-- Mark as timed out
|
|
|
|
item.ttl = 0
|
|
|
|
end
|
|
|
|
|
|
|
|
local function monitoring_trigger_entity(item)
|
|
|
|
item.ttl = techage.SystemTime + 1
|
|
|
|
end
|
|
|
|
|
2021-11-15 21:26:59 +03:00
|
|
|
-------------------------------------------------------------------------------
|
2022-01-03 23:40:31 +03:00
|
|
|
-- to_path function for the fly/move path
|
2021-11-15 21:26:59 +03:00
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
local function strsplit(text)
|
|
|
|
text = text:gsub("\r\n", "\n")
|
|
|
|
text = text:gsub("\r", "\n")
|
|
|
|
return string.split(text, "\n", true)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function trim(s)
|
|
|
|
return (s:gsub("^%s*(.-)%s*$", "%1"))
|
|
|
|
end
|
|
|
|
|
|
|
|
function flylib.distance(v)
|
|
|
|
return math.abs(v.x) + math.abs(v.y) + math.abs(v.z)
|
|
|
|
end
|
|
|
|
|
2022-08-18 19:06:55 +03:00
|
|
|
function flylib.to_vector(s, max_dist)
|
2021-11-15 21:26:59 +03:00
|
|
|
local x,y,z = unpack(string.split(s, ","))
|
2022-08-18 19:06:55 +03:00
|
|
|
x = tonumber(x) or 0
|
|
|
|
y = tonumber(y) or 0
|
|
|
|
z = tonumber(z) or 0
|
2021-11-15 21:26:59 +03:00
|
|
|
if x and y and z then
|
2022-08-18 19:06:55 +03:00
|
|
|
if not max_dist or (math.abs(x) + math.abs(y) + math.abs(z)) <= max_dist then
|
|
|
|
return {x = x, y = y, z = z}
|
|
|
|
end
|
2021-11-15 21:26:59 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function flylib.to_path(s, max_dist)
|
|
|
|
local tPath
|
2021-12-11 22:15:55 +03:00
|
|
|
local dist = 0
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2021-11-15 21:26:59 +03:00
|
|
|
for _, line in ipairs(strsplit(s)) do
|
|
|
|
line = trim(line)
|
|
|
|
line = string.split(line, "--", true, 1)[1] or ""
|
|
|
|
if line ~= "" then
|
|
|
|
local v = flylib.to_vector(line)
|
2021-12-11 22:15:55 +03:00
|
|
|
if v then
|
2021-12-24 18:05:04 +03:00
|
|
|
dist = dist + flylib.distance(v)
|
|
|
|
if not max_dist or dist <= max_dist then
|
2021-12-11 22:15:55 +03:00
|
|
|
tPath = tPath or {}
|
|
|
|
tPath[#tPath + 1] = v
|
2021-12-24 18:05:04 +03:00
|
|
|
else
|
2022-09-13 22:13:09 +03:00
|
|
|
return tPath, S("Error: Max. length of the flight route exceeded by @1 blocks !!", dist - max_dist)
|
2021-12-24 18:05:04 +03:00
|
|
|
end
|
2021-12-11 22:15:55 +03:00
|
|
|
else
|
|
|
|
return tPath, S("Error: Invalid path !!")
|
2021-11-15 21:26:59 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return tPath
|
|
|
|
end
|
|
|
|
|
|
|
|
local function next_path_pos(pos, lpath, idx)
|
|
|
|
local offs = lpath[idx]
|
|
|
|
if offs then
|
|
|
|
return vector.add(pos, offs)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function reverse_path(lpath)
|
|
|
|
local lres = {}
|
|
|
|
for i = #lpath, 1, -1 do
|
|
|
|
lres[#lres + 1] = vector.multiply(lpath[i], -1)
|
|
|
|
end
|
|
|
|
return lres
|
|
|
|
end
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2021-11-15 21:26:59 +03:00
|
|
|
local function dest_offset(lpath)
|
|
|
|
local offs = {x=0, y=0, z=0}
|
|
|
|
for i = 1,#lpath do
|
|
|
|
offs = vector.add(offs, lpath[i])
|
|
|
|
end
|
|
|
|
return offs
|
|
|
|
end
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2022-06-23 21:36:36 +03:00
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
-- Protect the doors from being opened by hand
|
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
local function new_on_rightclick(old_on_rightclick)
|
|
|
|
return function(pos, node, clicker, itemstack, pointed_thing)
|
|
|
|
if M(pos):contains("ta_door_locked") then
|
|
|
|
return itemstack
|
|
|
|
end
|
|
|
|
if old_on_rightclick then
|
|
|
|
return old_on_rightclick(pos, node, clicker, itemstack, pointed_thing)
|
|
|
|
else
|
|
|
|
return itemstack
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function flylib.protect_door_from_being_opened(name)
|
|
|
|
-- Change on_rightclick function.
|
|
|
|
local ndef = minetest.registered_nodes[name]
|
|
|
|
if ndef then
|
|
|
|
local old_on_rightclick = ndef.on_rightclick
|
|
|
|
minetest.override_item(ndef.name, {
|
|
|
|
on_rightclick = new_on_rightclick(old_on_rightclick)
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-11-15 21:26:59 +03:00
|
|
|
-------------------------------------------------------------------------------
|
2022-01-03 23:40:31 +03:00
|
|
|
-- Entity / Move / Attach / Detach
|
2021-11-15 21:26:59 +03:00
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
local MIN_SPEED = 0.4
|
|
|
|
local MAX_SPEED = 8
|
|
|
|
local CORNER_SPEED = 4
|
|
|
|
|
|
|
|
local function calc_speed(v)
|
|
|
|
return math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Only the ID ist stored, not the object
|
|
|
|
local function get_object_id(object)
|
|
|
|
for id, entity in pairs(minetest.luaentities) do
|
|
|
|
if entity.object == object then
|
|
|
|
return id
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- determine exact position of attached entities
|
|
|
|
local function obj_pos(obj)
|
|
|
|
local _, _, pos = obj:get_attach()
|
|
|
|
if pos then
|
|
|
|
pos = vector.divide(pos, 29)
|
|
|
|
return vector.add(obj:get_pos(), pos)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Check access conflicts with other mods
|
|
|
|
local function lock_player(player)
|
|
|
|
local meta = player:get_meta()
|
2022-01-03 23:40:31 +03:00
|
|
|
if meta:get_int("player_physics_locked") == 0 then
|
2021-11-15 21:26:59 +03:00
|
|
|
meta:set_int("player_physics_locked", 1)
|
|
|
|
meta:set_string("player_physics_locked_by", "ta_flylib")
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
local function unlock_player(player)
|
|
|
|
local meta = player:get_meta()
|
2022-01-03 23:40:31 +03:00
|
|
|
if meta:get_int("player_physics_locked") == 1 then
|
2021-11-15 21:26:59 +03:00
|
|
|
if meta:get_string("player_physics_locked_by") == "ta_flylib" then
|
|
|
|
meta:set_int("player_physics_locked", 0)
|
|
|
|
meta:set_string("player_physics_locked_by", "")
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
local function detach_player(player)
|
|
|
|
local pos = obj_pos(player)
|
|
|
|
if pos then
|
|
|
|
player:set_detach()
|
|
|
|
player:set_properties({visual_size = {x=1, y=1}})
|
|
|
|
player:set_pos(pos)
|
|
|
|
end
|
|
|
|
-- TODO: move to save position
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Attach player/mob to given parent object (block)
|
2023-02-05 20:14:01 +03:00
|
|
|
local function attach_single_object(parent, obj, distance)
|
2021-11-15 21:26:59 +03:00
|
|
|
local self = parent:get_luaentity()
|
|
|
|
local res = obj:get_attach()
|
2021-12-24 18:05:04 +03:00
|
|
|
if not res then -- not already attached
|
|
|
|
local yaw
|
|
|
|
if obj:is_player() then
|
|
|
|
yaw = obj:get_look_horizontal()
|
|
|
|
else
|
|
|
|
yaw = obj:get_rotation().y
|
|
|
|
end
|
|
|
|
-- store for later use
|
2023-02-05 20:14:01 +03:00
|
|
|
local offs = table.copy(distance)
|
2021-12-24 18:05:04 +03:00
|
|
|
-- Calc entity rotation, which is relative to the parent's rotation
|
|
|
|
local rot = parent:get_rotation()
|
|
|
|
if self.param2 >= 20 then
|
2023-02-05 20:14:01 +03:00
|
|
|
distance = rotate(distance, 2 * math.pi - rot.y)
|
|
|
|
distance.y = -distance.y
|
|
|
|
distance.x = -distance.x
|
2021-12-24 18:05:04 +03:00
|
|
|
rot.y = rot.y - yaw
|
|
|
|
elseif self.param2 < 4 then
|
2023-02-05 20:14:01 +03:00
|
|
|
distance = rotate(distance, 2 * math.pi - rot.y)
|
2021-12-24 18:05:04 +03:00
|
|
|
rot.y = rot.y - yaw
|
|
|
|
end
|
2023-02-05 20:14:01 +03:00
|
|
|
distance = vector.multiply(distance, 29)
|
|
|
|
obj:set_attach(parent, "", distance, vector.multiply(rot, 180 / math.pi))
|
2021-11-15 21:26:59 +03:00
|
|
|
obj:set_properties({visual_size = {x=2.9, y=2.9}})
|
|
|
|
if obj:is_player() then
|
|
|
|
if lock_player(obj) then
|
|
|
|
table.insert(self.players, {name = obj:get_player_name(), offs = offs})
|
|
|
|
end
|
|
|
|
else
|
|
|
|
table.insert(self.entities, {objID = get_object_id(obj), offs = offs})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Attach all objects around to the parent object
|
|
|
|
-- offs is the search/attach position offset
|
2023-02-05 20:14:01 +03:00
|
|
|
-- distance (optional) is the attach distance to the center of the entity
|
|
|
|
local function attach_objects(pos, offs, parent, yoffs, distance)
|
2021-11-15 21:26:59 +03:00
|
|
|
local pos1 = vector.add(pos, offs)
|
|
|
|
for _, obj in pairs(minetest.get_objects_inside_radius(pos1, 0.9)) do
|
2023-02-05 20:14:01 +03:00
|
|
|
-- keep relative object position
|
|
|
|
distance = distance or vector.subtract(obj:get_pos(), pos)
|
2021-11-15 21:26:59 +03:00
|
|
|
local entity = obj:get_luaentity()
|
|
|
|
if entity then
|
2022-01-10 23:36:54 +03:00
|
|
|
local mod = entity.name:gmatch("(.-):")()
|
|
|
|
if techage.RegisteredMobsMods[mod] then
|
2023-02-05 20:14:01 +03:00
|
|
|
distance.y = distance.y + yoffs
|
|
|
|
attach_single_object(parent, obj, distance)
|
2021-11-15 21:26:59 +03:00
|
|
|
end
|
|
|
|
elseif obj:is_player() then
|
2023-02-05 20:14:01 +03:00
|
|
|
attach_single_object(parent, obj, distance)
|
2021-11-15 21:26:59 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Detach all attached objects from the parent object
|
|
|
|
local function detach_objects(pos, self)
|
|
|
|
for _, item in ipairs(self.entities or {}) do
|
|
|
|
local entity = minetest.luaentities[item.objID]
|
|
|
|
if entity then
|
|
|
|
local obj = entity.object
|
|
|
|
obj:set_detach()
|
|
|
|
obj:set_properties({visual_size = {x=1, y=1}})
|
|
|
|
local pos1 = vector.add(pos, item.offs)
|
2021-12-25 18:12:09 +03:00
|
|
|
pos1.y = pos1.y - (self.yoffs or 0)
|
2021-11-15 21:26:59 +03:00
|
|
|
obj:set_pos(pos1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
for _, item in ipairs(self.players or {}) do
|
|
|
|
local obj = minetest.get_player_by_name(item.name)
|
|
|
|
if obj then
|
|
|
|
obj:set_detach()
|
|
|
|
obj:set_properties({visual_size = {x=1, y=1}})
|
|
|
|
local pos1 = vector.add(pos, item.offs)
|
2021-12-24 18:05:04 +03:00
|
|
|
pos1.y = pos1.y + 0.1
|
2021-11-15 21:26:59 +03:00
|
|
|
obj:set_pos(pos1)
|
|
|
|
unlock_player(obj)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
self.entities = {}
|
|
|
|
self.players = {}
|
|
|
|
end
|
|
|
|
|
|
|
|
local function entity_to_node(pos, obj)
|
|
|
|
local self = obj:get_luaentity()
|
2022-12-06 20:43:10 +03:00
|
|
|
if self and self.item then
|
2023-02-05 20:14:01 +03:00
|
|
|
local playername = self.players and self.players[1] and self.players[1].name
|
2021-11-15 21:26:59 +03:00
|
|
|
detach_objects(pos, self)
|
2022-12-06 20:43:10 +03:00
|
|
|
monitoring_del_entity(self.item)
|
2022-07-03 17:07:38 +03:00
|
|
|
minetest.after(0.1, obj.remove, obj)
|
2023-02-05 20:14:01 +03:00
|
|
|
set_node(self.item, playername)
|
2021-11-15 21:26:59 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-02-04 17:32:05 +03:00
|
|
|
-- Create a node entitiy.
|
|
|
|
-- * base_pos is controller block related
|
|
|
|
-- * start_pos and dest_pos are entity positions
|
2022-12-06 20:43:10 +03:00
|
|
|
local function node_to_entity(base_pos, start_pos, dest_pos)
|
2021-11-15 21:26:59 +03:00
|
|
|
local meta = M(start_pos)
|
2023-02-05 20:14:01 +03:00
|
|
|
local node, metadata, cartdef
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2023-02-05 20:14:01 +03:00
|
|
|
node = techage.get_node_lvm(start_pos)
|
|
|
|
if minecart.is_cart(node.name) then
|
|
|
|
cartdef = minecart.remove_cart(start_pos)
|
|
|
|
elseif meta:contains("ta_move_block") then
|
2021-11-15 21:26:59 +03:00
|
|
|
-- Move-block stored as metadata
|
|
|
|
node = minetest.deserialize(meta:get_string("ta_move_block"))
|
|
|
|
metadata = {}
|
|
|
|
meta:set_string("ta_move_block", "")
|
2022-06-23 21:36:36 +03:00
|
|
|
meta:set_string("ta_block_locked", "true")
|
|
|
|
elseif not meta:contains("ta_block_locked") then
|
2021-11-15 21:26:59 +03:00
|
|
|
-- Block with other metadata
|
2022-12-06 20:43:10 +03:00
|
|
|
node = techage.get_node_lvm(start_pos)
|
2021-11-15 21:26:59 +03:00
|
|
|
metadata = meta:to_table()
|
2022-07-03 17:07:38 +03:00
|
|
|
minetest.after(0.1, minetest.remove_node, start_pos)
|
2022-06-23 21:36:36 +03:00
|
|
|
else
|
|
|
|
return
|
2021-11-15 21:26:59 +03:00
|
|
|
end
|
|
|
|
local obj = minetest.add_entity(start_pos, "techage:move_item")
|
|
|
|
if obj then
|
2022-01-03 23:40:31 +03:00
|
|
|
local self = obj:get_luaentity()
|
2021-11-15 21:26:59 +03:00
|
|
|
local rot = techage.facedir_to_rotation(node.param2)
|
|
|
|
obj:set_rotation(rot)
|
|
|
|
obj:set_properties({wield_item=node.name})
|
|
|
|
obj:set_armor_groups({immortal=1})
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2021-11-15 21:26:59 +03:00
|
|
|
-- To be able to revert to node
|
|
|
|
self.param2 = node.param2
|
2022-12-06 20:43:10 +03:00
|
|
|
self.item = {
|
|
|
|
name = node.name,
|
|
|
|
param2 = node.param2,
|
|
|
|
metadata = metadata or {},
|
|
|
|
dest_pos = dest_pos,
|
|
|
|
base_pos = base_pos,
|
2023-02-05 20:14:01 +03:00
|
|
|
cartdef = cartdef,
|
2022-12-06 20:43:10 +03:00
|
|
|
}
|
|
|
|
monitoring_add_entity(self.item)
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2021-11-15 21:26:59 +03:00
|
|
|
-- Prepare for attachments
|
|
|
|
self.players = {}
|
|
|
|
self.entities = {}
|
|
|
|
-- Prepare for path walk
|
2021-11-16 22:07:52 +03:00
|
|
|
self.path_idx = 1
|
2023-02-05 20:14:01 +03:00
|
|
|
return obj, self.item.cartdef ~= nil
|
2021-11-15 21:26:59 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- move block direction
|
|
|
|
local function determine_dir(pos1, pos2)
|
|
|
|
local vdist = vector.subtract(pos2, pos1)
|
|
|
|
local ndist = vector.length(vdist)
|
2021-11-28 16:42:18 +03:00
|
|
|
if ndist > 0 then
|
|
|
|
return vector.divide(vdist, ndist)
|
|
|
|
end
|
|
|
|
return {x=0, y=0, z=0}
|
2021-11-15 21:26:59 +03:00
|
|
|
end
|
|
|
|
|
2023-02-04 17:32:05 +03:00
|
|
|
local function move_entity(obj, next_pos, dir, is_corner)
|
2021-11-15 21:26:59 +03:00
|
|
|
local self = obj:get_luaentity()
|
2023-02-04 17:32:05 +03:00
|
|
|
self.next_pos = next_pos
|
2021-11-15 21:26:59 +03:00
|
|
|
self.dir = dir
|
|
|
|
if is_corner then
|
|
|
|
local vel = vector.multiply(dir, math.min(CORNER_SPEED, self.max_speed))
|
|
|
|
obj:set_velocity(vel)
|
|
|
|
end
|
|
|
|
local acc = vector.multiply(dir, self.max_speed / 2)
|
|
|
|
obj:set_acceleration(acc)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function moveon_entity(obj, self, pos1)
|
2023-02-04 17:32:05 +03:00
|
|
|
local pos2 = next_path_pos(pos1, self.lmove, self.path_idx)
|
2021-11-15 21:26:59 +03:00
|
|
|
if pos2 then
|
2021-11-16 22:07:52 +03:00
|
|
|
self.path_idx = self.path_idx + 1
|
2021-11-15 21:26:59 +03:00
|
|
|
local dir = determine_dir(pos1, pos2)
|
|
|
|
move_entity(obj, pos2, dir, true)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_entity("techage:move_item", {
|
|
|
|
initial_properties = {
|
|
|
|
pointable = true,
|
|
|
|
makes_footstep_sound = true,
|
2022-12-06 20:43:10 +03:00
|
|
|
static_save = false,
|
2021-11-15 21:26:59 +03:00
|
|
|
collide_with_objects = false,
|
|
|
|
physical = false,
|
|
|
|
visual = "wielditem",
|
|
|
|
wield_item = "default:dirt",
|
|
|
|
visual_size = {x=0.67, y=0.67, z=0.67},
|
|
|
|
selectionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
|
|
|
|
},
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2021-11-15 21:26:59 +03:00
|
|
|
on_step = function(self, dtime, moveresult)
|
|
|
|
local stop_obj = function(obj, self)
|
2023-02-04 17:32:05 +03:00
|
|
|
local next_pos = self.next_pos
|
|
|
|
obj:move_to(self.next_pos, true)
|
2021-11-15 21:26:59 +03:00
|
|
|
obj:set_acceleration({x=0, y=0, z=0})
|
|
|
|
obj:set_velocity({x=0, y=0, z=0})
|
2023-02-04 17:32:05 +03:00
|
|
|
self.next_pos = nil
|
2021-11-15 21:26:59 +03:00
|
|
|
self.old_dist = nil
|
2023-02-04 17:32:05 +03:00
|
|
|
return next_pos
|
2021-11-15 21:26:59 +03:00
|
|
|
end
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2023-02-04 17:32:05 +03:00
|
|
|
if self.next_pos then
|
2021-11-15 21:26:59 +03:00
|
|
|
local obj = self.object
|
|
|
|
local pos = obj:get_pos()
|
2023-02-04 17:32:05 +03:00
|
|
|
local dist = vector.distance(pos, self.next_pos)
|
2021-11-15 21:26:59 +03:00
|
|
|
local speed = calc_speed(obj:get_velocity())
|
|
|
|
self.old_dist = self.old_dist or dist
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2023-02-04 17:32:05 +03:00
|
|
|
if self.lmove and self.lmove[self.path_idx] then
|
2021-11-15 21:26:59 +03:00
|
|
|
if dist < 1 or dist > self.old_dist then
|
2023-02-02 21:22:37 +03:00
|
|
|
-- change of direction
|
2023-02-04 17:32:05 +03:00
|
|
|
local next_pos = stop_obj(obj, self)
|
|
|
|
if not moveon_entity(obj, self, next_pos) then
|
|
|
|
minetest.after(0.5, entity_to_node, next_pos, obj)
|
2021-11-15 21:26:59 +03:00
|
|
|
end
|
|
|
|
return
|
|
|
|
end
|
2023-02-04 17:32:05 +03:00
|
|
|
elseif dist < 0.05 or dist > self.old_dist then
|
|
|
|
-- Landing
|
|
|
|
local next_pos = stop_obj(obj, self)
|
|
|
|
local dest_pos = self.item.dest_pos or next_pos
|
|
|
|
minetest.after(0.5, entity_to_node, dest_pos, obj)
|
2021-11-16 22:07:52 +03:00
|
|
|
return
|
2021-11-15 21:26:59 +03:00
|
|
|
end
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2021-11-15 21:26:59 +03:00
|
|
|
self.old_dist = dist
|
2022-01-03 23:40:31 +03:00
|
|
|
|
|
|
|
-- Braking or limit max speed
|
2023-02-04 17:32:05 +03:00
|
|
|
if speed > (dist * 2) or speed > self.max_speed then
|
|
|
|
speed = math.min(speed, math.max(dist * 2, MIN_SPEED))
|
|
|
|
local vel = vector.multiply(self.dir,speed)
|
|
|
|
obj:set_velocity(vel)
|
|
|
|
obj:set_acceleration({x=0, y=0, z=0})
|
2021-11-15 21:26:59 +03:00
|
|
|
end
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2022-12-06 20:43:10 +03:00
|
|
|
monitoring_trigger_entity(self.item)
|
2021-11-15 21:26:59 +03:00
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
local function is_valid_dest(pos)
|
2022-12-06 20:43:10 +03:00
|
|
|
local node = techage.get_node_lvm(pos)
|
2022-06-23 21:36:36 +03:00
|
|
|
if techage.is_air_like(node.name) then
|
2021-11-15 21:26:59 +03:00
|
|
|
return true
|
|
|
|
end
|
2023-02-06 19:42:25 +03:00
|
|
|
if minecart.is_rail(pos, node.name) or minecart.is_cart(node.name) then
|
2023-02-05 21:34:08 +03:00
|
|
|
return true
|
|
|
|
end
|
2021-11-15 21:26:59 +03:00
|
|
|
if not M(pos):contains("ta_move_block") then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
local function is_simple_node(pos)
|
2023-02-05 20:14:01 +03:00
|
|
|
local node = techage.get_node_lvm(pos)
|
2023-02-05 21:34:08 +03:00
|
|
|
if not minecart.is_rail(pos, node.name) then
|
2023-02-11 20:00:27 +03:00
|
|
|
if node.name == "air" then
|
|
|
|
minetest.swap_node(pos, {name = "techage:moveblock", param2 = 0})
|
|
|
|
return true
|
|
|
|
end
|
2023-02-05 20:14:01 +03:00
|
|
|
local ndef = minetest.registered_nodes[node.name]
|
|
|
|
return not techage.is_air_like(node.name) and techage.can_dig_node(node.name, ndef) or minecart.is_cart(node.name)
|
|
|
|
end
|
2022-01-03 23:40:31 +03:00
|
|
|
end
|
2021-11-15 21:26:59 +03:00
|
|
|
|
2023-02-04 17:32:05 +03:00
|
|
|
-- Move node from 'pos1' to the destination, calculated by means of 'lmove'
|
|
|
|
-- * pos and meta are controller block related
|
|
|
|
-- * lmove is the movement as a list of `moves`
|
|
|
|
-- * height is move block height as value between 0 and 1 and used to calculate the offset
|
|
|
|
-- for the attached object (player).
|
|
|
|
local function move_node(pos, meta, pos1, lmove, max_speed, height)
|
|
|
|
local pos2 = next_path_pos(pos1, lmove, 1)
|
|
|
|
local offs = dest_offset(lmove)
|
|
|
|
local dest_pos = vector.add(pos1, offs)
|
2021-12-25 18:12:09 +03:00
|
|
|
-- optional for non-player objects
|
2023-02-04 17:32:05 +03:00
|
|
|
local yoffs = meta:get_float("offset")
|
2021-12-25 18:12:09 +03:00
|
|
|
|
2021-11-15 21:26:59 +03:00
|
|
|
if pos2 then
|
2023-02-04 17:32:05 +03:00
|
|
|
local dir = determine_dir(pos1, pos2)
|
2023-02-05 20:14:01 +03:00
|
|
|
local obj, is_cart = node_to_entity(pos, pos1, dest_pos)
|
2021-11-15 21:26:59 +03:00
|
|
|
|
|
|
|
if obj then
|
2023-02-05 20:14:01 +03:00
|
|
|
if is_cart then
|
2023-02-05 21:34:08 +03:00
|
|
|
attach_objects(pos1, 0, obj, yoffs, {x = 0, y = -0.4, z = 0})
|
2023-02-05 20:14:01 +03:00
|
|
|
else
|
|
|
|
local offs = {x=0, y=height or 1, z=0}
|
|
|
|
attach_objects(pos1, offs, obj, yoffs)
|
|
|
|
if dir.y == 0 then
|
|
|
|
if (dir.x ~= 0 and dir.z == 0) or (dir.x == 0 and dir.z ~= 0) then
|
|
|
|
attach_objects(pos1, dir, obj, yoffs)
|
|
|
|
end
|
2021-11-15 21:26:59 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
local self = obj:get_luaentity()
|
2021-11-16 22:07:52 +03:00
|
|
|
self.path_idx = 2
|
2023-02-04 17:32:05 +03:00
|
|
|
self.lmove = lmove
|
2021-11-15 21:26:59 +03:00
|
|
|
self.max_speed = max_speed
|
2021-12-25 18:12:09 +03:00
|
|
|
self.yoffs = yoffs
|
2021-11-15 21:26:59 +03:00
|
|
|
move_entity(obj, pos2, dir)
|
2022-12-09 23:17:01 +03:00
|
|
|
return true
|
|
|
|
else
|
|
|
|
return false
|
2021-11-15 21:26:59 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-02-04 17:32:05 +03:00
|
|
|
-- Move the nodes from nvm.lpos1 to nvm.lpos2
|
|
|
|
-- * nvm.lpos1 is a list of nodes
|
|
|
|
-- * lmove is the movement as a list of `moves`
|
|
|
|
-- * pos, meta, and nvm are controller block related
|
|
|
|
--- height is move block height as value between 0 and 1 and used to calculate the offset
|
|
|
|
-- for the attached object (player).
|
|
|
|
local function multi_move_nodes(pos, meta, nvm, lmove, max_speed, height, move2to1)
|
2021-11-15 21:26:59 +03:00
|
|
|
local owner = meta:get_string("owner")
|
2023-02-04 17:32:05 +03:00
|
|
|
techage.counting_add(owner, #lmove, #nvm.lpos1 * #lmove)
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2021-11-15 21:26:59 +03:00
|
|
|
for idx = 1, #nvm.lpos1 do
|
|
|
|
local pos1 = nvm.lpos1[idx]
|
|
|
|
local pos2 = nvm.lpos2[idx]
|
2023-02-04 17:32:05 +03:00
|
|
|
--print("multi_move_nodes", idx, P2S(pos1), P2S(pos2))
|
2021-11-15 21:26:59 +03:00
|
|
|
|
|
|
|
if move2to1 then
|
|
|
|
pos1, pos2 = pos2, pos1
|
|
|
|
end
|
|
|
|
|
|
|
|
if not minetest.is_protected(pos1, owner) and not minetest.is_protected(pos2, owner) then
|
|
|
|
if is_simple_node(pos1) and is_valid_dest(pos2) then
|
2023-02-04 17:32:05 +03:00
|
|
|
if move_node(pos, meta, pos1, lmove, max_speed, height) == false then
|
2022-12-09 23:17:01 +03:00
|
|
|
meta:set_string("status", S("No valid node at the start position"))
|
|
|
|
return false
|
|
|
|
end
|
2021-11-15 21:26:59 +03:00
|
|
|
else
|
|
|
|
if not is_simple_node(pos1) then
|
|
|
|
meta:set_string("status", S("No valid node at the start position"))
|
|
|
|
else
|
|
|
|
meta:set_string("status", S("No valid destination position"))
|
|
|
|
end
|
2022-12-06 20:43:10 +03:00
|
|
|
return false
|
2021-11-15 21:26:59 +03:00
|
|
|
end
|
|
|
|
else
|
|
|
|
if minetest.is_protected(pos1, owner) then
|
|
|
|
meta:set_string("status", S("Start position is protected"))
|
|
|
|
else
|
|
|
|
meta:set_string("status", S("Destination position is protected"))
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
2022-12-06 20:43:10 +03:00
|
|
|
meta:set_string("status", S("Running"))
|
2021-11-15 21:26:59 +03:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2023-03-05 23:44:35 +03:00
|
|
|
-- Move the nodes from lpos1 to lpos2.
|
2023-02-04 17:32:05 +03:00
|
|
|
-- * lpos1 is a list of nodes
|
|
|
|
-- * lpos2 = lpos1 + move
|
|
|
|
-- * pos and meta are controller block related
|
|
|
|
-- * height is move block height as value between 0 and 1 and used to calculate the offset
|
|
|
|
-- for the attached object (player).
|
|
|
|
local function move_nodes(pos, meta, lpos1, move, max_speed, height)
|
2022-06-23 21:36:36 +03:00
|
|
|
local owner = meta:get_string("owner")
|
2023-01-28 13:12:04 +03:00
|
|
|
lpos1 = lpos1 or {}
|
2022-06-23 21:36:36 +03:00
|
|
|
techage.counting_add(owner, #lpos1)
|
|
|
|
|
|
|
|
local lpos2 = {}
|
|
|
|
for idx = 1, #lpos1 do
|
2022-09-03 20:22:43 +03:00
|
|
|
|
2022-06-23 21:36:36 +03:00
|
|
|
local pos1 = lpos1[idx]
|
2023-02-04 17:32:05 +03:00
|
|
|
local pos2 = vector.add(lpos1[idx], move)
|
2022-06-23 21:36:36 +03:00
|
|
|
lpos2[idx] = pos2
|
2022-09-03 20:22:43 +03:00
|
|
|
|
2022-06-23 21:36:36 +03:00
|
|
|
if not minetest.is_protected(pos1, owner) and not minetest.is_protected(pos2, owner) then
|
|
|
|
if is_simple_node(pos1) and is_valid_dest(pos2) then
|
2023-02-04 17:32:05 +03:00
|
|
|
move_node(pos, meta, pos1, {move}, max_speed, height)
|
2022-06-23 21:36:36 +03:00
|
|
|
else
|
|
|
|
if not is_simple_node(pos1) then
|
|
|
|
meta:set_string("status", S("No valid node at the start position"))
|
|
|
|
else
|
|
|
|
meta:set_string("status", S("No valid destination position"))
|
|
|
|
end
|
2022-12-06 20:43:10 +03:00
|
|
|
return false, lpos1
|
2022-06-23 21:36:36 +03:00
|
|
|
end
|
|
|
|
else
|
|
|
|
if minetest.is_protected(pos1, owner) then
|
|
|
|
meta:set_string("status", S("Start position is protected"))
|
|
|
|
else
|
|
|
|
meta:set_string("status", S("Destination position is protected"))
|
|
|
|
end
|
|
|
|
return false, lpos1
|
|
|
|
end
|
|
|
|
end
|
2022-09-03 20:22:43 +03:00
|
|
|
|
2022-12-06 20:43:10 +03:00
|
|
|
meta:set_string("status", S("Running"))
|
2022-06-23 21:36:36 +03:00
|
|
|
return true, lpos2
|
|
|
|
end
|
|
|
|
|
2023-02-04 17:32:05 +03:00
|
|
|
-- move2to1 is the direction and is true for 'from pos2 to pos1'
|
|
|
|
-- Move path and other data is stored as meta data of pos
|
2022-01-03 23:40:31 +03:00
|
|
|
function flylib.move_to_other_pos(pos, move2to1)
|
2021-11-15 21:26:59 +03:00
|
|
|
local meta = M(pos)
|
|
|
|
local nvm = techage.get_nvm(pos)
|
2023-02-04 17:32:05 +03:00
|
|
|
local lmove, err = flylib.to_path(meta:get_string("path")) or {}
|
2021-11-15 21:26:59 +03:00
|
|
|
local max_speed = meta:contains("max_speed") and meta:get_int("max_speed") or MAX_SPEED
|
|
|
|
local height = meta:contains("height") and meta:get_float("height") or 1
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2022-12-06 20:43:10 +03:00
|
|
|
if err or nvm.running then return false end
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2021-11-15 21:26:59 +03:00
|
|
|
height = techage.in_range(height, 0, 1)
|
|
|
|
max_speed = techage.in_range(max_speed, MIN_SPEED, MAX_SPEED)
|
2021-11-28 16:42:18 +03:00
|
|
|
nvm.lpos1 = nvm.lpos1 or {}
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2023-02-04 17:32:05 +03:00
|
|
|
local offs = dest_offset(lmove)
|
2021-11-15 21:26:59 +03:00
|
|
|
if move2to1 then
|
2023-02-04 17:32:05 +03:00
|
|
|
lmove = reverse_path(lmove)
|
2021-11-15 21:26:59 +03:00
|
|
|
end
|
2021-11-28 16:42:18 +03:00
|
|
|
-- calc destination positions
|
|
|
|
nvm.lpos2 = lvect_add_vec(nvm.lpos1, offs)
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2023-02-04 17:32:05 +03:00
|
|
|
nvm.running = multi_move_nodes(pos, meta, nvm, lmove, max_speed, height, move2to1)
|
2022-12-06 20:43:10 +03:00
|
|
|
nvm.moveBA = nvm.running and not move2to1
|
|
|
|
return nvm.running
|
2021-11-15 21:26:59 +03:00
|
|
|
end
|
|
|
|
|
2023-02-04 17:32:05 +03:00
|
|
|
-- `move` the movement as a vector
|
|
|
|
function flylib.move_to(pos, move)
|
2022-06-23 21:36:36 +03:00
|
|
|
local meta = M(pos)
|
|
|
|
local nvm = techage.get_nvm(pos)
|
|
|
|
local height = techage.in_range(meta:contains("height") and meta:get_float("height") or 1, 0, 1)
|
|
|
|
local max_speed = meta:contains("max_speed") and meta:get_int("max_speed") or MAX_SPEED
|
|
|
|
|
2022-12-06 20:43:10 +03:00
|
|
|
if nvm.running then return false end
|
|
|
|
|
2023-02-04 17:32:05 +03:00
|
|
|
nvm.running, nvm.lastpos = move_nodes(pos, meta, nvm.lastpos or nvm.lpos1, move, max_speed, height)
|
2022-12-06 20:43:10 +03:00
|
|
|
return nvm.running
|
2022-06-23 21:36:36 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
function flylib.reset_move(pos)
|
|
|
|
local meta = M(pos)
|
|
|
|
local nvm = techage.get_nvm(pos)
|
|
|
|
local height = techage.in_range(meta:contains("height") and meta:get_float("height") or 1, 0, 1)
|
|
|
|
local max_speed = meta:contains("max_speed") and meta:get_int("max_speed") or MAX_SPEED
|
2022-12-06 20:43:10 +03:00
|
|
|
|
|
|
|
if nvm.running then return false end
|
|
|
|
|
2022-10-29 21:50:06 +03:00
|
|
|
if nvm.lpos1 and nvm.lpos1[1] then
|
|
|
|
local move = vector.subtract(nvm.lpos1[1], (nvm.lastpos or nvm.lpos1)[1])
|
2022-06-23 21:36:36 +03:00
|
|
|
|
2023-02-04 17:32:05 +03:00
|
|
|
nvm.running, nvm.lastpos = move_nodes(pos, meta, nvm.lastpos or nvm.lpos1, move, max_speed, height)
|
2022-12-06 20:43:10 +03:00
|
|
|
return nvm.running
|
2022-10-29 21:50:06 +03:00
|
|
|
end
|
|
|
|
return false
|
2022-06-23 21:36:36 +03:00
|
|
|
end
|
|
|
|
|
2023-02-04 17:32:05 +03:00
|
|
|
-- pos is the controller block pos
|
|
|
|
-- lpos is a list of node positions to be moved
|
2021-11-15 21:26:59 +03:00
|
|
|
-- rot is one of "l", "r", "2l", "2r"
|
2023-02-04 17:32:05 +03:00
|
|
|
function flylib.rotate_nodes(pos, lpos, rot)
|
2021-11-15 21:26:59 +03:00
|
|
|
local meta = M(pos)
|
|
|
|
local owner = meta:get_string("owner")
|
2023-02-04 17:32:05 +03:00
|
|
|
-- cpos is the center pos
|
2021-11-15 21:26:59 +03:00
|
|
|
local cpos = meta:contains("center") and flylib.to_vector(meta:get_string("center"))
|
2023-02-04 17:32:05 +03:00
|
|
|
local lpos2 = techage.rotate_around_center(lpos, rot, cpos)
|
2021-11-15 21:26:59 +03:00
|
|
|
local param2
|
|
|
|
local nodes2 = {}
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2023-02-04 17:32:05 +03:00
|
|
|
techage.counting_add(owner, #lpos * 2)
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2023-02-04 17:32:05 +03:00
|
|
|
for i, pos1 in ipairs(lpos) do
|
2021-11-15 21:26:59 +03:00
|
|
|
local node = techage.get_node_lvm(pos1)
|
|
|
|
if rot == "l" then
|
|
|
|
param2 = techage.param2_turn_right(node.param2)
|
2022-01-05 14:48:36 +03:00
|
|
|
elseif rot == "r" then
|
|
|
|
param2 = techage.param2_turn_left(node.param2)
|
2021-11-15 21:26:59 +03:00
|
|
|
else
|
2022-01-05 14:48:36 +03:00
|
|
|
param2 = techage.param2_turn_right(techage.param2_turn_right(node.param2))
|
2021-11-15 21:26:59 +03:00
|
|
|
end
|
|
|
|
if not minetest.is_protected(pos1, owner) and is_simple_node(pos1) then
|
|
|
|
minetest.remove_node(pos1)
|
2023-02-04 17:32:05 +03:00
|
|
|
nodes2[#nodes2 + 1] = {pos = lpos2[i], name = node.name, param2 = param2}
|
2021-11-15 21:26:59 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
for _,item in ipairs(nodes2) do
|
|
|
|
if not minetest.is_protected(item.pos, owner) and is_valid_dest(item.pos) then
|
|
|
|
minetest.add_node(item.pos, {name = item.name, param2 = item.param2})
|
|
|
|
end
|
|
|
|
end
|
2023-02-04 17:32:05 +03:00
|
|
|
return lpos2
|
2021-11-15 21:26:59 +03:00
|
|
|
end
|
|
|
|
|
2022-06-10 11:59:59 +03:00
|
|
|
function flylib.exchange_node(pos, name, param2)
|
|
|
|
local meta = M(pos)
|
|
|
|
local move_block
|
2022-09-03 20:22:43 +03:00
|
|
|
|
2022-06-10 11:59:59 +03:00
|
|
|
-- consider stored "objects"
|
|
|
|
if meta:contains("ta_move_block") then
|
|
|
|
move_block = meta:get_string("ta_move_block")
|
|
|
|
end
|
2022-09-03 20:22:43 +03:00
|
|
|
|
2022-06-10 11:59:59 +03:00
|
|
|
minetest.swap_node(pos, {name = name, param2 = param2})
|
2022-09-03 20:22:43 +03:00
|
|
|
|
2022-06-10 11:59:59 +03:00
|
|
|
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
|
2022-09-03 20:22:43 +03:00
|
|
|
|
2022-06-10 11:59:59 +03:00
|
|
|
-- consider stored "objects"
|
|
|
|
if meta:contains("ta_move_block") then
|
|
|
|
move_block = meta:get_string("ta_move_block")
|
|
|
|
end
|
2022-09-03 20:22:43 +03:00
|
|
|
|
2022-06-10 11:59:59 +03:00
|
|
|
minetest.remove_node(pos)
|
2022-09-03 20:22:43 +03:00
|
|
|
|
2022-06-10 11:59:59 +03:00
|
|
|
if move_block then
|
|
|
|
local node = minetest.deserialize(move_block)
|
|
|
|
minetest.add_node(pos, node)
|
|
|
|
meta:set_string("ta_move_block", "")
|
|
|
|
end
|
|
|
|
end
|
2021-11-15 21:26:59 +03:00
|
|
|
|
2023-02-11 20:00:27 +03:00
|
|
|
minetest.register_node("techage:moveblock", {
|
|
|
|
description = "Techage Move Block",
|
|
|
|
drawtype = "normal",
|
|
|
|
tiles = {"techage_invisible.png"},
|
|
|
|
sunlight_propagates = true,
|
|
|
|
walkable = false,
|
|
|
|
pointable = false,
|
|
|
|
diggable = false,
|
|
|
|
buildable_to = true,
|
|
|
|
floodable = true,
|
|
|
|
is_ground_content = false,
|
|
|
|
groups = {not_in_creative_inventory=1},
|
|
|
|
drop = "",
|
|
|
|
})
|
|
|
|
|
2021-11-15 21:26:59 +03:00
|
|
|
minetest.register_on_joinplayer(function(player)
|
|
|
|
unlock_player(player)
|
|
|
|
end)
|
|
|
|
|
|
|
|
minetest.register_on_leaveplayer(function(player)
|
|
|
|
if unlock_player(player) then
|
|
|
|
detach_player(player)
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
minetest.register_on_dieplayer(function(player)
|
|
|
|
if unlock_player(player) then
|
|
|
|
detach_player(player)
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2022-12-06 20:43:10 +03:00
|
|
|
techage.flylib = flylib
|