Initial version

master
Alex Yst 2018-02-09 13:34:54 -08:00
commit 71dfd1ae91
4 changed files with 343 additions and 0 deletions

5
depends.txt Normal file
View File

@ -0,0 +1,5 @@
bucket?
default
flowers?
minestats
tnt?

301
init.lua Normal file
View File

@ -0,0 +1,301 @@
-- Trace Minerals mod for Minetest
-- Copyright © 2018 Alex Yst <mailto:copyright@y.st>
-- This program is free software; you can redistribute it and/or
-- modify it under the terms of the GNU Lesser General Public
-- License as published by the Free Software Foundation; either
-- version 2.1 of the License, or (at your option) any later version.
-- This software is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-- Lesser General Public License for more details.
-- You should have received a copy of the GNU Lesser General Public
-- License along with this program. If not, see
-- <https://www.gnu.org./licenses/>.
-----------------------------------------------------------------------
-- We'll read the settings only once at load time. No need to read them
-- every time a "default:stone" is dug, that'd just be slow.
local config = {
renew_minerals = minetest.settings:get_bool("trace_minerals.renew_minerals"),
renew_soils = minetest.settings:get_bool("trace_minerals.renew_soils"),
renew_living = minetest.settings:get_bool("trace_minerals.renew_living"),
renew_liquids = minetest.settings:get_bool("trace_minerals.renew_liquids"),
renew_gunpowder = minetest.settings:get("trace_minerals.renew_gunpowder"),
drops = {}, -- will be used later
can_harvest = {}, -- will be used later
mapgen = minetest.get_mapgen_params().mgname,
}
-- These settings are booleans, but it looks lime we don't have a way
-- to set default values. We set defaults in settingtypes.txt, but it
-- looks like those only apply in the menu, not in the actual game.
-- Let's set some values if none are found.
if config.renew_minerals == nil then
config.renew_minerals = true
end
if config.renew_soils == nil then
config.renew_soils = true
end
if config.renew_living == nil then
config.renew_living = false
end
if config.renew_liquids == nil then
config.renew_liquids = false
end
-- This setting is read as a string. We need to make sure it has a sane
-- value so we can avoid strange behaviour.
if (config.renew_gunpowder == "Flint" and not config.renew_minerals) or
(config.renew_gunpowder == "Gravel" and not config.renew_soils) or
(config.renew_gunpowder ~= "Flint" and config.renew_gunpowder ~= "Gravel") then
config.renew_gunpowder = "None"
end
-- For randomisation, we need to know how many possible drops can be
-- had, based on the administrator's settings. Let's add them up.
-- Remember, we need to take the map generator into consideration. This
-- mod intends to make existing obtainable materials renewable, not
-- provide access to otherwise-unobtainable materials.
minetest.debug(dump(config.renew_minerals))
if config.mapgen ~= "singlenode" then
if config.renew_minerals then
config.can_harvest["default:clay_lump"] = true
config.can_harvest["default:coal_lump"] = true
config.can_harvest["default:copper_lump"] = true
config.can_harvest["default:diamond"] = true
config.can_harvest["default:gold_lump"] = true
config.can_harvest["default:iron_lump"] = true
config.can_harvest["default:mese_crystal_fragment"] = true
config.can_harvest["default:tin_lump"] = true
if config.renew_gunpowder ~= "Gravel" then
config.can_harvest["default:flint"] = true
end
if not minetest.registered_items["bucket:bucket_lava"] or not config.renew_liquids then
config.can_harvest["default:obsidian_shard"] = true
end
end
if config.renew_soils then
config.can_harvest["default:desert_sand"] = true
config.can_harvest["default:dirt"] = true
config.can_harvest["default:sand"] = true
config.can_harvest["default:silver_sand"] = true
config.can_harvest["default:ice"] = true
config.can_harvest["default:desert_cobble"] = true
if config.renew_gunpowder == "Gravel" then
config.can_harvest["default:gravel"] = true
end
end
if config.renew_liquids then
if minetest.registered_items["bucket:bucket_lava"] then
config.can_harvest["default:lava_source"] = false
end
if config.mapgen == "valleys" and minetest.registered_items["bucket:bucket_river_water"] then
config.can_harvest["default:river_water_source"] = false
end
end
if config.renew_living then
config.can_harvest["flowers:waterlily"] = true
if config.mapgen ~= "v6" then
config.can_harvest["default:coral_skeleton"] = true
end
end
end
-- We've composed a list of things we want stone to sometimes drop, and
-- that's all well and good. However, do we really know if all (or any)
-- of these have been defined? Due to a hard dependency on default
-- (required because this mod is useless if we don't redefine
-- "default:stone"), we can be fairly sure any of these items from
-- default are present, but this mod might be assuming a different
-- version of Minetest Game than is present. If Minetest Game is too
-- old, some of these might not be defined. Additionally, some of these
-- items are from mods that are only softly depended on. Let's try not
-- to drop unknown items; we should check to be sure of which items are
-- present. This mod is totally going to crash your server at load time
-- if "default:stone" isn't defined though. Just sayin'. But for all
-- other items, we'll check instead of assuming.
minetest.debug(dump(config.can_harvest))
for item, _ in next, config.can_harvest do
if minetest.registered_items[item] then
config.drops[#config.drops+1] = item
else
config.can_harvest[item] = nil
end
end
-- This should be less verbose.
local get_drop_stats = {
["default:coal_lump"] = function(player_name)
return {
player = __minestats__.get_stacks_mined(player_name, "default:coal_lump"),
max = __minestats__.level_max("default:coal_lump"),
}
end,
["default:copper_lump"] = function(player_name)
return {
player = __minestats__.get_stacks_mined(player_name, "default:copper_lump"),
max = __minestats__.level_max("default:copper_lump"),
}
end,
["default:diamond"] = function(player_name)
return {
player = __minestats__.get_stacks_mined(player_name, "default:diamond"),
max = __minestats__.level_max("default:diamond"),
}
end,
["default:flint"] = function(player_name)
return {
player = __minestats__.get_stacks_mined(player_name, "default:flint"),
max = __minestats__.level_max("default:flint"),
}
end,
["default:gold_lump"] = function(player_name)
return {
player = __minestats__.get_stacks_mined(player_name, "default:gold_lump"),
max = __minestats__.level_max("default:gold_lump"),
}
end,
["default:iron_lump"] = function(player_name)
return {
player = __minestats__.get_stacks_mined(player_name, "default:iron_lump"),
max = __minestats__.level_max("default:iron_lump"),
}
end,
["default:mese_crystal_fragment"] = function(player_name)
return {
player = __minestats__.get_stacks_mined(player_name, "default:mese_crystal"),
max = __minestats__.level_max("default:mese_crystal"),
}
end,
["default:tin_lump"] = function(player_name)
return {
player = __minestats__.get_stacks_mined(player_name, "default:tin_lump"),
max = __minestats__.level_max("default:tin_lump"),
}
end,
["default:obsidian_shard"] = function(player_name)
return {
player = __minestats__.get_stacks_mined(player_name, "farming:wheat"),
max = __minestats__.level_max("farming:wheat"),
}
end,
["default:clay_lump"] = function(player_name)
return {
player = __minestats__.get_stacks_mined(player_name, "farming:cotton"),
max = __minestats__.level_max("farming:cotton"),
}
end,
["default:dirt"] = function(player_name)
return {
player = __minestats__.get_stacks_mined(player_name, "farming:cotton") + __minestats__.get_stacks_mined(player_name, "farming:wheat"),
max = __minestats__.level_max("farming:cotton") + __minestats__.level_max("farming:wheat"),
}
end,
["default:sand"] = function(player_name)
return {
player = __minestats__.get_stacks_mined(player_name, "default:coal_lump") + __minestats__.get_stacks_mined(player_name, "farming:cotton"),
max = __minestats__.level_max("default:coal_lump") + __minestats__.level_max("farming:cotton"),
}
end,
["default:silver_sand"] = function(player_name)
return {
player = __minestats__.get_stacks_mined(player_name, "default:iron_lump") + __minestats__.get_stacks_mined(player_name, "farming:wheat"),
max = __minestats__.level_max("default:iron_lump") + __minestats__.level_max("farming:wheat"),
}
end,
["default:desert_cobble"] = function(player_name)
return {
player = __minestats__.get_stacks_mined(player_name, "default:copper_lump") + __minestats__.get_stacks_mined(player_name, "farming:wheat"),
max = __minestats__.level_max("default:copper_lump") + __minestats__.level_max("farming:wheat"),
}
end,
["default:desert_sand"] = function(player_name)
return {
player = __minestats__.get_stacks_mined(player_name, "default:tin_lump") + __minestats__.get_stacks_mined(player_name, "farming:cotton"),
max = __minestats__.level_max("default:tin_lump") + __minestats__.level_max("farming:cotton"),
}
end,
["default:ice"] = function(player_name)
return {
player = __minestats__.get_stacks_mined(player_name, "default:gold_lump") + __minestats__.get_stacks_mined(player_name, "farming:wheat"),
max = __minestats__.level_max("default:gold_lump") + __minestats__.level_max("farming:wheat"),
}
end,
["default:river_water_source"] = function(player_name)
return {
player = __minestats__.get_stacks_mined(player_name, "default:flint") + __minestats__.get_stacks_mined(player_name, "farming:cotton"),
max = __minestats__.level_max("default:flint") + __minestats__.level_max("farming:cotton"),
}
end,
["flowers:waterlily"] = function(player_name)
return {
player = __minestats__.get_stacks_mined(player_name, "default:mese_crystal") + __minestats__.get_stacks_mined(player_name, "farming:wheat"),
max = __minestats__.level_max("default:mese_crystal") + __minestats__.level_max("farming:wheat"),
}
end,
["default:coral_skeleton"] = function(player_name)
return {
player = __minestats__.get_stacks_mined(player_name, "default:diamond") + __minestats__.get_stacks_mined(player_name, "farming:cotton"),
max = __minestats__.level_max("default:diamond") + __minestats__.level_max("farming:cotton"),
}
end,
}
get_drop_stats["default:lava_source"] = get_drop_stats["default:obsidian_shard"]
get_drop_stats["default:gravel"] = get_drop_stats["default:flint"]
if #config.drops > 0 then
minetest.override_item("default:stone", {
on_dig = function(pos, node, digger)
if math.random(0, 99) == 0 then
local player_name = digger:get_player_name()
if not minetest.is_protected(pos, player_name) then
local random_drop = config.drops[math.random(#config.drops)]
local drop_stats = get_drop_stats[random_drop](player_name)
-- Lua's math.random() is weird. If we don't specify a minimum but we
-- do specify a maximum, Lua uses one, not zero, as the minimum. Lua
-- really loves to give zero the shaft every chance it gets. Anyway, in
-- this particular case, we need to make sure the random number chosen
-- is greater than zero, as at level zero, you should fail to get any
-- bonuses at all. So because of Lua's default minimum of one, we don't
-- really need to do anything else. This time.
if drop_stats.player > math.random(drop_stats.max) then
local tool = digger:get_wielded_item()
local tooldef = tool:get_definition()
local capabilities = tool:get_tool_capabilities()
local params = core.get_dig_params(minetest.registered_nodes["default:stone"].groups, capabilities)
tool:add_wear(params.wear)
digger:set_wielded_item(tool)
if config.can_harvest[random_drop] then
minetest.handle_node_drops(pos, {random_drop}, digger)
minetest.remove_node(pos)
else
minetest.set_node(pos, {name=random_drop})
end
else
minetest.node_dig(pos, node, digger)
end
end
else
minetest.node_dig(pos, node, digger)
end
end,
})
end
if config.renew_gunpowder == "Flint" then
minetest.clear_craft({
type = "shapeless",
recipe = {"default:coal_lump", "default:gravel"},
})
minetest.register_craft({
type = "shapeless",
recipe = {"default:coal_lump", "default:flint"},
output = {"tnt:gunpowder"},
})
end

1
mod.conf Normal file
View File

@ -0,0 +1 @@
name = trace_minerals

36
settingtypes.txt Normal file
View File

@ -0,0 +1,36 @@
# If enabled, mining stone will occasionally result in a mineral dropping, instead of cobble.
trace_minerals.renew_minerals (Add trace minerals) bool true
# If enabled, mining stone will occasionally result in a more rare ground node dropping,
# instead of cobble. Such nodes include dirt, sand (all three types), ice, and desert cobble.
trace_minerals.renew_soils (Add ground node upgrades) bool true
# If enabled, coral skeletons and lily pads can be dug up occasionally. Disable this if you want
# a realistic world.
trace_minerals.renew_living (Add fossils) bool false
# If enabled, mining stone will occasionally result not in a drop, but in a liquid pocket. The
# mined stone will become lava or sometimes (if the "valleys" map generator is in use) river
# water. Mining can result in a nasty surprise, as one's torches are burned away and their toes
# singed. Enable this to add a bit of danger.
trace_minerals.renew_liquids (Add liquid pockets) bool false
# Gunpowder is sort of a strange corner case, and there's no one-size-fits-all solution to
# renewing it. The option of how to handle this is left up to the server administrator.
#
# If set to "None", gunpowder and TNT cannot be renewed, plain and simple. They remain a
# finite resource. In this case, if "Add trace minerals" is enabled, flint can be found in stone
# occasionally.
#
# If set to "Flint" and "Add trace minerals" is enabled, gunpowder can be renewed through
# flint. Like when set to "none", flint can be found in stone occasionally, and the crafting
# recipe for gunpowder is additionally modified to use flint instead of gravel. In all honesty,
# flint makes a more logical ingredient to gunpowder than gravel does anyway.
#
# If set to "Gravel" and "Add ground node upgrades" is enabled, gunpowder is renewable
# through gravel; the crafting recipe is left unchanged. Instead of flint ever being found in
# stone, occasionally gravel can be found.
#
# If set to "Flint" and "Add trace minerals" is disabled or if set to "Gravel" and "Add ground
# node upgrades" is disabled, this setting is treated as if it were set to "None".
trace_minerals.renew_gunpowder (Make gunpowder renewable through ...) enum None None,Flint,Gravel