commit 80ec47195392bcf78b32e90bef0385dde0f03f38 Author: Auke Kok Date: Wed Nov 22 00:41:49 2017 -0800 Initial Commit diff --git a/.luacheckrc b/.luacheckrc new file mode 100644 index 0000000..15eed66 --- /dev/null +++ b/.luacheckrc @@ -0,0 +1,15 @@ +unused_args = false +allow_defined_top = true + +read_globals = { + "DIR_DELIM", + "minetest", "core", + "dump", + "vector", "nodeupdate", + "VoxelManip", "VoxelArea", + "PseudoRandom", "ItemStack", + "intllib", + "default", + table = { fields = { "copy", "getn" } } +} + diff --git a/depends.txt b/depends.txt new file mode 100644 index 0000000..4ad96d5 --- /dev/null +++ b/depends.txt @@ -0,0 +1 @@ +default diff --git a/description.txt b/description.txt new file mode 100644 index 0000000..51cee77 --- /dev/null +++ b/description.txt @@ -0,0 +1 @@ +Bring color into the mgv7 mapgen world. diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..5efb142 --- /dev/null +++ b/init.lua @@ -0,0 +1,185 @@ + +--[[ + + grass - biome colored grass + + (C) LGPL-2.1+ Auke Kok + + Textures are licensed according to their respective origin + from github.com/minetest/minetest_game, generally CC-BY-SA-4.0 + or similar. + +]]-- + +local wp = minetest.get_worldpath() .. "/luscious" + +local mgp = minetest.get_mapgen_params() +local chunksize = 16 * mgp.chunksize + +local function after_place_node(pos, placer, itemstack, pointed_thing) + -- get chunk from pos + local v = vector.apply(pos, function(a) return math.floor((a - 48) / chunksize) end) + local o = vector.subtract(pos, vector.apply(v, function(a) return (a * chunksize) + 48 end)) + local l = o.z * (chunksize) + o.x + local p = minetest.hash_node_position(v) + + local f = assert(io.open(wp .. "/" .. string.format("%d", p), "r"), + "unable to find map for " .. string.format("%d", p)) + local z = f:read("*a") + f:close() + local map = minetest.decompress(z) + + local node = minetest.get_node(pos) + node.param2 = string.byte(map, l + 1) + minetest.swap_node(pos, node) +end + +minetest.override_item("default:dirt_with_grass", { + paramtype2 = "color", + drawtype = "color", + palette_index = 136, + palette = "default_luscious_palette.png", + tiles = {"default_grass.png", {name = "default_dirt.png", color = "white"}, "default_grass.png"}, + overlay_tiles = {"", "", {name = "default_dirt_overlay.png", color = "white"}}, + place_param2 = 136, + after_place_node = after_place_node, +}) + +for _, v in pairs({ + "default:leaves", + "default:aspen_leaves", + "default:jungleleaves", + "default:pine_needles", + "default:acacia_leaves", + "default:bush_leaves", + "default:acacia_bush_leaves", +}) do + minetest.override_item(v, { + paramtype2 = "color", + palette_index = 136, + palette = "default_luscious_palette.png", + place_param2 = 136, + after_place_node = after_place_node, + }) +end + +minetest.register_alias_force("default:dirt_with_dry_grass", "default:dirt_with_grass") +minetest.register_alias_force("default:dirt_with_rainforest_litter", "default:dirt_with_grass") +minetest.register_alias_force("default:dirt_with_snow", "default:dirt_with_grass") + +for _, v in pairs({ + "default:grass_1", + "default:grass_2", + "default:grass_3", + "default:grass_4", + "default:grass_5", + "default:junglegrass", +}) do + minetest.override_item(v, { + paramtype2 = "color", + palette_index = 136, + palette = "default_luscious_palette.png", + place_param2 = 136, + after_place_node = after_place_node, + }) +end +for i = 1, 5 do + minetest.register_alias_force("default:dry_grass_" .. i, "default:grass_" .. i) +end + +-- content ids +local cn = { + ["default:dirt_with_grass"] = 1, + ["default:grass_1"] = 1, + ["default:grass_2"] = 1, + ["default:grass_3"] = 1, + ["default:grass_4"] = 1, + ["default:grass_5"] = 1, + ["default:junglegrass"] = 1, + ["default:leaves"] = 1, + ["default:aspen_leaves"] = 1, + ["default:jungleleaves"] = 1, + ["default:pine_needles"] = 1, + ["default:acacia_leaves"] = 1, + ["default:bush_leaves"] = 1, + ["default:acacia_bush_leaves"] = 1, +} +local cs = {} +for k, _ in pairs(cn) do + cs[minetest.get_content_id(k)] = 1 +end + +minetest.register_on_generated(function(minp, maxp, blockseed) + local v = vector.apply(minp, function(a) return (a - 48) / chunksize end) + local heatmap = minetest.get_mapgen_object("heatmap") + local humiditymap = minetest.get_mapgen_object("humiditymap") + local map = "" + for i = 1, #heatmap do + local h1 = heatmap[i] + local h2 = humiditymap[i] + h1 = math.floor(math.min(math.max(math.floor(h1), 0), 100) / 6.6) + h2 = math.floor(math.min(math.max(math.floor(h2), 0), 100) / 6.6) + map = map .. string.char(h1 + (h2 * 16)) + end + local p = string.format("%d", minetest.hash_node_position(v)) + + local f = assert(io.open(wp .. "/" .. p, "w"), wp .. "/" .. p) + f:write(minetest.compress(map)) + f:close() + + local vm, emin, emax = minetest.get_mapgen_object("voxelmanip") + local area = VoxelArea:new{MinEdge = emin, MaxEdge = emax} + local data = vm:get_data() + local p2data = vm:get_param2_data() + for z = minp.z, maxp.z do + for y = minp.y, maxp.y do + local vi = area:index(minp.x, y, z) + for x = minp.x, maxp.x do + local vv = (x - minp.x) + ((z - minp.z) * chunksize) + if cs[data[vi]] then + local mv = string.byte(map, vv + 1) + p2data[vi] = mv + end + vi = vi + 1 + end + end + end + vm:set_param2_data(p2data) + vm:write_to_map() +end) + +local function update_p2(pos, size) + local minp = {x = pos.x - size[1], y = pos.y, z = pos.z - size[1]} + local maxp = {x = pos.x + size[1], y = pos.y + size[2], z = pos.z + size[1]} + for x = minp.x, maxp.x do + for y = minp.y, maxp.y do + for z = minp.z, maxp.z do + local p = vector.new(x, y, z) + local node = minetest.get_node(p) + if cn[node.name] then + after_place_node(p) + end + end + end + end +end + +local saplings = { + ["default:sapling"] = {2, 8}, + ["default:junglesapling"] = {2, 17}, + ["default:pine_sapling"] = {2, 14}, + ["default:acacia_sapling"] = {4, 8}, + ["default:aspen_sapling"] = {2, 12}, + ["default:bush_sapling"] = {1, 3}, + ["default:acacia_bush_sapling"] = {1, 3}, +} + +for k, v in pairs(saplings) do + minetest.override_item(k, { + on_timer = function(pos) + default.grow_sapling(pos) + update_p2(pos, v) + end, + }) +end + diff --git a/mod.conf b/mod.conf new file mode 100644 index 0000000..7aa8a5f --- /dev/null +++ b/mod.conf @@ -0,0 +1 @@ +name = luscious diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..47359e6 --- /dev/null +++ b/readme.md @@ -0,0 +1,33 @@ + +## luscious + +Makes your map luscious. + +This mod heavily modifies your base landscape and modifies various +nodes like dirt and leaves so that they become colored using node +coloring. + +The color selection of each node is decided based on the biome data, +using heat and humidity. These are mapped on a 16x16 palette where +the heat is mapped along the x axis from 0-15 and the humidity along +the y axis with the same range. This gives us a total of 256 possible +colorizations of each node. + +Manual placing of the nodes, and sapling placement is also modified to +make trees growing or manual placing of nodes also result in colorized +nodes in the landscape. + +## features + +- jungle dirt is replaced by dirt with grass +- dirt with dry grass is replaced by dirt with grass +- dirt with snow is replaced by dirt with grass +- dry grass is replaced with grass + +## bugs + +- leaf decay is broken due to p2 usage +- grass spread is broken or will place wrongly colored grass nodes +- inventory items lack proper coloring +- snowy pine trees are missing + diff --git a/textures/default_acacia_leaves.png b/textures/default_acacia_leaves.png new file mode 100644 index 0000000..bc9d3db Binary files /dev/null and b/textures/default_acacia_leaves.png differ diff --git a/textures/default_aspen_leaves.png b/textures/default_aspen_leaves.png new file mode 100644 index 0000000..0f8fa11 Binary files /dev/null and b/textures/default_aspen_leaves.png differ diff --git a/textures/default_dirt_overlay.png b/textures/default_dirt_overlay.png new file mode 100644 index 0000000..e4cdc1c Binary files /dev/null and b/textures/default_dirt_overlay.png differ diff --git a/textures/default_grass.png b/textures/default_grass.png new file mode 100644 index 0000000..fa132b4 Binary files /dev/null and b/textures/default_grass.png differ diff --git a/textures/default_grass_1.png b/textures/default_grass_1.png new file mode 100644 index 0000000..d726b73 Binary files /dev/null and b/textures/default_grass_1.png differ diff --git a/textures/default_grass_2.png b/textures/default_grass_2.png new file mode 100644 index 0000000..275800e Binary files /dev/null and b/textures/default_grass_2.png differ diff --git a/textures/default_grass_3.png b/textures/default_grass_3.png new file mode 100644 index 0000000..b151db3 Binary files /dev/null and b/textures/default_grass_3.png differ diff --git a/textures/default_grass_4.png b/textures/default_grass_4.png new file mode 100644 index 0000000..741d242 Binary files /dev/null and b/textures/default_grass_4.png differ diff --git a/textures/default_grass_5.png b/textures/default_grass_5.png new file mode 100644 index 0000000..dc96c06 Binary files /dev/null and b/textures/default_grass_5.png differ diff --git a/textures/default_grass_side.png b/textures/default_grass_side.png new file mode 100644 index 0000000..344ec81 Binary files /dev/null and b/textures/default_grass_side.png differ diff --git a/textures/default_jungleleaves.png b/textures/default_jungleleaves.png new file mode 100644 index 0000000..06c184a Binary files /dev/null and b/textures/default_jungleleaves.png differ diff --git a/textures/default_leaves.png b/textures/default_leaves.png new file mode 100644 index 0000000..5488985 Binary files /dev/null and b/textures/default_leaves.png differ diff --git a/textures/default_luscious_palette.png b/textures/default_luscious_palette.png new file mode 100644 index 0000000..ab0cfa0 Binary files /dev/null and b/textures/default_luscious_palette.png differ diff --git a/textures/default_pine_needles.png b/textures/default_pine_needles.png new file mode 100644 index 0000000..e9244a0 Binary files /dev/null and b/textures/default_pine_needles.png differ