From c1567b34eeaf37242da135df28963dfdd21c8fb8 Mon Sep 17 00:00:00 2001 From: tchncs Date: Fri, 2 Dec 2016 16:51:40 +0100 Subject: [PATCH] refactor watermechanics only load water.lua if ethereal is not present --- init.lua | 117 ++---------------------------------------------------- water.lua | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+), 114 deletions(-) create mode 100644 water.lua diff --git a/init.lua b/init.lua index f10fd1f..9083685 100644 --- a/init.lua +++ b/init.lua @@ -10,117 +10,6 @@ dofile(minetest.get_modpath("illuna").."/shop.lua") if minetest.get_modpath("moreblocks") then dofile(minetest.get_modpath("illuna").."/moreblocks.lua") end - --- Water mechanics from the ethereal mod --- --- If Crystal Spike, Crystal Dirt, Snow near Water, change Water to Ice -minetest.register_abm({ - label = "Illuna freeze water", - nodenames = { - "default:snow", "default:snowblock" - }, - neighbors = {"default:water_source", "default:river_water_source"}, - interval = 15, - chance = 4, - catch_up = false, - action = function(pos, node) - - local near = minetest.find_node_near(pos, 1, - {"default:water_source", "default:river_water_source"}) - - if near then - minetest.swap_node(near, {name = "default:ice"}) - end - end, -}) - --- If Heat Source near Ice or Snow then melt -minetest.register_abm({ - label = "Ethereal melt snow/ice", - nodenames = { - "default:ice", "default:snowblock", "default:snow", - "default:dirt_with_snow" - }, - neighbors = { - "fire:basic_fire", "default:lava_source", "default:lava_flowing", - "default:furnace_active", "default:torch" - }, - interval = 5, - chance = 4, - catch_up = false, - action = function(pos, node) - - local water_node = "default:water" - - if pos.y > 2 then - water_node = "default:river_water" - end - - if node.name == "default:ice" - or node.name == "default:snowblock" - or node.name == "ethereal:icebrick" - or node.name == "ethereal:snowbrick" then - minetest.swap_node(pos, {name = water_node.."_source"}) - - elseif node.name == "default:snow" then - minetest.swap_node(pos, {name = water_node.."_flowing"}) - - elseif node.name == "default:dirt_with_snow" then - minetest.swap_node(pos, {name = "default:dirt_with_grass"}) - end - - nodeupdate(pos) - end, -}) - --- If Water Source near Dry Dirt, change to normal Dirt -minetest.register_abm({ - label = "Ethereal wet dry dirt", - nodenames = {"ethereal:dry_dirt", "default:dirt_with_dry_grass"}, - neighbors = {"group:water"}, - interval = 15, - chance = 2, - catch_up = false, - action = function(pos, node) - - if node == "ethereal:dry_dirt" then - minetest.swap_node(pos, {name = "default:dirt"}) - else - minetest.swap_node(pos, {name = "ethereal:green_dirt"}) - end - end, -}) - --- If torch touching water then drop as item -minetest.register_abm({ - label = "Ethereal drop torch", - nodenames = {"default:torch"}, - neighbors = {"group:water"}, - interval = 5, - chance = 1, - catch_up = false, - action = function(pos, node) - - local num = #minetest.find_nodes_in_area( - {x = pos.x - 1, y = pos.y, z = pos.z}, - {x = pos.x + 1, y = pos.y, z = pos.z}, - {"group:water"}) - - num = num + #minetest.find_nodes_in_area( - {x = pos.x, y = pos.y, z = pos.z - 1}, - {x = pos.x, y = pos.y, z = pos.z + 1}, - {"group:water"}) - - num = num + #minetest.find_nodes_in_area( - {x = pos.x, y = pos.y + 1, z = pos.z}, - {x = pos.x, y = pos.y + 1, z = pos.z}, - {"group:water"}) - - if num > 0 then - - minetest.swap_node(pos, {name = "air"}) - - minetest.add_item(pos, {name = node.name}) - end - end, -}) +if not minetest.get_modpath("ethereal") then + dofile(minetest.get_modpath("illuna").."/water.lua" +end diff --git a/water.lua b/water.lua new file mode 100644 index 0000000..f1b30d8 --- /dev/null +++ b/water.lua @@ -0,0 +1,113 @@ +-- Water mechanics from the ethereal mod +-- +-- If Crystal Spike, Crystal Dirt, Snow near Water, change Water to Ice +minetest.register_abm({ + label = "Illuna freeze water", + nodenames = { + "default:snow", "default:snowblock" + }, + neighbors = {"default:water_source", "default:river_water_source"}, + interval = 15, + chance = 4, + catch_up = false, + action = function(pos, node) + + local near = minetest.find_node_near(pos, 1, + {"default:water_source", "default:river_water_source"}) + + if near then + minetest.swap_node(near, {name = "default:ice"}) + end + end, +}) + +-- If Heat Source near Ice or Snow then melt +minetest.register_abm({ + label = "Ethereal melt snow/ice", + nodenames = { + "default:ice", "default:snowblock", "default:snow", + "default:dirt_with_snow" + }, + neighbors = { + "fire:basic_fire", "default:lava_source", "default:lava_flowing", + "default:furnace_active", "default:torch" + }, + interval = 5, + chance = 4, + catch_up = false, + action = function(pos, node) + + local water_node = "default:water" + + if pos.y > 2 then + water_node = "default:river_water" + end + + if node.name == "default:ice" + or node.name == "default:snowblock" + or node.name == "ethereal:icebrick" + or node.name == "ethereal:snowbrick" then + minetest.swap_node(pos, {name = water_node.."_source"}) + + elseif node.name == "default:snow" then + minetest.swap_node(pos, {name = water_node.."_flowing"}) + + elseif node.name == "default:dirt_with_snow" then + minetest.swap_node(pos, {name = "default:dirt_with_grass"}) + end + + nodeupdate(pos) + end, +}) + +-- If Water Source near Dry Dirt, change to normal Dirt +minetest.register_abm({ + label = "Ethereal wet dry dirt", + nodenames = {"ethereal:dry_dirt", "default:dirt_with_dry_grass"}, + neighbors = {"group:water"}, + interval = 15, + chance = 2, + catch_up = false, + action = function(pos, node) + + if node == "ethereal:dry_dirt" then + minetest.swap_node(pos, {name = "default:dirt"}) + else + minetest.swap_node(pos, {name = "ethereal:green_dirt"}) + end + end, +}) + +-- If torch touching water then drop as item +minetest.register_abm({ + label = "Ethereal drop torch", + nodenames = {"default:torch"}, + neighbors = {"group:water"}, + interval = 5, + chance = 1, + catch_up = false, + action = function(pos, node) + + local num = #minetest.find_nodes_in_area( + {x = pos.x - 1, y = pos.y, z = pos.z}, + {x = pos.x + 1, y = pos.y, z = pos.z}, + {"group:water"}) + + num = num + #minetest.find_nodes_in_area( + {x = pos.x, y = pos.y, z = pos.z - 1}, + {x = pos.x, y = pos.y, z = pos.z + 1}, + {"group:water"}) + + num = num + #minetest.find_nodes_in_area( + {x = pos.x, y = pos.y + 1, z = pos.z}, + {x = pos.x, y = pos.y + 1, z = pos.z}, + {"group:water"}) + + if num > 0 then + + minetest.swap_node(pos, {name = "air"}) + + minetest.add_item(pos, {name = node.name}) + end + end, +})