Compare commits
5 Commits
68cc54d760
...
c57fa04829
Author | SHA1 | Date |
---|---|---|
texmex | c57fa04829 | |
Yzel Junior | 44e78b8527 | |
Yzel Junior | 6f5064d79e | |
texmex | 17d3b1ea17 | |
Yzel Junior | 17fdc94b6a |
200
init.lua
200
init.lua
|
@ -1,47 +1,157 @@
|
|||
local floodables = {
|
||||
{ group = "torch", drop = "default:torch", sound = "floodables_torch", gain = 0.8 },
|
||||
{ group = "flora", sound = "floodables_grass", gain = 0.2 },
|
||||
{ group = "wheat", drop = "farming:seed_wheat", sound = "floodables_grass", gain = 0.2 },
|
||||
{ name = "default:junglegrass", sound = "floodables_grass", gain = 0.2 },
|
||||
{ group = "grass", drop = "default:grass_1", sound = "floodables_grass", gain = 0.2 },
|
||||
{ group = "dry_grass", drop = "default:dry_grass_1", sound = "floodables_grass", gain = 0.2 },
|
||||
-- { name = "default:dirt_with_grass", erode = true },
|
||||
}
|
||||
floodables = {}
|
||||
|
||||
for _,c in ipairs(floodables) do
|
||||
if c.name ~=nil then
|
||||
minetest.override_item(c.name, {
|
||||
floodable = true,
|
||||
on_flood = function(pos, oldnode, newnode)
|
||||
minetest.remove_node(pos)
|
||||
if c.sound ~= nil then
|
||||
minetest.sound_play({ name = c.sound, gain = c.gain }, { pos = pos, max_hear_distance = 16 })
|
||||
end
|
||||
if c.drop == nil or c.drop ~= false then c.drop = c.name end
|
||||
minetest.add_item(pos, {name = c.drop})
|
||||
if c.erode == true then
|
||||
minetest.remove_node( { x = pos.x, y = pos.y-1, z = pos.z } )
|
||||
end
|
||||
end
|
||||
})
|
||||
elseif c.group ~=nil then
|
||||
for _,v in pairs(minetest.registered_nodes) do
|
||||
if minetest.get_item_group(v.name, c.group) ~= 0 then
|
||||
minetest.override_item(v.name, {
|
||||
floodable = true,
|
||||
on_flood = function(pos, oldnode, newnode)
|
||||
minetest.remove_node(pos)
|
||||
if c.sound ~= nil then
|
||||
minetest.sound_play({ name = c.sound, gain = c.gain }, { pos = pos, max_hear_distance = 16 })
|
||||
end
|
||||
if c.drop == nil or c.drop == true then c.drop = v.name end
|
||||
minetest.add_item(pos, {name = c.drop})
|
||||
if c.erode == true then
|
||||
minetest.remove_node( { x = pos.x, y = pos.y-1, z = pos.z } )
|
||||
end
|
||||
end
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
function floodables.register_soil(def)
|
||||
for key,value in pairs(minetest.registered_nodes) do
|
||||
if minetest.get_item_group(value.name, def.name) ~= 0 then
|
||||
|
||||
-- overrides all soil nodes to add the falling_group
|
||||
minetest.override_item(value.name,{
|
||||
groups = {soil = 1, falling_node = 1},
|
||||
})
|
||||
|
||||
minetest.register_abm({
|
||||
label = "soil erosion",
|
||||
nodenames = value.name,
|
||||
neighbors = "air",
|
||||
interval = def.interval,
|
||||
chance = def.chance,
|
||||
|
||||
-- This function check if there space under the soil, and if true, set "air" at
|
||||
-- the old position and put the old node 1 Y lower
|
||||
action = function(pos)
|
||||
if math.random(def.erode_chance) == 1 then
|
||||
local pmin = {x = pos.x - 1, y = pos.y - 1, z = pos.z - 1}
|
||||
local pmax = {x = pos.x + 1, y = pos.y - 1, z = pos.z + 1}
|
||||
local area = minetest.find_nodes_in_area(pmin,pmax,"air")
|
||||
if table.getn(area) > 0 then
|
||||
minetest.set_node(pos,{name = "air"})
|
||||
local pos = area[math.random(table.getn(area))]
|
||||
minetest.set_node(pos,{name = value.name})
|
||||
minetest.check_single_for_falling(pos) -- make all floating dirt fall
|
||||
end
|
||||
end
|
||||
end,
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function floodables.register_crops(def)
|
||||
local size = 1
|
||||
while minetest.registered_nodes[def.name.."_"..size] ~= nil do
|
||||
minetest.override_item(def.name.."_"..size, {
|
||||
floodable = true,
|
||||
|
||||
on_flood = function(pos)
|
||||
if math.random(def.func_chance) == 1 then
|
||||
minetest.sound_play({ name = def.sound, gain = def.gain }, { pos = pos, max_hear_distance = 16 })
|
||||
if math.random(def.drop_chance) == 1 then
|
||||
local node = minetest.get_node(pos)
|
||||
local drops = minetest.get_node_drops(node.name)
|
||||
local index = math.random(table.getn(drops))
|
||||
minetest.set_node(pos, {name="air"})
|
||||
minetest.add_item(pos, drops[index])
|
||||
else
|
||||
minetest.set_node(pos, {name="air"})
|
||||
end
|
||||
end
|
||||
end,
|
||||
})
|
||||
size = size + 1
|
||||
end
|
||||
end
|
||||
|
||||
function floodables.register_groups(def)
|
||||
for key,value in pairs(minetest.registered_nodes) do
|
||||
if minetest.get_item_group(value.name, def.name) ~= 0 then
|
||||
minetest.override_item(value.name, {
|
||||
floodable = true,
|
||||
|
||||
on_flood = function(pos)
|
||||
if math.random(def.func_chance) == 1 then
|
||||
minetest.sound_play({ name = def.sound, gain = def.gain }, { pos = pos, max_hear_distance = 16 })
|
||||
if math.random(def.drop_chance) == 1 then
|
||||
local drops = minetest.get_node_drops(value.name)
|
||||
local index = math.random(table.getn(drops))
|
||||
minetest.set_node(pos, {name="air"})
|
||||
minetest.add_item(pos, drops[index])
|
||||
else
|
||||
minetest.set_node(pos, {name="air"})
|
||||
end
|
||||
end
|
||||
end,
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Groups registration
|
||||
--------------------------------------------------------------------------------
|
||||
floodables.register_soil({
|
||||
name = "soil",
|
||||
chance = 4,
|
||||
interval = 2,
|
||||
erode_chance = 8,
|
||||
})
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Groups registration
|
||||
--------------------------------------------------------------------------------
|
||||
floodables.register_groups({
|
||||
name = "flora",
|
||||
func_chance = 2,
|
||||
drop_chance = 4,
|
||||
sound = "floodables_grass",
|
||||
gain = 0.2,
|
||||
})
|
||||
floodables.register_groups({
|
||||
name = "flower",
|
||||
func_chance = 2,
|
||||
drop_chance = 4,
|
||||
sound = "floodables_grass",
|
||||
gain = 0.2,
|
||||
})
|
||||
floodables.register_groups({
|
||||
name = "torch",
|
||||
func_chance = 1,
|
||||
drop_chance = 1,
|
||||
sound = "floodables_torch",
|
||||
gain = 0.8,
|
||||
})
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Crops registration
|
||||
--------------------------------------------------------------------------------
|
||||
floodables.register_crops({
|
||||
name = "farming:wheat",
|
||||
func_chance = 1,
|
||||
drop_chance = 1,
|
||||
sound = "floodables_grass",
|
||||
gain = 0.2,
|
||||
})
|
||||
floodables.register_crops({
|
||||
name = "farming:cotton",
|
||||
func_chance = 1,
|
||||
drop_chance = 1,
|
||||
sound = "floodables_grass",
|
||||
gain = 0.2,
|
||||
})
|
||||
|
||||
-- Although the grass is inside the flora group, i prefered to add is in a crop
|
||||
-- function, just to be same with the dry grass, which has no group
|
||||
floodables.register_crops({
|
||||
name = "default:grass",
|
||||
func_chance = 1,
|
||||
drop_chance = 1,
|
||||
sound = "floodables_grass",
|
||||
gain = 0.2,
|
||||
})
|
||||
floodables.register_crops({
|
||||
name = "default:dry_grass",
|
||||
func_chance = 1,
|
||||
drop_chance = 1,
|
||||
sound = "floodables_grass",
|
||||
gain = 0.2,
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue