Use tabs for indentation

This commit is contained in:
Hybrid Dog 2017-09-06 15:51:34 +02:00
parent 04c441768f
commit bfcc14bb4b

285
init.lua

@ -1,154 +1,175 @@
if minetest.settings:get_bool("enable_item_pickup") ~= false then if minetest.settings:get_bool("enable_item_pickup") ~= false then
local pickup_gain = tonumber(minetest.settings:get("item_pickup_gain")) or 0.4 local pickup_gain = tonumber(minetest.settings:get("item_pickup_gain"))
local pickup_radius = tonumber(minetest.settings:get("item_pickup_radius")) or 0.75 or 0.4
local key_triggered = minetest.settings:get_bool("enable_item_pickup_key") ~= false local pickup_radius = tonumber(minetest.settings:get("item_pickup_radius"))
local keytype or 0.75
if key_triggered then local key_triggered = minetest.settings:get_bool("enable_item_pickup_key")
keytype = minetest.settings:get("item_pickup_keytype") or "Use" ~= false
end local keytype
local damage_enabled = minetest.settings:get_bool("enable_damage") if key_triggered then
keytype = minetest.settings:get("item_pickup_keytype") or "Use"
end
local damage_enabled = minetest.settings:get_bool("enable_damage")
local function pickupfunc() local function pickupfunc()
for _,player in ipairs(minetest.get_connected_players()) do for _,player in ipairs(minetest.get_connected_players()) do
local keys_pressed = not key_triggered local keys_pressed = not key_triggered
local control = player:get_player_control() local control = player:get_player_control()
if keytype == "Use" then if keytype == "Use" then
keys_pressed = control.aux1 keys_pressed = control.aux1
elseif keytype == "Sneak" then elseif keytype == "Sneak" then
keys_pressed = control.sneak keys_pressed = control.sneak
elseif keytype == "LeftAndRight" then -- LeftAndRight combination elseif keytype == "LeftAndRight" then -- LeftAndRight combination
keys_pressed = control.left and control.right keys_pressed = control.left and control.right
elseif keytype == "RMB" then elseif keytype == "RMB" then
keys_pressed = control.RMB keys_pressed = control.RMB
elseif keytype == "SneakAndRMB" then -- SneakAndRMB combination elseif keytype == "SneakAndRMB" then -- SneakAndRMB combination
keys_pressed = control.sneak and control.RMB keys_pressed = control.sneak and control.RMB
end end
if not keys_pressed if not keys_pressed
or (damage_enabled and player:get_hp() <= 0) then or (damage_enabled and player:get_hp() <= 0) then
return return
end end
local pos = player:getpos() local pos = player:getpos()
pos.y = pos.y+0.5 pos.y = pos.y+0.5
local inv = player:get_inventory() local inv = player:get_inventory()
local objectlist = minetest.get_objects_inside_radius(pos, pickup_radius) local objectlist = minetest.get_objects_inside_radius(pos,
for _,object in ipairs(objectlist) do pickup_radius)
if not object:is_player() for _,object in ipairs(objectlist) do
and object:get_luaentity() if not object:is_player()
and object:get_luaentity().name == "__builtin:item" then and object:get_luaentity()
local pos2 = object:getpos() and object:get_luaentity().name == "__builtin:item" then
local distance = math.sqrt(((pos2.x - pos.x) * (pos2.x - pos.x)) + ((pos2.y - pos.y) * (pos2.y - pos.y)) local pos2 = object:getpos()
+ ((pos2.z - pos.z) * (pos2.z - pos.z))) local distance = vector.distance(pos, pos2)
if distance <= 1 then if distance <= 1 then
if inv and inv:room_for_item("main", ItemStack(object:get_luaentity().itemstring)) then if inv
inv:add_item("main", ItemStack(object:get_luaentity().itemstring)) and inv:room_for_item("main",
if object:get_luaentity().itemstring ~= "" then ItemStack(object:get_luaentity().itemstring)
minetest.sound_play("item_drop_pickup", { ) then
to_player = player:get_player_name(), inv:add_item("main", ItemStack(
gain = pickup_gain, object:get_luaentity().itemstring))
}) if object:get_luaentity().itemstring ~= "" then
end minetest.sound_play("item_drop_pickup", {
object:get_luaentity().itemstring = "" to_player = player:get_player_name(),
object:remove() gain = pickup_gain,
end })
else end
if object:get_luaentity().collect then object:get_luaentity().itemstring = ""
if inv and inv:room_for_item("main", ItemStack(object:get_luaentity().itemstring)) then object:remove()
local pos1 = pos end
pos1.y = pos1.y+0.2 else
local vec = {x=pos1.x-pos2.x, y=pos1.y-pos2.y, z=pos1.z-pos2.z} if object:get_luaentity().collect then
vec.x = vec.x*3 if inv
vec.y = vec.y*3 and inv:room_for_item("main",
vec.z = vec.z*3 ItemStack(object:get_luaentity().itemstring)
object:setvelocity(vec) ) then
object:get_luaentity().physical_state = false local pos1 = pos
object:get_luaentity().object:set_properties({ pos1.y = pos1.y+0.2
physical = false local vec = {x=pos1.x-pos2.x, y=pos1.y-pos2.y,
}) z=pos1.z-pos2.z}
vec.x = vec.x*3
vec.y = vec.y*3
vec.z = vec.z*3
object:setvelocity(vec)
object:get_luaentity().physical_state = false
object:get_luaentity().object:set_properties({
physical = false
})
minetest.after(1, function() minetest.after(1, function()
local lua = object:get_luaentity() local lua = object:get_luaentity()
if not lua or not lua.itemstring then if not lua or not lua.itemstring then
return return
end end
if inv:room_for_item("main", ItemStack(object:get_luaentity().itemstring)) then if inv:room_for_item("main",
inv:add_item("main", ItemStack(object:get_luaentity().itemstring)) ItemStack(object:get_luaentity(
if object:get_luaentity().itemstring ~= "" then ).itemstring)
minetest.sound_play("item_drop_pickup", { ) then
to_player = player:get_player_name(), inv:add_item("main",
gain = pickup_gain, ItemStack(object:get_luaentity(
}) ).itemstring))
end if object:get_luaentity().itemstring ~= "" then
object:get_luaentity().itemstring = "" minetest.sound_play("item_drop_pickup", {
object:remove() to_player = player:get_player_name(),
else gain = pickup_gain,
object:setvelocity({x=0,y=0,z=0}) })
object:get_luaentity().physical_state = true end
object:get_luaentity().object:set_properties({ object:get_luaentity().itemstring = ""
physical = true object:remove()
}) else
end object:setvelocity({x=0,y=0,z=0})
end, {player, object}) object:get_luaentity().physical_state = true
end object:get_luaentity().object:set_properties({
end physical = true
end })
end end
end end, {player, object})
end end
end end
end
end
end
end
end
local function pickup_step() local function pickup_step()
pickupfunc() pickupfunc()
minetest.after(0.2, pickup_step) minetest.after(0.2, pickup_step)
end end
minetest.after(3.0, pickup_step) minetest.after(3.0, pickup_step)
end end
if minetest.settings:get_bool("enable_item_drop") ~= false then if minetest.settings:get_bool("enable_item_drop") ~= false then
function minetest.handle_node_drops(pos, drops, digger) function minetest.handle_node_drops(pos, drops, digger)
local inv local inv
local diggerPos = pos local diggerPos = pos
if minetest.settings:get_bool("creative_mode") and digger and digger:is_player() then if minetest.settings:get_bool("creative_mode")
inv = digger:get_inventory() and digger
diggerPos = digger:getpos() and digger:is_player() then
end inv = digger:get_inventory()
diggerPos = digger:getpos()
end
for _,item in ipairs(drops) do for _,item in ipairs(drops) do
local count, name local count, name
if type(item) == "string" then if type(item) == "string" then
count = 1 count = 1
name = item name = item
else else
count = item:get_count() count = item:get_count()
name = item:get_name() name = item:get_name()
end end
if not inv or not inv:contains_item("main", ItemStack(name)) then if not inv or not inv:contains_item("main", ItemStack(name)) then
for i=1,count do for i=1,count do
local adjustedPos = {x=diggerPos.x, y=diggerPos.y, z=diggerPos.z} local adjustedPos = {x=diggerPos.x, y=diggerPos.y,
local obj = minetest.add_item(adjustedPos, name) z=diggerPos.z}
local obj = minetest.add_item(adjustedPos, name)
if obj ~= nil then if obj ~= nil then
obj:get_luaentity().collect = true obj:get_luaentity().collect = true
local x = math.random(1, 5) local x = math.random(1, 5)
if math.random(1,2) == 1 then x = -x end if math.random(1,2) == 1 then x = -x end
local z = math.random(1, 5) local z = math.random(1, 5)
if math.random(1,2) == 1 then z = -z end if math.random(1,2) == 1 then z = -z end
obj:setvelocity({x=1/x, y=obj:getvelocity().y, z=1/z}) obj:setvelocity({x=1/x, y=obj:getvelocity().y, z=1/z})
end end
end end
end end
end end
end end
end end
if minetest.settings:get("log_mods") then minetest.log("action", "[Mod] item_drop loaded") end if minetest.settings:get("log_mods") then
minetest.log("action", "[Mod] item_drop loaded")
end