compass_rose/internal.lua

79 lines
2.3 KiB
Lua

local function on_place(itemstack, placer, pointed_thing)
if not minetest.is_player(placer) then
return minetest.item_place(itemstack, placer, pointed_thing)
end
local look_dir = placer:get_look_dir()
if not vector.check(look_dir) then
return minetest.item_place(itemstack, placer, pointed_thing)
end
local facedir = minetest.dir_to_facedir(look_dir)
local aim_dir = pointed_thing.under - pointed_thing.above
local param2 = 20 + math.random(0, 3) -- random rotation for the "upside-down" position
if aim_dir.y == -1 then
param2 = 0
elseif aim_dir.x == 1 then
param2 = 16
elseif aim_dir.x == -1 then
param2 = 12
elseif aim_dir.z == 1 then
param2 = 8
elseif aim_dir.z == -1 then
param2 = 4
end
return minetest.item_place(itemstack, placer, pointed_thing, param2)
end
minetest.register_node("compass_rose:decal", {
description = "Compass rose decal",
drawtype = "nodebox",
use_texture_alpha = "blend",
tiles = {
"compass_rose_decal.png",
"blank.png",
"blank.png",
"blank.png",
"blank.png",
"blank.png",
},
visual_scale = 3.0,
is_ground_content = false,
inventory_image = "compass_rose_decal.png",
wield_image = "compass_rose_decal.png",
paramtype = "light",
paramtype2 = "facedir",
walkable = false,
climbable = false,
sunlight_propagates = true,
node_box = {
type = "fixed",
-- shift tiny bit upwards (0.49) to prevent z-fighting
fixed = {-1.5/3, -0.5/3, -1.5/3, 1.5/3, -0.49/3, 1.5/3}
},
selection_box = {
type = "fixed",
fixed = {-1.5, -0.45, -1.5, 1.5, -0.5, 1.5}
},
groups = {choppy = 3, dig_immediate = 2},
on_place = on_place,
on_rotate = false, -- probably disable rotations
})
if core.get_modpath("alphabet") then
minetest.register_craft({
type = "shaped",
output = "compass_rose:decal",
recipe = {
{"", "alphabet:n", ""},
{"alphabet:w", "default:stone_block", "alphabet:e"},
{"", "alphabet:s", ""},
}
})
end