Initial commit
commit
3015d28404
|
@ -0,0 +1,20 @@
|
|||
Copyright (c) 2015 BlockMen <blockmen2015@gmail.com>
|
||||
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty. In no
|
||||
event will the authors be held liable for any damages arising from the use of
|
||||
this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose, including
|
||||
commercial applications, and to alter it and redistribute it freely, subject to the
|
||||
following restrictions:
|
||||
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software in a
|
||||
product, an acknowledgment in the product documentation is required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must not
|
||||
be misrepresented as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source distribution.
|
|
@ -0,0 +1,38 @@
|
|||
Mod "Nametag" [nametag]
|
||||
=======================
|
||||
Copyright (c) 2015 BlockMen <blockmen2015@gmail.com>
|
||||
|
||||
Version: 1.0 alpha
|
||||
|
||||
|
||||
A simple mod that allows to give nearly every object a name, only Players can't be renamed.
|
||||
|
||||
You can craft a nametag with paper and coal. To rename an object rightlick it with the nametag,
|
||||
then you can type the wanted name.
|
||||
|
||||
NOTE: This mod requires a current development build of Minetest from 16th December 2015 or newer. Also useable with blockplanet.
|
||||
|
||||
|
||||
License:
|
||||
~~~~~~~~
|
||||
Code:
|
||||
(c) Copyright 2015 BlockMen; modified zlib-License
|
||||
see "LICENSE.txt" for details.
|
||||
|
||||
Media(if not stated differently):
|
||||
(c) Copyright (2015) BlockMen; CC-BY-SA 3.0
|
||||
|
||||
|
||||
Github:
|
||||
~~~~~~~
|
||||
https://github.com/BlockMen/nametag
|
||||
|
||||
|
||||
Forum:
|
||||
~~~~~~
|
||||
-
|
||||
|
||||
|
||||
Changelog:
|
||||
~~~~~~~~~~
|
||||
-
|
|
@ -0,0 +1 @@
|
|||
default
|
|
@ -0,0 +1,147 @@
|
|||
-- "Nametag" [nametag]
|
||||
-- Copyright (c) 2015 BlockMen <blockmen2015@gmail.com>
|
||||
--
|
||||
-- init.lua
|
||||
--
|
||||
-- This software is provided 'as-is', without any express or implied warranty. In no
|
||||
-- event will the authors be held liable for any damages arising from the use of
|
||||
-- this software.
|
||||
--
|
||||
-- Permission is granted to anyone to use this software for any purpose, including
|
||||
-- commercial applications, and to alter it and redistribute it freely, subject to the
|
||||
-- following restrictions:
|
||||
--
|
||||
-- 1. The origin of this software must not be misrepresented; you must not
|
||||
-- claim that you wrote the original software. If you use this software in a
|
||||
-- product, an acknowledgment in the product documentation is required.
|
||||
-- 2. Altered source versions must be plainly marked as such, and must not
|
||||
-- be misrepresented as being the original software.
|
||||
-- 3. This notice may not be removed or altered from any source distribution.
|
||||
--
|
||||
|
||||
|
||||
local current_obj = {}
|
||||
local current_stack = {}
|
||||
|
||||
local function set_nametag(self, clicker)
|
||||
if self and self.object and clicker then
|
||||
if self.object:is_player() then
|
||||
core.chat_send_player(clicker:get_player_name(), "You can't rename players, sorry.")
|
||||
return false
|
||||
end
|
||||
local item = clicker:get_wielded_item()
|
||||
if item then
|
||||
local name = item:get_name()
|
||||
if name == "nametag:tag" then
|
||||
local player_name = clicker:get_player_name()
|
||||
current_obj[player_name] = self
|
||||
current_stack[player_name] = item
|
||||
--show formspec
|
||||
local formspec = "size[8,8]" .. default.gui_bg ..
|
||||
"field[0.5,1;7.5,0;name;Name:;]" ..
|
||||
"button_exit[2.5,7.5;3,1;save_name;Save name]"
|
||||
|
||||
core.show_formspec(player_name, "nametag_name_obj", formspec)
|
||||
return true
|
||||
end
|
||||
end
|
||||
else
|
||||
if clicker then
|
||||
core.chat_send_player(clicker:get_player_name(), "You can't name this object, sorry.")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function getentities()
|
||||
for a,b in pairs(core.registered_entities) do
|
||||
local org = table.copy(b)
|
||||
|
||||
b.on_activate = function(self, staticdata, dtime_s)
|
||||
local new_stats
|
||||
if staticdata then
|
||||
new_stats = core.deserialize(staticdata)
|
||||
end
|
||||
|
||||
if new_stats and new_stats.flag then
|
||||
if new_stats.nametag then
|
||||
self.nametag = new_stats.nametag
|
||||
end
|
||||
end
|
||||
|
||||
if self.object and self.nametag and self.nametag ~= "" then
|
||||
self.object:set_properties({nametag = self.nametag, nametag_color = "#FFFF00"})
|
||||
end
|
||||
|
||||
if org.on_activate then
|
||||
return org.on_activate(self, (new_stats and new_stats.org) or "", dtime_s)
|
||||
end
|
||||
end
|
||||
|
||||
b.on_rightclick = function(self, clicker)
|
||||
local retval = set_nametag(self, clicker)
|
||||
if retval then
|
||||
return
|
||||
end
|
||||
|
||||
if org.on_rightclick then
|
||||
org.on_rightclick(self, clicker)
|
||||
end
|
||||
end
|
||||
|
||||
b.get_staticdata = function(self)
|
||||
local retval
|
||||
local tab = {}
|
||||
if org.get_staticdata then
|
||||
retval = org.get_staticdata(self)
|
||||
end
|
||||
|
||||
if retval then
|
||||
tab.org = retval
|
||||
else
|
||||
tab.org = {}
|
||||
end
|
||||
|
||||
-- insert own data
|
||||
tab.nametag = self.nametag
|
||||
tab.flag = "yes"
|
||||
|
||||
return core.serialize(tab)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
core.register_craftitem("nametag:tag", {
|
||||
description = "Nametag",
|
||||
inventory_image = "nametag_tag.png",
|
||||
liquids_pointable = false
|
||||
})
|
||||
|
||||
core.register_craft({
|
||||
type = "shapeless",
|
||||
output = "nametag:tag",
|
||||
recipe = {"default:paper", "default:coal_lump"},
|
||||
})
|
||||
|
||||
|
||||
core.register_on_player_receive_fields(function(player, form_name, fields)
|
||||
if form_name ~= "nametag_name_obj" or not fields.save_name or fields.name == "" then
|
||||
return
|
||||
end
|
||||
|
||||
local name = player:get_player_name()
|
||||
local obj = current_obj[name]
|
||||
if obj and obj.object then
|
||||
obj.object:set_properties({nametag = fields.name, nametag_color = "#FFFF00"})
|
||||
obj.nametag = fields.name
|
||||
current_obj[name] = nil
|
||||
if not core.setting_getbool("creative_mode") then
|
||||
local itemstack = current_stack[name]
|
||||
itemstack:take_item()
|
||||
player:set_wielded_item(itemstack)
|
||||
end
|
||||
current_stack[name] = nil
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
core.after(0.1, getentities)
|
Binary file not shown.
After Width: | Height: | Size: 510 B |
Loading…
Reference in New Issue