Add Toter buff

master
Alexand(er|ra) Yst 2020-12-20 13:25:09 -08:00
parent e66118b08a
commit eba1dbfce7
5 changed files with 141 additions and 3 deletions

BIN
menu/overlay.4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 569 KiB

View File

@ -167,7 +167,7 @@ return {
sword = "thirst",
},
mushroom_brown = {
axe = "rapid",
axe = "toter",
fire_starter = "debug",
pick = "rapid",
hoe = "debug",
@ -176,7 +176,7 @@ return {
sword = "pruner",
},
mushroom_red = {
axe = "rapid",
axe = "toter",
fire_starter = "debug",
pick = "rapid",
hoe = "debug",

View File

@ -0,0 +1,136 @@
-- 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/>.
minetest.register_craftitem("runes:toted_chest", {
description = "Toted Chest",
stack_max = 65535,
inventory_image = "default_chest_front.png",
on_place = function(itemstack, placer, pointed_thing)
if not minetest.is_protected(pointed_thing.above, placer:get_player_name()) then
local old_node = minetest.get_node(pointed_thing.above)
if minetest.registered_nodes[old_node.name] and
minetest.registered_nodes[old_node.name].buildable_to then
local placer_pos = placer:get_pos()
minetest.set_node(pointed_thing.above, {
name = "default:chest",
param2 = minetest.dir_to_facedir({
x = pointed_thing.above.x - placer_pos.x,
y = pointed_thing.above.y - placer_pos.y,
z = pointed_thing.above.z - placer_pos.z
}),
})
local toted_meta = itemstack:get_meta()
local node_inv = minetest.get_meta(pointed_thing.above):get_inventory()
for index = 1, 32 do
local item = toted_meta:get_string(index)
if item then
node_inv:set_stack("main", index, item)
end
end
itemstack:take_item()
return itemstack
end
end
end,
})
local chest_is_empty = minetest.registered_items["default:chest"].can_dig
local chest_override = {
-- If the chest isn't empty, return a toted chest instead of a regular
-- one and preserve the inventory.
preserve_metadata = function(pos, oldnode, oldmeta, drops)
local inv = minetest.get_meta(pos):get_inventory()
if not inv:is_empty("main") then
drops[1] = ItemStack("runes:toted_chest")
local toted_meta = drops[1]:get_meta()
for key = 1, 32 do
local stack = inv:get_stack("main", key)
if not stack:is_empty() then
toted_meta:set_string(key, stack:to_string())
end
end
end
end,
-- If the chest can be dug normally, allow it to be dug. Otherwise,
-- allow it to be dug if a Toter-enabled rune axe is used on it.
can_dig = function(pos, player)
local tool = player:get_wielded_item()
if chest_is_empty(pos, player) then
return true
else
return tool:get_name() == "runes:axe" and tool:get_meta():get_string("toter") ~= ""
end
end,
-- Chests cannot be nested.
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
if stack:get_name() == "runes:toted_chest" then
return 0
else
return stack:get_count()
end
end,
-- There's a glitch in Minetest that lets you bypass the
-- allow_metadata_inventory_put() callback by taking instead of putting
-- but then performing a swap instead of a take. The only way around
-- this seems to be to either disallow taking or to check the inventory
-- slot and correcting the issue using the on_metadata_inventory_take()
-- callback. (This same glitch lets you instead bypass the
-- allow_metadata_inventory_take() callback by putting instead of
-- taking and then performing a swap; this can be detected and
-- corrected using an on_metadata_inventory_put() callback.)
on_metadata_inventory_take = function(pos, listname, index, stack, player)
local inv = minetest.get_meta(pos):get_inventory()
local check_stack = inv:get_stack(listname, index)
if check_stack:get_name() == "runes:toted_chest" then
minetest.handle_node_drops(pos, {
check_stack,
}, player)
inv:set_stack(listname, index, "")
end
end,
}
minetest.override_item("default:chest", chest_override)
minetest.override_item("default:chest_open", chest_override)
local locked_chest_allow_metadata_inventory_put = minetest.registered_items["default:chest"].allow_metadata_inventory_put
local locked_chest_override = {
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
if stack:get_name() == "runes:toted_chest" then
return 0
else
return locked_chest_allow_metadata_inventory_put(pos, listname, index, stack, player)
end
end,
on_metadata_inventory_take = chest_override.on_metadata_inventory_take,
}
minetest.override_item("default:chest_locked", locked_chest_override)
minetest.override_item("default:chest_locked_open", locked_chest_override)
local furnace_allow_metadata_inventory_put = minetest.registered_items["default:furnace"].allow_metadata_inventory_put
local furnace_override = {
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
if stack:get_name() == "runes:toted_chest" then
return 0
else
return furnace_allow_metadata_inventory_put(pos, listname, index, stack, player)
end
end,
on_metadata_inventory_take = chest_override.on_metadata_inventory_take,
}
minetest.override_item("default:furnace", furnace_override)
minetest.override_item("default:furnace_active", furnace_override)

View File

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

View File

@ -52,7 +52,8 @@ local buff_name = {
pruner = S("Pruner"),
spreader = S("Spreader"),
durability = S("Durability"),
rapid = S("Rapid Dig"),
rapid = S("Rapid Digger"),
toter = S("Toter"),
}
local rune_element_modname = {