Store configuration in the world directory.

This commit is contained in:
ShadowNinja 2013-04-25 21:39:08 -04:00
parent 31b1393b21
commit 00328622d9
8 changed files with 122 additions and 73 deletions

1
item_drop/depends.txt Normal file
View File

@ -0,0 +1 @@
technic

View File

@ -1,66 +1,72 @@
dofile(minetest.get_modpath("item_drop").."/item_entity.lua") dofile(minetest.get_modpath("item_drop").."/item_entity.lua")
time_pick = 3 time_pick = 3
minetest.register_globalstep(function(dtime)
for _,player in ipairs(minetest.get_connected_players()) do if technic.config:getBool("enable_item_pickup") then
local pos = player:getpos() minetest.register_globalstep(function(dtime)
pos.y = pos.y+0.5 for _,player in ipairs(minetest.get_connected_players()) do
local inv = player:get_inventory() local pos = player:getpos()
for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, 2)) do pos.y = pos.y+0.5
if not object:is_player() and object:get_luaentity() then local inv = player:get_inventory()
local obj=object:get_luaentity() for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, 2)) do
if obj.name == "__builtin:item" then if not object:is_player() and object:get_luaentity() then
if inv:room_for_item("main", ItemStack(obj.itemstring)) then local obj=object:get_luaentity()
if obj.timer > time_pick then if obj.name == "__builtin:item" then
inv:add_item("main", ItemStack(obj.itemstring)) if inv:room_for_item("main", ItemStack(obj.itemstring)) then
if obj.itemstring ~= "" then if obj.timer > time_pick then
minetest.sound_play("item_drop_pickup",{pos = pos, gain = 1.0, max_hear_distance = 10}) inv:add_item("main", ItemStack(obj.itemstring))
end if obj.itemstring ~= "" then
if object:get_luaentity() then minetest.sound_play("item_drop_pickup",{pos = pos, gain = 1.0, max_hear_distance = 10})
object:get_luaentity().itemstring = "" end
object:remove() if object:get_luaentity() then
object:get_luaentity().itemstring = ""
object:remove()
end
end end
end end
end end
end end
end end
end end
end end)
end) end
function minetest.handle_node_drops(pos, drops, digger) if technic.config:getBool("enable_item_drop") then
for _,item in ipairs(drops) do function minetest.handle_node_drops(pos, drops, digger)
local count, name for _,item in ipairs(drops) do
if type(item) == "string" then local count, name
count = 1 if type(item) == "string" then
name = item count = 1
else name = item
count = item:get_count() else
name = item:get_name() count = item:get_count()
end name = item:get_name()
for i=1,count do end
local obj = minetest.env:add_item(pos, name) for i=1,count do
if obj ~= nil then local obj = minetest.env:add_item(pos, name)
obj:get_luaentity().collect = true if obj ~= nil then
local x = math.random(1, 5) obj:get_luaentity().collect = true
if math.random(1,2) == 1 then local x = math.random(1, 5)
x = -x if math.random(1,2) == 1 then
end x = -x
local z = math.random(1, 5) end
if math.random(1,2) == 1 then local z = math.random(1, 5)
z = -z if math.random(1,2) == 1 then
end z = -z
obj:setvelocity({x=1/x, y=obj:getvelocity().y, z=1/z}) end
obj:get_luaentity().timer = time_pick obj:setvelocity({x=1/x, y=obj:getvelocity().y, z=1/z})
-- FIXME this doesnt work for deactiveted objects obj:get_luaentity().timer = time_pick
if minetest.setting_get("remove_items") and tonumber(minetest.setting_get("remove_items")) then -- FIXME this doesnt work for deactiveted objects
minetest.after(tonumber(minetest.setting_get("remove_items")), function(obj) if minetest.setting_get("remove_items") and tonumber(minetest.setting_get("remove_items")) then
obj:remove() minetest.after(tonumber(minetest.setting_get("remove_items")), function(obj)
end, obj) obj:remove()
end, obj)
end
end end
end end
end end
end end
end end
--[[ --[[
minetest.register_on_dieplayer(function(name, pos) minetest.register_on_dieplayer(function(name, pos)
local inv = name:get_inventory() local inv = name:get_inventory()

View File

@ -1,7 +1,42 @@
enable_technic_inventory=true technic.config = {}
enable_mining_drill=true
enable_mining_laser=true technic.config.loaded = {}
enable_flashlight=true
enable_rubber_tree_generation=true technic.config.default = {
enable_marble_generation=true enable_mining_drill = "true",
enable_granite_generation=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

View File

@ -2,5 +2,3 @@ default
moreores moreores
pipeworks pipeworks
mesecons mesecons
technic_worldgen

View File

@ -2,6 +2,8 @@
-- namespace: technic -- namespace: technic
-- (c) 2012-2013 by RealBadAngel <mk@realbadangel.pl> -- (c) 2012-2013 by RealBadAngel <mk@realbadangel.pl>
technic = {}
modpath=minetest.get_modpath("technic") modpath=minetest.get_modpath("technic")
--Read technic config file --Read technic config file
@ -38,9 +40,9 @@ dofile(modpath.."/forcefield.lua")
dofile(modpath.."/wires_hv.lua") dofile(modpath.."/wires_hv.lua")
--Tools --Tools
if enable_mining_drill==true then dofile(modpath.."/mining_drill.lua") end if technic.config:getBool("enable_mining_drill") then dofile(modpath.."/mining_drill.lua") end
if enable_mining_laser==true then dofile(modpath.."/mining_laser_mk1.lua") end if technic.config:getBool("enable_mining_laser") then dofile(modpath.."/mining_laser_mk1.lua") end
if enable_flashlight==true then dofile(modpath.."/flashlight.lua") end if technic.config:getBool("enable_flashlight") then dofile(modpath.."/flashlight.lua") end
dofile(modpath.."/cans.lua") dofile(modpath.."/cans.lua")
dofile(modpath.."/chainsaw.lua") dofile(modpath.."/chainsaw.lua")
dofile(modpath.."/tree_tap.lua") dofile(modpath.."/tree_tap.lua")

View File

@ -88,14 +88,12 @@ minetest.register_abm({
end end
}) })
minetest.register_on_generated(function(minp, maxp, blockseed) if technic.config:getBool("enable_rubber_tree_generation") then
if math.random(1, 100) > 5 then minetest.register_on_generated(function(minp, maxp, blockseed)
return if math.random(1, 100) > 5 then
end return
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} end
local pos = minetest.env:find_node_near(tmp, maxp.x-minp.x, {"default:dirt_with_grass"}) local rubber_tree={
if pos ~= nil then
rubber_tree={
axiom="FFFFA", axiom="FFFFA",
rules_a="[&FFBFA]////[&BFFFA]////[&FBFFA]", rules_a="[&FFBFA]////[&BFFFA]////[&FBFFA]",
rules_b="[&FFA]////[&FFA]////[&FFA]", rules_b="[&FFA]////[&FFA]////[&FFA]",
@ -107,10 +105,14 @@ minetest.register_on_generated(function(minp, maxp, blockseed)
thin_trunks=false; thin_trunks=false;
fruit_tree=false, fruit_tree=false,
fruit="" fruit=""
} }
minetest.env:spawn_tree({x=pos.x, y=pos.y+1, z=pos.z},rubber_tree) 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}
end local pos = minetest.env:find_node_near(tmp, maxp.x-minp.x, {"default:dirt_with_grass"})
end) if pos ~= nil then
minetest.env:spawn_tree({x=pos.x, y=pos.y+1, z=pos.z}, rubber_tree)
end
end)
end
-- ========= FUEL ========= -- ========= FUEL =========

View File

@ -1 +1,2 @@
default default
technic

View File

@ -28,6 +28,7 @@ minetest.register_ore({
height_min = -31000, height_min = -31000,
height_max = 2, height_max = 2,
}) })
if technic.config:getBool("enable_marble_generation") then
minetest.register_ore({ minetest.register_ore({
ore_type = "sheet", ore_type = "sheet",
ore = "technic:marble", ore = "technic:marble",
@ -40,6 +41,8 @@ minetest.register_ore({
noise_threshhold = 0.4, noise_threshhold = 0.4,
noise_params = {offset=0, scale=15, spread={x=150, y=150, z=150}, seed=23, octaves=3, persist=0.70} 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({ minetest.register_ore({
ore_type = "sheet", ore_type = "sheet",
ore = "technic:granite", ore = "technic:granite",
@ -52,4 +55,5 @@ minetest.register_ore({
noise_threshhold = 0.4, noise_threshhold = 0.4,
noise_params = {offset=0, scale=15, spread={x=130, y=130, z=130}, seed=24, octaves=3, persist=0.70} noise_params = {offset=0, scale=15, spread={x=130, y=130, z=130}, seed=24, octaves=3, persist=0.70}
}) })
end