forked from MineClone5/MineClone5
fix codestyle version 2
This commit is contained in:
parent
61d3e072ef
commit
e9bbe67fbd
|
@ -11,58 +11,58 @@ local compass_frames = 32
|
||||||
|
|
||||||
-- Timer for random compass spinning
|
-- Timer for random compass spinning
|
||||||
local random_timer = 0
|
local random_timer = 0
|
||||||
local random_timer_trigger = 0.5 -- random compass spinning tick in seconds. Increase if there are performance problems
|
local random_timer_trigger = 0.5 -- random compass spinning tick in seconds. Incr ease if there are performance problems
|
||||||
|
|
||||||
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, x, y, z)
|
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) and x ~= nil and y ~= nil and z ~= nil then
|
if mcl_worlds.compass_works(pos) and x ~= nil and y ~= nil and z ~= nil then
|
||||||
local _, dim = mcl_worlds.y_to_layer(y)
|
local _, dim = mcl_worlds.y_to_layer(y)
|
||||||
local _, playerdim = mcl_worlds.y_to_layer(pos.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
|
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 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 and x == 0 and y == 0 and z == 0 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}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local angle_north = math.deg(math.atan2(spawn.x - pos.x, spawn.z - pos.z))
|
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
|
if angle_north < 0 then angle_north = angle_north + 360 end
|
||||||
local angle_dir = -math.deg(dir)
|
local angle_dir = -math.deg(dir)
|
||||||
local angle_relative = (angle_north - angle_dir + 180) % 360
|
local angle_relative = (angle_north - angle_dir + 180) % 360
|
||||||
return math.floor((angle_relative/11.25) + 0.5) % compass_frames
|
return math.floor((angle_relative/11.25) + 0.5) % compass_frames
|
||||||
else
|
else
|
||||||
return random_frame
|
return random_frame
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if x ~= 0 and y ~= 0 and z~= 0 and x ~= nil and y ~= nil and x~= nil then
|
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 _, dim = mcl_worlds.y_to_layer(y)
|
||||||
local _, playerdim = mcl_worlds.y_to_layer(pos.y)
|
local _, playerdim = mcl_worlds.y_to_layer(pos.y)
|
||||||
if dim == playerdim then --already explained that very same if statement above
|
if dim == playerdim then --already explained that very same if statement above
|
||||||
local spawn = {x=x,y=y,z=z}
|
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 and x == 0 and y == 0 and z == 0 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}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local angle_north = math.deg(math.atan2(spawn.x - pos.x, spawn.z - pos.z))
|
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
|
if angle_north < 0 then angle_north = angle_north + 360 end
|
||||||
local angle_dir = -math.deg(dir)
|
local angle_dir = -math.deg(dir)
|
||||||
local angle_relative = (angle_north - angle_dir + 180) % 360
|
local angle_relative = (angle_north - angle_dir + 180) % 360
|
||||||
return math.floor((angle_relative/11.25) + 0.5) % compass_frames
|
return math.floor((angle_relative/11.25) + 0.5) % compass_frames
|
||||||
else
|
else
|
||||||
return random_frame
|
return random_frame
|
||||||
end
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
return random_frame
|
return random_frame
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -86,36 +86,36 @@ minetest.register_globalstep(function(dtime)
|
||||||
local pos = player:get_pos()
|
local pos = player:get_pos()
|
||||||
|
|
||||||
for j,stack in pairs(player:get_inventory():get_list("main")) do
|
for j,stack in pairs(player:get_inventory():get_list("main")) do
|
||||||
x = stack:get_meta():get_string("x") -- i know i could write the pos in meta, but i like this method more, and it is basicly the same, since else there would be one table with 3 values, and i have 3 values on their own
|
x = stack:get_meta():get_string("x") -- i know i could write the pos in meta, but i like this method more, and it is basicly the same, since else there would be one table with 3 values, and i have 3 values on their own
|
||||||
y = stack:get_meta():get_string("y")
|
y = stack:get_meta():get_string("y")
|
||||||
z = stack:get_meta():get_string("z")
|
z = stack:get_meta():get_string("z")
|
||||||
|
|
||||||
x = tonumber(x)
|
x = tonumber(x)
|
||||||
y = tonumber(y)
|
y = tonumber(y)
|
||||||
z = tonumber(z)
|
z = tonumber(z)
|
||||||
|
|
||||||
if x == nil or y == nil or z == nil then --checking if the compass has lodestone meta
|
if x == nil or y == nil or z == 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
|
compass_image = mcl_compass.get_compass_image(pos, player:get_look_horizontal(), 0, 0, 0) --no lodestone meta
|
||||||
else
|
else
|
||||||
checkblock = {x = x, y = y, z = z}
|
checkblock = {x = x, y = y, z = z}
|
||||||
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 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)
|
local node = minetest.get_node(pos)
|
||||||
if node.name == "ignore" then
|
if node.name == "ignore" then
|
||||||
minetest.get_voxel_manip():read_from_map(pos, pos)
|
minetest.get_voxel_manip():read_from_map(pos, pos)
|
||||||
node = minetest.get_node(pos)
|
node = minetest.get_node(pos)
|
||||||
end
|
end
|
||||||
return node
|
return node
|
||||||
end
|
end
|
||||||
|
|
||||||
if get_far_node(checkblock).name == "mcl_compass:lodestone" then --check if lodestone still exists
|
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(), x, y, z)
|
compass_image = mcl_compass.get_compass_image(pos, player:get_look_horizontal(), x, y, z)
|
||||||
compass_image = compass_image .. "_lodestone"
|
compass_image = compass_image .. "_lodestone"
|
||||||
else -- lodestone got destroyed
|
else -- lodestone got destroyed
|
||||||
compass_image = random_frame .. "_lodestone"
|
compass_image = random_frame .. "_lodestone"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
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
|
||||||
|
@ -143,8 +143,8 @@ for i,img in ipairs(images) do
|
||||||
inv = 0
|
inv = 0
|
||||||
end
|
end
|
||||||
local use_doc, longdesc, tt
|
local use_doc, longdesc, tt
|
||||||
--Why is there no usage help? This should be fixed.
|
--Why is there no usage help? This should be fixed.
|
||||||
--local usagehelp
|
--local usagehelp
|
||||||
use_doc = i == stereotype_frame
|
use_doc = i == stereotype_frame
|
||||||
if use_doc then
|
if use_doc then
|
||||||
tt = S("Points to the world origin")
|
tt = S("Points to the world origin")
|
||||||
|
@ -162,8 +162,8 @@ for i,img in ipairs(images) do
|
||||||
stack_max = 64,
|
stack_max = 64,
|
||||||
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", {
|
minetest.register_craftitem(itemstring .. "_lodestone", {
|
||||||
description = S("Lodestone Compass"),
|
description = S("Lodestone Compass"),
|
||||||
_tt_help = tt,
|
_tt_help = tt,
|
||||||
_doc_items_create_entry = use_doc,
|
_doc_items_create_entry = use_doc,
|
||||||
|
@ -191,12 +191,12 @@ minetest.register_craft({
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = "mcl_compass:lodestone",
|
output = "mcl_compass:lodestone",
|
||||||
recipe = {
|
recipe = {
|
||||||
{"mcl_core:stonebrickcarved","mcl_core:stonebrickcarved","mcl_core:stonebrickcarved"},
|
{"mcl_core:stonebrickcarved","mcl_core:stonebrickcarved","mcl_core:stonebrickcarved"},
|
||||||
{"mcl_core:stonebrickcarved", "mcl_nether:netherite_ingot", "mcl_core:stonebrickcarved"},
|
{"mcl_core:stonebrickcarved", "mcl_nether:netherite_ingot", "mcl_core:stonebrickcarved"},
|
||||||
{"mcl_core:stonebrickcarved", "mcl_core:stonebrickcarved", "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)
|
||||||
|
@ -206,17 +206,17 @@ mcl_compass.stereotype = "mcl_compass:"..tostring(stereotype_frame)
|
||||||
|
|
||||||
|
|
||||||
minetest.register_node("mcl_compass:lodestone",{
|
minetest.register_node("mcl_compass:lodestone",{
|
||||||
description="Lodestone",
|
description="Lodestone",
|
||||||
on_rightclick = function(pos, node, player, itemstack)
|
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).match(itemstack.get_name(itemstack),"mcl_compass:") then
|
||||||
if itemstack.get_name(itemstack) ~= "mcl_compass:lodestone" then
|
if itemstack.get_name(itemstack) ~= "mcl_compass:lodestone" then
|
||||||
itemstack:get_meta():set_string("x", pos.x)
|
itemstack:get_meta():set_string("x", pos.x)
|
||||||
itemstack:get_meta():set_string("y", pos.y)
|
itemstack:get_meta():set_string("y", pos.y)
|
||||||
itemstack:get_meta():set_string("z", pos.z)
|
itemstack:get_meta():set_string("z", pos.z)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
tiles = {
|
tiles = {
|
||||||
"lodestone_top.png",
|
"lodestone_top.png",
|
||||||
"lodestone_bottom.png",
|
"lodestone_bottom.png",
|
||||||
"lodestone_side1.png",
|
"lodestone_side1.png",
|
||||||
|
@ -224,8 +224,8 @@ minetest.register_node("mcl_compass:lodestone",{
|
||||||
"lodestone_side3.png",
|
"lodestone_side3.png",
|
||||||
"lodestone_side4.png"
|
"lodestone_side4.png"
|
||||||
},
|
},
|
||||||
groups = {pickaxey=1, material_stone=1},
|
groups = {pickaxey=1, material_stone=1},
|
||||||
_mcl_hardness = 1.5,
|
_mcl_hardness = 1.5,
|
||||||
_mcl_blast_resistance = 6,
|
_mcl_blast_resistance = 6,
|
||||||
sounds = mcl_sounds.node_sound_stone_defaults()
|
sounds = mcl_sounds.node_sound_stone_defaults()
|
||||||
})
|
})
|
Loading…
Reference in New Issue