diff --git a/creativeGeneral.lua b/creativeGeneral.lua new file mode 100644 index 0000000..dea2bbc --- /dev/null +++ b/creativeGeneral.lua @@ -0,0 +1 @@ +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("width", meta:get_int("width")-1) end if fields.widthplusone then updateDimension = true meta:set_int("width", meta:get_int("width")+1) end if fields.widthplusten then updateDimension = true meta:set_int("width", meta:get_int("width")+10) end if fields.lengthminusten then updateDimension = true meta:set_int("length", meta:get_int("length")-10) end if fields.lengthminusone then updateDimension = true meta:set_int("length", meta:get_int("length")-1) end if fields.lengthplusone then updateDimension = true meta:set_int("length", meta:get_int("length")+1) end if fields.lengthplusten then updateDimension = true meta:set_int("length", meta:get_int("length")+10) end if fields.heightminusten then updateDimension = true meta:set_int("height", meta:get_int("height")-10) end if fields.heightminusone then updateDimension = true meta:set_int("height", meta:get_int("height")-1) end if fields.heightplusone then updateDimension = true meta:set_int("height", meta:get_int("height")+1) end if fields.heightplusten then updateDimension = true meta:set_int("height", meta:get_int("height")+10) end local area = adventures.findArea(meta, pos, delta) if updateDimension then area:set_properties({visual_size={x=meta:get_int("width"),y=meta:get_int("height")}}) end area:setpos(adventures.snapPosition(meta, pos)) meta:set_string("formspec", updateGeneralSourceFormspec(meta)) end, on_destruct = function(pos) adventures.sources[adventures.positionToString(pos)] = nil local area = adventures.findArea(minetest.env:get_meta(pos), pos, {x=0,y=0,z=0}) if(area ~= nil) then area:remove() end end, }) end local function updateIDSourceFormspec(meta) local formspec = "size[6.25,4.5]".. "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;>>]".. "label[2.875,3.125;ID]".. "button[1.5,4;.75,.5;idminusten;<<]button[2.1,4;.75,.5;idminusone;<]label[2.75,3.875;"..meta:get_int("id").."]button[3.325,4;.75,.5;idplusone;>]button[3.925,4;.75,.5;idplusten;>>]" return formspec end local function updateIDSourceInfotext(meta) return "ID is "..meta:get_int("id") end for name,source in pairs(adventures.generalIDSources) 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 id = 0 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] id = data[11] 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_int("id", id) meta:set_string("formspec", updateIDSourceFormspec(meta)) meta:set_string("infotext", updateIDSourceInfotext(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("width", meta:get_int("width")-1) end if fields.widthplusone then updateDimension = true meta:set_int("width", meta:get_int("width")+1) end if fields.widthplusten then updateDimension = true meta:set_int("width", meta:get_int("width")+10) end if fields.lengthminusten then updateDimension = true meta:set_int("length", meta:get_int("length")-10) end if fields.lengthminusone then updateDimension = true meta:set_int("length", meta:get_int("length")-1) end if fields.lengthplusone then updateDimension = true meta:set_int("length", meta:get_int("length")+1) end if fields.lengthplusten then updateDimension = true meta:set_int("length", meta:get_int("length")+10) end if fields.heightminusten then updateDimension = true meta:set_int("height", meta:get_int("height")-10) end if fields.heightminusone then updateDimension = true meta:set_int("height", meta:get_int("height")-1) end if fields.heightplusone then updateDimension = true meta:set_int("height", meta:get_int("height")+1) end if fields.heightplusten then updateDimension = true meta:set_int("height", meta:get_int("height")+10) end if fields.idminusten then meta:set_int("id", meta:get_int("id")-10) end if fields.idminusone then meta:set_int("id", meta:get_int("id")-1) end if fields.idplusone then meta:set_int("id", meta:get_int("id")+1) end if fields.idplusten then meta:set_int("id", meta:get_int("id")+10) end local area = adventures.findArea(meta, pos, delta) if updateDimension then area:set_properties({visual_size={x=meta:get_int("width"),y=meta:get_int("height")}}) end area:setpos(adventures.snapPosition(meta, pos)) meta:set_string("formspec", updateIDSourceFormspec(meta)) meta:set_string("infotext", updateIDSourceInfotext(meta)) end, on_destruct = function(pos) adventures.sources[adventures.positionToString(pos)] = nil local area = adventures.findArea(minetest.env:get_meta(pos), pos, {x=0,y=0,z=0}) if(area ~= nil) then area:remove() end end, }) end \ No newline at end of file diff --git a/creativeInitialStuff.lua b/creativeInitialStuff.lua new file mode 100644 index 0000000..f5dd085 --- /dev/null +++ b/creativeInitialStuff.lua @@ -0,0 +1,17 @@ +minetest.register_node("adventures:initial_stuff", { + description = "Initial Stuff", + walkable = false, + groups = {crumbly=3}, + tiles = {"adventures_initialStuff.png"}, + on_construct = function(pos) + adventures.sources[adventures.positionToString(pos)] = {name="adventures:initial_stuff",pos=pos} + local meta = minetest.env:get_meta(pos) + meta:set_string("formspec", "size[8,9]".. + "list[detached:initialstuff;main;0,0;8,4;]".. + "list[current_player;main;0,5;8,4;]") + meta:get_inventory():set_size("main", 32) + end, + on_destruct = function(pos) + adventures.sources[adventures.positionToString(pos)] = nil + end, +}) \ No newline at end of file diff --git a/creativeQuest.lua b/creativeQuest.lua new file mode 100644 index 0000000..6188836 --- /dev/null +++ b/creativeQuest.lua @@ -0,0 +1,69 @@ +local function updateQuest(meta) + return "size[8,9]".. + "field[0.25,0.25;5,1;name;Quest Name;"..meta:get_string("name").."]".. + "field[0.25,1.25;5,1;objective;Objective;"..meta:get_string("objective").."]".. + "field[0.25,2.25;5,1;description;Description;"..meta:get_string("description").."]button[5.5,0;2,0.75;save;Save]".. + "label[0,2.5;Quest Items]list[context;items;0,3;2,2;]".. + "label[6,2.5;Quest Reward]list[context;reward;6,3;2,2;]".. + "button[2.325,4;.75,.5;idminusten;<<]button[2.925,4;.75,.5;idminusone;<]label[3.75,3.875;"..meta:get_int("id").."]button[4.325,4;.75,.5;idplusone;>]button[4.925,4;.75,.5;idplusten;>>]".. + "list[current_player;main;0,5;8,4]" +end + +minetest.register_node("adventures:quest", { + description = "Quest", + walkable = false, + groups = {crumbly=3}, + tiles = {"adventures_quest.png"}, + on_construct = function(pos) + adventures.sources[adventures.positionToString(pos)] = {name="adventures:quest",pos=pos} + local meta = minetest.env:get_meta(pos) + local data = adventures.sourceData[adventures.positionToString(pos)] + if data ~= nil then + meta:set_string("name", data[5]) + meta:set_string("objective", data[6]) + meta:set_string("description", data[7]) + meta:set_int("id", data[8]) + else + meta:set_string("name", "") + meta:set_string("objective", "") + meta:set_string("description", "") + meta:set_int("id", 0) + end + meta:set_string("formspec", updateQuest(meta)) + local inv = meta:get_inventory() + inv:set_size("items", 4) + inv:set_size("reward", 4) + end, + on_receive_fields = function(pos, formname, fields, sender) + local meta = minetest.env:get_meta(pos) + if fields.save then + meta:set_string("name", fields.name) + meta:set_string("objective", fields.objective) + meta:set_string("description", fields.description) + end + if fields.idminusten then meta:set_int("id", meta:get_int("id")-10) end + if fields.idminusone then meta:set_int("id", meta:get_int("id")-1) end + if fields.idplusone then meta:set_int("id", meta:get_int("id")+1) end + if fields.idplusten then meta:set_int("id", meta:get_int("id")+10) end + meta:set_string("formspec", updateQuest(meta)) + end, + on_destruct = function(pos) + adventures.sources[adventures.positionToString(pos)] = nil + end, +}) + +minetest.register_node("adventures:quest_destination", { + description = "Quest Destination", + walkable = false, + groups = {crumbly=3}, + tiles = {"adventures_questDestination.png"}, + on_construct = function(pos) + adventures.sources[adventures.positionToString(pos)] = {name="adventures:quest",pos=pos} + local meta = minetest.env:get_meta(pos) + end, + on_receive_fields = function(pos, formname, fields, sender) + end, + on_destruct = function(pos) + adventures.sources[adventures.positionToString(pos)] = nil + end, +}) \ No newline at end of file diff --git a/standardInitialStuff.lua b/standardInitialStuff.lua new file mode 100644 index 0000000..bcf585f --- /dev/null +++ b/standardInitialStuff.lua @@ -0,0 +1,3 @@ +function adventures.giveInitialStuff(player) + player:get_inventory():set_list("main", minetest.get_inventory({type="detached",name="initialstuff"}):get_list("main")) +end \ No newline at end of file diff --git a/standardProtect.lua b/standardProtect.lua new file mode 100644 index 0000000..48f053a --- /dev/null +++ b/standardProtect.lua @@ -0,0 +1,33 @@ +function adventures.storeUnbreakableNodes(data) + local start = adventures.getStartNode(data) + for y=0,data[10]-1,1 do + for z=0,data[8]-1,1 do + for x=0,data[8]-1,1 do + adventures.unbreakable[adventures.positionToString({x=start.x+x,y=start.y+y,z=start.z+z})] = true + end + end + end +end + +function adventures.storeUnbuildableNodes(data) + local start = adventures.getStartNode(data) + for y=0,data[10]-1,1 do + for z=0,data[8]-1,1 do + for x=0,data[8]-1,1 do + adventures.unbuildable[adventures.positionToString({x=start.x+x,y=start.y+y,z=start.z+z})] = true + end + end + end +end + +function adventures.storeFullyProtectedNodes(data) + local start = adventures.getStartNode(data) + for y=0,data[10]-1,1 do + for z=0,data[8]-1,1 do + for x=0,data[8]-1,1 do + adventures.unbuildable[adventures.positionToString({x=start.x+x,y=start.y+y,z=start.z+z})] = true + adventures.unbreakable[adventures.positionToString({x=start.x+x,y=start.y+y,z=start.z+z})] = true + end + end + end +end \ No newline at end of file diff --git a/standardQuest.lua b/standardQuest.lua new file mode 100644 index 0000000..65aadd3 --- /dev/null +++ b/standardQuest.lua @@ -0,0 +1,62 @@ +local function subdivideObjective(str, desc) + local subdata = str:split(" ") + if subdata[1] == "Return" then + return {type=subdata[1], description=desc, count=subdata[2],content=subdata[3]} + elseif subdata[1] == "Collect" then + return {type=subdata[1], description=desc, count=subdata[2],content=subdata[3]} + elseif subdata[1] == "Kill" then + return {type=subdata[1], description=desc, count=subdata[2],content=subdata[3]} + end +end +local function convertObjectiveString(str, desc) + local objs = {} + if str:find("|") == nil then + objs[1] = subdivideObjective(str, desc) + else + local data = str:split("|") + local descdata = desc:split("|") + for i,o in ipairs(data) do + if o ~= nil then + objs[i] = subdivideObjective(o, descdata[i]) + end + end + end + return objs +end +function adventures.storeQuestData(data) + local pos = {x=data[2],y=data[3],z=data[4]} + local meta = minetest.env:get_meta(pos) + local objs = convertObjectiveString(meta:get_string("objective"), meta:get_string("description")) + local y = 3+table.getn(objs) + local str = "label[0,0;"..meta:get_string("name").."]".. + "list[context;reward;4,"..(y-3)..";2,2;]".. + "list[context;items;0,"..(y-3)..";2,2;]".. + "button[1.5,"..(y-1)..";1.5,0.75;accept;Accept]".. + "button_exit[3,"..(y-1)..";1.5,0.75;decline;Decline]" + for i,obj in pairs(objs) do + str = str.."label[0.125,"..(i/2)..";"..obj.description.."]" + end + str = "size[6,"..y.."]"..str + meta:set_string("formspec", str) + adventures.quests[meta:get_string("name")] = {objectives = objs, id = meta:get_int("id")} +end + +minetest.register_node("adventures:quest", { + description = "Quest", + walkable = true, + groups = {immortal=1}, + tiles = {"adventures_quest.png"}, + on_receive_fields = function(pos, formname, fields, sender) + if fields.accept then + local meta = minetest.env:get_meta(pos) + local quests = adventures.playerQuests[sender] + quests[meta:get_string("name")] = adventures.quests[meta:get_string("name")] + end + end, + allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) + return 0 end, + allow_metadata_inventory_put = function(pos, listname, index, stack, player) + return 0 end, + allow_metadata_inventory_take = function(pos, listname, index, stack, player) + return 0 end +}) \ No newline at end of file diff --git a/standardSpawning.lua b/standardSpawning.lua new file mode 100644 index 0000000..704865d --- /dev/null +++ b/standardSpawning.lua @@ -0,0 +1,36 @@ +function adventures.storeSpawnPositions(data) + local start = adventures.getStartNode(data) + for y=0,data[10]-1,1 do + for z=0,data[8]-1,1 do + for x=0,data[8]-1,1 do + table.insert(adventures.spawnPoints, {x=start.x+x,y=start.y+y,z=start.z+z}) + adventures.unbuildable[adventures.positionToString({x=start.x+x,y=start.y+y,z=start.z+z})] = true + end + end + end +end + +function adventures.storeRespawnPositions(data) + local start = adventures.getStartNode(data) + local points = {} + for y=0,data[10]-1,1 do + for z=0,data[8]-1,1 do + for x=0,data[8]-1,1 do + table.insert(points, {x=start.x+x,y=start.y+y,z=start.z+z}) + adventures.unbuildable[adventures.positionToString({x=start.x+x,y=start.y+y,z=start.z+z})] = true + end + end + end + adventures.respawnPoints[data[11]] = points +end + +function adventures.storeCheckpointPositions(data) + local start = adventures.getStartNode(data) + for y=0,data[10]-1,1 do + for z=0,data[8]-1,1 do + for x=0,data[8]-1,1 do + adventures.checkPoints[adventures.positionToString({x=start.x+x,y=start.y+y,z=start.z+z})] = data[11] + end + end + end +end \ No newline at end of file