Add a meteor.
parent
85a47b7049
commit
8ecbbb5716
15
init.lua
15
init.lua
|
@ -116,24 +116,31 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||||
local pos = vector.add(use, def.offset)
|
local pos = vector.add(use, def.offset)
|
||||||
minetest.place_schematic(pos, def.schematic, "random")
|
minetest.place_schematic(pos, def.schematic, "random")
|
||||||
|
|
||||||
-- Very Hacky Solution due to minetest.place_schematic carrying the replacements parameter between calls.
|
|
||||||
-- This parses the schematic file manually, then replaces appropriate nodes between all possible positions.
|
|
||||||
local schematic_size = {}
|
local schematic_size = {}
|
||||||
|
|
||||||
|
-- Open the schematic and read the three size integers into schematic_size.
|
||||||
local sf = io.open(def.schematic, "rb")
|
local sf = io.open(def.schematic, "rb")
|
||||||
sf:read(6)
|
sf:read(6)
|
||||||
schematic_size.x = string.byte(sf:read(1)) * 256 + string.byte(sf:read(1))
|
schematic_size.x = string.byte(sf:read(1)) * 256 + string.byte(sf:read(1))
|
||||||
schematic_size.y = string.byte(sf:read(1)) * 256 + string.byte(sf:read(1))
|
schematic_size.y = string.byte(sf:read(1)) * 256 + string.byte(sf:read(1))
|
||||||
schematic_size.z = string.byte(sf:read(1)) * 256 + string.byte(sf:read(1))
|
schematic_size.z = string.byte(sf:read(1)) * 256 + string.byte(sf:read(1))
|
||||||
sf:close()
|
sf:close()
|
||||||
|
|
||||||
|
local mid = vector.add(pos, vector.divide(schematic_size, 2))
|
||||||
|
|
||||||
|
-- Replace appropriate nodes in the possible schematic area.
|
||||||
for k,v in pairs(r) do
|
for k,v in pairs(r) do
|
||||||
local positions = minetest.find_nodes_in_area(vector.subtract(pos, schematic_size), vector.add(maxp, schematic_size), {k})
|
local positions = minetest.find_nodes_in_area(vector.subtract(mid, schematic_size), vector.add(mid, schematic_size), {k})
|
||||||
if positions then
|
if positions then
|
||||||
for _,p in ipairs(positions) do
|
for _,p in ipairs(positions) do
|
||||||
minetest.set_node(p, {name=v})
|
minetest.set_node(p, {name=v})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- End Very Hacky Solution
|
|
||||||
|
if def.special then
|
||||||
|
def.special(pos, mid, schematic_size)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Binary file not shown.
|
@ -187,7 +187,7 @@ end
|
||||||
ancient_world.register("ancient_world:mine_1", {
|
ancient_world.register("ancient_world:mine_1", {
|
||||||
schematic = minetest.get_modpath("ancient_world") .. "/schematics/mine_1.mts",
|
schematic = minetest.get_modpath("ancient_world") .. "/schematics/mine_1.mts",
|
||||||
type = "decoration",
|
type = "decoration",
|
||||||
on = {"default:dirt_with_grass"},
|
on = {"default:dirt_with_grass", "default:dirt_with_dry_grass"},
|
||||||
offset = {
|
offset = {
|
||||||
x = 0,
|
x = 0,
|
||||||
y = -48,
|
y = -48,
|
||||||
|
@ -207,3 +207,57 @@ ancient_world.register("ancient_world:mine_1", {
|
||||||
{"default:stone_with_gold", "default:stone_with_copper", "default:stone_with_iron"}),
|
{"default:stone_with_gold", "default:stone_with_copper", "default:stone_with_iron"}),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
ancient_world.register("ancient_world:meteor_1", {
|
||||||
|
schematic = minetest.get_modpath("ancient_world") .. "/schematics/meteor_1.mts",
|
||||||
|
type = "decoration",
|
||||||
|
on = {"default:dirt_with_grass", "default:dirt_with_dry_grass"},
|
||||||
|
offset = {
|
||||||
|
x = 0,
|
||||||
|
y = -2,
|
||||||
|
z = 0,
|
||||||
|
},
|
||||||
|
limit_y = {
|
||||||
|
max = 31000,
|
||||||
|
min = -32,
|
||||||
|
},
|
||||||
|
replacements = {
|
||||||
|
["ancient_world:placeholder_1"] = "fire:basic_flame",
|
||||||
|
},
|
||||||
|
special = function(pos, mid, schematic_size)
|
||||||
|
local want = {
|
||||||
|
["default:dirt_with_dry_grass"] = true,
|
||||||
|
["default:dirt_with_grass"] = true,
|
||||||
|
["default:stone"] = true,
|
||||||
|
}
|
||||||
|
local t = vector.add(mid, schematic_size)
|
||||||
|
t.y = t.y - 4
|
||||||
|
local positions = minetest.find_nodes_in_area(vector.subtract(mid, schematic_size), t, {"air"})
|
||||||
|
if positions then
|
||||||
|
for _,p in ipairs(positions) do
|
||||||
|
if math.random(1, 100) <= 10 then
|
||||||
|
local hit = p
|
||||||
|
local tries = 1
|
||||||
|
while true do
|
||||||
|
hit = vector.add(hit, {x=0, y=-1, z=0})
|
||||||
|
if want[minetest.get_node(vector.add(hit, {x=0, y=-1, z=0})).name] then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
if want[minetest.get_node(vector.add(hit, {x=0, y=-1, z=0})).name] == "ignore" then
|
||||||
|
hit = nil
|
||||||
|
break
|
||||||
|
end
|
||||||
|
if tries > 16 then
|
||||||
|
hit = nil
|
||||||
|
break
|
||||||
|
end
|
||||||
|
tries = tries + 1
|
||||||
|
end
|
||||||
|
if hit then
|
||||||
|
minetest.set_node(hit, {name="default:dirt"})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
Loading…
Reference in New Issue