forked from VoxeLibre/VoxeLibre
update init.lua to add lodestones
This commit is contained in:
parent
77c2f9371e
commit
6ee562271f
|
@ -13,12 +13,16 @@ local random_timer_trigger = 0.5 -- random compass spinning tick in seconds. Inc
|
||||||
|
|
||||||
local random_frame = math.random(0, compass_frames-1)
|
local random_frame = math.random(0, compass_frames-1)
|
||||||
|
|
||||||
function mcl_compass.get_compass_image(pos, dir)
|
function mcl_compass.get_compass_image(pos, dir, x, y, z)
|
||||||
-- Compasses do not work in certain zones
|
-- Compasses do not work in certain zones
|
||||||
if mcl_worlds.compass_works(pos) then
|
if mcl_worlds.compass_works(pos) and x ~= nil and y ~= nil and z ~= nil then
|
||||||
local spawn = {x=0,y=0,z=0}
|
local _, dim = mcl_worlds.y_to_layer(y)
|
||||||
|
local _, playerdim = mcl_worlds.y_to_layer(pos.y)
|
||||||
|
|
||||||
|
if dim == playerdim then --Check if player and compass target are in the same dimension, above check is just if the diemension is valid for the non lodestone compass
|
||||||
|
local spawn = {x=x,y=y,z=z}
|
||||||
local ssp = minetest.setting_get_pos("static_spawnpoint")
|
local ssp = minetest.setting_get_pos("static_spawnpoint")
|
||||||
if ssp then
|
if ssp and x == 0 and y == 0 and z == 0 then
|
||||||
spawn = ssp
|
spawn = ssp
|
||||||
if type(spawn) ~= "table" or type(spawn.x) ~= "number" or type(spawn.y) ~= "number" or type(spawn.z) ~= "number" then
|
if type(spawn) ~= "table" or type(spawn.x) ~= "number" or type(spawn.y) ~= "number" or type(spawn.z) ~= "number" then
|
||||||
spawn = {x=0,y=0,z=0}
|
spawn = {x=0,y=0,z=0}
|
||||||
|
@ -32,6 +36,32 @@ function mcl_compass.get_compass_image(pos, dir)
|
||||||
else
|
else
|
||||||
return random_frame
|
return random_frame
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
if x ~= 0 and y ~= 0 and z~= 0 and x ~= nil and y ~= nil and x~= nil then
|
||||||
|
local _, dim = mcl_worlds.y_to_layer(y)
|
||||||
|
local _, playerdim = mcl_worlds.y_to_layer(pos.y)
|
||||||
|
if dim == playerdim then --already explained that very same if statement above
|
||||||
|
local spawn = {x=x,y=y,z=z}
|
||||||
|
local ssp = minetest.setting_get_pos("static_spawnpoint")
|
||||||
|
if ssp and x == 0 and y == 0 and z == 0 then
|
||||||
|
spawn = ssp
|
||||||
|
if type(spawn) ~= "table" or type(spawn.x) ~= "number" or type(spawn.y) ~= "number" or type(spawn.z) ~= "number" then
|
||||||
|
spawn = {x=0,y=0,z=0}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local angle_north = math.deg(math.atan2(spawn.x - pos.x, spawn.z - pos.z))
|
||||||
|
if angle_north < 0 then angle_north = angle_north + 360 end
|
||||||
|
local angle_dir = -math.deg(dir)
|
||||||
|
local angle_relative = (angle_north - angle_dir + 180) % 360
|
||||||
|
return math.floor((angle_relative/11.25) + 0.5) % compass_frames
|
||||||
|
else
|
||||||
|
return random_frame
|
||||||
|
end
|
||||||
|
|
||||||
|
else
|
||||||
|
return random_frame
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
|
@ -52,9 +82,34 @@ minetest.register_globalstep(function(dtime)
|
||||||
end
|
end
|
||||||
if has_compass(player) then
|
if has_compass(player) then
|
||||||
local pos = player:get_pos()
|
local pos = player:get_pos()
|
||||||
local compass_image = mcl_compass.get_compass_image(pos, player:get_look_horizontal())
|
|
||||||
|
|
||||||
for j,stack in pairs(player:get_inventory():get_list("main")) do
|
for j,stack in pairs(player:get_inventory():get_list("main")) do
|
||||||
|
checkblock = {x = nil, y = nil, z = nil}
|
||||||
|
checkblock = minetest.string_to_pos(stack:get_meta():get_string("pointsto"))
|
||||||
|
|
||||||
|
|
||||||
|
if checkblock == nil then --checking if the compass has lodestone meta
|
||||||
|
compass_image = mcl_compass.get_compass_image(pos, player:get_look_horizontal(), 0, 0, 0) --no lodestone meta
|
||||||
|
else
|
||||||
|
local function get_far_node(pos) --function that tries to read node normally, and does it even if its unloaded https://dev.minetest.net/minetest.get_node
|
||||||
|
local node = minetest.get_node(pos)
|
||||||
|
if node.name == "ignore" then
|
||||||
|
minetest.get_voxel_manip():read_from_map(pos, pos)
|
||||||
|
node = minetest.get_node(pos)
|
||||||
|
end
|
||||||
|
return node
|
||||||
|
end
|
||||||
|
|
||||||
|
if get_far_node(checkblock).name == "mcl_compass:lodestone" then --check if lodestone still exists
|
||||||
|
compass_image = mcl_compass.get_compass_image(pos, player:get_look_horizontal(), checkblock.x, checkblock.y, checkblock.z)
|
||||||
|
compass_image = compass_image .. "_lodestone"
|
||||||
|
else -- lodestone got destroyed
|
||||||
|
compass_image = random_frame .. "_lodestone"
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
if minetest.get_item_group(stack:get_name(), "compass") ~= 0 and
|
if minetest.get_item_group(stack:get_name(), "compass") ~= 0 and
|
||||||
minetest.get_item_group(stack:get_name(), "compass")-1 ~= compass_image then
|
minetest.get_item_group(stack:get_name(), "compass")-1 ~= compass_image then
|
||||||
local itemname = "mcl_compass:"..compass_image
|
local itemname = "mcl_compass:"..compass_image
|
||||||
|
@ -101,6 +156,18 @@ for i,img in ipairs(images) do
|
||||||
groups = {not_in_creative_inventory=inv, compass=i, tool=1, disable_repair=1 }
|
groups = {not_in_creative_inventory=inv, compass=i, tool=1, disable_repair=1 }
|
||||||
})
|
})
|
||||||
|
|
||||||
|
minetest.register_craftitem(itemstring .. "_lodestone", {
|
||||||
|
description = S("Lodestone Compass"),
|
||||||
|
_tt_help = tt,
|
||||||
|
_doc_items_create_entry = use_doc,
|
||||||
|
_doc_items_longdesc = longdesc,
|
||||||
|
--_doc_items_usagehelp = usagehelp,
|
||||||
|
inventory_image = img .. "^[colorize:purple:50",
|
||||||
|
wield_image = img .. "^[colorize:purple:50",
|
||||||
|
stack_max = 64,
|
||||||
|
groups = {not_in_creative_inventory=1, compass=i, tool=1, disable_repair=1 }
|
||||||
|
})
|
||||||
|
|
||||||
-- Help aliases. Makes sure the lookup tool works correctly
|
-- Help aliases. Makes sure the lookup tool works correctly
|
||||||
if not use_doc and doc_mod then
|
if not use_doc and doc_mod then
|
||||||
doc.add_entry_alias("craftitems", "mcl_compass:"..(stereotype_frame-1), "craftitems", itemstring)
|
doc.add_entry_alias("craftitems", "mcl_compass:"..(stereotype_frame-1), "craftitems", itemstring)
|
||||||
|
@ -116,9 +183,41 @@ minetest.register_craft({
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
minetest.register_craft({
|
||||||
|
output = "mcl_compass:lodestone",
|
||||||
|
recipe = {
|
||||||
|
{"mcl_core:stonebrickcarved","mcl_core:stonebrickcarved","mcl_core:stonebrickcarved"},
|
||||||
|
{"mcl_core:stonebrickcarved", "mcl_nether:netherite_ingot", "mcl_core:stonebrickcarved"},
|
||||||
|
{"mcl_core:stonebrickcarved", "mcl_core:stonebrickcarved", "mcl_core:stonebrickcarved"}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
minetest.register_alias("mcl_compass:compass", "mcl_compass:"..stereotype_frame)
|
minetest.register_alias("mcl_compass:compass", "mcl_compass:"..stereotype_frame)
|
||||||
|
|
||||||
-- Export stereotype item for other mods to use
|
-- Export stereotype item for other mods to use
|
||||||
mcl_compass.stereotype = "mcl_compass:"..tostring(stereotype_frame)
|
mcl_compass.stereotype = "mcl_compass:"..tostring(stereotype_frame)
|
||||||
|
|
||||||
|
|
||||||
|
minetest.register_node("mcl_compass:lodestone",{
|
||||||
|
description=S("Lodestone"),
|
||||||
|
on_rightclick = function(pos, node, player, itemstack)
|
||||||
|
if itemstack.get_name(itemstack).match(itemstack.get_name(itemstack),"mcl_compass:") then
|
||||||
|
if itemstack.get_name(itemstack) ~= "mcl_compass:lodestone" then
|
||||||
|
itemstack:get_meta():set_string("pointsto", minetest.pos_to_string(pos))
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
tiles = {
|
||||||
|
"lodestone_top.png",
|
||||||
|
"lodestone_bottom.png",
|
||||||
|
"lodestone_side1.png",
|
||||||
|
"lodestone_side2.png",
|
||||||
|
"lodestone_side3.png",
|
||||||
|
"lodestone_side4.png"
|
||||||
|
},
|
||||||
|
groups = {pickaxey=1, material_stone=1},
|
||||||
|
_mcl_hardness = 1.5,
|
||||||
|
_mcl_blast_resistance = 6,
|
||||||
|
sounds = mcl_sounds.node_sound_stone_defaults()
|
||||||
|
})
|
Loading…
Reference in New Issue