Continued some optimizations of code in bamboo.on_place.

Begun work on scaffolding.
This commit is contained in:
Michieal 2023-01-03 15:57:58 -05:00 committed by Michieal
parent 966c914a8e
commit 50e50e2904
2 changed files with 66 additions and 61 deletions

View File

@ -105,7 +105,6 @@ local bamboo_def = {
end end
mcl_bamboo.mcl_log("placement of bamboo is not protected.") mcl_bamboo.mcl_log("placement of bamboo is not protected.")
-- Use pointed node's on_rightclick function first, if present -- Use pointed node's on_rightclick function first, if present
if placer and not placer:get_player_control().sneak then 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 if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then
@ -138,8 +137,8 @@ local bamboo_def = {
if wdir ~= 1 then if wdir ~= 1 then
return return
end end
local place_item = ItemStack(itemstack) -- make a copy so that we don't indirectly mess with the original.
local place_item = ItemStack(itemstack) -- make a copy so that we don't indirectly mess with the original.
itemstack:set_count(itemstack:get_count() - 1) itemstack:set_count(itemstack:get_count() - 1)
if nodename == bamboo then if nodename == bamboo then
-- return the missing item, so that we can lower the code -- return the missing item, so that we can lower the code
@ -147,17 +146,11 @@ local bamboo_def = {
itemstack:set_count(itemstack:get_count() + 1) itemstack:set_count(itemstack:get_count() + 1)
return minetest.item_place(itemstack, placer, pointed_thing, fdir) return minetest.item_place(itemstack, placer, pointed_thing, fdir)
elseif nodename == bamboo_one then elseif nodename == bamboo_one then
place_item:set_name(bamboo_one) place_item = ItemStack(bamboo_one)
minetest.item_place(place_item, placer, pointed_thing, fdir)
return itemstack, pointed_thing.under
elseif nodename == bamboo_two then elseif nodename == bamboo_two then
place_item:set_name(bamboo_two) place_item = ItemStack(bamboo_two)
minetest.item_place(place_item, placer, pointed_thing, fdir)
return itemstack, pointed_thing.under
elseif nodename == bamboo_three then elseif nodename == bamboo_three then
place_item:set_name(bamboo_three) place_item = ItemStack(bamboo_three)
minetest.item_place(place_item, placer, pointed_thing, fdir)
return itemstack, pointed_thing.under
else else
local placed_type = pr:next(0, 3) -- randomly choose which one to place. local placed_type = pr:next(0, 3) -- randomly choose which one to place.
mcl_bamboo.mcl_log("Place_Bamboo_Shoot--Type: " .. placed_type) mcl_bamboo.mcl_log("Place_Bamboo_Shoot--Type: " .. placed_type)
@ -170,9 +163,9 @@ local bamboo_def = {
elseif placed_type == 3 then elseif placed_type == 3 then
place_item = ItemStack(bamboo_three) place_item = ItemStack(bamboo_three)
end end
minetest.item_place(place_item, placer, pointed_thing, fdir)
return itemstack, pointed_thing.under
end end
minetest.item_place(place_item, placer, pointed_thing, fdir)
return itemstack, pointed_thing.under
end, end,
on_destruct = function(pos) on_destruct = function(pos)

View File

@ -223,7 +223,6 @@ if minetest.get_modpath("mcl_fences") then
{"mcl_core:stick", craft_wood, "mcl_core:stick"}, {"mcl_core:stick", craft_wood, "mcl_core:stick"},
} }
}) })
-- mcl_fences.register_fence("nether_brick_fence", S("Nether Brick Fence"), "mcl_fences_fence_nether_brick.png", {pickaxey=1, deco_block=1, fence_nether_brick=1}, 2, 30, {"group:fence_nether_brick"}, mcl_sounds.node_sound_stone_defaults())
minetest.register_alias("bamboo_fence", "mcl_fences:" .. id) minetest.register_alias("bamboo_fence", "mcl_fences:" .. id)
minetest.register_alias("bamboo_fence_gate", "mcl_fences:" .. id_gate) minetest.register_alias("bamboo_fence_gate", "mcl_fences:" .. id_gate)
end end
@ -294,60 +293,73 @@ minetest.register_node("mcl_bamboo:scaffolding", {
_mcl_hardness = 0, _mcl_hardness = 0,
on_place = function(itemstack, placer, ptd) on_place = function(itemstack, placer, ptd)
local scaff_node_name = "mcl_bamboo:scaffolding" local scaff_node_name = "mcl_bamboo:scaffolding"
if SIDE_SCAFFOLDING then mcl_bamboo.mcl_log("Checking for protected placement of scaffolding.")
-- count param2 up when placing to the sides. Fall when > 6
local ctrl = placer:get_player_control()
if ctrl and ctrl.sneak then
local pp2 = minetest.get_node(ptd.under).param2
local np2 = pp2 + 1
if minetest.get_node(vector.offset(ptd.above, 0, -1, 0)).name == "air" then
minetest.set_node(ptd.above, {name = "mcl_bamboo:scaffolding_horizontal", param2 = np2})
itemstack:take_item(1)
end
if np2 > 6 then
minetest.check_single_for_falling(ptd.above)
end
return itemstack
end
end
mcl_bamboo.mcl_log("Checking for protected placement of scaffolding.")
local node = minetest.get_node(ptd.under) local node = minetest.get_node(ptd.under)
local pos = ptd.under local pos = ptd.under
if mcl_bamboo.is_protected(pos, placer) then local dir = vector.subtract(pointed_thing.under, pointed_thing.above)
return local wdir = minetest.dir_to_wallmounted(dir)
end local fdir = minetest.dir_to_facedir(dir)
mcl_bamboo.mcl_log("placement of scaffolding is not protected.") if wdir == 1 then
--place on solid nodes -- top placement. Prevents placing scaffolding along the sides of other nodes.
if itemstack:get_name() ~= node.name then
minetest.set_node(ptd.above, {name = scaff_node_name, param2 = 0}) if mcl_bamboo.is_protected(pos, placer) then
if not minetest.is_creative_enabled(placer:get_player_name()) then return
itemstack:take_item(1)
end end
return itemstack mcl_bamboo.mcl_log("placement of scaffolding is not protected.")
end -- place on solid nodes
if node.name ~= scaff_node_name then
--build up when placing on existing scaffold minetest.set_node(ptd.above, {name = scaff_node_name, param2 = 0})
local h = 0
repeat
pos.y = pos.y + 1
local cn = minetest.get_node(pos)
local cnb = minetest.get_node(ptd.under)
local bn = minetest.get_node(vector.offset(ptd.under, 0, -1, 0))
if cn.name == "air" then
-- first step to making scaffolding work like Minecraft scaffolding.
if cnb.name == scaff_node_name and bn == scaff_node_name and SIDE_SCAFFOLDING == false then
return itemstack
end
minetest.set_node(pos, node)
if not minetest.is_creative_enabled(placer:get_player_name()) then if not minetest.is_creative_enabled(placer:get_player_name()) then
itemstack:take_item(1) itemstack:take_item(1)
end end
placer:set_wielded_item(itemstack)
return itemstack return itemstack
end end
h = h + 1 --build up when placing on existing scaffold
until cn.name ~= node.name or itemstack:get_count() == 0 or h >= 128 local h = 0
repeat
pos.y = pos.y + 1
local cn = minetest.get_node(pos)
local cnb = minetest.get_node(ptd.under)
local bn = minetest.get_node(vector.offset(ptd.under, 0, -1, 0))
if cn.name == "air" then
-- first step to making scaffolding work like Minecraft scaffolding.
if cnb.name == scaff_node_name and bn == scaff_node_name and SIDE_SCAFFOLDING == false then
return itemstack
end
if mcl_bamboo.is_protected(pos, placer) then
return
end
minetest.set_node(pos, node)
if not minetest.is_creative_enabled(placer:get_player_name()) then
itemstack:take_item(1)
end
placer:set_wielded_item(itemstack)
return itemstack
end
h = h + 1
until cn.name ~= node.name or itemstack:get_count() == 0 or h >= 128
else
-- Don't use. From cora, who failed to make something awesome.
if SIDE_SCAFFOLDING then
-- count param2 up when placing to the sides. Fall when > 6
local ctrl = placer:get_player_control()
if ctrl and ctrl.sneak then
local pp2 = minetest.get_node(ptd.under).param2
local np2 = pp2 + 1
if minetest.get_node(vector.offset(ptd.above, 0, -1, 0)).name == "air" then
minetest.set_node(ptd.above, {name = "mcl_bamboo:scaffolding_horizontal", param2 = np2})
itemstack:take_item(1)
end
if np2 > 6 then
minetest.check_single_for_falling(ptd.above)
end
return itemstack
end
end
end
end, end,
on_destruct = function(pos) on_destruct = function(pos)
-- Node destructor; called before removing node. -- Node destructor; called before removing node.
@ -369,7 +381,7 @@ minetest.register_node("mcl_bamboo:scaffolding", {
}) })
minetest.register_node("mcl_bamboo:scaffolding_horizontal", { minetest.register_node("mcl_bamboo:scaffolding_horizontal", {
description = S("Scaffolding (horizontal)"), description = S("Scaffolding"),
doc_items_longdesc = S("Scaffolding block used to climb up or out across areas."), doc_items_longdesc = S("Scaffolding block used to climb up or out across areas."),
doc_items_hidden = false, doc_items_hidden = false,
tiles = {"mcl_bamboo_scaffolding_top.png", "mcl_bamboo_scaffolding_top.png", "mcl_bamboo_scaffolding_bottom.png"}, tiles = {"mcl_bamboo_scaffolding_top.png", "mcl_bamboo_scaffolding_top.png", "mcl_bamboo_scaffolding_bottom.png"},