From 26fb517eb50241e3c2edbea036e79ed6ce7d7daa Mon Sep 17 00:00:00 2001 From: Thomas Rudin Date: Fri, 25 Oct 2019 21:19:13 +0200 Subject: [PATCH] stash/unstash II --- blocks/stash_inventory.lua | 81 +++++++++++++++++++++++++++++++++++ blocks/unstash_inventory.lua | 32 ++++++++++++++ textures/epic_briefcase.png | Bin 0 -> 663 bytes textures/epic_cut.png | Bin 0 -> 710 bytes textures/epic_filter.png | Bin 0 -> 651 bytes 5 files changed, 113 insertions(+) create mode 100644 blocks/stash_inventory.lua create mode 100644 blocks/unstash_inventory.lua create mode 100644 textures/epic_briefcase.png create mode 100644 textures/epic_cut.png create mode 100644 textures/epic_filter.png diff --git a/blocks/stash_inventory.lua b/blocks/stash_inventory.lua new file mode 100644 index 0000000..b64cf7f --- /dev/null +++ b/blocks/stash_inventory.lua @@ -0,0 +1,81 @@ + + +local update_formspec = function(meta) + meta:set_string("infotext", "Stash inventory") + + meta:set_string("formspec", "size[8,7;]" .. + -- col 2 + "list[context;main;0,0.5;8,1;]" .. + "list[current_player;main;0,3;8,4;]" .. + "listring[]" .. + "") +end + +minetest.register_node("epic:stash_inv", { + description = "Epic stash inventory block", + tiles = { + "epic_node_bg.png", + "epic_node_bg.png", + "epic_node_bg.png", + "epic_node_bg.png", + "epic_node_bg.png", + "epic_node_bg.png^epic_briefcase.png", + }, + paramtype2 = "facedir", + groups = {cracky=3,oddly_breakable_by_hand=3,epic=1}, + on_rotate = screwdriver.rotate_simple, + + after_place_node = function(pos) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + inv:set_size("main", 8) + + update_formspec(meta, pos) + end, + + + allow_metadata_inventory_put = function(pos, _, _, stack, player) + if minetest.is_protected(pos, player:get_player_name()) then + return 0 + end + + return stack:get_count() + end, + + allow_metadata_inventory_take = function(pos, _, _, stack, player) + if minetest.is_protected(pos, player:get_player_name()) then + return 0 + end + + return stack:get_count() + end, + + epic = { + on_enter = function(_, meta, player, ctx) + ctx.data.stashed_items = ctx.data.stashed_items or {} + local filter_map = {} + local inv = meta:get_inventory() + local filter_items = inv:get_list("main") + for _, filter_item in ipairs(filter_items) do + local node_name = filter_item:get_name() + if node_name and node_name ~= "" then + filter_map[node_name] = true + end + end + + local player_inv = player:get_inventory() + local i = 1 + while i <= player_inv:get_size("main") do + local stack = player_inv:get_stack("main", i) + if filter_map[stack:get_name()] then + player_inv:set_stack("main", i, ItemStack(nil)) + table.insert(ctx.data.stashed_items, stack:to_string()) + end + + i = i + 1 + end + + ctx.next() + end + } +}) diff --git a/blocks/unstash_inventory.lua b/blocks/unstash_inventory.lua new file mode 100644 index 0000000..b3b4c51 --- /dev/null +++ b/blocks/unstash_inventory.lua @@ -0,0 +1,32 @@ + + +minetest.register_node("epic:unstash_inv", { + description = "Epic unstash inventory block", + tiles = { + "epic_node_bg.png", + "epic_node_bg.png", + "epic_node_bg.png", + "epic_node_bg.png", + "epic_node_bg.png", + "epic_node_bg.png^epic_briefcase.png", + }, + paramtype2 = "facedir", + groups = {cracky=3,oddly_breakable_by_hand=3,epic=1}, + on_rotate = screwdriver.rotate_simple, + + epic = { + on_enter = function(_, _, player, ctx) + ctx.data.stashed_items = ctx.data.stashed_items or {} + local player_inv = player:get_inventory() + + for _, itemstr in ipairs(ctx.data.stashed_items) do + local stack = ItemStack(itemstr) + if player_inv:room_for_item("main", stack) then + player_inv:add_item("main", stack) + end + end + + ctx.next() + end + } +}) diff --git a/textures/epic_briefcase.png b/textures/epic_briefcase.png new file mode 100644 index 0000000000000000000000000000000000000000..b8d3e35b53ce9311ebeae81e591df1074ac9831d GIT binary patch literal 663 zcmV;I0%-k-P){kWM|!uj^$dm+%YmbR`tWrPk65Lcz<)_p@Od``Kmj&~v)w zh*s(m^Bw3|2|k~?iK-hX0AU+dm__RR161ET3!^Cp7xL)7TfN=v+41@pb2DyJpfxx& zJkJNO-HX_05{jDwxzg}!nxWqIA|8)HGe$~=^`(iItnWgruBh9D+^kC(IYAUeK8w5+ zqsWC02_OR>p|t6hgQ8(2BqsYmf%RTIpvx+JcvF+$mMK}GPz{TOzZzZi6^#7S=6I8w z1$)}rrpwE7aMM!+kpGym#&WYH$JqNh14!5zc;D0D@(+LtsduwQ#Vu+_ECC3MBmHF_ z?BTHny`jv8JN=CSMGJXD1OdlW>FwVtlxDaq=JOc=`8RRk!n2=G?d3P4F ztrJZrJ0o%b{VwF5cfl%Ny9i*6b{2$S*W2r~CYt+oB6^Viyb-jXL(7><(K&hh8rJpQ zHN6w0kVFt5?f3?;r?wKA)JMRk)hR~XR2WXVOM0%|oIt2~G*`hnLdxDhGGzd}wpGAM zeV`e{qY?|49j`SDH5t(Wib@(Z6lra&o$n{b$e$`w1(@?VftXZl(YL002ovPDHLkV1i8dHx&Q? literal 0 HcmV?d00001 diff --git a/textures/epic_cut.png b/textures/epic_cut.png new file mode 100644 index 0000000000000000000000000000000000000000..cf1a93b2cda33022c2e651a86743d05e6c062c30 GIT binary patch literal 710 zcmV;%0y+JOP)YcUY|IBMO<2tmz7^cnCrol7p8I&V(#4BoHAeo zEe6dYw9X;=$J+zc)yU3OkF6iYW8( z32_RGa53)Mx$h7o7q60_q(Th1?B(uY~|E+1qFC{ z8I+V&7`XX37?^+-e*5-=;n0CYcQ0JN;>XA(W|XR*zhu_a3oBC}t!`Y)$|jL&R=K9r zLQjan>h~Fjw_krVu&{G~e*5Lyi??sze|+@t{-ZaqUY&jU=KcJOM|MAF}q96-m5zz|;%Pr>GG*?coWa`A+Zrk1MZujp$qR7%0`yK~({D0ri{f-Gdo!hIH z;Imd6T5M+CYvh9j9cHaB!uCs7G&yRXe@boa3muN{t zx}afnNr6;UvB%C~EF~hcP=K3PvB_e>-7iA_io#s^^(mT;f$8{}{q;?SB7p@ZxT