mirror of
https://github.com/minetest-mods/item_drop.git
synced 2025-06-29 21:31:03 +02:00
Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
2730deca16 | |||
fc89b2d2b4 | |||
f5187108f1 | |||
902daba7cf | |||
3c9c0e34e3 | |||
eaa44e2a36 | |||
a69bdd2275 | |||
1b0bc8461c | |||
b42a64cfa4 | |||
760acbc593 |
@ -6,7 +6,7 @@ By [PilzAdam](https://github.com/PilzAdam),
|
||||
This mod adds Minecraft like drop/pick up of items to Minetest.
|
||||
|
||||
## Licensing
|
||||
LGPLv2.1/CC BY-SA 3.0.
|
||||
LGPLv2.1/CC BY-SA 3.0. Particle code from WCILA mod by Aurailus, originally licensed MIT.
|
||||
|
||||
## Notes
|
||||
item_drop can be played with Minetest 0.4.16 or above. It was originally
|
||||
@ -19,6 +19,8 @@ developed by [PilzAdam](https://github.com/PilzAdam/item_drop).
|
||||
`true` (true by default) It does nothing in creative mode.
|
||||
* Puts dropped items to the player's inventory if `item_drop.enable_item_pickup`
|
||||
is `true` (true by default)
|
||||
* Multiple items are picked in a quick succession instead of all at once which
|
||||
is indicated by the pickup sound.
|
||||
* It uses a node radius set in `item_drop.pickup_radius` (default 0.75),
|
||||
if items are within this radius around the player's belt, they're picked.
|
||||
* If `item_drop.pickup_age` is something positive, items dropped by players
|
||||
@ -41,6 +43,9 @@ developed by [PilzAdam](https://github.com/PilzAdam/item_drop).
|
||||
* Sneak key and right mouse button combined (`SneakAndRMB`)
|
||||
* If `item_drop.pickup_keyinvert` is `true` (false by default), items are
|
||||
collected when the key is not pressed instead of when it's pressed.
|
||||
* Displays a particle of the picked item above the player if
|
||||
`item_drop.pickup_particle` is `true` (true by default)
|
||||
|
||||
|
||||
## Known issues
|
||||
|
||||
|
106
init.lua
106
init.lua
@ -38,6 +38,19 @@ minetest.settings:get_bool("enable_item_pickup") ~= false then
|
||||
error"zero velocity mode can't be used together with magnet mode"
|
||||
end
|
||||
|
||||
-- tells whether an inventorycube should be shown as pickup_particle or not
|
||||
-- for known drawtypes
|
||||
local inventorycube_drawtypes = {
|
||||
normal = true,
|
||||
allfaces = true,
|
||||
allfaces_optional = true,
|
||||
glasslike = true,
|
||||
glasslike_framed = true,
|
||||
glasslike_framed_optional = true,
|
||||
liquid = true,
|
||||
flowingliquid = true,
|
||||
}
|
||||
|
||||
-- adds the item to the inventory and removes the object
|
||||
local function collect_item(ent, pos, player)
|
||||
minetest.sound_play("item_drop_pickup", {
|
||||
@ -45,30 +58,29 @@ minetest.settings:get_bool("enable_item_pickup") ~= false then
|
||||
gain = pickup_gain,
|
||||
})
|
||||
if pickup_particle then
|
||||
local item = minetest.registered_nodes[ent.itemstring:gsub("(.*)%s.*$","%1")]
|
||||
local item = minetest.registered_nodes[
|
||||
ent.itemstring:gsub("(.*)%s.*$", "%1")]
|
||||
local image = ""
|
||||
if item and minetest.registered_items[item.name] and minetest.registered_items[item.name].tiles then
|
||||
if minetest.registered_items[item.name].tiles[1] then
|
||||
local dt = minetest.registered_items[item.name].drawtype
|
||||
if dt == "normal" or dt == "allfaces" or dt == "allfaces_optional"
|
||||
or dt == "glasslike" or dt =="glasslike_framed" or dt == "glasslike_framed_optional"
|
||||
or dt == "liquid" or dt == "flowingliquid" then
|
||||
local tiles = minetest.registered_items[item.name].tiles
|
||||
if item and item.tiles and item.tiles[1] then
|
||||
if inventorycube_drawtypes[item.drawtype] then
|
||||
local tiles = item.tiles
|
||||
|
||||
local top = tiles[1]
|
||||
if (type(top) == "table") then top = top.item end
|
||||
local left = tiles[3]
|
||||
if not left then left = top end
|
||||
if (type(left) == "table") then left = left.item end
|
||||
local right = tiles[5]
|
||||
if not right then right = left end
|
||||
if (type(right) == "table") then right = right.item end
|
||||
local top = tiles[1]
|
||||
if type(top) == "table" then
|
||||
top = top.name
|
||||
end
|
||||
local left = tiles[3] or top
|
||||
if type(left) == "table" then
|
||||
left = left.name
|
||||
end
|
||||
local right = tiles[5] or left
|
||||
if type(right) == "table" then
|
||||
right = right.name
|
||||
end
|
||||
|
||||
image = minetest.inventorycube(top, left, right)
|
||||
else
|
||||
image = minetest.registered_items[item.name].inventory_image
|
||||
if not image then image = minetest.registered_items[item.name].tiles[1] end
|
||||
end
|
||||
image = minetest.inventorycube(top, left, right)
|
||||
else
|
||||
image = item.inventory_image or item.tiles[1]
|
||||
end
|
||||
minetest.add_particle({
|
||||
pos = {x = pos.x, y = pos.y + 1.5, z = pos.z},
|
||||
@ -130,13 +142,38 @@ minetest.settings:get_bool("enable_item_pickup") ~= false then
|
||||
and inv:room_for_item("main", item) then
|
||||
collect_item(ent, object:get_pos(), player)
|
||||
else
|
||||
object:setvelocity({x=0,y=0,z=0})
|
||||
ent.physical_state = true
|
||||
ent.object:set_properties({
|
||||
physical = true
|
||||
})
|
||||
-- the acceleration will be reset by the object's on_step
|
||||
object:set_velocity({x=0,y=0,z=0})
|
||||
ent.is_magnet_item = false
|
||||
end
|
||||
end
|
||||
|
||||
-- disable velocity and acceleration changes of items flying to players
|
||||
minetest.after(0, function()
|
||||
local ObjectRef
|
||||
local blocked_methods = {"set_acceleration", "set_velocity",
|
||||
"setacceleration", "setvelocity"}
|
||||
local itemdef = minetest.registered_entities["__builtin:item"]
|
||||
local old_on_step = itemdef.on_step
|
||||
local function do_nothing() end
|
||||
function itemdef.on_step(self, dtime)
|
||||
if not self.is_magnet_item then
|
||||
return old_on_step(self, dtime)
|
||||
end
|
||||
ObjectRef = ObjectRef or getmetatable(self.object)
|
||||
local old_funcs = {}
|
||||
for i = 1, #blocked_methods do
|
||||
local method = blocked_methods[i]
|
||||
old_funcs[method] = ObjectRef[method]
|
||||
ObjectRef[method] = do_nothing
|
||||
end
|
||||
old_on_step(self, dtime)
|
||||
for i = 1, #blocked_methods do
|
||||
local method = blocked_methods[i]
|
||||
ObjectRef[method] = old_funcs[method]
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
-- set keytype to the key name if possible
|
||||
@ -209,15 +246,12 @@ minetest.settings:get_bool("enable_item_pickup") ~= false then
|
||||
collect_item(ent, pos, player)
|
||||
return true
|
||||
end
|
||||
local vel = vector.multiply(
|
||||
vector.subtract(pos, pos2), 3)
|
||||
local vel = vector.multiply(vector.subtract(pos, pos2), 3)
|
||||
vel.y = vel.y + 0.6
|
||||
object:setvelocity(vel)
|
||||
if ent.physical_state then
|
||||
ent.physical_state = false
|
||||
ent.object:set_properties({
|
||||
physical = false
|
||||
})
|
||||
object:set_velocity(vel)
|
||||
if not ent.is_magnet_item then
|
||||
ent.object:set_acceleration({x=0, y=0, z=0})
|
||||
ent.is_magnet_item = true
|
||||
|
||||
minetest.after(magnet_time, afterflight,
|
||||
object, inv, player)
|
||||
@ -282,7 +316,7 @@ and not minetest.settings:get_bool("creative_mode") then
|
||||
z = z+1
|
||||
end
|
||||
vel.z = 1 / z
|
||||
obj:setvelocity(vel)
|
||||
obj:set_velocity(vel)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -294,5 +328,5 @@ local msg = "[item_drop] loaded after ca. " .. time .. " seconds."
|
||||
if time > 0.01 then
|
||||
print(msg)
|
||||
else
|
||||
minetest.log("info", msg)
|
||||
minetest.log("action", msg)
|
||||
end
|
||||
|
Reference in New Issue
Block a user