emeraldblocks

This commit is contained in:
Nathaniel Freeman 2021-07-24 14:54:50 +02:00
parent 6347740637
commit 2c915ff06d
2 changed files with 13 additions and 7 deletions

@ -14,7 +14,7 @@
Add a crafteable Emerald bank node. Craft can be disable in mod settings. 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. If punch the bank, get back your Emeralds.

@ -31,19 +31,23 @@ function emeraldbank.keep(player, itemstack, num)
local player_meta = player:get_meta() local player_meta = player:get_meta()
local bankemeralds = player_meta:get_int("emeraldbank:emerald") local bankemeralds = player_meta:get_int("emeraldbank:emerald")
local name = player:get_player_name() 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) player_meta:set_int("emeraldbank:emerald", bankemeralds+num)
core.chat_send_player(name, S("Emeralds in Bank: @1", bankemeralds+num) ) core.chat_send_player(name, S("Emeralds in Bank: @1", bankemeralds+num) )
end end
function emeraldbank.take(player, num) function emeraldbank.take(player)
local player_meta = player:get_meta() local player_meta = player:get_meta()
local bankemeralds = player_meta:get_int("emeraldbank:emerald") local bankemeralds = player_meta:get_int("emeraldbank:emerald")
local name = player:get_player_name() local name = player:get_player_name()
local pos = player:get_pos() 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) 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) ) core.chat_send_player(name, S("Emeralds in Bank: @1", bankemeralds-num) )
return true return true
end end
@ -70,13 +74,15 @@ core.register_node("emeraldbank:bank", {
local name = clicker:get_player_name() local name = clicker:get_player_name()
if itemname == "mcl_core:emerald" then if itemname == "mcl_core:emerald" then
emeraldbank.keep(clicker, itemstack, 1) emeraldbank.keep(clicker, itemstack, 1)
elseif itemname == "mcl_core:emeraldblock" then
emeraldbank.keep(clicker, itemstack, 9)
else 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
end, end,
on_punch = function(pos, node, puncher, pointed_thing) on_punch = function(pos, node, puncher, pointed_thing)
emeraldbank.take(puncher, 1) emeraldbank.take(puncher)
end, end,
}) })