Camas/mods/nav/compass.lua

164 lines
3.6 KiB
Lua
Raw Normal View History

--
2015-09-01 17:15:24 +02:00
-- Compass handling
--
2019-08-28 17:31:41 +02:00
local S = minetest.get_translator("nav")
2015-09-01 17:15:24 +02:00
2015-10-20 21:00:54 +02:00
local wield_image_0 = "nav_compass_inventory_0.png"
local wield_image_1 = "nav_compass_inventory_1.png"
function on_globalstep(dtime)
for _, player in pairs(minetest.get_connected_players()) do
local inv = player:get_inventory()
local yaw = player:get_look_horizontal()
local dir = math.floor(((yaw / math.pi) * 4) + 0.5)
if dir < 0 then
dir = dir + 8
end
if dir >= 8 then
dir = 0
end
for i = 1, 8 do
local itemstack = inv:get_stack("main", i)
local item = minetest.registered_items[itemstack:get_name()]
if item ~= nil then
if item.groups.nav_compass then
inv:set_stack("main", i, ItemStack("nav:compass_"..dir))
end
end
end
end
end
minetest.register_globalstep(on_globalstep)
-- Items
minetest.register_craftitem(
2015-09-01 17:15:24 +02:00
"nav:compass_0",
{
2019-08-28 17:31:41 +02:00
description = S("Compass"),
2015-09-01 17:15:24 +02:00
inventory_image = "nav_compass_inventory_0.png",
wield_image = wield_image_0,
2015-09-01 17:15:24 +02:00
groups = {nav_compass = 1},
stack_max = 1,
})
2015-09-01 17:15:24 +02:00
minetest.register_craftitem(
2015-09-01 17:15:24 +02:00
"nav:compass_1",
{
2019-08-28 17:31:41 +02:00
description = S("Compass"),
2015-09-01 17:15:24 +02:00
inventory_image = "nav_compass_inventory_1.png",
wield_image = wield_image_1,
2015-09-01 17:15:24 +02:00
groups = {nav_compass = 1, not_in_creative_inventory = 1},
2015-09-01 17:15:24 +02:00
stack_max = 1,
})
2015-09-01 17:15:24 +02:00
minetest.register_craftitem(
2015-09-01 17:15:24 +02:00
"nav:compass_2",
{
2019-08-28 17:31:41 +02:00
description = S("Compass"),
2015-09-01 17:15:24 +02:00
inventory_image = "nav_compass_inventory_0.png^[transformR270",
wield_image = wield_image_0 .. "^[transformR270",
2015-09-01 17:15:24 +02:00
groups = {nav_compass = 1, not_in_creative_inventory = 1},
2015-09-01 17:15:24 +02:00
stack_max = 1,
})
2015-09-01 17:15:24 +02:00
minetest.register_craftitem(
2015-09-01 17:15:24 +02:00
"nav:compass_3",
{
2019-08-28 17:31:41 +02:00
description = S("Compass"),
2015-09-01 17:15:24 +02:00
inventory_image = "nav_compass_inventory_1.png^[transformR270",
wield_image = wield_image_1 .. "^[transformR270",
2015-09-01 17:15:24 +02:00
groups = {nav_compass = 1, not_in_creative_inventory = 1},
2015-09-01 17:15:24 +02:00
stack_max = 1,
})
2015-09-01 17:15:24 +02:00
minetest.register_craftitem(
2015-09-01 17:15:24 +02:00
"nav:compass_4",
{
2019-08-28 17:31:41 +02:00
description = S("Compass"),
2015-09-01 17:15:24 +02:00
inventory_image = "nav_compass_inventory_0.png^[transformR180",
wield_image = wield_image_0 .. "^[transformR180",
2015-09-01 17:15:24 +02:00
groups = {nav_compass = 1, not_in_creative_inventory = 1},
2015-09-01 17:15:24 +02:00
stack_max = 1,
})
2015-09-01 17:15:24 +02:00
minetest.register_craftitem(
2015-09-01 17:15:24 +02:00
"nav:compass_5",
{
2019-08-28 17:31:41 +02:00
description = S("Compass"),
2015-09-01 17:15:24 +02:00
inventory_image = "nav_compass_inventory_1.png^[transformR180",
wield_image = wield_image_1 .. "^[transformR180",
2015-09-01 17:15:24 +02:00
groups = {nav_compass = 1, not_in_creative_inventory = 1},
2015-09-01 17:15:24 +02:00
stack_max = 1,
})
2015-09-01 17:15:24 +02:00
minetest.register_craftitem(
2015-09-01 17:15:24 +02:00
"nav:compass_6",
{
2019-08-28 17:31:41 +02:00
description = S("Compass"),
2015-09-01 17:15:24 +02:00
inventory_image = "nav_compass_inventory_0.png^[transformR90",
wield_image = wield_image_0 .. "^[transformR90",
2015-09-01 17:15:24 +02:00
groups = {nav_compass = 1, not_in_creative_inventory = 1},
2015-09-01 17:15:24 +02:00
stack_max = 1,
})
2015-09-01 17:15:24 +02:00
minetest.register_craftitem(
2015-09-01 17:15:24 +02:00
"nav:compass_7",
{
2019-08-28 17:31:41 +02:00
description = S("Compass"),
2015-09-01 17:15:24 +02:00
inventory_image = "nav_compass_inventory_1.png^[transformR90",
wield_image = wield_image_1 .. "^[transformR90",
2015-09-01 17:15:24 +02:00
groups = {nav_compass = 1, not_in_creative_inventory = 1},
2015-09-01 17:15:24 +02:00
stack_max = 1,
})
2015-09-01 17:15:24 +02:00
minetest.register_alias("nav:compass", "nav:compass_0")
2015-09-01 17:15:24 +02:00
-- Crafting
crafting.register_craft(
2015-09-01 17:15:24 +02:00
{
output = "nav:compass",
items = {
"default:ingot_steel 4",
"default:stick",
2015-09-01 17:15:24 +02:00
}
})
-- Achievements
achievements.register_achievement(
"true_navigator",
{
title = "True Navigator",
description = "Craft a compass",
times = 1,
2017-05-18 17:30:43 +02:00
craftitem = "nav:compass_0",
})
default.log("compass", "loaded")