forked from mtcontrib/farming
grapes can be placed in itemframes
This commit is contained in:
parent
cc157b97f3
commit
568b5a1641
89
grapes.lua
89
grapes.lua
@ -1,6 +1,60 @@
|
|||||||
|
|
||||||
local S = farming.intllib
|
local S = farming.intllib
|
||||||
|
|
||||||
|
-- place trellis
|
||||||
|
function place_grapes(itemstack, placer, pointed_thing, plantname)
|
||||||
|
|
||||||
|
local pt = pointed_thing
|
||||||
|
|
||||||
|
-- check if pointing at a node
|
||||||
|
if not pt or pt.type ~= "node" then
|
||||||
|
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local under = minetest.get_node(pt.under)
|
||||||
|
|
||||||
|
-- return if any of the nodes are not registered
|
||||||
|
if not minetest.registered_nodes[under.name] then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- am I right-clicking on something that has a custom on_place set?
|
||||||
|
-- thanks to Krock for helping with this issue :)
|
||||||
|
local def = minetest.registered_nodes[under.name]
|
||||||
|
if def and def.on_rightclick then
|
||||||
|
return def.on_rightclick(pt.under, under, placer, itemstack)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- check if pointing at trellis
|
||||||
|
if under.name ~= "farming:trellis" then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- add the node and remove 1 item from the itemstack
|
||||||
|
minetest.set_node(pt.under, {name = plantname})
|
||||||
|
|
||||||
|
minetest.sound_play("default_place_node", {pos = pt.under, gain = 1.0})
|
||||||
|
|
||||||
|
if not minetest.setting_getbool("creative_mode") then
|
||||||
|
|
||||||
|
itemstack:take_item()
|
||||||
|
|
||||||
|
-- check for refill
|
||||||
|
if itemstack:get_count() == 0 then
|
||||||
|
|
||||||
|
minetest.after(0.20,
|
||||||
|
farming.refill_plant,
|
||||||
|
placer,
|
||||||
|
"farming:grapes",
|
||||||
|
placer:get_wield_index()
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return itemstack
|
||||||
|
end
|
||||||
|
|
||||||
-- grapes
|
-- grapes
|
||||||
minetest.register_craftitem("farming:grapes", {
|
minetest.register_craftitem("farming:grapes", {
|
||||||
description = S("Grapes"),
|
description = S("Grapes"),
|
||||||
@ -8,39 +62,8 @@ minetest.register_craftitem("farming:grapes", {
|
|||||||
on_use = minetest.item_eat(2),
|
on_use = minetest.item_eat(2),
|
||||||
|
|
||||||
on_place = function(itemstack, placer, pointed_thing)
|
on_place = function(itemstack, placer, pointed_thing)
|
||||||
|
return place_grapes(itemstack, placer, pointed_thing, "farming:grapes_1")
|
||||||
if minetest.is_protected(pointed_thing.under, placer:get_player_name()) then
|
end,
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local nodename = minetest.get_node(pointed_thing.under).name
|
|
||||||
|
|
||||||
if nodename == "farming:trellis" then
|
|
||||||
minetest.set_node(pointed_thing.under, {name = "farming:grapes_1"})
|
|
||||||
|
|
||||||
minetest.sound_play("default_place_node", {pos = pointed_thing.above, gain = 1.0})
|
|
||||||
else
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
if not minetest.setting_getbool("creative_mode") then
|
|
||||||
|
|
||||||
itemstack:take_item()
|
|
||||||
|
|
||||||
-- check for refill
|
|
||||||
if itemstack:get_count() == 0 then
|
|
||||||
|
|
||||||
minetest.after(0.20,
|
|
||||||
farming.refill_plant,
|
|
||||||
placer,
|
|
||||||
"farming:grapes",
|
|
||||||
placer:get_wield_index()
|
|
||||||
)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return itemstack
|
|
||||||
end
|
|
||||||
})
|
})
|
||||||
|
|
||||||
-- grapes can be used for violet dye
|
-- grapes can be used for violet dye
|
||||||
|
Loading…
Reference in New Issue
Block a user