Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop items left in workbench and in player crafting. #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*~
30 changes: 30 additions & 0 deletions mods/workbench/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,35 @@ minetest.register_node("workbench:workbench", {
end,
})

local players_viewdir = {}

minetest.register_globalstep(function(dtime)
for _,player in ipairs(minetest.get_connected_players()) do
local name = player:get_player_name()
local pitch = player:get_look_pitch()
local yaw = player:get_look_yaw()
local pos = player:getpos()
local o = players_viewdir[name]
if pitch ~= o.pitch or yaw ~= o.yaw or pos.x ~= o.pos.x or pos.y ~= o.pos.y or pos.z ~= o.pos.z then
players_viewdir[name] = {pitch = pitch, yaw = yaw, pos = {x = pos.x, y = pos.y, z = pos.z}}
local inv = player:get_inventory()
pos.y = pos.y+1.5
local ldir = player:get_look_dir()
pos.x = pos.x + ldir.x
pos.y = pos.y + ldir.y
pos.z = pos.z + ldir.z
for i,stack in ipairs(inv:get_list("craft")) do
local obj = minetest.add_item(pos, stack)
if obj then
obj:setvelocity(ldir)
end
stack:clear()
inv:set_stack("craft", i, stack)
end
end
end
end)

minetest.register_craft({
output = "workbench:workbench",
recipe = {
Expand All @@ -25,6 +54,7 @@ minetest.register_craft({

minetest.register_on_joinplayer(function(player)
if not minetest.setting_getbool("creative_mode") then
players_viewdir[player:get_player_name()] = {pitch = 0, yaw = 0, pos={x = 0, y = 0, z = 0}}
player:get_inventory():set_width("craft", 3)
player:get_inventory():set_size("craft", 9)
player:get_inventory():set_size("main", 9*4)
Expand Down