Add new mod: rp_label
This commit is contained in:
parent
a12e7b70f1
commit
31662dc440
@ -51,7 +51,7 @@ local function get_bookshelf_formspec(pos)
|
||||
form = form .. rp_formspec.image_button(xstart+xoff, ystart + 1.15, 1, 1, "open_"..i, "ui_icon_view.png", S("Read book"))
|
||||
end
|
||||
end
|
||||
form = form .. default.container_label_formspec_element(meta)
|
||||
form = form .. rp_label.container_label_formspec_element(meta)
|
||||
return form
|
||||
end
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
name = rp_book
|
||||
description = Writable books, bookshelf
|
||||
depends = rp_crafting, rp_default, rp_formspec, rp_paint
|
||||
depends = rp_crafting, rp_default, rp_formspec, rp_paint, rp_label
|
||||
optional_depends = rp_itemdef_defaults
|
||||
|
@ -1,10 +1,5 @@
|
||||
-- Functions/ABMs
|
||||
|
||||
### `default.write_name(pos, text)`
|
||||
|
||||
This function is currently unused.
|
||||
|
||||
|
||||
### `default.is_sapling_growing(pos)`
|
||||
|
||||
Returns true if node at pos is a sapling and
|
||||
@ -24,19 +19,6 @@ Returns true if the given biome is considered to be
|
||||
a 'dry' biome (e.g. for dry grass). Custom or unknown
|
||||
biomes are never dry.
|
||||
|
||||
### `default.container_label_formspec_element(meta)`
|
||||
Returns a formspec string for a given node metadata
|
||||
that adds a white 'label' formspec element on top of the
|
||||
formspec showing the current label of the node (added
|
||||
with the "label and graphite") item. The node label
|
||||
is defined in the metadata string `"name"`.
|
||||
|
||||
Useful for all container nodes that can be labelled
|
||||
that way.
|
||||
|
||||
If the label is empty, an empty formspec string will
|
||||
be returned.
|
||||
|
||||
## Functions for builtin biomes
|
||||
|
||||
This mod adds all the core biomes for this game. There are some helper functions
|
||||
|
@ -23,7 +23,7 @@ end
|
||||
|
||||
local get_chest_formspec = function(meta)
|
||||
local form = rp_formspec.get_page("rp_default:chest")
|
||||
form = form .. default.container_label_formspec_element(meta)
|
||||
form = form .. rp_label.container_label_formspec_element(meta)
|
||||
return form
|
||||
end
|
||||
local get_chest_infotext = function(meta)
|
||||
|
@ -425,17 +425,6 @@ crafting.register_craft(
|
||||
}
|
||||
})
|
||||
|
||||
-- Label
|
||||
|
||||
crafting.register_craft(
|
||||
{
|
||||
output = "rp_default:label 20",
|
||||
items = {
|
||||
"rp_default:sheet_graphite",
|
||||
"rp_default:paper",
|
||||
}
|
||||
})
|
||||
|
||||
-- Minerals
|
||||
|
||||
crafting.register_craft(
|
||||
|
@ -75,7 +75,6 @@ dofile(minetest.get_modpath("rp_default").."/ingot.lua")
|
||||
dofile(minetest.get_modpath("rp_default").."/bucket.lua")
|
||||
dofile(minetest.get_modpath("rp_default").."/tools.lua")
|
||||
dofile(minetest.get_modpath("rp_default").."/fertilizer.lua")
|
||||
dofile(minetest.get_modpath("rp_default").."/label.lua")
|
||||
|
||||
dofile(minetest.get_modpath("rp_default").."/crafting.lua")
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
name = rp_default
|
||||
depends = rp_sounds, rp_util, rp_formspec, rp_crafting, rp_item_drop, rp_paint, rp_textures
|
||||
depends = rp_sounds, rp_util, rp_formspec, rp_crafting, rp_item_drop, rp_paint, rp_label, rp_textures
|
||||
optional_depends = rp_achievements, rp_checkitem, rp_weather, rp_itemdef_defaults
|
||||
description = Main Repixture content mod. Contains most of the basic building blocks and items, including tools, weapons, fertilizer, buckets, chest, furnace, torches, ladders and fences. Also contains the core map generator.
|
||||
|
21
mods/rp_label/API.md
Normal file
21
mods/rp_label/API.md
Normal file
@ -0,0 +1,21 @@
|
||||
## Functions
|
||||
|
||||
### `rp_label.write_name(pos, text)`
|
||||
|
||||
Sets the name/label text of the node at `pos` to `text`.
|
||||
Only has an effect if the node supports labels.
|
||||
|
||||
### `rp_label.container_label_formspec_element(meta)`
|
||||
|
||||
Returns a formspec string for a given node metadata
|
||||
that adds a white 'label' formspec element on top of the
|
||||
formspec showing the current label of the node (added
|
||||
with the "label and graphite") item. The node label
|
||||
is defined in the metadata string `"name"`.
|
||||
|
||||
Useful for all container nodes that can be labelled
|
||||
that way.
|
||||
|
||||
If the label is empty, an empty formspec string will
|
||||
be returned.
|
||||
|
@ -1,6 +1,8 @@
|
||||
-- Label
|
||||
|
||||
local S = minetest.get_translator("rp_default")
|
||||
local S = minetest.get_translator("rp_label")
|
||||
|
||||
rp_label = {}
|
||||
|
||||
-- Maximum length of the name of a named node (e.g. with label)
|
||||
local NAMED_NODE_MAX_TEXT_LENGTH = 40
|
||||
@ -11,11 +13,11 @@ form_label = form_label .. "size[8.5,4.5]"
|
||||
form_label = form_label .. rp_formspec.default.boilerplate
|
||||
form_label = form_label .. "background[0,0;8.5,4.5;ui_formspec_bg_short.png]"
|
||||
form_label = form_label .. rp_formspec.button_exit(2.75, 3, 3, 1, "", minetest.formspec_escape(S("Write")), false)
|
||||
rp_formspec.register_page("rp_default:label", form_label)
|
||||
rp_formspec.register_page("rp_label:label", form_label)
|
||||
|
||||
local active_posses = {}
|
||||
|
||||
default.container_label_formspec_element = function(meta)
|
||||
rp_label.container_label_formspec_element = function(meta)
|
||||
local name = meta:get_string("name")
|
||||
local form = ""
|
||||
if name ~= "" then
|
||||
@ -27,7 +29,7 @@ default.container_label_formspec_element = function(meta)
|
||||
end
|
||||
|
||||
-- Assign a name to a node
|
||||
default.write_name = function(pos, text)
|
||||
rp_label.write_name = function(pos, text)
|
||||
-- Discard everything after the first newline or carriage return
|
||||
local tsplit = string.split(text, "\n", nil, 1)
|
||||
if #tsplit >= 1 then
|
||||
@ -71,11 +73,11 @@ local write = function(itemstack, player, pointed_thing)
|
||||
local meta = minetest.get_meta(pointed_thing.under)
|
||||
local text = meta:get_string("name")
|
||||
|
||||
local form = rp_formspec.get_page("rp_default:label")
|
||||
local form = rp_formspec.get_page("rp_label:label")
|
||||
form = form .. "field[1,1.5;6.5,0.5;text;;"..minetest.formspec_escape(text).."]"
|
||||
form = form .. "set_focus[text;true]"
|
||||
|
||||
minetest.show_formspec(player:get_player_name(), "rp_default:label", form)
|
||||
minetest.show_formspec(player:get_player_name(), "rp_label:label", form)
|
||||
end
|
||||
|
||||
if not minetest.is_creative_enabled(player:get_player_name()) then
|
||||
@ -85,23 +87,23 @@ local write = function(itemstack, player, pointed_thing)
|
||||
end
|
||||
|
||||
minetest.register_craftitem(
|
||||
"rp_default:label",
|
||||
"rp_label:label",
|
||||
{
|
||||
description = S("Label and Graphite"),
|
||||
_tt_help = S("Give a name to containers"),
|
||||
inventory_image = "rp_default_label.png",
|
||||
wield_image = "rp_default_label.png",
|
||||
inventory_image = "rp_label_label.png",
|
||||
wield_image = "rp_label_label.png",
|
||||
on_use = write,
|
||||
})
|
||||
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if formname ~= "rp_default:label" then
|
||||
if formname ~= "rp_label:label" then
|
||||
return
|
||||
end
|
||||
if fields.text then
|
||||
local pos = active_posses[player:get_player_name()]
|
||||
if pos then
|
||||
default.write_name(pos, fields.text)
|
||||
rp_label.write_name(pos, fields.text)
|
||||
end
|
||||
elseif fields.quit then
|
||||
active_posses[player:get_player_name()] = nil
|
||||
@ -111,3 +113,16 @@ end)
|
||||
minetest.register_on_leaveplayer(function(player)
|
||||
active_posses[player:get_player_name()] = nil
|
||||
end)
|
||||
|
||||
|
||||
-- Crafting
|
||||
if minetest.get_modpath("default") ~= nil then
|
||||
crafting.register_craft({
|
||||
output = "rp_label:label 20",
|
||||
items = {
|
||||
"rp_default:sheet_graphite",
|
||||
"rp_default:paper",
|
||||
}
|
||||
})
|
||||
end
|
||||
|
3
mods/rp_label/mod.conf
Normal file
3
mods/rp_label/mod.conf
Normal file
@ -0,0 +1,3 @@
|
||||
name = rp_label
|
||||
description = Labels to give names to containers like chests
|
||||
depends = rp_util, rp_formspec, rp_crafting
|
Before Width: | Height: | Size: 272 B After Width: | Height: | Size: 272 B |
@ -333,7 +333,7 @@ local chest_def = {
|
||||
form = form .. "listring[nodemeta:" .. np .. ";main]"
|
||||
form = form .. "listring[current_name;main]"
|
||||
|
||||
form = form .. default.container_label_formspec_element(meta)
|
||||
form = form .. rp_label.container_label_formspec_element(meta)
|
||||
|
||||
minetest.show_formspec(
|
||||
player:get_player_name(),
|
||||
|
@ -1,3 +1,3 @@
|
||||
name = rp_locks
|
||||
depends = rp_sounds, rp_util, rp_default, rp_formspec, rp_crafting, rp_achievements, rp_paint
|
||||
depends = rp_sounds, rp_util, rp_default, rp_formspec, rp_crafting, rp_achievements, rp_paint, rp_label
|
||||
optional_depends = rp_itemdef_defaults
|
||||
|
@ -823,6 +823,15 @@ rp_mobs.drag = function(self, dtime, drag, drag_axes)
|
||||
self.object:set_velocity(targetvel)
|
||||
end
|
||||
|
||||
rp_mobs.set_nametag = function(self, nametag)
|
||||
self.object:set_properties({nametag=nametag})
|
||||
end
|
||||
|
||||
rp_mobs.get_nametag = function(self)
|
||||
local props = self.object:get_properties()
|
||||
return props.nametag
|
||||
end
|
||||
|
||||
minetest.register_on_chatcommand(function(name, command, params)
|
||||
if not setting_peaceful_only then
|
||||
return
|
||||
|
@ -649,11 +649,9 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
-- Note: Don't show written sign text in log to prevent log flooding
|
||||
" wrote something to a sign at "..minetest.pos_to_string(pos))
|
||||
meta:set_string("infotext", "")
|
||||
default.write_name(pos, text)
|
||||
end)
|
||||
|
||||
local on_destruct = function(pos)
|
||||
default.write_name(pos, "")
|
||||
remove_text_entities(pos)
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user