forked from minetest-mods/item_drop
Merge branch 'master' of yunohost.local:minetest-mods/item_drop into nalc-1.2-dev
This commit is contained in:
commit
c6a80bd4fa
@ -43,7 +43,7 @@ developed by [PilzAdam](https://github.com/PilzAdam/item_drop).
|
|||||||
* Left and Right keys combined (`LeftAndRight`)
|
* Left and Right keys combined (`LeftAndRight`)
|
||||||
* Right mouse button (`RMB`)
|
* Right mouse button (`RMB`)
|
||||||
* Sneak key and right mouse button combined (`SneakAndRMB`)
|
* Sneak key and right mouse button combined (`SneakAndRMB`)
|
||||||
* If `item_drop.pickup_keyinvert` is `true` (false by default), items are
|
* If `item_drop.pickup_keyinvert` is `true`, items are
|
||||||
collected when the key is not pressed instead of when it's pressed.
|
collected when the key is not pressed instead of when it's pressed.
|
||||||
* Displays a particle of the picked item above the player if
|
* Displays a particle of the picked item above the player if
|
||||||
`item_drop.pickup_particle` is `true` (true by default)
|
`item_drop.pickup_particle` is `true` (true by default)
|
||||||
|
@ -1 +1 @@
|
|||||||
This mod adds Minecraft like drop/pick up of items to Minetest.
|
A highly configurable mod providing item magnet and in-world node drops
|
||||||
|
137
init.lua
137
init.lua
@ -23,27 +23,41 @@ item_drop = {
|
|||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
if minetest.settings:get_bool("item_drop.enable_item_pickup") ~= false and
|
local function legacy_setting_getbool(name_new, name_old, default)
|
||||||
minetest.settings:get_bool("enable_item_pickup") ~= false then
|
local v = minetest.settings:get_bool(name_new)
|
||||||
local pickup_gain = tonumber(
|
if v == nil then
|
||||||
minetest.settings:get("item_drop.pickup_sound_gain")) or
|
v = minetest.settings:get_bool(name_new)
|
||||||
tonumber(minetest.settings:get("item_pickup_gain")) or 0.2
|
end
|
||||||
|
if default then
|
||||||
|
return v ~= false
|
||||||
|
end
|
||||||
|
return v
|
||||||
|
end
|
||||||
|
|
||||||
|
local function legacy_setting_getnumber(name_new, name_old, default)
|
||||||
|
return tonumber(minetest.settings:get(name_new))
|
||||||
|
or tonumber(minetest.settings:get(name_old))
|
||||||
|
or default
|
||||||
|
end
|
||||||
|
|
||||||
|
if legacy_setting_getbool("item_drop.enable_item_pickup",
|
||||||
|
"enable_item_pickup", true) then
|
||||||
|
local pickup_gain = legacy_setting_getnumber("item_drop.pickup_sound_gain",
|
||||||
|
"item_pickup_gain", 0.2)
|
||||||
local pickup_particle =
|
local pickup_particle =
|
||||||
minetest.settings:get_bool("item_drop.pickup_particle") ~= false
|
minetest.settings:get_bool("item_drop.pickup_particle", true)
|
||||||
local pickup_radius = tonumber(
|
local pickup_radius = legacy_setting_getnumber("item_drop.pickup_radius",
|
||||||
minetest.settings:get("item_drop.pickup_radius")) or
|
"item_pickup_radius", 0.75)
|
||||||
tonumber(minetest.settings:get("item_pickup_radius")) or 0.75
|
|
||||||
local magnet_radius = tonumber(
|
local magnet_radius = tonumber(
|
||||||
minetest.settings:get("item_drop.magnet_radius")) or -1
|
minetest.settings:get("item_drop.magnet_radius")) or -1
|
||||||
local magnet_time = tonumber(
|
local magnet_time = tonumber(
|
||||||
minetest.settings:get("item_drop.magnet_time")) or 5.0
|
minetest.settings:get("item_drop.magnet_time")) or 5.0
|
||||||
local pickup_age = tonumber(
|
local pickup_age = tonumber(
|
||||||
minetest.settings:get("item_drop.pickup_age")) or 0.5
|
minetest.settings:get("item_drop.pickup_age")) or 0.5
|
||||||
local key_triggered = minetest.settings:get_bool(
|
local key_triggered = legacy_setting_getbool("item_drop.enable_pickup_key",
|
||||||
"item_drop.enable_pickup_key") or
|
"enable_item_pickup_key", true)
|
||||||
minetest.settings:get_bool("enable_item_pickup_key") ~= false
|
|
||||||
local key_invert = minetest.settings:get_bool(
|
local key_invert = minetest.settings:get_bool(
|
||||||
"item_drop.pickup_keyinvert") or false
|
"item_drop.pickup_keyinvert") ~= false
|
||||||
local keytype
|
local keytype
|
||||||
if key_triggered then
|
if key_triggered then
|
||||||
keytype = minetest.settings:get("item_drop.pickup_keytype") or
|
keytype = minetest.settings:get("item_drop.pickup_keytype") or
|
||||||
@ -131,7 +145,7 @@ minetest.settings:get_bool("enable_item_pickup") ~= false then
|
|||||||
if zero_velocity_mode then
|
if zero_velocity_mode then
|
||||||
function opt_get_ent(object)
|
function opt_get_ent(object)
|
||||||
if object:is_player()
|
if object:is_player()
|
||||||
or not vector.equals(object:getvelocity(), {x=0, y=0, z=0}) then
|
or not vector.equals(object:get_velocity(), {x=0, y=0, z=0}) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local ent = object:get_luaentity()
|
local ent = object:get_luaentity()
|
||||||
@ -246,7 +260,7 @@ minetest.settings:get_bool("enable_item_pickup") ~= false then
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local pos = player:getpos()
|
local pos = player:get_pos()
|
||||||
pos.y = pos.y+0.5
|
pos.y = pos.y+0.5
|
||||||
local inv
|
local inv
|
||||||
|
|
||||||
@ -270,7 +284,7 @@ minetest.settings:get_bool("enable_item_pickup") ~= false then
|
|||||||
local flying_item
|
local flying_item
|
||||||
local pos2
|
local pos2
|
||||||
if magnet_mode then
|
if magnet_mode then
|
||||||
pos2 = object:getpos()
|
pos2 = object:get_pos()
|
||||||
flying_item = vector.distance(pos, pos2) > pickup_radius
|
flying_item = vector.distance(pos, pos2) > pickup_radius
|
||||||
end
|
end
|
||||||
if not flying_item then
|
if not flying_item then
|
||||||
@ -314,45 +328,84 @@ minetest.settings:get_bool("enable_item_pickup") ~= false then
|
|||||||
minetest.after(3.0, pickup_step)
|
minetest.after(3.0, pickup_step)
|
||||||
end
|
end
|
||||||
|
|
||||||
if minetest.settings:get_bool("item_drop.enable_item_drop") ~= false and
|
if legacy_setting_getbool("item_drop.enable_item_drop", "enable_item_drop", true)
|
||||||
minetest.settings:get_bool("enable_item_drop") ~= false
|
|
||||||
and not minetest.settings:get_bool("creative_mode") then
|
and not minetest.settings:get_bool("creative_mode") then
|
||||||
function minetest.handle_node_drops(pos, drops)
|
-- Workaround to test if an item metadata (ItemStackMetaRef) is empty
|
||||||
|
local function itemmeta_is_empty(meta)
|
||||||
|
local t = meta:to_table()
|
||||||
|
for k, v in pairs(t) do
|
||||||
|
if k ~= "fields" then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
assert(type(v) == "table")
|
||||||
|
if next(v) ~= nil then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Tests if the item has special information such as metadata
|
||||||
|
local function can_split_item(item)
|
||||||
|
return item:get_wear() == 0 and itemmeta_is_empty(item:get_meta())
|
||||||
|
end
|
||||||
|
|
||||||
|
local function spawn_items(pos, items_to_spawn)
|
||||||
|
for i = 1,#items_to_spawn do
|
||||||
|
local obj = minetest.add_item(pos, items_to_spawn[i])
|
||||||
|
if not obj then
|
||||||
|
error("Couldn't spawn item " .. name .. ", drops: "
|
||||||
|
.. dump(drops))
|
||||||
|
end
|
||||||
|
|
||||||
|
local vel = obj:get_velocity()
|
||||||
|
local x = math.random(-5, 4)
|
||||||
|
if x >= 0 then
|
||||||
|
x = x+1
|
||||||
|
end
|
||||||
|
vel.x = 1 / x
|
||||||
|
local z = math.random(-5, 4)
|
||||||
|
if z >= 0 then
|
||||||
|
z = z+1
|
||||||
|
end
|
||||||
|
vel.z = 1 / z
|
||||||
|
obj:set_velocity(vel)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local old_handle_node_drops = minetest.handle_node_drops
|
||||||
|
function minetest.handle_node_drops(pos, drops, player)
|
||||||
|
if player.is_fake_player then
|
||||||
|
-- Node Breaker or similar machines should receive items in the
|
||||||
|
-- inventory
|
||||||
|
return old_handle_node_drops(pos, drops, player)
|
||||||
|
end
|
||||||
for i = 1,#drops do
|
for i = 1,#drops do
|
||||||
local item = drops[i]
|
local item = drops[i]
|
||||||
local count, name
|
|
||||||
if type(item) == "string" then
|
if type(item) == "string" then
|
||||||
count = 1
|
-- The string is not necessarily only the item name,
|
||||||
name = item
|
-- so always convert it to ItemStack
|
||||||
else
|
item = ItemStack(item)
|
||||||
count = item:get_count()
|
|
||||||
name = item:get_name()
|
|
||||||
end
|
end
|
||||||
|
local count = item:get_count()
|
||||||
|
local name = item:get_name()
|
||||||
|
|
||||||
-- Sometimes nothing should be dropped
|
-- Sometimes nothing should be dropped
|
||||||
if name == ""
|
if name == ""
|
||||||
or not minetest.registered_nodes[name] then
|
or not minetest.registered_items[name] then
|
||||||
count = 0
|
count = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
for _ = 1,count do
|
if count > 0 then
|
||||||
local obj = minetest.add_item(pos, name)
|
-- Split items if possible
|
||||||
if not obj then
|
local items_to_spawn = {item}
|
||||||
error("Couldn't spawn item " .. name .. ", drops: " .. dump(drops))
|
if can_split_item(item) then
|
||||||
|
for i = 1,count do
|
||||||
|
items_to_spawn[i] = name
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local vel = obj:getvelocity()
|
spawn_items(pos, items_to_spawn)
|
||||||
local x = math.random(-5, 4)
|
|
||||||
if x >= 0 then
|
|
||||||
x = x+1
|
|
||||||
end
|
|
||||||
vel.x = 1 / x
|
|
||||||
local z = math.random(-5, 4)
|
|
||||||
if z >= 0 then
|
|
||||||
z = z+1
|
|
||||||
end
|
|
||||||
vel.z = 1 / z
|
|
||||||
obj:set_velocity(vel)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
1
mod.conf
1
mod.conf
@ -1 +1,2 @@
|
|||||||
name = item_drop
|
name = item_drop
|
||||||
|
description = A highly configurable mod providing item magnet and in-world node drops
|
||||||
|
@ -8,7 +8,7 @@ item_drop.enable_item_drop (Enable item drops) bool true
|
|||||||
item_drop.enable_pickup_key (Use pickup key) bool true
|
item_drop.enable_pickup_key (Use pickup key) bool true
|
||||||
|
|
||||||
#Collect items when the key is not pressed instead of when it is pressed
|
#Collect items when the key is not pressed instead of when it is pressed
|
||||||
item_drop.pickup_keyinvert (Invert pickup key) bool false
|
item_drop.pickup_keyinvert (Invert pickup key) bool true
|
||||||
|
|
||||||
#What keytype to use as pickup key
|
#What keytype to use as pickup key
|
||||||
item_drop.pickup_keytype (Pickup keytype) enum Use Use,Sneak,LeftAndRight,RMB,SneakAndRMB
|
item_drop.pickup_keytype (Pickup keytype) enum Use Use,Sneak,LeftAndRight,RMB,SneakAndRMB
|
||||||
|
Loading…
Reference in New Issue
Block a user