mirror of
https://github.com/minetest-mods/technic.git
synced 2025-01-03 03:07:36 +01:00
Make those frames able to move
This commit is contained in:
parent
68f7d34e1b
commit
8fba5e1140
@ -3,6 +3,8 @@ local S = technic.getter
|
|||||||
|
|
||||||
frames = {}
|
frames = {}
|
||||||
|
|
||||||
|
local frames_pos = {}
|
||||||
|
|
||||||
-- Helpers
|
-- Helpers
|
||||||
|
|
||||||
local function get_face(pos,ppos,pvect)
|
local function get_face(pos,ppos,pvect)
|
||||||
@ -99,7 +101,7 @@ local function move_nodes_vect(poslist,vect,must_not_move,owner)
|
|||||||
for _,pos in ipairs(poslist) do
|
for _,pos in ipairs(poslist) do
|
||||||
local npos=vector.add(pos,vect)
|
local npos=vector.add(pos,vect)
|
||||||
local name = minetest.env:get_node(npos).name
|
local name = minetest.env:get_node(npos).name
|
||||||
if (name~="air" and minetest.registered_nodes[name].liquidtype=="none") and not(pos_in_list(poslist,npos)) then
|
if (name~="air" and minetest.registered_nodes[name].liquidtype=="none" and frames_pos[pos_to_string(npos)]) and not(pos_in_list(poslist,npos)) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
--[[if pos.x==must_not_move.x and pos.y==must_not_move.y and pos.z==must_not_move.z then
|
--[[if pos.x==must_not_move.x and pos.y==must_not_move.y and pos.z==must_not_move.z then
|
||||||
@ -107,10 +109,15 @@ local function move_nodes_vect(poslist,vect,must_not_move,owner)
|
|||||||
end]]
|
end]]
|
||||||
end
|
end
|
||||||
nodelist={}
|
nodelist={}
|
||||||
|
frameslist = {}
|
||||||
for _,pos in ipairs(poslist) do
|
for _,pos in ipairs(poslist) do
|
||||||
local node=minetest.env:get_node(pos)
|
local node=minetest.env:get_node(pos)
|
||||||
local meta=minetest.env:get_meta(pos):to_table()
|
local meta=minetest.env:get_meta(pos):to_table()
|
||||||
nodelist[#(nodelist)+1]={pos=pos,node=node,meta=meta}
|
nodelist[#(nodelist)+1]={pos=pos,node=node,meta=meta}
|
||||||
|
if frames_pos[pos_to_string(pos)] then
|
||||||
|
frameslist[#frameslist+1] = {pos=pos, name=frames_pos[pos_to_string(pos)]}
|
||||||
|
frames_pos[pos_to_string(pos)] = nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
objects={}
|
objects={}
|
||||||
for _,pos in ipairs(poslist) do
|
for _,pos in ipairs(poslist) do
|
||||||
@ -125,6 +132,10 @@ local function move_nodes_vect(poslist,vect,must_not_move,owner)
|
|||||||
le.start_pos=vector.add(le.start_pos,vect)
|
le.start_pos=vector.add(le.start_pos,vect)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
for _, n in ipairs(frameslist) do
|
||||||
|
local npos=vector.add(n.pos,vect)
|
||||||
|
frames_pos[pos_to_string(npos)] = n.name
|
||||||
|
end
|
||||||
for _,n in ipairs(nodelist) do
|
for _,n in ipairs(nodelist) do
|
||||||
local npos=vector.add(n.pos,vect)
|
local npos=vector.add(n.pos,vect)
|
||||||
minetest.env:set_node(npos,n.node)
|
minetest.env:set_node(npos,n.node)
|
||||||
@ -142,6 +153,9 @@ local function move_nodes_vect(poslist,vect,must_not_move,owner)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function is_supported_node(name)
|
||||||
|
return ((string.find(name, "tube") ~= nil) and (string.find(name, "pipeworks") ~= nil))
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Frames
|
-- Frames
|
||||||
@ -213,8 +227,7 @@ local nodeboxes= {
|
|||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
frame=1,
|
frame=1,
|
||||||
drop="technic:frame_111111",
|
drop="technic:frame_111111",
|
||||||
frame_connect_all=function(pos)
|
frame_connect_all=function(nodename)
|
||||||
local nodename=minetest.env:get_node(pos).name
|
|
||||||
l2={}
|
l2={}
|
||||||
l1={{x=-1,y=0,z=0},{x=1,y=0,z=0},{x=0,y=-1,z=0},{x=0,y=1,z=0},{x=0,y=0,z=-1},{x=0,y=0,z=1}}
|
l1={{x=-1,y=0,z=0},{x=1,y=0,z=0},{x=0,y=-1,z=0},{x=0,y=1,z=0},{x=0,y=0,z=-1},{x=0,y=0,z=1}}
|
||||||
for i,dir in ipairs(l1) do
|
for i,dir in ipairs(l1) do
|
||||||
@ -244,8 +257,10 @@ local nodeboxes= {
|
|||||||
if pos == nil then return end
|
if pos == nil then return end
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
if node.name ~= "air" then
|
if node.name ~= "air" then
|
||||||
obj = minetest.add_entity(pos, "technic:frame_entity")
|
if is_supported_node(node.name) then
|
||||||
obj:get_luaentity():set_node({name=itemstack:get_name()})
|
obj = minetest.add_entity(pos, "technic:frame_entity")
|
||||||
|
obj:get_luaentity():set_node({name=itemstack:get_name()})
|
||||||
|
end
|
||||||
else
|
else
|
||||||
minetest.set_node(pos, {name = itemstack:get_name()})
|
minetest.set_node(pos, {name = itemstack:get_name()})
|
||||||
end
|
end
|
||||||
@ -273,6 +288,9 @@ minetest.register_entity("technic:frame_entity", {
|
|||||||
|
|
||||||
set_node = function(self, node)
|
set_node = function(self, node)
|
||||||
self.node = node
|
self.node = node
|
||||||
|
local pos = self.object:getpos()
|
||||||
|
pos = {x = math.floor(pos.x+0.5), y = math.floor(pos.y+0.5), z = math.floor(pos.z+0.5)}
|
||||||
|
frames_pos[pos_to_string(pos)] = node.name
|
||||||
local stack = ItemStack(node.name)
|
local stack = ItemStack(node.name)
|
||||||
local itemtable = stack:to_table()
|
local itemtable = stack:to_table()
|
||||||
local itemname = nil
|
local itemname = nil
|
||||||
@ -303,6 +321,9 @@ minetest.register_entity("technic:frame_entity", {
|
|||||||
|
|
||||||
dig = function(self)
|
dig = function(self)
|
||||||
minetest.handle_node_drops(self.object:getpos(), {ItemStack("technic:frame_111111")}, self.last_puncher)
|
minetest.handle_node_drops(self.object:getpos(), {ItemStack("technic:frame_111111")}, self.last_puncher)
|
||||||
|
local pos = self.object:getpos()
|
||||||
|
pos = {x = math.floor(pos.x+0.5), y = math.floor(pos.y+0.5), z = math.floor(pos.z+0.5)}
|
||||||
|
frames_pos[pos_to_string(pos)] = nil
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
end,
|
end,
|
||||||
|
|
||||||
@ -390,13 +411,16 @@ minetest.register_entity("technic:damage_entity", {
|
|||||||
local function connected(pos,c,adj)
|
local function connected(pos,c,adj)
|
||||||
for _,vect in ipairs(adj) do
|
for _,vect in ipairs(adj) do
|
||||||
local pos1=vector.add(pos,vect)
|
local pos1=vector.add(pos,vect)
|
||||||
local nodename=minetest.env:get_node(pos1).name
|
local nodename=minetest.get_node(pos1).name
|
||||||
|
if frames_pos[pos_to_string(pos1)] then
|
||||||
|
nodename = frames_pos[pos_to_string(pos1)]
|
||||||
|
end
|
||||||
if not(pos_in_list(c,pos1)) and nodename~="air" and
|
if not(pos_in_list(c,pos1)) and nodename~="air" and
|
||||||
(minetest.registered_nodes[nodename].frames_can_connect==nil or
|
(minetest.registered_nodes[nodename].frames_can_connect==nil or
|
||||||
minetest.registered_nodes[nodename].frames_can_connect(pos1,vect)) then
|
minetest.registered_nodes[nodename].frames_can_connect(pos1,vect)) then
|
||||||
c[#(c)+1]=pos1
|
c[#(c)+1]=pos1
|
||||||
if minetest.registered_nodes[nodename].frame==1 then
|
if minetest.registered_nodes[nodename].frame==1 then
|
||||||
local adj=minetest.registered_nodes[nodename].frame_connect_all(pos1)
|
local adj=minetest.registered_nodes[nodename].frame_connect_all(nodename)
|
||||||
connected(pos1,c,adj)
|
connected(pos1,c,adj)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -406,7 +430,10 @@ end
|
|||||||
local function get_connected_nodes(pos)
|
local function get_connected_nodes(pos)
|
||||||
c={pos}
|
c={pos}
|
||||||
local nodename=minetest.env:get_node(pos).name
|
local nodename=minetest.env:get_node(pos).name
|
||||||
connected(pos,c,minetest.registered_nodes[nodename].frame_connect_all(pos))
|
if frames_pos[pos_to_string(pos)] then
|
||||||
|
nodename = frames_pos[pos_to_string(pos)]
|
||||||
|
end
|
||||||
|
connected(pos,c,minetest.registered_nodes[nodename].frame_connect_all(nodename))
|
||||||
return c
|
return c
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -415,6 +442,9 @@ local function frame_motor_on(pos, node)
|
|||||||
local nnodepos = vector.add(pos, dirs[math.floor(node.param2/4)+1])
|
local nnodepos = vector.add(pos, dirs[math.floor(node.param2/4)+1])
|
||||||
local dir = minetest.facedir_to_dir(node.param2)
|
local dir = minetest.facedir_to_dir(node.param2)
|
||||||
local nnode=minetest.get_node(nnodepos)
|
local nnode=minetest.get_node(nnodepos)
|
||||||
|
if frames_pos[pos_to_string(nnodepos)] then
|
||||||
|
nnode.name = frames_pos[pos_to_string(nnodepos)]
|
||||||
|
end
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local owner = meta:get_string("owner")
|
local owner = meta:get_string("owner")
|
||||||
if minetest.registered_nodes[nnode.name].frame==1 then
|
if minetest.registered_nodes[nnode.name].frame==1 then
|
||||||
|
Loading…
Reference in New Issue
Block a user