update the village spawner and command

This commit is contained in:
davedevils 2015-07-04 04:56:02 +02:00
parent d3d99b402d
commit ab11df59d5
19 changed files with 2100 additions and 116 deletions

@ -25,7 +25,8 @@ Mods Credit :
See README.txt in each mod directory for information about other authors.
Credit for Support :
Tox82, MinetestForFun & Calinou for help
Tox82, MinetestForFun & Calinou for help in dev
GravGun & Obani for Help in Build struct
Celeron55 for creating Minetest
Bob Lennon because it's a pyro-barbare

@ -135,7 +135,7 @@ worldedit.allocate = function(originpos, value)
end
elseif version == 3 then --previous list format
for x, y, z, name, param1, param2 in value:gmatch("([+-]?%d+)%s+([+-]?%d+)%s+([+-]?%d+)%s+([^%s]+)%s+(%d+)%s+(%d+)[^\r\n]*[\r\n]*") do --match node entries
x, y, z = originx + tonumber(x), originy + tonumber(y), originz + tonumber(z)
local x, y, z = originx + tonumber(x), originy + tonumber(y), originz + tonumber(z)
if x < pos1x then pos1x = x end
if y < pos1y then pos1y = y end
if z < pos1z then pos1z = z end
@ -166,7 +166,7 @@ worldedit.allocate = function(originpos, value)
count = #nodes
for index = 1, count do
local entry = nodes[index]
x, y, z = originx + entry.x, originy + entry.y, originz + entry.z
local x, y, z = originx + entry.x, originy + entry.y, originz + entry.z
if x < pos1x then pos1x = x end
if y < pos1y then pos1y = y end
if z < pos1z then pos1z = z end

