forked from mtcontrib/farming
grapes can be placed in itemframes
This commit is contained in:
parent
cc157b97f3
commit
568b5a1641
51
grapes.lua
51
grapes.lua
@ -1,28 +1,41 @@
|
|||||||
|
|
||||||
local S = farming.intllib
|
local S = farming.intllib
|
||||||
|
|
||||||
-- grapes
|
-- place trellis
|
||||||
minetest.register_craftitem("farming:grapes", {
|
function place_grapes(itemstack, placer, pointed_thing, plantname)
|
||||||
description = S("Grapes"),
|
|
||||||
inventory_image = "farming_grapes.png",
|
|
||||||
on_use = minetest.item_eat(2),
|
|
||||||
|
|
||||||
on_place = function(itemstack, placer, pointed_thing)
|
local pt = pointed_thing
|
||||||
|
|
||||||
|
-- check if pointing at a node
|
||||||
|
if not pt or pt.type ~= "node" then
|
||||||
|
|
||||||
if minetest.is_protected(pointed_thing.under, placer:get_player_name()) then
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local nodename = minetest.get_node(pointed_thing.under).name
|
local under = minetest.get_node(pt.under)
|
||||||
|
|
||||||
if nodename == "farming:trellis" then
|
-- return if any of the nodes are not registered
|
||||||
minetest.set_node(pointed_thing.under, {name = "farming:grapes_1"})
|
if not minetest.registered_nodes[under.name] then
|
||||||
|
|
||||||
minetest.sound_play("default_place_node", {pos = pointed_thing.above, gain = 1.0})
|
|
||||||
else
|
|
||||||
return
|
return
|
||||||
end
|
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
|
if not minetest.setting_getbool("creative_mode") then
|
||||||
|
|
||||||
itemstack:take_item()
|
itemstack:take_item()
|
||||||
@ -40,7 +53,17 @@ minetest.register_craftitem("farming:grapes", {
|
|||||||
end
|
end
|
||||||
|
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- grapes
|
||||||
|
minetest.register_craftitem("farming:grapes", {
|
||||||
|
description = S("Grapes"),
|
||||||
|
inventory_image = "farming_grapes.png",
|
||||||
|
on_use = minetest.item_eat(2),
|
||||||
|
|
||||||
|
on_place = function(itemstack, placer, pointed_thing)
|
||||||
|
return place_grapes(itemstack, placer, pointed_thing, "farming:grapes_1")
|
||||||
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- grapes can be used for violet dye
|
-- grapes can be used for violet dye
|
||||||
|
Loading…
Reference in New Issue
Block a user