adventures/creativeGeneral.lua

1 line
12 KiB
Lua
Raw Normal View History

local function updateGeneralSourceFormspec(meta) local formspec = "size[6.25,3]".. "label[1,0;Position]".. "button[0,1;.75,.5;xminusten;<<]button[.6,1;.75,.5;xminusone;<]label[1.25,.875;"..meta:get_int("x").."]button[1.75,1;.75,.5;xplusone;>]button[2.35,1;.75,.5;xplusten;>>]".. "button[0,1.75;.75,.5;yminusten;<<]button[.6,1.75;.75,.5;yminusone;<]label[1.25,1.625;"..meta:get_int("y").."]button[1.75,1.75;.75,.5;yplusone;>]button[2.35,1.75;.75,.5;yplusten;>>]".. "button[0,2.5;.75,.5;zminusten;<<]button[.6,2.5;.75,.5;zminusone;<]label[1.25,2.4;"..meta:get_int("z").."]button[1.75,2.5;.75,.5;zplusone;>]button[2.35,2.5;.75,.5;zplusten;>>]".. "label[4,0;Dimension]".. "button[3.15,1;.75,.5;widthminusten;<<]button[3.75,1;.75,.5;widthminusone;<]label[4.375,.875;"..meta:get_int("width").."]button[4.9,1;.75,.5;widthplusone;>]button[5.5,1;.75,.5;widthplusten;>>]".. "button[3.15,1.75;.75,.5;lengthminusten;<<]button[3.75,1.75;.75,.5;lengthminusone;<]label[4.375,1.625;"..meta:get_int("length").."]button[4.9,1.75;.75,.5;lengthplusone;>]button[5.5,1.75;.75,.5;lengthplusten;>>]".. "button[3.15,2.5;.75,.5;heightminusten;<<]button[3.75,2.5;.75,.5;heightminusone;<]label[4.375,2.4;"..meta:get_int("height").."]button[4.9,2.5;.75,.5;heightplusone;>]button[5.5,2.5;.75,.5;heightplusten;>>]" return formspec end for name,source in pairs(adventures.generalSources) do minetest.register_entity(source.area.name ,{ physical = true, visual = "cube", visual_size = {x=2,y=1}, collisionbox = {0,0,0,0,0,0}, textures = {source.area.texture,source.area.texture,source.area.texture,source.area.texture,source.area.texture,source.area.texture}, }) minetest.register_node(name ,{ description = source.description, walkable = false, groups = {crumbly=3}, tiles = source.tiles, on_construct = function(pos) adventures.sources[adventures.positionToString(pos)] = {name=name,pos=pos} local meta = minetest.env:get_meta(pos) local x = 0 local y = 0 local z = 0 local width = 2 local length = 2 local height = 1 local data = adventures.sourceData[adventures.positionToString(pos)] if(data ~= 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", updateGeneralSourceFormspec(meta)) local area = minetest.env:add_entity(pos, source.area.name) area:setpos(adventures.snapPosition(meta, pos)) area:set_properties({visual_size={x=width,y=height}}) end, on_receive_fields = function(pos, formname, fields, sender) local meta = minetest.env:get_meta(pos) local delta = {x=0,y=0,z=0} local updateDimension = false if fields.xminusten then delta.x = -10 meta:set_int("x", meta:get_int("x")-10) end if fields.xminusone then delta.x = -1 meta:set_int("x", meta:get_int("x")-1) end if fields.xplusone then delta.x = 1 meta:set_int("x", meta:get_int("x")+1) end if fields.xplusten then delta.x = 10 meta:set_int("x", meta:get_int("x")+10) end if fields.yminusten then delta.y = -10 meta:set_int("y", meta:get_int("y")-10) end if fields.yminusone then delta.y = -1 meta:set_int("y", meta:get_int("y")-1) end if fields.yplusone then delta.y = 1 meta:set_int("y", meta:get_int("y")+1) end if fields.yplusten then delta.y = 10 meta:set_int("y", meta:get_int("y")+10) end if fields.zminusten then delta.z = -10 meta:set_int("z", meta:get_int("z")-10) end if fields.zminusone then delta.z = -1 meta:set_int("z", meta:get_int("z")-1) end if fields.zplusone then delta.z = 1 meta:set_int("z", meta:get_int("z")+1) end if fields.zplusten then delta.z = 10 meta:set_int("z", meta:get_int("z")+10) end if fields.widthminusten then updateDimension = true meta:set_int("width", meta:get_int("width")-10) end if fields.widthminusone then updateDimension = true meta:set_int("widt