version 0.21
61
mods/inventory/api.lua
Normal file
|
@ -0,0 +1,61 @@
|
|||
inven = {}
|
||||
|
||||
function inventory.creative_inv(player)
|
||||
local name = player:get_player_name()
|
||||
CREATIVE_FORMSPEC = "invsize[11,9.75;]"..
|
||||
--"background[-0.25,1;10.5,8;inventory_creative_inventory_bg.png]"..
|
||||
"button[9.5,0;1.5,1.5;creative_search;Search]"..
|
||||
"list[detached:"..name.."_armor;armor_head;0.25,1.25;1,1;]"..
|
||||
"list[detached:"..name.."_armor;armor_torso;0.25,2.5;1,1;]"..
|
||||
"list[detached:"..name.."_armor;armor_legs;2.75,1.25;1,1;]"..
|
||||
"list[detached:"..name.."_armor;armor_feet;2.75,2.5;1,1;]"..
|
||||
"image[1.3,1;1.5,3;player.png]"..
|
||||
"list[current_player;main;0,4;9,4;9]"..
|
||||
"list[current_player;main;0,7.75;9,1;]"..
|
||||
"list[detached:creative_trash;main;9.1,7.75;1,1;]"..
|
||||
"button[9.15,6;1,1;clear_inventory;Clear]"..
|
||||
"button[9.5,8.75;1.5,1.5;creative_survival;Survival]"
|
||||
player:get_inventory():set_width("main", 9)
|
||||
player:get_inventory():set_size("main", 36)
|
||||
player:set_inventory_formspec(CREATIVE_FORMSPEC)
|
||||
end
|
||||
|
||||
function inventory.survival_inv(player)
|
||||
local name = player:get_player_name()
|
||||
SURVIVAL_FORMSPEC = "invsize[9,9.5;]"..
|
||||
--"background[-0.4,-0.45;9.8,9.825;inventory_survival_inventory_bg.png]"..
|
||||
"list[detached:"..name.."_armor;armor_head;0,0;1,1;]"..
|
||||
"list[detached:"..name.."_armor;armor_torso;0,1;1,1;]"..
|
||||
"list[detached:"..name.."_armor;armor_legs;0,2;1,1;]"..
|
||||
"list[detached:"..name.."_armor;armor_feet;0,3;1,1;]"..
|
||||
"image[1.6,0.25;2,4;player.png]"..
|
||||
"list[current_player;main;0,4.5;9,4;9]"..
|
||||
"list[current_player;main;0,8.25;9,1;]"..
|
||||
"list[current_player;craft;4,1;2,2;]"..
|
||||
"list[current_player;craftpreview;7,1.5;1,1;]"
|
||||
player:get_inventory():set_width("craft", 2)
|
||||
player:get_inventory():set_size("craft", 4)
|
||||
player:get_inventory():set_width("main", 9)
|
||||
player:get_inventory():set_size("main", 36)
|
||||
player:set_inventory_formspec(SURVIVAL_FORMSPEC)
|
||||
end
|
||||
|
||||
CRAFTING_FORMSPEC = "size[9,8.5]"..
|
||||
"background[-0.4,-0.5;9.78,9.5;inventory_crafting_inventory_bg.png]"..
|
||||
"list[current_player;main;0,4.32;9,4;9]"..
|
||||
"list[current_player;main;0,7.6;9,1;]"..
|
||||
"list[current_player;craft;1.218,0.46;3,3;]"..
|
||||
"list[current_player;craftpreview;6.44,1.5;1.5,1.5;]"
|
||||
|
||||
--
|
||||
-- Hotbar
|
||||
--
|
||||
|
||||
function inventory.hotbar(player)
|
||||
local name = player:get_player_name()
|
||||
if player.hud_set_hotbar_itemcount then
|
||||
minetest.after(0, player.hud_set_hotbar_itemcount, player, 9)
|
||||
end
|
||||
player:hud_set_hotbar_image("inventory_hotbar.png")
|
||||
player:hud_set_hotbar_selected_image("inventory_hotbar_selected.png")
|
||||
end
|
13
mods/inventory/config.txt
Normal file
|
@ -0,0 +1,13 @@
|
|||
--Configuration file for Inventory
|
||||
|
||||
Default_Mode = "Survival"
|
||||
--Mode players are in when they join for the first time. Possible values: Creative, Survival. CASE SENSITIVE
|
||||
|
||||
--IMPORTANT: This formspec must be valid. If you want compatibility with other inventory-changing mods
|
||||
--or games, you must change the above to the formspec definition for that mod and remove it
|
||||
--from their mod.
|
||||
|
||||
--NOTE: At the moment, the creative formspec cannot be changed, as it is required to use variables inside the mod.
|
||||
--You can try to change it, but it probably will not work. The same is true for a survival inventory with variables,
|
||||
--such as inventory_plus. It is still possible to change the SURVIVAL_FORMSPEC variable inside the code to cope
|
||||
--with this, but it will not be easy.
|
2
mods/inventory/depends.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
default
|
||||
3d_armor
|
251
mods/inventory/init.lua
Normal file
|
@ -0,0 +1,251 @@
|
|||
local path = minetest.get_modpath(minetest.get_current_modname())
|
||||
|
||||
local filepath = minetest.get_worldpath()
|
||||
|
||||
local function save_player_data()
|
||||
local file = io.open(filepath .. "/playerdata.txt", "w")
|
||||
file:write(minetest.serialize(playerdata))
|
||||
file:close()
|
||||
end
|
||||
|
||||
function load_player_data()
|
||||
local file = io.open(filepath .. "/playerdata.txt", "r")
|
||||
if file then
|
||||
local table = minetest.deserialize(file:read("*all"))
|
||||
if type(table) == "table" then
|
||||
return table
|
||||
|
||||
end
|
||||
end
|
||||
return {}
|
||||
end
|
||||
|
||||
inventory = {}
|
||||
inventory.inventory_size = 0
|
||||
pagenum = 0
|
||||
playerdata = load_player_data()
|
||||
|
||||
dofile(path.."/config.txt")
|
||||
dofile(path.."/api.lua")
|
||||
dofile(path.."/workbench.lua")
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
pname = player:get_player_name()
|
||||
playerdata = load_player_data()
|
||||
if not playerdata[pname] then
|
||||
playerdata[pname] = {}
|
||||
playerdata[pname]['gamemode'] = Default_Mode
|
||||
save_player_data()
|
||||
end
|
||||
if not playerdata[pname]['gamemode'] then
|
||||
playerdata[pname]['gamemode'] = Default_Mode
|
||||
save_player_data()
|
||||
playerdata = load_player_data()
|
||||
minetest.after(0.3, function() updategamemode(pname, "0") end)
|
||||
else
|
||||
minetest.after(0.3, function() updategamemode(pname, "0") end)
|
||||
end
|
||||
end)
|
||||
|
||||
--Ensure that all mods are loaded before editing inventory.
|
||||
minetest.after(0.3, function()
|
||||
local trash = minetest.create_detached_inventory("creative_trash", {
|
||||
-- Allow the stack to be placed and remove it in on_put()
|
||||
-- This allows the creative inventory to restore the stack
|
||||
allow_put = function(inv, listname, index, stack, player)
|
||||
return stack:get_count()
|
||||
end,
|
||||
on_put = function(inv, listname, index, stack, player)
|
||||
inv:set_stack(listname, index, "")
|
||||
end,
|
||||
})
|
||||
trash:set_size("main", 1)
|
||||
|
||||
|
||||
creative_list = {}
|
||||
for name,def in pairs(minetest.registered_items) do
|
||||
if (not def.groups.not_in_creative_inventory or def.groups.not_in_creative_inventory == 0)
|
||||
and def.description and def.description ~= "" then
|
||||
table.insert(creative_list, name)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
local inv = minetest.create_detached_inventory("creative", {
|
||||
allow_move = function(inv, from_list, from_index, to_list, to_index, count, player)
|
||||
return count
|
||||
end,
|
||||
allow_put = function(inv, listname, index, stack, player)
|
||||
return 0
|
||||
end,
|
||||
allow_take = function(inv, listname, index, stack, player)
|
||||
return -1
|
||||
end,
|
||||
on_move = function(inv, from_list, from_index, to_list, to_index, count, player)
|
||||
end,
|
||||
on_put = function(inv, listname, index, stack, player)
|
||||
end,
|
||||
on_take = function(inv, listname, index, stack, player)
|
||||
print(player:get_player_name().." takes item from creative inventory; listname="..dump(listname)..", index="..dump(index)..", stack="..dump(stack))
|
||||
if stack then
|
||||
print("stack:get_name()="..dump(stack:get_name())..", stack:get_count()="..dump(stack:get_count()))
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
table.sort(creative_list)
|
||||
|
||||
inv:set_size("main", #creative_list)
|
||||
|
||||
for _,itemstring in ipairs(creative_list) do
|
||||
local stack = ItemStack(itemstring)
|
||||
local stack2 = nil
|
||||
if stack:get_stack_max() == 1 then
|
||||
stack2 = ItemStack(stack:get_name())
|
||||
else
|
||||
stack2 = ItemStack(stack:get_name().." "..(stack:get_stack_max()))--- for know how many item
|
||||
end
|
||||
inv:add_item("main", stack2)
|
||||
end
|
||||
inventory.inventory_size = #creative_list
|
||||
|
||||
end)
|
||||
|
||||
-- Create detached creative inventory after loading all mods
|
||||
function updategamemode(pname, status)
|
||||
playerdata = load_player_data()
|
||||
if not status then
|
||||
print(pname.." has switched to "..playerdata[pname]['gamemode'].." Mode.")
|
||||
minetest.chat_send_all(pname.." has switched to "..playerdata[pname]['gamemode'].." Mode.")
|
||||
end
|
||||
if playerdata[pname]['gamemode'] == "Creative" then
|
||||
local player = minetest.env:get_player_by_name(pname)
|
||||
|
||||
inventory.set_player_formspec(player, 1, 1)
|
||||
else
|
||||
|
||||
local player = minetest.env:get_player_by_name(pname)
|
||||
inventory.set_player_formspec(player, 1, 1)
|
||||
|
||||
end
|
||||
end
|
||||
inventory.set_player_formspec = function(player, start_i, pagenum)
|
||||
playerdata = load_player_data()
|
||||
if playerdata[player:get_player_name()]['gamemode'] == "Creative" or creative_type == "default" then
|
||||
inventory.creative_inv(player)
|
||||
inventory.hotbar(player)
|
||||
end
|
||||
if creative_type == "search" then
|
||||
pagenum = math.floor(pagenum)
|
||||
pagemax = math.floor((inventory.inventory_size-1) / (9*3) + 1)
|
||||
CREATIVE_SEARCH_ITEMS = "invsize[10,7;]"..
|
||||
"background[-0.22,-0.25;10.8,7.7;creative_inventory_bg.png]"..
|
||||
"button[8,0;1.5,1;creative_search;Search]"..
|
||||
"list[current_player;main;0.21,6.05;9,1;]"..
|
||||
"list[detached:creative;main;0.21,2.78;9,3;"..tostring(start_i).."]"..
|
||||
"label[7.25,1.7;"..tostring(pagenum).."/"..tostring(pagemax).."]"..
|
||||
"button[5.5,1.5;1.5,1;creative_prev;<<]"..
|
||||
"button[8,1.5;1.5,1;creative_next;>>]"..
|
||||
"button[5.5,0;1.5,1;creative_survival;Survival]"..
|
||||
"list[detached:creative_trash;main;9.28,6.05;1,1;]"
|
||||
player:set_inventory_formspec(CREATIVE_SEARCH_ITEMS)
|
||||
inventory.hotbar(player)
|
||||
end
|
||||
if playerdata[player:get_player_name()]['gamemode'] == "Survival" then
|
||||
inventory.survival_inv(player)
|
||||
inventory.hotbar(player)
|
||||
end
|
||||
end
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if not playerdata[pname]['gamemode'] == "Creative" then
|
||||
return
|
||||
end
|
||||
-- Figure out current page from formspec
|
||||
local current_page = 0
|
||||
local formspec = player:get_inventory_formspec()
|
||||
local start_i = string.match(formspec, "list%[detached:creative;main;[%d.]+,[%d.]+;[%d.]+,[%d.]+;(%d+)%]")
|
||||
start_i = tonumber(start_i) or 0
|
||||
|
||||
if fields.clear_inventory then
|
||||
local inventory = {}
|
||||
player:get_inventory():set_list("main", inventory)
|
||||
end
|
||||
|
||||
if fields.creative_search then
|
||||
creative_type = "search"
|
||||
end
|
||||
|
||||
if fields.creative_survival then
|
||||
creative_type = "default"
|
||||
inventory.creative_inv(player)
|
||||
end
|
||||
|
||||
if fields.creative_prev then
|
||||
start_i = start_i - 9*3
|
||||
end
|
||||
if fields.creative_next then
|
||||
start_i = start_i + 9*3
|
||||
end
|
||||
|
||||
if start_i < 0 then
|
||||
start_i = start_i + 9*3
|
||||
end
|
||||
if start_i >= inventory.inventory_size then
|
||||
start_i = start_i - 9*3
|
||||
end
|
||||
|
||||
if start_i < 0 or start_i >= inventory.inventory_size then
|
||||
start_i = 0
|
||||
end
|
||||
|
||||
inventory.set_player_formspec(player, start_i, start_i / (9*3) + 1)
|
||||
end)
|
||||
|
||||
if minetest.setting_getbool("creative_mode")==false then
|
||||
local gm_priv = true
|
||||
elseif minetest.setting_getbool("creative_mode")==true then
|
||||
local gm_priv = false
|
||||
end
|
||||
|
||||
minetest.register_chatcommand('gamemode',{
|
||||
params = "1, c | 0, s",
|
||||
description = 'Switch your gamemode',
|
||||
privs = {gamemode = gm_priv},
|
||||
func = function(name, param)
|
||||
if param == "1" or param == "c" then
|
||||
playerdata[name]['gamemode'] = "Creative"
|
||||
save_player_data()
|
||||
minetest.chat_send_player(name, 'Your gamemode is now: '..playerdata[name]['gamemode'])
|
||||
updategamemode(name)
|
||||
elseif param == "0" or param == "s" then
|
||||
playerdata[name]['gamemode'] = "Survival"
|
||||
save_player_data()
|
||||
minetest.chat_send_player(name, 'Your gamemode is now: '..playerdata[name]['gamemode'])
|
||||
updategamemode(name)
|
||||
else
|
||||
minetest.chat_send_player(name, "Error: That player does not exist!")
|
||||
return false
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
|
||||
--[[minetest.register_on_punchnode(function(pos, node, puncher)
|
||||
local pos = pos
|
||||
local pname = puncher:get_player_name()
|
||||
if playerdata[pname]['gamemode'] == "Creative" then
|
||||
minetest.after(0.1, function()
|
||||
minetest.env:remove_node(pos)
|
||||
end)
|
||||
end
|
||||
end)]]
|
||||
|
||||
minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack)
|
||||
local pname = placer:get_player_name()
|
||||
if playerdata[pname]['gamemode'] == "Creative" then
|
||||
return true
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_privilege("gamemode", "Permission to use /gamemode.")
|
BIN
mods/inventory/textures/3d_armor_inv_boots_clear.png
Normal file
After Width: | Height: | Size: 174 B |
BIN
mods/inventory/textures/3d_armor_inv_chestplate_clear.png
Normal file
After Width: | Height: | Size: 294 B |
BIN
mods/inventory/textures/3d_armor_inv_helmet_clear.png
Normal file
After Width: | Height: | Size: 171 B |
BIN
mods/inventory/textures/3d_armor_inv_leggings_clear.png
Normal file
After Width: | Height: | Size: 145 B |
BIN
mods/inventory/textures/New folder/crafting_inventory.png
Normal file
After Width: | Height: | Size: 12 KiB |
BIN
mods/inventory/textures/New folder/crafting_inventory_player.png
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
mods/inventory/textures/New folder/crafting_workbench.png
Normal file
After Width: | Height: | Size: 4.6 KiB |
BIN
mods/inventory/textures/New folder/trap.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
mods/inventory/textures/creative_inventory_bg.png
Normal file
After Width: | Height: | Size: 12 KiB |
BIN
mods/inventory/textures/inventory_crafting_inventory_bg.png
Normal file
After Width: | Height: | Size: 5.1 KiB |
BIN
mods/inventory/textures/inventory_crafting_table_front.png
Normal file
After Width: | Height: | Size: 801 B |
BIN
mods/inventory/textures/inventory_crafting_table_side.png
Normal file
After Width: | Height: | Size: 768 B |
BIN
mods/inventory/textures/inventory_crafting_table_top.png
Normal file
After Width: | Height: | Size: 1,012 B |
After Width: | Height: | Size: 4.5 KiB |
BIN
mods/inventory/textures/inventory_creative_inventory_bg.png
Normal file
After Width: | Height: | Size: 3.2 KiB |
BIN
mods/inventory/textures/inventory_hotbar.png
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
mods/inventory/textures/inventory_hotbar_selected.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
mods/inventory/textures/inventory_survival_inventory_bg.png
Normal file
After Width: | Height: | Size: 3.5 KiB |
26
mods/inventory/workbench.lua
Normal file
|
@ -0,0 +1,26 @@
|
|||
minetest.register_node("inventory:crafting_table", {
|
||||
description = "Crafting Table",
|
||||
tiles = {"inventory_crafting_table_top.png", "default_wood.png", "inventory_crafting_table_side.png",
|
||||
"inventory_crafting_table_side.png", "inventory_crafting_table_front.png", "inventory_crafting_table_front.png"},
|
||||
paramtype2 = "facedir",
|
||||
paramtype = "light",
|
||||
groups = {choppy=2,oddly_breakable_by_hand=1,flammable=2},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
on_rightclick = function(pos, node, clicker, itemstack)
|
||||
clicker:get_inventory():set_width("craft", 3)
|
||||
clicker:get_inventory():set_size("craft", 9)
|
||||
clicker:get_inventory():set_width("main", 9)
|
||||
clicker:get_inventory():set_size("main", 36)
|
||||
minetest.show_formspec(clicker:get_player_name(), "inventory:craftin_table", CRAFTING_FORMSPEC)
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "inventory:crafting_table",
|
||||
recipe = {
|
||||
{"group:wood", "group:wood"},
|
||||
{"group:wood", "group:wood"},
|
||||
},
|
||||
})
|
||||
|
||||
|