How to…

User avatar
Sergey
Member
 
Posts: 784
Joined: Wed Jan 11, 2017 13:28
Location: Russia

How to…

by Sergey » Sat Sep 02, 2017 18:40

How to get information about node player destroyed?
How to get information about near/adjacent nodes around destroyed node?
How to put item(s) into my inventory?
How to remove item(s) from my inventory?
How to manipulate durability bar of using tool (e.g. pickaxe)?
 

User avatar
azekill_DIABLO
Member
 
Posts: 7490
Joined: Wed Oct 29, 2014 20:05
Location: OMICRON
GitHub: azekillDIABLO
In-game: azekill_DIABLO

Re: How to…

by azekill_DIABLO » Sun Sep 03, 2017 09:47

Sergey wrote:How to get information about node player destroyed?
How to get information about near/adjacent nodes around destroyed node?
How to put item(s) into my inventory?
How to remove item(s) from my inventory?
How to manipulate durability bar of using tool (e.g. pickaxe)?


check lua_api.txt
> minetest.after_dig_node
> no idea sir... after_dig_node + radius test?
> hah.
> *bis*
> Probably not possible.
 

User avatar
Sergey
Member
 
Posts: 784
Joined: Wed Jan 11, 2017 13:28
Location: Russia

Re: How to…

by Sergey » Sun Sep 03, 2017 12:02

Well, I figured out something

1) To get info about destroyed node I can use on_destruct method
Code: Select all
on_destruct = function(pos)
    local node = minetest.get_node( pos )
end

while registering new node (minetest.register_node) or overriding existing one (minetest.override_item)

2) To get info about adjacent nodes around destroyed node
Code: Select all
on_destruct = function(pos)
    ...
    local node2 = minetest.get_node( { x = pos.x + 1, y = pos.y, z = pos.z } )
    ...
    local node2 = minetest.get_node( { x = pos.x, y = pos.y, z = pos.z + 1 } )
    ...
    ... and so on
end


3) But how to work with inventory is a problem for me at the moment.

I am learning modding. So I need help.
 

User avatar
azekill_DIABLO
Member
 
Posts: 7490
Joined: Wed Oct 29, 2014 20:05
Location: OMICRON
GitHub: azekillDIABLO
In-game: azekill_DIABLO

Re: How to…

by azekill_DIABLO » Sun Sep 03, 2017 12:58

inventory is hard thing to understand. I never figured how to use it really.
 

User avatar
rubenwardy
Moderator
 
Posts: 5893
Joined: Tue Jun 12, 2012 18:11
Location: United Kingdom
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
 

User avatar
azekill_DIABLO
Member
 
Posts: 7490
Joined: Wed Oct 29, 2014 20:05
Location: OMICRON
GitHub: azekillDIABLO
In-game: azekill_DIABLO
 

User avatar
octacian
Member
 
Posts: 594
Joined: Mon Dec 21, 2015 22:18
Location: Canada
GitHub: octacian
IRC: octacian
In-game: octacian

Re: How to…

by octacian » Sun Sep 03, 2017 14:41

I know all your questions have been mostly answered, but I figured I'd go through them one-by-one here.

1. Use the on_destruct method or minetest.register_on_dignode
2. Use a function like this in combination with the above
3. See this (adding items)
4. See this (taking items)
5. Use the get_wear, set_wear, and add_wear ItemStack (this or this) methods
MicroExpansion, Working Computers, All Projects - Check out my YouTube channel! (octacian)
I'm currently inactive in the Minetest community! So if I don't respond, that's why.
 

User avatar
Sergey
Member
 
Posts: 784
Joined: Wed Jan 11, 2017 13:28
Location: Russia

Re: How to…

by Sergey » Sun Sep 03, 2017 16:43

What is "main" itemstack?
How many stacks there are?
What are their names and what are their purpose?
If I add stack of 10 cobbles to my inventory, will these cobble append to cobbles I already have in inventory? Or they will use separate cell in inventory?

Sorry, if I ask silly questions.
 

User avatar
azekill_DIABLO
Member
 
Posts: 7490
Joined: Wed Oct 29, 2014 20:05
Location: OMICRON
GitHub: azekillDIABLO
In-game: azekill_DIABLO

Re: How to…

by azekill_DIABLO » Sun Sep 03, 2017 17:06

