mirror of
https://github.com/minetest-mods/mesecons.git
synced 2025-03-20 19:10:39 +01:00
Merge 4b0c0dec63f3f6d151197c708a1da55ff231f500 into 80d136125ef8f17af85d0045800d5e761ace3229
This commit is contained in:
commit
215bb16131
@ -25,6 +25,82 @@ minetest.register_craft({
|
|||||||
|
|
||||||
-- GHOSTSTONE
|
-- GHOSTSTONE
|
||||||
|
|
||||||
|
local function get_tab(pos, func)
|
||||||
|
local tab = {pos}
|
||||||
|
local tab_avoid = {[pos.x.." "..pos.y.." "..pos.z] = true}
|
||||||
|
local tab_done,num = {pos},2
|
||||||
|
while tab[1] do
|
||||||
|
for n,p in pairs(tab) do
|
||||||
|
for i = -1,1,2 do
|
||||||
|
for _,p2 in pairs({
|
||||||
|
{x=p.x+i, y=p.y, z=p.z},
|
||||||
|
{x=p.x, y=p.y+i, z=p.z},
|
||||||
|
{x=p.x, y=p.y, z=p.z+i},
|
||||||
|
}) do
|
||||||
|
local pstr = p2.x.." "..p2.y.." "..p2.z
|
||||||
|
if not tab_avoid[pstr]
|
||||||
|
and func(p2) then
|
||||||
|
tab_avoid[pstr] = true
|
||||||
|
tab_done[num] = p2
|
||||||
|
num = num+1
|
||||||
|
table.insert(tab, p2)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
tab[n] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return tab_done
|
||||||
|
end
|
||||||
|
|
||||||
|
local function is_ghoststone(pos)
|
||||||
|
return minetest.get_node(pos).name == "mesecons_random:ghoststone"
|
||||||
|
end
|
||||||
|
|
||||||
|
local function is_ghoststone_active(pos)
|
||||||
|
return minetest.get_node(pos).name == "mesecons_random:ghoststone_active"
|
||||||
|
end
|
||||||
|
|
||||||
|
local c = {}
|
||||||
|
local function update_ghoststones(pos, func, name)
|
||||||
|
func = func or is_ghoststone
|
||||||
|
name = name or "mesecons_random:ghoststone_active"
|
||||||
|
local tab = get_tab(pos, func)
|
||||||
|
if #tab < 50 then
|
||||||
|
for _,p in pairs(tab) do
|
||||||
|
minetest.set_node(p, {name=name})
|
||||||
|
end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local p = tab[1]
|
||||||
|
local min = vector.new(p)
|
||||||
|
local max = vector.new(p)
|
||||||
|
for _,p in pairs(tab) do
|
||||||
|
for _,coord in pairs({"x", "y", "z"}) do
|
||||||
|
min[coord] = math.min(min[coord], p[coord])
|
||||||
|
max[coord] = math.max(max[coord], p[coord])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
c[name] = c[name] or minetest.get_content_id(name)
|
||||||
|
local c_name = c[name]
|
||||||
|
|
||||||
|
local manip = minetest.get_voxel_manip()
|
||||||
|
local emerged_pos1, emerged_pos2 = manip:read_from_map(min, max)
|
||||||
|
local area = VoxelArea:new({MinEdge=emerged_pos1, MaxEdge=emerged_pos2})
|
||||||
|
local nodes = manip:get_data()
|
||||||
|
|
||||||
|
for _,p in pairs(tab) do
|
||||||
|
nodes[area:indexp(p)] = c_name
|
||||||
|
end
|
||||||
|
|
||||||
|
manip:set_data(nodes)
|
||||||
|
manip:write_to_map()
|
||||||
|
manip:update_map()
|
||||||
|
--print(string.format("[mesecons] ghostblocks updated after ca. %.2fs", os.clock() - --t1))
|
||||||
|
end
|
||||||
|
|
||||||
minetest.register_node("mesecons_random:ghoststone", {
|
minetest.register_node("mesecons_random:ghoststone", {
|
||||||
description="ghoststone",
|
description="ghoststone",
|
||||||
tiles = {"jeija_ghoststone.png"},
|
tiles = {"jeija_ghoststone.png"},
|
||||||
@ -32,18 +108,32 @@ minetest.register_node("mesecons_random:ghoststone", {
|
|||||||
inventory_image = minetest.inventorycube("jeija_ghoststone_inv.png"),
|
inventory_image = minetest.inventorycube("jeija_ghoststone_inv.png"),
|
||||||
groups = {cracky=3},
|
groups = {cracky=3},
|
||||||
sounds = default.node_sound_stone_defaults(),
|
sounds = default.node_sound_stone_defaults(),
|
||||||
mesecons = {conductor = {
|
mesecons = {--[[conductor = {
|
||||||
state = mesecon.state.off,
|
state = mesecon.state.off,
|
||||||
rules = { --axes
|
rules = { --axes
|
||||||
{x = -1, y = 0, z = 0},
|
{x = -1, y = 0, z = 0},
|
||||||
{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 = 1, z = 0},
|
{x = 0, y = 1, z = 0},
|
||||||
{x = 0, y = 0, z = -1},
|
{x = 0, y = 0, z = -1},
|
||||||
{x = 0, y = 0, z = 1},
|
{x = 0, y = 0, z = 1},
|
||||||
},
|
},
|
||||||
onstate = "mesecons_random:ghoststone_active"
|
onstate = "mesecons_random:ghoststone_active"
|
||||||
}}
|
},]]
|
||||||
|
effector = {
|
||||||
|
rules = {
|
||||||
|
{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},
|
||||||
|
},
|
||||||
|
action_on = function(pos)
|
||||||
|
update_ghoststones(pos)
|
||||||
|
end
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_node("mesecons_random:ghoststone_active", {
|
minetest.register_node("mesecons_random:ghoststone_active", {
|
||||||
@ -53,23 +143,37 @@ minetest.register_node("mesecons_random:ghoststone_active", {
|
|||||||
diggable = false,
|
diggable = false,
|
||||||
sunlight_propagates = true,
|
sunlight_propagates = true,
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
mesecons = {conductor = {
|
mesecons = {--[[conductor = {
|
||||||
state = mesecon.state.on,
|
state = mesecon.state.on,
|
||||||
rules = {
|
rules = {
|
||||||
{x = -1, y = 0, z = 0},
|
{x = -1, y = 0, z = 0},
|
||||||
{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 = 1, z = 0},
|
{x = 0, y = 1, z = 0},
|
||||||
{x = 0, y = 0, z = -1},
|
{x = 0, y = 0, z = -1},
|
||||||
{x = 0, y = 0, z = 1},
|
{x = 0, y = 0, z = 1},
|
||||||
},
|
},
|
||||||
offstate = "mesecons_random:ghoststone"
|
offstate = "mesecons_random:ghoststone"
|
||||||
}},
|
},]]
|
||||||
|
effector = {
|
||||||
|
rules = {
|
||||||
|
{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},
|
||||||
|
},
|
||||||
|
action_off = function(pos)
|
||||||
|
update_ghoststones(pos, is_ghoststone_active, "mesecons_random:ghoststone")
|
||||||
|
end
|
||||||
|
}
|
||||||
|
},
|
||||||
on_construct = function(pos)
|
on_construct = function(pos)
|
||||||
--remove shadow
|
--remove shadow
|
||||||
pos2 = {x = pos.x, y = pos.y + 1, z = pos.z}
|
pos.y = pos.y+1
|
||||||
if ( minetest.get_node(pos2).name == "air" ) then
|
if minetest.get_node(pos).name == "air" then
|
||||||
minetest.dig_node(pos2)
|
minetest.dig_node(pos)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user