From: oilboi <47129783+oilboi@users.noreply.github.com> Date: Sun, 31 May 2020 08:39:01 +0000 (-0400) Subject: Add in Krock's awesome CSM Colored Names chat mod X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=1ea84788f3a810351de39c2bebcd20fa8a144d11;p=crafter_client.git Add in Krock's awesome CSM Colored Names chat mod --- diff --git a/colored_names/LICENSE b/colored_names/LICENSE new file mode 100644 index 0000000..ab60297 --- /dev/null +++ b/colored_names/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/colored_names/README.md b/colored_names/README.md new file mode 100644 index 0000000..094607b --- /dev/null +++ b/colored_names/README.md @@ -0,0 +1,18 @@ +# Colored Names + +## Description + +![Screenshot](https://raw.githubusercontent.com/SmallJoker/colored_names/master/screenshot.png) + +This client mod colorizes the nicknames in-game, so communicating gets easier, even when many people are chatting with each other. On some servers with special chat mods, this mod will stay inactive until it detects a raw/unmodified chat line. + +License: MIT + +## Installation +1. Close all Minetest processes +2. Join the Minetest directory which contains the directories `mods`, `games`, ... +3. (Create and) open the directory `clientmods` in this location +4. `git clone https://github.com/SmallJoker/colored_names.git` +5. (Create and) open the file `mods.conf` in `clientmods` +6. Add or update the line `load_mod_colored_names = true` +7. Start Minetest diff --git a/colored_names/colored_names.lua b/colored_names/colored_names.lua new file mode 100644 index 0000000..e228d3c --- /dev/null +++ b/colored_names/colored_names.lua @@ -0,0 +1,80 @@ +-- Backwards compatibility for 0.4.x +if not core.register_on_receiving_chat_message then + core.register_on_receiving_chat_message = core.register_on_receiving_chat_messages +end + +local color_reset = "\x1b(c@#FFF)" +local c_pattern = "\x1b%(c@#[0-9a-fA-F]+%)" + +core.register_on_receiving_chat_message(function(line) + local myname_l = "~[CAPS£" + if core.localplayer then + myname_l = core.localplayer:get_name():lower() + end + + -- Detect color to still do the name mentioning effect + local color, line_nc = line:match("^(" .. c_pattern .. ")(.*)") + line = line_nc or line + + local prefix + local chat_line = false + + local name, color_end, message = line:match("^%<(%S+)%>%s*(" .. c_pattern .. ")%s*(.*)") + if not message then + name, message = line:match("^%<(%S+)%> (.*)") + if name then + name = name:gsub(c_pattern, "") + end + end + + if message then + -- To keep the notation + chat_line = true + else + -- Server messages, actions + prefix, name, message = line:match("^(%*+ )(%S+) (.*)") + end + if not message then + -- Colored prefix + prefix, name, message = line:match("^(.* )%<(%S+)%> (.*)") + if color and message and prefix:len() > 0 then + prefix = color .. prefix .. color_reset + color = nil + end + chat_line = true + end + if not message then + -- Skip unknown chat line + return + end + + prefix = prefix or "" + local name_wrap = name + + -- No color yet? We need color. + if not color then + local color = core.sha1(name, true) + local R = color:byte( 1) % 0x10 + local G = color:byte(10) % 0x10 + local B = color:byte(20) % 0x10 + if R + G + B < 24 then + R = 15 - R + G = 15 - G + B = 15 - B + end + if chat_line then + name_wrap = "<" .. name .. ">" + end + name_wrap = minetest.colorize(string.format("#%X%X%X", R, G, B), name_wrap) + elseif chat_line then + name_wrap = "<" .. name .. ">" + end + + if (chat_line or prefix == "* ") and name:lower() ~= myname_l + and message:lower():find(myname_l) then + prefix = minetest.colorize("#F33", "[!] ") .. prefix + end + + return minetest.display_chat_message(prefix .. (color or "") + .. name_wrap .. (color_end or "") .. " " .. message) +end) \ No newline at end of file diff --git a/init.lua b/init.lua index cde4606..c61eb85 100644 --- a/init.lua +++ b/init.lua @@ -29,6 +29,7 @@ function initialize_all() dofile(path.."/waila.lua") dofile(path.."/music_handling.lua") dofile(path.."/version_send.lua") + dofile(path.."/colored_names/colored_names.lua") end --we must delay initialization until the player exists in the world diff --git a/version_send.lua b/version_send.lua index 8c86950..06d7e78 100644 --- a/version_send.lua +++ b/version_send.lua @@ -1,3 +1,3 @@ minetest.after(0,function() - version_channel:send_all("0.5001") + version_channel:send_all("0.5002") end) \ No newline at end of file