-
-
Save Jordach/2918317 to your computer and use it in GitHub Desktop.
init.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Simple logging mod | |
local path = minetest.get_modpath("log").."/data/" | |
-- returns block coordinates containing [pos] node | |
local function convert_position(pos) | |
return {x = math.floor(pos.x / 16), y = math.floor(pos.y / 16), z = math.floor(pos.z / 16)} | |
end | |
local function filename(pos, short) | |
if short == true then | |
return path..pos.x.."/"..pos.y.."/" | |
else | |
return path..pos.x.."/"..pos.y.."/"..pos.z | |
end | |
end | |
-- creates missing directories | |
local function make_dirs(pos) | |
os.execute("mkdir -p "..filename(pos, true)) | |
end | |
local function time() | |
return os.time(os.date('*t')) | |
end | |
minetest.register_on_placenode(function(pos, newnode, placer) | |
block_pos = convert_position(pos) | |
make_dirs(block_pos) | |
local fout = io.open(filename(block_pos), "a") | |
fout:write(pos.x..","..pos.y..","..pos.z..",p,"..placer:get_player_name()..","..newnode.name..","..time().."\n") | |
fout:close() | |
end) | |
minetest.register_on_dignode(function(pos, oldnode, digger) | |
block_pos = convert_position(pos) | |
make_dirs(block_pos) | |
local fout = io.open(filename(block_pos), "a") | |
fout:write(pos.x..","..pos.y..","..pos.z..",d,"..digger:get_player_name()..","..oldnode.name..","..time().."\n") | |
fout:close() | |
end) | |
minetest.register_craftitem("log:wand", { | |
description = "Admin wand", | |
inventory_image = "log_wand.png", | |
}) | |
minetest.register_on_punchnode(function(pos, node, puncher) | |
if puncher:get_wielded_item():get_name() == "log:wand" then | |
minetest.chat_send_player(puncher:get_player_name(), "coordinates: "..pos.x.." x "..pos.y.." x "..pos.z) | |
end | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment