Fixed initial node creation

Nodes that are encoded and then decoded in creative mode are now added
to the environment during a player join event. Previously they were
added before the environment had been initialized.
master
Austin Shenk 2013-01-04 20:55:15 -05:00
parent e3c5394818
commit 17db6429ee
5 changed files with 66 additions and 28 deletions

View File

@ -1,5 +1,25 @@
--Creative Mode
minetest.register_on_joinplayer(function(obj)
local file = io.open(minetest.get_worldpath().."/adventures_previousmode", "r")
if(file:read("*l") == adventures.normal) then
file:close()
local creative = minetest.setting_get("creative_mode")
local node = nil
local pos = nil
for _,data in ipairs(adventures.sourceData) do
node = data[1]
pos = {x=data[2],y=data[3],z=data[4]}
minetest.env:add_node({name=node}, pos)
end
file = io.open(minetest.get_worldpath().."/adventures_previousmode", "w")
file:write(adventures.creative)
file:close()
else
file:close()
end
end)
function adventures.snapPosition(meta, pos)
local newPos = {x=pos.x,y=pos.y,z=pos.z}
if(meta:get_int("width")%2 == 0) then
@ -56,12 +76,26 @@ minetest.register_node("adventures:invincible_source" ,{
on_construct = function(pos)
adventures.sources[pos] = minetest.env:get_node(pos).name
local meta = minetest.env:get_meta(pos)
meta:set_int("x", 0)
meta:set_int("y", 0)
meta:set_int("z", 0)
meta:set_int("width", 2)
meta:set_int("length", 2)
meta:set_int("height", 1)
local x = 0
local y = 0
local z = 0
local width = 2
local length = 2
local height = 1
if(adventures.sourceData[pos] ~= nil) then
x = data[5]
y = data[6]
z = data[7]
width = data[8]
length = data[9]
height = data[10]
end
meta:set_int("x", x)
meta:set_int("y", y)
meta:set_int("z", z)
meta:set_int("width", width)
meta:set_int("length", length)
meta:set_int("height", height)
meta:set_string("formspec", updateInvincibleSourceFormspec(meta))
local area = minetest.env:add_entity(pos, "adventures:invincible_area")
area:setpos(adventures.snapPosition(meta, pos))
@ -136,7 +170,7 @@ minetest.register_node("adventures:invincible_source" ,{
end,
})
minetest.register_chatcommand("saveAdventure", {
minetest.register_chatcommand("save", {
description = "saveAdventure : Save all node data to files",
func = function(name, param)
dofile(minetest.get_modpath("adventures").."/encode.lua")

View File

@ -1,6 +1,5 @@
local file = io.open(minetest.get_worldpath().."/adventures_sources", "r")
if(file ~= nil) then
local creative = minetest.setting_get("creative_mode")
local start = 1
for line in file:lines() do
local comma = line:find(",")
@ -13,24 +12,9 @@ if(file ~= nil) then
start = comma+1
comma = line:find(",", start)
end
local node = data[1]
local pos = {x=data[2],y=data[3],z=data[4]}
if(node == "adventures:invincible_source") then
if(creative) then
minetest.env:add_node({name=node}, pos)
local meta = minetest.env:get_meta(pos)
local area = adventures.findArea(meta, pos, {x=0,y=0,z=0})
meta:set_int("x", data[5])
meta:set_int("y", data[6])
meta:set_int("z", data[7])
meta:set_int("width", data[8])
meta:set_int("length", data[9])
meta:set_int("height", data[10])
area:set_properties({visual_size={x=data[8],y=data[10]}})
area:setpos(adventures.snapPosition(meta, pos))
else
end
local creative = minetest.setting_get("creative_mode")
if(creative) then
adventures.sourceData[{x=data[2],y=data[3],z=data[4]}] = data
end
end
end

View File

@ -1,10 +1,13 @@
--run Files
local init = io.open(minetest.get_worldpath().."/adventures_init", "w")
if(init == nil) then
init:write("init")
init:write("initialized")
init:close()
local file = io.open(minetest.get_worldpath().."/adventures_sources", "w")
file:write(" ")
file:write("initialized")
file:close()
local file = io.open(minetest.get_worldpath().."/adventures_previousmode", "w")
file:write("initialized")
file:close()
end

View File

@ -1 +1,15 @@
--Normal Mode
minetest.register_on_joinplayer(function(obj)
local file = io.open(minetest.get_worldpath().."/adventures_previousmode", "r")
if(file:read("*l") == adventures.creative) then
file:close()
local node = nil
local pos = nil
for _,data in ipairs(adventures.sourceData) do
pos = {x=data[2],y=data[3],z=data[4]}
node = minetest.env:get_node(pos)
end
else
file:close()
end
end)

View File

@ -1,5 +1,8 @@
adventures = {}
adventures.creative = "creative"
adventures.normal = "normal"
adventures.sources = {}
adventures.sourceData = {}
adventures.Unbreakable = {}
adventures.Unbuildable = {}
adventures.areas = {}