Post your modding questions here

ZenonSeth
Member
 
Posts: 12
Joined: Mon Sep 18, 2017 19:23

Re: Post your modding questions here

by ZenonSeth » Sun Sep 24, 2017 09:47

Krock wrote:You can do more than just show the formspec in on_rightclick. [snipped]


Ah ok, I see. I wasn't sure about using a mod-global list of names cause I wasn't sure of the access order - e.g. if I store the pos in a table, my form shows, but then another of my form's right click is process before mine, using up the pos. I think just being new to the minetest modding api, and having bad experiences with global tables like that before, made me cautious.

The approach I 'solved' it with is essentially the same, only i stored the pos in the formspec itself, using:
Code: Select all
"field[-1,-1;0,0;"..fieldNodePos..";;" .. spos .. "]"..

where spos is a comma-separated coord list. Though even if 'hidden' the field can still be edited. A solution that just occured to me is to store the pos in the field name, as in have the name be some known prefix, say fieldNodePos, concatinated with the comma-separated coords. Would probably work, just have to iterate over all fields on the formspec callback.

But I mean, if the minetest_game uses the global lookup table to store right clicked position, I should too. Thanks
 

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

Re: Post your modding questions here

by rubenwardy » Sun Sep 24, 2017 13:35

ZenonSeth wrote:
Krock wrote:You can do more than just show the formspec in on_rightclick. [snipped]


Ah ok, I see. I wasn't sure about using a mod-global list of names cause I wasn't sure of the access order - e.g. if I store the pos in a table, my form shows, but then another of my form's right click is process before mine, using up the pos. I think just being new to the minetest modding api, and having bad experiences with global tables like that before, made me cautious.

The approach I 'solved' it with is essentially the same, only i stored the pos in the formspec itself, using:
Code: Select all
"field[-1,-1;0,0;"..fieldNodePos..";;" .. spos .. "]"..

where spos is a comma-separated coord list. Though even if 'hidden' the field can still be edited. A solution that just occured to me is to store the pos in the field name, as in have the name be some known prefix, say fieldNodePos, concatinated with the comma-separated coords. Would probably work, just have to iterate over all fields on the formspec callback.

But I mean, if the minetest_game uses the global lookup table to store right clicked position, I should too. Thanks


That's hacky and a bad idea. I suggest reading about contexts

Remember that a malicious client can modify anything that you send to it, so don't give it the ability to choose a position unless you check that the position is in range in the callback, and always check for permissions in the callback too.
 

ZenonSeth
Member
 
Posts: 12
Joined: Mon Sep 18, 2017 19:23

Re: Post your modding questions here

by ZenonSeth » Sun Sep 24, 2017 13:55

rubenwardy wrote:That's hacky and a bad idea. I suggest reading about contexts

Remember that a malicious client can modify anything that you send to it, so don't give it the ability to choose a position unless you check that the position is in range in the callback, and always check for permissions in the callback too.


Cool, thanks for the link, I've already been reading that site, but I hadn't seen that section.

Yeah, I understand that sending that data over to client can be very problematic. I had already added protection to prevent mis-use, in the form of checking a unique meta data string that only my node has. So at worse it would've just failed to do anything. But either way - I've switched to using the context way, having a global key/value of playerName/Position, and it works fine :)
 

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

Re: Post your modding questions here

by rubenwardy » Sun Sep 24, 2017 14:18

Note that meta data is also usually sent to the client, so make sure you mark any such secret fields as private: https://rubenwardy.com/minetest_modding ... name1name2
 

ZenonSeth
Member
 
Posts: 12
Joined: Mon Sep 18, 2017 19:23

Re: Post your modding questions here

by ZenonSeth » Sun Sep 24, 2017 16:18

rubenwardy wrote:Note that meta data is also usually sent to the client, so make sure you mark any such secret fields as private: https://rubenwardy.com/minetest_modding ... name1name2


Hah, I *just* realised that you're the author of that site. Thanks - didn't know about private meta-data either, I'll have to play around with it.

In the meanwhile I have another issue. I'm trying to give the player items when he right-clicks on a node (they're copied, not moved from the node's internal intentory).

So I realized that on_rightclick can return an ItemStack that is the modified wielded stack. And that meant that if it got added to during the function, and I wasn't returning anything, it seemed to overwrite the stack. My code in the on_rightclick function looks like this: (or you can see my full code with context here: https://github.com/ZenonSeth/treasure_c ... t.lua#L138)

