Cleanup codes [needs testing]

master
SmallJoker 2014-09-28 19:01:27 +02:00
parent 8592aaa7e9
commit 1ff1124c69
2 changed files with 52 additions and 58 deletions

View File

@ -1,3 +1,3 @@
A first test of a mod that tries to imitate that scurril rail corridors of Minecraft. This mod tries to imitate the known rail corridors of Minecraft.
Dies ist eine Testversion eines Mods, der versucht, die aus Minecraft bekannten Minenschächte mit Schienen nachzubilden. Diese Modifikation versucht die aus Minecraft bekannten Minenschächte mit Schienen nachzubilden.

106
init.lua
View File

@ -17,7 +17,7 @@ local probability_up_or_down = 0.27
-- Zufallsgenerator / random generator -- Zufallsgenerator / random generator
local pr local pr
local pr_initialized = false; local pr_initialized = false
function InitRandomizer(seeed) function InitRandomizer(seeed)
pr = PseudoRandom(seeed) pr = PseudoRandom(seeed)
@ -31,11 +31,11 @@ end
-- Cube… -- Cube…
function Cube(p, radius, node) function Cube(p, radius, node)
for zi = p.z-radius, p.z+radius do for zi = p.z-radius, p.z+radius do
for yi = p.y-radius, p.y+radius do for yi = p.y-radius, p.y+radius do
for xi = p.x-radius, p.x+radius do for xi = p.x-radius, p.x+radius do
minetest.set_node({x=xi,y=yi,z=zi}, node) minetest.set_node({x=xi,y=yi,z=zi}, node)
end end
end end
end end
end end
@ -49,50 +49,45 @@ function corridor_part(start_point, segment_vector, segment_count)
for segmentindex = 0, segment_count-1 do for segmentindex = 0, segment_count-1 do
Cube(p, 1, {name="air"}) Cube(p, 1, {name="air"})
-- Diese komischen Holz-Konstruktionen -- Diese komischen Holz-Konstruktionen
-- These funny wood structs -- These strange wood structs
if segmentindex % 2 == 1 and segment_vector.y == 0 then if segmentindex % 2 == 1 and segment_vector.y == 0 then
minetest.set_node({x=p.x, y=p.y+1, z=p.z}, {name="default:wood"}) local dir = {0, 0}
local node_wood = {name="default:wood"}
local node_fence = {name="default:fence_wood"}
if segment_vector.x == 0 and segment_vector.z ~= 0 then if segment_vector.x == 0 and segment_vector.z ~= 0 then
minetest.set_node({x=p.x+1, y=p.y+1, z=p.z}, {name="default:wood"}) dir = {1, 0}
minetest.set_node({x=p.x-1, y=p.y+1, z=p.z}, {name="default:wood"})
minetest.set_node({x=p.x-1, y=p.y, z=p.z}, {name="default:fence_wood"})
minetest.set_node({x=p.x+1, y=p.y, z=p.z}, {name="default:fence_wood"})
minetest.set_node({x=p.x+1, y=p.y-1, z=p.z}, {name="default:fence_wood"})
minetest.set_node({x=p.x-1, y=p.y-1, z=p.z}, {name="default:fence_wood"})
if minetest.get_node({x=p.x,y=p.y-2,z=p.z}).name=="air" then
minetest.set_node({x=p.x+1, y=p.y-2, z=p.z}, {name="default:fence_wood"})
minetest.set_node({x=p.x-1, y=p.y-2, z=p.z}, {name="default:fence_wood"})
end
if torches then
minetest.set_node({x=p.x, y=p.y+1, z=p.z+1}, {name="default:torch", param2=1})
minetest.set_node({x=p.x, y=p.y+1, z=p.z-1}, {name="default:torch", param2=1})
end
elseif segment_vector.x ~= 0 and segment_vector.z == 0 then elseif segment_vector.x ~= 0 and segment_vector.z == 0 then
minetest.set_node({x=p.x, y=p.y+1, z=p.z+1}, {name="default:wood"}) dir = {0, 1}
minetest.set_node({x=p.x, y=p.y+1, z=p.z-1}, {name="default:wood"}) end
minetest.set_node({x=p.x, y=p.y, z=p.z+1}, {name="default:fence_wood"})
minetest.set_node({x=p.x, y=p.y, z=p.z-1}, {name="default:fence_wood"}) local calc = {
minetest.set_node({x=p.x, y=p.y-1, z=p.z+1}, {name="default:fence_wood"}) p.x+dir[1], p.z+dir[2], -- X and Z, added by direction
minetest.set_node({x=p.x, y=p.y-1, z=p.z-1}, {name="default:fence_wood"}) p.x-dir[1], p.z-dir[2], -- subtracted
if minetest.get_node({x=p.x,y=p.y-2,z=p.z}).name=="air" then }
minetest.set_node({x=p.x, y=p.y-2, z=p.z+1}, {name="default:fence_wood"}) minetest.set_node({x=p.x, y=p.y+1, z=p.z}, node_wood)
minetest.set_node({x=p.x, y=p.y-2, z=p.z-1}, {name="default:fence_wood"}) minetest.set_node({x=calc[1], y=p.y+1, z=calc[2]}, node_wood)
end minetest.set_node({x=calc[1], y=p.y , z=calc[2]}, node_fence)
if torches then minetest.set_node({x=calc[1], y=p.y-1, z=calc[2]}, node_fence)
minetest.set_node({x=p.x+1, y=p.y+1, z=p.z}, {name="default:torch", param2=1})
minetest.set_node({x=p.x-1, y=p.y+1, z=p.z}, {name="default:torch", param2=1}) minetest.set_node({x=calc[3], y=p.y+1, z=calc[4]}, node_wood)
end minetest.set_node({x=calc[3], y=p.y , z=calc[4]}, node_fence)
minetest.set_node({x=calc[3], y=p.y-1, z=calc[4]}, node_fence)
if minetest.get_node({x=p.x,y=p.y-2,z=p.z}).name=="air" then
minetest.set_node({x=calc[1], y=p.y-2, z=calc[2]}, node_fence)
minetest.set_node({x=calc[3], y=p.y-2, z=calc[4]}, node_fence)
end
if torches then
minetest.set_node({x=calc[1], y=p.y+1, z=calc[2]}, {name="default:torch", param2=1})
minetest.set_node({x=calc[3], y=p.y+1, z=calc[4]}, {name="default:torch", param2=1})
end end
end end
-- nächster Punkt durch vektoraddition -- nächster Punkt durch vektoraddition
-- next way point -- next way point
p.x = p.x + segment_vector.x p = vector.add(p, segment_vector)
p.y = p.y + segment_vector.y
p.z = p.z + segment_vector.z
end end
p.x = p.x - segment_vector.x p = vector.subtract(p, segment_vector)
p.y = p.y - segment_vector.y
p.z = p.z - segment_vector.z
end end
function corridor_func(waypoint, coord, sign, up_or_down, up) function corridor_func(waypoint, coord, sign, up_or_down, up)
@ -110,11 +105,11 @@ function corridor_func(waypoint, coord, sign, up_or_down, up)
vek.z=segamount vek.z=segamount
end end
if up_or_down then if up_or_down then
if up then if up then
vek.y = 1 vek.y = 1
else else
vek.y = -1 vek.y = -1
end end
end end
local segcount = pr:next(4,6) local segcount = pr:next(4,6)
corridor_part(waypoint, vek, segcount) corridor_part(waypoint, vek, segcount)
@ -132,11 +127,11 @@ function corridor_func(waypoint, coord, sign, up_or_down, up)
vek.z=segamount vek.z=segamount
end end
if up_or_down then if up_or_down then
if up then if up then
vek.y = 1 vek.y = 1
else else
vek.y = -1 vek.y = -1
end end
end end
if not up_or_down then if not up_or_down then
segcount = segcount * 2.5 segcount = segcount * 2.5
@ -153,7 +148,7 @@ function corridor_func(waypoint, coord, sign, up_or_down, up)
for i=1,segcount do for i=1,segcount do
p = {x=waypoint.x+vek.x*i, y=waypoint.y+vek.y*i-1, z=waypoint.z+vek.z*i} p = {x=waypoint.x+vek.x*i, y=waypoint.y+vek.y*i-1, z=waypoint.z+vek.z*i}
if minetest.get_node({x=p.x,y=p.y-1,z=p.z}).name=="air" then if minetest.get_node({x=p.x,y=p.y-1,z=p.z}).name=="air" then
p.y = p.y - 1; p.y = p.y - 1;
end end
minetest.set_node(p, {name = "default:rail"}) minetest.set_node(p, {name = "default:rail"})
end end
@ -172,7 +167,7 @@ function start_corridor(waypoint, coord, sign, psra)
ud = true ud = true
up = nextrandom(0, 2) < 1 up = nextrandom(0, 2) < 1
else else
ud = false ud = false
end end
wp = corridor_func(wp,c,s, ud, up) wp = corridor_func(wp,c,s, ud, up)
-- coord und sign verändern -- coord und sign verändern
@ -207,14 +202,13 @@ function place_corridors(main_cave_coords, psra)
if nextrandom(0, 2) < 1 then if nextrandom(0, 2) < 1 then
start_corridor(main_cave_coords, "z", not zs, psra) start_corridor(main_cave_coords, "z", not zs, psra)
end end
end end
minetest.register_on_generated(function(minp, maxp, seed) minetest.register_on_generated(function(minp, maxp, seed)
if not pr_initialized then if not pr_initialized then
InitRandomizer(seed) InitRandomizer(seed)
end end
if maxp.y < 0 and nextrandom(0, 1) < probability_railcaves_in_chunk then if maxp.y < 0 and nextrandom(0, 1) < probability_railcaves_in_chunk then
-- Mittelpunkt berechnen -- Mittelpunkt berechnen
-- Mid point of the chunk -- Mid point of the chunk
local p = {x=minp.x+(maxp.x-minp.x)/2, y=minp.y+(maxp.y-minp.y)/2, z=minp.z+(maxp.z-minp.z)/2} local p = {x=minp.x+(maxp.x-minp.x)/2, y=minp.y+(maxp.y-minp.y)/2, z=minp.z+(maxp.z-minp.z)/2}