Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions item_drop.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ end
local function removeObjectWithSound(object)
movers[object] = nil
removedAlreadyDammit[object] = true
local pos=object:getpos()
local pos = object:get_pos()
minetest.sound_play("item_gone", {
pos=pos,
pos = pos,
gain = 0.2,
max_hear_distance = 32,
})
Expand Down Expand Up @@ -86,8 +86,8 @@ local function stop(object)
movers[object] = nil
-- no pickup, even though it's close, so
-- stop moving towards the player
object:setvelocity({x=0, y=0, z=0})
object:setacceleration({x=0, y=0, z=0})
object:set_velocity({x=0, y=0, z=0})
object:set_acceleration({x=0, y=0, z=0})
-- also we can walk on it and it can push pressure plates
-- physical_state = false means "please make us physical again"
local lua = object:get_luaentity()
Expand Down Expand Up @@ -119,14 +119,14 @@ drops.playerGMass = 1.7

local function moveTowards(object, player, pickupRadius, attractRadius)
-- move it towards the player, then pick it up after a delay!
local pos1 = player:getpos()
local pos1 = player:get_pos()
if pos1 == nil then return end
local pos2 = object:getpos()
local pos2 = object:get_pos()
if pos2 == nil then return end
pos1.y = pos1.y+0.5 -- head towards player's belt
local direct = vector.subtract(pos1, pos2)
local R = vector.length(direct)
local v = object:getvelocity()
local v = object:get_velocity()
local stopped = v.x == 0 and v.y == 0 and v.z == 0
-- when direction(X) = direction(V) we passed the player
-- so project V onto X. If same, passed. If not, approaching.
Expand All @@ -146,7 +146,7 @@ local function moveTowards(object, player, pickupRadius, attractRadius)
return
end
if R < pickupRadius or (not stopped and vector.dot(v,direct) < 0) then
pickupOrStop(object,player:get_inventory(),player,nil)
pickupOrStop(object, player:get_inventory(), player, nil)
return
end
-- Fg = G*M1*M2/R^2
Expand All @@ -158,18 +158,18 @@ local function moveTowards(object, player, pickupRadius, attractRadius)
local A
A = drops.playerGMass / R^2
A = math.max(A,2*drops.playerGMass)
object:setacceleration(vector.multiply(direct,A))
object:set_acceleration(vector.multiply(direct,A))
end

if minetest.setting_get("enable_item_pickup") == "true" then
if minetest.settings:get("enable_item_pickup") == "true" then
local tickets = 0 -- XXX: oy vey
moveDelay = 0
minetest.register_globalstep(function(dtime)
-- it's much more efficient to just restart... no way to unregister_globalstep right?
if not minetest.setting_get("enable_item_pickup") then return end
if not minetest.settings:get("enable_item_pickup") then return end
moveDelay = moveDelay + dtime
local pickupRadius = tonumber(minetest.setting_get("pickup_radius"))
local attractRadius = tonumber(minetest.setting_get("attract_radius"))
local pickupRadius = tonumber(minetest.settings:get("pickup_radius"))
local attractRadius = tonumber(minetest.settings:get("attract_radius"))
if not pickupRadius then pickupRadius = 0.5 end
if not attractRadius then attractRadius = 3 end

Expand All @@ -182,8 +182,8 @@ if minetest.setting_get("enable_item_pickup") == "true" then
end
end
for _, player in ipairs(minetest.get_connected_players()) do
if player:get_hp() > 0 or not minetest.setting_getbool("enable_damage") then
local playerPosition = player:getpos()
if player:get_hp() > 0 or not minetest.settings:get_bool("enable_damage") then
local playerPosition = player:get_pos()
if playerPosition ~= nil then
playerPosition.y = playerPosition.y + 0.5
local inv = player:get_inventory()
Expand Down Expand Up @@ -222,7 +222,7 @@ if minetest.setting_get("enable_item_pickup") == "true" then
end)
end

if minetest.setting_get("enable_item_drops") == "true" then
if minetest.settings:get("enable_item_drops") == "true" then
local old_handle_node_drops = minetest.handle_node_drops

function new_handle_node_drops(pos, drops, digger)
Expand All @@ -231,7 +231,7 @@ if minetest.setting_get("enable_item_drops") == "true" then
end
local inv
-- the digger might be a node, like a constructor
if minetest.setting_getbool("creative_mode") and digger and digger:is_player() then
if minetest.settings:get_bool("creative_mode") and digger and digger:is_player() then
inv = digger:get_inventory()
end
for _, item in ipairs(drops) do
Expand All @@ -245,7 +245,7 @@ if minetest.setting_get("enable_item_drops") == "true" then
end
-- Only drop the item if not in creative, or if the item is not in creative inventory
if not inv or not inv:contains_item("main", ItemStack(name)) then
for i=1, count do
for i = 1, count do
local obj = minetest.add_item(pos, item)
if obj ~= nil then
local x = math.random(1, 5)
Expand All @@ -258,7 +258,7 @@ if minetest.setting_get("enable_item_drops") == "true" then
end
-- hurl it out into space at a random velocity
-- (still falling though)
obj:setvelocity({x=1/x, y=obj:getvelocity().y, z=1/z})
obj:set_velocity({x = 1/x, y = obj:get_velocity().y, z = 1/z})
end
end
end
Expand All @@ -269,7 +269,7 @@ if minetest.setting_get("enable_item_drops") == "true" then
end

function checkSetting(pos, drops, digger)
if minetest.setting_get("enable_item_drops") == "true" then
if minetest.settings:get("enable_item_drops") == "true" then
return new_handle_node_drops(pos, drops, digger)
else
return old_handle_node_drops(pos, drops, digger)
Expand Down
1 change: 1 addition & 0 deletions mod.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name = item_tweaks