Added Soulbound buff for all tool types

master
Alexand(er|ra) Yst 2020-12-28 03:46:34 -08:00
parent 323c0e9d7a
commit 81416e8af2
5 changed files with 218 additions and 98 deletions

View File

@ -41,53 +41,53 @@ return {
pine_sapling = "lumberjack",
acacia_sapling = "lumberjack",
mushroom_brown = "toter",
mushroom_red = "toter",
mushroom_red = "soulbound",
mushroom_spores_brown = "toter",
mushroom_spores_red = "toter",
mushroom_spores_red = "soulbound",
aspen_sapling = "lumberjack",
flint = "lumberjack",
coral_skeleton = "toter",
acacia_bush_sapling = "termite",
bush_sapling = "termite",
tin_lump = "toter",
blueberries = "toter",
blueberries = "soulbound",
blueberry_bush_sapling = "lumberjack",
ice = "toter",
pine_bush_sapling = "termite",
dry_dirt = "toter",
},
fire_starter = {
sand = "debug",
coal_lump = "debug",
iron_lump = "debug",
sapling = "debug",
sand = "soulbound",
coal_lump = "soulbound",
iron_lump = "soulbound",
sapling = "soulbound",
mese_crystal = "durable",
copper_lump = "debug",
copper_lump = "soulbound",
diamond = "durable",
gold_lump = "debug",
junglesapling = "debug",
seed_cotton = "debug",
seed_wheat = "debug",
string = "debug",
wheat = "debug",
cotton = "debug",
pine_sapling = "debug",
acacia_sapling = "debug",
mushroom_brown = "debug",
mushroom_red = "debug",
mushroom_spores_brown = "debug",
mushroom_spores_red = "debug",
aspen_sapling = "debug",
flint = "debug",
coral_skeleton = "debug",
acacia_bush_sapling = "debug",
bush_sapling = "debug",
tin_lump = "debug",
blueberries = "debug",
blueberry_bush_sapling = "debug",
ice = "debug",
pine_bush_sapling = "debug",
dry_dirt = "debug",
gold_lump = "soulbound",
junglesapling = "soulbound",
seed_cotton = "soulbound",
seed_wheat = "soulbound",
string = "soulbound",
wheat = "soulbound",
cotton = "soulbound",
pine_sapling = "soulbound",
acacia_sapling = "soulbound",
mushroom_brown = "soulbound",
mushroom_red = "soulbound",
mushroom_spores_brown = "soulbound",
mushroom_spores_red = "soulbound",
aspen_sapling = "soulbound",
flint = "soulbound",
coral_skeleton = "soulbound",
acacia_bush_sapling = "soulbound",
bush_sapling = "soulbound",
tin_lump = "soulbound",
blueberries = "soulbound",
blueberry_bush_sapling = "soulbound",
ice = "soulbound",
pine_bush_sapling = "soulbound",
dry_dirt = "soulbound",
},
pick = {
sand = "rapid",
@ -106,87 +106,87 @@ return {
cotton = "cobbleeater",
pine_sapling = "rapid",
acacia_sapling = "rapid",
mushroom_brown = "rapid",
mushroom_red = "rapid",
mushroom_spores_brown = "rapid",
mushroom_spores_red = "rapid",
mushroom_brown = "soulbound",
mushroom_red = "soulbound",
mushroom_spores_brown = "soulbound",
mushroom_spores_red = "soulbound",
aspen_sapling = "rapid",
flint = "rapid",
coral_skeleton = "rapid",
acacia_bush_sapling = "rapid",
bush_sapling = "rapid",
tin_lump = "rapid",
blueberries = "rapid",
blueberries = "soulbound",
blueberry_bush_sapling = "rapid",
ice = "rapid",
pine_bush_sapling = "rapid",
dry_dirt = "rapid",
},
hoe = {
sand = "debug",
coal_lump = "debug",
iron_lump = "debug",
sapling = "debug",
sand = "soulbound",
coal_lump = "soulbound",
iron_lump = "soulbound",
sapling = "soulbound",
mese_crystal = "durable",
copper_lump = "debug",
copper_lump = "soulbound",
diamond = "durable",
gold_lump = "debug",
junglesapling = "debug",
seed_cotton = "debug",
seed_wheat = "debug",
string = "debug",
wheat = "debug",
cotton = "debug",
pine_sapling = "debug",
acacia_sapling = "debug",
mushroom_brown = "debug",
mushroom_red = "debug",
mushroom_spores_brown = "debug",
mushroom_spores_red = "debug",
aspen_sapling = "debug",
flint = "debug",
coral_skeleton = "debug",
acacia_bush_sapling = "debug",
bush_sapling = "debug",
tin_lump = "debug",
blueberries = "debug",
blueberry_bush_sapling = "debug",
ice = "debug",
pine_bush_sapling = "debug",
dry_dirt = "debug",
gold_lump = "soulbound",
junglesapling = "soulbound",
seed_cotton = "soulbound",
seed_wheat = "soulbound",
string = "soulbound",
wheat = "soulbound",
cotton = "soulbound",
pine_sapling = "soulbound",
acacia_sapling = "soulbound",
mushroom_brown = "soulbound",
mushroom_red = "soulbound",
mushroom_spores_brown = "soulbound",
mushroom_spores_red = "soulbound",
aspen_sapling = "soulbound",
flint = "soulbound",
coral_skeleton = "soulbound",
acacia_bush_sapling = "soulbound",
bush_sapling = "soulbound",
tin_lump = "soulbound",
blueberries = "soulbound",
blueberry_bush_sapling = "soulbound",
ice = "soulbound",
pine_bush_sapling = "soulbound",
dry_dirt = "soulbound",
},
screwdriver = {
sand = "debug",
coal_lump = "debug",
iron_lump = "debug",
sapling = "debug",
sand = "soulbound",
coal_lump = "soulbound",
iron_lump = "soulbound",
sapling = "soulbound",
mese_crystal = "durable",
copper_lump = "debug",
copper_lump = "soulbound",
diamond = "durable",
gold_lump = "debug",
junglesapling = "debug",
seed_cotton = "debug",
seed_wheat = "debug",
string = "debug",
wheat = "debug",
cotton = "debug",
pine_sapling = "debug",
acacia_sapling = "debug",
mushroom_brown = "debug",
mushroom_red = "debug",
mushroom_spores_brown = "debug",
mushroom_spores_red = "debug",
aspen_sapling = "debug",
flint = "debug",
coral_skeleton = "debug",
acacia_bush_sapling = "debug",
bush_sapling = "debug",
tin_lump = "debug",
blueberries = "debug",
blueberry_bush_sapling = "debug",
ice = "debug",
pine_bush_sapling = "debug",
dry_dirt = "debug",
gold_lump = "soulbound",
junglesapling = "soulbound",
seed_cotton = "soulbound",
seed_wheat = "soulbound",
string = "soulbound",
wheat = "soulbound",
cotton = "soulbound",
pine_sapling = "soulbound",
acacia_sapling = "soulbound",
mushroom_brown = "soulbound",
mushroom_red = "soulbound",
mushroom_spores_brown = "soulbound",
mushroom_spores_red = "soulbound",
aspen_sapling = "soulbound",
flint = "soulbound",
coral_skeleton = "soulbound",
acacia_bush_sapling = "soulbound",
bush_sapling = "soulbound",
tin_lump = "soulbound",
blueberries = "soulbound",
blueberry_bush_sapling = "soulbound",
ice = "soulbound",
pine_bush_sapling = "soulbound",
dry_dirt = "soulbound",
},
shovel = {
sand = "rapid",
@ -206,9 +206,9 @@ return {
pine_sapling = "thirst",
acacia_sapling = "thirst",
mushroom_brown = "spreader",
mushroom_red = "spreader",
mushroom_red = "soulbound",
mushroom_spores_brown = "spreader",
mushroom_spores_red = "spreader",
mushroom_spores_red = "soulbound",
aspen_sapling = "thirst",
flint = "thirst",
coral_skeleton = "rapid",
@ -248,7 +248,7 @@ return {
acacia_bush_sapling = "thirst",
bush_sapling = "thirst",
tin_lump = "rapid",
blueberries = "pruner",
blueberries = "soulbound",
blueberry_bush_sapling = "thirst",
ice = "rapid",
pine_bush_sapling = "thirst",

View File

@ -1,3 +1,20 @@
-- runes mod for Minetest
-- Copyright © 2020 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/>.
for _, log in next, {
"default:acacia_tree",
"default:aspen_tree",

View File

@ -0,0 +1,101 @@
-- runes mod for Minetest
-- Copyright © 2020 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 have to act before the bones mod does in order to prevent the
-- bones mod from taking a player's Soulbound tools and putting them in
-- the player's bones node. To do this, we have to register our
-- on_dieplayer function before the bones mod does. The problem is that
-- there's no way for us to declare that a given mod needs to be run
-- before a given other mod; all we can do is declare that a given mod
-- has to be run *after* a given other mod. That is, we can depend on
-- the bones mod to make this mod load after it, but there's nothing we
-- can do in this mod to make this mod always load *before* the bones
-- mod. As such, we have to resort to a messy workaround.
--
-- First, we'll replace the minetest.registered_on_dieplayers table
-- with a new one in which all the old callbacks are pushed further
-- back and our function is put at the front of the queue. Then, we'll
-- wait until all the mods have loaded and register a function that'll
-- be run after them all. The first function will take the tools from
-- the player before any other on_dieplayer callbacks can mess with
-- them, then the final function will give them back to the player
-- before the player respawns.
--
-- As a side note, I was originally going to register the tool-taking
-- function as a player-got-damaged callback and register the
-- tool-returning function as an on-respawning callback, but if a
-- player doesn't respawn right away and disconnects, I think the tools
-- might just get deleted if the server shuts down before the player
-- logs back in. This mod doesn't store persistent data, so they
-- wouldn't simply be able to reclaim their tools later. They've got to
-- be given back right away.
local tool_cache = {}
local new_registered_on_dieplayers_table = {
[1] = function(player)
local cache_entry = {
main = {},
craft = {},
}
local inventory = player:get_inventory()
for list, length in next, {
main = 32,
craft = 9,
} do
for key = 1, length do
local stack = inventory:get_stack(list, key)
if stack:get_name():sub(1, 6) == "runes:" and
minetest.registered_tools[stack:get_name()] then
if stack:get_meta():get("soulbound") then
cache_entry[list][key] = stack
inventory:set_stack(list, key, "")
end
end
end
end
tool_cache[player:get_player_name()] = cache_entry
end,
}
for key, value in next, minetest.registered_on_dieplayers do
new_registered_on_dieplayers_table[key + 1] = value
end
minetest.registered_on_dieplayers = new_registered_on_dieplayers_table
minetest.register_on_mods_loaded(function()
--[[ minetest.register_on_dieplayer(function(player)
local inventory = player:get_inventory()
for list, items in next, tool_cache[player:get_player_name()] do
for key, item in next, items do
inventory:set_stack(list, key, item)
end
end
end)]]
-- I'm not sure why, but registering a new on_dieplayer callback after
-- the mods have loaded doesn't seem to work. Manually adding a new
-- callback to the end of the callback table works as expected though ...
minetest.registered_on_dieplayers[#minetest.registered_on_dieplayers + 1] = function(player)
local inventory = player:get_inventory()
for list, items in next, tool_cache[player:get_player_name()] do
for key, item in next, items do
inventory:set_stack(list, key, item)
end
end
end
end)

View File

@ -20,4 +20,5 @@ dofile(minetest.get_modpath("runes").."/tools.lua")
dofile(minetest.get_modpath("runes").."/tool_crafting.lua")
dofile(minetest.get_modpath("runes").."/buffs/toter.lua")
dofile(minetest.get_modpath("runes").."/buffs/lumberjack.lua")
dofile(minetest.get_modpath("runes").."/buffs/soulbound.lua")
dofile(minetest.get_modpath("runes").."/debug.lua")

View File

@ -58,6 +58,7 @@ local buff_name = {
lumberjack = S("Lumberjack"),
termite = S("Termite"),
cobbleeater = S("Cobble Eater"),
soulbound = S("Soulbound"),
}
local rune_element_modname = {