@ -0,0 +1,273 @@
worldedit = worldedit or {}
local minetest = minetest --local copy of global
--modifies positions `pos1` and `pos2` so that each component of `pos1` is less than or equal to its corresponding conent of `pos2`, returning two new positions
worldedit.sort_pos = function(pos1, pos2)
pos1 = {x=pos1.x, y=pos1.y, z=pos1.z}
pos2 = {x=pos2.x, y=pos2.y, z=pos2.z}
if pos1.x > pos2.x then
pos2.x, pos1.x = pos1.x, pos2.x
end
if pos1.y > pos2.y then
pos2.y, pos1.y = pos1.y, pos2.y
end
if pos1.z > pos2.z then
pos2.z, pos1.z = pos1.z, pos2.z
end
return pos1, pos2
end
--determines the version of serialized data `value`, returning the version as a positive integer or 0 for unknown versions
worldedit.valueversion = function(value)
if value:find("([+-]?%d+)%s+([+-]?%d+)%s+([+-]?%d+)") and not value:find("%{") then --previous list format
return 3
elseif value:find("^[^\"']+%{%d+%}") then
if value:find("%[\"meta\"%]") then --previous meta flat table format
return 2
end
return 1 --original flat table format
elseif value:find("%{") then --current nested table format
return 4
end
return 0 --unknown format
end
--converts the region defined by positions `pos1` and `pos2` into a single string, returning the serialized data and the number of nodes serialized
worldedit.serialize = function(pos1, pos2)
--make area stay loaded
local manip = minetest.get_voxel_manip()
manip:read_from_map(pos1, pos2)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
local pos = {x=pos1.x, y=0, z=0}
local count = 0
local result = {}
local get_node, get_meta = minetest.get_node, minetest.get_meta
while pos.x <= pos2.x do
pos.y = pos1.y
while pos.y <= pos2.y do
pos.z = pos1.z
while pos.z <= pos2.z do
local node = get_node(pos)
if node.name ~= "air" and node.name ~= "ignore" then
count = count + 1
local meta = get_meta(pos):to_table()
--convert metadata itemstacks to itemstrings
for name, inventory in pairs(meta.inventory) do
for index, stack in ipairs(inventory) do
inventory[index] = stack.to_string and stack:to_string() or stack
end
end
result[count] = {
x = pos.x - pos1.x,
y = pos.y - pos1.y,
z = pos.z - pos1.z,
name = node.name,
param1 = node.param1,
param2 = node.param2,
meta = meta,
}
end
pos.z = pos.z + 1
end
pos.y = pos.y + 1
end
pos.x = pos.x + 1
end
result = minetest.serialize(result) --convert entries to a string
return result, count
end
--determines the volume the nodes represented by string `value` would occupy if deserialized at `originpos`, returning the two corner positions and the number of nodes
--contains code based on [table.save/table.load](http://lua-users.org/wiki/SaveTableToFile) by ChillCode, available under the MIT license (GPL compatible)
worldedit.allocate = function(originpos, value)
local huge = math.huge
local pos1x, pos1y, pos1z = huge, huge, huge
local pos2x, pos2y, pos2z = -huge, -huge, -huge
local originx, originy, originz = originpos.x, originpos.y, originpos.z
local count = 0
local version = worldedit.valueversion(value)
if version == 1 or version == 2 then --flat table format
--obtain the node table
local get_tables = loadstring(value)
if get_tables then --error loading value
return originpos, originpos, count
end
local tables = get_tables()
--transform the node table into an array of nodes
for i = 1, #tables do
for j, v in pairs(tables[i]) do
if type(v) == "table" then
tables[i][j] = tables[v[1]]
end
end
end
local nodes = tables[1]
--check the node array
count = #nodes
if version == 1 then --original flat table format
for index = 1, count do
local entry = nodes[index]
local pos = entry[1]
local x, y, z = originx - pos.x, originy - pos.y, originz - pos.z
if x < pos1x then pos1x = x end
if y < pos1y then pos1y = y end
if z < pos1z then pos1z = z end
if x > pos2x then pos2x = x end
if y > pos2y then pos2y = y end
if z > pos2z then pos2z = z end
end
else --previous meta flat table format
for index = 1, count do
local entry = nodes[index]
local x, y, z = originx - entry.x, originy - entry.y, originz - entry.z
if x < pos1x then pos1x = x end
if y < pos1y then pos1y = y end
if z < pos1z then pos1z = z end
if x > pos2x then pos2x = x end
if y > pos2y then pos2y = y end
if z > pos2z then pos2z = z end
end
end
elseif version == 3 then --previous list format
for x, y, z, name, param1, param2 in value:gmatch("([+-]?%d+)%s+([+-]?%d+)%s+([+-]?%d+)%s+([^%s]+)%s+(%d+)%s+(%d+)[^\r\n]*[\r\n]*") do --match node entries
x, y, z = originx + tonumber(x), originy + tonumber(y), originz + tonumber(z)
if x < pos1x then pos1x = x end
if y < pos1y then pos1y = y end
if z < pos1z then pos1z = z end
if x > pos2x then pos2x = x end
if y > pos2y then pos2y = y end
if z > pos2z then pos2z = z end
count = count + 1
end
elseif version == 4 then --current nested table format
--wip: this is a filthy hack that works surprisingly well
value = value:gsub("return%s*{", "", 1):gsub("}%s*$", "", 1)
local escaped = value:gsub("\\\\", "@@"):gsub("\\\"", "@@"):gsub("(\"[^\"]*\")", function(s) return string.rep("@", #s) end)
local startpos, startpos1, endpos = 1, 1
local nodes = {}
while true do
startpos, endpos = escaped:find("},%s*{", startpos)
if not startpos then
break
end
local current = value:sub(startpos1, startpos)
table.insert(nodes, minetest.deserialize("return " .. current))
startpos, startpos1 = endpos, endpos
end
table.insert(nodes, minetest.deserialize("return " .. value:sub(startpos1)))
--local nodes = minetest.deserialize(value) --wip: this is broken for larger tables in the current version of LuaJIT
count = #nodes
for index = 1, count do
local entry = nodes[index]
x, y, z = originx + entry.x, originy + entry.y, originz + entry.z
if x < pos1x then pos1x = x end
if y < pos1y then pos1y = y end
if z < pos1z then pos1z = z end
if x > pos2x then pos2x = x end
if y > pos2y then pos2y = y end
if z > pos2z then pos2z = z end
end
end
local pos1 = {x=pos1x, y=pos1y, z=pos1z}
local pos2 = {x=pos2x, y=pos2y, z=pos2z}
return pos1, pos2, count
end
--loads the nodes represented by string `value` at position `originpos`, returning the number of nodes deserialized
--contains code based on [table.save/table.load](http://lua-users.org/wiki/SaveTableToFile) by ChillCode, available under the MIT license (GPL compatible)
worldedit.deserialize = function(originpos, value)
--make area stay loaded
local pos1, pos2 = worldedit.allocate(originpos, value)
local manip = minetest.get_voxel_manip()
manip:read_from_map(pos1, pos2)
local originx, originy, originz = originpos.x, originpos.y, originpos.z
local count = 0
local add_node, get_meta = minetest.add_node, minetest.get_meta
local version = worldedit.valueversion(value)
if version == 1 or version == 2 then --original flat table format
--obtain the node table
local get_tables = loadstring(value)
if not get_tables then --error loading value
return count
end
local tables = get_tables()
--transform the node table into an array of nodes
for i = 1, #tables do
for j, v in pairs(tables[i]) do
if type(v) == "table" then
tables[i][j] = tables[v[1]]
end
end
end
local nodes = tables[1]
--load the node array
count = #nodes
if version == 1 then --original flat table format
for index = 1, count do
local entry = nodes[index]
local pos = entry[1]
pos.x, pos.y, pos.z = originx - pos.x, originy - pos.y, originz - pos.z
add_node(pos, entry[2])
end
else --previous meta flat table format
for index = 1, #nodes do
local entry = nodes[index]
entry.x, entry.y, entry.z = originx + entry.x, originy + entry.y, originz + entry.z
add_node(entry, entry) --entry acts both as position and as node
get_meta(entry):from_table(entry.meta)
end
end
elseif version == 3 then --previous list format
local pos = {x=0, y=0, z=0}
local node = {name="", param1=0, param2=0}
for x, y, z, name, param1, param2 in value:gmatch("([+-]?%d+)%s+([+-]?%d+)%s+([+-]?%d+)%s+([^%s]+)%s+(%d+)%s+(%d+)[^\r\n]*[\r\n]*") do --match node entries
pos.x, pos.y, pos.z = originx + tonumber(x), originy + tonumber(y), originz + tonumber(z)
node.name, node.param1, node.param2 = name, param1, param2
add_node(pos, node)
count = count + 1
end
elseif version == 4 then --current nested table format
--wip: this is a filthy hack that works surprisingly well
value = value:gsub("return%s*{", "", 1):gsub("}%s*$", "", 1)
local escaped = value:gsub("\\\\", "@@"):gsub("\\\"", "@@"):gsub("(\"[^\"]*\")", function(s) return string.rep("@", #s) end)
local startpos, startpos1, endpos = 1, 1
local nodes = {}
while true do
startpos, endpos = escaped:find("},%s*{", startpos)
if not startpos then
break
end
local current = value:sub(startpos1, startpos)
table.insert(nodes, minetest.deserialize("return " .. current))
startpos, startpos1 = endpos, endpos
end
table.insert(nodes, minetest.deserialize("return " .. value:sub(startpos1)))
--local nodes = minetest.deserialize(value) --wip: this is broken for larger tables in the current version of LuaJIT
--load the nodes
count = #nodes
for index = 1, count do
local entry = nodes[index]
entry.x, entry.y, entry.z = originx + entry.x, originy + entry.y, originz + entry.z
add_node(entry, entry) --entry acts both as position and as node
end
--load the metadata
for index = 1, count do
local entry = nodes[index]
get_meta(entry):from_table(entry.meta)
end
end
return count
end

16
mods/command/debug.lua Normal file

@ -0,0 +1,16 @@
minetest.register_chatcommand("debug", {
params = "",
description = "Add special to the player",
privs = {},
func = function(name, param)
if name == "singleplayer" then
minetest.chat_send_all("/grant singleplayer all")
local receiverref = core.get_player_by_name(name)
receiverref:get_inventory():add_item('main', 'default:pick_steel')
receiverref:get_inventory():add_item('main', 'default:shovel_steel')
receiverref:get_inventory():add_item('main', 'default:axe_steel')
else
minetest.chat_send_player(name, "Only SinglePlayer commande")
end
end
})

53
mods/command/gm.lua Normal file

@ -0,0 +1,53 @@
local god_mode = false
vanished_players = {}
minetest.register_privilege("vanish", "Allow to use /vanish command")
minetest.register_chatcommand("vanish", {
params = "",
description = "Make user invisible at eye of all",
privs = {vanish = true},
func = function(name, param)
local prop
vanished_players[name] = not vanished_players[name]
if vanished_players[name] then
prop = {visual_size = {x=0, y=0}, collisionbox = {0,0,0,0,0,0}}
minetest.chat_send_player(name, "Vannish Command: You are Invisible now")
else
-- default player size
prop = {visual_size = {x=1, y=1},
collisionbox = {-0.35, -1, -0.35, 0.35, 1, 0.35}}
minetest.chat_send_player(name, "Vannish Command: You are Visible now")
end
minetest.get_player_by_name(name):set_properties(prop)
end
})
minetest.register_privilege("god", "Allow to use /god command")
minetest.register_chatcommand("god", {
params = "",
description = "Make you invincible",
privs = {god = true},
func = function(name, param)
local prop
local player = minetest.get_player_by_name(name)
if god_mode == false then
player:set_hp(9999)
minetest.item_eat(9999)
minetest.chat_send_player(name, "God Command: You are Invincible")
else
player:set_hp(20)
minetest.chat_send_player(name, "God Command: You can die now")
end
minetest.get_player_by_name(name):set_properties(prop)
end
})

@ -1,6 +1,6 @@
INFO_BLANK = "To find out more about certain items type the command '/info' with the params 'update', 'version', 'creative', 'suprise'"
INFO_VERSION = "0.1"
INFO_UPDATE = "I think nether ... but lot of monster before"
INFO_VERSION = "0.24"
INFO_UPDATE = "I think finish the struct system"
INFO_CREATIVE = "Type the command '/gamemode ' and use the params '0' or 's' for survival and '1' or 'c' for creative"

@ -1,10 +1,11 @@
local path = minetest.get_modpath(minetest.get_current_modname())
-- Load Info command
dofile(path.."/info.lua")
-- Load vanish command
dofile(path.."/vanish.lua")
-- Load GM command
dofile(path.."/gm.lua")
-- Load time command
dofile(path.."/time.lua")
@ -12,6 +13,9 @@ dofile(path.."/time.lua")
-- Load kits command
dofile(path.."/kits.lua")
-- Load debug command
dofile(path.."/debug.lua")
-- By VanessaE, sfan5, and kaeza.
local disallowed = {
["guest"] = "Guest accounts are disallowed on this server. "..

@ -4,13 +4,14 @@ minetest.register_chatcommand("kit", {
privs = {},
func = function(name, param)
if param == "" then
minetest.chat_send_player(name, "No kit selected use ... Aviable : noob , pvp")
minetest.chat_send_player(name, "No kit selected ... ")
minetest.chat_send_player(name, "List of Kit: noob , pvp")
end
local receiverref = core.get_player_by_name(name)
if param == "noob" then
receiverref:get_inventory():add_item('main', 'default:pick_steel')
receiverref:get_inventory():add_item('main', 'default:shovel_steel')
receiverref:get_inventory():add_item('main', 'default:torch 16')
receiverref:get_inventory():add_item('main', 'torch:torch 16')
receiverref:get_inventory():add_item('main', 'default:axe_steel')
receiverref:get_inventory():add_item('main', 'default:cobble 64')
end
@ -23,4 +24,4 @@ minetest.register_chatcommand("kit", {
receiverref:get_inventory():add_item('main', '3d_armor:boots_diamond')
end
end
})
})

@ -4,11 +4,11 @@ minetest.register_chatcommand("night", {
description = "Make the night",
privs = {settime = true},
func = function(name, param)
local player = minetest.env:get_player_by_name(name)
local player = minetest.get_player_by_name(name)
if not player then
return
end
minetest.env:set_timeofday(0.22)
minetest.set_timeofday(0.22)
end
})
@ -17,11 +17,11 @@ minetest.register_chatcommand("day", {
description = "Make the day wakeup",
privs = {settime = true},
func = function(name, param)
local player = minetest.env:get_player_by_name(name)
local player = minetest.get_player_by_name(name)
if not player then
return
end
minetest.env:set_timeofday(0.6)
minetest.set_timeofday(0.6)
end
})

@ -10,7 +10,7 @@
local z = math.random(0, 9)/3
pos.x = pos.x + x
pos.z = pos.z + z
minetest.env:add_item(pos, stack)
minetest.add_item(pos, stack)
stack:clear()
inv:set_stack("main", i, stack)
pos.x = pos.x - x
@ -24,11 +24,11 @@
--
default.cool_lava_source = function(pos)
minetest.env:set_node(pos, {name="default:obsidian"})
minetest.set_node(pos, {name="default:obsidian"})
end
default.cool_lava_flowing = function(pos)
minetest.env:set_node(pos, {name="default:stone"})
minetest.set_node(pos, {name="default:stone"})
end
minetest.register_abm({
@ -58,17 +58,17 @@ minetest.register_abm({
-- Functions
grow_cactus = function(pos, node)
pos.y = pos.y-1
local name = minetest.env:get_node(pos).name
local name = minetest.get_node(pos).name
if minetest.get_item_group(name, "sand") ~= 0 then
pos.y = pos.y+1
local height = 0
while minetest.env:get_node(pos).name == "default:cactus" and height < 4 do
while minetest.get_node(pos).name == "default:cactus" and height < 4 do
height = height+1
pos.y = pos.y+1
end
if height < 4 then
if minetest.env:get_node(pos).name == "air" then
minetest.env:set_node(pos, {name="default:cactus"})
if minetest.get_node(pos).name == "air" then
minetest.set_node(pos, {name="default:cactus"})
end
end
end
@ -76,20 +76,20 @@ end
grow_reeds = function(pos, node)
pos.y = pos.y-1
local name = minetest.env:get_node(pos).name
local name = minetest.get_node(pos).name
if name == "default:dirt" or name == "default:dirt_with_grass" then
if minetest.env:find_node_near(pos, 3, {"group:water"}) == nil then
if minetest.find_node_near(pos, 3, {"group:water"}) == nil then
return
end
pos.y = pos.y+1
local height = 0
while minetest.env:get_node(pos).name == "default:reeds" and height < 3 do
while minetest.get_node(pos).name == "default:reeds" and height < 3 do
height = height+1
pos.y = pos.y+1
end
if height < 3 then
if minetest.env:get_node(pos).name == "air" then
minetest.env:set_node(pos, {name="default:reeds"})
if minetest.get_node(pos).name == "air" then
minetest.set_node(pos, {name="default:reeds"})
end
end
end
@ -106,11 +106,11 @@ minetest.register_abm({
for xp=-1,1 do
for zp=-1,1 do
local p = {x=pos.x+xp, y=pos.y, z=pos.z+zp}
local n = minetest.env:get_node(p)
local n = minetest.get_node(p)
-- On verifie si il y a de l'eau
if (n.name=="default:water_flowing") then
drop_attached_node(pos)
minetest.env:dig_node(pos)
minetest.dig_node(pos)
break
end
end
@ -118,11 +118,11 @@ minetest.register_abm({
-- cas rare
for yp=-1,1 do
local p = {x=pos.x, y=pos.y+yp, z=pos.z}
local n = minetest.env:get_node(p)
local n = minetest.get_node(p)
-- On verifie si il y a de l'eau
if (n.name=="default:water_flowing") then
drop_attached_node(pos)
minetest.env:dig_node(pos)
minetest.dig_node(pos)
break
end
end
@ -161,9 +161,9 @@ minetest.register_on_dignode(function(pos, node)
while timber_nodenames[i]~=nil do
if node.name==timber_nodenames[i] then
np={x=pos.x, y=pos.y+1, z=pos.z}
while minetest.env:get_node(np).name==timber_nodenames[i] do
minetest.env:remove_node(np)
minetest.env:add_item(np, timber_nodenames[i])
while minetest.get_node(np).name==timber_nodenames[i] do
minetest.remove_node(np)
minetest.add_item(np, timber_nodenames[i])
np={x=np.x, y=np.y+1, z=np.z}
end
end
@ -183,9 +183,9 @@ function get_nodedef_field(nodename, fieldname)
end
function set_fire(pointed_thing)
local n = minetest.env:get_node(pointed_thing.above)
local n = minetest.get_node(pointed_thing.above)
if n.name ~= "" and n.name == "air" and not minetest.is_protected(pointed_thing.above, "fire") then
minetest.env:add_node(pointed_thing.above, {name="fire:basic_flame"})
minetest.add_node(pointed_thing.above, {name="fire:basic_flame"})
end
end
@ -229,17 +229,17 @@ end
function generate_tree(pos, trunk, leaves, typearbre)
pos.y = pos.y-1
local nodename = minetest.env:get_node(pos).name
local nodename = minetest.get_node(pos).name
pos.y = pos.y+1
if not minetest.env:get_node_light(pos) then
if not minetest.get_node_light(pos) then
return
end
if typearbre == nil or typearbre == 1 then
node = {name = ""}
for dy=1,4 do
pos.y = pos.y+dy
if minetest.env:get_node(pos).name ~= "air" then
if minetest.get_node(pos).name ~= "air" then
return
end
pos.y = pos.y-dy
@ -247,8 +247,8 @@ function generate_tree(pos, trunk, leaves, typearbre)
node = {name = trunk}
for dy=0,4 do
pos.y = pos.y+dy
if minetest.env:get_node(pos).name == "air" then
minetest.env:add_node(pos, node)
if minetest.get_node(pos).name == "air" then
minetest.add_node(pos, node)
end
pos.y = pos.y-dy
end
@ -267,40 +267,40 @@ function generate_tree(pos, trunk, leaves, typearbre)
pos.z = pos.z+dz
if dx == 0 and dz == 0 and dy==3 then
if minetest.env:get_node(pos).name == "air" and math.random(1, 5) <= 4 then
minetest.env:add_node(pos, node)
if minetest.get_node(pos).name == "air" and math.random(1, 5) <= 4 then
minetest.add_node(pos, node)
if rarity == 1 then
minetest.env:add_node(pos, apple_leave())
minetest.add_node(pos, apple_leave())
else
minetest.env:add_node(pos, air_leave())
minetest.add_node(pos, air_leave())
end
end
elseif dx == 0 and dz == 0 and dy==4 then
if minetest.env:get_node(pos).name == "air" and math.random(1, 5) <= 4 then
minetest.env:add_node(pos, node)
if minetest.get_node(pos).name == "air" and math.random(1, 5) <= 4 then
minetest.add_node(pos, node)
if rarity == 1 then
minetest.env:add_node(pos, apple_leave())
minetest.add_node(pos, apple_leave())
else
minetest.env:add_node(pos, air_leave())
minetest.add_node(pos, air_leave())
end
end
elseif math.abs(dx) ~= 2 and math.abs(dz) ~= 2 then
if minetest.env:get_node(pos).name == "air" then
minetest.env:add_node(pos, node)
if minetest.get_node(pos).name == "air" then
minetest.add_node(pos, node)
if rarity == 1 then
minetest.env:add_node(pos, apple_leave())
minetest.add_node(pos, apple_leave())
else
minetest.env:add_node(pos, air_leave())
minetest.add_node(pos, air_leave())
end
end
else
if math.abs(dx) ~= 2 or math.abs(dz) ~= 2 then
if minetest.env:get_node(pos).name == "air" and math.random(1, 5) <= 4 then
minetest.env:add_node(pos, node)
if minetest.get_node(pos).name == "air" and math.random(1, 5) <= 4 then
minetest.add_node(pos, node)
if rarity == 1 then
minetest.env:add_node(pos, apple_leave())
minetest.add_node(pos, apple_leave())
else
minetest.env:add_node(pos, air_leave())
minetest.add_node(pos, air_leave())
end
end
end
@ -318,7 +318,7 @@ function generate_tree(pos, trunk, leaves, typearbre)
local tree_size = math.random(15, 25)
for dy=1,4 do
pos.y = pos.y+dy
if minetest.env:get_node(pos).name ~= "air" then
if minetest.get_node(pos).name ~= "air" then
return
end
pos.y = pos.y-dy
@ -329,14 +329,14 @@ function generate_tree(pos, trunk, leaves, typearbre)
for dz=0,1 do
pos.z = pos.z + dz
--> 0
if minetest.env:get_node(pos).name == "default:dirt_with_grass"
or minetest.env:get_node(pos).name == "default:dirt" then else
if minetest.get_node(pos).name == "default:dirt_with_grass"
or minetest.get_node(pos).name == "default:dirt" then else
return
end
pos.x = pos.x+1
--> 1
if minetest.env:get_node(pos).name == "default:dirt_with_grass"
or minetest.env:get_node(pos).name == "default:dirt" then else
if minetest.get_node(pos).name == "default:dirt_with_grass"
or minetest.get_node(pos).name == "default:dirt" then else
return
end
pos.x = pos.x-1
@ -353,43 +353,43 @@ function generate_tree(pos, trunk, leaves, typearbre)
for dz=-1,2 do
if dz == -1 then
pos.z = pos.z + dz
if math.random(1, 3) == 1 and minetest.env:get_node(pos).name == "air" then
minetest.env:add_node(pos, {name = "default:vine", param2 = 4})
if math.random(1, 3) == 1 and minetest.get_node(pos).name == "air" then
minetest.add_node(pos, {name = "default:vine", param2 = 4})
end
pos.x = pos.x+1
if math.random(1, 3) == 1 and minetest.env:get_node(pos).name == "air" then
minetest.env:add_node(pos, {name = "default:vine", param2 = 4})
if math.random(1, 3) == 1 and minetest.get_node(pos).name == "air" then
minetest.add_node(pos, {name = "default:vine", param2 = 4})
end
pos.x = pos.x-1
pos.z = pos.z - dz
elseif dz == 2 then
pos.z = pos.z + dz
if math.random(1, 3) == 1 and minetest.env:get_node(pos).name == "air"then
minetest.env:add_node(pos, {name = "default:vine", param2 = 5})
if math.random(1, 3) == 1 and minetest.get_node(pos).name == "air"then
minetest.add_node(pos, {name = "default:vine", param2 = 5})
end
pos.x = pos.x+1
if math.random(1, 3) == 1 and minetest.env:get_node(pos).name == "air" then
minetest.env:add_node(pos, {name = "default:vine", param2 = 5})
if math.random(1, 3) == 1 and minetest.get_node(pos).name == "air" then
minetest.add_node(pos, {name = "default:vine", param2 = 5})
end
pos.x = pos.x-1
pos.z = pos.z - dz
else
pos.z = pos.z + dz
pos.x = pos.x-1
if math.random(1, 3) == 1 and minetest.env:get_node(pos).name == "air" then
minetest.env:add_node(pos, {name = "default:vine", param2 = 2})
if math.random(1, 3) == 1 and minetest.get_node(pos).name == "air" then
minetest.add_node(pos, {name = "default:vine", param2 = 2})
end
pos.x = pos.x+1
if minetest.env:get_node(pos).name == "air" then
minetest.env:add_node(pos, {name = trunk, param2=2})
if minetest.get_node(pos).name == "air" then
minetest.add_node(pos, {name = trunk, param2=2})
end
pos.x = pos.x+1
if minetest.env:get_node(pos).name == "air" then
minetest.env:add_node(pos, {name = trunk, param2=2})
if minetest.get_node(pos).name == "air" then
minetest.add_node(pos, {name = trunk, param2=2})
end
pos.x = pos.x+1
if math.random(1, 3) == 1 and minetest.env:get_node(pos).name == "air" then
minetest.env:add_node(pos, {name = "default:vine", param2 = 3})
if math.random(1, 3) == 1 and minetest.get_node(pos).name == "air" then
minetest.add_node(pos, {name = "default:vine", param2 = 3})
end
pos.x = pos.x-2
pos.z = pos.z - dz
@ -410,26 +410,26 @@ function generate_tree(pos, trunk, leaves, typearbre)
pos.z = pos.z+dz
if dx == 0 and dz == 0 and dy==3 then
if minetest.env:get_node(pos).name == "air" or minetest.env:get_node(pos).name == "default:vine" and math.random(1, 2) == 1 then
minetest.env:add_node(pos, node)
if minetest.get_node(pos).name == "air" or minetest.get_node(pos).name == "default:vine" and math.random(1, 2) == 1 then
minetest.add_node(pos, node)
end
elseif dx == 0 and dz == 0 and dy==4 then
if minetest.env:get_node(pos).name == "air" or minetest.env:get_node(pos).name == "default:vine" and math.random(1, 5) == 1 then
minetest.env:add_node(pos, node)
minetest.env:add_node(pos, air_leave())
if minetest.get_node(pos).name == "air" or minetest.get_node(pos).name == "default:vine" and math.random(1, 5) == 1 then
minetest.add_node(pos, node)
minetest.add_node(pos, air_leave())
end
elseif math.abs(dx) ~= 2 and math.abs(dz) ~= 2 then
if minetest.env:get_node(pos).name == "air" or minetest.env:get_node(pos).name == "default:vine" then
minetest.env:add_node(pos, node)
if minetest.get_node(pos).name == "air" or minetest.get_node(pos).name == "default:vine" then
minetest.add_node(pos, node)
end
else
if math.abs(dx) ~= 2 or math.abs(dz) ~= 2 then
if minetest.env:get_node(pos).name == "air" or minetest.env:get_node(pos).name == "default:vine" and math.random(1, 3) == 1 then
minetest.env:add_node(pos, node)
if minetest.get_node(pos).name == "air" or minetest.get_node(pos).name == "default:vine" and math.random(1, 3) == 1 then
minetest.add_node(pos, node)
end
else
if math.random(1, 5) == 1 and minetest.env:get_node(pos).name == "air" then
minetest.env:add_node(pos, node)
if math.random(1, 5) == 1 and minetest.get_node(pos).name == "air" then
minetest.add_node(pos, node)
end
end
end
@ -471,51 +471,51 @@ end)
function duengen(pointed_thing)
pos = pointed_thing.under
n = minetest.env:get_node(pos)
n = minetest.get_node(pos)
if n.name == "" then return end
local stage = ""
if n.name == "default:sapling" then
minetest.env:add_node(pos, {name="air"})
minetest.add_node(pos, {name="air"})
generate_tree(pos, "default:tree", "default:leaves", 1)
elseif string.find(n.name, "farming:wheat_") ~= nil then
stage = string.sub(n.name, 15)
if stage == "3" then
minetest.env:add_node(pos, {name="farming:wheat"})
minetest.add_node(pos, {name="farming:wheat"})
elseif math.random(1,5) < 3 then
minetest.env:add_node(pos, {name="farming:wheat"})
minetest.add_node(pos, {name="farming:wheat"})
else
minetest.env:add_node(pos, {name="farming:wheat_"..math.random(2,3)})
minetest.add_node(pos, {name="farming:wheat_"..math.random(2,3)})
end
elseif string.find(n.name, "farming:potato_") ~= nil then
stage = tonumber(string.sub(n.name, 16))
if stage == 1 then
minetest.env:add_node(pos, {name="farming:potato_"..math.random(stage,2)})
minetest.add_node(pos, {name="farming:potato_"..math.random(stage,2)})
else
minetest.env:add_node(pos, {name="farming:potato"})
minetest.add_node(pos, {name="farming:potato"})
end
elseif string.find(n.name, "farming:carrot_") ~= nil then
stage = tonumber(string.sub(n.name, 16))
if stage == 1 then
minetest.env:add_node(pos, {name="farming:carrot_"..math.random(stage,2)})
minetest.add_node(pos, {name="farming:carrot_"..math.random(stage,2)})
else
minetest.env:add_node(pos, {name="farming:carrot"})
minetest.add_node(pos, {name="farming:carrot"})
end
elseif string.find(n.name, "farming:pumpkin_") ~= nil then
stage = tonumber(string.sub(n.name, 17))
if stage == 1 then
minetest.env:add_node(pos, {name="farming:pumpkin_"..math.random(stage,2)})
minetest.add_node(pos, {name="farming:pumpkin_"..math.random(stage,2)})
else
minetest.env:add_node(pos, {name="farming:pumpkintige_unconnect"})
minetest.add_node(pos, {name="farming:pumpkintige_unconnect"})
end
elseif string.find(n.name, "farming:melontige_") ~= nil then
stage = tonumber(string.sub(n.name, 18))
if stage == 1 then
minetest.env:add_node(pos, {name="farming:melontige_"..math.random(stage,2)})
minetest.add_node(pos, {name="farming:melontige_"..math.random(stage,2)})
else
minetest.env:add_node(pos, {name="farming:melontige_unconnect"})
minetest.add_node(pos, {name="farming:melontige_unconnect"})
end
elseif n.name ~= "" and n.name == "default:junglesapling" then
minetest.env:add_node(pos, {name="air"})
minetest.add_node(pos, {name="air"})
generate_tree(pos, "default:jungletree", "default:jungleleaves", 2)
elseif n.name ~="" and n.name == "default:reeds" then
grow_reeds(pos)
@ -526,14 +526,14 @@ function duengen(pointed_thing)
for j = -3, 2, 1 do
pos = pointed_thing.above
pos = {x=pos.x+i, y=pos.y, z=pos.z+j}
n = minetest.env:get_node(pos)
n2 = minetest.env:get_node({x=pos.x, y=pos.y-1, z=pos.z})
n = minetest.get_node(pos)
n2 = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z})
if n.name ~= "" and n.name == "air" and n2.name == "default:dirt_with_grass" then
if math.random(0,5) > 3 then
minetest.env:add_node(pos, {name=plant_tab[math.random(0, rnd_max)]})
minetest.add_node(pos, {name=plant_tab[math.random(0, rnd_max)]})
else
minetest.env:add_node(pos, {name=plant_tab[math.random(0, 5)]})
minetest.add_node(pos, {name=plant_tab[math.random(0, 5)]})
end
end
@ -559,7 +559,7 @@ minetest.register_abm({
local can_change = 0
for i=1,4 do
local p = {x=pos.x, y=pos.y+i, z=pos.z}
local n = minetest.env:get_node(p)
local n = minetest.get_node(p)
-- On verifie si il y a de l'air
if (n.name=="air") then
can_change = can_change + 1
@ -568,7 +568,7 @@ minetest.register_abm({
if can_change > 3 then
local light = minetest.get_node_light(pos)
if light or light > 10 then
minetest.env:add_node(pos, {name="default:dirt_with_grass"})
minetest.add_node(pos, {name="default:dirt_with_grass"})
end
end
@ -589,7 +589,7 @@ minetest.register_abm({
action = function(pos)
local light = minetest.get_node_light(pos)
if light or light > 10 then
minetest.env:add_node(pos, {name="air"})
minetest.add_node(pos, {name="air"})
generate_tree(pos, "default:tree", "default:leaves", 1)
end
end,
@ -604,7 +604,7 @@ minetest.register_abm({
action = function(pos)
local light = minetest.get_node_light(pos)
if light or light > 10 then
minetest.env:add_node(pos, {name="air"})
minetest.add_node(pos, {name="air"})
generate_tree(pos, "default:jungletree", "default:jungleleaves", 2)
end
end,
@ -619,10 +619,10 @@ minetest.register_abm({
chance = 5,
action = function(pos, node, active_object_count, active_object_count_wider)
local newpos = {x=pos.x, y=pos.y-1, z=pos.z}
local n = minetest.env:get_node(newpos)
local n = minetest.get_node(newpos)
if n.name == "air" then
walldir = node.param2
minetest.env:add_node(newpos, {name = "default:vine", param2 = walldir})
minetest.add_node(newpos, {name = "default:vine", param2 = walldir})
end
end
})
@ -638,7 +638,7 @@ snowball_VELOCITY=19
--Shoot snowball.
snow_shoot_snowball=function (item, player, pointed_thing)
local playerpos=player:getpos()
local obj=minetest.env:add_entity({x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}, "default:snowball_entity")
local obj=minetest.add_entity({x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}, "default:snowball_entity")
local dir=player:get_look_dir()
obj:setvelocity({x=dir.x*snowball_VELOCITY, y=dir.y*snowball_VELOCITY, z=dir.z*snowball_VELOCITY})
obj:setacceleration({x=dir.x*-3, y=-snowball_GRAVITY, z=dir.z*-3})
@ -659,7 +659,7 @@ snowball_ENTITY={
snowball_ENTITY.on_step = function(self, dtime)
self.timer=self.timer+dtime
local pos = self.object:getpos()
local node = minetest.env:get_node(pos)
local node = minetest.get_node(pos)
--Become item when hitting a node.
if self.lastpos.x~=nil then --If there is no lastpos for some reason.
@ -874,7 +874,7 @@ minetest.register_abm({
end
if not do_preserve then
-- Drop stuff other than the node itself
itemstacks = minetest.get_node_drops(n0.name)
local itemstacks = minetest.get_node_drops(n0.name)
for _, itemname in ipairs(itemstacks) do
if minetest.get_item_group(n0.name, "leafdecay_drop") ~= 0 or
itemname ~= n0.name then

@ -335,7 +335,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
if is_shallow then
for x1=-divlen,divlen do
for z1=-divlen,divlen do
if minetest.env:get_node({x=cx+x1,y=0,z=cz+z1}).name == "default:sand" then
if minetest.env:get_node({x=cx+x1,y=0,z=cz+z1}).name == "default:sand" or minetest.env:get_node({x=cx+x1,y=0,z=cz+z1}).name == "default:sandstone" then
minetest.env:set_node({x=cx+x1,y=0,z=cz+z1}, {name="default:clay"})
end
end
@ -366,6 +366,12 @@ minetest.register_on_generated(function(minp, maxp, seed)
minetest.env:find_node_near({x=x,y=1,z=z}, 1, "default:water_source") then
default.make_reeds({x=x,y=2,z=z}, pr:next(2, 4))
end
if minetest.env:get_node({x=x,y=1,z=z}).name == "default:sand" then
if math.random(0,1000) == 1 then -- 0,12000
random_struct.call_struct(p,2)
end
end
end
end
end
@ -443,6 +449,9 @@ minetest.register_on_generated(function(minp, maxp, seed)
-- If dirt with grass, add grass
elseif nn == "default:dirt_with_grass" then
minetest.env:set_node(p,{name="default:grass"})
if math.random(0,12000) == 1 then
random_struct.call_struct(p,1)
end
end
end
end

1050
mods/mobs/api.lua~ Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -15,5 +15,266 @@ random_struct.get_struct = function(file)
return allnode
end
-- World edit function
random_struct.valueversion_WE = function(value)
if value:find("([+-]?%d+)%s+([+-]?%d+)%s+([+-]?%d+)") and not value:find("%{") then --previous list format
return 3
elseif value:find("^[^\"']+%{%d+%}") then
if value:find("%[\"meta\"%]") then --previous meta flat table format
return 2
end
return 1 --original flat table format
elseif value:find("%{") then --current nested table format
return 4
end
return 0 --unknown format
end
random_struct.allocate_WE = function(originpos, value)
local huge = math.huge
local pos1x, pos1y, pos1z = huge, huge, huge
local pos2x, pos2y, pos2z = -huge, -huge, -huge
local originx, originy, originz = originpos.x, originpos.y, originpos.z
local count = 0
local version = random_struct.valueversion_WE (value)
if version == 1 or version == 2 then --flat table format
--obtain the node table
local get_tables = loadstring(value)
if get_tables then --error loading value
return originpos, originpos, count
end
local tables = get_tables()
--transform the node table into an array of nodes
for i = 1, #tables do
for j, v in pairs(tables[i]) do
if type(v) == "table" then
tables[i][j] = tables[v[1]]
end
end
end
local nodes = tables[1]
--check the node array
count = #nodes
if version == 1 then --original flat table format
for index = 1, count do
local entry = nodes[index]
local pos = entry[1]
local x, y, z = originx - pos.x, originy - pos.y, originz - pos.z
if x < pos1x then pos1x = x end
if y < pos1y then pos1y = y end
if z < pos1z then pos1z = z end
if x > pos2x then pos2x = x end
if y > pos2y then pos2y = y end
if z > pos2z then pos2z = z end
end
else --previous meta flat table format
for index = 1, count do
local entry = nodes[index]
local x, y, z = originx - entry.x, originy - entry.y, originz - entry.z
if x < pos1x then pos1x = x end
if y < pos1y then pos1y = y end
if z < pos1z then pos1z = z end
if x > pos2x then pos2x = x end
if y > pos2y then pos2y = y end
if z > pos2z then pos2z = z end
end
end
elseif version == 3 then --previous list format
for x, y, z, name, param1, param2 in value:gmatch("([+-]?%d+)%s+([+-]?%d+)%s+([+-]?%d+)%s+([^%s]+)%s+(%d+)%s+(%d+)[^\r\n]*[\r\n]*") do --match node entries
local x, y, z = originx + tonumber(x), originy + tonumber(y), originz + tonumber(z)
if x < pos1x then pos1x = x end
if y < pos1y then pos1y = y end
if z < pos1z then pos1z = z end
if x > pos2x then pos2x = x end
if y > pos2y then pos2y = y end
if z > pos2z then pos2z = z end
count = count + 1
end
elseif version == 4 then --current nested table format
--wip: this is a filthy hack that works surprisingly well
value = value:gsub("return%s*{", "", 1):gsub("}%s*$", "", 1)
local escaped = value:gsub("\\\\", "@@"):gsub("\\\"", "@@"):gsub("(\"[^\"]*\")", function(s) return string.rep("@", #s) end)
local startpos, startpos1, endpos = 1, 1
local nodes = {}
while true do
startpos, endpos = escaped:find("},%s*{", startpos)
if not startpos then
break
end
local current = value:sub(startpos1, startpos)
table.insert(nodes, minetest.deserialize("return " .. current))
startpos, startpos1 = endpos, endpos
end
table.insert(nodes, minetest.deserialize("return " .. value:sub(startpos1)))
--local nodes = minetest.deserialize(value) --wip: this is broken for larger tables in the current version of LuaJIT
count = #nodes
for index = 1, count do
local entry = nodes[index]
local x, y, z = originx + entry.x, originy + entry.y, originz + entry.z
if x < pos1x then pos1x = x end
if y < pos1y then pos1y = y end
if z < pos1z then pos1z = z end
if x > pos2x then pos2x = x end
if y > pos2y then pos2y = y end
if z > pos2z then pos2z = z end
end
end
local pos1 = {x=pos1x, y=pos1y, z=pos1z}
local pos2 = {x=pos2x, y=pos2y, z=pos2z}
return pos1, pos2, count
end
random_struct.deserialise_WE = function(originpos, value)
--make area stay loaded
local pos1, pos2 = random_struct.allocate_WE(originpos, value)
local manip = minetest.get_voxel_manip()
manip:read_from_map(pos1, pos2)
local originx, originy, originz = originpos.x, originpos.y, originpos.z
local count = 0
local add_node, get_meta = minetest.add_node, minetest.get_meta
local version = random_struct.valueversion_WE(value)
if version == 1 or version == 2 then --original flat table format
--obtain the node table
local get_tables = loadstring(value)
if not get_tables then --error loading value
return count
end
local tables = get_tables()
--transform the node table into an array of nodes
for i = 1, #tables do
for j, v in pairs(tables[i]) do
if type(v) == "table" then
tables[i][j] = tables[v[1]]
end
end
end
local nodes = tables[1]
--load the node array
count = #nodes
if version == 1 then --original flat table format
for index = 1, count do
local entry = nodes[index]
local pos = entry[1]
pos.x, pos.y, pos.z = originx - pos.x, originy - pos.y, originz - pos.z
add_node(pos, entry[2])
end
else --previous meta flat table format
for index = 1, #nodes do
local entry = nodes[index]
entry.x, entry.y, entry.z = originx + entry.x, originy + entry.y, originz + entry.z
add_node(entry, entry) --entry acts both as position and as node
get_meta(entry):from_table(entry.meta)
end
end
elseif version == 3 then --previous list format
local pos = {x=0, y=0, z=0}
local node = {name="", param1=0, param2=0}
for x, y, z, name, param1, param2 in value:gmatch("([+-]?%d+)%s+([+-]?%d+)%s+([+-]?%d+)%s+([^%s]+)%s+(%d+)%s+(%d+)[^\r\n]*[\r\n]*") do --match node entries
pos.x, pos.y, pos.z = originx + tonumber(x), originy + tonumber(y), originz + tonumber(z)
node.name, node.param1, node.param2 = name, param1, param2
add_node(pos, node)
count = count + 1
end
elseif version == 4 then --current nested table format
--wip: this is a filthy hack that works surprisingly well
value = value:gsub("return%s*{", "", 1):gsub("}%s*$", "", 1)
local escaped = value:gsub("\\\\", "@@"):gsub("\\\"", "@@"):gsub("(\"[^\"]*\")", function(s) return string.rep("@", #s) end)
local startpos, startpos1, endpos = 1, 1
local nodes = {}
while true do
startpos, endpos = escaped:find("},%s*{", startpos)
if not startpos then
break
end
local current = value:sub(startpos1, startpos)
table.insert(nodes, minetest.deserialize("return " .. current))
startpos, startpos1 = endpos, endpos
end
table.insert(nodes, minetest.deserialize("return " .. value:sub(startpos1)))
--local nodes = minetest.deserialize(value) --wip: this is broken for larger tables in the current version of LuaJIT
--load the nodes
count = #nodes
for index = 1, count do
local entry = nodes[index]
entry.x, entry.y, entry.z = originx + entry.x, originy + entry.y, originz + entry.z
add_node(entry, entry) --entry acts both as position and as node
end
--load the metadata
for index = 1, count do
local entry = nodes[index]
get_meta(entry):from_table(entry.meta)
end
end
return count
end
-- End of world edit deserialise part
-- The call of Struct
random_struct.call_struct= function(pos, struct_style)
-- 1 : City , 2 : Temple Sand
if struct_style == 1 then
random_struct.generatecity(pos)
elseif struct_style == 2 then
random_struct.generate_temple_sand(pos)
end
end
random_struct.generatecity = function(pos)
-- No Generating for the moment only place it :D
local city = random_struct.get_struct("pnj_town_1.we")
local newpos = {x=pos.x,y=pos.y,z=pos.z}
if newpos == nil then
return
end
random_struct.deserialise_WE(newpos, city )
end
random_struct.generate_temple_sand = function(pos)
-- No Generating for the temple ... Why using it ? No Change
local temple = random_struct.get_struct("desert_temple.we")
local newpos = {x=pos.x,y=pos.y-12,z=pos.z}
if newpos == nil then
return
end
random_struct.deserialise_WE(newpos, temple)
end
-- Debug command
minetest.register_chatcommand("spawnstruct", {
params = "",
description = "Spawn a Struct.",
func = function(name, param)
local pos= minetest.get_player_by_name(name):getpos()
if not pos then
return
end
if param == "" or param == "help" then
minetest.chat_send_player(name, "Please use instruction /spawnstruct TYPE")
minetest.chat_send_player(name, "TYPE avaiable : town, temple_sand")
end
if param == "town" then
random_struct.generatecity(pos)
minetest.chat_send_player(name, "Town Created")
end
if param == "temple_sand" then
random_struct.generate_temple_sand(pos)
minetest.chat_send_player(name, "Temple Sand Created")
end
end
})
local time_to_load= os.clock() - init
print(string.format("[MOD] "..minetest.get_current_modname().." loaded in %.4f s", time_to_load))

@ -0,0 +1,282 @@
local init = os.clock()
random_struct ={}
random_struct.get_struct = function(file)
local localfile = minetest.get_modpath("random_struct").."/build/"..file
local file, errorload = io.open(localfile, "rb")
if errorload ~= nil then
minetest.log("action", '[Random_Struct] error: could not open this struct "' .. localfile .. '"')
return nil
end
local allnode = file:read("*a")
file:close()
return allnode
end
-- World edit function
random_struct.valueversion_WE = function(value)
if value:find("([+-]?%d+)%s+([+-]?%d+)%s+([+-]?%d+)") and not value:find("%{") then --previous list format
return 3
elseif value:find("^[^\"']+%{%d+%}") then
if value:find("%[\"meta\"%]") then --previous meta flat table format
return 2
end
return 1 --original flat table format
elseif value:find("%{") then --current nested table format
return 4
end
return 0 --unknown format
end
random_struct.allocate_WE = function(originpos, value)
local huge = math.huge
local pos1x, pos1y, pos1z = huge, huge, huge
local pos2x, pos2y, pos2z = -huge, -huge, -huge
local originx, originy, originz = originpos.x, originpos.y, originpos.z
local count = 0
local version = random_struct.valueversion_WE (value)
if version == 1 or version == 2 then --flat table format
--obtain the node table
local get_tables = loadstring(value)
if get_tables then --error loading value
return originpos, originpos, count
end
local tables = get_tables()
--transform the node table into an array of nodes
for i = 1, #tables do
for j, v in pairs(tables[i]) do
if type(v) == "table" then
tables[i][j] = tables[v[1]]
end
end
end
local nodes = tables[1]
--check the node array
count = #nodes
if version == 1 then --original flat table format
for index = 1, count do
local entry = nodes[index]
local pos = entry[1]
local x, y, z = originx - pos.x, originy - pos.y, originz - pos.z
if x < pos1x then pos1x = x end
if y < pos1y then pos1y = y end
if z < pos1z then pos1z = z end
if x > pos2x then pos2x = x end
if y > pos2y then pos2y = y end
if z > pos2z then pos2z = z end
end
else --previous meta flat table format
for index = 1, count do
local entry = nodes[index]
local x, y, z = originx - entry.x, originy - entry.y, originz - entry.z
if x < pos1x then pos1x = x end
if y < pos1y then pos1y = y end
if z < pos1z then pos1z = z end
if x > pos2x then pos2x = x end
if y > pos2y then pos2y = y end
if z > pos2z then pos2z = z end
end
end
elseif version == 3 then --previous list format
for x, y, z, name, param1, param2 in value:gmatch("([+-]?%d+)%s+([+-]?%d+)%s+([+-]?%d+)%s+([^%s]+)%s+(%d+)%s+(%d+)[^\r\n]*[\r\n]*") do --match node entries
local x, y, z = originx + tonumber(x), originy + tonumber(y), originz + tonumber(z)
if x < pos1x then pos1x = x end
if y < pos1y then pos1y = y end
if z < pos1z then pos1z = z end
if x > pos2x then pos2x = x end
if y > pos2y then pos2y = y end
if z > pos2z then pos2z = z end
count = count + 1
end
elseif version == 4 then --current nested table format
--wip: this is a filthy hack that works surprisingly well
value = value:gsub("return%s*{", "", 1):gsub("}%s*$", "", 1)
local escaped = value:gsub("\\\\", "@@"):gsub("\\\"", "@@"):gsub("(\"[^\"]*\")", function(s) return string.rep("@", #s) end)
local startpos, startpos1, endpos = 1, 1
local nodes = {}
while true do
startpos, endpos = escaped:find("},%s*{", startpos)
if not startpos then
break
end
local current = value:sub(startpos1, startpos)
table.insert(nodes, minetest.deserialize("return " .. current))
startpos, startpos1 = endpos, endpos
end
table.insert(nodes, minetest.deserialize("return " .. value:sub(startpos1)))
--local nodes = minetest.deserialize(value) --wip: this is broken for larger tables in the current version of LuaJIT
count = #nodes
for index = 1, count do
local entry = nodes[index]
local x, y, z = originx + entry.x, originy + entry.y, originz + entry.z
if x < pos1x then pos1x = x end
if y < pos1y then pos1y = y end
if z < pos1z then pos1z = z end
if x > pos2x then pos2x = x end
if y > pos2y then pos2y = y end
if z > pos2z then pos2z = z end
end
end
local pos1 = {x=pos1x, y=pos1y, z=pos1z}
local pos2 = {x=pos2x, y=pos2y, z=pos2z}
return pos1, pos2, count
end
random_struct.deserialise_WE = function(originpos, value)
--make area stay loaded
local pos1, pos2 = random_struct.allocate_WE(originpos, value)
local manip = minetest.get_voxel_manip()
manip:read_from_map(pos1, pos2)
local originx, originy, originz = originpos.x, originpos.y, originpos.z
local count = 0
local add_node, get_meta = minetest.add_node, minetest.get_meta
local version = random_struct.valueversion_WE(value)
if version == 1 or version == 2 then --original flat table format
--obtain the node table
local get_tables = loadstring(value)
if not get_tables then --error loading value
return count
end
local tables = get_tables()
--transform the node table into an array of nodes
for i = 1, #tables do
for j, v in pairs(tables[i]) do
if type(v) == "table" then
tables[i][j] = tables[v[1]]
end
end
end
local nodes = tables[1]
--load the node array
count = #nodes
if version == 1 then --original flat table format
for index = 1, count do
local entry = nodes[index]
local pos = entry[1]
pos.x, pos.y, pos.z = originx - pos.x, originy - pos.y, originz - pos.z
add_node(pos, entry[2])
end
else --previous meta flat table format
for index = 1, #nodes do
local entry = nodes[index]
entry.x, entry.y, entry.z = originx + entry.x, originy + entry.y, originz + entry.z
add_node(entry, entry) --entry acts both as position and as node
get_meta(entry):from_table(entry.meta)
end
end
elseif version == 3 then --previous list format
local pos = {x=0, y=0, z=0}
local node = {name="", param1=0, param2=0}
for x, y, z, name, param1, param2 in value:gmatch("([+-]?%d+)%s+([+-]?%d+)%s+([+-]?%d+)%s+([^%s]+)%s+(%d+)%s+(%d+)[^\r\n]*[\r\n]*") do --match node entries
pos.x, pos.y, pos.z = originx + tonumber(x), originy + tonumber(y), originz + tonumber(z)
node.name, node.param1, node.param2 = name, param1, param2
add_node(pos, node)
count = count + 1
end
elseif version == 4 then --current nested table format
--wip: this is a filthy hack that works surprisingly well
value = value:gsub("return%s*{", "", 1):gsub("}%s*$", "", 1)
local escaped = value:gsub("\\\\", "@@"):gsub("\\\"", "@@"):gsub("(\"[^\"]*\")", function(s) return string.rep("@", #s) end)
local startpos, startpos1, endpos = 1, 1
local nodes = {}
while true do
startpos, endpos = escaped:find("},%s*{", startpos)
if not startpos then
break
end
local current = value:sub(startpos1, startpos)
table.insert(nodes, minetest.deserialize("return " .. current))
startpos, startpos1 = endpos, endpos
end
table.insert(nodes, minetest.deserialize("return " .. value:sub(startpos1)))
--local nodes = minetest.deserialize(value) --wip: this is broken for larger tables in the current version of LuaJIT
--load the nodes
count = #nodes
for index = 1, count do
local entry = nodes[index]
entry.x, entry.y, entry.z = originx + entry.x, originy + entry.y, originz + entry.z
add_node(entry, entry) --entry acts both as position and as node
end
--load the metadata
for index = 1, count do
local entry = nodes[index]
get_meta(entry):from_table(entry.meta)
end
end
return count
end
-- End of world edit deserialise part
-- The call of Struct
random_struct.call_struct= function(pos, struct_style)
if math.random(1,2) == 1 then
-- 1 : City , 2 : Temple Sand
if struct_style == 1 then
random_struct.generatecity(pos)
elseif struct_style == 2 then
random_struct.generate_temple_sand(pos)
end
end
end
random_struct.generatecity = function(pos)
-- No Generating for the moment only place it :D
local city = random_struct.get_struct("pnj_town_1.we")
local newpos = {x=pos.x,y=pos.y,z=pos.z}
if newpos == nil then
return
end
random_struct.deserialise_WE(newpos, city )
end
random_struct.generate_temple_sand = function(pos)
-- No Generating for the temple ... Why using it ? No Change
local temple = random_struct.get_struct("desert_temple.we")
local newpos = {x=pos.x,y=pos.y-12,z=pos.z}
if newpos == nil then
return
end
random_struct.deserialise_WE(newpos, temple)
end
-- Debug command
minetest.register_chatcommand("spawnstruct", {
params = "",
description = "Spawn a Struct.",
func = function(name, param)
local pos= minetest.get_player_by_name(name):getpos()
if not pos then
return
end
if param == "" or param == "help" then
minetest.chat_send_player(name, "Please use instruction /spawnstruct TYPE")
minetest.chat_send_player(name, "TYPE avaiable : town, temple_sand")
end
if param == "town" then
random_struct.generatecity(pos)
minetest.chat_send_player(name, "Town Created")
end
if param == "temple_sand" then
random_struct.generate_temple_sand(pos)
minetest.chat_send_player(name, "Temple Sand Created")
end
end
})
local time_to_load= os.clock() - init
print(string.format("[MOD] "..minetest.get_current_modname().." loaded in %.4f s", time_to_load))

@ -36,6 +36,18 @@ function stairs.register_stair(subname, recipeitem, groups, images, description,
return itemstack
end
end
local futurpos = pointed_thing.under
local frontstair = {x=futurpos.x-1, y=futurpos.y+1, z=futurpos.z}
local leftstair = {x=futurpos.x, y=futurpos.y+1, z=futurpos.z+1}
print( minetest.get_node(frontstair).name)
if minetest.get_node(frontstair).name == "stairs:stair_"..subname.."" and minetest.get_node(leftstair).name == "stairs:stair_"..subname.."" then
local fakestack = ItemStack("stairs:stair_" .. subname.."_corner_1")
local ret = minetest.item_place(fakestack, placer, pointed_thing)
if ret:is_empty() then
itemstack:take_item()
return itemstack
end
end
-- Otherwise place regularly
return minetest.item_place(itemstack, placer, pointed_thing)
@ -60,6 +72,24 @@ function stairs.register_stair(subname, recipeitem, groups, images, description,
},
})
minetest.register_node(":stairs:stair_" .. subname.."_corner_1", {
drop = "stairs:stair_" .. subname,
drawtype = "nodebox",
tiles = images,
paramtype = "light",
paramtype2 = "facedir",
is_ground_content = true,
groups = groups,
sounds = sounds,
node_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5, 0, 0.5},
{-0.5, -0, -0, 0, 0.5, 0.5},
},
},
})
minetest.register_craft({
output = 'stairs:stair_' .. subname .. ' 4',
recipe = {