Store configuration in the world directory.
authorShadowNinja <noreply@gmail.com>
Fri, 26 Apr 2013 01:39:08 +0000 (21:39 -0400)
committerShadowNinja <noreply@gmail.com>
Sat, 27 Apr 2013 17:53:12 +0000 (13:53 -0400)
item_drop/depends.txt [new file with mode: 0644]
item_drop/init.lua
technic/config.lua
technic/depends.txt
technic/init.lua
technic/rubber.lua
technic_worldgen/depends.txt
technic_worldgen/oregen.lua

diff --git a/item_drop/depends.txt b/item_drop/depends.txt
new file mode 100644 (file)
index 0000000..b88d3ff
--- /dev/null
@@ -0,0 +1 @@
+technic
index a25a3b5a3772ff0b4cb344b0c0a29231343e4331..db1f2a34e0cd118d60a7511d4efafba12bae34bd 100644 (file)
@@ -1,66 +1,72 @@
 dofile(minetest.get_modpath("item_drop").."/item_entity.lua")
 time_pick = 3
-minetest.register_globalstep(function(dtime)
-       for _,player in ipairs(minetest.get_connected_players()) do
-               local pos = player:getpos()
-               pos.y = pos.y+0.5
-               local inv = player:get_inventory()
-               for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, 2)) do
-                       if not object:is_player() and object:get_luaentity() then 
-                               local obj=object:get_luaentity() 
-                               if obj.name == "__builtin:item" then
-                                       if inv:room_for_item("main", ItemStack(obj.itemstring)) then
-                                               if obj.timer > time_pick then
-                                                       inv:add_item("main", ItemStack(obj.itemstring))
-                                                       if obj.itemstring ~= "" then
-                                                               minetest.sound_play("item_drop_pickup",{pos = pos, gain = 1.0, max_hear_distance = 10}) 
-                                                       end
-                                                       if object:get_luaentity() then 
-                                                               object:get_luaentity().itemstring = ""
-                                                               object:remove()
+
+if technic.config:getBool("enable_item_pickup") then
+       minetest.register_globalstep(function(dtime)
+               for _,player in ipairs(minetest.get_connected_players()) do
+                       local pos = player:getpos()
+                       pos.y = pos.y+0.5
+                       local inv = player:get_inventory()
+                       for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, 2)) do
+                               if not object:is_player() and object:get_luaentity() then
+                                       local obj=object:get_luaentity()
+                                       if obj.name == "__builtin:item" then
+                                               if inv:room_for_item("main", ItemStack(obj.itemstring)) then
+                                                       if obj.timer > time_pick then
+                                                               inv:add_item("main", ItemStack(obj.itemstring))
+                                                               if obj.itemstring ~= "" then
+                                                                       minetest.sound_play("item_drop_pickup",{pos = pos, gain = 1.0, max_hear_distance = 10}) 
+                                                               end
+                                                               if object:get_luaentity() then
+                                                                       object:get_luaentity().itemstring = ""
+                                                                       object:remove()
+                                                               end
                                                        end
                                                end
                                        end
                                end
                        end
                end
-       end
-end)
+       end)
+end
 
