mirror of
https://github.com/Beanzilla/OreTracker.git
synced 2024-11-25 16:53:48 +01:00
Converted to modpack
Renamed original mod to Orehud. Added planned feature (2nd mod) Xray. Documented what features are currently avalible and what are planned.
This commit is contained in:
parent
22f54039ca
commit
206536834c
58
README.md
58
README.md
@ -1,54 +1,32 @@
|
|||||||
# Ore Tracker
|
# Oretracker
|
||||||
|
|
||||||
A useful mod for tracking what ores are around the player.
|
Combines various tech to allow advanced mining operations.
|
||||||
|
|
||||||
## About this mod
|
## What's in the box
|
||||||
|
|
||||||
This mod provides a graphical HUD interface which displays a series of ores.
|
* Orehud: The original Oretracker mod with a single command to toggle the mod on or off per individual player.
|
||||||
|
* Xray: Based on Orehud except trackes non-ores and makes them appear invisible.
|
||||||
|
|
||||||
## The ores
|
### Planned features for both mods
|
||||||
|
|
||||||
| Ore name | Text Shown | Color code (HEX) |
|
* Require a priviledge for both mods to prevent every player from using all features. (Perhaps you allow your regulars only orehud but not xray)
|
||||||
|----------|------------|------------------|
|
|
||||||
| Coal | Coa | 0xc8c8c8 |
|
|
||||||
| Iron | Iro | 0xaf644b |
|
|
||||||
| Gold | Gol | 0xc8c84b |
|
|
||||||
| Mese\* | Mes | 0xffff4b |
|
|
||||||
| Diamond | Dia | 0x4bfafa |
|
|
||||||
| Quartz\*\*| Qua | 0xc8c8c8 |
|
|
||||||
| Copper\*\*\*| Cop | 0xc86400 |
|
|
||||||
| Tin\* | Tin | 0xc8c8c8 |
|
|
||||||
| Ancient Debris\*\*| Deb | 0xaa644b |
|
|
||||||
| Lapis | Lap | 0x4b4bc8 |
|
|
||||||
| Redstone\*\* | Red | 0xc81919 |
|
|
||||||
| Glowstone\*\* | Glo | 0xffff4b |
|
|
||||||
|
|
||||||
\* Only found in MTG.
|
## Orehud
|
||||||
|
|
||||||
\*\* Found in MCL5 or MCL2 with the proper mods.
|
Displays ore positions via the player's HUD.
|
||||||
|
|
||||||
\*\*\* Found in MTG and MCL5 or MCL2 with the proper mods.
|
> `/orehud` toggles the rendering of the ore positions on or off.
|
||||||
|
|
||||||
## Settings
|
## Xray (Comming Soon)
|
||||||
|
|
||||||
### Detect Range
|
Hides unwanted stone (and other varients) from view, only showing a empty node in it's wake.
|
||||||
|
|
||||||
The number of blocks away from the player the mod will scan/display for ores.
|
> `/xray` toggles the unwanted stone from visible to invisible (on or off).
|
||||||
|
|
||||||
> Recommended 8 blocks with no more than 16 (Bigger numbers equals much higher loads on server and possibly client)
|
### To be done
|
||||||
|
|
||||||
### Scan Frequency
|
* Use the pre-existing orehud code in a seperate mod for tracking stone (including varients).
|
||||||
|
* Make replacement nodes that are "invisible" with a general category feature (light grey for stone, dark red for netherrack, etc.)\*
|
||||||
The time in seconds till the mod updates ores it is indicating and if any new ores enter the scaning area (Dictated by Detect Range)
|
* When wished to be on, swap nodes in the detect range from their visible to invisble counterparts.
|
||||||
|
|
||||||
> Recommended no faster than 1 (for 1 second) (Lower numbers equals faster scans but can/will increase loads on server and possibly client)
|
|
||||||
|
|
||||||
> Use 0 or negative number to indicate instantanious (no delay) scans. (Not recommended)
|
|
||||||
|
|
||||||
# Future Plans
|
|
||||||
|
|
||||||
* Make a hand held item that dictates if the mod runs (displays ores) for that player.
|
|
||||||
* Possibly make a priviledge to limit what player can see ores.
|
|
||||||
* Make a GUI for changing colors, what gets shown for what ore, what ore gets displayed. (Per player settings)
|
|
||||||
* Make a longer range or faster scan priviledge for players (like admins or "ranked" players)
|
|
||||||
|
|
||||||
|
\* I need to make invisible counterparts for all varients so you still get the original resource.
|
||||||
|
38
api.lua
38
api.lua
@ -1,38 +0,0 @@
|
|||||||
|
|
||||||
oretracker.add_ore = function(orename)
|
|
||||||
if minetest.registered_nodes[orename] then
|
|
||||||
table.insert(oretracker.ores, orename)
|
|
||||||
else
|
|
||||||
minetest.log("action", "[oretracker] Failed to add '"..orename.."' as it is a unregistered node.")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
oretracker.add_pos = function(pname, pos, title, color)
|
|
||||||
if not title then
|
|
||||||
title = minetest.pos_to_string(pos)
|
|
||||||
end
|
|
||||||
local player = minetest.get_player_by_name(pname)
|
|
||||||
local wps = minetest.deserialize(oretracker.store:get_string(pname)) or {}
|
|
||||||
if not color then
|
|
||||||
color = 0xffffff
|
|
||||||
end
|
|
||||||
table.insert(wps,
|
|
||||||
player:hud_add({
|
|
||||||
hud_elem_type = "waypoint",
|
|
||||||
name = title,
|
|
||||||
text = "m",
|
|
||||||
number = color,
|
|
||||||
world_pos = pos
|
|
||||||
})
|
|
||||||
)
|
|
||||||
oretracker.store:set_string(pname, minetest.serialize(wps))
|
|
||||||
end
|
|
||||||
|
|
||||||
oretracker.clear_pos = function(pname)
|
|
||||||
local player = minetest.get_player_by_name(pname)
|
|
||||||
local wps = minetest.deserialize(oretracker.store:get_string(pname)) or {}
|
|
||||||
for i, v in ipairs(wps) do
|
|
||||||
player:hud_remove(v)
|
|
||||||
end
|
|
||||||
oretracker.store:set_string(pname, minetest.serialize({}))
|
|
||||||
end
|
|
163
init.lua
163
init.lua
@ -1,163 +0,0 @@
|
|||||||
|
|
||||||
-- https://rubenwardy.com/minetest_modding_book/en/map/environment.html#finding-nodes
|
|
||||||
|
|
||||||
-- A public API
|
|
||||||
oretracker = {}
|
|
||||||
|
|
||||||
oretracker.S = minetest.get_translator("oretracker")
|
|
||||||
oretracker.modpath = minetest.get_modpath("oretracker")
|
|
||||||
oretracker.store = minetest.get_mod_storage()
|
|
||||||
|
|
||||||
-- Settings
|
|
||||||
-- Do not set detect_range to a very high number it may cause extreme loads when there are multiple players with this range
|
|
||||||
-- Recommended range is 8 blocks
|
|
||||||
oretracker.detect_range = 8 -- Range in blocks
|
|
||||||
-- The prefered fastest is 1 second, 0 or negative is instantanious updates (Which greatly impacts the server/client)
|
|
||||||
-- Recommended default is 3 seconds.
|
|
||||||
oretracker.scan_frequency = 3 -- Frequency in seconds
|
|
||||||
|
|
||||||
-- This attempts to detect the gamemode
|
|
||||||
if not minetest.registered_nodes["default:stone"] then
|
|
||||||
if not minetest.registered_nodes["mcl_core:stone"] then
|
|
||||||
oretracker.gamemode = "N/A"
|
|
||||||
else
|
|
||||||
oretracker.gamemode = "MCL"
|
|
||||||
-- Attempt to determine if it's MCL5 or MCL2
|
|
||||||
if not minetest.registered_nodes["mcl_nether:ancient_debris"] then
|
|
||||||
oretracker.gamemode = "MCL2"
|
|
||||||
else
|
|
||||||
oretracker.gamemode = "MCL5"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
oretracker.gamemode = "MTG"
|
|
||||||
end
|
|
||||||
|
|
||||||
minetest.log("action", "[oretracker] Detected game "..oretracker.gamemode..".")
|
|
||||||
|
|
||||||
-- Form a container to track what ores we want to follow
|
|
||||||
oretracker.ores = {}
|
|
||||||
|
|
||||||
dofile(oretracker.modpath .. "/api.lua")
|
|
||||||
|
|
||||||
-- Use api to assign ores we know/should be caring about
|
|
||||||
if oretracker.gamemode == "MCL2" or oretracker.gamemode == "MCL5" then
|
|
||||||
oretracker.add_ore("mcl_core:stone_with_coal")
|
|
||||||
oretracker.add_ore("mcl_core:stone_with_iron")
|
|
||||||
oretracker.add_ore("mcl_core:stone_with_gold")
|
|
||||||
oretracker.add_ore("mcl_core:stone_with_redstone")
|
|
||||||
oretracker.add_ore("mcl_core:stone_with_redstone_lit")
|
|
||||||
oretracker.add_ore("mcl_core:stone_with_lapis")
|
|
||||||
oretracker.add_ore("mcl_core:stone_with_emerald")
|
|
||||||
oretracker.add_ore("mcl_core:stone_with_diamond")
|
|
||||||
oretracker.add_ore("mcl_nether:quartz_ore") -- This fails on MCL2 :S
|
|
||||||
-- oretracker.add_ore("mcl_nether:glowstone") -- Same here, though by default this is disabled as glowstone isn't a "ore"
|
|
||||||
end
|
|
||||||
|
|
||||||
if oretracker.gamemode == "MCL5" then
|
|
||||||
oretracker.add_ore("mcl_copper:stone_with_copper")
|
|
||||||
oretracker.add_ore("mcl_nether:ancient_debris")
|
|
||||||
oretracker.add_ore("mcl_nether_gold:nether_gold_ore")
|
|
||||||
end
|
|
||||||
|
|
||||||
if oretracker.gamemode == "MTG" then
|
|
||||||
oretracker.add_ore("default:stone_with_coal")
|
|
||||||
oretracker.add_ore("default:stone_with_iron")
|
|
||||||
oretracker.add_ore("default:stone_with_gold")
|
|
||||||
oretracker.add_ore("default:stone_with_copper")
|
|
||||||
oretracker.add_ore("default:stone_with_tin")
|
|
||||||
oretracker.add_ore("default:stone_with_mese")
|
|
||||||
oretracker.add_ore("default:stone_with_diamond")
|
|
||||||
end
|
|
||||||
|
|
||||||
local size = 0
|
|
||||||
local result = "Ores: "
|
|
||||||
for i, v in ipairs(oretracker.ores) do
|
|
||||||
result = result..v.." "
|
|
||||||
size = size + 1
|
|
||||||
end
|
|
||||||
minetest.log("action", "[oretracker] Found "..size.." ores configured.")
|
|
||||||
minetest.log("action", "[oretracker] "..result)
|
|
||||||
|
|
||||||
-- Now to add the tracker notification system
|
|
||||||
oretracker.check_player = function(player)
|
|
||||||
local p = player
|
|
||||||
if not minetest.is_player(p) then
|
|
||||||
p = minetest.get_player_by_name(p)
|
|
||||||
end
|
|
||||||
local pos = p:get_pos()
|
|
||||||
local pname = p:get_player_name()
|
|
||||||
-- I need to clean up the player's ore waypoints added by the latter code
|
|
||||||
oretracker.clear_pos(pname)
|
|
||||||
local p1 = vector.subtract(pos, {x = oretracker.detect_range, y = oretracker.detect_range, z = oretracker.detect_range})
|
|
||||||
local p2 = vector.add(pos, {x = oretracker.detect_range, y = oretracker.detect_range, z = oretracker.detect_range})
|
|
||||||
local area = minetest.find_nodes_in_area(p1, p2, oretracker.ores)
|
|
||||||
for i=1, #area do
|
|
||||||
local node = minetest.get_node_or_nil(area[i])
|
|
||||||
if node == nil then
|
|
||||||
minetest.log("action", "[oretracker] Failed to obtain node at "..minetest.pos_to_string(area[1], 1)..".")
|
|
||||||
else
|
|
||||||
local delta = vector.subtract(area[i], pos)
|
|
||||||
local distance = (delta.x*delta.x) + (delta.y*delta.y) + (delta.z*delta.z)
|
|
||||||
if distance <= oretracker.detect_range*oretracker.detect_range then
|
|
||||||
distance = string.format("%.0f", math.sqrt(distance))
|
|
||||||
local block = "?"
|
|
||||||
local color = 0xffffff
|
|
||||||
if string.find(node.name, "coal") then
|
|
||||||
block = "Coa"
|
|
||||||
color = 0xc8c8c8
|
|
||||||
elseif string.find(node.name, "iron") then
|
|
||||||
block = "Iro"
|
|
||||||
color = 0xaf644b
|
|
||||||
elseif string.find(node.name, "gold") then
|
|
||||||
block = "Gol"
|
|
||||||
color = 0xc8c84b
|
|
||||||
elseif string.find(node.name, "mese") then
|
|
||||||
block = "Mes"
|
|
||||||
color = 0xffff4b
|
|
||||||
elseif string.find(node.name, "diamond") then
|
|
||||||
block = "Dia"
|
|
||||||
color = 0x4bfafa
|
|
||||||
elseif string.find(node.name, "quartz") then
|
|
||||||
block = "Qua"
|
|
||||||
color = 0xc8c8c8
|
|
||||||
elseif string.find(node.name, "copper") then
|
|
||||||
block = "Cop"
|
|
||||||
color = 0xc86400
|
|
||||||
elseif string.find(node.name, "tin") then
|
|
||||||
block = "Tin"
|
|
||||||
color = 0xc8c8c8
|
|
||||||
elseif string.find(node.name, "debris") then
|
|
||||||
block = "Deb"
|
|
||||||
color = 0xaa644b
|
|
||||||
elseif string.find(node.name, "lapis") then
|
|
||||||
block = "Lap"
|
|
||||||
color = 0x4b4bc8
|
|
||||||
elseif string.find(node.name, "redstone") then
|
|
||||||
block = "Red"
|
|
||||||
color = 0xc81919
|
|
||||||
elseif string.find(node.name, "glowstone") then
|
|
||||||
block = "Glo"
|
|
||||||
color = 0xffff4b
|
|
||||||
end
|
|
||||||
if block == "?" then
|
|
||||||
minetest.log("action", "[oretracker] Found '"..node.name.."' at "..minetest.pos_to_string(area[i], 1).." which is "..distance.." away from '"..pname..".")
|
|
||||||
block = node.name
|
|
||||||
end
|
|
||||||
-- Make a waypoint with the nodes name
|
|
||||||
oretracker.add_pos(pname, area[i], block, color)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local interval = 0
|
|
||||||
minetest.register_globalstep(function(dtime)
|
|
||||||
interval = interval - dtime
|
|
||||||
if interval <= 0 then
|
|
||||||
for _, player in ipairs(minetest.get_connected_players()) do
|
|
||||||
oretracker.check_player(player)
|
|
||||||
end
|
|
||||||
interval = oretracker.scan_frequency
|
|
||||||
end
|
|
||||||
end)
|
|
4
mod.conf
4
mod.conf
@ -1,4 +0,0 @@
|
|||||||
name = oretracker
|
|
||||||
description = "A useful mod for tracking what ores are around the player."
|
|
||||||
author = ApolloX
|
|
||||||
optional_depends = default, mcl_core
|
|
0
modpack.txt
Normal file
0
modpack.txt
Normal file
48
orehud/README.md
Normal file
48
orehud/README.md
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
# Ore Tracker > Ore hud
|
||||||
|
|
||||||
|
Displays ore position by using the HUD.
|
||||||
|
|
||||||
|
## About this mod
|
||||||
|
|
||||||
|
This mod provides a graphical HUD interface which displays a series of ores.
|
||||||
|
|
||||||
|
Simply use `/orehud` to enable or disable displaying the ores on your HUD.
|
||||||
|
|
||||||
|
## The ores
|
||||||
|
|
||||||
|
| Ore name | Text Shown | Color code (HEX) |
|
||||||
|
|----------|------------|------------------|
|
||||||
|
| Coal | Coa | 0xc8c8c8 |
|
||||||
|
| Iron | Iro | 0xaf644b |
|
||||||
|
| Gold | Gol | 0xc8c84b |
|
||||||
|
| Mese\* | Mes | 0xffff4b |
|
||||||
|
| Diamond | Dia | 0x4bfafa |
|
||||||
|
| Quartz\*\*| Qua | 0xc8c8c8 |
|
||||||
|
| Copper\*\*\*| Cop | 0xc86400 |
|
||||||
|
| Tin\* | Tin | 0xc8c8c8 |
|
||||||
|
| Ancient Debris\*\*| Deb | 0xaa644b |
|
||||||
|
| Lapis | Lap | 0x4b4bc8 |
|
||||||
|
| Redstone\*\* | Red | 0xc81919 |
|
||||||
|
| Glowstone\*\* | Glo | 0xffff4b |
|
||||||
|
|
||||||
|
\* Only found in MTG.
|
||||||
|
|
||||||
|
\*\* Found in MCL5 or MCL2 with the proper mods.
|
||||||
|
|
||||||
|
\*\*\* Found in MTG and MCL5 or MCL2 with the proper mods.
|
||||||
|
|
||||||
|
## Settings
|
||||||
|
|
||||||
|
### Detect Range
|
||||||
|
|
||||||
|
The number of blocks away from the player the mod will scan/display for ores.
|
||||||
|
|
||||||
|
> Recommended 8 blocks with no more than 16 (Bigger numbers equals much higher loads on server and possibly client)
|
||||||
|
|
||||||
|
### Scan Frequency
|
||||||
|
|
||||||
|
The time in seconds till the mod updates ores it is indicating and if any new ores enter the scaning area (Dictated by Detect Range)
|
||||||
|
|
||||||
|
> Recommended no faster than 1 (for 1 second) (Lower numbers equals faster scans but can/will increase loads on server and possibly client)
|
||||||
|
|
||||||
|
> Use 0 or negative number to indicate instantanious (no delay) scans. (Not recommended)
|
41
orehud/api.lua
Normal file
41
orehud/api.lua
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
|
||||||
|
-- Adds an "ore" node to track, only if that node actually is a valid node
|
||||||
|
orehud.add_ore = function(orename)
|
||||||
|
if minetest.registered_nodes[orename] then
|
||||||
|
table.insert(orehud.ores, orename)
|
||||||
|
else
|
||||||
|
minetest.log("action", "[oretracker-orehud] Failed to add '"..orename.."' as it is a unregistered node.")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Adds a waypoint to the given player's HUD, given title and color
|
||||||
|
orehud.add_pos = function(pname, pos, title, color)
|
||||||
|
if not title then
|
||||||
|
title = minetest.pos_to_string(pos)
|
||||||
|
end
|
||||||
|
local player = minetest.get_player_by_name(pname)
|
||||||
|
local wps = orehud.store[pname] or {}
|
||||||
|
if not color then
|
||||||
|
color = 0xffffff
|
||||||
|
end
|
||||||
|
table.insert(wps,
|
||||||
|
player:hud_add({
|
||||||
|
hud_elem_type = "waypoint",
|
||||||
|
name = title,
|
||||||
|
text = "m",
|
||||||
|
number = color,
|
||||||
|
world_pos = pos
|
||||||
|
})
|
||||||
|
)
|
||||||
|
orehud.store[pname] = wps
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Clears all waypoints from the given player's HUD
|
||||||
|
orehud.clear_pos = function(pname)
|
||||||
|
local player = minetest.get_player_by_name(pname)
|
||||||
|
local wps = orehud.store[pname] or {}
|
||||||
|
for i, v in ipairs(wps) do
|
||||||
|
player:hud_remove(v)
|
||||||
|
end
|
||||||
|
orehud.store[pname] = {}
|
||||||
|
end
|
207
orehud/init.lua
Normal file
207
orehud/init.lua
Normal file
@ -0,0 +1,207 @@
|
|||||||
|
|
||||||
|
-- https://rubenwardy.com/minetest_modding_book/en/map/environment.html#finding-nodes
|
||||||
|
|
||||||
|
-- A public API
|
||||||
|
orehud = {}
|
||||||
|
|
||||||
|
orehud.S = minetest.get_translator("orehud")
|
||||||
|
orehud.modpath = minetest.get_modpath("orehud")
|
||||||
|
orehud.store = {}
|
||||||
|
orehud.p_stats = {}
|
||||||
|
|
||||||
|
-- Settings
|
||||||
|
-- Do not set detect_range to a very high number it may cause extreme loads when there are multiple players with this range
|
||||||
|
-- Recommended range is 8 blocks
|
||||||
|
orehud.detect_range = 8 -- Range in blocks
|
||||||
|
-- The prefered fastest is 1 second, 0 or negative is instantanious updates (Which greatly impacts the server/client)
|
||||||
|
-- Recommended default is 3 seconds.
|
||||||
|
orehud.scan_frequency = 3 -- Frequency in seconds
|
||||||
|
|
||||||
|
-- This attempts to detect the gamemode
|
||||||
|
if not minetest.registered_nodes["default:stone"] then
|
||||||
|
if not minetest.registered_nodes["mcl_core:stone"] then
|
||||||
|
orehud.gamemode = "N/A"
|
||||||
|
else
|
||||||
|
orehud.gamemode = "MCL"
|
||||||
|
-- Attempt to determine if it's MCL5 or MCL2
|
||||||
|
if not minetest.registered_nodes["mcl_nether:ancient_debris"] then
|
||||||
|
orehud.gamemode = "MCL2"
|
||||||
|
else
|
||||||
|
orehud.gamemode = "MCL5"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
orehud.gamemode = "MTG"
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.log("action", "[oretracker-orehud] Detected game "..orehud.gamemode..".")
|
||||||
|
|
||||||
|
-- Form a container to track what ores we want to follow
|
||||||
|
orehud.ores = {}
|
||||||
|
|
||||||
|
dofile(orehud.modpath .. "/api.lua")
|
||||||
|
|
||||||
|
-- Use api to assign ores we know/should be caring about
|
||||||
|
if orehud.gamemode == "MCL2" or orehud.gamemode == "MCL5" then
|
||||||
|
orehud.add_ore("mcl_core:stone_with_coal")
|
||||||
|
orehud.add_ore("mcl_core:stone_with_iron")
|
||||||
|
orehud.add_ore("mcl_core:stone_with_gold")
|
||||||
|
orehud.add_ore("mcl_core:stone_with_redstone")
|
||||||
|
orehud.add_ore("mcl_core:stone_with_redstone_lit")
|
||||||
|
orehud.add_ore("mcl_core:stone_with_lapis")
|
||||||
|
orehud.add_ore("mcl_core:stone_with_emerald")
|
||||||
|
orehud.add_ore("mcl_core:stone_with_diamond")
|
||||||
|
orehud.add_ore("mcl_nether:quartz_ore") -- This fails on MCL2 :S (LOL, I didn't realize my test suite was MCL2, I though it was MCL5)
|
||||||
|
-- orehud.add_ore("mcl_nether:glowstone") -- By default this is disabled as glowstone isn't a "ore", but just uncomment this line to get it too
|
||||||
|
end
|
||||||
|
|
||||||
|
if orehud.gamemode == "MCL5" then
|
||||||
|
orehud.add_ore("mcl_copper:stone_with_copper")
|
||||||
|
orehud.add_ore("mcl_nether:ancient_debris")
|
||||||
|
orehud.add_ore("mcl_nether_gold:nether_gold_ore")
|
||||||
|
end
|
||||||
|
|
||||||
|
if orehud.gamemode == "MTG" then
|
||||||
|
orehud.add_ore("default:stone_with_coal")
|
||||||
|
orehud.add_ore("default:stone_with_iron")
|
||||||
|
orehud.add_ore("default:stone_with_gold")
|
||||||
|
orehud.add_ore("default:stone_with_copper")
|
||||||
|
orehud.add_ore("default:stone_with_tin")
|
||||||
|
orehud.add_ore("default:stone_with_mese")
|
||||||
|
orehud.add_ore("default:stone_with_diamond")
|
||||||
|
end
|
||||||
|
|
||||||
|
local size = 0
|
||||||
|
local result = "Ores: "
|
||||||
|
for i, v in ipairs(orehud.ores) do
|
||||||
|
result = result..v.." "
|
||||||
|
size = size + 1
|
||||||
|
end
|
||||||
|
minetest.log("action", "[oretracker-orehud] Found "..size.." ores configured.")
|
||||||
|
minetest.log("action", "[oretracker-orehud] "..result)
|
||||||
|
|
||||||
|
-- Itterates an area of nodes for "ores", then adds a waypoint at that nodes position for that "ore".
|
||||||
|
orehud.check_player = function(player)
|
||||||
|
local p = player
|
||||||
|
if not minetest.is_player(p) then
|
||||||
|
p = minetest.get_player_by_name(p)
|
||||||
|
end
|
||||||
|
local pos = p:get_pos()
|
||||||
|
local pname = p:get_player_name()
|
||||||
|
local p1 = vector.subtract(pos, {x = orehud.detect_range, y = orehud.detect_range, z = orehud.detect_range})
|
||||||
|
local p2 = vector.add(pos, {x = orehud.detect_range, y = orehud.detect_range, z = orehud.detect_range})
|
||||||
|
local area = minetest.find_nodes_in_area(p1, p2, orehud.ores)
|
||||||
|
for i=1, #area do
|
||||||
|
local node = minetest.get_node_or_nil(area[i])
|
||||||
|
if node == nil then
|
||||||
|
minetest.log("action", "[oretracker-orehud] Failed to obtain node at "..minetest.pos_to_string(area[1], 1)..".")
|
||||||
|
else
|
||||||
|
local delta = vector.subtract(area[i], pos)
|
||||||
|
local distance = (delta.x*delta.x) + (delta.y*delta.y) + (delta.z*delta.z)
|
||||||
|
if distance <= orehud.detect_range*orehud.detect_range then
|
||||||
|
distance = string.format("%.0f", math.sqrt(distance))
|
||||||
|
local block = "?"
|
||||||
|
local color = 0xffffff
|
||||||
|
if string.find(node.name, "coal") then
|
||||||
|
block = "Coa"
|
||||||
|
color = 0xc8c8c8
|
||||||
|
elseif string.find(node.name, "iron") then
|
||||||
|
block = "Iro"
|
||||||
|
color = 0xaf644b
|
||||||
|
elseif string.find(node.name, "gold") then
|
||||||
|
block = "Gol"
|
||||||
|
color = 0xc8c84b
|
||||||
|
elseif string.find(node.name, "mese") then
|
||||||
|
block = "Mes"
|
||||||
|
color = 0xffff4b
|
||||||
|
elseif string.find(node.name, "diamond") then
|
||||||
|
block = "Dia"
|
||||||
|
color = 0x4bfafa
|
||||||
|
elseif string.find(node.name, "quartz") then
|
||||||
|
block = "Qua"
|
||||||
|
color = 0xc8c8c8
|
||||||
|
elseif string.find(node.name, "copper") then
|
||||||
|
block = "Cop"
|
||||||
|
color = 0xc86400
|
||||||
|
elseif string.find(node.name, "tin") then
|
||||||
|
block = "Tin"
|
||||||
|
color = 0xc8c8c8
|
||||||
|
elseif string.find(node.name, "debris") then
|
||||||
|
block = "Deb"
|
||||||
|
color = 0xaa644b
|
||||||
|
elseif string.find(node.name, "lapis") then
|
||||||
|
block = "Lap"
|
||||||
|
color = 0x4b4bc8
|
||||||
|
elseif string.find(node.name, "redstone") then
|
||||||
|
block = "Red"
|
||||||
|
color = 0xc81919
|
||||||
|
elseif string.find(node.name, "glowstone") then
|
||||||
|
block = "Glo"
|
||||||
|
color = 0xffff4b
|
||||||
|
end
|
||||||
|
if block == "?" then
|
||||||
|
minetest.log("action", "[oretracker-orehud] Found '"..node.name.."' at "..minetest.pos_to_string(area[i], 1).." which is "..distance.." away from '"..pname..".")
|
||||||
|
block = node.name
|
||||||
|
end
|
||||||
|
-- Make a waypoint with the nodes name
|
||||||
|
orehud.add_pos(pname, area[i], block, color)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Now register with minetest to actually do something
|
||||||
|
|
||||||
|
local interval = 0
|
||||||
|
minetest.register_globalstep(function(dtime)
|
||||||
|
interval = interval - dtime
|
||||||
|
if interval <= 0 then
|
||||||
|
for _, player in ipairs(minetest.get_connected_players()) do
|
||||||
|
local p = player
|
||||||
|
if not minetest.is_player(p) then
|
||||||
|
p = minetest.get_player_by_name(p)
|
||||||
|
end
|
||||||
|
-- I need to clean up the player's ore waypoints added by the latter code
|
||||||
|
orehud.clear_pos(p:get_player_name())
|
||||||
|
if orehud.p_stats[p:get_player_name()] or false then
|
||||||
|
-- Only run if that player wants to run
|
||||||
|
orehud.check_player(p)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
interval = orehud.scan_frequency
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
minetest.register_on_joinplayer(function(player, laston)
|
||||||
|
orehud.p_stats[player:get_player_name()] = false
|
||||||
|
end)
|
||||||
|
|
||||||
|
minetest.register_on_leaveplayer(function(player, timeout)
|
||||||
|
local indx = 0
|
||||||
|
local found = false
|
||||||
|
for pname, val in ipairs(orehud.p_stats) do
|
||||||
|
if pname == player:get_player_name() then
|
||||||
|
found = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
indx = indx + 1
|
||||||
|
end
|
||||||
|
if found then
|
||||||
|
table.remove(orehud.p_stats, indx)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
minetest.register_chatcommand("orehud", {
|
||||||
|
privs = {
|
||||||
|
shout = true,
|
||||||
|
},
|
||||||
|
func = function(name, param)
|
||||||
|
if orehud.p_stats[name] then
|
||||||
|
orehud.p_stats[name] = false
|
||||||
|
minetest.chat_send_player(name, "Orehud: OFF")
|
||||||
|
else
|
||||||
|
orehud.p_stats[name] = true
|
||||||
|
minetest.chat_send_player(name, "Orehud: ON")
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
4
orehud/mod.conf
Normal file
4
orehud/mod.conf
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
name = orehud
|
||||||
|
description = Displays ore positions via the HUD.
|
||||||
|
author = ApolloX
|
||||||
|
optional_depends = default, mcl_core
|
Before Width: | Height: | Size: 405 KiB After Width: | Height: | Size: 405 KiB |
Loading…
Reference in New Issue
Block a user