Add value getter

This commit is contained in:
Wuzzy 2022-04-09 20:39:15 +02:00
parent 57ccd051e4
commit 2c5c45f1b2
2 changed files with 38 additions and 8 deletions

View File

@ -31,6 +31,34 @@ minetest.register_node("perlin_explorer:node_negative", {
-- Force-drop without metadata to avoid spamming the inventory
drop = "perlin_explorer:node_negative",
})
minetest.register_tool("perlin_explorer:getter", {
description = S("Perlin Value Getter"),
_tt_help = S("Punch a node to display the Perlin noise value at this position"),
inventory_image = "perlin_explorer_getter.png",
wield_image = "perlin_explorer_getter.png",
groups = { disable_repair = 1 },
on_use = function(itemstack, user, pointed_thing)
if current_perlin.noise then
if pointed_thing.type ~= "node" then
-- No-op for non-nodes
return
end
local pos = pointed_thing.under
local val
if current_perlin.dimensions == 2 then
val = current_perlin.noise:get_2d({x=pos.x, y=pos.z})
else
val = current_perlin.noise:get_3d(pos)
end
minetest.chat_send_player(user:get_player_name(), S("pos=@1, value=@2", minetest.pos_to_string(pos), val))
else
local msg = S("No Perlin noise set. Set one with /set_perlin!")
minetest.chat_send_player(user:get_player_name(), msg)
end
end,
})
local CONTENT_TEST_NODE = minetest.get_content_id("perlin_explorer:node")
local CONTENT_TEST_NODE_NEGATIVE = minetest.get_content_id("perlin_explorer:node_negative")
@ -143,9 +171,9 @@ create_perlin = function(pos, options)
current_perlin.show_negative = options.show_negative
if current_perlin.show_negative == nil then
if current_perlin.dimensions == 2 then
options.show_negative = true
current_perlin.show_negative = true
elseif current_perlin.dimensions == 3 then
options.show_negative = false
current_perlin.show_negative = false
end
end
local mpos = vector.round(pos)
@ -197,25 +225,27 @@ minetest.register_chatcommand("perlin_set", {
minetest.register_chatcommand("perlin_generate", {
privs = { server = true },
description = S("Generate Perlin noise"),
params = S("<pos>"),
params = S("<pos> <dimensions> <squarius>"),
func = function(name, param)
local x, y, z = string.match(param, "([0-9.-]+) ([0-9.-]+) ([0-9.-]+)")
if not x or not y or not z then
local x, y, z, dimensions, squarius = string.match(param, "([0-9.-]+) ([0-9.-]+) ([0-9.-]+) ([23]) ([0-9]+)")
if not x then
return false
end
x = tonumber(x)
y = tonumber(y)
z = tonumber(z)
if not x or not y or not z then
dimensions = tonumber(dimensions)
squarius = tonumber(squarius)
if not x or not y or not z or not dimensions or not squarius then
return false
end
if not x or not y or not z then
if not x or not y or not z or not dimensions or not squarius then
return false, S("Invalid parameter type.")
end
local pos = vector.new(x, y, z)
minetest.chat_send_player(name, S("Creating Perlin noise, please wait …"))
local msg = create_perlin(pos, {dimensions=3, squarius=64})
local msg = create_perlin(pos, {dimensions=dimensions, squarius=squarius})
if msg == false then
return false, S("No Perlin noise set. Set one with '/perlin_set' first!")
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB