How to use Plantlike meshoptions [SOLVED]

Post Reply
User avatar
Nathan.S
Member
Posts: 1147
Joined: Wed Sep 24, 2014 17:47
GitHub: NathanSalapat
IRC: NathanS21
In-game: NathanS21
Location: Bigsby Texas
Contact:

How to use Plantlike meshoptions [SOLVED]

by Nathan.S » Post

I'm probably just really stupid, but for the life of me I can't figure this out.

Code: Select all

* `paramtype2 = "meshoptions"`
    * Only valid for "plantlike". The value of `param2` becomes a bitfield which
      can be used to change how the client draws plantlike nodes.
    * Bits 0, 1 and 2 form a mesh selector.
      Currently the following meshes are choosable:
        * 0 = a "x" shaped plant (ordinary plant)
        * 1 = a "+" shaped plant (just rotated 45 degrees)
        * 2 = a "*" shaped plant with 3 faces instead of 2
        * 3 = a "#" shaped plant with 4 faces instead of 2
        * 4 = a "#" shaped plant with 4 faces that lean outwards
        * 5-7 are unused and reserved for future meshes.
    * Bits 3 through 7 are optional flags that can be combined and give these
      effects:
        * bit 3 (0x08) - Makes the plant slightly vary placement horizontally
        * bit 4 (0x10) - Makes the plant mesh 1.4x larger
        * bit 5 (0x20) - Moves each face randomly a small bit down (1/8 max)
        * bits 6-7 are reserved for future use.
I can get the shape to change without any trouble.

Code: Select all

drawtype = 'plantlike',
   paramtype2 = 'meshoptions',
   place_param2 = 4,
How in the world do I use the effects, or more specifically how do I combine the values? If I try putting the 0x08 behind the first number I get an error about a malformed number. Obviously separating the numbers with a comma does nothing as the engine expect that to be a completely different value.
Likely I just don't understand bitfields at all, but a google search didn't return any thing that looked like it was related to what I need to do here.

I found the solution digging through the closed issues on Github.

Code: Select all

place_param2 = 4 + 0x10,
I record Minetest videos, Mod reviews, Modding tutorials, and Lets plays.
Check out my website, and brand new Minetest Modding Course

sofar
Developer
Posts: 2146
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: How to use Plantlike meshoptions [SOLVED]

by sofar » Post

yep, you just add the values (which is why I give the hex values).

0x10 = 16 = 2^4 (e.g. the 4th bit), aka 00010000 binary, add to '4' which is 00000100, results in 00010100 (20 dec).

User avatar
texmex
Member
Posts: 1753
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: tacotexmex

Re: How to use Plantlike meshoptions [SOLVED]

by texmex » Post

Now, why is are these hex values? What's the reason for exposing these values to the user of the Lua API? Why not convert human readable values into the hex values behind the scenes? There's probably some reason, but still. Jeeze! ':D

sofar
Developer
Posts: 2146
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: How to use Plantlike meshoptions [SOLVED]

by sofar » Post

texmex wrote:Now, why is are these hex values? What's the reason for exposing these values to the user of the Lua API? Why not convert human readable values into the hex values behind the scenes? There's probably some reason, but still. Jeeze! ':D
"jeeze".

You're using a programming API. You're a programmer or an aspiring one. You should definitely attempt to understand bitwise values, binary, and hexadecimal, if the API specifically needs to convey bits. There are only 8 bits to work with in this case, so the best way to pack this field is, bits, and that calls for bit wise notation, bit enums and bit operators.

Including a tutorial on bits goes way too far. The lua API shouldn't do that, but it should also not dumb things down too much because the best way to work with bits is .. using hex/bit descriptive text. Oh, and lua knows how to read hexadecimal. :P

User avatar
TumeniNodes
Member
Posts: 2941
Joined: Fri Feb 26, 2016 19:49
GitHub: TumeniNodes
IRC: tumeninodes
In-game: TumeniNodes
Location: in the dark recesses of the mind
Contact:

Re: How to use Plantlike meshoptions [SOLVED]

by TumeniNodes » Post

Ya... what the hex tex? :P
(sorry, I just really had too, it was just sitting there)
A Wonderful World

User avatar
Nathan.S
Member
Posts: 1147
Joined: Wed Sep 24, 2014 17:47
GitHub: NathanSalapat
IRC: NathanS21
In-game: NathanS21
Location: Bigsby Texas
Contact:

Re: How to use Plantlike meshoptions [SOLVED]

by Nathan.S » Post

sofar wrote:yep, you just add the values (which is why I give the hex values).

0x10 = 16 = 2^4 (e.g. the 4th bit), aka 00010000 binary, add to '4' which is 00000100, results in 00010100 (20 dec).
I was just really confused because the first set of values didn't look like hex and obviously they weren't binary. I've never used Hex or bitfields , but now that you explain it like this, it make sense.

I also realized that 1-9 are the same in hex and decimal form after reading your reply. >.<
I record Minetest videos, Mod reviews, Modding tutorials, and Lets plays.
Check out my website, and brand new Minetest Modding Course

User avatar
texmex
Member
Posts: 1753
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: tacotexmex

Re: How to use Plantlike meshoptions [SOLVED]

by texmex » Post

Fair enough, fair enough. I didn't realize the complexity of combinations at first, now I see.

ShadMOrdre
Member
Posts: 1118
Joined: Mon Dec 29, 2014 08:07
Location: USA

Re: How to use Plantlike meshoptions [SOLVED]

by ShadMOrdre » Post

This seems to be an appropriate example, that should be added to the Lua_api.txt file, for clarity sake and just to have a code sample.

sofar
Developer
Posts: 2146
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: How to use Plantlike meshoptions [SOLVED]

by sofar » Post

ShadMOrdre wrote:This seems to be an appropriate example, that should be added to the Lua_api.txt file, for clarity sake and just to have a code sample.
The documentation would be too lengthy, since there are plenty of other functions that fall in the same category or assume some level of generic programming knowledge. That sort of stuff is better off in the minetest modding book by rubenwardy, or the wiki.

User avatar
Nathan.S
Member
Posts: 1147
Joined: Wed Sep 24, 2014 17:47
GitHub: NathanSalapat
IRC: NathanS21
In-game: NathanS21
Location: Bigsby Texas
Contact:

Re: How to use Plantlike meshoptions [SOLVED]

by Nathan.S » Post

I'll be making a video on this once 5.0 releases. Was working on figuring out how this function for that exact purpose.
I record Minetest videos, Mod reviews, Modding tutorials, and Lets plays.
Check out my website, and brand new Minetest Modding Course

sofar
Developer
Posts: 2146
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: How to use Plantlike meshoptions [SOLVED]

by sofar » Post

Nathan.S wrote:I'll be making a video on this once 5.0 releases. Was working on figuring out how this function for that exact purpose.
Do you need a guest co-host?

User avatar
Nathan.S
Member
Posts: 1147
Joined: Wed Sep 24, 2014 17:47
GitHub: NathanSalapat
IRC: NathanS21
In-game: NathanS21
Location: Bigsby Texas
Contact:

Re: How to use Plantlike meshoptions [SOLVED]

by Nathan.S » Post

A co-host, I've never done that for a modding video. I'm not really sure how that would even work. I think I should be good, but that you for the offer. I got it all figured out, mixed all the things together, everything is working. :)

If you ever want to co-host a live stream with me feel free to let me know.
I record Minetest videos, Mod reviews, Modding tutorials, and Lets plays.
Check out my website, and brand new Minetest Modding Course

sofar
Developer
Posts: 2146
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: How to use Plantlike meshoptions [SOLVED]

by sofar » Post

Nathan.S wrote:A co-host, I've never done that for a modding video. I'm not really sure how that would even work. I think I should be good, but that you for the offer. I got it all figured out, mixed all the things together, everything is working. :)

If you ever want to co-host a live stream with me feel free to let me know.
So I've watched your videos and you do a great job of "asking" during your gameplay. It feels only natural you also have someone there to give you answers. For lots of your mod reviews, this would really help viewers I think.

ShadMOrdre
Member
Posts: 1118
Joined: Mon Dec 29, 2014 08:07
Location: USA

Re: How to use Plantlike meshoptions [SOLVED]

by ShadMOrdre » Post

Nathan,

He's right. Grab a friend. Do what they all do, grab a female friend. It certainly expands the appeal to both genders. I'm certain there are plenty of women who enjoy MC and or MT. I know plenty of kids of both genders LOVE MC, and thus potentially MT.

