minetest_origin/init.lua

72 lines
2.3 KiB
Lua
Raw Permalink Normal View History

2016-07-02 05:24:09 -07:00
--[[
The Origin
2016-08-07 19:03:35 -07:00
version 1.3.0
2016-07-02 05:24:09 -07:00
]]
local S
if (minetest.get_modpath("intllib")) then
2016-11-08 17:25:41 -08:00
S = intllib.Getter()
else
S = function ( s ) return s end
end
2016-08-11 08:57:37 -07:00
local origin = {}
origin.settings = {}
2016-07-02 05:24:09 -07:00
do
local filepath = minetest.get_worldpath().."/origin.mt"
local file = io.open(filepath, "r")
if file then
io.close(file)
origin.exists = true
else
origin.exists = false
end
2017-06-20 07:56:03 -07:00
origin.settings.force_singlenode = minetest.settings:get_bool("origin_force_singlenode")
if origin.settings.force_singlenode == nil then
origin.settings.force_singlenode = true
end
2016-07-02 05:24:09 -07:00
end
minetest.register_node("origin:origin",{
description = S("The Origin"),
2016-11-15 21:41:06 -08:00
_doc_items_longdesc = S("The Origin is the starting block of this world. On the Origin the earliest visitors of this world arrive and it is the first block at which all other blocks can be built to, so that builders can build their architectural masterpieces in a world which would be (usually) empty otherwise."),
2016-11-02 14:37:36 -07:00
groups = { not_in_creative_inventory = 1, immortal = 1 },
2016-08-07 15:39:22 -07:00
diggable = false,
2016-07-02 05:24:09 -07:00
tiles = {"origin_origin.png"},
sounds = { footstep = "origin_origin_footstep" },
is_ground_content = false,
2016-08-05 08:38:03 -07:00
drop = "",
2016-07-02 05:24:09 -07:00
})
minetest.register_on_mapgen_init(function(mgparams)
if origin.settings.force_singlenode == true then
minetest.set_mapgen_params({mgname = "singlenode"})
end
2016-07-02 05:24:09 -07:00
end)
minetest.register_on_generated(function(minp, maxp, seed)
local spawn = minetest.setting_get_pos("static_spawnpoint")
if origin.exists ~= true then
2016-07-02 05:24:09 -07:00
local blockpos
if spawn ~= nil then
blockpos = { x=spawn.x, y=spawn.y-1, z=spawn.z }
else
blockpos = { x=0, y=-1, z=0 }
end
if(minp.x <= blockpos.x and maxp.x >= blockpos.x and minp.y <= blockpos.y and maxp.y >= blockpos.y and minp.z <= blockpos.z and maxp.z >= blockpos.z) then
minetest.set_node(blockpos, {name = "origin:origin"})
minetest.log("action", "[origin] The Origin has been set at "..minetest.pos_to_string(blockpos)..".")
origin.exists = true
local filepath = minetest.get_worldpath().."/origin.mt"
local file = io.open(filepath, "w")
if file then
file:write(minetest.pos_to_string(blockpos))
else
minetest.log("error", "[origin] Failed to write origin data into "..filepath..". The Origin may be placed again if you change static_spawnpoint.")
end
end
end
end)