Code: Select all
-- itemStackToAdd is an ItemStack -  obtained from Node inventory (I'm not removing it from there)
itemStackToAdd = playerInv:add_item("main", itemStackToAdd);

if not itemStackToAdd:is_empty() then
    minetest.item_drop(itemStackToAdd, player, player:get_pos());
end

return playerInv:get_stack(player:get_wield_list(), player:get_wield_index());


I have some weird behavior here. All item stacks I tried this with, it works - even if you're wielding them, the stack gets incremented. But with Trees (any tree log item)... it doesn't. Meaning, if the stack of tree items is wielded, and I add to it via the code above, after it's done executing, the stack remains unchanged. Not sure why..
 

Byakuren
Member
 
Posts: 657
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri
In-game: Raymoo

Re: Post your modding questions here

by Byakuren » Sun Sep 24, 2017 19:02

BirgitLachner wrote:
Byakuren wrote:Currently nodes aren't flexible enough for what you want. You either need to register a node for every combination, or use entities to display the pictures.

Okay, no problem ... if you mean that for every kind of size 1x1, 1x2, 2x1, 2x2 and so on ... we need a special node, that's okay.

The questions are:
1.) How can we make it flexible, to have a given frame and then a choosen picture.
2.) Is it possible to replace the starting-node, where you can choose the size and picture, the the wanted size node and the wanted picture.

Birgit


I mean every combination of picture + size + frame texture.
Every time a mod API is left undocumented, a koala dies.
 

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

Re: Post your modding questions here

by hajo » Sun Sep 24, 2017 19:51

BirgitLachner wrote:make a mod to show pictures on the wall. ..
mod "gemalde" viewtopic.php?id=4635


On the server linuxworks, they have a big map
of the train-network that stretches over several nodes.

But I guess that is simply done using several textures.

So, if that is usable for your purpose depends on how many different pictures
you want to show, and how often they change.
 

User avatar
Devy
Member
 
Posts: 99
Joined: Sat Jan 21, 2017 02:31
In-game: Pyro

Re: Post your modding questions here

by Devy » Mon Sep 25, 2017 01:12

BirgitLachner wrote:
Byakuren wrote:Currently nodes aren't flexible enough for what you want. You either need to register a node for every combination, or use entities to display the pictures.

Okay, no problem ... if you mean that for every kind of size 1x1, 1x2, 2x1, 2x2 and so on ... we need a special node, that's okay.

The questions are:
1.) How can we make it flexible, to have a given frame and then a choosen picture.
2.) Is it possible to replace the starting-node, where you can choose the size and picture, the the wanted size node and the wanted picture.

Birgit


1. You could make the frame and the pictures entities and have items for placing the entities. So, when you right click with the item, you can check if the thing you are clicking on is a frame, and if it is a frame then you can make the picture a child of the picture frame.

2. I'm not sure what you are asking here.
 

User avatar
BirgitLachner
Member
 
Posts: 294
Joined: Thu May 05, 2016 10:18
In-game: Bibs

Re: Post your modding questions here

by BirgitLachner » Mon Sep 25, 2017 11:00

Byakuren wrote:
BirgitLachner wrote:
Byakuren wrote:Currently nodes aren't flexible enough for what you want. You either need to register a node for every combination, or use entities to display the pictures.

Okay, no problem ... if you mean that for every kind of size 1x1, 1x2, 2x1, 2x2 and so on ... we need a special node, that's okay.

The questions are:
1.) How can we make it flexible, to have a given frame and then a choosen picture.
2.) Is it possible to replace the starting-node, where you can choose the size and picture, the the wanted size node and the wanted picture.

Birgit


I mean every combination of picture + size + frame texture.


Hmmm, easy but not comfortable. Okay.
 

User avatar
BirgitLachner
Member
 
Posts: 294
Joined: Thu May 05, 2016 10:18
In-game: Bibs

Re: Post your modding questions here

by BirgitLachner » Tue Sep 26, 2017 05:51

hajo wrote:
BirgitLachner wrote:make a mod to show pictures on the wall. ..
mod "gemalde" viewtopic.php?id=4635


On the server linuxworks, they have a big map
of the train-network that stretches over several nodes.

But I guess that is simply done using several textures.

So, if that is usable for your purpose depends on how many different pictures
you want to show, and how often they change.

Thanks for this hint. I'll serach for the mod that does it. I think that I have already heard about it.

Birgit
 

