Add trashcan.
This commit is contained in:
parent
d234d95a7a
commit
963ed683bb
2
init.lua
2
init.lua
@ -14,5 +14,5 @@ mod.dat = {}
|
||||
mod.magic_ingredient = 'default:mese_crystal' -- Hmmm.... ?
|
||||
|
||||
|
||||
dofile(mod.path .. '/recipes.lua')
|
||||
dofile(mod.path .. '/inventory.lua')
|
||||
dofile(mod.path .. '/recipes.lua')
|
||||
|
128
inventory.lua
128
inventory.lua
@ -211,6 +211,38 @@ function mod.empty_craft(player)
|
||||
end
|
||||
|
||||
|
||||
function mod.empty_trash(player)
|
||||
local pos
|
||||
|
||||
if player and player.get_player_name then
|
||||
local player_name = player:get_player_name()
|
||||
if mod.dat[player_name].trash_opened then
|
||||
pos = mod.dat[player_name].trash_opened
|
||||
end
|
||||
end
|
||||
|
||||
if not pos then
|
||||
return
|
||||
end
|
||||
|
||||
local meta = minetest.get_meta(pos)
|
||||
if not meta then
|
||||
return
|
||||
end
|
||||
|
||||
local inv = meta:get_inventory()
|
||||
if not inv then
|
||||
return
|
||||
end
|
||||
|
||||
local size = inv:get_size('main')
|
||||
for i = 1, size do
|
||||
--local st = inv:get_stack('main', i)
|
||||
inv:set_stack('main', i, nil)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function mod.get_all_craft_recipes(craft_item)
|
||||
local recipes = {}
|
||||
for k, v in pairs(minetest.get_all_craft_recipes(craft_item) or {}) do
|
||||
@ -243,6 +275,29 @@ function mod.get_main_size_by_bags(player)
|
||||
end
|
||||
|
||||
|
||||
function mod.get_trashcan_formspec(pos, player)
|
||||
local scroll_to = 0
|
||||
if player and player.get_player_name then
|
||||
local player_name = player:get_player_name()
|
||||
if mod.dat[player_name].scroll_main_to then
|
||||
scroll_to = mod.dat[player_name].scroll_main_to
|
||||
end
|
||||
end
|
||||
|
||||
local spos = pos.x .. ',' .. pos.y .. ',' .. pos.z
|
||||
local formspec = 'size[9,8]' ..
|
||||
'list[nodemeta:' .. spos .. ';main;0,0.3;8,4;]' ..
|
||||
'list[current_player;main;0,4;8,4;' .. scroll_to .. ']' ..
|
||||
'listring[]' ..
|
||||
'image_button[3,2.5;2,1;transparent_button.png;dinv_trash_empty;Empty Trash]' ..
|
||||
'image_button[8,4;1,1;transparent_button.png;dinv_trash_inventory_up;Up]' ..
|
||||
'image_button[8,6;1,1;transparent_button.png;dinv_trash_inventory_down;Down]' ..
|
||||
default.get_hotbar_bg(0,4.85)
|
||||
|
||||
return formspec
|
||||
end
|
||||
|
||||
|
||||
-- Any warmth over zero is sufficient at the moment.
|
||||
function mod.get_warmth(player)
|
||||
if not player then
|
||||
@ -649,7 +704,7 @@ function mod.scroll_main(player, amount, max)
|
||||
local scroll = mod.dat[player_name].scroll_main_to or 0
|
||||
if scroll and scroll % 8 == 0 then
|
||||
scroll = (scroll + amount)
|
||||
if scroll > max or scroll < 0 then
|
||||
if scroll > max - 1 or scroll < 0 then
|
||||
scroll = 0
|
||||
end
|
||||
mod.dat[player_name].scroll_main_to = scroll
|
||||
@ -658,6 +713,34 @@ function mod.scroll_main(player, amount, max)
|
||||
end
|
||||
|
||||
|
||||
function mod.scroll_trash(player, amount, max)
|
||||
if not (player and amount) then
|
||||
return
|
||||
end
|
||||
|
||||
local player_name = player:get_player_name()
|
||||
if not player_name then
|
||||
return
|
||||
end
|
||||
|
||||
local dat = mod.dat[player_name] or {}
|
||||
local pos = dat.trash_opened
|
||||
if not pos then
|
||||
return
|
||||
end
|
||||
|
||||
local scroll = mod.dat[player_name].scroll_main_to or 0
|
||||
if scroll and scroll % 8 == 0 then
|
||||
scroll = (scroll + amount)
|
||||
if scroll > max - 1 or scroll < 0 then
|
||||
scroll = 0
|
||||
end
|
||||
mod.dat[player_name].scroll_main_to = scroll
|
||||
minetest.show_formspec(player_name, mod_name..':trashcan', mod.get_trashcan_formspec(pos, player))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function mod.set_armor(player)
|
||||
if not player then
|
||||
return
|
||||
@ -788,6 +871,40 @@ function mod.switch_recipe(player, amount)
|
||||
end
|
||||
|
||||
|
||||
function mod.trashcan_can_dig(pos,player)
|
||||
local meta = minetest.get_meta(pos);
|
||||
local inv = meta:get_inventory()
|
||||
return inv:is_empty('main')
|
||||
end
|
||||
|
||||
|
||||
function mod.trashcan_construct(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string('infotext', 'Trashcan')
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size('main', 8*2)
|
||||
end
|
||||
|
||||
|
||||
function mod.trashcan_rightclick(pos, node, player, itemstack, pointed_thing)
|
||||
local player_name
|
||||
if player and player.get_player_name then
|
||||
player_name = player:get_player_name()
|
||||
end
|
||||
|
||||
if not player_name then
|
||||
return
|
||||
end
|
||||
|
||||
local dat = mod.dat[player_name]
|
||||
if dat then
|
||||
dat.trash_opened = pos
|
||||
end
|
||||
|
||||
minetest.show_formspec(player_name, mod_name..':trashcan', mod.get_trashcan_formspec(pos, player))
|
||||
end
|
||||
|
||||
|
||||
-- Return true if there's an item at that body location.
|
||||
function mod.wearing_on_location(player, loc)
|
||||
for k, v in worn_items(player) do
|
||||
@ -995,6 +1112,9 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
or fields['dinv_recipe_next']
|
||||
or fields['dinv_empty_craft']
|
||||
or fields['dinv_fill_craft']
|
||||
or fields['dinv_trash_inventory_up']
|
||||
or fields['dinv_trash_inventory_down']
|
||||
or fields['dinv_trash_empty']
|
||||
) then
|
||||
return
|
||||
end
|
||||
@ -1014,6 +1134,12 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
mod.empty_craft(player)
|
||||
elseif fields and fields['dinv_fill_craft'] then
|
||||
mod.recipe_fill(player)
|
||||
elseif fields and fields['dinv_trash_inventory_up'] then
|
||||
mod.scroll_trash(player, -16, main_inventory_size)
|
||||
elseif fields and fields['dinv_trash_inventory_down'] then
|
||||
mod.scroll_trash(player, 16, main_inventory_size)
|
||||
elseif fields and fields['dinv_trash_empty'] then
|
||||
mod.empty_trash(player)
|
||||
end
|
||||
end)
|
||||
|
||||
|
29
recipes.lua
29
recipes.lua
@ -347,6 +347,35 @@ minetest.register_craft({
|
||||
})
|
||||
|
||||
|
||||
local trashcan_nodebox = {
|
||||
type = 'fixed',
|
||||
fixed = {
|
||||
{ -0.35, -0.5, -0.35, 0.35, 0.5, 0.35 },
|
||||
}
|
||||
}
|
||||
|
||||
minetest.register_node(mod_name..':trashcan', {
|
||||
description = 'Trash',
|
||||
tiles = { 'default_wood.png', 'default_wood.png', 'default_wood.png^recycle.png', },
|
||||
drawtype = 'nodebox',
|
||||
node_box = trashcan_nodebox,
|
||||
groups = { choppy = 1, oddly_breakable_by_hand = 1 },
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
on_rightclick = mod.trashcan_rightclick,
|
||||
on_construct = mod.trashcan_construct,
|
||||
can_dig = mod.trashcan_can_dig,
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = mod_name..':trashcan',
|
||||
recipe = {
|
||||
{'', 'group:leaves', ''},
|
||||
{'', 'group:wood', ''},
|
||||
{'', 'group:wood', ''},
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
minetest.register_chatcommand('killunk', {
|
||||
|
BIN
textures/recycle.png
Normal file
BIN
textures/recycle.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 642 B |
Loading…
x
Reference in New Issue
Block a user