Add sneak pickup a.k.a Survival X sneak

This commit is contained in:
Juraj Vajda 2023-02-22 20:56:27 -05:00
parent a5ebce011f
commit aef135c7ae
10 changed files with 159 additions and 0 deletions

View File

@ -991,6 +991,13 @@ GNU Lesser General Public License v2.1 or later (see included LICENSE file)
- everness_ambience_ice_cracking_2
- everness_ambience_ice_cracking_3
**CC0-1.0, by onikage22**, https://freesound.org
- everness_item_drop_pickup.1.ogg
- everness_item_drop_pickup.2.ogg
- everness_item_drop_pickup.3.ogg
- everness_item_drop_pickup.4.ogg
### Models
**CC-BY-SA-4.0, by SaKeL**

View File

@ -9,6 +9,8 @@ It also adds structures, dungeons with loot chests, and custom skyboxes based on
## Features
* player name tag will hide when sneaking
* item magnet pickup when holding sneak
* granular biome settings
* custom sounds for some blocks, biomes
* custom textures

View File

@ -516,6 +516,9 @@ Everness = {
y_max = tonumber(minetest.settings:get('everness_forsaken_tundra_under_y_max')) or -256,
y_min = tonumber(minetest.settings:get('everness_forsaken_tundra_under_y_min')) or -31000,
},
},
features = {
everness_feature_sneak_pickup = minetest.settings:get_bool('everness_feature_sneak_pickup', true),
}
},
}

View File

@ -166,6 +166,10 @@ dofile(path .. '/loot_chests.lua')
dofile(path .. '/skybox.lua')
dofile(path .. '/env_sounds.lua')
if Everness.settings.features.everness_feature_sneak_pickup then
dofile(path .. '/sneak_pickup.lua')
end
local mod_end_time = (minetest.get_us_time() - mod_start_time) / 1000000
print('[Mod] everness loaded.. [' .. mod_end_time .. 's]')

View File

@ -324,3 +324,8 @@ everness_forsaken_tundra_under_y_max (y max) int -256
# Lower limit for biome.
everness_forsaken_tundra_under_y_min (y min) int -31000
[Features]
# Enable/ Disable Item pick up with sneak key
# [Shift + E + Q] single drop item
everness_feature_sneak_pickup (Sneak Pickup) bool true

138
sneak_pickup.lua Normal file
View File

@ -0,0 +1,138 @@
--[[
Everness. Never ending discovery in Everness mapgen.
Copyright (C) 2023 SaKeL <juraj.vajda@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to juraj.vajda@gmail.com
--]]
local DELAY = 0
local TIMER = 0
local function pick_dropped_items(player)
local pos = player:get_pos()
local inv = player:get_inventory()
if not inv then
return
end
local objects = minetest.get_objects_inside_radius(pos, 3)
local objects_to_collect = {}
-- filter - leave only builtin items
for _, object in ipairs(objects) do
if not object:is_player()
and object:get_luaentity()
and object:get_luaentity().name == '__builtin:item'
and object:get_luaentity().itemstring ~= ''
then
table.insert(objects_to_collect, object)
end
end
-- sort with the oldest objects first
table.sort(objects_to_collect, function (a, b)
return b:get_luaentity().age < a:get_luaentity().age
end)
for _, object in ipairs(objects_to_collect) do
local itemstack = ItemStack(object:get_luaentity().itemstring)
if inv:room_for_item('main', itemstack) and not object:get_luaentity()._being_collected
then
inv:add_item('main', itemstack)
object:get_luaentity()._being_collected = true
object:set_acceleration({ x = 0, y = 0, z = 0 })
object:set_velocity({ x = 0, y = 0, z = 0 })
object:get_luaentity().physical_state = false
object:get_luaentity().object:set_properties({ physical = false })
local pos_obj = object:get_pos()
object:move_to(vector.new(
(pos.x - pos_obj.x) + pos_obj.x,
(pos.y - pos_obj.y) + pos_obj.y + 1.25,
(pos.z - pos_obj.z) + pos_obj.z
))
minetest.sound_play('everness_item_drop_pickup', {
pos = pos,
max_hear_distance = 16,
gain = 0.4,
})
minetest.after(0.25, function(v_object)
if v_object and v_object:get_luaentity() then
v_object:remove()
end
end, object)
end
end
end
minetest.register_on_joinplayer(function(player)
local player_meta = player:get_meta()
player_meta:set_int('everness_is_sneaking', 0)
end)
minetest.register_globalstep(function(dtime)
TIMER = TIMER + dtime
if DELAY > 0 then
DELAY = DELAY - dtime
elseif DELAY < 0 then
DELAY = 0
end
-- every 1 second
if TIMER > 1 then
for _, player in ipairs(minetest.get_connected_players()) do
local player_meta = player:get_meta()
local control = player:get_player_control()
local player_hp = player:get_hp()
local is_sneaking = player_meta:get_int('everness_is_sneaking') > 0
if control.sneak and (player_hp > 0 or not minetest.settings:get_bool('enable_damage')) then
-- [Shift + E + Q] single drop item
-- Autopickup after DELAY
if control.aux1 then
DELAY = 1.5
end
if DELAY == 0 then
pick_dropped_items(player)
end
end
-- Hide nametag when sneaking
if control.sneak ~= is_sneaking then
if control.sneak and player_hp > 0 then
local nametag_tbl = player:get_nametag_attributes()
nametag_tbl.color.a = 0
player:set_nametag_attributes(nametag_tbl)
player:set_properties{makes_footstep_sound = false}
else
local nametag_tbl = player:get_nametag_attributes()
nametag_tbl.color.a = 255
player:set_nametag_attributes(nametag_tbl)
player:set_properties{makes_footstep_sound = true}
end
player_meta:set_int('everness_is_sneaking', control.sneak and 1 or 0)
end
end
TIMER = 0
end
end)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.