diff --git a/README.md b/README.md index d9045f9..d7f3e70 100644 --- a/README.md +++ b/README.md @@ -33,4 +33,48 @@ TODO: Detect AFK player ------------------ -AFK (away from keyboard) is detected when player doesn't move for certain time, player will sit down. \ No newline at end of file +AFK (away from keyboard) is detected when player doesn't move for certain time, player will sit down. + +===ITEM_DROP MOD for MINETEST-C55=== +------------------------------------- +by PilzAdam + +Introduction: +This mod adds Minecraft like drop/pick up of items to Minetest. + +How to install: +Unzip the archive an place it in minetest-base-directory/mods/minetest/ +if you have a windows client or a linux run-in-place client. If you have +a linux system-wide instalation place it in ~/.minetest/mods/minetest/. +If you want to install this mod only in one world create the folder +worldmods/ in your worlddirectory. +For further information or help see: +http://wiki.minetest.com/wiki/Installing_Mods + +How to use the mod: +Just install it an everything works. + +For developers: +You dont have to use get_drops() anymore because of changes in the +builtin files of minetest. + +License: +Sourcecode: WTFPL (see below) +Sound: WTFPL (see below) + +See also: +http://minetest.net/ + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 + + Copyright (C) 2004 Sam Hocevar + + Everyone is permitted to copy and distribute verbatim or modified + copies of this license document, and changing it is allowed as long + as the name is changed. + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. You just DO WHAT THE FUCK YOU WANT TO. diff --git a/init.lua b/init.lua index bc5e144..ddc64b7 100644 --- a/init.lua +++ b/init.lua @@ -38,6 +38,13 @@ if SPAWN_POINT then print("[Mod][enhancements] SPAWN_POINT enabled") end +-- pick dropped items by holding shift (sneak) +if ITEM_DROP then + dofile(minetest.get_modpath("enhancements").."/item_drop.lua") + + print("[Mod][enhancements] ITEM_DROP enabled") +end + -- manage privileges i areas mod - if using areas mod only for admin purposes -- WIP DONT ENABLE! if AREAS_ENHANCE and minetest.get_modpath("areas") then diff --git a/item_drop.lua b/item_drop.lua new file mode 100644 index 0000000..08fcff8 --- /dev/null +++ b/item_drop.lua @@ -0,0 +1,82 @@ +minetest.register_globalstep(function(dtime) + for _,player in ipairs(minetest.get_connected_players()) do + if player:get_player_control().sneak and (player:get_hp() > 0 or not minetest.setting_getbool("enable_damage")) then + + if player:get_player_control().aux1 then + return + end + + pick_dropped_items(player) + end + end +end) + +function pick_dropped_items(player) + local pos = player:getpos() + pos.y = pos.y+0.5 + local inv = player:get_inventory() + + --collection + for _,object in ipairs(minetest.get_objects_inside_radius(pos, 1)) do + if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "__builtin:item" then + if inv and inv:room_for_item("main", ItemStack(object:get_luaentity().itemstring)) then + inv:add_item("main", ItemStack(object:get_luaentity().itemstring)) + if object:get_luaentity().itemstring ~= "" then + minetest.sound_play("item_drop_pickup", { + to_player = player:get_player_name(), + gain = 0.4, + }) + end + object:get_luaentity().itemstring = "" + object:remove() + end + end + end + + --magnet + for _,object in ipairs(minetest.get_objects_inside_radius(pos, 2)) do + if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "__builtin:item" then + if object:get_luaentity().collect then + if inv and inv:room_for_item("main", ItemStack(object:get_luaentity().itemstring)) then + local pos1 = pos + pos1.y = pos1.y+0.2 + local pos2 = object:getpos() + 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:moveto(vec) + object:get_luaentity().physical_state = false + object:get_luaentity().object:set_properties({ + physical = false + }) + + minetest.after(1, function(args) + local lua = object:get_luaentity() + if object == nil or lua == nil or lua.itemstring == nil then + return + end + if inv:room_for_item("main", ItemStack(object:get_luaentity().itemstring)) then + inv:add_item("main", ItemStack(object:get_luaentity().itemstring)) + if object:get_luaentity().itemstring ~= "" then + minetest.sound_play("item_drop_pickup", { + to_player = player:get_player_name(), + gain = 0.4, + }) + end + object:get_luaentity().itemstring = "" + object:remove() + else + object:moveto(pos, false) + object:get_luaentity().physical_state = true + object:get_luaentity().object:set_properties({ + physical = true + }) + end + end, {player, object}) + + end + end + end + end +end diff --git a/settings.txt b/settings.txt index 8146113..482ea76 100644 --- a/settings.txt +++ b/settings.txt @@ -3,4 +3,5 @@ CLEAN_UNKNOWN = true EXTERNAL_CMD = true PLAYER_AFK = true SPAWN_POINT = true +ITEM_DROP = true AREAS_ENHANCE = false diff --git a/sounds/item_drop_pickup.1.ogg b/sounds/item_drop_pickup.1.ogg new file mode 100644 index 0000000..2ae432d Binary files /dev/null and b/sounds/item_drop_pickup.1.ogg differ diff --git a/sounds/item_drop_pickup.2.ogg b/sounds/item_drop_pickup.2.ogg new file mode 100644 index 0000000..f58bf08 Binary files /dev/null and b/sounds/item_drop_pickup.2.ogg differ diff --git a/sounds/item_drop_pickup.3.ogg b/sounds/item_drop_pickup.3.ogg new file mode 100644 index 0000000..cf57c94 Binary files /dev/null and b/sounds/item_drop_pickup.3.ogg differ diff --git a/sounds/item_drop_pickup.4.ogg b/sounds/item_drop_pickup.4.ogg new file mode 100644 index 0000000..bfe99d9 Binary files /dev/null and b/sounds/item_drop_pickup.4.ogg differ