2017-01-05 23:37:40 +01: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 18:21:46 +01:00
|
|
|
local obj = minetest.add_item(p, itemstack)
|
2017-01-05 23:37:40 +01:00
|
|
|
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:getpos())
|
|
|
|
stack:clear()
|
|
|
|
inv:set_stack(name, i, stack)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local player_armor = {}
|
|
|
|
|
|
|
|
local function update_armor(player)
|
|
|
|
local out = ""
|
|
|
|
if not player then return end
|
|
|
|
local name = player:get_player_name()
|
|
|
|
if not armor or not armor.textures then return end
|
|
|
|
local armor_str = armor.textures[name].armor
|
|
|
|
if string.find(armor_str, "leggings") then
|
|
|
|
out = out .. "^crafting_armor_legs.png"
|
|
|
|
end
|
|
|
|
if string.find(armor_str, "boots") then
|
|
|
|
out = out .. "^crafting_armor_boots.png"
|
|
|
|
end
|
|
|
|
if string.find(armor_str, "helmet") then
|
|
|
|
out = out .. "^crafting_armor_helmet.png"
|
|
|
|
end
|
|
|
|
if string.find(armor_str, "chestplate") then
|
|
|
|
out = out .. "^crafting_armor_chest.png"
|
|
|
|
end
|
|
|
|
player_armor[name] = out
|
|
|
|
end
|
|
|
|
|
|
|
|
local function set_inventory(player)
|
|
|
|
if minetest.setting_getbool("creative_mode") then
|
2017-01-06 01:25:49 +01:00
|
|
|
crafting.set_creative_formspec(player, 0, 1)
|
|
|
|
return
|
2017-01-05 23:37:40 +01:00
|
|
|
end
|
2017-01-06 01:18:02 +01:00
|
|
|
player:get_inventory():set_width("craft", 2)
|
|
|
|
player:get_inventory():set_size("craft", 4)
|
2017-01-05 23:37:40 +01:00
|
|
|
|
|
|
|
local player_name = player:get_player_name()
|
|
|
|
local img = "crafting_inventory_player.png"
|
|
|
|
local armor_img = ""
|
|
|
|
if show_armor then
|
|
|
|
armor_img = "^crafting_inventory_armor.png"
|
|
|
|
if player_armor[player_name] ~= nil then
|
|
|
|
img = img .. player_armor[player_name]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local img_element = "image[1,0;3,4;"..img.."]"
|
|
|
|
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
|
|
|
|
img_element = "image[1.5,0;2,4;"..img.."]"
|
|
|
|
end
|
|
|
|
|
|
|
|
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-01-31 23:32:56 +01:00
|
|
|
mcl_core.inventory_header..
|
2017-01-06 00:36:58 +01:00
|
|
|
img_element..
|
2017-01-05 23:37:40 +01:00
|
|
|
--armor
|
2017-01-06 00:36:58 +01: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]"..
|
|
|
|
-- craft and inventory
|
2017-01-05 23:37:40 +01:00
|
|
|
"list[current_player;main;0,4.5;9,3;9]"..
|
|
|
|
"list[current_player;main;0,7.74;9,1;]"..
|
2017-01-06 01:18:02 +01:00
|
|
|
"list[current_player;craft;4,1;2,2]"..
|
2017-01-05 23:37:40 +01:00
|
|
|
"list[current_player;craftpreview;7,1.5;1,1;]"..
|
2017-01-06 00:36:58 +01:00
|
|
|
-- for shortcuts
|
|
|
|
"listring[current_player;main]"..
|
|
|
|
"listring[current_player;craft]"..
|
|
|
|
"listring[current_player;main]"..
|
|
|
|
"listring[detached:"..player_name.."_armor;armor]"..
|
2017-01-05 23:37:40 +01:00
|
|
|
"inv"
|
|
|
|
|
|
|
|
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-01-31 23:32:56 +01:00
|
|
|
mcl_core.inventory_header..
|
2017-01-05 23:37:40 +01: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;]"..
|
|
|
|
"list[current_player;craftpreview;5.75,1.5;1,1;]"..
|
2017-01-06 00:36:58 +01:00
|
|
|
"listring[current_player;main]"..
|
|
|
|
"listring[current_player;craft]"..
|
2017-01-05 23:37:40 +01:00
|
|
|
"wob"
|
|
|
|
|
|
|
|
--player:set_inventory_formspec(form)
|
|
|
|
minetest.show_formspec(player:get_player_name(), "main", form)
|
|
|
|
end
|
|
|
|
|
|
|
|
--drop craf items and reset inventory on closing
|
|
|
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|
|
|
if fields.quit then
|
|
|
|
local formspec = player:get_inventory_formspec()
|
|
|
|
local size = string.len(formspec)
|
|
|
|
local marker = string.sub(formspec,size-2)
|
|
|
|
if marker == "inv" or marker == "wob" then
|
|
|
|
drop_fields(player,"craft")
|
2017-01-09 03:29:52 +01:00
|
|
|
set_inventory(player)
|
2017-01-05 23:37:40 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
minetest.register_on_joinplayer(function(player)
|
|
|
|
--init inventory
|
|
|
|
set_inventory(player)
|
2017-01-06 01:18:02 +01:00
|
|
|
player:get_inventory():set_width("main", 9)
|
|
|
|
player:get_inventory():set_size("main", 36)
|
|
|
|
|
2017-01-05 23:37:40 +01:00
|
|
|
--set hotbar size
|
2017-01-06 01:25:49 +01:00
|
|
|
player:hud_set_hotbar_itemcount(9)
|
2017-01-05 23:37:40 +01:00
|
|
|
--add hotbar images
|
2017-01-06 01:25:49 +01:00
|
|
|
player:hud_set_hotbar_image("crafting_hotbar.png")
|
|
|
|
player:hud_set_hotbar_selected_image("crafting_hotbar_selected.png")
|
|
|
|
|
|
|
|
if show_armor then
|
|
|
|
local armor_orginal = armor.set_player_armor
|
|
|
|
armor.set_player_armor = function(self, player)
|
|
|
|
armor_orginal(self, player)
|
|
|
|
update_armor(player)
|
|
|
|
set_inventory(player)
|
2017-01-05 23:37:40 +01:00
|
|
|
end
|
2017-01-06 01:25:49 +01:00
|
|
|
end
|
2017-01-05 23:37:40 +01:00
|
|
|
end)
|
|
|
|
|
|
|
|
minetest.register_node("crafting:workbench", {
|
2017-01-05 23:54:02 +01:00
|
|
|
description = "Crafting Table",
|
2017-01-05 23:37:40 +01: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-02-01 13:44:36 +01:00
|
|
|
groups = {choppy=2,oddly_breakable_by_hand=2,deco_block=1},
|
2017-01-05 23:37:40 +01:00
|
|
|
on_rightclick = function(pos, node, clicker, itemstack)
|
|
|
|
set_workbench(clicker)
|
2017-01-05 23:54:02 +01:00
|
|
|
end,
|
2017-01-31 23:32:56 +01:00
|
|
|
sounds = mcl_core.node_sound_wood_defaults(),
|
2017-01-05 23:37:40 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "crafting:workbench",
|
|
|
|
recipe = {
|
|
|
|
{"group:wood", "group:wood"},
|
|
|
|
{"group:wood", "group:wood"}
|
|
|
|
}
|
|
|
|
})
|
2017-01-10 06:43:07 +01:00
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
type = "fuel",
|
|
|
|
recipe = "crafting:workbench",
|
|
|
|
burntime = 15,
|
|
|
|
})
|
|
|
|
|
2017-01-24 21:18:42 +01:00
|
|
|
if minetest.setting_getbool("creative_mode") then
|
|
|
|
dofile(minetest.get_modpath("crafting").."/creative.lua")
|
|
|
|
end
|
|
|
|
|