123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694 |
- local weirding = {
- just_placed = {},
- }
- local function clear()
- weirding.just_placed = {}
- minetest.after(1, clear)
- end
- minetest.after(1, clear)
- minetest.register_node("weirding:mover", {
- description = "mover",
- tiles = {
- "default_dirt.png^weirding_yellow_arrow.png",
- "default_dirt.png",
- "default_dirt.png",
- "default_dirt.png",
- "default_dirt.png",
- "default_dirt.png",
- },
- groups = {cracky = 1, oddly_breakable_by_hand = 3},
- is_ground_content = false,
- paramtype2 = "facedir",
- on_place = minetest.rotate_node,
- sounds = default.node_sound_dirt_defaults({
- footstep = {name = "default_stone_footstep", gain = 0.25},
- }),
- })
- minetest.register_abm({
- nodenames = {"weirding:mover"},
- -- neighbors = {"group:soil"},
- interval = 1,
- chance = 1,
- -- catch_up = true,
- action = function(pos)
- local node = minetest.get_node(pos)
-
- local back_dir = minetest.facedir_to_dir(node.param2)
-
- local top_dir = ({[0]={x=0, y=1, z=0},
- {x=0, y=0, z=1},
- {x=0, y=0, z=-1},
- {x=1, y=0, z=0},
- {x=-1, y=0, z=0},
- {x=0, y=-1, z=0}})[math.floor(node.param2/4)]
-
- local right_dir = vector.cross(top_dir, back_dir)
-
- -- local front_dir = vector.multiply(back_dir, -1)
- local backpos = vector.add(pos, top_dir)
- local frontpos = vector.add(backpos, back_dir)
-
- local bnode = minetest.get_node(backpos)
- if bnode == nil or bnode.name == "air" then
- return
- end
-
- local bhash = minetest.hash_node_position(backpos)
- if weirding.just_placed[bhash] == true then
- return
- end
-
- local fnode = minetest.get_node(frontpos)
- if fnode ~= nil and fnode.name ~= "air" then
- return
- end
-
- local fhash = minetest.hash_node_position(frontpos)
- weirding.just_placed[fhash] = true
-
-
- minetest.swap_node(frontpos, bnode)
- minetest.set_node(backpos, {name="air"})
-
- minetest.check_for_falling(frontpos)
- end,
- })
- minetest.register_node("weirding:dropper", {
- description = "mover",
- tiles = {
- "default_dirt.png^weirding_yellow_arrow_circle.png",
- "default_dirt.png",
- "default_dirt.png",
- "default_dirt.png",
- "default_dirt.png",
- "default_dirt.png",
- },
- groups = {cracky = 1, oddly_breakable_by_hand = 3},
- is_ground_content = false,
- paramtype2 = "facedir",
- on_place = minetest.rotate_node,
- sounds = default.node_sound_dirt_defaults({
- footstep = {name = "default_stone_footstep", gain = 0.25},
- }),
- })
- minetest.register_abm({
- nodenames = {"weirding:dropper"},
- -- neighbors = {"group:soil"},
- interval = 1,
- chance = 1,
- -- catch_up = true,
- action = function(pos)
- local node = minetest.get_node(pos)
-
- local back_dir = minetest.facedir_to_dir(node.param2)
-
- local top_dir = ({[0]={x=0, y=1, z=0},
- {x=0, y=0, z=1},
- {x=0, y=0, z=-1},
- {x=1, y=0, z=0},
- {x=-1, y=0, z=0},
- {x=0, y=-1, z=0}})[math.floor(node.param2/4)]
-
-
- local front_dir = vector.multiply(back_dir, -1)
- local toppos = vector.add(pos, top_dir)
- local backpos = vector.add(pos, back_dir)
- local frontpos = vector.add(pos, back_dir)
-
- local tnode = minetest.get_node(toppos)
- if tnode == nil or tnode.name == "air" then
- return
- end
-
- local thash = minetest.hash_node_position(toppos)
- if weirding.just_placed[thash] == true then
- return
- end
-
- -- try the front
- local fnode = minetest.get_node(frontpos)
- if fnode ~= nil and fnode.name == "air" then
-
- local fhash = minetest.hash_node_position(frontpos)
- weirding.just_placed[fhash] = true
-
- minetest.swap_node(frontpos, tnode)
- minetest.set_node(toppos, {name="air"})
-
- minetest.check_for_falling(frontpos)
- return
- end
-
- -- try moving on
- local frontpos = vector.add(toppos, back_dir)
- local fnode = minetest.get_node(frontpos)
- if fnode ~= nil and fnode.name == "air" then
-
- local fhash = minetest.hash_node_position(frontpos)
- weirding.just_placed[fhash] = true
-
- minetest.swap_node(frontpos, tnode)
- minetest.set_node(toppos, {name="air"})
-
- minetest.check_for_falling(frontpos)
- return
- end
- end,
- })
- --[[
- minetest.register_node("weirding:rotator", {
- description = "rotator",
- tiles = {
- "default_dirt.png^weirding_green_circle_arrow.png",
- "default_dirt.png",
- "default_dirt.png",
- "default_dirt.png",
- "default_dirt.png",
- "default_dirt.png",
- },
- groups = {cracky = 1, oddly_breakable_by_hand = 3},
- is_ground_content = false,
- paramtype2 = "facedir",
- on_place = minetest.rotate_node,
- sounds = default.node_sound_dirt_defaults({
- footstep = {name = "default_stone_footstep", gain = 0.25},
- }),
- })
- minetest.register_abm({
- nodenames = {"weirding:rotator"},
- -- neighbors = {"group:soil"},
- interval = 10000000,
- chance = 1,
- -- catch_up = true,
- action = function(pos)
- local node = minetest.get_node(pos)
-
- local back_dir = minetest.facedir_to_dir(node.param2)
-
- local top_dir = ({[0]={x=0, y=1, z=0},
- {x=0, y=0, z=1},
- {x=0, y=0, z=-1},
- {x=1, y=0, z=0},
- {x=-1, y=0, z=0},
- {x=0, y=-1, z=0}})[math.floor(node.param2/4)]
-
- local right_dir = vector.cross(top_dir, back_dir)
-
- -- local front_dir = vector.multiply(back_dir, -1)
- local backpos = vector.add(pos, back_dir)
-
- local i = 0
- while true do
-
- local frontpos = vector.add(pos, right_dir)
-
-
- local bnode = minetest.get_node(backpos)
- if bnode == nil or bnode.name == "air" then
- return
- end
-
- local bhash = minetest.hash_node_position(backpos)
- if weirding.just_placed[bhash] == true then
- return
- end
-
-
- local fnode = minetest.get_node(frontpos)
- if fnode ~= nil and fnode.name ~= "air" then
- return
- end
-
- local fhash = minetest.hash_node_position(frontpos)
- weirding.just_placed[fhash] = true
-
- minetest.swap_node(frontpos, bnode)
- minetest.set_node(backpos, {name="air"})
-
- break
- end
- end,
- })
- ]]
- minetest.register_abm({
- nodenames = {"weirding:rotator"},
- -- neighbors = {"group:soil"},
- interval = 1,
- chance = 1,
- -- catch_up = true,
- action = function(pos)
- local node = minetest.get_node(pos)
-
- local back_dir = minetest.facedir_to_dir(node.param2)
- local backpos = vector.add(pos, back_dir)
-
-
-
- local front_dir = vector.cross(back_dir, -1)
- local frontpos = vector.add(pos, front_dir)
-
- local bnode = minetest.get_node(backpos)
- if bnode == nil or bnode.name == "air" then
- return
- end
-
- local bhash = minetest.hash_node_position(backpos)
- if weirding.just_placed[bhash] == true then
- return
- end
-
- local fnode = minetest.get_node(frontpos)
- if fnode ~= nil and fnode.name ~= "air" then
- return
- end
-
- local fhash = minetest.hash_node_position(frontpos)
- weirding.just_placed[fhash] = true
-
- minetest.swap_node(frontpos, bnode)
- minetest.set_node(backpos, {name="air"})
-
- end,
- })
- minetest.register_node("weirding:eater", {
- description = "eater",
- tiles = {
- "default_dirt.png^weirding_red_arrow.png",
- "default_dirt.png",
- "default_dirt.png",
- "default_dirt.png",
- "default_dirt.png",
- "default_dirt.png",
- },
- groups = {cracky = 1, oddly_breakable_by_hand = 3},
- is_ground_content = false,
- paramtype2 = "facedir",
- on_place = minetest.rotate_node,
- sounds = default.node_sound_dirt_defaults({
- footstep = {name = "default_stone_footstep", gain = 0.25},
- }),
- })
- minetest.register_abm({
- nodenames = {"weirding:eater"},
- -- neighbors = {"group:soil"},
- interval = 1,
- chance = 1,
- -- catch_up = true,
- action = function(pos)
- local node = minetest.get_node(pos)
-
- local front_dir = minetest.facedir_to_dir(node.param2)
- local frontpos = vector.add(pos, front_dir)
-
- local back_dir = vector.multiply(front_dir, -1)
- local backpos = vector.add(pos, back_dir)
-
- local bnode = minetest.get_node(backpos)
- if bnode == nil or bnode.name == "air" then
- return
- end
-
- local bhash = minetest.hash_node_position(backpos)
- if weirding.just_placed[bhash] == true then
- return
- end
-
- local meta = minetest.get_meta(frontpos)
- if meta == nil then return end
- local inv = meta:get_inventory()
- if inv == nil then return end
- if inv:get_size("main") == 0 then return end
-
- local drops = minetest.get_node_drops(bnode.name, nil)
- for _,v in ipairs(drops) do
- inv:add_item("main", v)
- end
-
- minetest.set_node(backpos, {name="air"})
-
- end,
- })
- minetest.register_node("weirding:green_node", {
- description = "green node",
- tiles = {
- "default_dirt.png^[colorize:green:120",
- },
- groups = {cracky = 1, oddly_breakable_by_hand = 3},
- is_ground_content = false,
- -- paramtype2 = "facedir",
- -- on_place = minetest.rotate_node,
- sounds = default.node_sound_dirt_defaults({
- footstep = {name = "default_glass_footstep", gain = 0.25},
- }),
- })
- minetest.register_node("weirding:purple_node", {
- description = "purple node",
- tiles = {
- "default_dirt.png^[colorize:purple:120",
- },
- groups = {cracky = 1, oddly_breakable_by_hand = 3},
- is_ground_content = false,
- -- paramtype2 = "facedir",
- -- on_place = minetest.rotate_node,
- sounds = default.node_sound_dirt_defaults({
- footstep = {name = "default_glass_footstep", gain = 0.25},
- }),
- })
- minetest.register_node("weirding:orange_node", {
- description = "orange node",
- tiles = {
- "default_dirt.png^[colorize:orange:120",
- },
- groups = {cracky = 1, oddly_breakable_by_hand = 3},
- is_ground_content = false,
- -- paramtype2 = "facedir",
- -- on_place = minetest.rotate_node,
- sounds = default.node_sound_dirt_defaults({
- footstep = {name = "default_glass_footstep", gain = 0.25},
- }),
- })
- minetest.register_node("weirding:red_node", {
- description = "red node",
- tiles = {
- "default_dirt.png^[colorize:red:120",
- },
- groups = {cracky = 1, oddly_breakable_by_hand = 3},
- is_ground_content = false,
- -- paramtype2 = "facedir",
- -- on_place = minetest.rotate_node,
- sounds = default.node_sound_dirt_defaults({
- footstep = {name = "default_glass_footstep", gain = 0.25},
- }),
- })
- minetest.register_node("weirding:yellow_node", {
- description = "yellow node",
- tiles = {
- "default_dirt.png^[colorize:yellow:120",
- },
- groups = {cracky = 1, oddly_breakable_by_hand = 3},
- is_ground_content = false,
- -- paramtype2 = "facedir",
- -- on_place = minetest.rotate_node,
- sounds = default.node_sound_dirt_defaults({
- footstep = {name = "default_glass_footstep", gain = 0.25},
- }),
- })
- minetest.register_node("weirding:gray_node", {
- description = "gray node",
- tiles = {
- "default_dirt.png^[colorize:gray:120",
- },
- groups = {cracky = 1, oddly_breakable_by_hand = 3},
- is_ground_content = false,
- -- paramtype2 = "facedir",
- -- on_place = minetest.rotate_node,
- sounds = default.node_sound_dirt_defaults({
- footstep = {name = "default_glass_footstep", gain = 0.25},
- }),
-
- on_timer = function(pos)
- local meta = minetest.get_meta(pos)
- local n = meta:get_string("name")
- if n ~= "" then
- minetest.set_node(pos, {
- name = n,
- param2 = meta:get_int("param2"),
- })
- end
- end,
- })
- local function set_later(pos, name)
- local n = name
- local p = {x=pos.x, y=pos.y, z=pos.z}
- minetest.after(1, function()
- minetest.set_node(p, {name=n})
- end)
- end
- local function set_now(pos, name)
- minetest.set_node(pos, {name=name})
- end
- minetest.register_abm({
- nodenames = {"weirding:red_node"},
- neighbors = {"weirding:red_node"},
- interval = 2,
- chance = 1,
- -- catch_up = true,
- action = function(pos)
- local node = minetest.get_node(pos)
- if node.name ~= "weirding:red_node" then return end
-
- -- local bhash = minetest.hash_node_position(pos)
- -- if weirding.just_placed[bhash] == true then
- -- return
- -- end
- -- weirding.just_placed[bhash] = true
-
- local red_nodes = minetest.find_nodes_in_area(
- {x=pos.x - 1, y=pos.y - 1, z=pos.z - 1},
- {x=pos.x + 1, y=pos.y + 1, z=pos.z + 1},
- {"weirding:red_node"}
- )
-
- -- if #red_nodes >= 4 then
- -- minetest.set_node(pos, {name="weirding:green_node"})
- -- return
- -- end
-
- for _,rnp in ipairs(red_nodes) do
-
- -- local bhash = minetest.hash_node_position(rnp)
- -- if weirding.just_placed[bhash] == true then
- -- return
- -- end
- -- weirding.just_placed[bhash] = true
-
- local d = vector.subtract(pos, rnp);
- local opp = vector.add(pos, d);
-
- local on = minetest.get_node(opp)
- if on ~= nil and (on.name == "air" or minetest.registered_nodes[on.name].buildable_to) then
- -- minetest.set_node(rnp, {name="air"})
- set_later(opp, "weirding:red_node")
- end
- end
- --
- -- minetest.set_node(pos, {name="weirding:red_node"})
-
- end,
- })
- minetest.register_abm({
- nodenames = {"weirding:yellow_node"},
- neighbors = {"weirding:red_node"},
- interval = 2,
- chance = 1,
- -- catch_up = true,
- action = function(pos)
- local node = minetest.get_node(pos)
- if node.name ~= "weirding:yellow_node" then return end
-
- local red_nodes = minetest.find_nodes_in_area(
- {x=pos.x - 1, y=pos.y - 1, z=pos.z - 1},
- {x=pos.x + 1, y=pos.y + 1, z=pos.z + 1},
- {"weirding:red_node"}
- )
-
- for _,rnp in ipairs(red_nodes) do
-
- local bhash = minetest.hash_node_position(rnp)
- if weirding.just_placed[bhash] == true then
- return
- end
- weirding.just_placed[bhash] = true
-
- local d = vector.subtract(pos, rnp);
- local opp = vector.add(pos, d);
-
- local on = minetest.get_node(opp)
- if on ~= nil and on.name ~= "air" then
- -- minetest.set_node(rnp, {name="air"})
- minetest.set_node(rnp, {name="weirding:gray_node"})
- local meta = minetest.get_meta(rnp)
- meta:set_string("name", on.name)
- meta:set_int("param2", on.param2)
-
- local t = minetest.get_node_timer(rnp)
- t:start(10)
- end
- end
-
- end,
- })
- minetest.register_abm({
- nodenames = {"weirding:gray_node"},
- neighbors = {"weirding:red_node"},
- interval = 1,
- chance = 1,
- -- catch_up = true,
- action = function(pos)
- local node = minetest.get_node(pos)
- if node.name ~= "weirding:gray_node" then return end
-
- local nmeta = minetest.get_meta(pos)
- local param2 = nmeta:get_int("param2")
- local name = nmeta:get_string("name")
-
- local red_nodes = minetest.find_nodes_in_area(
- {x=pos.x - 1, y=pos.y - 1, z=pos.z - 1},
- {x=pos.x + 1, y=pos.y + 1, z=pos.z + 1},
- {"weirding:red_node"}
- )
-
- for _,rnp in ipairs(red_nodes) do
-
- -- minetest.set_node(rnp, {name="air"})
- minetest.set_node(rnp, {name="weirding:gray_node"})
- local meta = minetest.get_meta(rnp)
- meta:set_string("name", name)
- meta:set_int("param2", param2)
-
- local t = minetest.get_node_timer(rnp)
- t:start(10)
- end
-
- end,
- })
- -- clear
- minetest.register_abm({
- nodenames = {"weirding:green_node", "weirding:red_node"},
- interval = 100000000,
- chance = 1,
- -- catch_up = true,
- action = function(pos)
- -- minetest.set_node(pos, {name="air"})
- end,
- })
- minetest.register_abm({
- nodenames = {"weirding:green_node"},
- neighbors = {"weirding:purple_node"},
- interval = 2,
- chance = 1,
- -- catch_up = true,
- action = function(pos)
- local node = minetest.get_node(pos)
- if node.name ~= "weirding:green_node" then
- -- minetest.set_node(pos, {name="air"})
- return
- end
-
- local bhash = minetest.hash_node_position(pos)
- if weirding.just_placed[bhash] == true then
- return
- end
-
-
- local purple_nodes = minetest.find_nodes_in_area(
- {x=pos.x - 1, y=pos.y - 1, z=pos.z - 1},
- {x=pos.x + 1, y=pos.y + 1, z=pos.z + 1},
- {"weirding:purple_node"}
- )
-
- if #purple_nodes ~= 1 then
- minetest.set_node(pos, {name="default:glass"})
- return
- end
-
- local pu_pos = purple_nodes[1]
-
- local orange_nodes = minetest.find_nodes_in_area(
- {x=pu_pos.x - 1, y=pu_pos.y - 1, z=pu_pos.z - 1},
- {x=pu_pos.x + 1, y=pu_pos.y + 1, z=pu_pos.z + 1},
- {"weirding:orange_node"}
- )
- if #orange_nodes ~= 1 then
- minetest.set_node(pos, {name="default:glass"})
- return
- end
-
- local or_pos = orange_nodes[1]
- local mvdir = vector.subtract(pos, pu_pos)
- local or_next_pos = vector.add(or_pos, mvdir)
- local orn = minetest.get_node(or_next_pos)
- if orn and not minetest.registered_nodes[orn.name].buildable_to then
- minetest.set_node(pos, {name="default:glass"})
- return
- end
-
-
-
- local dir = vector.subtract(pu_pos, or_pos)
- -- local inv_dir = vector.multiply(dir, -1)
-
- -- from the corner to behind
- local source_pos_a = vector.add(pos, mvdir)
- local target_pos_a = vector.add(source_pos_a, dir)
-
- local src_a = minetest.get_node(source_pos_a)
- local tar_a = minetest.get_node(target_pos_a)
- minetest.swap_node(source_pos_a, tar_a)
- minetest.swap_node(target_pos_a, src_a)
-
-
- local mvdir = vector.subtract(pos, pu_pos)
- minetest.set_node(pu_pos, {name="air"})
- minetest.set_node(or_pos, {name="air"})
- minetest.set_node(pos, {name="air"})
- set_now(vector.add(pu_pos, mvdir), "weirding:purple_node")
- set_now(vector.add(or_pos, mvdir), "weirding:orange_node")
- set_now(vector.add(pos, mvdir), "weirding:green_node")
-
- weirding.just_placed[minetest.hash_node_position(vector.add(pos, mvdir))] = true
-
-
- end,
- })
|