1
0
Fork 0

Prevent placing most plants on mycelium

This commit is contained in:
Wuzzy 2017-05-14 01:45:57 +02:00
parent 5a746b5f29
commit 8e2d601f85
4 changed files with 69 additions and 1 deletions

View File

@ -228,3 +228,48 @@ end
function mcl_util.layer_to_y(layer, minecraft_dimension) function mcl_util.layer_to_y(layer, minecraft_dimension)
return layer + mcl_vars.mg_overworld_min return layer + mcl_vars.mg_overworld_min
end end
-- on_place function for plants which can't grow on mycelium
function mcl_util.on_place_non_mycelium_plant(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 place_pos, soil_node
local def_under = minetest.registered_nodes[minetest.get_node(pointed_thing.under).name]
local def_above = minetest.registered_nodes[minetest.get_node(pointed_thing.above).name]
if def_under.buildable_to then
place_pos = pointed_thing.under
elseif def_above.buildable_to then
place_pos = pointed_thing.above
else
return itemstack
end
soil_node = minetest.get_node({x=place_pos.x, y=place_pos.y-1, z=place_pos.z})
-- Placement rules:
-- * Allowed on everything except mycelium
if soil_node.name ~= "mcl_core:mycelium" then
local idef = itemstack:get_definition()
local new_itemstack, 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
itemstack = new_itemstack
end
return itemstack
end

View File

@ -712,6 +712,8 @@ minetest.register_node("mcl_core:sapling", {
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_int("stage", 0) meta:set_int("stage", 0)
end, end,
node_placement_prediction = "",
on_place = mcl_util.on_place_non_mycelium_plant,
_mcl_blast_resistance = 0, _mcl_blast_resistance = 0,
_mcl_hardness = 0, _mcl_hardness = 0,
}) })
@ -796,6 +798,8 @@ minetest.register_node("mcl_core:darksapling", {
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_int("stage", 0) meta:set_int("stage", 0)
end, end,
node_placement_prediction = "",
on_place = mcl_util.on_place_non_mycelium_plant,
_mcl_blast_resistance = 0, _mcl_blast_resistance = 0,
_mcl_hardness = 0, _mcl_hardness = 0,
}) })
@ -938,6 +942,8 @@ minetest.register_node("mcl_core:junglesapling", {
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_int("stage", 0) meta:set_int("stage", 0)
end, end,
node_placement_prediction = "",
on_place = mcl_util.on_place_non_mycelium_plant,
_mcl_blast_resistance = 0, _mcl_blast_resistance = 0,
_mcl_hardness = 0, _mcl_hardness = 0,
}) })
@ -1013,6 +1019,8 @@ minetest.register_node("mcl_core:acaciasapling", {
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_int("stage", 0) meta:set_int("stage", 0)
end, end,
node_placement_prediction = "",
on_place = mcl_util.on_place_non_mycelium_plant,
stack_max = 64, stack_max = 64,
groups = {dig_immediate=3, sapling=1,non_mycelium_plant=1,non_mycelium_plant=1,attached_node=1,dig_by_water=1,deco_block=1}, groups = {dig_immediate=3, sapling=1,non_mycelium_plant=1,non_mycelium_plant=1,attached_node=1,dig_by_water=1,deco_block=1},
sounds = mcl_sounds.node_sound_leaves_defaults(), sounds = mcl_sounds.node_sound_leaves_defaults(),
@ -1099,6 +1107,8 @@ minetest.register_node("mcl_core:sprucesapling", {
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_int("stage", 0) meta:set_int("stage", 0)
end, end,
node_placement_prediction = "",
on_place = mcl_util.on_place_non_mycelium_plant,
_mcl_blast_resistance = 0, _mcl_blast_resistance = 0,
_mcl_hardness = 0, _mcl_hardness = 0,
}) })
@ -1177,6 +1187,8 @@ minetest.register_node("mcl_core:birchsapling", {
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_int("stage", 0) meta:set_int("stage", 0)
end, end,
node_placement_prediction = "",
on_place = mcl_util.on_place_non_mycelium_plant,
_mcl_blast_resistance = 0, _mcl_blast_resistance = 0,
_mcl_hardness = 0, _mcl_hardness = 0,
}) })
@ -1280,6 +1292,8 @@ minetest.register_node("mcl_core:reeds", {
stack_max = 64, stack_max = 64,
groups = {dig_immediate=3, craftitem=1, non_mycelium_plant=1, dig_by_piston=1}, groups = {dig_immediate=3, craftitem=1, non_mycelium_plant=1, dig_by_piston=1},
sounds = mcl_sounds.node_sound_leaves_defaults(), sounds = mcl_sounds.node_sound_leaves_defaults(),
node_placement_prediction = "",
on_place = mcl_util.on_place_non_mycelium_plant,
_mcl_blast_resistance = 0, _mcl_blast_resistance = 0,
_mcl_hardness = 0, _mcl_hardness = 0,
}) })
@ -1813,6 +1827,8 @@ minetest.register_node("mcl_core:deadbush", {
type = "fixed", type = "fixed",
fixed = {-6/16, -8/16, -6/16, 6/16, 8/16, 6/16}, fixed = {-6/16, -8/16, -6/16, 6/16, 8/16, 6/16},
}, },
node_placement_prediction = "",
on_place = mcl_util.on_place_non_mycelium_plant,
_mcl_blast_resistance = 0, _mcl_blast_resistance = 0,
_mcl_hardness = 0, _mcl_hardness = 0,
}) })