-function minetest.handle_node_drops(pos, drops, digger)
-       for _,item in ipairs(drops) do
-               local count, name
-               if type(item) == "string" then
-                       count = 1
-                       name = item
-               else
-                       count = item:get_count()
-                       name = item:get_name()
-               end
-               for i=1,count do
-                       local obj = minetest.env:add_item(pos, name)
-                       if obj ~= nil then
-                               obj:get_luaentity().collect = true
-                               local x = math.random(1, 5)
-                               if math.random(1,2) == 1 then
-                                       x = -x
-                               end
-                               local z = math.random(1, 5)
-                               if math.random(1,2) == 1 then
-                                       z = -z
-                               end
-                               obj:setvelocity({x=1/x, y=obj:getvelocity().y, z=1/z})
-                               obj:get_luaentity().timer = time_pick
-                               -- FIXME this doesnt work for deactiveted objects
-                               if minetest.setting_get("remove_items") and tonumber(minetest.setting_get("remove_items")) then
-                                       minetest.after(tonumber(minetest.setting_get("remove_items")), function(obj)
-                                               obj:remove()
-                                       end, obj)
+if technic.config:getBool("enable_item_drop") then
+       function minetest.handle_node_drops(pos, drops, digger)
+               for _,item in ipairs(drops) do
+                       local count, name
+                       if type(item) == "string" then
+                               count = 1
+                               name = item
+                       else
+                               count = item:get_count()
+                               name = item:get_name()
+                       end
+                       for i=1,count do
+                               local obj = minetest.env:add_item(pos, name)
+                               if obj ~= nil then
+                                       obj:get_luaentity().collect = true
+                                       local x = math.random(1, 5)
+                                       if math.random(1,2) == 1 then
+                                               x = -x
+                                       end
+                                       local z = math.random(1, 5)
+                                       if math.random(1,2) == 1 then
+                                               z = -z
+                                       end
+                                       obj:setvelocity({x=1/x, y=obj:getvelocity().y, z=1/z})
+                                       obj:get_luaentity().timer = time_pick
+                                       -- FIXME this doesnt work for deactiveted objects
+                                       if minetest.setting_get("remove_items") and tonumber(minetest.setting_get("remove_items")) then
+                                               minetest.after(tonumber(minetest.setting_get("remove_items")), function(obj)
+                                                       obj:remove()
+                                               end, obj)
+                                       end
                                end
                        end
                end
        end
 end