User avatar
Stix
Member
 
Posts: 431
Joined: Fri Aug 04, 2017 14:19
Location: USA
In-game: Stix

Re: Post your modding questions here

by Stix » Tue Sep 26, 2017 20:01

Question: why is there a player.png in the default textures folder? why is it there if Minetest_Game now uses 3d characters, instead of 2d ones? is there a way to enable its use in Minetest_Game?
Need to know something? "Google it" --GreenDimond
Why do so many people believe in "God"?
Want to know whats gonna be in the next release of your favorite game? "Bugfixes" --Wuzzy
The new Minetest-offtopic can be found here: https://minetestoftopic.createaforum.com/index.php
 

User avatar
Krock
Developer
 
Posts: 3763
Joined: Thu Oct 03, 2013 07:48
Location: Switzerland
GitHub: SmallJoker

Re: Post your modding questions here

by Krock » Tue Sep 26, 2017 20:34

Stix wrote:is there a way to enable its use in Minetest_Game?

It's still used as a fallback texture when the defined model failed to load. Some skin mods also make use of this behaviour to let players use (ancient) 2D player textures.
Trigger for the 2D-mode with custom textures:
Code: Select all
-- New, in-development minetest_game version
player_api.set_model(player)
player_api.set_textures(player, {"player.png", "player_back.png"})
-- 0.4.16 compatibility
default.player_set_model(player)
player:set_properties({
   textures = {"player.png", "player_back.png"}
})

EDIT: Forgot "player" param for set_textures.
Last edited by Krock on Wed Sep 27, 2017 08:13, edited 1 time in total.
Mod Search Engine - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>
 

User avatar
Stix
Member
 
Posts: 431
Joined: Fri Aug 04, 2017 14:19
Location: USA
In-game: Stix

Re: Post your modding questions here

by Stix » Tue Sep 26, 2017 20:42

Krock wrote:
Stix wrote:is there a way to enable its use in Minetest_Game?

It's still used as a fallback texture when the defined model failed to load. Some skin mods also make use of this behaviour to let players use (ancient) 2D player textures.
Trigger for the 2D-mode with custom textures:
Code: Select all
-- New, in-development minetest_game version
player_api.set_model(player)
player_api.set_textures({"player.png", "player_back.png"})
-- 0.4.16 compatibility
default.player_set_model(player)
player:set_properties({
   textures = {"player.png", "player_back.png"}
})

where do i put this code?
Need to know something? "Google it" --GreenDimond
Why do so many people believe in "God"?
Want to know whats gonna be in the next release of your favorite game? "Bugfixes" --Wuzzy
The new Minetest-offtopic can be found here: https://minetestoftopic.createaforum.com/index.php
 

User avatar
Krock
Developer
 
Posts: 3763
Joined: Thu Oct 03, 2013 07:48
Location: Switzerland
GitHub: SmallJoker

Re: Post your modding questions here

by Krock » Wed Sep 27, 2017 08:31

Stix wrote:where do i put this code?

Meh, just download the mod below to get the 2D player back. I couldn't figure out how to correct the Y position of the sprite for the in-development versions. However, it should display fine with the 0.4.16 stable.
Attachments
2d_player.zip
License: CC0
(571 Bytes) Downloaded 6 times
Mod Search Engine - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>
 

User avatar
Stix
Member
 
Posts: 431
Joined: Fri Aug 04, 2017 14:19
Location: USA
In-game: Stix

Re: Post your modding questions here

by Stix » Wed Sep 27, 2017 16:41

Krock wrote:
Stix wrote:where do i put this code?

Meh, just download the mod below to get the 2D player back. I couldn't figure out how to correct the Y position of the sprite for the in-development versions. However, it should display fine with the 0.4.16 stable.

thx!
Need to know something? "Google it" --GreenDimond
Why do so many people believe in "God"?
Want to know whats gonna be in the next release of your favorite game? "Bugfixes" --Wuzzy
The new Minetest-offtopic can be found here: https://minetestoftopic.createaforum.com/index.php
 

User avatar
Stix
Member
 
Posts: 431
Joined: Fri Aug 04, 2017 14:19
Location: USA
In-game: Stix

Re: Post your modding questions here

by Stix » Wed Sep 27, 2017 16:44

i tried it and the 2d_avatar looked a little squashed.....
Need to know something? "Google it" --GreenDimond
Why do so many people believe in "God"?
Want to know whats gonna be in the next release of your favorite game? "Bugfixes" --Wuzzy
The new Minetest-offtopic can be found here: https://minetestoftopic.createaforum.com/index.php
 

