Compare commits

...

19 Commits

Author SHA1 Message Date
chmodsayshello 3a08ba6f78 add force laod cooldown 2022-04-27 18:23:50 +00:00
chmodsayshello 3e152db05a Merge pull request 'merge lodestone in new branch' (#2) from mcl2_lodestone into lodestone_with_cooldown
Reviewed-on: #2
2022-04-27 18:22:51 +00:00
chmodsayshello cdb9c840fa resolve conflict (one commit in fork ended up in master) 2022-04-27 18:22:38 +00:00
chmodsayshello 14e8e46e9c Merge pull request 'update branch' (#3) from MineClone2/MineClone2:master into lodestone_with_cooldown
Reviewed-on: #3
2022-04-27 18:17:24 +00:00
chmodsayshello 44b21512c5 fix crash (return not in the last line of if statement) 2022-04-26 19:42:33 +00:00
chmodsayshello 09193b4907 various fixes 2022-04-26 19:24:58 +00:00
chmodsayshello a2c02fc431 various fixes 2022-04-26 19:22:30 +00:00
chmodsayshello 1735343c5e add support for static_spawnpoint back 2022-04-26 13:00:52 +00:00
chmodsayshello 0c2562b88c fix formatting || compass_image local 2022-04-26 12:49:34 +00:00
chmodsayshello 5c8f94d620 make compass_image local 2022-04-25 19:51:44 +00:00
chmodsayshello e36a7df75d fix crash when trying to put a compass into an itemframe 2022-04-25 19:46:37 +00:00
chmodsayshello 5b67091921 use itemstack in get_compass_image to generate image 2022-04-25 19:33:17 +00:00
chmodsayshello a6b2aa7a05 remove mcl_nether from dependencies 2022-04-25 15:05:17 +00:00
chmodsayshello 0e15559bc7 replace mcl5 recepie 2022-04-25 15:04:47 +00:00
chmodsayshello 58b4bb46f6 add new dependencies 2022-04-25 13:10:37 +00:00
chmodsayshello 0cecc814e1 upload textures 2/2 2022-04-25 13:05:48 +00:00
chmodsayshello bbbf69aa5e upload textures 1/2 2022-04-25 13:05:26 +00:00
chmodsayshello 6ee562271f update init.lua to add lodestones 2022-04-25 13:03:05 +00:00
chmodsayshello 77c2f9371e Merge pull request 'Update Fork' (#1) from MineClone2/MineClone2:master into master
Reviewed-on: #1
2022-04-25 12:31:14 +00:00
9 changed files with 122 additions and 24 deletions

View File

@ -1,9 +1,34 @@
local stereotype_frame = 18
local S = minetest.get_translator(minetest.get_current_modname())
mcl_compass = {}
local compass_frames = 32
local function get_far_node(pos, itemstack) --code from minetest dev wiki: https://dev.minetest.net/minetest.get_node, some edits have been made to add a cooldown for force loads
local node = minetest.get_node(pos)
if node.name == "ignore" then
tstamp = tonumber(itemstack:get_meta():get_string("last_forceload"))
if tstamp == nil then --this is only relevant for new lodestone compasses, the ones that have never performes a forceload yet
itemstack:get_meta():set_string("last_forceload", tostring(os.time(os.date("!*t"))))
tstamp = tonumber(os.time(os.date("!*t")))
end
if tonumber(os.time(os.date("!*t"))) - tstamp > 180 then --current time in secounds - old time in secounds, if it is over 180 (3 mins): forceload
itemstack:get_meta():set_string("last_forceload", tostring(os.time(os.date("!*t"))))
minetest.get_voxel_manip():read_from_map(pos, pos)
node = minetest.get_node(pos)
minetest.log("forceloaded, cooldown reset!")
else
minetest.log("cooldown not over yet")
node = {name="mcl_compass:lodestone"} --cooldown not over yet, pretend like there is something...
end
end
return node
end
--Not sure spawn point should be dymanic (is it in mc?)
--local default_spawn_settings = minetest.settings:get("static_spawnpoint")
@ -13,10 +38,34 @@ local random_timer_trigger = 0.5 -- random compass spinning tick in seconds. Inc
local random_frame = math.random(0, compass_frames-1)
function mcl_compass.get_compass_image(pos, dir)
-- Compasses do not work in certain zones
if mcl_worlds.compass_works(pos) then
local spawn = {x=0,y=0,z=0}
function mcl_compass.get_compass_image(pos, dir, itemstack)
if not itemstack then
minetest.log("WARNING: mcl_compass.get_compass_image() was called without itemstack, returning random frame!")
return random_frame
end
local lodestone_pos = minetest.string_to_pos(itemstack:get_meta():get_string("pointsto"))
if lodestone_pos then --lodestone meta present
local _, dim = mcl_worlds.y_to_layer(lodestone_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 get_far_node(lodestone_pos, itemstack).name == "mcl_compass:lodestone" then --check if lodestone still exists
local angle_north = math.deg(math.atan2(lodestone_pos.x - pos.x, lodestone_pos.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 .. "_lodestone"
else -- lodestone got destroyed
return random_frame .. "_lodestone"
end
else
return random_frame .. "_lodestone"
end
else --no lodestone meta, normal compass....
local spawn = {x = 0, y=0, z=0} --before you guys tell me that the normal compass no points to real spawn, it always pointed to 0 0
local ssp = minetest.setting_get_pos("static_spawnpoint")
if ssp then
spawn = ssp
@ -24,13 +73,17 @@ function mcl_compass.get_compass_image(pos, dir)
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
if mcl_worlds.compass_works(pos) then --is the player in the overworld?
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
end
end
@ -41,7 +94,7 @@ minetest.register_globalstep(function(dtime)
random_frame = (random_frame + math.random(-1, 1)) % compass_frames
random_timer = 0
end
for i,player in pairs(minetest.get_connected_players()) do
for _,player in pairs(minetest.get_connected_players()) do
local function has_compass(player)
for _,stack in pairs(player:get_inventory():get_list("main")) do
if minetest.get_item_group(stack:get_name(), "compass") ~= 0 then
@ -52,15 +105,18 @@ minetest.register_globalstep(function(dtime)
end
if has_compass(player) then
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
if minetest.get_item_group(stack:get_name(), "compass") ~= 0 and
minetest.get_item_group(stack:get_name(), "compass")-1 ~= compass_image then
local itemname = "mcl_compass:"..compass_image
stack:set_name(itemname)
player:get_inventory():set_stack("main", j, stack)
if minetest.get_item_group(stack:get_name(), "compass") ~= 0 then
local compass_image = mcl_compass.get_compass_image(pos, player:get_look_horizontal(), stack)
if minetest.get_item_group(stack:get_name(), "compass")-1 ~= compass_image and minetest.get_item_group(stack:get_name(), "compass")-1 .. "_lodestone" ~=compass_image then --Explaination: First check for normal compasses, secound check for lodestone ones
local itemname = "mcl_compass:"..compass_image
--minetest.log(os.time(os.date("!*t")))
stack:set_name(itemname)
player:get_inventory():set_stack("main", j, stack)
end
end
end
end
end
@ -74,15 +130,14 @@ end
local doc_mod = minetest.get_modpath("doc")
local stereotype_frame = 18
for i,img in ipairs(images) do
local inv = 1
if i == stereotype_frame then
inv = 0
end
local use_doc, longdesc, tt
--Why is there no usage help? This should be fixed.
--local usagehelp
--Why is there no usage help? This should be fixed.
--local usagehelp
use_doc = i == stereotype_frame
if use_doc then
tt = S("Points to the world origin")
@ -100,6 +155,18 @@ for i,img in ipairs(images) do
stack_max = 64,
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
if not use_doc and doc_mod then
@ -116,9 +183,40 @@ minetest.register_craft({
}
})
minetest.register_craft({
output = "mcl_compass:lodestone",
recipe = {
{"mcl_core:stonebrickcarved","mcl_core:stonebrickcarved","mcl_core:stonebrickcarved"},
{"mcl_core:stonebrickcarved", "mcl_core:diamondblock", "mcl_core:stonebrickcarved"},
{"mcl_core:stonebrickcarved", "mcl_core:stonebrickcarved", "mcl_core:stonebrickcarved"}
}
})
minetest.register_alias("mcl_compass:compass", "mcl_compass:"..stereotype_frame)
-- Export stereotype item for other mods to use
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()
})

View File

@ -1,4 +1,4 @@
name = mcl_compass
description = A compass item which points towards the world origin.
depends = mcl_core, mcl_worlds, mesecons
optional_depends = doc
depends = mcl_core, mcl_worlds, mesecons, mcl_sounds
optional_depends = doc

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

View File

@ -222,7 +222,7 @@ minetest.register_node("mcl_itemframes:item_frame",{
put_itemstack:set_count(1)
local itemname = put_itemstack:get_name()
if minetest.get_item_group(itemname, "compass") > 0 then
put_itemstack:set_name("mcl_compass:" .. mcl_compass.get_compass_image(pos, minetest.dir_to_yaw(minetest.facedir_to_dir(node.param2))))
put_itemstack:set_name("mcl_compass:" .. mcl_compass.get_compass_image(pos, minetest.dir_to_yaw(minetest.facedir_to_dir(node.param2)), put_itemstack))
end
if minetest.get_item_group(itemname, "clock") > 0 then
minetest.get_node_timer(pos):start(1.0)