diff options
author | Auke Kok <auke-jan.h.kok@intel.com> | 2015-01-25 22:19:46 -0800 |
---|---|---|
committer | Auke Kok <auke-jan.h.kok@intel.com> | 2015-01-25 22:19:46 -0800 |
commit | abdb71452fae4d8251b0d1c8768c5ae2b7756d3f (patch) | |
tree | d98925ef8454deff321ff6991d31e736419620c2 | |
parent | 8ef590bad26cdb3fb8dd0c4b45fa0619976965a8 (diff) |
Convert material props to table. Add some non-default nodes as well.
-rw-r--r-- | init.lua | 91 | ||||
-rw-r--r-- | nodes.lua | 87 |
2 files changed, 106 insertions, 72 deletions
@@ -23,6 +23,8 @@ License along with this library -- github.com/sofar -- +local mprops = dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/nodes.lua") + local interval = 1.0 local count = 20 local radius = 100 @@ -284,47 +286,11 @@ local function sed() local node = minetest.get_node(pos) - -- check if we're material that we can do something with - local hardness = 1.0 - local resistance = 1.0 - - if node.name == "default:dirt" or - node.name == "default:dirt_with_grass" or - node.name == "default:dirt_with_grass_footsteps" or - node.name == "default:dirt_with_snow" then - -- default hardness (very soft) here - elseif node.name == "default:sand" or node.name == "default:desert_sand" then - -- sand is "hard" to break into clay, but moves easily - hardness = 0.01 - elseif node.name == "default:gravel" then - hardness = 0.15 - resistance = 0.70 - elseif node.name == "default:clay" then - resistance = 0.3 - elseif node.name == "default:sandstone" or - node.name == "default:cobble" or - node.name == "default:mossycobble" or - node.name == "default:desert_cobble" then - hardness = 0.05 - resistance = 0.05 - elseif node.name == "default:desert_stone" or - node.name == "default:stone" then - hardness = 0.01 - resistance = 0.01 - elseif node.name == "default:stone_with_coal" or - node.name == "default:stone_with_iron" or - node.name == "default:stone_with_copper" or - node.name == "default:stone_with_gold" or - node.name == "default:stone_with_mese" or - node.name == "default:stone_with_diamond" then - hardness = 0.0001 - resistance = 0.01 - else - -- we don't do anything with this node type + -- do we handle this material? + if not mprops[node.name] then return end - -- determine nearby water scaling local waterfactor = 0.01 if underliquid > 0 then @@ -349,7 +315,6 @@ local function sed() return end - -- displacement - before we erode this material, we check to see if -- it's not easier to move the material first. If that fails, we'll -- end up degrading the material as calculated @@ -383,7 +348,7 @@ local function sed() if lowest < pos.y then local tpos = {x = pos.x + lowesto.x, y = lowest, z = pos.z + lowesto.z} - if not roll(resistance) then + if not roll(mprops[node.name].r) then local tnode = minetest.get_node(tpos) if node_is_valid_target_for_displacement(tpos) then @@ -430,45 +395,27 @@ local function sed() end end - if roll(hardness) then + if roll(mprops[node.name].h) then return end -- finally, determine new material type local newmat = "air" - if node.name == "default:dirt" then - local fpos = minetest.find_node_near(pos, 2, "default:desert_sand") - if not fpos then - newmat = "default:sand" - else - newmat = "default:desert_sand" + if table.getn(mprops[node.name].t) > 1 then + -- multiple possibilities, scan area around for best suitable type + for i = table.getn(mprops[node.name].t), 2, -1 do + local fpos = minetest.find_node_near(pos, 5, mprops[node.name].t[i]) + if fpos then + newmat = mprops[node.name].t[i] + break + end end - elseif node.name == "default:dirt_with_grass" or - node.name == "default:dirt_with_grass_footsteps" or - node.name == "default:dirt_with_snow" then - newmat = "default:dirt" - elseif node.name == "default:sand" or node.name == "default:desert_sand" then - newmat = "default:clay" - elseif node.name == "default:gravel" then - newmat = "default:dirt" - elseif node.name == "default:clay" then - return - elseif node.name == "default:sandstone" or - node.name == "default:cobble" or - node.name == "default:mossycobble" or - node.name == "default:desert_cobble" then - newmat = "default:gravel" - elseif node.name == "default:desert_stone" or - node.name == "default:stone" then - newmat = "default:cobble" - elseif node.name == "default:stone_with_coal" or - node.name == "default:stone_with_iron" or - node.name == "default:stone_with_copper" or - node.name == "default:stone_with_gold" or - node.name == "default:stone_with_mese" or - node.name == "default:stone_with_diamond" then - newmat = "default:stone" + if newmat == "air" then + newmat = mprops[node.name].t[1] + end + else + newmat = mprops[node.name].t[1] end minetest.set_node(pos, {name = newmat}) diff --git a/nodes.lua b/nodes.lua new file mode 100644 index 0000000..a96ed8b --- /dev/null +++ b/nodes.lua @@ -0,0 +1,87 @@ + +-- material properties table + +-- h = probability of degradation (hardness) into lower quality material +-- r = probability of displacement (resistance) to a lower elevation +-- t = list of target materials, first one is default, others will be picked based on surroundings + +return { + -- default game materials + ["default:dirt"] + = { h = 1.0, r = 1.0, t = { "default:sand", "default:desert_sand" }}, + ["default:dirt_with_grass"] + = { h = 1.0, r = 1.0, t = { "default:dirt" }}, + ["default:dirt_with_grass_footsteps"] + = { h = 1.0, r = 1.0, t = { "default:dirt" }}, + ["default:dirt_with_snow"] + = { h = 1.0, r = 1.0, t = { "default:dirt" }}, + ["default:sand"] + = { h = 0.01, r = 1.0, t = { "default:clay" }}, + ["default:desert_sand"] + = { h = 0.01, r = 1.0, t = { "default:clay" }}, + ["default:gravel"] + = { h = 0.15, r = 0.7, t = { "default:dirt" }}, + ["default:clay"] + = { h = 0.0, r = 0.3, t = { "default:clay" }}, + ["default:sandstone"] + = { h = 0.05, r = 0.05, t = { "default:gravel" }}, + ["default:cobble"] + = { h = 0.05, r = 0.05, t = { "default:gravel" }}, + ["default:mossycobble"] + = { h = 0.05, r = 0.05, t = { "default:gravel" }}, + ["default:desert_cobble"] + = { h = 0.05, r = 0.05, t = { "default:gravel" }}, + ["default:desert_stone"] + = { h = 0.01, r = 0.01, t = { "default:desert_cobble" }}, + ["default:stone"] + = { h = 0.01, r = 0.01, t = { "default:cobblestone", "default:desert_cobble" }}, + ["default:stone_with_coal"] + = { h = 0.0001, r = 0.01, t = { "default:stone", "default:desert_stone" }}, + ["default:stone_with_iron"] + = { h = 0.0001, r = 0.01, t = { "default:stone", "default:desert_stone" }}, + ["default:stone_with_copper"] + = { h = 0.0001, r = 0.01, t = { "default:stone", "default:desert_stone" }}, + ["default:stone_with_gold"] + = { h = 0.0001, r = 0.01, t = { "default:stone", "default:desert_stone" }}, + ["default:stone_with_mese"] + = { h = 0.0001, r = 0.01, t = { "default:stone", "default:desert_stone" }}, + ["default:stone_with_diamond"] + = { h = 0.0001, r = 0.01, t = { "default:stone", "default:desert_stone" }}, + + -- mg + ["mg:dirt_with_dry_grass"] + = { h = 1.0, r = 1.0, t = { "default:dirt" }}, + + -- woodsoils + ["woodsoils:dirt_with_leaves_1"] + = { h = 1.0, r = 1.0, t = { "default:dirt" }}, + ["woodsoils:dirt_with_leaves_2"] + = { h = 1.0, r = 1.0, t = { "woodsoils:dirt_with_leaves_1" }}, + ["woodsoils:grass_with_leaves_1"] + = { h = 1.0, r = 1.0, t = { "woodsoils:dirt_with_leaves_2" }}, + ["woodsoils:grass_with_leaves_2"] + = { h = 1.0, r = 1.0, t = { "woodsoils:grass_with_leaves_1" }}, + + -- dryplants + ["dryplants:grass_short"] + = { h = 1.0, r = 1.0, t = { "default:dirt" }}, + + -- moreores + ["moreores:mineral_mithril"] + = { h = 0.0001, r = 0.01, t = { "default:stone", "default:desert_stone" }}, + ["moreores:mineral_silver"] + = { h = 0.0001, r = 0.01, t = { "default:stone", "default:desert_stone" }}, + ["moreores:mineral_tin"] + = { h = 0.0001, r = 0.01, t = { "default:stone", "default:desert_stone" }}, + ["moreores:mineral_tin"] + = { h = 0.0001, r = 0.01, t = { "default:stone", "default:desert_stone" }}, + + -- technic + ["technic:mineral_chromium"] + = { h = 0.0001, r = 0.01, t = { "default:stone", "default:desert_stone" }}, + ["technic:mineral_uranium"] + = { h = 0.0001, r = 0.01, t = { "default:stone", "default:desert_stone" }}, + ["technic:mineral_zinc"] + = { h = 0.0001, r = 0.01, t = { "default:stone", "default:desert_stone" }}, +} + |