From a99ac7add48fc750add45eeb81b385655ee4b369 Mon Sep 17 00:00:00 2001 From: Sokomine Date: Tue, 21 Jan 2014 02:42:51 +0100 Subject: [PATCH] added diffrent resolutions; right-click to change --- README.md | 16 +++++++++++++++- init.lua | 49 +++++++++++++++++++++++++++++++++++++------------ 2 files changed, 52 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 6a9369a..830a3a9 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,18 @@ mapp ==== -an experimental mod for minetest which adds maps \ No newline at end of file +an experimental mod for minetest which adds maps + + +Written originally by 4aiman +Original can be found under https://github.com/4aiman/mapp + +Changes done by Sokomine: +* added diffrent resolutions +* resolution can be changed by right-clicking with the map +* Supported: 2x2, 4x4, 8x8, 16x16, 32x32, 64x64, 128x128 + +DO.NOT.USE.ON.A.SERVER. This is serious! The higher the resolution, +the more problematic it gets. For me, it works to some degree up +to 64x64, but 128er resolution usually glitches horribly and takes +a long time to display. Play with it in your singleplayer world only! diff --git a/init.lua b/init.lua index f485d2d..a2f5fb9 100644 --- a/init.lua +++ b/init.lua @@ -1,9 +1,34 @@ + +FACTOR = 8; +MAX_FACTOR = 128; -- the bigger, the more graphical glitches you get +MIN_FACTOR = 1; + +SIZE_FULL = 2*FACTOR; --32 +SIZE_HALF = math.ceil(SIZE_FULL/2)+1; +DRAW_SIZE1 = 4.2/FACTOR; --0.15; +DRAW_SIZE2 = 6.4/FACTOR; + minetest.register_tool("mapp:map", { description = "map", inventory_image = "map_block.png", on_use = function(itemstack, user, pointed_thing) map_handler(itemstack,user,pointed_thing) end, + on_place = function(itemstack, placer, pointed_thing) + + FACTOR = FACTOR*2; + if( FACTOR >= MAX_FACTOR ) then + FACTOR = MIN_FACTOR; + end + + SIZE_FULL = 2*FACTOR; --32 + SIZE_HALF = math.ceil(SIZE_FULL/2)+1; + DRAW_SIZE1 = 4.2/FACTOR; --0.15; + DRAW_SIZE2 = 6.4/FACTOR; + + minetest.chat_send_player( placer:get_player_name(), + 'Info: Map resolution set to '..tostring( SIZE_FULL )..'x'..tostring( SIZE_FULL )..'.'); + end, }) function map_handler (itemstack, user, pointed_thing) local pos = user:getpos() @@ -42,10 +67,10 @@ function map_handler (itemstack, user, pointed_thing) local env = minetest.env local registered_nodes = minetest.registered_nodes - for i = -17,17,1 do - mapar[i+17] = {} - for j = -17,17,1 do - mapar[i+17][j+17] = {} + for i = (-1*SIZE_HALF),SIZE_HALF,1 do + mapar[i+SIZE_HALF] = {} + for j = (-1*SIZE_HALF),SIZE_HALF,1 do + mapar[i+SIZE_HALF][j+SIZE_HALF] = {} po.x, po.y, po.z = pos.x+i, pos.y, pos.z+j local no = env:get_node(po) local k=po.y @@ -76,8 +101,8 @@ function map_handler (itemstack, user, pointed_thing) if type(tile)=="table" then tile=tile["name"] end - mapar[i+17][j+17].y = k - mapar[i+17][j+17].im = tile + mapar[i+SIZE_HALF][j+SIZE_HALF].y = k + mapar[i+SIZE_HALF][j+SIZE_HALF].im = tile end end @@ -87,24 +112,24 @@ function map_handler (itemstack, user, pointed_thing) pp = #p pp = pp + 1 - p[pp] = "size[5.2,5]" + p[pp] = "size[10.4,10]" - for i=1,32,1 do - for j=1,32,1 do + for i=1,SIZE_FULL,1 do + for j=1,SIZE_FULL,1 do if mapar[i][j].y ~= mapar[i][j+1].y then mapar[i][j].im = mapar[i][j].im .. "^1black_blockt.png" end if mapar[i][j].y ~= mapar[i][j-1].y then mapar[i][j].im = mapar[i][j].im .. "^1black_blockb.png" end if mapar[i][j].y ~= mapar[i-1][j].y then mapar[i][j].im = mapar[i][j].im .. "^1black_blockl.png" end if mapar[i][j].y ~= mapar[i+1][j].y then mapar[i][j].im = mapar[i][j].im .. "^1black_blockr.png" end pp = pp + 1 - p[pp] = "image[".. 0.15*(i) ..",".. 0.15*(32-j)+0.1 ..";0.2,0.2;" .. mapar[i][j].im .. "]" + p[pp] = "image[".. DRAW_SIZE1*(i) ..",".. DRAW_SIZE1*(SIZE_FULL-j)+0.1 ..";"..DRAW_SIZE2..","..DRAW_SIZE2..";" .. mapar[i][j].im .. "]" end end pp = pp + 1 if rotate ~= 0 then - p[pp] = "image[".. 0.15*(16)+0.075 ..",".. 0.15*(16)-0.085 ..";0.4,0.4;d" .. yaw .. ".png^[transformFYR".. rotate .."]" + p[pp] = "image[".. DRAW_SIZE1*(SIZE_HALF-1)+0.075 ..",".. DRAW_SIZE1*(SIZE_HALF-1)-0.085 ..";0.4,0.4;d" .. yaw .. ".png^[transformFYR".. rotate .."]" else - p[pp] = "image[".. 0.15*(16)+0.075 ..",".. 0.15*(16)-0.085 ..";0.4,0.4;d" .. yaw .. ".png^[transformFY]" + p[pp] = "image[".. DRAW_SIZE1*(SIZE_HALF-1)+0.075 ..",".. DRAW_SIZE1*(SIZE_HALF-1)-0.085 ..";0.4,0.4;d" .. yaw .. ".png^[transformFY]" end map = table.concat(p, "\n")