| | |
| | | |
| | | frames = {} |
| | | |
| | | local infinite_stacks = minetest.setting_getbool("creative_mode") and minetest.get_modpath("unified_inventory") == nil |
| | | |
| | | local frames_pos = {} |
| | | |
| | | -- Helpers |
| | |
| | | end |
| | | |
| | | local function add_table(table,toadd) |
| | | local i=1 |
| | | local i = 1 |
| | | while true do |
| | | o=table[i] |
| | | if o==toadd then return end |
| | | if o==nil then break end |
| | | i=i+1 |
| | | o = table[i] |
| | | if o == toadd then return end |
| | | if o == nil then break end |
| | | i = i+1 |
| | | end |
| | | table[i]=toadd |
| | | table[i] = toadd |
| | | end |
| | | |
| | | local function move_nodes_vect(poslist,vect,must_not_move,owner) |
| | |
| | | return |
| | | end]] |
| | | end |
| | | nodelist={} |
| | | frameslist = {} |
| | | for _,pos in ipairs(poslist) do |
| | | local node=minetest.get_node(pos) |
| | | local meta=minetest.get_meta(pos):to_table() |
| | | 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 |
| | | local nodelist = {} |
| | | for _, pos in ipairs(poslist) do |
| | | local node = minetest.get_node(pos) |
| | | local meta = minetest.get_meta(pos):to_table() |
| | | nodelist[#(nodelist)+1] = {oldpos = pos, pos = vector.add(pos, vect), node = node, meta = meta} |
| | | end |
| | | objects={} |
| | | for _,pos in ipairs(poslist) do |
| | | local objects = {} |
| | | for _, pos in ipairs(poslist) do |
| | | for _,object in ipairs(minetest.get_objects_inside_radius(pos, 1)) do |
| | | add_table(objects,object) |
| | | local entity = object:get_luaentity() |
| | | if not entity or not mesecon:is_mvps_unmov(entity.name) then |
| | | add_table(objects, object) |
| | | end |
| | | end |
| | | end |
| | | for _,obj in ipairs(objects) do |
| | | obj:setpos(vector.add(obj:getpos(),vect)) |
| | | le=obj:get_luaentity() |
| | | if le and le.name == "pipeworks:tubed_item" then |
| | | le.start_pos=vector.add(le.start_pos,vect) |
| | | end |
| | | end |
| | | for _, n in ipairs(frameslist) do |
| | | local npos=vector.add(n.pos,vect) |
| | | frames_pos[pos_to_string(npos)] = n.name |
| | | for _, obj in ipairs(objects) do |
| | | obj:setpos(vector.add(obj:getpos(), vect)) |
| | | end |
| | | for _,n in ipairs(nodelist) do |
| | | local npos=vector.add(n.pos,vect) |
| | | minetest.set_node(npos,n.node) |
| | | local meta=minetest.get_meta(npos) |
| | | local npos = n.pos |
| | | minetest.set_node(npos, n.node) |
| | | local meta = minetest.get_meta(npos) |
| | | meta:from_table(n.meta) |
| | | for __,pos in ipairs(poslist) do |
| | | if npos.x==pos.x and npos.y==pos.y and npos.z==pos.z then |
| | | if npos.x == pos.x and npos.y == pos.y and npos.z == pos.z then |
| | | table.remove(poslist, __) |
| | | break |
| | | end |
| | | end |
| | | end |
| | | for __,pos in ipairs(poslist) do |
| | | for __, pos in ipairs(poslist) do |
| | | minetest.remove_node(pos) |
| | | end |
| | | for _, callback in ipairs(mesecon.on_mvps_move) do |
| | | callback(nodelist) |
| | | end |
| | | end |
| | | |
| | |
| | | paramtype = "light", |
| | | frame=1, |
| | | drop="technic:frame_111111", |
| | | sunlight_propagates = true, |
| | | frame_connect_all=function(nodename) |
| | | 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}} |
| | |
| | | end, |
| | | on_place = function(itemstack, placer, pointed_thing) |
| | | local pos = pointed_thing.above |
| | | if minetest.is_protected(pos, placer:get_player_name()) then |
| | | minetest.log("action", placer:get_player_name() |
| | | .. " tried to place " .. itemstack:get_name() |
| | | .. " at protected position " |
| | | .. minetest.pos_to_string(pos)) |
| | | minetest.record_protection_violation(pos, placer:get_player_name()) |
| | | return itemstack |
| | | end |
| | | if pos == nil then return end |
| | | local node = minetest.get_node(pos) |
| | | if node.name ~= "air" then |
| | |
| | | end |
| | | else |
| | | minetest.set_node(pos, {name = itemstack:get_name()}) |
| | | end |
| | | if not infinite_stacks then |
| | | itemstack:take_item() |
| | | end |
| | | return itemstack |
| | | end, |
| | | on_rightclick = function(pos, node, placer, itemstack, pointed_thing) |
| | | if is_supported_node(itemstack:get_name()) then |
| | | if minetest.is_protected(pos, placer:get_player_name()) then |
| | | minetest.log("action", placer:get_player_name() |
| | | .. " tried to place " .. itemstack:get_name() |
| | | .. " at protected position " |
| | | .. minetest.pos_to_string(pos)) |
| | | minetest.record_protection_violation(pos, placer:get_player_name()) |
| | | return itemstack |
| | | end |
| | | |
| | | minetest.set_node(pos, {name = itemstack:get_name()}) |
| | | |
| | | local take_item = true |
| | | local def = minetest.registered_items[itemstack:get_name()] |
| | | -- Run callback |
| | | if def.after_place_node then |
| | | -- Copy place_to because callback can modify it |
| | | local pos_copy = {x=pos.x, y=pos.y, z=pos.z} |
| | | if def.after_place_node(pos_copy, placer, itemstack) then |
| | | take_item = false |
| | | end |
| | | end |
| | | |
| | | -- Run script hook |
| | | local _, callback |
| | | for _, callback in ipairs(minetest.registered_on_placenodes) do |
| | | -- Copy pos and node because callback can modify them |
| | | local pos_copy = {x=pos.x, y=pos.y, z=pos.z} |
| | | local newnode_copy = {name=def.name, param1=0, param2=0} |
| | | local oldnode_copy = {name="air", param1=0, param2=0} |
| | | if callback(pos_copy, newnode_copy, placer, oldnode_copy, itemstack) then |
| | | take_item = false |
| | | end |
| | | end |
| | | |
| | | if take_item then |
| | | itemstack:take_item() |
| | | end |
| | | |
| | | obj = minetest.add_entity(pos, "technic:frame_entity") |
| | | obj:get_luaentity():set_node({name=node.name}) |
| | | |
| | | return itemstack |
| | | else |
| | | --local pointed_thing = {type = "node", under = pos} |
| | | if pointed_thing then |
| | | minetest.item_place_node(itemstack, placer, pointed_thing) |
| | | end |
| | | end |
| | | end, |
| | | }) |
| | |
| | | minetest.register_entity("technic:frame_entity", { |
| | | initial_properties = { |
| | | physical = true, |
| | | collide_with_objects = false, |
| | | collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5}, |
| | | visual = "wielditem", |
| | | textures = {}, |
| | |
| | | end |
| | | end, |
| | | }) |
| | | |
| | | mesecon:register_mvps_unmov("technic:frame_entity") |
| | | mesecon:register_mvps_unmov("technic:damage_entity") |
| | | mesecon:register_on_mvps_move(function(moved_nodes) |
| | | local to_move = {} |
| | | for _, n in ipairs(moved_nodes) do |
| | | if frames_pos[pos_to_string(n.oldpos)] ~= nil then |
| | | to_move[#to_move+1] = {pos = n.pos, oldpos = n.oldpos, name = frames_pos[pos_to_string(n.oldpos)]} |
| | | frames_pos[pos_to_string(n.oldpos)] = nil |
| | | end |
| | | end |
| | | if #to_move > 0 then |
| | | for _, t in ipairs(to_move) do |
| | | frames_pos[pos_to_string(t.pos)] = t.name |
| | | local objects = minetest.get_objects_inside_radius(t.oldpos, 0.1) |
| | | for _, obj in ipairs(objects) do |
| | | local entity = obj:get_luaentity() |
| | | if entity and (entity.name == "technic:frame_entity" or entity.name == "technic:damage_entity") then |
| | | obj:setpos(t.pos) |
| | | end |
| | | end |
| | | end |
| | | end |
| | | end) |
| | | |
| | | minetest.register_on_dignode(function(pos, node) |
| | | if frames_pos[pos_to_string(pos)] ~= nil then |
| | | minetest.set_node(pos, {name = frames_pos[pos_to_string(pos)]}) |
| | | frames_pos[pos_to_string(pos)] = nil |
| | | local objects = minetest.get_objects_inside_radius(pos, 0.1) |
| | | for _, obj in ipairs(objects) do |
| | | local entity = obj:get_luaentity() |
| | | if entity and (entity.name == "technic:frame_entity" or entity.name == "technic:damage_entity") then |
| | | obj:remove() |
| | | end |
| | | end |
| | | end |
| | | end) |
| | | |
| | | -- Frame motor |
| | | local function connected(pos,c,adj) |
| | |
| | | }) |
| | | |
| | | minetest.register_tool("technic:template_tool",{ |
| | | description = S("Template tool"), |
| | | description = S("Template Tool"), |
| | | inventory_image = "technic_template_tool.png", |
| | | on_use = function(itemstack, puncher, pointed_thing) |
| | | local pos = pointed_thing.under |
| | | if pos == nil or (minetest.is_protected and minetest.is_protected(pos, placer:get_player_name())) then |
| | | if pos == nil or (minetest.is_protected and minetest.is_protected(pos, puncher:get_player_name())) then |
| | | return nil |
| | | end |
| | | local node = minetest.get_node(pos) |
| | |
| | | end |
| | | |
| | | minetest.register_node("technic:template_motor",{ |
| | | description = S("Template motor"), |
| | | description = S("Template Motor"), |
| | | tiles = {"pipeworks_filter_top.png^[transformR90", "technic_lv_cable.png", "technic_lv_cable.png", |
| | | "technic_lv_cable.png", "technic_lv_cable.png", "technic_lv_cable.png"}, |
| | | groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,mesecon=2}, |
| | |
| | | output = 'technic:frame_motor', |
| | | recipe = { |
| | | {'', 'technic:frame_111111', ''}, |
| | | {'group:mesecons_conductor_craftable', 'technic:motor', 'group:mesecons_conductor_craftable'}, |
| | | {'group:mesecon_conductor_craftable', 'technic:motor', 'group:mesecon_conductor_craftable'}, |
| | | {'', 'technic:frame_111111', ''}, |
| | | } |
| | | }) |
| | |
| | | output = 'technic:template_motor', |
| | | recipe = { |
| | | {'', 'technic:template', ''}, |
| | | {'group:mesecons_conductor_craftable', 'technic:motor', 'group:mesecons_conductor_craftable'}, |
| | | {'group:mesecon_conductor_craftable', 'technic:motor', 'group:mesecon_conductor_craftable'}, |
| | | {'', 'technic:template', ''}, |
| | | } |
| | | }) |