From a635cc2c90ca71b3b8da617b18ae03bab10cbeff Mon Sep 17 00:00:00 2001 From: Zughy <4279489-marco_a@users.noreply.gitlab.com> Date: Sun, 5 Jul 2020 23:26:25 +0000 Subject: [PATCH] Several small changes --- _en/index.md | 2 +- _en/items/creating_textures.md | 2 +- _en/items/inventories.md | 28 +++++++++++++++++----------- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/_en/index.md b/_en/index.md index d5ea154..ce9555c 100644 --- a/_en/index.md +++ b/_en/index.md @@ -28,7 +28,7 @@ you can also [download it in HTML form](https://gitlab.com/rubenwardy/minetest_m Noticed a mistake, or want to give feedback? Make sure to tell me about it. -* Create a [GitHub Issue](https://gitlab.com/rubenwardy/minetest_modding_book/-/issues). +* Create a [GitLab Issue](https://gitlab.com/rubenwardy/minetest_modding_book/-/issues). * Post in the [Forum Topic](https://forum.minetest.net/viewtopic.php?f=14&t=10729). * [Contact me](https://rubenwardy.com/contact/). * Fancy contributing? diff --git a/_en/items/creating_textures.md b/_en/items/creating_textures.md index 8f4b66f..dd5cc95 100644 --- a/_en/items/creating_textures.md +++ b/_en/items/creating_textures.md @@ -3,7 +3,7 @@ title: Creating Textures layout: default root: ../.. idx: 2.2 -description: An introduction to making textures in your editor of choice, an a guide on GIMP. +description: An introduction to making textures in your editor of choice, and a guide on GIMP. redirect_from: /en/chapters/creating_textures.html --- diff --git a/_en/items/inventories.md b/_en/items/inventories.md index 31d35ba..44e7727 100644 --- a/_en/items/inventories.md +++ b/_en/items/inventories.md @@ -42,7 +42,7 @@ and Nodes only have at most one inventory in them. ## ItemStacks -ItemStacks have three components to them. +ItemStacks have four components to them: name, count, wear and metadata. The item name may be the item name of a registered item, an alias, or an unknown item name. @@ -129,21 +129,21 @@ local inv = player:get_inventory() A detached inventory is one which is independent of players or nodes. Detached inventories also don't save over a restart. -Detached inventories need to be created before they can be used - -this will be covered later. ```lua local inv = minetest.get_inventory({ type="detached", name="inventory_name" }) ``` -Unlike the other types of inventory, you must first create a detached inventory: +Unlike the other types of inventory, you must first create a detached inventory +before accessing it: ```lua minetest.create_detached_inventory("inventory_name") ``` -The create_detached_inventory function accepts 3 arguments, only first is required. +The create_detached_inventory function accepts 3 arguments, where only the first - the inventory name - +is required. The second argument takes a table of callbacks, which can be used to control how players interact with the inventory: @@ -165,16 +165,15 @@ minetest.create_detached_inventory("inventory_name", { on_put = function(inv, listname, index, stack, player) minetest.chat_send_all(player:get_player_name() .. " gave " .. stack:to_string() .. - " to the donation chest at " .. minetest.pos_to_str(pos)) + " to the donation chest from " .. minetest.pos_to_string(player:get_pos())) end, }) ``` -Permission callbacks - ie: those starting with `allow_`- return the number +Permission callbacks - ie: those starting with `allow_` - return the number of items to transfer, with -1 being used to prevent transfer completely. -Action callbacks - starting with `on_` - don't have a return value and -can't prevent transfers. +On the contrary, action callbacks - starting with `on_` - don't have a return value. ## Lists @@ -213,13 +212,20 @@ if inv:is_empty("main") then end ``` -`contains_item` can be used to see if a list contains a specific item. +`contains_item` can be used to see if a list contains a specific item: + +```lua +if inv:contains_item("main", "default:stone") then + print("I've found some stone!") +end +``` ## Modifying Inventories and ItemStacks ### Adding to a List -To add items to a list named `"main"` while respecting maximum stack sizes: +`add_item` adds items to a list (in this case `"main"`). In the example below, +the maximum stack size is also respected: ```lua local stack = ItemStack("default:stone 99")