2017-03-09 19:16:50 +03:00
|
|
|
|
mcl_inventory = {}
|
|
|
|
|
|
2017-01-06 01:37:40 +03:00
|
|
|
|
local show_armor = false
|
|
|
|
|
if minetest.get_modpath("3d_armor") ~= nil then show_armor = true end
|
|
|
|
|
|
|
|
|
|
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)
|
2017-01-11 20:21:46 +03:00
|
|
|
|
local obj = minetest.add_item(p, itemstack)
|
2017-01-06 01:37:40 +03:00
|
|
|
|
if obj then
|
|
|
|
|
v.x = v.x*4
|
|
|
|
|
v.y = v.y*4 + 2
|
|
|
|
|
v.z = v.z*4
|
|
|
|
|
obj:setvelocity(v)
|
2017-05-30 19:34:08 +03:00
|
|
|
|
obj:get_luaentity()._insta_collect = false
|
2017-01-06 01:37:40 +03:00
|
|
|
|
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:getpos())
|
|
|
|
|
stack:clear()
|
|
|
|
|
inv:set_stack(name, i, stack)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function update_armor(player)
|
2017-02-17 04:07:18 +03:00
|
|
|
|
return
|
2017-01-06 01:37:40 +03:00
|
|
|
|
end
|
|
|
|
|
|
2017-03-09 20:58:35 +03:00
|
|
|
|
local function set_inventory(player, armor_change_only)
|
2017-01-06 01:37:40 +03:00
|
|
|
|
if minetest.setting_getbool("creative_mode") then
|
2017-03-09 20:58:35 +03:00
|
|
|
|
if armor_change_only then
|
|
|
|
|
-- Stay on survival inventory plage if only the armor has been changed
|
2017-06-02 23:46:39 +03:00
|
|
|
|
mcl_inventory.set_creative_formspec(player, 0, 0, nil, nil, "inv")
|
2017-03-09 20:58:35 +03:00
|
|
|
|
else
|
|
|
|
|
mcl_inventory.set_creative_formspec(player, 0, 1)
|
|
|
|
|
end
|
2017-01-06 03:25:49 +03:00
|
|
|
|
return
|
2017-01-06 01:37:40 +03:00
|
|
|
|
end
|
2017-03-09 07:24:50 +03:00
|
|
|
|
local inv = player:get_inventory()
|
|
|
|
|
inv:set_width("craft", 2)
|
|
|
|
|
inv:set_size("craft", 4)
|
2017-01-06 01:37:40 +03:00
|
|
|
|
|
|
|
|
|
local player_name = player:get_player_name()
|
2017-03-09 20:26:16 +03:00
|
|
|
|
|
|
|
|
|
-- Show armor and player image
|
2017-02-17 06:50:12 +03:00
|
|
|
|
-- TODO: Use player.png to allow for custom skins
|
2017-02-17 04:07:18 +03:00
|
|
|
|
local img = "crafting_player2d.png"
|
2017-01-06 01:37:40 +03:00
|
|
|
|
local armor_img = ""
|
2017-03-09 20:26:16 +03:00
|
|
|
|
local player_preview = "image[0.6,0.2;2,4;"..img.."]"
|
2017-01-06 01:37:40 +03:00
|
|
|
|
if show_armor and armor.textures[player_name] and armor.textures[player_name].preview then
|
|
|
|
|
img = armor.textures[player_name].preview
|
|
|
|
|
local s1 = img:find("character_preview")
|
|
|
|
|
if s1 ~= nil then
|
|
|
|
|
s1 = img:sub(s1+21)
|
|
|
|
|
img = "crafting_player2d.png"..s1
|
|
|
|
|
end
|
2017-03-09 20:26:16 +03:00
|
|
|
|
player_preview = "image[1.1,0.2;2,4;"..img.."]"
|
2017-01-06 01:37:40 +03:00
|
|
|
|
end
|
|
|
|
|
|
2017-04-01 06:41:53 +03:00
|
|
|
|
local armor_slots = {"helmet", "chestplate", "leggings", "boots"}
|
2017-03-09 07:24:50 +03:00
|
|
|
|
local armor_slot_imgs = ""
|
|
|
|
|
for a=1,4 do
|
|
|
|
|
if inv:get_stack("armor", a+1):is_empty() then
|
2017-04-01 06:41:53 +03:00
|
|
|
|
armor_slot_imgs = armor_slot_imgs .. "image[0,"..(a-1)..";1,1;mcl_inventory_empty_armor_slot_"..armor_slots[a]..".png]"
|
2017-03-09 07:24:50 +03:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2017-01-06 01:37:40 +03:00
|
|
|
|
local form = "size[9,8.75]"..
|
|
|
|
|
"background[-0.19,-0.25;9.41,9.49;crafting_formspec_bg.png^crafting_inventory.png"..armor_img.."]"..
|
2017-02-18 01:06:52 +03:00
|
|
|
|
mcl_vars.inventory_header..
|
2017-03-09 20:26:16 +03:00
|
|
|
|
player_preview..
|
2017-01-06 01:37:40 +03:00
|
|
|
|
--armor
|
2017-01-06 02:36:58 +03:00
|
|
|
|
"list[detached:"..player_name.."_armor;armor;0,0;1,1;1]"..
|
|
|
|
|
"list[detached:"..player_name.."_armor;armor;0,1;1,1;2]"..
|
|
|
|
|
"list[detached:"..player_name.."_armor;armor;0,2;1,1;3]"..
|
|
|
|
|
"list[detached:"..player_name.."_armor;armor;0,3;1,1;4]"..
|
2017-03-09 07:24:50 +03:00
|
|
|
|
armor_slot_imgs..
|
2017-01-06 02:36:58 +03:00
|
|
|
|
-- craft and inventory
|
2017-01-06 01:37:40 +03:00
|
|
|
|
"list[current_player;main;0,4.5;9,3;9]"..
|
|
|
|
|
"list[current_player;main;0,7.74;9,1;]"..
|
2017-01-06 03:18:02 +03:00
|
|
|
|
"list[current_player;craft;4,1;2,2]"..
|
2017-01-06 01:37:40 +03:00
|
|
|
|
"list[current_player;craftpreview;7,1.5;1,1;]"..
|
2017-02-06 00:23:44 +03:00
|
|
|
|
-- crafting guide button
|
|
|
|
|
"image_button[8,0;1,1;craftguide_book.png;__mcl_craftguide;]"..
|
|
|
|
|
"tooltip[__mcl_craftguide;Show crafting recipes]"..
|
2017-03-18 05:27:36 +03:00
|
|
|
|
-- help button
|
|
|
|
|
"image_button[8,1;1,1;doc_button_icon_lores.png;__mcl_doc;]"..
|
|
|
|
|
"tooltip[__mcl_doc;Help]"..
|
2017-03-04 03:57:10 +03:00
|
|
|
|
-- achievements button
|
2017-03-18 05:27:36 +03:00
|
|
|
|
"image_button[8,2;1,1;mcl_achievements_button.png;__mcl_achievements;]"..
|
2017-03-04 03:57:10 +03:00
|
|
|
|
"tooltip[__mcl_achievements;Achievements]"..
|
2017-01-06 02:36:58 +03:00
|
|
|
|
-- for shortcuts
|
|
|
|
|
"listring[current_player;main]"..
|
|
|
|
|
"listring[current_player;craft]"..
|
|
|
|
|
"listring[current_player;main]"..
|
2017-06-01 23:57:13 +03:00
|
|
|
|
"listring[detached:"..player_name.."_armor;armor]"
|
|
|
|
|
|
2017-01-06 01:37:40 +03:00
|
|
|
|
player:set_inventory_formspec(form)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function set_workbench(player)
|
|
|
|
|
player:get_inventory():set_width("craft", 3)
|
|
|
|
|
player:get_inventory():set_size("craft", 9)
|
|
|
|
|
|
|
|
|
|
local form = "size[9,8.75]"..
|
|
|
|
|
"background[-0.19,-0.25;9.41,9.49;crafting_formspec_bg.png^crafting_inventory_workbench.png]"..
|
2017-02-18 01:06:52 +03:00
|
|
|
|
mcl_vars.inventory_header..
|
2017-01-06 01:37:40 +03:00
|
|
|
|
"list[current_player;main;0,4.5;9,3;9]"..
|
|
|
|
|
"list[current_player;main;0,7.74;9,1;]"..
|
|
|
|
|
"list[current_player;craft;1.75,0.5;3,3;]"..
|
2017-03-09 07:15:19 +03:00
|
|
|
|
"list[current_player;craftpreview;6.1,1.5;1,1;]"..
|
2017-02-06 00:23:44 +03:00
|
|
|
|
"image_button[8,0;1,1;craftguide_book.png;__mcl_craftguide;]"..
|
|
|
|
|
"tooltip[__mcl_craftguide;Show crafting recipes]"..
|
2017-01-06 02:36:58 +03:00
|
|
|
|
"listring[current_player;main]"..
|
2017-06-01 23:57:13 +03:00
|
|
|
|
"listring[current_player;craft]"
|
2017-01-06 01:37:40 +03:00
|
|
|
|
|
|
|
|
|
--player:set_inventory_formspec(form)
|
|
|
|
|
minetest.show_formspec(player:get_player_name(), "main", form)
|
|
|
|
|
end
|
|
|
|
|
|
2017-06-01 23:57:13 +03:00
|
|
|
|
-- Drop items in craft grid and reset inventory on closing
|
2017-01-06 01:37:40 +03:00
|
|
|
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|
|
|
|
if fields.quit then
|
2017-06-01 23:57:13 +03:00
|
|
|
|
drop_fields(player,"craft")
|
2017-06-02 02:14:21 +03:00
|
|
|
|
if not minetest.setting_getbool("creative_mode") and (formname == "" or formname == "main") then
|
2017-01-09 05:29:52 +03:00
|
|
|
|
set_inventory(player)
|
2017-01-06 01:37:40 +03:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
|
2017-03-02 01:34:48 +03:00
|
|
|
|
-- Drop crafting grid items on leaving
|
|
|
|
|
minetest.register_on_leaveplayer(function(player)
|
|
|
|
|
drop_fields(player, "craft")
|
|
|
|
|
end)
|
|
|
|
|
|
2017-01-06 01:37:40 +03:00
|
|
|
|
minetest.register_on_joinplayer(function(player)
|
|
|
|
|
--init inventory
|
2017-01-06 03:18:02 +03:00
|
|
|
|
player:get_inventory():set_width("main", 9)
|
|
|
|
|
player:get_inventory():set_size("main", 36)
|
|
|
|
|
|
2017-01-06 01:37:40 +03:00
|
|
|
|
--set hotbar size
|
2017-01-06 03:25:49 +03:00
|
|
|
|
player:hud_set_hotbar_itemcount(9)
|
2017-01-06 01:37:40 +03:00
|
|
|
|
--add hotbar images
|
2017-01-06 03:25:49 +03:00
|
|
|
|
player:hud_set_hotbar_image("crafting_hotbar.png")
|
|
|
|
|
player:hud_set_hotbar_selected_image("crafting_hotbar_selected.png")
|
|
|
|
|
|
|
|
|
|
if show_armor then
|
2017-03-09 21:15:09 +03:00
|
|
|
|
local set_player_armor_original = armor.set_player_armor
|
|
|
|
|
local update_inventory_original = armor.update_inventory
|
2017-01-06 03:25:49 +03:00
|
|
|
|
armor.set_player_armor = function(self, player)
|
2017-03-09 21:15:09 +03:00
|
|
|
|
set_player_armor_original(self, player)
|
2017-01-06 03:25:49 +03:00
|
|
|
|
update_armor(player)
|
2017-03-09 21:15:09 +03:00
|
|
|
|
end
|
|
|
|
|
armor.update_inventory = function(self, player)
|
|
|
|
|
update_inventory_original(self, player)
|
2017-01-06 01:37:40 +03:00
|
|
|
|
end
|
2017-03-09 21:19:53 +03:00
|
|
|
|
armor:set_player_armor(player)
|
|
|
|
|
armor:update_inventory(player)
|
2017-01-06 03:25:49 +03:00
|
|
|
|
end
|
2017-03-02 01:34:48 +03:00
|
|
|
|
|
2017-06-03 00:43:39 +03:00
|
|
|
|
-- In Creative Mode, the initial inventory setup is handled in creative.lua
|
|
|
|
|
if not minetest.setting_get("creative_mode") then
|
|
|
|
|
set_inventory(player)
|
|
|
|
|
end
|
2017-03-09 21:15:09 +03:00
|
|
|
|
|
2017-03-02 01:34:48 +03:00
|
|
|
|
--[[ Make sure the crafting grid is empty. Why? Because the player might have
|
|
|
|
|
items remaining in the crafting grid from the previous join; this is likely
|
|
|
|
|
when the server has been shutdown and the server didn't clean up the player
|
|
|
|
|
inventories. ]]
|
|
|
|
|
drop_fields(player, "craft")
|
2017-01-06 01:37:40 +03:00
|
|
|
|
end)
|
|
|
|
|
|
2017-03-09 19:16:50 +03:00
|
|
|
|
minetest.register_node("mcl_inventory:workbench", {
|
2017-01-06 01:54:02 +03:00
|
|
|
|
description = "Crafting Table",
|
2017-03-11 09:27:10 +03:00
|
|
|
|
_doc_items_longdesc = "A crafting table is a block which grants you access to a 3×3 crafting grid which allows you to perform advanced crafts.",
|
|
|
|
|
_doc_items_usagehelp = "Rightclick the crafting table to access the 3×3 crafting grid.",
|
2017-03-20 18:38:16 +03:00
|
|
|
|
_doc_items_hidden = false,
|
2017-03-11 18:36:05 +03:00
|
|
|
|
is_ground_content = false,
|
2017-01-06 01:37:40 +03:00
|
|
|
|
tiles = {"crafting_workbench_top.png", "default_wood.png", "crafting_workbench_side.png",
|
|
|
|
|
"crafting_workbench_side.png", "crafting_workbench_front.png", "crafting_workbench_front.png"},
|
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
|
paramtype = "light",
|
2017-03-11 07:34:58 +03:00
|
|
|
|
groups = {handy=1,axey=1, deco_block=1, material_wood=1},
|
2017-01-06 01:37:40 +03:00
|
|
|
|
on_rightclick = function(pos, node, clicker, itemstack)
|
|
|
|
|
set_workbench(clicker)
|
2017-01-06 01:54:02 +03:00
|
|
|
|
end,
|
2017-02-11 20:46:23 +03:00
|
|
|
|
sounds = mcl_sounds.node_sound_wood_defaults(),
|
2017-02-27 20:32:35 +03:00
|
|
|
|
_mcl_blast_resistance = 12.5,
|
|
|
|
|
_mcl_hardness = 2.5,
|
2017-01-06 01:37:40 +03:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
minetest.register_craft({
|
2017-03-09 19:16:50 +03:00
|
|
|
|
output = "mcl_inventory:workbench",
|
2017-01-06 01:37:40 +03:00
|
|
|
|
recipe = {
|
|
|
|
|
{"group:wood", "group:wood"},
|
|
|
|
|
{"group:wood", "group:wood"}
|
|
|
|
|
}
|
|
|
|
|
})
|
2017-01-10 08:43:07 +03:00
|
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
|
type = "fuel",
|
2017-03-09 19:16:50 +03:00
|
|
|
|
recipe = "mcl_inventory:workbench",
|
2017-01-10 08:43:07 +03:00
|
|
|
|
burntime = 15,
|
|
|
|
|
})
|
|
|
|
|
|
2017-03-09 19:16:50 +03:00
|
|
|
|
minetest.register_alias("crafting:workbench", "mcl_inventory:workbench")
|
|
|
|
|
|
2017-01-24 23:18:42 +03:00
|
|
|
|
if minetest.setting_getbool("creative_mode") then
|
2017-03-09 19:16:50 +03:00
|
|
|
|
dofile(minetest.get_modpath("mcl_inventory").."/creative.lua")
|
2017-01-24 23:18:42 +03:00
|
|
|
|
end
|