many worldgen mods and gonna try technic now

This commit is contained in:
2026-09-13 03:30:48 -06:00
parent bac6ac94a3
commit 548749cb1a
4811 changed files with 163271 additions and 1 deletions
+152
View File
@@ -0,0 +1,152 @@
# API Documentation
## Quick Links
- [`axis`](#axis)
- [`options`](#options)
- [`shape`](#shape)
- [`vizlib.colors`](#vizlibcolors)
- [`vizlib.default_color`](#vizlibdefault_color)
- [`vizlib.select_color()`](#vizlibselect_color)
- [`vizlib.random_color()`](#vizlibrandom_color)
- [`vizlib.erase_shape(shape)`](#vizliberase_shapeshape)
- [`vizlib.draw_point(pos, options)`](#vizlibdraw_pointpos-options)
- [`vizlib.draw_circle(pos, radius, axis, options)`](#vizlibdraw_circlepos-radius-axis-options)
- [`vizlib.draw_sphere(pos, radius, options)`](#vizlibdraw_spherepos-radius-options)
- [`vizlib.draw_line(pos1, pos2, options)`](#vizlibdraw_linepos1-pos2-options)
- [`vizlib.draw_square(pos, radius, axis, options)`](#vizlibdraw_squarepos-radius-axis-options)
- [`vizlib.draw_cube(pos, radius, options)`](#vizlibdraw_cubepos-radius-options)
- [`vizlib.draw_area(pos1, pos2, options)`](#vizlibdraw_areapos1-pos2-options)
## Data Types
#### **`axis`**
A string consisting of either "x", "y" or "z". Required by certain drawing functions. Must be lower case.
#### **`options`**
A table of values used to set shape options when passed to a drawing function. All values are optional.
**Values**
- `color` - String. The color of the shape. Defaults to `vizlib.default_color`.
- `infinite` - Boolean. If true, the shape will never expire. By default the shape will expire after 10 seconds.
- `player` - String or player object. If set, only the specified player will see the shape.
#### **`shape`**
A table of values defining a created shape. Returned from all drawing functions.
**Values**
- `name` - String. The player name, if a player was specified upon creation.
- `expiry` - The time this shape will expire, if not infinite. Can be compared to `os.time()`.
- `ids` - Table. The IDs for the particle spawners this shape is made of.
## Colors
#### **`vizlib.colors`**
Provides a list of 24 colors, sorted by hue. Each value is a table containing two values:
- `name` - The name of the color, in lowercase.
- `hex` - The RGB hex code for the color, including the `#` prefix.
#### **`vizlib.default_color`**
The default color for shapes if no color is specified upon creation.
Value is set by the [`vizlib_default_color`](settingtypes.txt) setting.
#### **`vizlib.select_color()`**
Selects a random color from `vizlib.colors`.
**Returns**
- A hex color code, including the `#` prefix.
#### **`vizlib.random_color()`**
Generates a completely random color.
**Returns**
- A hex color code, including the `#` prefix.
## Utility
#### **`vizlib.erase_shape(shape)`**
Removes a shape from the world.
Useful for removing shapes created with `options.infinite = true`.
**Arguments**
- `shape` - The shape to be removed.
## Drawing
#### **`vizlib.draw_point(pos, options)`**
Draws a point (one slightly bigger particle).
**Arguments**
- `pos` - Vector. The position of the point.
- `options` - Table. See [`options`](#options) above.
#### **`vizlib.draw_circle(pos, radius, axis, options)`**
Draws an approximate circle on a particular axis.
**Arguments**
- `pos` - Vector. The position of the center of the circle.
- `radius` - Number. The radius of the circle.
- `axis` - String. See [`axis`](#axis) above. The axis the circle will be positioned perpendicular to.
- `options` - Table. See [`options`](#options) above.
#### **`vizlib.draw_sphere(pos, radius, options)`**
Draws an approximate sphere.
**Arguments**
- `pos` - Vector. The position of the center of the sphere.
- `radius` - Number. The radius of the sphere.
- `options` - Table. See [`options`](#options) above.
#### **`vizlib.draw_line(pos1, pos2, options)`**
Draws a line from `pos1` to `pos2`.
**Arguments**
- `pos1` - Vector. The starting point of the line.
- `pos2` - Vector. The ending point of the line.
- `options` - Table. See [`options`](#options) above.
#### **`vizlib.draw_square(pos, radius, axis, options)`**
Draws a square on a particular axis.
**Arguments**
- `pos` - Vector. The position of the center of the square.
- `radius` - Number. The distance from the center to the edge of the square.
- `axis` - String. See [`axis`](#axis) above. The axis the square will be positioned perpendicular to.
- `options` - Table. See [`options`](#options) above.
#### **`vizlib.draw_cube(pos, radius, options)`**
Draws a cube.
**Arguments**
- `pos` - Vector. The position of the center of the cube.
- `radius` - Number. The distance from the center to the side of the cube.
- `options` - Table. See [`options`](#options) above.
#### **`vizlib.draw_area(pos1, pos2, options)`**
Draws a rectangular cuboid between `pos1` and `pos2`.
**Arguments**
- `pos1` - Vector. The first corner of the area.
- `pos2` - Vector. The second corner of the area.
- `options` - Table. See [`options`](#options) above.
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2023 OgelGames
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.
+68
View File
@@ -0,0 +1,68 @@
# Minetest Visulization Library [vizlib]
[![luacheck](https://github.com/OgelGames/vizlib/workflows/luacheck/badge.svg)](https://github.com/OgelGames/vizlib/actions)
[![License](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE.md)
[![Minetest](https://img.shields.io/badge/Minetest-5.0+-blue.svg)](https://www.minetest.net)
[![ContentDB](https://content.minetest.net/packages/OgelGames/vizlib/shields/downloads/)](https://content.minetest.net/packages/OgelGames/vizlib/)
## Overview
This mod is a code library for visualizing basic shapes in-game. You can draw lines, circles, cubes, spheres and more.
It's ideal for showing the working area or range of functional nodes, and a better alternative to using entities.
![Overview](overview.gif?raw=true "Overview")
## Usage
Simply add `vizlib` to your mod's dependencies, and call any of the API functions from your code.
See [API.md](API.md) for detailed documentation.
## Examples
Drawing a line between two points.
```lua
local pos1 = vector.new(-2, 0, -2)
local pos2 = vector.new(2, 2, 2)
vizlib.draw_line(pos1, pos2)
```
Drawing a blue sphere for the player Sam and removing it after 60 seconds.
```lua
local pos = vector.new(0, 5, 0)
local options = {
color = "#0000ff",
player = "Sam",
infinite = true,
}
local shape = vizlib.draw_sphere(pos, 3, options)
minetest.after(60, vizlib.erase_shape, shape)
```
Showing a working range when punching a node with an empty hand.
```lua
on_punch = function(pos, _, player)
if not player or player:get_wielded_item():get_name() ~= "" then
-- Only show range when using an empty hand
return
end
local radius = minetest.get_meta(pos):get_int("radius") + 0.5
vizlib.draw_cube(pos, radius, {player = player})
end
```
## Installation
Download the [master branch](https://github.com/OgelGames/vizlib/archive/master.zip) or the [latest release](https://github.com/OgelGames/vizlib/releases), and follow [the usual installation steps](https://wiki.minetest.net/Installing_Mods).
Alternatively, you can download and install the mod from [ContentDB](https://content.minetest.net/packages/OgelGames/vizlib) or the online content tab in Minetest.
## License
All code is licensed under the [MIT License](LICENSE).
`vizlib_particle.png` is licensed as [CC0](https://creativecommons.org/publicdomain/zero/1.0/).
+274
View File
@@ -0,0 +1,274 @@
local circles = {}
-- Calculate the values for the segments of the circles
do
local sqrt2 = math.sqrt(2) * 0.5
local rad90 = math.rad(90)
local pos = vector.new(sqrt2, 0, sqrt2)
local vel = vector.new((1 - sqrt2) * 2, 0, -sqrt2)
local acc = vector.new((1 - sqrt2) * -2, 0, 0)
local axes = {
x = vector.new(1, 0, 0),
y = vector.new(0, 1, 0),
z = vector.new(0, 0, 1),
}
for _,axis in ipairs({"y", "x", "z"}) do -- This order is important
circles[axis] = {}
if axis == "x" then
pos = vector.rotate_around_axis(pos, axes.z, rad90)
vel = vector.rotate_around_axis(vel, axes.z, rad90)
acc = vector.rotate_around_axis(acc, axes.z, rad90)
elseif axis == "z" then
pos = vector.rotate_around_axis(pos, axes.y, rad90)
vel = vector.rotate_around_axis(vel, axes.y, rad90)
acc = vector.rotate_around_axis(acc, axes.y, rad90)
end
for i=1, 4 do
circles[axis][i] = {
pos = vector.rotate_around_axis(pos, axes[axis], rad90 * i),
vel = vector.rotate_around_axis(vel, axes[axis], rad90 * i),
acc = vector.rotate_around_axis(acc, axes[axis], rad90 * i),
}
end
end
end
local function get_valid_options(options)
if type(options) ~= "table" then
options = {}
end
local color = options.color or vizlib.default_color
for _,c in ipairs(vizlib.colors) do
if c.name == color then
color = c.hex
end
end
local time = options.infinite and 0 or 10
local density = options.infinite and 1 or 10
local name
local t = type(options.player)
if t == "string" then
name = options.player
elseif t == "userdata" or t == "table" then
name = options.player:get_player_name()
end
return color, name, time, density
end
local function make_shape(name, time, ids)
local shape = {name = name}
if time > 0 then
shape.expiry = os.time() + time
end
if type(ids) ~= "table" then
shape.ids = {ids}
else
shape.ids = ids
end
return shape
end
local function make_arc(arc, pos, radius, color, name, time, density)
pos = vector.add(pos, vector.multiply(arc.pos, radius))
local vel = vector.multiply(arc.vel, radius)
local acc = vector.multiply(arc.acc, radius)
return minetest.add_particlespawner({
playername = name,
time = time,
amount = math.ceil(radius * density * 6.0),
minpos = pos,
maxpos = pos,
minvel = vel,
maxvel = vel,
minacc = acc,
maxacc = acc,
minexptime = 2,
maxexptime = 2,
texture = "vizlib_particle.png^[multiply:"..color,
glow = 14,
})
end
local function make_line(pos1, pos2, color, name, time, density)
local distance = vector.distance(pos1, pos2)
local dir = vector.direction(pos1, pos2)
local vel = vector.multiply(dir, math.min(distance, 10.0))
local expt = math.max(distance / 10.0, 1.0)
return minetest.add_particlespawner({
playername = name,
time = time,
amount = math.ceil(math.min(distance, 10.0) * density * 3.0),
minpos = pos1,
maxpos = pos1,
minvel = vel,
maxvel = vel,
minexptime = expt,
maxexptime = expt,
texture = "vizlib_particle.png^[multiply:"..color,
glow = 14,
})
end
local function make_point(pos, color, name, time, density)
return minetest.add_particlespawner({
playername = name,
time = time,
amount = density * 2,
minpos = pos,
maxpos = pos,
minexptime = 2.0,
maxexptime = 2.0,
texture = "vizlib_particle.png^[multiply:"..color,
glow = 14,
size = 1.5,
})
end
--------------------------------------------------
-- API Functions. See API.md for details.
--------------------------------------------------
function vizlib.select_color()
return vizlib.colors[math.random(24)].hex
end
function vizlib.random_color()
local r = math.random(0, 255)
local g = math.random(0, 255)
local b = math.random(0, 255)
return string.format("#%02x%02x%02x", r, g, b)
end
function vizlib.draw_point(pos, options)
local color, name, time, density = get_valid_options(options)
local ids = make_point(pos, color, name, time, density)
return make_shape(name, time, ids)
end
function vizlib.draw_circle(pos, radius, axis, options)
local color, name, time, density = get_valid_options(options)
local ids = {}
for _,arc in pairs(circles[axis]) do
table.insert(ids, make_arc(arc, pos, radius, color, name, time, density))
end
return make_shape(name, time, ids)
end
function vizlib.draw_sphere(pos, radius, options)
local color, name, time, density = get_valid_options(options)
local ids = {}
for _,circle in pairs(circles) do
for _,arc in pairs(circle) do
table.insert(ids, make_arc(arc, pos, radius, color, name, time, density))
end
end
return make_shape(name, time, ids)
end
function vizlib.draw_line(pos1, pos2, options)
local color, name, time, density = get_valid_options(options)
local ids = make_line(pos1, pos2, color, name, time, density)
return make_shape(name, time, ids)
end
function vizlib.draw_square(pos, radius, axis, options)
local color, name, time, density = get_valid_options(options)
local p1, p2, p3, p4
if axis == "x" then
p1 = vector.add(pos, vector.new(0, -radius, -radius))
p2 = vector.add(pos, vector.new(0, radius, -radius))
p3 = vector.add(pos, vector.new(0, radius, radius))
p4 = vector.add(pos, vector.new(0, -radius, radius))
elseif axis == "y" then
p1 = vector.add(pos, vector.new(-radius, 0, -radius))
p2 = vector.add(pos, vector.new( radius, 0, -radius))
p3 = vector.add(pos, vector.new( radius, 0, radius))
p4 = vector.add(pos, vector.new(-radius, 0, radius))
elseif axis == "z" then
p1 = vector.add(pos, vector.new(-radius, -radius, 0))
p2 = vector.add(pos, vector.new( radius, -radius, 0))
p3 = vector.add(pos, vector.new( radius, radius, 0))
p4 = vector.add(pos, vector.new(-radius, radius, 0))
end
local ids = {
make_line(p1, p2, color, name, time, density),
make_line(p2, p3, color, name, time, density),
make_line(p3, p4, color, name, time, density),
make_line(p4, p1, color, name, time, density),
}
return make_shape(name, time, ids)
end
function vizlib.draw_cube(pos, radius, options)
local color, name, time, density = get_valid_options(options)
local p1 = vector.add(pos, vector.new(-radius, radius, -radius))
local p2 = vector.add(pos, vector.new( radius, radius, -radius))
local p3 = vector.add(pos, vector.new( radius, radius, radius))
local p4 = vector.add(pos, vector.new(-radius, radius, radius))
local p5 = vector.add(pos, vector.new(-radius, -radius, -radius))
local p6 = vector.add(pos, vector.new( radius, -radius, -radius))
local p7 = vector.add(pos, vector.new( radius, -radius, radius))
local p8 = vector.add(pos, vector.new(-radius, -radius, radius))
local ids = {
-- Top
make_line(p1, p2, color, name, time, density),
make_line(p2, p3, color, name, time, density),
make_line(p3, p4, color, name, time, density),
make_line(p4, p1, color, name, time, density),
-- Bottom
make_line(p5, p6, color, name, time, density),
make_line(p6, p7, color, name, time, density),
make_line(p7, p8, color, name, time, density),
make_line(p8, p5, color, name, time, density),
-- Sides
make_line(p1, p5, color, name, time, density),
make_line(p2, p6, color, name, time, density),
make_line(p3, p7, color, name, time, density),
make_line(p4, p8, color, name, time, density),
}
return make_shape(name, time, ids)
end
function vizlib.draw_area(pos1, pos2, options)
local color, name, time, density = get_valid_options(options)
local minp, maxp = {}, {}
for _,c in pairs({"x", "y", "z"}) do
minp[c] = math.min(pos1[c], pos2[c])
maxp[c] = math.max(pos1[c], pos2[c])
end
local p1 = vector.new(minp.x, maxp.y, minp.z)
local p2 = vector.new(maxp.x, maxp.y, minp.z)
local p3 = vector.new(maxp.x, maxp.y, maxp.z)
local p4 = vector.new(minp.x, maxp.y, maxp.z)
local p5 = vector.new(minp.x, minp.y, minp.z)
local p6 = vector.new(maxp.x, minp.y, minp.z)
local p7 = vector.new(maxp.x, minp.y, maxp.z)
local p8 = vector.new(minp.x, minp.y, maxp.z)
local ids = {
-- Top
make_line(p1, p2, color, name, time, density),
make_line(p2, p3, color, name, time, density),
make_line(p3, p4, color, name, time, density),
make_line(p4, p1, color, name, time, density),
-- Bottom
make_line(p5, p6, color, name, time, density),
make_line(p6, p7, color, name, time, density),
make_line(p7, p8, color, name, time, density),
make_line(p8, p5, color, name, time, density),
-- Sides
make_line(p1, p5, color, name, time, density),
make_line(p2, p6, color, name, time, density),
make_line(p3, p7, color, name, time, density),
make_line(p4, p8, color, name, time, density),
}
return make_shape(name, time, ids)
end
function vizlib.erase_shape(shape)
if type(shape) ~= "table" or not shape.ids then
return
end
for _,id in pairs(shape.ids) do
minetest.delete_particlespawner(id)
end
end
+33
View File
@@ -0,0 +1,33 @@
vizlib = {}
vizlib.colors = {
{name = "red", hex = "#ff0000"},
{name = "vermilion", hex = "#ff4000"},
{name = "orange", hex = "#ff8000"},
{name = "amber", hex = "#ffbf00"},
{name = "yellow", hex = "#ffff00"},
{name = "lime", hex = "#bfff00"},
{name = "chartreuse", hex = "#80ff00"},
{name = "harlequin", hex = "#40ff00"},
{name = "green", hex = "#00ff00"},
{name = "malachite", hex = "#00ff40"},
{name = "spring", hex = "#00ff80"},
{name = "turquoise", hex = "#00ffbf"},
{name = "cyan", hex = "#00ffff"},
{name = "cerulean", hex = "#00bfff"},
{name = "azure", hex = "#0080ff"},
{name = "sapphire", hex = "#0040ff"},
{name = "blue", hex = "#0000ff"},
{name = "indigo", hex = "#4000ff"},
{name = "violet", hex = "#8000ff"},
{name = "mulberry", hex = "#bf00ff"},
{name = "magenta", hex = "#ff00ff"},
{name = "fuchsia", hex = "#ff00bf"},
{name = "rose", hex = "#ff0080"},
{name = "crimson", hex = "#ff0040"}
}
vizlib.default_color = minetest.settings:get("vizlib_default_color") or "#ff0000"
dofile(minetest.get_modpath("vizlib").."/api.lua")
+3
View File
@@ -0,0 +1,3 @@
name = vizlib
description = Minetest visulization library
min_minetest_version = 5.0
Binary file not shown.

After

Width:  |  Height:  |  Size: 174 KiB

+2
View File
@@ -0,0 +1,2 @@
# The default color for shapes if no color is specified upon creation. Must be a valid color string.
vizlib_default_color (Default particle color) string #ff0000
Binary file not shown.

After

Width:  |  Height:  |  Size: 273 B