From 3828c22946783fe5cfd94db16dfe70a92051bda4 Mon Sep 17 00:00:00 2001 From: Jude Melton-Houghton Date: Fri, 24 Sep 2021 10:30:37 -0400 Subject: [PATCH] Initial commit --- .luacheckrc | 5 ++ api.lua | 23 +++++++ behavior.lua | 125 ++++++++++++++++++++++++++++++++++ init.lua | 7 ++ mapgen.lua | 83 ++++++++++++++++++++++ mod.conf | 2 + slugs.lua | 61 +++++++++++++++++ textures/large_slugs_slug.png | Bin 0 -> 126 bytes 8 files changed, 306 insertions(+) create mode 100644 .luacheckrc create mode 100644 api.lua create mode 100644 behavior.lua create mode 100644 init.lua create mode 100644 mapgen.lua create mode 100644 mod.conf create mode 100644 slugs.lua create mode 100644 textures/large_slugs_slug.png diff --git a/.luacheckrc b/.luacheckrc new file mode 100644 index 0000000..03a7e36 --- /dev/null +++ b/.luacheckrc @@ -0,0 +1,5 @@ +std = "min" +read_globals = {"minetest", "vector"} +globals = {"large_slugs"} +ignore = {"21/_.*"} +max_line_length = 80 diff --git a/api.lua b/api.lua new file mode 100644 index 0000000..4ef9d6d --- /dev/null +++ b/api.lua @@ -0,0 +1,23 @@ +large_slugs.registered_slugs = {} + +function large_slugs.register_slug(name, def) + minetest.register_node(name, { + description = def.description, + drawtype = "signlike", + tiles = {def.texture}, + inventory_image = def.texture, + selection_box = { + type = "wallmounted", + wall_top = {-8/16, 8/16, -8/16, 8/16, 7/16, 8/16}, + wall_bottom = {-8/16, -8/16, -8/16, 8/16, -7/16, 8/16}, + wall_side = {-8/16, -8/16, -8/16, -7/16, 8/16, 8/16}, + }, + sunlight_propagates = true, + paramtype = "light", + paramtype2 = "wallmounted", + groups = {large_slug = 1, dig_immediate = 3, attached_node = 1}, + walkable = false, + floodable = true, + }) + large_slugs.registered_slugs[name] = def +end diff --git a/behavior.lua b/behavior.lua new file mode 100644 index 0000000..ddf4ad1 --- /dev/null +++ b/behavior.lua @@ -0,0 +1,125 @@ +local MOVE_INTERVAL = + tonumber(minetest.settings:get("large_slugs_move_interval")) or 5 +local MOVE_CHANCE = + tonumber(minetest.settings:get("large_slugs_move_chance")) or 5 +local BIRTH_INTERVAL = + tonumber(minetest.settings:get("large_slugs_birth_interval")) or 10 +local BIRTH_CHANCE = + tonumber(minetest.settings:get("large_slugs_birth_chance")) or 10 +local BIRTH_SPACE = + tonumber(minetest.settings:get("large_slugs_birth_space")) or 11 + +local WALLMOUNT_TO_PERP_WALLMOUNTS = {} +WALLMOUNT_TO_PERP_WALLMOUNTS[0] = {4, 2, 5, 3} +WALLMOUNT_TO_PERP_WALLMOUNTS[2] = {4, 0, 5, 1} +WALLMOUNT_TO_PERP_WALLMOUNTS[4] = {2, 0, 3, 1} +WALLMOUNT_TO_PERP_WALLMOUNTS[1] = WALLMOUNT_TO_PERP_WALLMOUNTS[0] +WALLMOUNT_TO_PERP_WALLMOUNTS[3] = WALLMOUNT_TO_PERP_WALLMOUNTS[2] +WALLMOUNT_TO_PERP_WALLMOUNTS[5] = WALLMOUNT_TO_PERP_WALLMOUNTS[4] + +local WALLMOUNT_TO_OPP_WALLMOUNT = { + [0] = 1, [1] = 0, [2] = 3, [3] = 2, [4] = 5, [5] = 4, +} + +local function get_move_options(pos, node, include_here) + local ground_nodes = large_slugs.registered_slugs[node.name].ground + + local wallmount = node.param2 % 6 + local dir = minetest.wallmounted_to_dir(wallmount) + + local rotate_opts = include_here and {} + local shift_opts = {} + local rotate_shift_opts = {} + + local perp_wallmounts = WALLMOUNT_TO_PERP_WALLMOUNTS[wallmount] + for _, perp_wallmount in ipairs(perp_wallmounts) do + local perp_dir = minetest.wallmounted_to_dir(perp_wallmount) + + local check_pos = vector.add(pos, perp_dir) + local check_node = minetest.get_node(check_pos) + if include_here and ground_nodes[check_node.name] then + rotate_opts[#rotate_opts + 1] = perp_wallmount + elseif check_node.name == "air" then + local shift_pos = check_pos + check_pos = vector.add(check_pos, dir) + check_node = minetest.get_node(check_pos) + if ground_nodes[check_node.name] then + shift_opts[#shift_opts + 1] = shift_pos + elseif check_node.name == "air" then + rotate_shift_opts[#rotate_shift_opts + 1] = { + WALLMOUNT_TO_OPP_WALLMOUNT[ + perp_wallmount], + check_pos, + } + end + end + end + + return rotate_opts, shift_opts, rotate_shift_opts +end + +local function move_slug(pos, node) + local rotate_opts, shift_opts, rotate_shift_opts = + get_move_options(pos, node, true) + + local n_rotate_opts = #rotate_opts + local n_shift_opts = #shift_opts + local n_rotate_shift_opts = #rotate_shift_opts + local n_opts = n_rotate_opts + n_shift_opts + n_rotate_shift_opts + if n_opts < 1 then return end + local choice = math.random(n_opts) + if choice <= n_rotate_opts then + local chosen_wallmount = rotate_opts[choice] + node.param2 = node.param2 - node.param2 % 8 + chosen_wallmount + minetest.swap_node(pos, node) + elseif choice <= n_rotate_opts + n_shift_opts then + local chosen_pos = shift_opts[choice - n_rotate_opts] + minetest.remove_node(pos) + minetest.set_node(chosen_pos, node) + else + local chosen = + rotate_shift_opts[choice - n_rotate_opts - n_shift_opts] + minetest.remove_node(pos) + node.param2 = node.param2 - node.param2 % 8 + chosen[1] + minetest.set_node(chosen[2], node) + end +end + +local function birth_slug(pos, node) + if minetest.find_node_near(pos, BIRTH_SPACE, node.name) then return end + + local _rotate_opts, shift_opts, rotate_shift_opts = + get_move_options(pos, node, false) + + local n_shift_opts = #shift_opts + local n_rotate_shift_opts = #rotate_shift_opts + local n_opts = n_shift_opts + n_rotate_shift_opts + if n_opts < 1 then return end + local choice = math.random(n_opts) + if choice <= n_shift_opts then + local chosen_pos = shift_opts[choice] + minetest.set_node(chosen_pos, node) + else + local chosen = rotate_shift_opts[choice - n_shift_opts] + node.param2 = node.param2 - node.param2 % 8 + chosen[1] + minetest.set_node(chosen[2], node) + end +end + +minetest.register_abm({ + label = "Slugs moving", + nodenames = "group:large_slug", + interval = MOVE_INTERVAL, + chance = MOVE_CHANCE, + catch_up = false, + action = move_slug, +}) + +minetest.register_abm({ + label = "Slugs birthing", + nodenames = "group:large_slug", + interval = BIRTH_INTERVAL, + chance = BIRTH_CHANCE, + catch_up = false, + action = birth_slug, +}) diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..3b94267 --- /dev/null +++ b/init.lua @@ -0,0 +1,7 @@ +large_slugs = {} + +local modpath = minetest.get_modpath(minetest.get_current_modname()) +dofile(modpath.."/api.lua") +dofile(modpath.."/behavior.lua") +dofile(modpath.."/slugs.lua") +dofile(modpath.."/mapgen.lua") diff --git a/mapgen.lua b/mapgen.lua new file mode 100644 index 0000000..d66b724 --- /dev/null +++ b/mapgen.lua @@ -0,0 +1,83 @@ +print("MAPGEN") + +local function noise_params(ratio, seed) + return { + offset = 0, + scale = ratio, + spread = {x = 32, y = 32, z = 32}, + seed = seed, + octaves = 1, + persistence = 1, + lacunarity = 1, + flags = "absvalue", + } +end + +minetest.register_decoration({ + name = "large_slugs:grass_slug", + deco_type = "simple", + place_on = {"default:dirt_with_grass"}, + fill_ratio = 0.01, + y_max = 200, + y_min = 0, + decoration = "large_slugs:grass_slug", + param2 = 1, +}) + +minetest.register_decoration({ + name = "large_slugs:pine_slug", + deco_type = "simple", + place_on = {"default:dirt_with_coniferous_litter"}, + fill_ratio = 0.01, + y_max = 250, + y_min = 0, + decoration = "large_slugs:pine_slug", + param2 = 1, +}) + +minetest.register_decoration({ + name = "large_slugs:rainforest_slug", + deco_type = "simple", + place_on = {"default:dirt_with_rainforest_litter"}, + fill_ratio = 0.01, + y_max = 200, + y_min = 0, + decoration = "large_slugs:rainforest_slug", + param2 = 1, +}) + +minetest.register_decoration({ + name = "large_slugs:cave_slug", + deco_type = "simple", + place_on = {"default:stone"}, + fill_ratio = 0.012, + flags = "all_floors", + y_max = -32, + y_min = -31000, + decoration = "large_slugs:cave_slug", + param2 = 1, +}) + +minetest.register_decoration({ + name = "large_slugs:iron_slug", + deco_type = "simple", + place_on = {"default:stone"}, + fill_ratio = 0.005, + flags = "all_floors", + y_max = -128, + y_min = -31000, + decoration = "large_slugs:iron_slug", + param2 = 1, +}) + +minetest.register_decoration({ + name = "large_slugs:mese_slug", + deco_type = "simple", + place_on = {"default:stone"}, + fill_ratio = 0.001, + flags = "all_floors", + y_max = -512, + y_min = -31000, + decoration = "large_slugs:mese_slug", + param2 = 1, +}) diff --git a/mod.conf b/mod.conf new file mode 100644 index 0000000..54257ef --- /dev/null +++ b/mod.conf @@ -0,0 +1,2 @@ +name = large_slugs +depends = default diff --git a/slugs.lua b/slugs.lua new file mode 100644 index 0000000..7b3fba1 --- /dev/null +++ b/slugs.lua @@ -0,0 +1,61 @@ +large_slugs.register_slug("large_slugs:grass_slug", { + description = "Grass Slug", + texture = "large_slugs_slug.png^[multiply:#696533", + ground = { + ["default:dirt"] = true, + ["default:dirt_with_grass"] = true, + }, +}) + +large_slugs.register_slug("large_slugs:pine_slug", { + description = "Pine Slug", + texture = "large_slugs_slug.png^[multiply:#444220", + ground = { + ["default:dirt"] = true, + ["default:dirt_with_coniferous_litter"] = true, + ["default:pine_tree"] = true, + }, +}) + +large_slugs.register_slug("large_slugs:rainforest_slug", { + description = "Rainforest Slug", + texture = "large_slugs_slug.png^[multiply:#B5AC44", + ground = { + ["default:dirt"] = true, + ["default:dirt_with_rainforest_litter"] = true, + ["default:jungletree"] = true, + }, +}) + +large_slugs.register_slug("large_slugs:cave_slug", { + description = "Cave Slug", + texture = "large_slugs_slug.png^[multiply:#555343", + ground = { + ["default:stone"] = true, + ["default:cobble"] = true, + ["default:mossycobble"] = true, + ["default:stone_with_coal"] = true, + }, +}) + +large_slugs.register_slug("large_slugs:iron_slug", { + description = "Iron Slug", + texture = "large_slugs_slug.png^[multiply:#A0661E", + ground = { + ["default:stone"] = true, + ["default:cobble"] = true, + ["default:mossycobble"] = true, + ["default:stone_with_iron"] = true, + }, +}) + +large_slugs.register_slug("large_slugs:mese_slug", { + description = "Mese Slug", + texture = "large_slugs_slug.png^[multiply:#FFEB00", + ground = { + ["default:stone"] = true, + ["default:cobble"] = true, + ["default:mossycobble"] = true, + ["default:stone_with_mese"] = true, + }, +}) diff --git a/textures/large_slugs_slug.png b/textures/large_slugs_slug.png new file mode 100644 index 0000000000000000000000000000000000000000..fea71eeff117b8e643a7fcd3fce6ea0683ea0fd2 GIT binary patch literal 126 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`uAVNAAr`0KPBIi?FkoT%DEhx% zD1K+iE(Ontr^05%8naytNJ_hLHk{$WW*J6?Ob4r-(F*FDb}wgK_e3Cc>VLU+Zqt62 ZMe$!Zu9y+fcm!x5gQu&X%Q~loCIGZ0DVzWR literal 0 HcmV?d00001