diff --git a/README.md b/README.md index 22898a7..94ec56e 100644 --- a/README.md +++ b/README.md @@ -15,4 +15,4 @@ Released under WTFPL 0.1 - Initial release 0.2 - New api commands added thanks to blert2112 -0.3 - New blocks added, some error checking and some new options +0.3 - New blocks added, also error checking, new options and schematic rehaul diff --git a/api.txt b/api.txt index 131e3fa..1a68a90 100644 --- a/api.txt +++ b/api.txt @@ -48,21 +48,17 @@ Drop 5x random Tools from list {"dro", {"default:pick_mese", "default:shovel_steel", "default:axe_diamond"}, 5} --= Place Schematic +-= Place Schematic (schematics must be added using lucky_block:add_schematics() before this can be used) -{"sch", "filename / schematic table", position, {schematic xyz offset}, force placement} +{"sch", "schematic name", position, force placement} e.g. -Replace Lucky Block with Tree -{"sch", minetest.get_modpath("default").."/schematics/apple_tree.mts", 0, {x=1, y=0, z=1}, false} +Remove lucky block and build lucky platform in it's place +{"sch", "platform", 0, true} -Place 2x Lava at player position -{"sch", { - size = {x = 1, y = 2, z = 1}, - data = { - {name="default:lava_source", param1=255}, {name="default:lava_source", param1=255}, - }, 1, {x=0, y=0, z=0}, true} +Place apple tree at player position +{"sch", "appletree", 1, false} -= Spawn Entity(s) @@ -164,3 +160,9 @@ lucky_block:add_chest_items({ {name = "default:diamond", max = 1}, {name = "default:pick_steel", max = 1} }) + + +lucky_block:add_schematics({line}) + +This adds a schematic to the main list before adding the actual lucky block +that contains the schematic reference name (see schems.lua for examples). diff --git a/blocks.lua b/blocks.lua index cbeb19b..8d12948 100644 --- a/blocks.lua +++ b/blocks.lua @@ -1,134 +1,7 @@ --- Generate schematics - -local a = "air" -local l = "default:lava_source" -local s = "default:sand" -local d = "default:dirt" -local w = "farming:soil_wet" -local v = "default:water_source" -local c = "farming:cotton_8" -local h = "farming:wheat_8" -local o = "default:obsidian_glass" -local t = "default:sandstone" -local b = "default:sandstonebrick" -local x = "lucky_block:lucky_block" - -local platform = { - size = {x = 5, y = 3, z = 5}, - data = { - -- left slice, middle slice, right slice (bottom to top) - {name=t, param1=255}, {name=t, param1=255}, {name=t, param1=255}, {name=t, param1=255}, {name=t, param1=255}, - {name=b, param1=255}, {name=b, param1=255}, {name=b, param1=255}, {name=b, param1=255}, {name=b, param1=255}, - {name=b, param1=255}, {name=b, param1=255}, {name=b, param1=255}, {name=b, param1=255}, {name=b, param1=255}, - - {name=t, param1=255}, {name=t, param1=255}, {name=t, param1=255}, {name=t, param1=255}, {name=t, param1=255}, - {name=b, param1=255}, {name=x, param1=255}, {name=a, param1=255}, {name=x, param1=255}, {name=b, param1=255}, - {name=b, param1=255}, {name=a, param1=255}, {name=a, param1=255}, {name=a, param1=255}, {name=b, param1=255}, - - {name=t, param1=255}, {name=t, param1=255}, {name=t, param1=255}, {name=t, param1=255}, {name=t, param1=255}, - {name=b, param1=255}, {name=a, param1=255}, {name=a, param1=255}, {name=a, param1=255}, {name=b, param1=255}, - {name=b, param1=255}, {name=a, param1=255}, {name=a, param1=255}, {name=a, param1=255}, {name=b, param1=255}, - - {name=t, param1=255}, {name=t, param1=255}, {name=t, param1=255}, {name=t, param1=255}, {name=t, param1=255}, - {name=b, param1=255}, {name=x, param1=255}, {name=a, param1=255}, {name=x, param1=255}, {name=b, param1=255}, - {name=b, param1=255}, {name=a, param1=255}, {name=a, param1=255}, {name=a, param1=255}, {name=b, param1=255}, - - {name=t, param1=255}, {name=t, param1=255}, {name=t, param1=255}, {name=t, param1=255}, {name=t, param1=255}, - {name=b, param1=255}, {name=b, param1=255}, {name=b, param1=255}, {name=b, param1=255}, {name=b, param1=255}, - {name=b, param1=255}, {name=b, param1=255}, {name=b, param1=255}, {name=b, param1=255}, {name=b, param1=255}, - - }, -} - -local insta_farm = { - size = {x = 5, y = 3, z = 3}, - data = { - -- left slice, middle slice, right slice (bottom to top) - {name=d, param1=255}, {name=d, param1=255}, {name=d, param1=255}, {name=d, param1=255}, {name=d, param1=255}, - {name=w, param1=255}, {name=w, param1=255}, {name=w, param1=255}, {name=w, param1=255}, {name=w, param1=255}, - {name=c, param1=255}, {name=c, param1=255}, {name=c, param1=255}, {name=c, param1=255}, {name=c, param1=255}, - - {name=w, param1=255}, {name=d, param1=255}, {name=d, param1=255}, {name=d, param1=255}, {name=w, param1=255}, - {name=w, param1=255}, {name=v, param1=255}, {name=v, param1=255}, {name=v, param1=255}, {name=w, param1=255}, - {name=c, param1=255}, {name=a, param1=255}, {name=a, param1=255}, {name=a, param1=255}, {name=h, param1=255}, - - {name=d, param1=255}, {name=d, param1=255}, {name=d, param1=255}, {name=d, param1=255}, {name=s, param1=255}, - {name=w, param1=255}, {name=w, param1=255}, {name=w, param1=255}, {name=w, param1=255}, {name=w, param1=255}, - {name=h, param1=255}, {name=h, param1=255}, {name=h, param1=255}, {name=h, param1=255}, {name=h, param1=255}, - - }, -} - -local lava_trap = { - size = {x = 3, y = 6, z = 3}, - data = { - -- left slice, middle slice, right slice (bottom to top) - {name=l, param1=255}, {name=l, param1=255}, {name=l, param1=255}, - {name=a, param1=255}, {name=a, param1=255}, {name=a, param1=255}, - {name=a, param1=255}, {name=a, param1=255}, {name=a, param1=255}, - {name=a, param1=255}, {name=a, param1=255}, {name=a, param1=255}, - {name=a, param1=255}, {name=a, param1=255}, {name=a, param1=255}, - {name=a, param1=255}, {name=a, param1=255}, {name=a, param1=255}, - - {name=l, param1=255}, {name=l, param1=255}, {name=l, param1=255}, - {name=a, param1=255}, {name=a, param1=255}, {name=a, param1=255}, - {name=a, param1=255}, {name=a, param1=255}, {name=a, param1=255}, - {name=a, param1=255}, {name=a, param1=255}, {name=a, param1=255}, - {name=a, param1=255}, {name=a, param1=255}, {name=a, param1=255}, - {name=a, param1=255}, {name=a, param1=255}, {name=a, param1=255}, - - {name=l, param1=255}, {name=l, param1=255}, {name=l, param1=255}, - {name=a, param1=255}, {name=a, param1=255}, {name=a, param1=255}, - {name=a, param1=255}, {name=a, param1=255}, {name=a, param1=255}, - {name=a, param1=255}, {name=a, param1=255}, {name=a, param1=255}, - {name=a, param1=255}, {name=a, param1=255}, {name=a, param1=255}, - {name=a, param1=255}, {name=a, param1=255}, {name=a, param1=255}, - - }, -} - -local sand_trap = { - size = {x = 3, y = 3, z = 3}, - data = { - -- left slice, middle slice, right slice (bottom to top) - {name=s, param1=255}, {name=s, param1=255}, {name=s, param1=255}, - {name=s, param1=255}, {name=s, param1=255}, {name=s, param1=255}, - {name=s, param1=255}, {name=s, param1=255}, {name=s, param1=255}, - - {name=s, param1=255}, {name=s, param1=255}, {name=s, param1=255}, - {name=s, param1=255}, {name=s, param1=255}, {name=s, param1=255}, - {name=s, param1=255}, {name=s, param1=255}, {name=s, param1=255}, - - {name=s, param1=255}, {name=s, param1=255}, {name=s, param1=255}, - {name=s, param1=255}, {name=s, param1=255}, {name=s, param1=255}, - {name=s, param1=255}, {name=s, param1=255}, {name=s, param1=255}, - - }, -} - -local water_trap = { - size = {x = 3, y = 3, z = 3}, - data = { - -- left slice, middle slice, right slice (bottom to top) - {name=o, param1=255}, {name=o, param1=255}, {name=o, param1=255}, - {name=o, param1=255}, {name=o, param1=255}, {name=o, param1=255}, - {name=o, param1=255}, {name=o, param1=255}, {name=o, param1=255}, - - {name=o, param1=255}, {name=o, param1=255}, {name=o, param1=255}, - {name=o, param1=255}, {name=v, param1=255}, {name=o, param1=255}, - {name=o, param1=255}, {name=o, param1=255}, {name=o, param1=255}, - - {name=o, param1=255}, {name=o, param1=255}, {name=o, param1=255}, - {name=o, param1=255}, {name=o, param1=255}, {name=o, param1=255}, - {name=o, param1=255}, {name=o, param1=255}, {name=o, param1=255}, - - }, -} - -- Default blocks lucky_block:add_blocks({ - {"sch", water_trap, 1, {x = 1, y = 0, z = 1}, true}, + {"sch", "watertrap", 1, true}, {"tel"}, {"dro", {"wool:"}, 10, true}, {"dro", {"default:apple"}, 10}, @@ -138,9 +11,9 @@ lucky_block:add_blocks({ {name = "default:wood", max = 3}, {name = "default:pick_diamond", max = 1}, {name = "default:coal_lump", max = 3}}}, - {"sch", sand_trap, 1, {x = 1, y = 0, z = 1}, true}, + {"sch", "sandtrap", 1, true}, {"nod", "flowers:rose", 0}, - {"sch", lava_trap, 1, {x = 1, y = 5, z = 1}, true}, + {"sch", "lava_trap", 1, true}, {"dro", {"default:mese_crystal_fragment", "default:mese_crystal"}, 10}, {"exp"}, {"nod", "default:diamondblock", 0}, @@ -154,7 +27,7 @@ lucky_block:add_blocks({ {"dro", {"default:axe_steel"}, 1}, {"dro", {"default:sword_bronze"}, 1}, {"exp"}, - {"sch", platform, 1, {x = 2, y = 1, z = 2}, true}, + {"sch", "platform", 1, true}, {"nod", "default:wood", 0}, {"dro", {"default:pick_bronze"}, 1}, {"dro", {"default:shovel_bronze"}, 1}, @@ -166,7 +39,7 @@ lucky_block:add_blocks({ if minetest.get_modpath("farming") then lucky_block:add_blocks({ {"dro", {"farming:bread"}, 5}, - {"sch", insta_farm, 0, {x = 2, y = 2, z = 1}, true}, + {"sch", insta_farm, 0, true}, {"nod", "default:water_source", 1}, }) @@ -282,26 +155,38 @@ end -- Ethereal mod if minetest.get_modpath("ethereal") then + local epath = minetest.get_modpath("ethereal") .. "/schematics/" + +lucky_block:add_schematics({ + {"pinetree", epath .. "pinetree.mts", {x = 3, y = 0, z = 3}}, + {"acaciatree", epath .. "acaciatree.mts", {x = 5, y = 0, z = 5}}, + {"palmtree", epath .. "palmtree.mts", {x = 4, y = 0, z = 4}}, + {"appletree", ethereal.appletree, {x = 1, y = 0, z = 1}}, + {"bananatree", ethereal.bananatree, {x = 3, y = 0, z = 3}}, + {"orangetree", ethereal.orangetree, {x = 1, y = 0, z = 1}}, + {"birchtree", ethereal.birchtree, {x = 2, y = 0, z = 2}}, +}) + lucky_block:add_blocks({ {"nod", "ethereal:crystal_spike", 1}, - {"sch", epath .. "pinetree.mts", 0, {x = 3, y = 0, z = 3}}, + {"sch", "pinetree", 0, false}, {"dro", {"ethereal:orange"}, 10}, - {"sch", ethereal.appletree, 0, {x = 1, y = 0, z = 1}}, + {"sch", "appletree", 0, false}, {"dro", {"ethereal:strawberry"}, 10}, - {"sch", ethereal.bananatree, 0, {x = 3, y = 0, z = 3}}, - {"sch", ethereal.orangetree, 0, {x = 1, y = 0, z = 1}}, + {"sch", "bananatree", 0, false}, + {"sch", "orangetree", 0, false}, {"dro", {"ethereal:banana"}, 10}, - {"sch", epath .. "acaciatree.mts", 0, {x = 5, y = 0, z = 5}}, + {"sch", "acaciatree", 0, false}, {"dro", {"ethereal:golden_apple"}, 3}, - {"sch", epath .. "palmtree.mts", 0, {x = 4, y = 0, z = 4}}, + {"sch", "palmtree", 0, false}, {"dro", {"ethereal:tree_sapling", "ethereal:orange_tree_sapling", "ethereal:banana_tree_sapling"}, 10}, {"dro", {"ethereal:green_dirt", "ethereal:prairie_dirt", "ethereal:grove_dirt", "ethereal:cold_dirt"}, 10}, {"dro", {"ethereal:axe_crystal"}, 1}, {"nod", "ethereal:fire_flower", 1}, {"dro", {"ethereal:sword_crystal"}, 1}, {"dro", {"ethereal:pick_crystal"}, 1}, - {"sch", ethereal.birchtree, 0, {x = 2, y = 0, z = 2}}, + {"sch", "birchtree", 0, false}, {"dro", {"ethereal:fish_raw"}, 1}, {"dro", {"ethereal:shovel_crystal"}, 1}, {"dro", {"ethereal:fishing_rod_baited"}, 1}, diff --git a/init.lua b/init.lua index c9fe349..6900737 100644 --- a/init.lua +++ b/init.lua @@ -1,4 +1,5 @@ lucky_block = {} +lucky_schems = {} lucky_block.seed = PseudoRandom(os.time()) @@ -24,8 +25,16 @@ function lucky_block:purge_block_list() } end --- import default blocks +-- add schematics to global list +function lucky_block:add_schematics(list) + for s = 1, #list do + table.insert(lucky_schems, list[s]) + end +end + +-- import default blocks and schematics dofile(minetest.get_modpath("lucky_block").."/blocks.lua") +dofile(minetest.get_modpath("lucky_block").."/schems.lua") -- for random colour selection local all_colours = { @@ -223,22 +232,30 @@ local lucky_block = function(pos, digger) -- place schematic if action == "sch" then - local offset = lucky_list[luck][4] - local switch = lucky_list[luck][3] + if #lucky_schems == 0 then + print ("[lucky block] No schematics") + return + end + local schem = lucky_list[luck][2] - local force = lucky_list[luck][5] or false + local switch = lucky_list[luck][3] or false + local force = lucky_list[luck][4] or true if switch == 1 then pos = digger:getpos() end - minetest.place_schematic( - { - x = pos.x - offset.x, - y = pos.y - offset.y, - z = pos.z - offset.z - }, - schem, "", {}, force) + for i = 1, #lucky_schems do + + if schem == lucky_schems[i][1] then + + local p1 = vector.subtract(pos, lucky_schems[i][3]) + + minetest.place_schematic(p1, lucky_schems[i][2], "", {}, force) + + break + end + end -- place node (if chest then fill chest) elseif action == "nod" then diff --git a/schems.lua b/schems.lua new file mode 100644 index 0000000..a7327f4 --- /dev/null +++ b/schems.lua @@ -0,0 +1,127 @@ + +-- Generate schematics + +local air = {name = "air"} +local san = {name = "default:sand"} +local sst = {name = "default:sandstone"} +local ssb = {name = "default:sandstonebrick"} +local luc = {name = "lucky_block:lucky_block"} +local lav = {name = "default:lava_source"} +local dir = {name = "default:dirt"} +local sow = {name = "farming:soil_wet"} +local wat = {name = "default:water_source"} +local whe = {name = "farming:wheat_8"} +local cot = {name = "farming:cotton_8"} +local obg = {name = "default:obsidian_glass"} + +local platform = { + size = {x = 5, y = 3, z = 5}, + data = { + sst, sst, sst, sst, sst, + ssb, ssb, ssb, ssb, ssb, + ssb, ssb, ssb, ssb, ssb, + + sst, sst, sst, sst, sst, + ssb, luc, air, luc, ssb, + ssb, air, air, air, ssb, + + sst, sst, sst, sst, sst, + ssb, air, air, air, ssb, + ssb, air, air, air, ssb, + + sst, sst, sst, sst, sst, + ssb, luc, air, luc, ssb, + ssb, air, air, air, ssb, + + sst, sst, sst, sst, sst, + ssb, ssb, ssb, ssb, ssb, + ssb, ssb, ssb, ssb, ssb, + }, +} + +local insta_farm = { + size = {x = 5, y = 3, z = 3}, + data = { + dir, dir, dir, dir, dir, + sow, sow, sow, sow, sow, + cot, cot, cot, cot, cot, + + sow, dir, dir, dir, sow, + sow, wat, wat, wat, sow, + cot, air, air, air, whe, + + dir, dir, dir, dir, san, + sow, sow, sow, sow, sow, + whe, whe, whe, whe, whe, + }, +} + +local lava_trap = { + size = {x = 3, y = 6, z = 3}, + data = { + lav, lav, lav, + air, air, air, + air, air, air, + air, air, air, + air, air, air, + air, air, air, + + lav, lav, lav, + air, air, air, + air, air, air, + air, air, air, + air, air, air, + air, air, air, + + lav, lav, lav, + air, air, air, + air, air, air, + air, air, air, + air, air, air, + air, air, air, + }, +} + +local sand_trap = { + size = {x = 3, y = 3, z = 3}, + data = { + san, san, san, + san, san, san, + san, san, san, + + san, san, san, + san, san, san, + san, san, san, + + san, san, san, + san, san, san, + san, san, san, + }, +} + +local water_trap = { + size = {x = 3, y = 3, z = 3}, + data = { + obg, obg, obg, + obg, obg, obg, + obg, obg, obg, + + obg, obg, obg, + obg, wat, obg, + obg, obg, obg, + + obg, obg, obg, + obg, obg, obg, + obg, obg, obg, + }, +} + +-- add schematics to list + +lucky_block:add_schematics({ + {"watertrap", water_trap, {x = 1, y = 0, z = 1}}, + {"sandtrap", sand_trap, {x = 1, y = 0, z = 1}}, + {"lavatrap", lava_trap, {x = 1, y = 5, z = 1}}, + {"platform", platform, {x = 2, y = 1, z = 2}}, + {"instafarm", insta_farm, {x = 2, y = 2, z = 1}}, +})