And you do make great vids!

Sofar,

Please understand I only implied providing the code example, not a detailed explanation of bitwise, as you stated in your reply to texmex. I was simply thinking something like this in lua_api... (copied directly from the code above) NOTE: place_param2 is not even referenced, in lua_api, it states that param2 is the bitfield, not place_param2, as used in the solution to this problem.

Code: Select all

Example:  If paramtype2 = meshoptions, place_param2 is used as below.
   drawtype = 'plantlike',
   paramtype2 = 'meshoptions',
   place_param2 = 4 + 0x10,
As for this going into either the wiki or reubenwardy's modding book, I can only say this...

The wiki is notoriously not updated, or some other issue is being reported on the forum. I code offline, and lua_api is my only reference. The modding book is not hosted by minetest, but by reubenwardy. Therefore, this cannot be viewed as official, even if it is a great resource. If the modding book is official, it should somehow be hosted by the official website, since we all have paranoia about third-party links. This is not outlandish, so please forgive the honest opinion.

Shad

sofar
Developer
Posts: 2146
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: How to use Plantlike meshoptions [SOLVED]

by sofar » Post

ShadMOrdre wrote:in lua_api, it states that param2 is the bitfield, not place_param2, as used in the solution to this problem.
That is because that would be incorrect:

You can change the param2 value, and thus the appearance of these nodes on the fly. That means that you can, through mod code, decide whether a node should always have the same param2 value when a player places it (place_param2 = value set in nodedef), or you can decide that you want to get a callback when the node is placed and then dynamically do a `n = minetest.get_node(pos); n.param2 = newparam2; swap_node(pos, n)` type swap.

In other words, the documentation describes the effect of the bits to the node. place_param2 is just ONE of the ways that the param2 value can be changed. Schematics and mapgen also can have effects, for instance, and for those you may need other methods (place_param2 isn't used by mapgen, for instance). Mods placing nodes also do not cause place_param2 to be used automatically.

User avatar
Nathan.S
Member
Posts: 1147
Joined: Wed Sep 24, 2014 17:47
GitHub: NathanSalapat
IRC: NathanS21
In-game: NathanS21
Location: Bigsby Texas
Contact:

Re: How to use Plantlike meshoptions [SOLVED]

by Nathan.S » Post

sofar wrote:
Nathan.S wrote:A co-host, I've never done that for a modding video. I'm not really sure how that would even work. I think I should be good, but that you for the offer. I got it all figured out, mixed all the things together, everything is working. :)

If you ever want to co-host a live stream with me feel free to let me know.
So I've watched your videos and you do a great job of "asking" during your gameplay. It feels only natural you also have someone there to give you answers. For lots of your mod reviews, this would really help viewers I think.
I just don't know how I would do the logistics. If I'm reviewing a mod, or writing code the guest has no idea what I'm doing I'd need some way for them to be able to see what I'm doing in real time, or possibly even interact with what I'm doing. Sounds like a logistical nightmare. Livestreams have a buffer so it's not truly live, there's a few second delay there. When I've done collaborative videos we've always just used some voice chat client, which is more or less real time, but just talking doesn't really sound like it would work for coding as the guest wouldn't know what code I have on screen.

ShadMOrde, if I had any friends, female or otherwise, that were interested in Minetest I'd try to get them to do something with me. Maybe if I ever get lucky and get a girlfriend I can convince her to join me on my live streams ;) Everybody knows that attractive girls pull in views. :P

Kinda off topic, but does anybody know of a mod that will let me change the param2 value of a node. I can write something up myself if I need to, but figure I can save a few minutes if something already exists. :)
I record Minetest videos, Mod reviews, Modding tutorials, and Lets plays.
Check out my website, and brand new Minetest Modding Course

sofar
Developer
Posts: 2146
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: How to use Plantlike meshoptions [SOLVED]

by sofar » Post

Nathan.S wrote: I just don't know how I would do the logistics. If I'm reviewing a mod, or writing code the guest has no idea what I'm doing I'd need some way for them to be able to see what I'm doing in real time, or possibly even interact with what I'm doing. Sounds like a logistical nightmare. Livestreams have a buffer so it's not truly live, there's a few second delay there. When I've done collaborative videos we've always just used some voice chat client, which is more or less real time, but just talking doesn't really sound like it would work for coding as the guest wouldn't know what code I have on screen.
Screen sharing, and even VNC would work. Not entirely trivial, but not too complex either.