+
 --[[
 minetest.register_on_dieplayer(function(name, pos)
        local inv = name:get_inventory()
index f2379686c8feffad7b46cfa9f9170600e63621c4..f546cf63c28fd84125ce6f65f2541103f223777e 100644 (file)
@@ -1,7 +1,42 @@
-enable_technic_inventory=true
-enable_mining_drill=true
-enable_mining_laser=true
-enable_flashlight=true
-enable_rubber_tree_generation=true
-enable_marble_generation=true
-enable_granite_generation=true
+technic.config = {}
+
+technic.config.loaded = {}
+
+technic.config.default = {
+       enable_mining_drill = "true",
+       enable_mining_laser = "true",
+       enable_flashlight = "true",
+       enable_item_drop = "true",
+       enable_item_pickup = "true",
+       enable_rubber_tree_generation = "true",
+       enable_marble_generation = "true",
+       enable_granite_generation = "true"
+}
+
+function technic.config:load(filename)
+       file, error = io.open(filename, "r")
+       if error then return end
+       local line = file:read("*l")
+       while line do
+               local found, _, setting, value = line:find("^([^#%s=]+)%s?=%s?([^%s#]+)")
+               if found then
+                       self.loaded[setting] = value
+               end
+               line = file:read("*l")
+       end
+       file:close()
+end
+
+technic.config:load(minetest.get_worldpath().."/technic.conf")
+
+function technic.config:get(setting)
+       if self.loaded[setting] then
+               return self.loaded[setting]
+       else
+               return self.default[setting]
+       end
+end
+
+function technic.config:getBool(setting)
+       return string.lower(self:get(setting)) == "true"
+end
index f034c60a431149376d777403cc7c9252f7c60a1e..3859f8ae732e41820626dda804f97f39ef8c6daa 100644 (file)
@@ -2,5 +2,3 @@ default
 moreores
 pipeworks
 mesecons
-technic_worldgen
-
index 2b85d2697cc3d8c46b281e014d72241b033db364..7f303c1a9cb62e8d60cf118d6b3a07ae7bcaea4e 100644 (file)
@@ -2,6 +2,8 @@
 -- namespace: technic
 -- (c) 2012-2013 by RealBadAngel <mk@realbadangel.pl>
 
+technic = {}
+
 modpath=minetest.get_modpath("technic")
 
 --Read technic config file
@@ -38,9 +40,9 @@ dofile(modpath.."/forcefield.lua")
 dofile(modpath.."/wires_hv.lua")
 
 --Tools
-if enable_mining_drill==true then dofile(modpath.."/mining_drill.lua") end
-if enable_mining_laser==true then dofile(modpath.."/mining_laser_mk1.lua") end
-if enable_flashlight==true then dofile(modpath.."/flashlight.lua") end
+if technic.config:getBool("enable_mining_drill") then dofile(modpath.."/mining_drill.lua") end
+if technic.config:getBool("enable_mining_laser") then dofile(modpath.."/mining_laser_mk1.lua") end
+if technic.config:getBool("enable_flashlight") then dofile(modpath.."/flashlight.lua") end
 dofile(modpath.."/cans.lua")
 dofile(modpath.."/chainsaw.lua")
 dofile(modpath.."/tree_tap.lua")
index 0e530ffd7c1b892574e0392841f6437995824036..6ec9731abbb10c509beb8f7348d74d0be2cea2eb 100644 (file)
@@ -88,14 +88,12 @@ minetest.register_abm({
        end
 })
 
-minetest.register_on_generated(function(minp, maxp, blockseed)
-       if math.random(1, 100) > 5 then
-               return
-       end
-       local tmp = {x=(maxp.x-minp.x)/2+minp.x, y=(maxp.y-minp.y)/2+minp.y, z=(maxp.z-minp.z)/2+minp.z}
-       local pos = minetest.env:find_node_near(tmp, maxp.x-minp.x, {"default:dirt_with_grass"})
-       if pos ~= nil then
-                       rubber_tree={
+if technic.config:getBool("enable_rubber_tree_generation") then
+       minetest.register_on_generated(function(minp, maxp, blockseed)
+               if math.random(1, 100) > 5 then
+                       return
+               end
+               local rubber_tree={
                        axiom="FFFFA",
                        rules_a="[&FFBFA]////[&BFFFA]////[&FBFFA]",
                        rules_b="[&FFA]////[&FFA]////[&FFA]",
@@ -107,10 +105,14 @@ minetest.register_on_generated(function(minp, maxp, blockseed)
                        thin_trunks=false;
                        fruit_tree=false,
                        fruit=""
-                       }
-                       minetest.env:spawn_tree({x=pos.x, y=pos.y+1, z=pos.z},rubber_tree)
-       end
-end)
+               }
+               local tmp = {x=(maxp.x-minp.x)/2+minp.x, y=(maxp.y-minp.y)/2+minp.y, z=(maxp.z-minp.z)/2+minp.z}
+               local pos = minetest.env:find_node_near(tmp, maxp.x-minp.x, {"default:dirt_with_grass"})
+               if pos ~= nil then
+                       minetest.env:spawn_tree({x=pos.x, y=pos.y+1, z=pos.z}, rubber_tree)
+               end
+       end)
+end
 
 
 -- ========= FUEL =========
index 4ad96d51599fb734101f6229f6c1a8a509bd6255..d684218158898725e421f1b6b104c22678427b71 100644 (file)
@@ -1 +1,2 @@
 default
+technic
index b17e4382a195362fc66917f00c49810364c68027..50f5415e2cba15919e606d160c581bde4397416a 100644 (file)
@@ -28,6 +28,7 @@ minetest.register_ore({
        height_min     = -31000,
        height_max     = 2,
 })
+if technic.config:getBool("enable_marble_generation") then
 minetest.register_ore({
        ore_type       = "sheet",
        ore            = "technic:marble",
@@ -40,6 +41,8 @@ minetest.register_ore({
        noise_threshhold = 0.4,
        noise_params = {offset=0, scale=15, spread={x=150, y=150, z=150}, seed=23, octaves=3, persist=0.70}
 })
+end
+if technic.config:getBool("enable_granite_generation") then
 minetest.register_ore({
        ore_type       = "sheet",
        ore            = "technic:granite",
@@ -52,4 +55,5 @@ minetest.register_ore({
        noise_threshhold = 0.4,
        noise_params = {offset=0, scale=15, spread={x=130, y=130, z=130}, seed=24, octaves=3, persist=0.70}
 })
+end