forked from Mirrorlandia_minetest/emeraldbank
emeraldblocks
This commit is contained in:
parent
6347740637
commit
2c915ff06d
@ -14,7 +14,7 @@
|
||||
|
||||
Add a crafteable Emerald bank node. Craft can be disable in mod settings.
|
||||
|
||||
If rightclick on bank, you can keep your Emeralds inside.
|
||||
If rightclick on bank, you can keep your Emeralds (or emeraldblocks) inside.
|
||||
|
||||
If punch the bank, get back your Emeralds.
|
||||
|
||||
|
18
init.lua
18
init.lua
@ -31,19 +31,23 @@ function emeraldbank.keep(player, itemstack, num)
|
||||
local player_meta = player:get_meta()
|
||||
local bankemeralds = player_meta:get_int("emeraldbank:emerald")
|
||||
local name = player:get_player_name()
|
||||
itemstack:take_item(num)
|
||||
itemstack:take_item() -- allways take 1 item
|
||||
player_meta:set_int("emeraldbank:emerald", bankemeralds+num)
|
||||
core.chat_send_player(name, S("Emeralds in Bank: @1", bankemeralds+num) )
|
||||
end
|
||||
|
||||
function emeraldbank.take(player, num)
|
||||
function emeraldbank.take(player)
|
||||
local player_meta = player:get_meta()
|
||||
local bankemeralds = player_meta:get_int("emeraldbank:emerald")
|
||||
local name = player:get_player_name()
|
||||
local pos = player:get_pos()
|
||||
if bankemeralds-num >= 0 then
|
||||
local num = 1
|
||||
if bankemeralds >= 1 then
|
||||
if bankemeralds >= 10 then
|
||||
num = 10
|
||||
end
|
||||
player_meta:set_int("emeraldbank:emerald", bankemeralds-num)
|
||||
core.add_item(pos, "mcl_core:emerald")
|
||||
core.add_item(pos, "mcl_core:emerald "..num)
|
||||
core.chat_send_player(name, S("Emeralds in Bank: @1", bankemeralds-num) )
|
||||
return true
|
||||
end
|
||||
@ -70,13 +74,15 @@ core.register_node("emeraldbank:bank", {
|
||||
local name = clicker:get_player_name()
|
||||
if itemname == "mcl_core:emerald" then
|
||||
emeraldbank.keep(clicker, itemstack, 1)
|
||||
elseif itemname == "mcl_core:emeraldblock" then
|
||||
emeraldbank.keep(clicker, itemstack, 9)
|
||||
else
|
||||
core.chat_send_player(name, S("You need keep emeralds in your hand!") )
|
||||
core.chat_send_player(name, S("You need keep emeralds or emeraldblocks in your hand!") )
|
||||
end
|
||||
end,
|
||||
|
||||
on_punch = function(pos, node, puncher, pointed_thing)
|
||||
emeraldbank.take(puncher, 1)
|
||||
emeraldbank.take(puncher)
|
||||
end,
|
||||
})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user