mirror of
https://github.com/Beanzilla/OreTracker.git
synced 2024-11-26 09:13:52 +01:00
Initalized Repo
V1.0 Releases.
This commit is contained in:
commit
92e6042911
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2021 Beanzilla
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
54
README.md
Normal file
54
README.md
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
# Ore Tracker
|
||||||
|
|
||||||
|
A useful mod for tracking what ores are around the player.
|
||||||
|
|
||||||
|
## About this mod
|
||||||
|
|
||||||
|
This mod provides a graphical HUD interface which displays a series of ores.
|
||||||
|
|
||||||
|
## 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)
|
||||||
|
|
||||||
|
# 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)
|
||||||
|
|
38
api.lua
Normal file
38
api.lua
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
|
||||||
|
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
Normal file
163
init.lua
Normal file
@ -0,0 +1,163 @@
|
|||||||
|
|
||||||
|
-- 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
Normal file
4
mod.conf
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
name = oretracker
|
||||||
|
description = "A useful mod for tracking what ores are around the player."
|
||||||
|
author = ApolloX
|
||||||
|
optional_depends = default, mcl_core
|
BIN
screenshot.png
Normal file
BIN
screenshot.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 405 KiB |
Loading…
Reference in New Issue
Block a user