Finish movecontroller
This commit is contained in:
parent
43bb2705cf
commit
0ffb786a57
4
init.lua
4
init.lua
@ -264,7 +264,7 @@ dofile(MP.."/logic/repeater.lua")
|
|||||||
dofile(MP.."/logic/programmer.lua")
|
dofile(MP.."/logic/programmer.lua")
|
||||||
dofile(MP.."/logic/signallamp.lua")
|
dofile(MP.."/logic/signallamp.lua")
|
||||||
dofile(MP.."/logic/sequencer.lua")
|
dofile(MP.."/logic/sequencer.lua")
|
||||||
--dofile(MP.."/logic/sequencer2.lua") still under dev.
|
dofile(MP.."/logic/sequencer2.lua")
|
||||||
dofile(MP.."/logic/timer.lua")
|
dofile(MP.."/logic/timer.lua")
|
||||||
dofile(MP.."/logic/lua_logic.lua") -- old
|
dofile(MP.."/logic/lua_logic.lua") -- old
|
||||||
dofile(MP.."/logic/logic_block.lua") -- new
|
dofile(MP.."/logic/logic_block.lua") -- new
|
||||||
@ -277,7 +277,7 @@ dofile(MP.."/logic/doorcontroller.lua") -- old
|
|||||||
dofile(MP.."/logic/doorcontroller2.lua") -- new
|
dofile(MP.."/logic/doorcontroller2.lua") -- new
|
||||||
dofile(MP.."/logic/collector.lua")
|
dofile(MP.."/logic/collector.lua")
|
||||||
dofile(MP.."/logic/button_4x.lua")
|
dofile(MP.."/logic/button_4x.lua")
|
||||||
--dofile(MP.."/logic/movecontroller.lua") still under dev.
|
dofile(MP.."/logic/movecontroller.lua")
|
||||||
if minetest.global_exists("mesecon") then
|
if minetest.global_exists("mesecon") then
|
||||||
dofile(MP.."/logic/mesecons_converter.lua")
|
dofile(MP.."/logic/mesecons_converter.lua")
|
||||||
end
|
end
|
||||||
|
@ -22,15 +22,15 @@ local S = techage.S
|
|||||||
-- Entity / Move / Attach / Detach
|
-- Entity / Move / Attach / Detach
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
local MIN_SPEED = 0.4
|
local MIN_SPEED = 0.4
|
||||||
local MAX_SPEED = 10
|
local MAX_SPEED = 8
|
||||||
|
|
||||||
local function to_vector(s)
|
local function to_vector(s)
|
||||||
local x,y,z = unpack(string.split(s, ","))
|
local x,y,z = unpack(string.split(s, ","))
|
||||||
if x and y and z then
|
if x and y and z then
|
||||||
return {
|
return {
|
||||||
x = tonumber(x) or 0,
|
x=tonumber(x) or 0,
|
||||||
y = tonumber(y) or 0,
|
y=tonumber(y) or 0,
|
||||||
z = tonumber(z) or 0,
|
z=tonumber(z) or 0,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
return {x=0, y=0, z=0}
|
return {x=0, y=0, z=0}
|
||||||
@ -52,7 +52,6 @@ local function obj_pos(obj)
|
|||||||
return vector.add(obj:get_pos(), pos)
|
return vector.add(obj:get_pos(), pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Check access conflicts with other mods
|
-- Check access conflicts with other mods
|
||||||
local function lock_player(player)
|
local function lock_player(player)
|
||||||
local meta = player:get_meta()
|
local meta = player:get_meta()
|
||||||
@ -79,118 +78,134 @@ end
|
|||||||
local function detach_player(player)
|
local function detach_player(player)
|
||||||
local pos = obj_pos(player)
|
local pos = obj_pos(player)
|
||||||
player:set_detach()
|
player:set_detach()
|
||||||
player:set_properties({visual_size = {x = 1, y = 1}})
|
player:set_properties({visual_size = {x=1, y=1}})
|
||||||
player:set_pos(pos)
|
player:set_pos(pos)
|
||||||
-- TODO: move to save position
|
-- TODO: move to save position
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Attach player/mob to given parent object (block)
|
-- Attach player/mob to given parent object (block)
|
||||||
local function attach_single_object(parent, obj, dir, height)
|
local function attach_single_object(parent, obj, dir)
|
||||||
local self = parent:get_luaentity()
|
local self = parent:get_luaentity()
|
||||||
local rot = {x=0, y=0, z=0}
|
local rot = obj:get_rotation()
|
||||||
local prop = obj:get_properties()
|
|
||||||
local res = obj:get_attach()
|
local res = obj:get_attach()
|
||||||
if not res and prop and prop.collisionbox then
|
if not res then
|
||||||
dir = table.copy(dir)
|
local offs = table.copy(dir)
|
||||||
dir.y = dir.y - 1.5 + (height or 1) - prop.collisionbox[2]
|
|
||||||
dir = vector.multiply(dir, 29)
|
dir = vector.multiply(dir, 29)
|
||||||
obj:set_attach(parent, "", dir, rot, true)
|
obj:set_attach(parent, "", dir, rot, true)
|
||||||
obj:set_properties({visual_size = {x = 2.9, y = 2.9}})
|
obj:set_properties({visual_size = {x=2.9, y=2.9}})
|
||||||
if obj:is_player() then
|
if obj:is_player() then
|
||||||
if lock_player(obj) then
|
if lock_player(obj) then
|
||||||
table.insert(self.players, obj:get_player_name())
|
table.insert(self.players, {name = obj:get_player_name(), offs = offs})
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
table.insert(self.entities, get_object_id(obj))
|
table.insert(self.entities, {objID = get_object_id(obj), offs = offs})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Attach all entities around to the parent object (block).
|
-- Attach all objects around to the parent object
|
||||||
-- height is the parent block height (0.1 to 1.0)
|
-- offs is the search/attach position offset
|
||||||
local function attach_objects(pos, parent, dir, height)
|
local function attach_objects(pos, offs, parent)
|
||||||
local pos1 = vector.add(pos, dir)
|
local pos1 = vector.add(pos, offs)
|
||||||
local self = parent:get_luaentity()
|
|
||||||
self.players = self.players or {}
|
|
||||||
self.entities = self.entities or {}
|
|
||||||
|
|
||||||
print("pos1", P2S(pos1))
|
|
||||||
for _, obj in pairs(minetest.get_objects_inside_radius(pos1, 0.9)) do
|
for _, obj in pairs(minetest.get_objects_inside_radius(pos1, 0.9)) do
|
||||||
|
local dir = vector.subtract(obj:get_pos(), pos)
|
||||||
local entity = obj:get_luaentity()
|
local entity = obj:get_luaentity()
|
||||||
if entity then
|
if entity then
|
||||||
if entity.name == "__builtin:item" then -- dropped items
|
if entity.name == "__builtin:item" then -- dropped items
|
||||||
--obj:set_attach(objref, "", {x=0, y=0, z=0}, {x=0, y=0, z=0}, true) -- hier kracht es
|
--obj:set_attach(objref, "", {x=0, y=0, z=0}, {x=0, y=0, z=0}, true) -- hier kracht es
|
||||||
elseif entity.name ~= "techage:move_item" then
|
elseif entity.name ~= "techage:move_item" then
|
||||||
attach_single_object(parent, obj, dir, 1)
|
attach_single_object(parent, obj, dir)
|
||||||
end
|
end
|
||||||
elseif obj:is_player() then
|
elseif obj:is_player() then
|
||||||
print("is_player")
|
attach_single_object(parent, obj, dir)
|
||||||
attach_single_object(parent, obj, dir, 1)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Detach all attached entities from the parent object (block)
|
-- Detach all attached objects from the parent object
|
||||||
local function detach_objects(pos, parent, dir)
|
local function detach_objects(pos, self)
|
||||||
local self = parent:get_luaentity()
|
for _, item in ipairs(self.entities or {}) do
|
||||||
|
local entity = minetest.luaentities[item.objID]
|
||||||
for _, objID in ipairs(self.entities or {}) do
|
|
||||||
local entity = minetest.luaentities[objID]
|
|
||||||
if entity then
|
if entity then
|
||||||
local obj = entity.object
|
local obj = entity.object
|
||||||
local pos1 = obj_pos(obj)
|
|
||||||
obj:set_detach()
|
obj:set_detach()
|
||||||
obj:set_properties({visual_size = {x = 1, y = 1}})
|
obj:set_properties({visual_size = {x=1, y=1}})
|
||||||
|
local pos1 = vector.add(pos, item.offs)
|
||||||
obj:set_pos(pos1)
|
obj:set_pos(pos1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for _, name in ipairs(self.players or {}) do
|
for _, item in ipairs(self.players or {}) do
|
||||||
local obj = minetest.get_player_by_name(name)
|
local obj = minetest.get_player_by_name(item.name)
|
||||||
if obj then
|
if obj then
|
||||||
local pos1 = obj_pos(obj)
|
|
||||||
obj:set_detach()
|
obj:set_detach()
|
||||||
obj:set_properties({visual_size = {x = 1, y = 1}})
|
obj:set_properties({visual_size = {x=1, y=1}})
|
||||||
|
local pos1 = vector.add(pos, item.offs)
|
||||||
obj:set_pos(pos1)
|
obj:set_pos(pos1)
|
||||||
unlock_player(obj)
|
unlock_player(obj)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
self.entities = nil
|
self.entities = {}
|
||||||
self.players = nil
|
self.players = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
local function entity_to_node(pos, obj)
|
local function entity_to_node(pos, obj)
|
||||||
local name = (obj:get_luaentity() or {}).item or "air"
|
local self = obj:get_luaentity()
|
||||||
local rot = obj:get_rotation()
|
if self then
|
||||||
detach_objects(pos, obj)
|
local name = self.item or "air"
|
||||||
obj:remove()
|
local metadata = self.metadata or {}
|
||||||
|
local rot = obj:get_rotation()
|
||||||
pos = vector.round(pos)
|
detach_objects(pos, self)
|
||||||
local dir = minetest.yaw_to_dir(rot.y or 0)
|
obj:remove()
|
||||||
local param2 = minetest.dir_to_facedir(dir) or 0
|
|
||||||
local node = minetest.get_node(pos)
|
pos = vector.round(pos)
|
||||||
local ndef1 = minetest.registered_nodes[name]
|
local dir = minetest.yaw_to_dir(rot.y or 0)
|
||||||
local ndef2 = minetest.registered_nodes[node.name]
|
local param2 = minetest.dir_to_facedir(dir) or 0
|
||||||
if ndef1 and ndef2 and ndef2.buildable_to then
|
local node = minetest.get_node(pos)
|
||||||
minetest.set_node(pos, {name = name, param2 = param2})
|
local ndef1 = minetest.registered_nodes[name]
|
||||||
elseif ndef1 then
|
local ndef2 = minetest.registered_nodes[node.name]
|
||||||
minetest.add_item(pos, ItemStack(name))
|
if ndef1 and ndef2 then
|
||||||
|
if ndef2.buildable_to then
|
||||||
|
local meta = M(pos)
|
||||||
|
minetest.set_node(pos, {name=name, param2=param2})
|
||||||
|
meta:from_table(metadata)
|
||||||
|
meta:set_string("ta_move_block", "")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local meta = M(pos)
|
||||||
|
if not meta:contains("ta_move_block") then
|
||||||
|
meta:set_string("ta_move_block", minetest.serialize({name=name, param2=param2}))
|
||||||
|
end
|
||||||
|
elseif ndef1 then
|
||||||
|
minetest.add_item(pos, ItemStack(name))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function node_to_entity(pos, handover)
|
local function node_to_entity(pos, handover)
|
||||||
local node = minetest.get_node(pos)
|
local meta = M(pos)
|
||||||
minetest.remove_node(pos)
|
local node, metadata
|
||||||
|
|
||||||
|
if meta:contains("ta_move_block") then
|
||||||
|
node = minetest.deserialize(meta:get_string("ta_move_block"))
|
||||||
|
metadata = {}
|
||||||
|
meta:set_string("ta_move_block", "")
|
||||||
|
else
|
||||||
|
node = minetest.get_node(pos)
|
||||||
|
meta:set_string("ta_move_block", "")
|
||||||
|
metadata = meta:to_table()
|
||||||
|
minetest.remove_node(pos)
|
||||||
|
end
|
||||||
local dir = minetest.facedir_to_dir(node.param2)
|
local dir = minetest.facedir_to_dir(node.param2)
|
||||||
local yaw = minetest.dir_to_yaw(dir)
|
local yaw = minetest.dir_to_yaw(dir)
|
||||||
local obj = minetest.add_entity(pos, "techage:move_item")
|
local obj = minetest.add_entity(pos, "techage:move_item")
|
||||||
if obj then
|
if obj then
|
||||||
local self = obj:get_luaentity()
|
local self = obj:get_luaentity()
|
||||||
obj:set_rotation({x=0, y=yaw, z=0})
|
obj:set_rotation({x=0, y=yaw, z=0})
|
||||||
obj:set_properties({wield_item = node.name})
|
obj:set_properties({wield_item=node.name})
|
||||||
obj:set_armor_groups({immortal=1})
|
obj:set_armor_groups({immortal=1})
|
||||||
self.item = node.name
|
self.item = node.name
|
||||||
|
self.metadata = metadata or {}
|
||||||
self.handover = handover
|
self.handover = handover
|
||||||
self.start_pos = table.copy(pos)
|
self.start_pos = table.copy(pos)
|
||||||
return obj
|
return obj
|
||||||
@ -259,6 +274,7 @@ minetest.register_entity("techage:move_item", {
|
|||||||
dest_pos = self.dest_pos,
|
dest_pos = self.dest_pos,
|
||||||
start_pos = self.start_pos,
|
start_pos = self.start_pos,
|
||||||
dir = self.dir,
|
dir = self.dir,
|
||||||
|
metadata = self.metadata,
|
||||||
respawn = true,
|
respawn = true,
|
||||||
})
|
})
|
||||||
end,
|
end,
|
||||||
@ -271,6 +287,7 @@ minetest.register_entity("techage:move_item", {
|
|||||||
self.dest_pos = tbl.dest_pos or self.object:get_pos()
|
self.dest_pos = tbl.dest_pos or self.object:get_pos()
|
||||||
self.start_pos = tbl.start_pos or self.object:get_pos()
|
self.start_pos = tbl.start_pos or self.object:get_pos()
|
||||||
self.dir = tbl.dir or {x=0, y=0, z=0}
|
self.dir = tbl.dir or {x=0, y=0, z=0}
|
||||||
|
self.metadata = tbl.metadata or {}
|
||||||
self.object:set_properties({wield_item = self.item})
|
self.object:set_properties({wield_item = self.item})
|
||||||
if tbl.respawn then
|
if tbl.respawn then
|
||||||
entity_to_node(self.start_pos, self.object)
|
entity_to_node(self.start_pos, self.object)
|
||||||
@ -324,12 +341,15 @@ local MarkedNodes = {} -- t[player] = {{entity, pos},...}
|
|||||||
local CurrentPos -- to mark punched entities
|
local CurrentPos -- to mark punched entities
|
||||||
local SimpleNodes = techage.logic.SimpleNodes
|
local SimpleNodes = techage.logic.SimpleNodes
|
||||||
|
|
||||||
local function is_air_like(pos)
|
local function is_valid_dest(pos)
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
local ndef = minetest.registered_nodes[node.name]
|
local ndef = minetest.registered_nodes[node.name]
|
||||||
if ndef and ndef.buildable_to then
|
if ndef and ndef.buildable_to then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
if not M(pos):contains("ta_move_block") then
|
||||||
|
return true
|
||||||
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -431,7 +451,7 @@ minetest.register_entity(":techage:moveblock_marker", {
|
|||||||
},
|
},
|
||||||
--use_texture_alpha = true,
|
--use_texture_alpha = true,
|
||||||
physical = false,
|
physical = false,
|
||||||
visual_size = {x = 1.1, y = 1.1},
|
visual_size = {x=1.1, y=1.1},
|
||||||
collisionbox = {-0.55,-0.55,-0.55, 0.55,0.55,0.55},
|
collisionbox = {-0.55,-0.55,-0.55, 0.55,0.55,0.55},
|
||||||
glow = 8,
|
glow = 8,
|
||||||
},
|
},
|
||||||
@ -457,11 +477,11 @@ minetest.register_entity(":techage:moveblock_marker", {
|
|||||||
local WRENCH_MENU = {
|
local WRENCH_MENU = {
|
||||||
{
|
{
|
||||||
type = "dropdown",
|
type = "dropdown",
|
||||||
choices = "0.5,1,2,4,6,8,10",
|
choices = "0.5,1,2,4,6,8",
|
||||||
name = "max_speed",
|
name = "max_speed",
|
||||||
label = S("Maximum Speed"),
|
label = S("Maximum Speed"),
|
||||||
tooltip = S("Maximum speed for the moving block."),
|
tooltip = S("Maximum speed for the moving block."),
|
||||||
default = "10",
|
default = "8",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type = "number",
|
type = "number",
|
||||||
@ -509,12 +529,16 @@ local function move_node(pos, pos1, pos2, max_speed, handover, height)
|
|||||||
local meta = M(pos)
|
local meta = M(pos)
|
||||||
local dir = determine_dir(pos1, pos2)
|
local dir = determine_dir(pos1, pos2)
|
||||||
local obj = node_to_entity(pos1, handover)
|
local obj = node_to_entity(pos1, handover)
|
||||||
|
local self = obj:get_luaentity()
|
||||||
|
self.players = {}
|
||||||
|
self.entities = {}
|
||||||
|
|
||||||
if obj then
|
if obj then
|
||||||
attach_objects(pos1, obj, {x=0, y=height, z=0}, height)
|
local offs = {x=0, y=height or 1, z=0}
|
||||||
|
attach_objects(pos1, offs, obj)
|
||||||
if dir.y == 0 then
|
if dir.y == 0 then
|
||||||
if (dir.x ~= 0 and dir.z == 0) or (dir.x == 0 and dir.z ~= 0) then
|
if (dir.x ~= 0 and dir.z == 0) or (dir.x == 0 and dir.z ~= 0) then
|
||||||
attach_objects(pos1, obj, dir, 1)
|
attach_objects(pos1, dir, obj)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
move_entity(obj, pos2, dir, max_speed)
|
move_entity(obj, pos2, dir, max_speed)
|
||||||
@ -533,7 +557,7 @@ local function move_nodes(pos, lpos1, lpos2, handover)
|
|||||||
local pos1 = lpos1[idx]
|
local pos1 = lpos1[idx]
|
||||||
local pos2 = lpos2[idx]
|
local pos2 = lpos2[idx]
|
||||||
if not minetest.is_protected(pos1, owner) and not minetest.is_protected(pos2, owner) then
|
if not minetest.is_protected(pos1, owner) and not minetest.is_protected(pos2, owner) then
|
||||||
if is_simple_node(pos1) and is_air_like(pos2) then
|
if is_simple_node(pos1) and is_valid_dest(pos2) then
|
||||||
move_node(pos, pos1, pos2, max_speed, handover, height)
|
move_node(pos, pos1, pos2, max_speed, handover, height)
|
||||||
else
|
else
|
||||||
if not is_simple_node(pos1) then
|
if not is_simple_node(pos1) then
|
||||||
@ -573,7 +597,7 @@ local function moveon_nodes(pos, lpos1, lpos2, handover)
|
|||||||
local pos1 = lpos1[idx]
|
local pos1 = lpos1[idx]
|
||||||
local pos2 = lpos2[idx]
|
local pos2 = lpos2[idx]
|
||||||
if not minetest.is_protected(pos1, owner) and not minetest.is_protected(pos2, owner) then
|
if not minetest.is_protected(pos1, owner) and not minetest.is_protected(pos2, owner) then
|
||||||
if is_air_like(pos2) then
|
if is_valid_dest(pos2) then
|
||||||
local dir = determine_dir(pos1, pos2)
|
local dir = determine_dir(pos1, pos2)
|
||||||
local obj = capture_entity(pos1)
|
local obj = capture_entity(pos1)
|
||||||
if obj then
|
if obj then
|
||||||
@ -584,7 +608,7 @@ local function moveon_nodes(pos, lpos1, lpos2, handover)
|
|||||||
if not is_simple_node(pos1) then
|
if not is_simple_node(pos1) then
|
||||||
meta:set_string("status", S("No valid node at the start position"))
|
meta:set_string("status", S("No valid node at the start position"))
|
||||||
else
|
else
|
||||||
meta:set_string("status", S("No air at the destination position"))
|
meta:set_string("status", S("No valid destination position"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user