sofar
Developer
Posts: 2146
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: How to use Plantlike meshoptions [SOLVED]

by sofar » Post

Nathan.S wrote:Kinda off topic, but does anybody know of a mod that will let me change the param2 value of a node. I can write something up myself if I need to, but figure I can save a few minutes if something already exists. :)
that's actually ON topic, lol

just do:

local n = minetest.get_node(pos)
n.param2 = <new value>
minetest.swap_node(pos, n)

User avatar
v-rob
Developer
Posts: 970
Joined: Thu Mar 24, 2016 03:19
GitHub: v-rob
IRC: v-rob
Location: Right behind you.

Re: How to use Plantlike meshoptions [SOLVED]

by v-rob » Post

It would be nice if the mesh/nodebox of an object was changeable like param2 so node could have animations without changing the node or using an animation like gears3d or waterwheel
Core Developer | My Best Mods: Bridger - Slats - Stained Glass

User avatar
paramat
Developer
Posts: 3700
Joined: Sun Oct 28, 2012 00:05
GitHub: paramat
IRC: paramat
Location: UK

Re: How to use Plantlike meshoptions [SOLVED]

by paramat » Post

Even i find the meshoptions docs a little challenging: The mixing of normal numbers and hex. I think they could be clearer, they seem unnecessarily technical.
The CSM restriction flags docs just give normal numbers to add up.

User avatar
Nathan.S
Member
Posts: 1147
Joined: Wed Sep 24, 2014 17:47
GitHub: NathanSalapat
IRC: NathanS21
In-game: NathanS21
Location: Bigsby Texas
Contact:

Re: How to use Plantlike meshoptions [SOLVED]

by Nathan.S » Post

sofar wrote: Screen sharing, and even VNC would work. Not entirely trivial, but not too complex either.
I've never used screen sharing or a VNC on linux, I guess I could look into those options.

I knew how to change the param2. :P I got code similar to that in the on_construct callback to randomize the rotation of plants with degrotate. :) I was wondering if there was a tool that existed that could do it, but I guess I'll have to code something as I couldn't find anything that would let me edit the param2 values. I just want to be able to show the difference without needing to launch the game a whole bunch to record all the clips individually.
I record Minetest videos, Mod reviews, Modding tutorials, and Lets plays.
Check out my website, and brand new Minetest Modding Course

User avatar
Nathan.S
Member
Posts: 1147
Joined: Wed Sep 24, 2014 17:47
GitHub: NathanSalapat
IRC: NathanS21
In-game: NathanS21
Location: Bigsby Texas
Contact:

Re: How to use Plantlike meshoptions [SOLVED]

by Nathan.S » Post

Actually found an easier way than making a tool. Just gave the node a formspec that lets me change the value from there. :)
I record Minetest videos, Mod reviews, Modding tutorials, and Lets plays.
Check out my website, and brand new Minetest Modding Course

jcarr
New member
Posts: 1
Joined: Thu Mar 18, 2021 17:45
GitHub: jarrancarr
In-game: Jarran

Re: How to use Plantlike meshoptions [SOLVED]

by jcarr » Post

this is my code and it doesn't work. I only ever get the cross instead of the hash layout

local def = {
drawtype = "plantlike",
tiles = {"starfire_fire.png"},
paramtype = "light",
paramtype2 = "meshoptions",
place_param2 = 3,
sunlight_propagates = true,
walkable = false,
buildable_to = true,
drop = "",
groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2}
}

-- stage 1
minetest.register_node("starfire:fire", table.copy(def))

User avatar
Nathan.S
Member
Posts: 1147
Joined: Wed Sep 24, 2014 17:47
GitHub: NathanSalapat
IRC: NathanS21
In-game: NathanS21
Location: Bigsby Texas
Contact:

Re: How to use Plantlike meshoptions [SOLVED]

by Nathan.S » Post

jcarr, I don't know why it's not working for you. I put the place_param2 line in some of my code, set it to three and the plants show as the # shape properly when placing them.
I record Minetest videos, Mod reviews, Modding tutorials, and Lets plays.
Check out my website, and brand new Minetest Modding Course

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 7 guests