dfcaverns/big_webs/init.lua
FaceDeer 0a0c97b74e
Mineclone compatibility (#36)
* latest versions of mapgen_helper and subterrane

* initial work

* call it "minetest_game" compatibility instead of "default" compatibility

* Getting started on moving all default dependencies to a single root mod

* distilling out more dependencies

* fix some typos

* more default dependencies

* beds

* start getting some MCL equivalents set up

* mine gas dependencies

* reorganize

* add some mapgen stuff

* getting close to actually being able to run mineclone with this

* it actually runs! Crashes with out-of-memory error when you try to go below -64, but it's a start.

* hide flowing pit plasma from creative inventory

* mineclone 5 settings

* Update subterrane

* get rid of meselamp dependency, bring in ancient lanterns from deep roads

* stair dependencies

* add mcl fences

* add mcl blast resistance and hardness to everything. Also an alternate name for Nethercap in MCL, since "nether" has another meaning there.

* buckets of oil and syrup should work in mineclone now

* 'splosions!

* make hunters avoid repaired ancient lanterns

* mapgen torchspine wasn't having its timer set

* split mapgen compatibility code into its own file

* bypass dependency indirection for df_farming.

* apply threshold alpha to food items, they look better that way

* bypass dependency indirection for df_mapitems

* bypass dependency indirection for df_primordial_items

* bypass dependency indirection for df_trees

* bypass dependency indirection for df_underworld_items

* bypass dependency indirection for df_caverns

* fixing up the puzzle seal to work in both

* fix puzzle seal formspec for mcl

* create built-in substitutes for fireflies and bones mods for when those aren't available

* set up mcl dungeon loot for underworld warriors, port over some translations from default

* overlooked a debug

* add itemslot backgrounds for mcl

* added mineclone groups to all registered nodes. TODO: craftitems.

This was extremely tedious. Completely untested, aside from simply running the game.

* minor fixes to the built-in bones node

* eatable group for edibles

* clean up some TODOs

* adjust pit plasma abm conditions

* add df_ambience

* fixing up explosions. Also make slade sand diggable in mcl, and fix a bug in web generators

* make tower cap caves less chirpy, fix bigger goblin hut schematic, allow glowing spindlestem extract bottles

* avoid an undeclared global check

* alas, cave pearls aren't set up right for attached_node_facedir.

* bunch of work on mineclone ores, moved main config into df_dependencies

* add a few more ores

* update depends in mod.conf

* add opaque group to light-sensitive dirt types

Mineclone adds the "opaque" group only to non-light nodes, and torches check for the opaque group to decide whether they can be placed there. light-sensitive nodes need the "light" paramtype to work, though. So adding the opaque group manually to these.

* add a touch of reverb to one of the whisper tracks, it didn't fit with the others without it

* bloodthorn also needs to be set opaque

* add sound to torchspines

* isolate Nethercap translation name to make it easier to swap out in Mineclone contexts

* ambience tweak

* fix dirt spreads

https://github.com/FaceDeer/dfcaverns/issues/35

* adding achievements! Almost all untested yet.

* fix a few achievements glitches

* tweak some more achievements, add delay when achievements unlock other achievements

* fix farming achievements, fix spindlestem callbacks on place

* icons for farming achievements

* more achievement icons, fix ancient lantern achievement

* two more icons, update text

* add icons for upper cavern layers

* all achievements have icons now. Also add another sound to the magma sea ambience

* hook into awards' trigger system to get "x/y" progress displayed for the multi-achievement achievements

* ironically, Mineclone has an old version of awards that is incompatible with my trigger work.

* every award should now have a description and a difficulty.

* removing leftovers

* missing callbacks for farmables

* put growth restrictions on farmables so the achievement doesn't trigger inappropriately.

* enable ores in MCL2, fix some undeclared globals, fix icecap growth in MCL (achievements are a good debugging tool)

* get *all* the copper and iron containing nodes

* fix old awards mod's handling of grouped dig items

* Add a little bonus for players who activate a slade breacher - a handheld 'splosion tool

* used the wrong drop method

* beef up explosions in MCL, make slade brick craftable from slade sand and lava

* better creative mode checks, fix crash when digging walls in MCL

* Update subterrane

* various bugfixes and tweaks

* whipping up a simple puzzle chest to give a clue about ancient numbering

The coding is done, but UI and a node mesh need to be done

* prepare for some art tomorrow

* chest node and sounds

* images for the combination dials

* add puzzle chests to the underworld buildings

* update translations

* oops, can't initialize the contents of puzzle chests every time or players get endless stuff

* add backgrounds to item slots in MCL

* wrap the existing function rather than copy and pasting it

* fix bucket dependency in cooking recipes

* add _mcl_saturation to edibles
2022-08-28 23:48:44 -06:00

201 lines
6.3 KiB
Lua

local modname = minetest.get_current_modname()
local S = minetest.get_translator(modname)
local sound
if df_dependencies.sound_leaves then
sound = df_dependencies.sound_leaves()
end
local get_node_box = function(connector_thickness)
return {
type = "connected",
--fixed = {-hub_thickness,-hub_thickness,-hub_thickness,hub_thickness,hub_thickness,hub_thickness},
connect_top = {-connector_thickness, 0, -connector_thickness, connector_thickness, 0.5, connector_thickness},
connect_bottom = {-connector_thickness, -0.5, -connector_thickness, connector_thickness, 0, connector_thickness},
connect_back = {-connector_thickness, -connector_thickness, 0, connector_thickness, connector_thickness, 0.5},
connect_right = {0, -connector_thickness, -connector_thickness, 0.5, connector_thickness, connector_thickness},
connect_front = {-connector_thickness, -connector_thickness, -0.5, connector_thickness, connector_thickness, 0},
connect_left = {-0.5, -connector_thickness, -connector_thickness, 0, connector_thickness, connector_thickness},
disconnected = {-connector_thickness, -connector_thickness, -connector_thickness, connector_thickness, connector_thickness, connector_thickness},
}
end
local anchor_groups = {"group:soil", "group:stone", "group:tree", "group:wood", "group:webbing", "group:solid"}
local in_anchor_group = function(name)
for _, group in pairs(anchor_groups) do
if minetest.get_item_group(name, string.sub(group, 7)) then
return true
end
end
if name == "ignore" then
return true
end
end
local cardinal_directions = {
{x=1,y=0,z=0},
{x=-1,y=0,z=0},
{x=0,y=1,z=0},
{x=0,y=-1,z=0},
{x=0,y=0,z=1},
{x=0,y=0,z=-1}
}
local cardinal_planes = {
{3,5},
{3,5},
{1,5},
{1,5},
{1,3},
{1,3},
}
local insert_if_not_in_hashtable = function(pos, insert_into, if_not_in)
local hash = minetest.hash_node_position(pos)
if if_not_in[hash] then
return
end
table.insert(insert_into, pos)
end
-- flood fill through the web to get all web and anchor locations
local get_web_nodes = function(pos, webs, anchors)
local to_check = {}
table.insert(to_check, pos)
while next(to_check) ~= nil do
local check_pos = table.remove(to_check)
local check_node = minetest.get_node(check_pos)
if minetest.get_item_group(check_node.name, "webbing") > 0 then
webs[minetest.hash_node_position(check_pos)] = true
for _, dir in pairs(cardinal_directions) do
insert_if_not_in_hashtable(vector.add(check_pos, dir), to_check, webs)
end
elseif in_anchor_group(check_node.name) then
anchors[minetest.hash_node_position(check_pos)] = true
end
end
end
local web_line = function(pos, dir, distance)
local anchored
local web_spine = {}
for i = 0, distance do
local web_pos = vector.add(pos, vector.multiply(dir,i))
local node_name = minetest.get_node(web_pos).name
if node_name == "air" or node_name == "big_webs:webbing" then
table.insert(web_spine, web_pos)
elseif in_anchor_group(node_name) then
anchored=true
break
else
anchored=false
break
end
end
if anchored then
for _, web_pos in pairs(web_spine) do
if math.random() < 0.9 then
minetest.set_node(web_pos, {name="big_webs:webbing"})
end
end
return web_spine
end
return nil
end
local generate_web = function(pos)
local dir_choice = math.random(1, 6)
local dir = cardinal_directions[dir_choice]
local web_spine = web_line(pos, dir, 30)
if web_spine then
local dir2 = cardinal_directions[cardinal_planes[dir_choice][math.random(1, 2)]]
local dir2_opposite = vector.multiply(dir2, -1)
for _, web_pos in pairs(web_spine) do
web_line(web_pos, dir2, 15)
web_line(web_pos, dir2_opposite, 15)
end
end
end
minetest.register_node("big_webs:webbing", {
description = S("Giant Cave Spider Webbing"),
_doc_items_longdesc = S("Thick ropes of sticky, springy silk, strung between cavern walls in hopes of catching bats and even larger beasts."),
_doc_items_usagehelp = S("Webbing can be collected and re-strung elsewhere to aid in climbing. It absorbs all falling damage when you land on it."),
tiles = {
{name="big_webs.png"},
},
use_texture_alpha = "blend",
connects_to = anchor_groups,
connect_sides = { "top", "bottom", "front", "left", "back", "right" },
drawtype = "nodebox",
node_box = get_node_box(0.0625),
collision_box = get_node_box(0.0625),
inventory_image = "big_webs_item.png",
wield_image = "big_webs_item.png",
paramtype = "light",
is_ground_content = false,
climbable = true,
groups = {snappy = 2, choppy = 2, webbing = 1, shearsy = 1, swordy=1, flammable=1, destroy_by_lava_flow=1, fall_damage_add_percent=-100, bouncy=20},
sounds = sound,
on_construct = function(pos)
minetest.get_node_timer(pos):start(30)
end,
on_destruct = function(pos)
for _, dir in pairs(cardinal_directions) do
local neighbor_pos = vector.add(pos, dir)
if minetest.get_item_group(minetest.get_node(neighbor_pos).name, "webbing") > 0 then
minetest.get_node_timer(neighbor_pos):start(30)
end
end
minetest.get_node_timer(pos):stop()
end,
on_timer = function(pos, elapsed)
local webs = {}
local anchors = {}
get_web_nodes(pos, webs, anchors)
local first_anchor = next(anchors)
for hash, _ in pairs(webs) do
local web_pos = minetest.get_position_from_hash(hash)
if first_anchor == nil then
-- unsupported web
minetest.set_node(web_pos, {name="air"})
minetest.item_drop(ItemStack("big_webs:webbing"), nil, web_pos)
end
minetest.get_node_timer(web_pos):stop() -- no need to recheck
end
end,
_mcl_blast_resistance = 1.0,
_mcl_hardness = 0.5,
})
minetest.register_node("big_webs:web_egg", {
description = S("Giant Cave Spider Web Generator"),
tiles = {
{name="big_webs.png"},
},
use_texture_alpha = "blend",
connects_to = anchor_groups,
connect_sides = { "top", "bottom", "front", "left", "back", "right" },
drawtype = "nodebox",
node_box = get_node_box(0.0625),
collision_box = get_node_box(0.0625),
inventory_image = "big_webs_item.png",
wield_image = "big_webs_item.png",
paramtype = "light",
is_ground_content = false,
climbable = true,
floodable = true,
groups = {snappy = 2, choppy = 2, webbing = 1, flammable=1, fall_damage_add_percent=-100, bouncy=20},
sounds = sound,
on_construct = function(pos)
minetest.get_node_timer(pos):start(1)
end,
on_timer = function(pos, elapsed)
minetest.set_node(pos, {name="air"})
generate_web(pos)
end,
_mcl_blast_resistance = 1.0,
_mcl_hardness = 0.5,
})