allow using "Sneak"/Shift to skip the on-pole/hanging/yard checks

(makes it possible to directly place a sign flat on the ground or
ceiling, among other things.)
This commit is contained in:
Vanessa Dannenberg 2019-09-26 01:10:28 -04:00
parent e92177b83e
commit ebeb035fac
2 changed files with 11 additions and 5 deletions

View File

@ -38,6 +38,8 @@ That said, there are some basic text formatting options:
* Pointing at an X or Z side of something that's detected as a pole/post will mount the sign onto that pole. Note that the sign actually occupies the node space in front of the pole, since they're still separate nodes. But, I figure, no one's going to want to use the space in front of the sign anyway, because doing so would of course obscure the sign, so it doesn't matter if the sign logically occupies that node space.
* If you're holding "Sneak" (usually shift) while placing, the on-pole/hanging/yard checks are skipped, allowing you to just place a sign flat onto the ground, ceiling, or top/bottom of a pole/post, like they used to work before `signs_lib` was a thing.
* If a sign is on the wall or flat on the ground, the screwdriver will spin it from one wall to the next, in clockwise order, whether there's a wall to attach to or not, followed by putting it flat on the ground, then flat against the ceiling, then back to wall orientation.
* If a sign is hanging from the ceiling (not flat against it), the screwdriver will just rotate it around its Y axis.

14
api.lua
View File

@ -815,6 +815,9 @@ end
function signs_lib.after_place_node(pos, placer, itemstack, pointed_thing, locked)
local playername = placer:get_player_name()
local controls = placer:get_player_control()
local signname = itemstack:get_name()
local no_wall_name = string.gsub(signname, "_wall", "")
@ -824,7 +827,7 @@ function signs_lib.after_place_node(pos, placer, itemstack, pointed_thing, locke
local pnode = minetest.get_node(ppos)
local pdef = minetest.registered_items[pnode.name]
if def.allow_onpole and signs_lib.check_for_pole(pos, pointed_thing) then
if def.allow_onpole and signs_lib.check_for_pole(pos, pointed_thing) and not controls.sneak then
local newparam2
local lookdir = minetest.yaw_to_dir(placer:get_look_horizontal())
if def.paramtype2 == "wallmounted" then
@ -834,7 +837,7 @@ function signs_lib.after_place_node(pos, placer, itemstack, pointed_thing, locke
end
local node = minetest.get_node(pos)
minetest.swap_node(pos, {name = no_wall_name.."_onpole", param2 = newparam2})
elseif def.allow_onpole_horizontal and signs_lib.check_for_horizontal_pole(pos, pointed_thing) then
elseif def.allow_onpole_horizontal and signs_lib.check_for_horizontal_pole(pos, pointed_thing) and not controls.sneak then
local newparam2
local lookdir = minetest.yaw_to_dir(placer:get_look_horizontal())
if def.paramtype2 == "wallmounted" then
@ -844,12 +847,12 @@ function signs_lib.after_place_node(pos, placer, itemstack, pointed_thing, locke
end
local node = minetest.get_node(pos)
minetest.swap_node(pos, {name = no_wall_name.."_onpole_horiz", param2 = newparam2})
elseif def.allow_hanging and signs_lib.check_for_ceiling(pointed_thing) then
elseif def.allow_hanging and signs_lib.check_for_ceiling(pointed_thing) and not controls.sneak then
local newparam2 = minetest.dir_to_facedir(placer:get_look_dir())
local node = minetest.get_node(pos)
minetest.swap_node(pos, {name = no_wall_name.."_hanging", param2 = newparam2})
elseif def.allow_yard and signs_lib.check_for_floor(pointed_thing) then
local newparam2 = minetest.dir_to_facedir(placer:get_look_dir())
elseif def.allow_yard and signs_lib.check_for_floor(pointed_thing) and not controls.sneak then
local newparam2 = minetest.dir_to_facedir(placer:get_look_dir())
local node = minetest.get_node(pos)
minetest.swap_node(pos, {name = no_wall_name.."_yard", param2 = newparam2})
elseif def.paramtype2 == "facedir" and signs_lib.check_for_ceiling(pointed_thing) then
@ -857,6 +860,7 @@ function signs_lib.after_place_node(pos, placer, itemstack, pointed_thing, locke
elseif def.paramtype2 == "facedir" and signs_lib.check_for_floor(pointed_thing) then
minetest.swap_node(pos, {name = signname, param2 = 4})
end
if locked then
local meta = minetest.get_meta(pos)
meta:set_string("owner", playername)