diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..65c5ca8 --- /dev/null +++ b/LICENSE @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/README.md b/README.md index 8679cf5..8f25636 100644 --- a/README.md +++ b/README.md @@ -1 +1,38 @@ -bau_coop +# Bau_Coop v1.0.0 + +[![Baixar](https://img.shields.io/badge/Baixar-v1.0.0-green.svg)](https://github.com/BrunoMine/bau_coop/archive/v1.0.0.zip) +[![Projeto](https://img.shields.io/badge/Git-Projeto-green.svg)](https://github.com/BrunoMine/bau_coop) +[![!Bower](https://img.shields.io/badge/Bower-Projeto-green.svg)](https://minetest-bower.herokuapp.com/mods/bau_coop) +[![Licença](https://img.shields.io/badge/Licença-LGPL_v3.0-blue.svg)](https://github.com/BrunoMine/bau_coop/blob/master/LICENSE) + +## Descrição +Adiciona um bau cooperativo configuravel + +## Requisitos + +* Minetest 0.4.16 ou superior +* Mod default + +## Recursos do projeto + +* [Baixar](https://github.com/BrunoMine/bau_coop/archive/v1.0.0.zip) +* [Projeto](https://github.com/BrunoMine/bau_coop) +* [Bower](https://minetest-bower.herokuapp.com/mods/bau_coop) + +## Licença +Veja LICENSE.txt para informações detalhadas da licença LGPL 3.0 + +### Autores do código fonte +Originalmente por BrunoMine, Bruno Borges (LGPL 3.0) + +### Autores de mídias (texturas, modelos and sons) +Todos que não estao listados aqui: +BrunoMine, Bruno Borges (CC BY-SA 3.0) + +Mike Koenig (CC BY 3.0) + bau_coop_open.ogg (clic) + bau_coop_close.ogg (clic) + +FreqMan (CC BY 3.0) + bau_coop_open.ogg (blip) + bau_coop_blip.ogg diff --git a/depends.txt b/depends.txt new file mode 100644 index 0000000..4ad96d5 --- /dev/null +++ b/depends.txt @@ -0,0 +1 @@ +default diff --git a/description.txt b/description.txt new file mode 100644 index 0000000..b210e3a --- /dev/null +++ b/description.txt @@ -0,0 +1 @@ +Bau cooperativo diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..085d23c --- /dev/null +++ b/init.lua @@ -0,0 +1,28 @@ +--[[ + Mod Bau_Coop para Minetest + Copyright (C) 2017 BrunoMine (https://github.com/BrunoMine) + + Recebeste uma cópia da GNU Lesser General + Public License junto com esse software, + se não, veja em . + + Inicializador de scripts + ]] + +-- Tabela global +bau_coop = {} + +-- Notificador de Inicializador +local notificar = function(msg) + if minetest.setting_get("log_mods") then + minetest.debug("[Bau_Coop]"..msg) + end +end + +-- Modpath +local modpath = minetest.get_modpath("bau_coop") + +-- Carregar scripts +notificar("Carregando...") +dofile(modpath.."/nodes.lua") +notificar("[OK]!") diff --git a/nodes.lua b/nodes.lua new file mode 100644 index 0000000..323effc --- /dev/null +++ b/nodes.lua @@ -0,0 +1,416 @@ +--[[ + Mod Bau_Coop para Minetest + Copyright (C) 2017 BrunoMine (https://github.com/BrunoMine) + + Recebeste uma cópia da GNU Lesser General + Public License junto com esse software, + se não, veja em . + + Nodes + ]] + + +-- Variavel de acesso +local acessos = {} + +-- Remover nome dos acessos ao sair +minetest.register_on_leaveplayer(function(player) + if not player then return end + local name = player:get_player_name() + + local tb = {} + for n,_ in pairs(acessos) do + if n ~= name then + tb[n] = acessos[n] + end + end + acessos = tb +end) + +-- Formspec de acesso negado +local formspec_acesso_negado = "size[7,2]" + .. default.gui_bg + .. default.gui_bg_img + .. "image[0,0;2,2;bau_coop_acesso.png]" + .. "label[2,0.75;"..core.colorize("#FF0000", "Acesso Negado").."]" + + +local function pegar_formspec_bau_compartilhado(pos) + local spos = pos.x .. "," .. pos.y .. "," .. pos.z + local formspec = + "size[8,10]" .. + default.gui_bg .. + default.gui_bg_img .. + default.gui_slots .. + "list[nodemeta:" .. spos .. ";main;0,1.3;8,4;]" .. + "list[current_player;main;0,5.85;8,1;]" .. + "list[current_player;main;0,7.08;8,3;8]" .. + "listring[nodemeta:" .. spos .. ";main]" .. + "listring[current_player;main]" .. + default.get_hotbar_bg(0,5.85) .. + "label[0,0;Bau Compartilhado]" .. + "image_button[7,0;1,1;bau_coop_acesso.png;controle_acesso;]" + return formspec +end + +local function pegar_formspec_painel_acesso(name, meta, msg, erro) + local lista = "" + local donos = meta:get_string("donos") + if donos and donos ~= "" then + donos = minetest.deserialize(donos) + for _,n in ipairs(donos) do + if lista ~= "" then lista = lista .. "," end + lista = lista .. n + end + end + local formspec = "size[8,7]" + .. default.gui_bg + .. default.gui_bg_img + .. "image[0,0;2,2;bau_coop_acesso.png]" + .. "label[2,0;Bau Compartilhado]" + .. "button[6,0;2,1;voltar;Voltar]" + -- Adicionar acesso + .. "field[0.3,2.8;4.8,1;novo_acesso;Adicionar novo jogador;]" + .. "button[5,2.49;3,1;adicionar;Adicionar Acesso]" + -- Remover acesso + .. "label[0,3.7;Jogadores com acesso]" + .. "dropdown[0,4.125;5,1;nome_acesso;"..lista..";]" + .. "button[5,4;3,1;remover;Remover Acesso]" + + if msg then + if erro then + formspec = formspec .. "label[2,1;"..core.colorize("#FF0000", msg).."]" + else + formspec = formspec .. "label[2,1;"..msg.."]" + end + end + + return formspec +end + +local function verificar_acesso(meta, player) + local name = "" + if player then + if minetest.check_player_privs(player, "protection_bypass") then + return true + end + name = player:get_player_name() + end + + if meta:get_string("donos") == "" then + return true + end + + for _,n in ipairs(minetest.deserialize(meta:get_string("donos"))) do + if name == n then + return true + end + end + return false +end + +-- Receptor de botoes +minetest.register_on_player_receive_fields(function(player, formname, fields) + if formname == "bau_coop:bau_compartilhado" then + local pos = acessos[player:get_player_name()] + local meta = minetest.get_meta(pos) + + if verificar_acesso(meta, player) == false then + return minetest.show_formspec( + player:get_player_name(), + "bau_coop:bau_compartilhado", + formspec_acesso_negado + ) + end + + -- Acessar painel de controle de acesso + if fields.controle_acesso then + + return minetest.show_formspec( + player:get_player_name(), + "bau_coop:bau_compartilhado", + pegar_formspec_painel_acesso(player:get_player_name(), meta) + ) + + -- Adicionar acesso de um jogador + elseif fields.adicionar then + local donos = minetest.deserialize(meta:get_string("donos")) + + -- Verificar se um nome foi especificado + if fields.novo_acesso == "" then + return minetest.show_formspec( + player:get_player_name(), + "bau_coop:bau_compartilhado", + pegar_formspec_painel_acesso(player:get_player_name(), meta, "Nenhum nome especificado", true) + ) + end + + -- Verificar se ja esta no limite de acessos + if table.maxn(donos) >= 10 then + return minetest.show_formspec( + player:get_player_name(), + "bau_coop:bau_compartilhado", + pegar_formspec_painel_acesso(player:get_player_name(), meta, "Limite de 10 jogadores", true) + ) + end + + -- Adiciona o acesso ao jogador + table.insert(donos, fields.novo_acesso) + meta:set_string("donos", minetest.serialize(donos)) + + minetest.sound_play("bau_coop_blip", {gain = 0.3, + pos = pos, max_hear_distance = 10}) + + return minetest.show_formspec( + player:get_player_name(), + "bau_coop:bau_compartilhado", + pegar_formspec_painel_acesso(player:get_player_name(), meta, fields.novo_acesso.." agora tem acesso") + ) + + -- Remover acesso de um jogador + elseif fields.remover then + local donos = minetest.deserialize(meta:get_string("donos")) + + -- Verificar se o jogador selecionado eh ultimo dono + if table.maxn(donos) == 1 then + return minetest.show_formspec( + player:get_player_name(), + "bau_coop:bau_compartilhado", + pegar_formspec_painel_acesso(player:get_player_name(), meta, "Apenas um dono restante", true) + ) + end + + -- Remover o acesso + local tb = {} + for _,n in ipairs(donos) do + if n ~= fields.nome_acesso then + table.insert(tb, n) + end + end + donos = tb + meta:set_string("donos", minetest.serialize(donos)) + + -- Verifica se o jogador ainda tem acesso + if verificar_acesso(meta, player) == false then + return minetest.show_formspec( + player:get_player_name(), + "bau_coop:bau_compartilhado", + formspec_acesso_negado + ) + end + + minetest.sound_play("bau_coop_blip", {gain = 0.3, + pos = pos, max_hear_distance = 10}) + + return minetest.show_formspec( + player:get_player_name(), + "bau_coop:bau_compartilhado", + pegar_formspec_painel_acesso(player:get_player_name(), meta, fields.nome_acesso.." perdeu o acesso") + ) + + -- Voltar para a formspec normal do bau + elseif fields.voltar then + if verificar_acesso(meta, player) then + minetest.show_formspec( + player:get_player_name(), + "bau_coop:bau_compartilhado", + pegar_formspec_bau_compartilhado(pos) + ) + end + + -- Sair + elseif fields.quit then + local name = player:get_player_name() + local node = minetest.get_node(pos) + + -- Verifica se tem mais alguem acessando + for k, v in pairs(acessos) do + if k ~= name and pos.x == pos.x and pos.y == pos.y and pos.z == pos.z then + acessos[name] = nil -- Remover nome dos acessos + return + end + end + minetest.after(0.2, minetest.swap_node, pos, { name = "bau_coop:bau_compartilhado", + param2 = node.param2 }) + minetest.sound_play("bau_coop_close", {gain = 0.3, pos = pos, max_hear_distance = 10}) + acessos[name] = nil -- Remover nome dos acessos + end + + end +end) + +minetest.register_node("bau_coop:bau_compartilhado", { + description = "Bau Compartilhado", + tiles = { + "default_chest_top.png", + "default_chest_top.png", + "default_chest_side.png^[transformFX", + "default_chest_side.png", + "default_chest_side.png", + "default_chest_side.png^bau_coop_frente.png" + }, + paramtype2 = "facedir", + groups = {choppy = 2, oddly_breakable_by_hand = 2}, + legacy_facedir_simple = true, + is_ground_content = false, + sounds = default.node_sound_wood_defaults(), + + after_place_node = function(pos, placer) + local meta = minetest.get_meta(pos) + meta:set_string("donos", minetest.serialize({placer:get_player_name()}) or "") + meta:set_string("infotext", "Bau Compartilhado") + end, + on_construct = function(pos) + local meta = minetest.get_meta(pos) + meta:set_string("donos", "") + local inv = meta:get_inventory() + inv:set_size("main", 8 * 4) + end, + can_dig = function(pos,player) + local meta = minetest.get_meta(pos); + local inv = meta:get_inventory() + return ( inv:is_empty("main") and verificar_acesso(meta, player) ) or minetest.check_player_privs(player, "protection_bypass") + end, + allow_metadata_inventory_move = function(pos, from_list, from_index, + to_list, to_index, count, player) + local meta = minetest.get_meta(pos) + if minetest.check_player_privs(player, "protection_bypass") then return count end + if not verificar_acesso(meta, player) then + return 0 + end + return count + end, + + allow_metadata_inventory_put = function(pos, listname, index, stack, player) + local meta = minetest.get_meta(pos) + if minetest.check_player_privs(player, "protection_bypass") then return stack:get_count() end + if not verificar_acesso(meta, player) then + return 0 + end + return stack:get_count() + end, + allow_metadata_inventory_take = function(pos, listname, index, stack, player) + local meta = minetest.get_meta(pos) + if minetest.check_player_privs(player, "protection_bypass") then return stack:get_count() end + if not verificar_acesso(meta, player) then + return 0 + end + return stack:get_count() + end, + on_metadata_inventory_put = function(pos, listname, index, stack, player) + minetest.log("action", player:get_player_name() .. + " moveu " .. stack:get_name() .. + " para o bau compartilhado em " .. minetest.pos_to_string(pos)) + end, + on_metadata_inventory_take = function(pos, listname, index, stack, player) + minetest.log("action", player:get_player_name() .. + " pegou " .. stack:get_name() .. + " do bau compartilhado em " .. minetest.pos_to_string(pos)) + end, + + on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) + + local name = clicker:get_player_name() + local meta = minetest.get_meta(pos) + + if verificar_acesso(meta, clicker) then + + if minetest.get_node(pos).name == "bau_coop:bau_compartilhado" then + minetest.sound_play("bau_coop_open", {gain = 0.3, + pos = pos, max_hear_distance = 10}) + minetest.after(0.1 , minetest.swap_node, pos, + { name = "bau_coop:bau_compartilhado_aceso", + param2 = node.param2 }) + if minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z}).name == "air" then + minetest.after(0.5 , minetest.swap_node, pos, + { name = "bau_coop:bau_compartilhado_open", + param2 = node.param2 }) + end + end + + acessos[clicker:get_player_name()] = {x=pos.x, y=pos.y, z=pos.z} + minetest.after(0.65, minetest.show_formspec, + clicker:get_player_name(), + "bau_coop:bau_compartilhado", + pegar_formspec_bau_compartilhado(pos) + ) + end + return itemstack + end, + on_blast = function() end, +}) + +-- Bau com telinha acessa +do + -- Copiar tabela de definições + local def = {} + for n,d in pairs(minetest.registered_nodes["bau_coop:bau_compartilhado"]) do + def[n] = d + end + -- Mantem a tabela groups separada + def.groups = minetest.deserialize(minetest.serialize(def.groups)) + def.drop = "bau_coop:bau_compartilhado" + + -- Altera alguns paremetros + def.tiles = { + "default_chest_top.png", + "default_chest_top.png", + "default_chest_side.png^[transformFX", + "default_chest_side.png", + "default_chest_side.png", + "default_chest_side.png^bau_coop_frente_acesa.png" + } + + -- Registra o novo node + minetest.register_node("bau_coop:bau_compartilhado_aceso", def) +end + +-- Bau aberto +do + -- Copiar tabela de definições + local def = {} + for n,d in pairs(minetest.registered_nodes["bau_coop:bau_compartilhado"]) do + def[n] = d + end + -- Mantem a tabela groups separada + def.groups = minetest.deserialize(minetest.serialize(def.groups)) + + -- Altera alguns paremetros + def.tiles = { + "default_chest_top.png", + "default_chest_top.png", + "default_chest_side.png", + "default_chest_side.png", + "default_chest_side.png^bau_coop_frente_acesa.png", + "default_chest_inside.png" + } + def.drawtype = "mesh" + def.visual = "mesh" + def.paramtype = "light" + def.paramtype2 = "facedir" + def.legacy_facedir_simple = true + def.is_ground_content = false + def.groups.not_in_creative_inventory = 1 + def.mesh = "chest_open.obj" + def.drop = "bau_coop:bau_compartilhado" + def.selection_box = { + type = "fixed", + fixed = { -1/2, -1/2, -1/2, 1/2, 3/16, 1/2 }, + } + def.can_dig = function() + return false + end + + -- Registra o novo node + minetest.register_node("bau_coop:bau_compartilhado_open", def) +end + + + +minetest.register_craft({ + output = 'bau_coop:bau_compartilhado', + recipe = { + {'default:chest_locked', 'default:steel_ingot'}, + {'default:steel_ingot', 'default:glass'} + } +}) diff --git a/screenshot.png b/screenshot.png new file mode 100644 index 0000000..e89ce1e Binary files /dev/null and b/screenshot.png differ diff --git a/sounds/bau_coop_blip.ogg b/sounds/bau_coop_blip.ogg new file mode 100644 index 0000000..a57450e Binary files /dev/null and b/sounds/bau_coop_blip.ogg differ diff --git a/sounds/bau_coop_close.ogg b/sounds/bau_coop_close.ogg new file mode 100644 index 0000000..eb9e388 Binary files /dev/null and b/sounds/bau_coop_close.ogg differ diff --git a/sounds/bau_coop_open.ogg b/sounds/bau_coop_open.ogg new file mode 100644 index 0000000..a3567b2 Binary files /dev/null and b/sounds/bau_coop_open.ogg differ diff --git a/textures/bau_coop_acesso.png b/textures/bau_coop_acesso.png new file mode 100644 index 0000000..3ec79c7 Binary files /dev/null and b/textures/bau_coop_acesso.png differ diff --git a/textures/bau_coop_frente.png b/textures/bau_coop_frente.png new file mode 100644 index 0000000..fea7802 Binary files /dev/null and b/textures/bau_coop_frente.png differ diff --git a/textures/bau_coop_frente_acesa.png b/textures/bau_coop_frente_acesa.png new file mode 100644 index 0000000..19a7434 Binary files /dev/null and b/textures/bau_coop_frente_acesa.png differ