Move item drop to builtin
This commit is contained in:
parent
c1acb73c80
commit
05f58b3a04
|
@ -449,12 +449,19 @@ function core.item_drop(itemstack, dropper, pos)
|
|||
local obj = core.add_item(p, item)
|
||||
if obj then
|
||||
if dropper_is_player then
|
||||
local vel = dropper:get_player_velocity()
|
||||
local dir = dropper:get_look_dir()
|
||||
dir.x = dir.x * 2.9
|
||||
dir.y = dir.y * 2.9 + 2
|
||||
dir.z = dir.z * 2.9
|
||||
dir.x = vel.x + dir.x * 4
|
||||
dir.y = vel.y + dir.y * 4 + 2
|
||||
dir.z = vel.z + dir.z * 4
|
||||
obj:set_velocity(dir)
|
||||
obj:get_luaentity().dropped_by = dropper:get_player_name()
|
||||
else
|
||||
obj:set_velocity({
|
||||
x = math.random(-2.5, 2.5),
|
||||
y = math.random(1, 4),
|
||||
z = math.random(-2.5, 2.5)
|
||||
})
|
||||
end
|
||||
return itemstack
|
||||
end
|
||||
|
@ -514,7 +521,7 @@ function core.handle_node_drops(pos, drops, digger)
|
|||
-- Add dropped items to object's inventory
|
||||
local inv = digger and digger:get_inventory()
|
||||
local give_item
|
||||
if inv then
|
||||
if inv and core.settings:get_bool("creative_mode") then
|
||||
give_item = function(item)
|
||||
return inv:add_item("main", item)
|
||||
end
|
||||
|
@ -528,12 +535,7 @@ function core.handle_node_drops(pos, drops, digger)
|
|||
for _, dropped_item in pairs(drops) do
|
||||
local left = give_item(dropped_item)
|
||||
if not left:is_empty() then
|
||||
local p = {
|
||||
x = pos.x + math.random()/2-0.25,
|
||||
y = pos.y + math.random()/2-0.25,
|
||||
z = pos.z + math.random()/2-0.25,
|
||||
}
|
||||
core.add_item(p, left)
|
||||
core.item_drop(left, nil, pos)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -75,69 +75,3 @@ minetest.register_globalstep(function()
|
|||
end
|
||||
player_iter = nil
|
||||
end)
|
||||
|
||||
--Drop items on dig
|
||||
--This only works in survival
|
||||
if minetest.setting_getbool("creative_mode") == false then
|
||||
function minetest.handle_node_drops(pos, drops)
|
||||
for _,item in ipairs(drops) do
|
||||
local count, name
|
||||
if type(item) == "string" then
|
||||
count = 1
|
||||
name = item
|
||||
else
|
||||
count = item:get_count()
|
||||
name = item:get_name()
|
||||
end
|
||||
--if not inv or not inv:contains_item("main", ItemStack(name)) then
|
||||
for _ = 1, count do
|
||||
local obj = minetest.add_item(pos, name)
|
||||
if obj ~= nil then
|
||||
obj:get_luaentity().collect = true
|
||||
obj:get_luaentity().age = 0
|
||||
obj:setvelocity({
|
||||
x = math.random(-3, 3),
|
||||
y = math.random(2, 5),
|
||||
z = math.random(-3, 3)
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--Throw items using player's velocity
|
||||
function minetest.item_drop(itemstack, dropper, pos)
|
||||
|
||||
--if player then do modified item drop
|
||||
if dropper and minetest.get_player_information(dropper:get_player_name()) then
|
||||
local v = dropper:get_look_dir()
|
||||
local vel = dropper:get_player_velocity()
|
||||
local p = {x=pos.x, y=pos.y+player_collect_height, z=pos.z}
|
||||
local item = itemstack:to_string()
|
||||
local obj = core.add_item(p, item)
|
||||
if obj then
|
||||
v.x = (v.x*5)+vel.x
|
||||
v.y = ((v.y*5)+2)+vel.y
|
||||
v.z = (v.z*5)+vel.z
|
||||
obj:setvelocity(v)
|
||||
obj:get_luaentity().dropped_by = dropper:get_player_name()
|
||||
itemstack:clear()
|
||||
return itemstack
|
||||
end
|
||||
--machine
|
||||
else
|
||||
local v = dropper:get_look_dir()
|
||||
local item = itemstack:to_string()
|
||||
local obj = minetest.add_item({x=pos.x,y=pos.y+1.5,z=pos.z}, item) --{x=pos.x+v.x,y=pos.y+v.y+1.5,z=pos.z+v.z}
|
||||
if obj then
|
||||
v.x = (v.x*5)
|
||||
v.y = (v.y*5)
|
||||
v.z = (v.z*5)
|
||||
obj:setvelocity(v)
|
||||
obj:get_luaentity().dropped_by = nil
|
||||
itemstack:clear()
|
||||
return itemstack
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,28 +1,9 @@
|
|||
local show_armor = minetest.get_modpath("3d_armor")
|
||||
|
||||
local function item_drop(itemstack, dropper, pos)
|
||||
if dropper:is_player() then
|
||||
local v = dropper:get_look_dir()
|
||||
local p = {x=pos.x, y=pos.y+1.2, z=pos.z}
|
||||
p.x = p.x+(math.random(1,3)*0.2)
|
||||
p.z = p.z+(math.random(1,3)*0.2)
|
||||
local obj = minetest.add_item(p, itemstack)
|
||||
if obj then
|
||||
v.x = v.x*4
|
||||
v.y = v.y*4 + 2
|
||||
v.z = v.z*4
|
||||
obj:setvelocity(v)
|
||||
end
|
||||
else
|
||||
minetest.add_item(pos, itemstack)
|
||||
end
|
||||
return itemstack
|
||||
end
|
||||
|
||||
local function drop_fields(player, name)
|
||||
local inv = player:get_inventory()
|
||||
for i,stack in ipairs(inv:get_list(name)) do
|
||||
item_drop(stack, player, player:get_pos())
|
||||
minetest.item_drop(stack, player, player:get_pos())
|
||||
stack:clear()
|
||||
inv:set_stack(name, i, stack)
|
||||
end
|
||||
|
|
|
@ -140,34 +140,6 @@ local split_inv = minetest.create_detached_inventory("split", {
|
|||
})
|
||||
split_inv:set_size("main", 1)
|
||||
|
||||
local function item_drop(itemstack, dropper, pos)
|
||||
if dropper:is_player() then
|
||||
local v = dropper:get_look_dir()
|
||||
local p = {x=pos.x, y=pos.y+1.2, z=pos.z}
|
||||
p.x = p.x+(math.random(1,3)*0.2)
|
||||
p.z = p.z+(math.random(1,3)*0.2)
|
||||
local obj = minetest.add_item(p, itemstack)
|
||||
if obj then
|
||||
v.x = v.x*4
|
||||
v.y = v.y*4 + 2
|
||||
v.z = v.z*4
|
||||
obj:setvelocity(v)
|
||||
end
|
||||
else
|
||||
minetest.add_item(pos, itemstack)
|
||||
end
|
||||
return itemstack
|
||||
end
|
||||
|
||||
local function drop_fields(player, name)
|
||||
local inv = player:get_inventory()
|
||||
for i,stack in ipairs(inv:get_list(name)) do
|
||||
item_drop(stack, player, player:get_pos())
|
||||
stack:clear()
|
||||
inv:set_stack(name, i, stack)
|
||||
end
|
||||
end
|
||||
|
||||
function workbench:set_formspec(meta, id)
|
||||
meta:set_string("formspec", "size[9,8.75;]"..
|
||||
"background[-0.2,-0.26;9.41,9.49;formspec_inventory.png]" ..
|
||||
|
@ -297,7 +269,19 @@ minetest.register_node("workbench:workbench", {
|
|||
on_metadata_inventory_put = workbench.on_put,
|
||||
on_metadata_inventory_take = workbench.on_take,
|
||||
allow_metadata_inventory_put = workbench.put,
|
||||
allow_metadata_inventory_move = workbench.move
|
||||
allow_metadata_inventory_move = workbench.move,
|
||||
on_receive_fields = function(pos, formname, fields, sender)
|
||||
if fields.quit and pos and sender then
|
||||
local inv = sender:get_inventory()
|
||||
if inv then
|
||||
for i, stack in ipairs(inv:get_list("craft")) do
|
||||
minetest.item_drop(stack, nil, pos)
|
||||
stack:clear()
|
||||
inv:set_stack("craft", i, stack)
|
||||
end
|
||||
end
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_tool("workbench:hammer", {
|
||||
|
|
Loading…
Reference in New Issue