Initial commit
This commit is contained in:
commit
3828c22946
5
.luacheckrc
Normal file
5
.luacheckrc
Normal file
@ -0,0 +1,5 @@
|
||||
std = "min"
|
||||
read_globals = {"minetest", "vector"}
|
||||
globals = {"large_slugs"}
|
||||
ignore = {"21/_.*"}
|
||||
max_line_length = 80
|
23
api.lua
Normal file
23
api.lua
Normal file
@ -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
|
125
behavior.lua
Normal file
125
behavior.lua
Normal file
@ -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,
|
||||
})
|
7
init.lua
Normal file
7
init.lua
Normal file
@ -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")
|
83
mapgen.lua
Normal file
83
mapgen.lua
Normal file
@ -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,
|
||||
})
|
61
slugs.lua
Normal file
61
slugs.lua
Normal file
@ -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,
|
||||
},
|
||||
})
|
BIN
textures/large_slugs_slug.png
Normal file
BIN
textures/large_slugs_slug.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 126 B |
Loading…
x
Reference in New Issue
Block a user