View File

@ -1,3 +1,4 @@
mcl_core mcl_core
mcl_util
mcl_sounds mcl_sounds
doc? doc?

View File

@ -20,6 +20,8 @@ local function add_simple_flower(name, desc, image, simple_selection_box)
stack_max = 64, stack_max = 64,
groups = {dig_immediate=3,flammable=2,flower=1,non_mycelium_plant=1,attached_node=1,dig_by_water=1,dig_by_piston=1,deco_block=1}, groups = {dig_immediate=3,flammable=2,flower=1,non_mycelium_plant=1,attached_node=1,dig_by_water=1,dig_by_piston=1,deco_block=1},
sounds = mcl_sounds.node_sound_leaves_defaults(), sounds = mcl_sounds.node_sound_leaves_defaults(),
node_placement_prediction = "",
on_place = mcl_util.on_place_non_mycelium_plant,
selection_box = { selection_box = {
type = "fixed", type = "fixed",
fixed = simple_selection_box, fixed = simple_selection_box,
@ -75,6 +77,8 @@ minetest.register_node("mcl_flowers:tallgrass", {
minetest.add_item(pos, oldnode.name) minetest.add_item(pos, oldnode.name)
end end
end, end,
node_placement_prediction = "",
on_place = mcl_util.on_place_non_mycelium_plant,
_mcl_blast_resistance = 0, _mcl_blast_resistance = 0,
_mcl_hardness = 0, _mcl_hardness = 0,
}) })
@ -102,6 +106,8 @@ minetest.register_node("mcl_flowers:fern", {
end end
end, end,
drop = wheat_seed_drop, drop = wheat_seed_drop,
node_placement_prediction = "",
on_place = mcl_util.on_place_non_mycelium_plant,
selection_box = { selection_box = {
type = "fixed", type = "fixed",
fixed = { -4/16, -0.5, -4/16, 4/16, 7/16, 4/16 }, fixed = { -4/16, -0.5, -4/16, 4/16, 7/16, 4/16 },
@ -151,7 +157,7 @@ local function add_large_plant(name, desc, longdesc, bottom_img, top_img, inv_im
local bottom_buildable = minetest.registered_nodes[minetest.get_node(bottom).name].buildable_to local bottom_buildable = minetest.registered_nodes[minetest.get_node(bottom).name].buildable_to
local top_buildable = minetest.registered_nodes[minetest.get_node(top).name].buildable_to local top_buildable = minetest.registered_nodes[minetest.get_node(top).name].buildable_to
local floorname = minetest.get_node({x=bottom.x, y=bottom.y-1, z=bottom.z}).name local floorname = minetest.get_node({x=bottom.x, y=bottom.y-1, z=bottom.z}).name
if minetest.registered_nodes[floorname].walkable and bottom_buildable and top_buildable then if floorname ~= "mcl_core:mycelium" and minetest.registered_nodes[floorname].walkable and bottom_buildable and top_buildable then
-- Success! We can now place the flower -- Success! We can now place the flower
minetest.sound_play(minetest.registered_nodes["mcl_flowers:"..name].sounds.place, {pos = bottom, gain=1}) minetest.sound_play(minetest.registered_nodes["mcl_flowers:"..name].sounds.place, {pos = bottom, gain=1})
minetest.set_node(bottom, {name="mcl_flowers:"..name}) minetest.set_node(bottom, {name="mcl_flowers:"..name})