1
0
Fork 0

Restrict placement of small mushrooms to dark, opaque, solid blocks

objects
Wuzzy 2017-03-31 19:30:18 +02:00
parent 20618fbea2
commit 720ab83e14
1 changed files with 48 additions and 0 deletions

View File

@ -1,3 +1,47 @@
local on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.type ~= "node" then
-- no interaction possible with entities
return itemstack
end
-- Call on_rightclick if the pointed node defines it
local node = minetest.get_node(pointed_thing.under)
if placer and not placer:get_player_control().sneak then
if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then
return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, placer, itemstack) or itemstack
end
end
local a = pointed_thing.above
local node_above = minetest.get_node(a)
local node_below = minetest.get_node({x=a.x, y=a.y-1, z=a.z})
local def = minetest.registered_nodes[node_below.name]
local def2 = minetest.registered_nodes[node_above.name]
-- Placement rules:
-- * Always allowed on podzol or mycelimu
-- * Otherwise, must be solid, opaque and have daylight light level <= 12
local light = minetest.get_node_light(a, 0.5)
local light_ok = false
if light and light <= 12 then
light_ok = true
end
if (node_below.name == "mcl_core:podzol" or node_below.name == "mcl_core:mycelium") or
(light_ok and (def.groups and def.groups.solid and def.groups.opaque)) and
def2.buildable_to then
local idef = itemstack:get_definition()
local success = minetest.item_place_node(itemstack, placer, pointed_thing)
if success then
if idef.sounds and idef.sounds.place then
minetest.sound_play(idef.sounds.place, {pos=above, gain=1})
end
end
end
return itemstack
end
minetest.register_node("mcl_mushrooms:mushroom_brown", { minetest.register_node("mcl_mushrooms:mushroom_brown", {
description = "Brown Mushroom", description = "Brown Mushroom",
drawtype = "plantlike", drawtype = "plantlike",
@ -14,6 +58,8 @@ minetest.register_node("mcl_mushrooms:mushroom_brown", {
type = "fixed", type = "fixed",
fixed = { -0.15, -0.5, -0.15, 0.15, 0.015, 0.15 }, fixed = { -0.15, -0.5, -0.15, 0.15, 0.015, 0.15 },
}, },
node_placement_prediction = "",
on_place = on_place,
_mcl_blast_resistance = 0, _mcl_blast_resistance = 0,
}) })
@ -32,6 +78,8 @@ minetest.register_node("mcl_mushrooms:mushroom_red", {
type = "fixed", type = "fixed",
fixed = { -0.15, -0.5, -0.15, 0.15, 0.015, 0.15 }, fixed = { -0.15, -0.5, -0.15, 0.15, 0.015, 0.15 },
}, },
node_placement_prediction = "",
on_place = on_place,
_mcl_blast_resistance = 0, _mcl_blast_resistance = 0,
}) })