>main is the inventory of player. For items you always refer to their containers, before calling them.
>stacks? depends on the size on the inventory!
>no idea, sorry
>depends if you tell them to go in your main inventory, everything will be fine.

don't be sorry, everyone must start somewhere.
 

hajo
Member
 
Posts: 598
Joined: Thu Oct 13, 2016 10:45
Location: DE

Re: How to…

by hajo » Sun Sep 03, 2017 18:12

Sergey wrote:What is "main" itemstack?

Player or chests have a "main" inventory.
The furnace has inventories "fuel", "src" and "dst".

For items from mods (eg. workbench or circular saw),
you need to look at their source / api-docs.
 

User avatar
Sergey
Member
 
Posts: 784
Joined: Wed Jan 11, 2017 13:28
Location: Russia

Re: How to…

by Sergey » Sun Sep 03, 2017 20:12

This is from tools.lua which is installed with the game

Code: Select all
minetest.register_tool("default:pick_diamond", {
   description = "Diamond Pickaxe",
   inventory_image = "default_tool_diamondpick.png",
   tool_capabilities = {
      full_punch_interval = 0.9,
      max_drop_level=3,
      groupcaps={
         cracky = {times={[1]=2.0, [2]=1.0, [3]=0.50}, uses=30, maxlevel=3},
      },
      damage_groups = {fleshy=5},
   },
   sound = {breaks = "default_tool_breaks"},
})


I don't understand why uses=30 if I can use diamond pickaxe 810 times to break stone.

What do all this parameters mean? Official documentation is poor!
 

User avatar
Sergey
Member
 
Posts: 784
Joined: Wed Jan 11, 2017 13:28
Location: Russia

Re: How to…

by Sergey » Sun Sep 03, 2017 20:56

How to get current player's name?

I need it to get player's inventory:
Code: Select all
local inv = minetest.get_inventory({type="player", name="foobar"})
 

User avatar
Sergey
Member
 
Posts: 784
Joined: Wed Jan 11, 2017 13:28
Location: Russia

Re: How to…

by Sergey » Mon Sep 04, 2017 15:14

OK. That's my progress.

[SOLVED] 1. How to get information about node player destroyed?
[SOLVED] 2. How to get information about near/adjacent nodes around destroyed node?
Thanks to octacian.
[SOLVED] 3. How to put item(s) into my inventory?
[SOLVED] 4. How to remove item(s) from my inventory?
Thanks to rubenwardy.
[SOLVED] 5. How to get current player's name?
It is simple. I used minetest.register_on_joinplayer method which run at the moment player start playing and give info about player joined. Then I use global variable to save that player's name.

What is unclear yet for me?
1. How to know what tool was used inside node's on_destruct method?
2. How to manipulate durability/wear bar of this tool correctly (e.g. pickaxe)?
3. How wear range 0–65535 of tools related to info in /usr/share/minetest/games/minetest/mods/default/tools.lua

For example, this is info about diamond pickaxe:
Code: Select all
minetest.register_tool("default:pick_diamond", {
   description = "Diamond Pickaxe",
   inventory_image = "default_tool_diamondpick.png",
   tool_capabilities = {
      full_punch_interval = 0.9,
      max_drop_level=3,
      groupcaps={
         cracky = {times={[1]=2.0, [2]=1.0, [3]=0.50}, uses=30, maxlevel=3},
      },
      damage_groups = {fleshy=5},
   },
   sound = {breaks = "default_tool_breaks"},
})

I don't know what all these parameters mean. I wish I know but I can't get details in official documentation. But from here (and from real experience) I know that I can use diamond pickaxe 810 times to break stone (stone pickaxe — 60 times respectively). So I don't see such info in tools.lua.
4. (from above) How I can manually increase wear state of some tool by 10 (for example) uses?
 

User avatar
Sergey
Member
 
Posts: 784
Joined: Wed Jan 11, 2017 13:28
Location: Russia

Re: How to…

by Sergey » Mon Sep 04, 2017 20:41

Is there event like register_on_toolwearout that run when active tool completely wear out?
 

User avatar
Sergey
Member
 
Posts: 784
Joined: Wed Jan 11, 2017 13:28
Location: Russia

Re: How to…

by Sergey » Mon Sep 04, 2017 21:12

I will continue posting my questions in more suitable topic — Post your modding questions here

I had to start asking questions there — more chances to get answers.
 


Return to Modding Discussion



Who is online

Users browsing this forum: No registered users and 2 guests