User avatar
Stix
Member
 
Posts: 431
Joined: Fri Aug 04, 2017 14:19
Location: USA
In-game: Stix

Re: Post your modding questions here

by Stix » Wed Sep 27, 2017 17:57

im trying to get it where i use an abm and if a certain neighbore node is near the node that runs the abm will be replaced by a different node, how do i do this???
Need to know something? "Google it" --GreenDimond
Why do so many people believe in "God"?
Want to know whats gonna be in the next release of your favorite game? "Bugfixes" --Wuzzy
The new Minetest-offtopic can be found here: https://minetestoftopic.createaforum.com/index.php
 

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

Re: Post your modding questions here

by hajo » Wed Sep 27, 2017 23:11

Stix wrote:abm .. node replace by a different node

you mean like dirt --> dirt-with-grass ?
 

User avatar
Stix
Member
 
Posts: 431
Joined: Fri Aug 04, 2017 14:19
Location: USA
In-game: Stix

Re: Post your modding questions here

by Stix » Thu Sep 28, 2017 00:05

hajo wrote:
Stix wrote:abm .. node replace by a different node

you mean like dirt --> dirt-with-grass ?

yes.
Need to know something? "Google it" --GreenDimond
Why do so many people believe in "God"?
Want to know whats gonna be in the next release of your favorite game? "Bugfixes" --Wuzzy
The new Minetest-offtopic can be found here: https://minetestoftopic.createaforum.com/index.php
 

User avatar
BirgitLachner
Member
 
Posts: 294
Joined: Thu May 05, 2016 10:18
In-game: Bibs

Re: Post your modding questions here

by BirgitLachner » Thu Sep 28, 2017 05:46

Devy wrote:
BirgitLachner wrote:
Byakuren wrote:Currently nodes aren't flexible enough for what you want. You either need to register a node for every combination, or use entities to display the pictures.

Okay, no problem ... if you mean that for every kind of size 1x1, 1x2, 2x1, 2x2 and so on ... we need a special node, that's okay.

The questions are:
1.) How can we make it flexible, to have a given frame and then a choosen picture.
2.) Is it possible to replace the starting-node, where you can choose the size and picture, the the wanted size node and the wanted picture.

Birgit


1. You could make the frame and the pictures entities and have items for placing the entities. So, when you right click with the item, you can check if the thing you are clicking on is a frame, and if it is a frame then you can make the picture a child of the picture frame.

2. I'm not sure what you are asking here.


Okay, I did not use entities before. But I'll have a look at it. Thanks.
 

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

Re: Post your modding questions here

by hajo » Thu Sep 28, 2017 09:16

Stix wrote:abm ... dirt --> dirt-with-grass

Have a look at the intro to the developer-wiki.
 

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

Re: Post your modding questions here

by rubenwardy » Thu Sep 28, 2017 10:26

hajo wrote:
Stix wrote:abm ... dirt --> dirt-with-grass

Have a look at the intro to the developer-wiki.


I'd also recommend my ABM chapter over that (I wrote most of the tutorial the intro is based on, btw). You'll need to remove the +1 to the y axis, as it currently places the node above the ABM node
 

User avatar
Lone_Wolf
Member
 
Posts: 1630
Joined: Sun Apr 09, 2017 05:50
Location: You wouldn't believe me
GitHub: LoneWolfHT
IRC: Lone_Wolf
In-game: Lone_Wolf or Somebody

Re: Post your modding questions here

by Lone_Wolf » Mon Oct 09, 2017 19:37

Is there a way to check for another mod and if the mod is found: Register a node/item/recipe?
 

User avatar
Lejo
Member
 
Posts: 230
Joined: Mon Oct 19, 2015 16:32
GitHub: Lejo1
In-game: Lejo

Re: Post your modding questions here

by Lejo » Tue Oct 10, 2017 05:15

You can use:
Code: Select all
if minetest.global_exists("sfinv") then  --sfinv is the modname
 --your code
end
 

User avatar
v-rob
Member
 
Posts: 349
Joined: Thu Mar 24, 2016 03:19

Re: Post your modding questions here

by v-rob » Wed Oct 11, 2017 23:12

EDIT: Never mind, I figured it out
 

PreviousNext

Return to Modding Discussion



Who is online

Users browsing this forum: No registered users and 2 guests