Compare commits

...

5 Commits

Author SHA1 Message Date
Wuzzy 7cda7ea240 Add show_wielded_item 2019-03-15 07:50:46 +01:00
Wuzzy 79ef23fbd3 Make a few nodes attached 2019-03-15 07:41:43 +01:00
Wuzzy ceb9672cde Add a bit of developer documention 2019-03-14 11:30:56 +01:00
Wuzzy 56265bc513 Remove /treset if debug setting is not used 2019-03-14 11:17:34 +01:00
Wuzzy f62d3b8521 REALLY generate dirt all the way down 2019-03-14 10:49:55 +01:00
13 changed files with 211 additions and 30 deletions

40
DEVELOPERS.md Normal file
View File

@ -0,0 +1,40 @@
Here is some useful info for developers.
### How the map is saved
The map is not stored in a traditional way, like in real Minetest world. Instead, the tutorial generates the world on-the-fly when the player creates a new world.
The tutorial castle is saved in the game itself in schematics and other binary metadata files in `mods/tutorial/mapdata`. When you start a new world, Tutorial force-sets the mapgen to `singlenode`, loads the schematics and places them. After that, it generates the grassland surroundings.
## How to edit the map
### Mod security
First, you need to list `tutorial` as a trusted mod because the `/tsave` command needs write access.
You can review the relevant code in `mods/tutorial/mapgen.lua`.
### Editing the map
You want to only edit the map data files. Here's how:
In `minetest.conf`, add the following settings:
```
tutorial_debug_map_editing = true
tutorial_debug_edit_item_spawners = true
```
This enables the `/treset` and `/tsave` commands to help editing the schematic. It also forces the Tutorial to only generate the raw castle, not the grasslands. Also, the item spawners become visible.
Create a new world in Creative Mode. Now edit the map to your likings using your instant digging power and the creative inventory. You can of course WorldEdit to speed up the process.
If you're finished, use the `/tsave` command. This updates the map files in `mods/tutorial/mapdata`. Note that there are limits as for how big the tutorial castle can be.
### About item spawners
To place items in the map, you must use the item spawners, these are simple nodes that spawn items. They have 2 states: active and inactive.
Inactive basically means "unconfigured". An inactive item spawner is made when you place one from the creative inventory. Place it somewhere where you want the item. If that place would be water, place it somewhere nearby. Rightclick the node and enter the itemstring and an optional offset. The item will spawn at the node position plus the offset. Click OK to make the item spawner active. You can't edit an item spawner once its configured, just remove it and place a new one.
In the finished map, all item spawners must be configured and active.
If you mess with item spawners, the setting `tutorial_debug_edit_item_spawners` MUST be `true` before you load the map.
### Testing and finalizing
To test your new map, remove the 2 `minetest.conf` settings and create a new world and check if everything works. If it does work, you can commit your changes now.
(Note: The `/tsave` command is not available if the `tutorial` mod failed to request an "insecure" environment due to mod security issues.)

View File

