From 80fb59f9ac37b359c0b667af03e16d20d1645e0d Mon Sep 17 00:00:00 2001 From: AFCMS Date: Thu, 20 Jan 2022 09:22:17 +0100 Subject: [PATCH] add barrel --- mods/CORE/mcl_util/init.lua | 19 +++ mods/ITEMS/mcl_barrels/init.lua | 141 ++++++++++++++++++ .../mcl_barrels/locale/mcl_barrels.de.tr | 1 + .../mcl_barrels/locale/mcl_barrels.es.tr | 1 + .../mcl_barrels/locale/mcl_barrels.fr.tr | 1 + .../mcl_barrels/locale/mcl_barrels.pl.tr | 1 + .../mcl_barrels/locale/mcl_barrels.ru.tr | 1 + mods/ITEMS/mcl_barrels/locale/template.txt | 1 + mods/ITEMS/mcl_barrels/mod.conf | 3 + .../textures/mcl_barrels_barrel_bottom.png | Bin 0 -> 542 bytes .../textures/mcl_barrels_barrel_side.png | Bin 0 -> 499 bytes .../textures/mcl_barrels_barrel_top.png | Bin 0 -> 566 bytes .../textures/mcl_barrels_barrel_top_open.png | Bin 0 -> 421 bytes mods/ITEMS/mcl_chests/init.lua | 17 +-- mods/ITEMS/mcl_core/nodes_trees.lua | 1 - 15 files changed, 170 insertions(+), 17 deletions(-) create mode 100644 mods/ITEMS/mcl_barrels/init.lua create mode 100644 mods/ITEMS/mcl_barrels/locale/mcl_barrels.de.tr create mode 100644 mods/ITEMS/mcl_barrels/locale/mcl_barrels.es.tr create mode 100644 mods/ITEMS/mcl_barrels/locale/mcl_barrels.fr.tr create mode 100644 mods/ITEMS/mcl_barrels/locale/mcl_barrels.pl.tr create mode 100644 mods/ITEMS/mcl_barrels/locale/mcl_barrels.ru.tr create mode 100644 mods/ITEMS/mcl_barrels/locale/template.txt create mode 100644 mods/ITEMS/mcl_barrels/mod.conf create mode 100755 mods/ITEMS/mcl_barrels/textures/mcl_barrels_barrel_bottom.png create mode 100755 mods/ITEMS/mcl_barrels/textures/mcl_barrels_barrel_side.png create mode 100755 mods/ITEMS/mcl_barrels/textures/mcl_barrels_barrel_top.png create mode 100755 mods/ITEMS/mcl_barrels/textures/mcl_barrels_barrel_top_open.png diff --git a/mods/CORE/mcl_util/init.lua b/mods/CORE/mcl_util/init.lua index 9be40a1e4..a9e8e7319 100644 --- a/mods/CORE/mcl_util/init.lua +++ b/mods/CORE/mcl_util/init.lua @@ -357,6 +357,25 @@ function mcl_util.get_first_occupied_inventory_slot(inventory, listname) return mcl_util.get_eligible_transfer_item_slot(inventory, listname) end +function mcl_util.drop_items_container_get(listname) + return function(pos, oldnode, oldmetadata) + local meta = minetest.get_meta(pos) + local meta2 = meta:to_table() + if oldmetadata then + meta:from_table(oldmetadata) + end + local inv = meta:get_inventory() + for i = 1, inv:get_size(listname) do + local stack = inv:get_stack(listname, i) + if not stack:is_empty() then + local p = vector.add(pos, vector.new(math.random(0, 10)/10 - 0.5, 0, math.random(0, 10)/10 - 0.5)) + minetest.add_item(p, stack) + end + end + meta:from_table(meta2) + end +end + -- Returns true if item (itemstring or ItemStack) can be used as a furnace fuel. -- Returns false otherwise function mcl_util.is_fuel(item) diff --git a/mods/ITEMS/mcl_barrels/init.lua b/mods/ITEMS/mcl_barrels/init.lua new file mode 100644 index 000000000..cec2f46d0 --- /dev/null +++ b/mods/ITEMS/mcl_barrels/init.lua @@ -0,0 +1,141 @@ +local S = minetest.get_translator("mcl_barrels") +local F = minetest.formspec_escape +local C = minetest.colorize + +--TODO: add craft +--TODO: add french translation +--TODO: complete ingame help and tooltips +--TODO: fix barrel rotation placement + +local open_barrels = {} + +local drop_content = mcl_util.drop_items_container_get("main") + +local function on_blast(pos) + local node = minetest.get_node(pos) + drop_content(pos, node) + minetest.remove_node(pos) +end + +local function barrel_open(pos, node, clicker) + local name = minetest.get_meta(pos):get_string("name") + + if name == "" then + name = S("Barrel") + end + + local playername = clicker:get_player_name() + + minetest.show_formspec(playername, + "mcl_barrels:barrel_"..pos.x.."_"..pos.y.."_"..pos.z, + table.concat({ + "size[9,8.75]", + "label[0,0;"..F(C("#313131", name)).."]", + "list[nodemeta:"..pos.x..","..pos.y..","..pos.z..";main;0,0.5;9,3;]", + mcl_formspec.get_itemslot_bg(0, 0.5, 9, 3), + "label[0,4.0;"..F(C("#313131", S("Inventory"))).."]", + "list[current_player;main;0,4.5;9,3;9]", + mcl_formspec.get_itemslot_bg(0, 4.5, 9, 3), + "list[current_player;main;0,7.74;9,1;]", + mcl_formspec.get_itemslot_bg(0, 7.74, 9, 1), + "listring[nodemeta:"..pos.x..","..pos.y..","..pos.z..";main]", + "listring[current_player;main]", + }) + ) + + minetest.swap_node(pos, { name = "mcl_barrels:barrel_open", param2 = node.param2 }) + open_barrels[playername] = pos +end + +local function close_forms(pos) + local players = minetest.get_connected_players() + local formname = "mcl_barrels:barrel_"..pos.x.."_"..pos.y.."_"..pos.z + for p = 1, #players do + if vector.distance(players[p]:get_pos(), pos) <= 30 then + minetest.close_formspec(players[p]:get_player_name(), formname) + end + end +end + +local function update_after_close(pos) + local node = minetest.get_node_or_nil(pos) + if not node then return end + if node.name == "mcl_barrels:barrel_open" then + minetest.swap_node(pos, {name = "mcl_barrels:barrel_closed", param2 = node.param2}) + end +end + +local function close_barrel(player) + local name = player:get_player_name() + local open = open_barrels[name] + if open == nil then + return + end + + update_after_close(open) + + open_barrels[name] = nil +end + +minetest.register_node("mcl_barrels:barrel_closed", { + description = S("Barrel"), + --_tt_help = tt_help, + --_doc_items_longdesc = longdesc, + --_doc_items_usagehelp = usagehelp, + tiles = {"mcl_barrels_barrel_top.png", "mcl_barrels_barrel_bottom.png", "mcl_barrels_barrel_side.png"}, + paramtype = "light", + paramtype2 = "facedir", + --on_place = mcl_util.rotate_axis, + on_place = function(itemstack, placer, pointed_thing) + minetest.rotate_and_place(itemstack, placer, pointed_thing, minetest.is_creative_enabled(placer:get_player_name()), {}, false) + return itemstack + end, + stack_max = 64, + sounds = mcl_sounds.node_sound_wood_defaults(), + groups = {handy = 1, axey = 1, container = 2, material_wood = 1, flammable = -1, deco_block = 1}, + on_construct = function(pos) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + inv:set_size("main", 9*3) + end, + after_place_node = function(pos, placer, itemstack, pointed_thing) + minetest.get_meta(pos):set_string("name", itemstack:get_meta():get_string("name")) + end, + after_dig_node = drop_content, + on_blast = on_blast, + on_rightclick = barrel_open, + on_destruct = close_forms, + _mcl_blast_resistance = 2.5, + _mcl_hardness = 2.5, +}) + +minetest.register_node("mcl_barrels:barrel_open", { + description = S("Barrel Open"), + --_tt_help = tt_help, + --_doc_items_longdesc = longdesc, + --_doc_items_usagehelp = usagehelp, + _doc_items_create_entry = false, + tiles = {"mcl_barrels_barrel_top_open.png", "mcl_barrels_barrel_bottom.png", "mcl_barrels_barrel_side.png"}, + paramtype = "light", + paramtype2 = "facedir", + drop = "mcl_barrels:barrel_closed", + stack_max = 64, + sounds = mcl_sounds.node_sound_wood_defaults(), + groups = {handy = 1, axey = 1, container = 2, material_wood = 1, flammable = -1, deco_block = 1, not_in_creative_inventory = 1}, + after_dig_node = drop_content, + on_blast = on_blast, + on_rightclick = barrel_open, + on_destruct = close_forms, + _mcl_blast_resistance = 2.5, + _mcl_hardness = 2.5, +}) + +minetest.register_on_player_receive_fields(function(player, formname, fields) + if formname:find("mcl_barrels:") == 1 and fields.quit then + close_barrel(player) + end +end) + +minetest.register_on_leaveplayer(function(player) + close_barrel(player) +end) \ No newline at end of file diff --git a/mods/ITEMS/mcl_barrels/locale/mcl_barrels.de.tr b/mods/ITEMS/mcl_barrels/locale/mcl_barrels.de.tr new file mode 100644 index 000000000..9d12a17cd --- /dev/null +++ b/mods/ITEMS/mcl_barrels/locale/mcl_barrels.de.tr @@ -0,0 +1 @@ +# textdomain: mcl_barrels \ No newline at end of file diff --git a/mods/ITEMS/mcl_barrels/locale/mcl_barrels.es.tr b/mods/ITEMS/mcl_barrels/locale/mcl_barrels.es.tr new file mode 100644 index 000000000..9d12a17cd --- /dev/null +++ b/mods/ITEMS/mcl_barrels/locale/mcl_barrels.es.tr @@ -0,0 +1 @@ +# textdomain: mcl_barrels \ No newline at end of file diff --git a/mods/ITEMS/mcl_barrels/locale/mcl_barrels.fr.tr b/mods/ITEMS/mcl_barrels/locale/mcl_barrels.fr.tr new file mode 100644 index 000000000..9d12a17cd --- /dev/null +++ b/mods/ITEMS/mcl_barrels/locale/mcl_barrels.fr.tr @@ -0,0 +1 @@ +# textdomain: mcl_barrels \ No newline at end of file diff --git a/mods/ITEMS/mcl_barrels/locale/mcl_barrels.pl.tr b/mods/ITEMS/mcl_barrels/locale/mcl_barrels.pl.tr new file mode 100644 index 000000000..9d12a17cd --- /dev/null +++ b/mods/ITEMS/mcl_barrels/locale/mcl_barrels.pl.tr @@ -0,0 +1 @@ +# textdomain: mcl_barrels \ No newline at end of file diff --git a/mods/ITEMS/mcl_barrels/locale/mcl_barrels.ru.tr b/mods/ITEMS/mcl_barrels/locale/mcl_barrels.ru.tr new file mode 100644 index 000000000..9d12a17cd --- /dev/null +++ b/mods/ITEMS/mcl_barrels/locale/mcl_barrels.ru.tr @@ -0,0 +1 @@ +# textdomain: mcl_barrels \ No newline at end of file diff --git a/mods/ITEMS/mcl_barrels/locale/template.txt b/mods/ITEMS/mcl_barrels/locale/template.txt new file mode 100644 index 000000000..9d12a17cd --- /dev/null +++ b/mods/ITEMS/mcl_barrels/locale/template.txt @@ -0,0 +1 @@ +# textdomain: mcl_barrels \ No newline at end of file diff --git a/mods/ITEMS/mcl_barrels/mod.conf b/mods/ITEMS/mcl_barrels/mod.conf new file mode 100644 index 000000000..2b0088b79 --- /dev/null +++ b/mods/ITEMS/mcl_barrels/mod.conf @@ -0,0 +1,3 @@ +name = mcl_barrels +depends = mcl_util, mcl_formspec, mcl_sounds +author = AFCMS \ No newline at end of file diff --git a/mods/ITEMS/mcl_barrels/textures/mcl_barrels_barrel_bottom.png b/mods/ITEMS/mcl_barrels/textures/mcl_barrels_barrel_bottom.png new file mode 100755 index 0000000000000000000000000000000000000000..9c5788061835706c6f4045a97ef519f3741ad999 GIT binary patch literal 542 zcmV+(0^$9MP)Px#1ZP1_K>z@;j|==^1poj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CPFTl(4AQ3y* zpte%l$ZnExH9t;M7LMIGb;a3?d}cgz&$;KGeE<6CQ7cKV6G~%=qY;I%T%2Z<#&*1M z9<3xTa-HyZx#HxxAX1>WEw?0B99=KN%N#+^@@9 zoU57X1W_6bfD~iGcFW?<@b0z7xIk$vVY}@vTI^RT#-Je7J476f@IDY{DY;I1FAr7G zK6qPfnhJ_NadlH-++V;xuEvzUTZb@0BalF|iN;9WT>yvzaQ^m1|6_ zoM$?nbmjk?Ujp#?Lq@7(PsX7fzkMLr2_jXJ>*a>UonZlF*(+A74V4X4Hgv|d)x^=L zlT#Y|)P-0Ga-EPmPx|(ZmryxRsCSL=(FkFj$NRw5P04Z<|2II-Oq}V2_4=NV=WlqQ zHT@sbecaCZpXQL70(Y)*K0-AbW|YuPggwCIK!T=@W7fo&!x$^>lFzu{b?9 z*w+8Bfk5rnr2CO)HA5Gj`^%W4)1&i;@!$U=F{)Zc6W&H-Nghz-Y;?L`_Wbv!z16dq zx9{#YSSZ$gu2N#{1*`tUb?xVVUVQJ=VxYKKtb6)n&e_k8|L*1%R8-M9xMu&)BALx? z1`AgleN^#^k-?B}^Mj>x9a99HoRq~}pa01!xZgfAcAAZLOlUOE%br6SrrvRCdVhCb zc>P*hYGc6L=PcV7l*+x@a6k6#J~PgVjRuZi6&J1A_W#|vHG$o&S~J5m_p}KJSv_C4 zOS)X(F~effDcprAiC$OzXB^vd&e=36Kh1H*g0_-*x*K&WOD8Rze`0~y@6uB)X=MTX zYuisSFjzge_nR51++t$)XR6y`(Jr0KZaQrxa;a8ZH_zF8WVv?@yV=xff0);(>;Q%# NgQu&X%Q~loCIAn3txf;{ literal 0 HcmV?d00001 diff --git a/mods/ITEMS/mcl_chests/init.lua b/mods/ITEMS/mcl_chests/init.lua index ad5c781f7..aba91fe87 100644 --- a/mods/ITEMS/mcl_chests/init.lua +++ b/mods/ITEMS/mcl_chests/init.lua @@ -291,22 +291,7 @@ local function register_chest(basename, desc, longdesc, usagehelp, tt_help, tile end end - local function drop_items_chest(pos, oldnode, oldmetadata) - local meta = minetest.get_meta(pos) - local meta2 = meta:to_table() - if oldmetadata then - meta:from_table(oldmetadata) - end - local inv = meta:get_inventory() - for i=1,inv:get_size("main") do - local stack = inv:get_stack("main", i) - if not stack:is_empty() then - local p = {x=pos.x+math.random(0, 10)/10-0.5, y=pos.y, z=pos.z+math.random(0, 10)/10-0.5} - minetest.add_item(p, stack) - end - end - meta:from_table(meta2) - end + local drop_items_chest = mcl_util.drop_items_container_get("main") local function on_chest_blast(pos) local node = minetest.get_node(pos) diff --git a/mods/ITEMS/mcl_core/nodes_trees.lua b/mods/ITEMS/mcl_core/nodes_trees.lua index a5ef7aa97..36ef28dc1 100644 --- a/mods/ITEMS/mcl_core/nodes_trees.lua +++ b/mods/ITEMS/mcl_core/nodes_trees.lua @@ -16,7 +16,6 @@ local function register_tree_trunk(subname, description_trunk, description_bark, _doc_items_hidden = false, tiles = {tile_inner, tile_inner, tile_bark}, paramtype2 = "facedir", - on_place = mcl_util.rotate_axis, stack_max = 64, groups = {handy=1,axey=1, tree=1, flammable=2, building_block=1, material_wood=1, fire_encouragement=5, fire_flammability=5}, sounds = mcl_sounds.node_sound_wood_defaults(),