emeraldbank/bank.lua

114 lines
3.4 KiB
Lua
Raw Normal View History

2021-10-13 14:23:40 +02:00
2022-02-18 02:35:18 +01:00
-- Copyright (C) 2021, 2022 GNU Hacker
2021-10-13 14:23:40 +02:00
-- This file is part of Emeraldbank Minetest Mod.
-- Emeraldbank is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
-- Emeraldbank 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 General Public License for more details.
-- You should have received a copy of the GNU General Public License
-- along with Emeraldbank. If not, see <https://www.gnu.org/licenses/>.
local S = core.get_translator(core.get_current_modname())
local bankcraft = core.settings:get_bool("emeraldbank.bank_craft") or true
2021-10-13 14:23:40 +02:00
2021-10-20 17:39:17 +02:00
function emeraldbank.add_emeralds(player, num)
if not player then return false end
2021-10-13 14:23:40 +02:00
local meta = player:get_meta()
local bankemeralds = meta:get_int("emeraldbank:emerald") -- if nil "get_int()" return 0 Magic!
local name = player:get_player_name()
2021-10-20 17:39:17 +02:00
if num then
meta:set_int("emeraldbank:emerald", bankemeralds+num)
core.chat_send_player(name, S("Emeralds in Bank: @1", bankemeralds+num) )
return true
end
return false
end
function emeraldbank.keep(player, itemstack)
2021-10-13 14:23:40 +02:00
local itemname = itemstack:get_name()
local itemcount = itemstack:get_count()
2021-10-20 17:39:17 +02:00
local name = player:get_player_name()
2021-10-13 14:23:40 +02:00
if itemname == "mcl_core:emerald" then
itemstack:take_item(itemcount)
2021-10-20 17:39:17 +02:00
emeraldbank.add_emeralds(player, itemcount)
2021-10-13 14:23:40 +02:00
return true
end
if itemname == "mcl_core:emeraldblock" then
2021-10-20 17:39:17 +02:00
itemstack:take_item(itemcount)
emeraldbank.add_emeralds(player, itemcount*9)
2021-10-13 14:23:40 +02:00
return true
end
core.chat_send_player(name, S("You need keep emeralds or emeraldblocks in your hand!") )
return false
end
function emeraldbank.take(player)
local meta = player:get_meta()
local bankemeralds = meta:get_int("emeraldbank:emerald")
local name = player:get_player_name()
local pos = player:get_pos()
local num = 1
if bankemeralds >= 1 then
if bankemeralds >= 10 then
num = 10
end
2021-10-20 17:39:17 +02:00
emeraldbank.add_emeralds(player, -num)
2021-10-13 14:23:40 +02:00
core.add_item(pos, "mcl_core:emerald "..num)
return true
end
core.chat_send_player(name, S("Not enough Emeralds in your account") )
return false
end
-- register bank node
core.register_node("emeraldbank:bank", {
description = S("Emerald Bank"),
_doc_items_longdesc = S("This block can keep your emeralds."),
is_ground_content = false,
tiles = {
"default_steel_block.png",
"default_steel_block.png",
"default_steel_block.png^mcl_core_emerald.png"
},
stack_max = 64,
groups = {pickaxey=1, handy=1, building_block=1, enderman_takable=1},
sounds = mcl_sounds.node_sound_metal_defaults(),
_mcl_blast_resistance = 5,
_mcl_hardness = 1,
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
emeraldbank.keep(clicker, itemstack)
end,
on_punch = function(pos, node, puncher, pointed_thing)
emeraldbank.take(puncher)
end,
})
if bankcraft then
core.register_craft({
output = "emeraldbank:bank",
recipe = {
{"mcl_core:emerald", "mcl_core:emerald", "mcl_core:emerald"},
{"mcl_core:emerald", "mcl_core:ironblock", "mcl_core:emerald"},
{"mcl_core:emerald", "mcl_core:emerald", "mcl_core:emerald"},
}
})
end