Easier orientation of dispenser/dropper placement

This commit is contained in:
Wuzzy 2018-01-11 01:28:36 +01:00
parent a2f1122405
commit 24a523baa4
2 changed files with 31 additions and 18 deletions

View file

@ -26,6 +26,21 @@ local setup_dispenser = function(pos)
inv:set_size("main", 9) inv:set_size("main", 9)
end end
local orientate_dispenser = function(pos, placer)
-- Not placed by player
if not placer then return end
-- Pitch in degrees
local pitch = placer:get_look_vertical() * (180 / math.pi)
local node = minetest.get_node(pos)
if pitch > 55 then
minetest.set_node(pos, {name="mcl_dispensers:dispenser_up", param2 = node.param2})
elseif pitch < -55 then
minetest.set_node(pos, {name="mcl_dispensers:dispenser_down", param2 = node.param2})
end
end
local on_rotate local on_rotate
if minetest.get_modpath("screwdriver") then if minetest.get_modpath("screwdriver") then
on_rotate = screwdriver.rotate_simple on_rotate = screwdriver.rotate_simple
@ -422,15 +437,7 @@ The dispenser will do different things, depending on the dispensed item:
horizontal_def.after_place_node = function(pos, placer, itemstack, pointed_thing) horizontal_def.after_place_node = function(pos, placer, itemstack, pointed_thing)
setup_dispenser(pos) setup_dispenser(pos)
orientate_dispenser(pos, placer)
-- When placed up and down, convert node to up/down dispenser
if pointed_thing.above.y < pointed_thing.under.y then
minetest.swap_node(pos, {name = "mcl_dispensers:dispenser_down"})
elseif pointed_thing.above.y > pointed_thing.under.y then
minetest.swap_node(pos, {name = "mcl_dispensers:dispenser_up"})
end
-- Else, the normal facedir logic applies
end end
horizontal_def.tiles = { horizontal_def.tiles = {
"default_furnace_top.png", "default_furnace_bottom.png", "default_furnace_top.png", "default_furnace_bottom.png",

View file

@ -26,6 +26,20 @@ local setup_dropper = function(pos)
inv:set_size("main", 9) inv:set_size("main", 9)
end end
local orientate_dropper = function(pos, placer)
-- Not placed by player
if not placer then return end
-- Pitch in degrees
local pitch = placer:get_look_vertical() * (180 / math.pi)
if pitch > 55 then
minetest.swap_node(pos, {name="mcl_droppers:dropper_up"})
elseif pitch < -55 then
minetest.swap_node(pos, {name="mcl_droppers:dropper_down"})
end
end
local on_rotate local on_rotate
if minetest.get_modpath("screwdriver") then if minetest.get_modpath("screwdriver") then
on_rotate = screwdriver.rotate_simple on_rotate = screwdriver.rotate_simple
@ -108,15 +122,7 @@ horizontal_def._doc_items_longdesc = "A dropper is a redstone component and a co
horizontal_def._doc_items_usagehelp = "Droppers can be placed in 6 possible directions, items will be dropped out of the hole. Rightclick the dropper to access its inventory. Supply it with redstone energy once to make the dropper drop or transfer a random item." horizontal_def._doc_items_usagehelp = "Droppers can be placed in 6 possible directions, items will be dropped out of the hole. Rightclick the dropper to access its inventory. Supply it with redstone energy once to make the dropper drop or transfer a random item."
horizontal_def.after_place_node = function(pos, placer, itemstack, pointed_thing) horizontal_def.after_place_node = function(pos, placer, itemstack, pointed_thing)
setup_dropper(pos) setup_dropper(pos)
orientate_dropper(pos, placer)
-- When placed up and down, convert node to up/down dropper
if pointed_thing.above.y < pointed_thing.under.y then
minetest.swap_node(pos, {name = "mcl_droppers:dropper_down"})
elseif pointed_thing.above.y > pointed_thing.under.y then
minetest.swap_node(pos, {name = "mcl_droppers:dropper_up"})
end
-- Else, the normal facedir logic applies
end end
horizontal_def.tiles = { horizontal_def.tiles = {
"default_furnace_top.png", "default_furnace_bottom.png", "default_furnace_top.png", "default_furnace_bottom.png",