2017-05-16 19:47:12 +02:00
|
|
|
|
|
|
|
--
|
2015-09-01 17:15:24 +02:00
|
|
|
-- Compass handling
|
2017-05-16 19:47:12 +02:00
|
|
|
--
|
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"
|
|
|
|
|
2017-05-16 19:47:12 +02:00
|
|
|
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
|
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
minetest.register_craftitem(
|
2015-09-01 17:15:24 +02:00
|
|
|
"nav:compass_0",
|
|
|
|
{
|
2017-05-16 20:12:49 +02:00
|
|
|
description = "Compass",
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2017-05-16 19:47:12 +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,
|
2017-05-16 19:47:12 +02:00
|
|
|
})
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
minetest.register_craftitem(
|
2015-09-01 17:15:24 +02:00
|
|
|
"nav:compass_1",
|
|
|
|
{
|
2017-05-16 20:12:49 +02:00
|
|
|
description = "Compass",
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2017-05-16 19:47:12 +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},
|
|
|
|
stack_max = 1,
|
2017-05-16 19:47:12 +02:00
|
|
|
})
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
minetest.register_craftitem(
|
2015-09-01 17:15:24 +02:00
|
|
|
"nav:compass_2",
|
|
|
|
{
|
2017-05-16 20:12:49 +02:00
|
|
|
description = "Compass",
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2017-05-16 19:47:12 +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},
|
|
|
|
stack_max = 1,
|
2017-05-16 19:47:12 +02:00
|
|
|
})
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
minetest.register_craftitem(
|
2015-09-01 17:15:24 +02:00
|
|
|
"nav:compass_3",
|
|
|
|
{
|
2017-05-16 20:12:49 +02:00
|
|
|
description = "Compass",
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2017-05-16 19:47:12 +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},
|
|
|
|
stack_max = 1,
|
2017-05-16 19:47:12 +02:00
|
|
|
})
|
|
|
|
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
minetest.register_craftitem(
|
2015-09-01 17:15:24 +02:00
|
|
|
"nav:compass_4",
|
|
|
|
{
|
2017-05-16 20:12:49 +02:00
|
|
|
description = "Compass",
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2017-05-16 19:47:12 +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},
|
|
|
|
stack_max = 1,
|
2017-05-16 19:47:12 +02:00
|
|
|
})
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
minetest.register_craftitem(
|
2015-09-01 17:15:24 +02:00
|
|
|
"nav:compass_5",
|
|
|
|
{
|
2017-05-16 20:12:49 +02:00
|
|
|
description = "Compass",
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2017-05-16 19:47:12 +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},
|
|
|
|
stack_max = 1,
|
2017-05-16 19:47:12 +02:00
|
|
|
})
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
minetest.register_craftitem(
|
2015-09-01 17:15:24 +02:00
|
|
|
"nav:compass_6",
|
|
|
|
{
|
2017-05-16 20:12:49 +02:00
|
|
|
description = "Compass",
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2017-05-16 19:47:12 +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},
|
|
|
|
stack_max = 1,
|
2017-05-16 19:47:12 +02:00
|
|
|
})
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
minetest.register_craftitem(
|
2015-09-01 17:15:24 +02:00
|
|
|
"nav:compass_7",
|
|
|
|
{
|
2017-05-16 20:12:49 +02:00
|
|
|
description = "Compass",
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2017-05-16 19:47:12 +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},
|
|
|
|
stack_max = 1,
|
2017-05-16 19:47:12 +02:00
|
|
|
})
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2017-05-16 20:12:49 +02:00
|
|
|
minetest.register_alias("nav:compass", "nav:compass_0")
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2017-05-16 19:47:12 +02:00
|
|
|
-- Crafting
|
|
|
|
|
|
|
|
crafting.register_craft(
|
2015-09-01 17:15:24 +02:00
|
|
|
{
|
2017-05-16 20:12:49 +02:00
|
|
|
output = "nav:compass",
|
2017-05-16 19:47:12 +02:00
|
|
|
items = {
|
|
|
|
"default:ingot_steel 4",
|
|
|
|
"default:stick",
|
2015-09-01 17:15:24 +02:00
|
|
|
}
|
2017-05-16 19:47:12 +02:00
|
|
|
})
|
2015-10-25 22:18:54 +01: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",
|
2017-05-16 19:47:12 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
default.log("compass", "loaded")
|