From ea87a700f93fb84ab405a27e7615991711c05524 Mon Sep 17 00:00:00 2001 From: Brett O'Donnell Date: Wed, 26 Sep 2012 19:01:23 +0930 Subject: [PATCH] added deploy_spiral --- ...nt.png => deploy_cylinder_y_blueprint.png} | Bin deploy_spiral/depends.txt | 1 + deploy_spiral/init.lua | 186 ++++++++++++++++++ .../textures/deploy_spiral_blueprint.png | Bin 0 -> 227 bytes .../textures/deploy_spiral_large.png | Bin 0 -> 227 bytes .../textures/deploy_spiral_medium.png | Bin 0 -> 227 bytes .../textures/deploy_spiral_small.png | Bin 0 -> 227 bytes 7 files changed, 187 insertions(+) rename deploy_cylinder_y/textures/{deploy_cylinder_y_large_blueprint.png => deploy_cylinder_y_blueprint.png} (100%) create mode 100644 deploy_spiral/depends.txt create mode 100644 deploy_spiral/init.lua create mode 100644 deploy_spiral/textures/deploy_spiral_blueprint.png create mode 100644 deploy_spiral/textures/deploy_spiral_large.png create mode 100644 deploy_spiral/textures/deploy_spiral_medium.png create mode 100644 deploy_spiral/textures/deploy_spiral_small.png diff --git a/deploy_cylinder_y/textures/deploy_cylinder_y_large_blueprint.png b/deploy_cylinder_y/textures/deploy_cylinder_y_blueprint.png similarity index 100% rename from deploy_cylinder_y/textures/deploy_cylinder_y_large_blueprint.png rename to deploy_cylinder_y/textures/deploy_cylinder_y_blueprint.png diff --git a/deploy_spiral/depends.txt b/deploy_spiral/depends.txt new file mode 100644 index 0000000..95307f3 --- /dev/null +++ b/deploy_spiral/depends.txt @@ -0,0 +1 @@ +deploy_nodes \ No newline at end of file diff --git a/deploy_spiral/init.lua b/deploy_spiral/init.lua new file mode 100644 index 0000000..319cffa --- /dev/null +++ b/deploy_spiral/init.lua @@ -0,0 +1,186 @@ +--[[ + +Deploy Nodes for Minetest + +Copyright (c) 2012 cornernote, Brett O'Donnell +Source Code: https://github.com/cornernote/minetest-deploy_nodes +License: GPLv3 + +SPIRAL + +]]-- + + +-- expose api +deploy_spiral = {} + + +-- deploy +deploy_spiral.deploy = function(pos,placer,nodename,width,height,spacer) + + -- set the pos to the center of the node + pos.x = math.floor(pos.x+0.5) + pos.y = math.floor(pos.y+0.5) + pos.z = math.floor(pos.z+0.5) + + -- check for space + if deploy_nodes.check_for_space==true then + for x=0,width*spacer do + for y=0,height do + for z=0,width*spacer do + if x~=0 or y~=0 or z~=0 then + local checkpos = {x=pos.x+x,y=pos.y+y,z=pos.z+z} + local checknode = minetest.env:get_node(checkpos).name + if checknode~="air" then + minetest.chat_send_player(placer:get_player_name(), "[deploy_spiral] no room to build because "..checknode.." is in the way at "..dump(checkpos).."") + return + end + end + end + end + end + end + + -- remove spiral node + minetest.env:remove_node(pos) + + -- build the spiral + -- spiral matrix - http://rosettacode.org/wiki/Spiral_matrix#Lua + av, sn = math.abs, function(s) return s~=0 and s/av(s) or 0 end + local function sindex(z, x) -- returns the value at (x, z) in a spiral that starts at 1 and goes outwards + if z == -x and z >= x then return (2*z+1)^2 end + local l = math.max(av(z), av(x)) + return (2*l-1)^2+4*l+2*l*sn(x+z)+sn(z^2-x^2)*(l-(av(z)==l and sn(z)*x or sn(x)*z)) -- OH GOD WHAT + end + local function spiralt(side) + local ret, id, start, stop = {}, 0, math.floor((-side+1)/2), math.floor((side-1)/2) + for i = 1, side do + for j = 1, side do + local id = side^2 - sindex(stop - i + 1,start + j - 1) + ret[id] = {x=i,z=j} + end + end + return ret + end + -- connect the joined parts + local spiral = spiralt(width) + height = tonumber(height) + if height < 1 then height = 1 end + spacer = tonumber(spacer)-1 + if spacer < 1 then spacer = 1 end + local node = {name=nodename} + local np,lp + for y=0,height do + lp = nil + for _,v in ipairs(spiral) do + np = {x=pos.x+v.x*spacer, y=pos.y+y, z=pos.z+v.z*spacer} + if lp~=nil then + if lp.x~=np.x then + if lp.x!lvI6;>1s;*b z3=Dh+L6~vJ#O${~L8%hgh?3y^w370~qEv=}#LT=BJwMkFg)(D3Q$0figD*u3fvVy? zT^vI!{F8tD|8LK%Iz#EKLO1(DMji+EhlgK0Y< literal 0 HcmV?d00001 diff --git a/deploy_spiral/textures/deploy_spiral_large.png b/deploy_spiral/textures/deploy_spiral_large.png new file mode 100644 index 0000000000000000000000000000000000000000..bbf393d659038b731ad27621d3ae5533b953b449 GIT binary patch literal 227 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Ea{HEjtmSN`?>!lvI6;>1s;*b z3=Dh+L6~vJ#O${~L8%hgh?3y^w370~qEv=}#LT=BJwMkFg)(D3Q$0figD*u3fvVy? zT^vI!{F8tD|8LK%Iz#EKLO1(DMji+EhlgK0Y< literal 0 HcmV?d00001 diff --git a/deploy_spiral/textures/deploy_spiral_medium.png b/deploy_spiral/textures/deploy_spiral_medium.png new file mode 100644 index 0000000000000000000000000000000000000000..bbf393d659038b731ad27621d3ae5533b953b449 GIT binary patch literal 227 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Ea{HEjtmSN`?>!lvI6;>1s;*b z3=Dh+L6~vJ#O${~L8%hgh?3y^w370~qEv=}#LT=BJwMkFg)(D3Q$0figD*u3fvVy? zT^vI!{F8tD|8LK%Iz#EKLO1(DMji+EhlgK0Y< literal 0 HcmV?d00001 diff --git a/deploy_spiral/textures/deploy_spiral_small.png b/deploy_spiral/textures/deploy_spiral_small.png new file mode 100644 index 0000000000000000000000000000000000000000..bbf393d659038b731ad27621d3ae5533b953b449 GIT binary patch literal 227 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Ea{HEjtmSN`?>!lvI6;>1s;*b z3=Dh+L6~vJ#O${~L8%hgh?3y^w370~qEv=}#LT=BJwMkFg)(D3Q$0figD*u3fvVy? zT^vI!{F8tD|8LK%Iz#EKLO1(DMji+EhlgK0Y< literal 0 HcmV?d00001