@ -72,6 +72,7 @@ The mod “`castle`” falls under the MIT License (the author allowed me an exc
The mod “`arrow_signs`” falls under the CC BY-SA 3.0.
The mod “`areas`” falls under the GNU LGPLv2.1 (or later).
The mod “`cottages`” falls under the GNU GPLv2 (the author allowed me an exception).
The mod “`show_wielded_item`” is licensed under the GNU LGPLv2 or later.
The mod “`supplemental`” falls under the MIT License, with one exception:
The texture `supplemental_loudspeaker.png` falls under the CC BY-SA 3.0 (from the developers of the Mesecons mod).
Everything else falls under the MIT License.

View File

@ -33,7 +33,7 @@ minetest.register_node("cottages:sleeping_mat", {
paramtype2 = "facedir",
is_ground_content = true,
walkable = false,
groups = { creative_breakable=1 },
groups = { attached_node=1, creative_breakable=1 },
sounds = default.node_sound_leaves_defaults(),
selection_box = {
type = "wallmounted",

View File

@ -25,7 +25,7 @@ minetest.register_node("cottages:straw_mat", {
paramtype2 = "facedir",
is_ground_content = true,
walkable = false,
groups = {creative_breakable=1},
groups = {attached_node=1,creative_breakable=1},
sounds = default.node_sound_leaves_defaults(),
node_box = {
type = "fixed",

View File

@ -126,7 +126,7 @@ minetest.register_node("default:grass_5", {
description = S("grass"),
tiles = {"default_grass_5.png"},
is_ground_content = true,
groups = {creative_breakable=1},
groups = {attached_node=1,creative_breakable=1},
sounds = default.node_sound_leaves_defaults(),
wield_image = "default_grass_5.png",
inventory_image = "default_grass_5.png",

View File

@ -0,0 +1,19 @@
# Show Wielded Item [`show_wielded_item`]
This Minetest mod displays the name of the wielded item above the hotbar and
statbars.
This mod is compatible with the HUD Bars [`hudbars`] mod.
Compability with other HUD-related mods is possible, but not guaranteed.
Version: 1.0.0
## Credits
Released by Wuzzy.
The original mod code was taken from the file “`item_names.lua`”
found in the Unified Inventory mod maintained by VanessaE. This code
has been later modified.
Original author: 4aiman
## License
This mod is licensed under GNU LGPLv2 or later
(see <https://www.gnu.org/licenses/lgpl-2.1.html>).

View File

@ -0,0 +1 @@
hudbars?

View File

@ -0,0 +1 @@
Displays the name of the wielded item.

View File

@ -0,0 +1,108 @@
-- Based on 4itemnames mod by 4aiman
local wield = {}
local wieldindex = {}
local huds = {}
local dtimes = {}
local dlimit = 3 -- HUD element will be hidden after this many seconds
local hudbars_mod = minetest.get_modpath("hudbars")
local function set_hud(player)
if not player:is_player() then return end
local player_name = player:get_player_name()
-- Fixed offset in config file
local fixed = tonumber(minetest.settings:get("show_wielded_item_y_offset"))
local off
if fixed and fixed ~= -1 then
-- Manual offset
off = {x=0, y=-fixed}
else
-- Default offset
off = {x=0, y=-101}
if hudbars_mod then
-- Tweak offset if hudbars mod was found
local rows = math.floor((#hb.get_hudbar_identifiers()-1) / 2) + 1
local vmargin = tonumber(minetest.settings:get("hudbars_vmargin")) or 24
off.y = -76 - vmargin*rows
end
-- Dirty trick to avoid collision with Minetest's status text (e.g. “Volume changed to 0%”)
if off.y >= -167 and off.y <= -156 then
off.y = -181
end
end
huds[player_name] = player:hud_add({
hud_elem_type = "text",
position = {x=0.5, y=1},
offset = off,
alignment = {x=0, y=0},
number = 0xFFFFFF ,
text = "",
})
end
minetest.register_on_joinplayer(function(player)
set_hud(player)
local name = player:get_player_name()
wield[name] = player:get_wielded_item():get_name()
wieldindex[name] = player:get_wield_index()
end)
minetest.register_on_leaveplayer(function(player)
local name = player:get_player_name()
wield[name] = nil
wieldindex[name] = nil
end)
minetest.register_globalstep(function(dtime)
for _, player in pairs(minetest.get_connected_players()) do
local player_name = player:get_player_name()
local wstack = player:get_wielded_item()
local wname = wstack:get_name()
local windex = player:get_wield_index()
if dtimes[player_name] and dtimes[player_name] < dlimit then
dtimes[player_name] = dtimes[player_name] + dtime
if dtimes[player_name] > dlimit and huds[player_name] then
player:hud_change(huds[player_name], 'text', "")
end
end
-- Update HUD when wielded item or wielded index changed
if wname ~= wield[player_name] or windex ~= wieldindex[player_name] then
wieldindex[player_name] = windex
wield[player_name] = wname
dtimes[player_name] = 0
if huds[player_name] then
local def = minetest.registered_items[wname]
local meta = wstack:get_meta()
--[[ Get description. Order of preference:
* description from metadata
* description from item definition
* itemstring ]]
local desc = meta:get_string("description")
if (desc == nil or desc == "") and def then
desc = def.description
end
if desc == nil or desc == "" then
desc = wname
end
-- Cut off item description after first newline
local firstnewline = string.find(desc, "\n")
if firstnewline then
desc = string.sub(desc, 1, firstnewline-1)
end
player:hud_change(huds[player_name], 'text', desc)
end
end
end
end)

View File

@ -0,0 +1 @@
name = show_wielded_item

View File

@ -0,0 +1,5 @@
#Use this setting to manually set the vertical offset of the label which shows
#the name of the wielded item. The offset is in pixels from the bottom of the
#screen.
#Set this to -1 to let the mod guess the offset automatically (recommended).
show_wielded_item_y_offset (Vertical offset of wielded item name display) int -1 -1

View File

@ -64,7 +64,7 @@ minetest.register_node("supplemental:spikes", {
paramtype = "light",
walkable = false,
drawtype = "plantlike",
groups = { creative_breakable = 1 },
groups = { attached_node = 1, creative_breakable = 1 },
damage_per_second = 1,
collision_box = {
type = "fixed",
@ -85,7 +85,7 @@ minetest.register_node("supplemental:spikes_large", {
paramtype = "light",
walkable = false,
drawtype = "plantlike",
groups = { creative_breakable = 1 },
groups = { attached_node = 1, creative_breakable = 1 },
damage_per_second = 2
})

View File

@ -2,7 +2,10 @@
-- == DEBUG SETTINGS ==
-- If true, the generated tutorial map is in "map editing" mode, only generating
-- the raw castle, no grass layer or other random decorations will be generated
-- the raw castle, no grass layer or other random decorations will be generated.
-- Also, 2 commands to manage the schematic will be available:
-- /treset and /tsave commands will be available.
-- (/tsave only if tutorial is trusted mod)
local map_editing = minetest.settings:get_bool("tutorial_debug_map_editing")
-- == END OF DEBUG SETTINGS ==
@ -273,36 +276,38 @@ end
------ Commands
minetest.register_privilege("tutorialmap", "Can use commands to manage the tutorial map")
minetest.register_chatcommand("treset", {
params = "",
description = "Resets the tutorial map",
privs = {tutorialmap=true},
func = function(name, param)
if load_schematic() then
minetest.chat_send_player(name, "Tutorial World schematic loaded")
else
minetest.chat_send_player(name, "An error occurred while loading Tutorial World schematic")
end
-- TODO: re-load entities?
end,
})
-- Add commands for saving map and entities, but only if tutorial mod is trusted
if insecure_environment then
minetest.register_chatcommand("tsave", {
if map_editing then
minetest.register_privilege("tutorialmap", "Can use commands to manage the tutorial map")
minetest.register_chatcommand("treset", {
params = "",
description = "Saves the tutorial map",
description = "Resets the tutorial map",
privs = {tutorialmap=true},
func = function(name, param)
if save_schematic() then
minetest.chat_send_player(name, "Tutorial World schematic saved")
if load_schematic() then
minetest.chat_send_player(name, "Tutorial World schematic loaded")
else
minetest.chat_send_player(name, "An error occurred while saving Tutorial World schematic")
minetest.chat_send_player(name, "An error occurred while loading Tutorial World schematic")
end
-- TODO: re-load entities?
end,
})
-- Add commands for saving map and entities, but only if tutorial mod is trusted
if insecure_environment then
minetest.register_chatcommand("tsave", {
params = "",
description = "Saves the tutorial map",
privs = {tutorialmap=true},
func = function(name, param)
if save_schematic() then
minetest.chat_send_player(name, "Tutorial World schematic saved")
else
minetest.chat_send_player(name, "An error occurred while saving Tutorial World schematic")
end
end,
})
end
end
------ Map Generation
@ -347,7 +352,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
-- Generate a flat grass land and a dirt-only underground for the rest of the map
if map_editing ~= true then
local grasslev = 0
if minp.y <= grasslev and maxp.y >= grasslev then
if minp.y <= grasslev then
local vdata = vm:get_data(vbuffer)
local area = VoxelArea:new({MinEdge=emin, MaxEdge=emax})
for x = minp.x, maxp.x do