Automatic, random texture placement

User avatar
TumeniNodes
Member
 
Posts: 1335
Joined: Fri Feb 26, 2016 19:49
GitHub: TumeniNodes

Automatic, random texture placement

by TumeniNodes » Thu Feb 09, 2017 00:41

I changed the title for this thread... random texture placement is the actual description

Was not really sure where I should post this?

Just something I threw together (related to a feature I have been wanting to see, or figure out how to obtain)
And had not noticed until now, that it actually has existed in MT right along :P

Automatic, random texture placement.

video : https://youtu.be/u4AmYAgUSQo (sorry it is wicked low fps using default OS recorder)

So, basically I did this to experiment, using the existing code to place default_grass_1 thru 5 at random

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.register_node("default:stone", {
   description = "Stone",
   tiles = {"default_stone.png"},
   groups = {cracky = 3, stone = 1},
   drop = 'default:cobble',
   legacy_mineral = true,
   sounds = default.node_sound_stone_defaults(),

   on_place = function(itemstack, placer, pointed_thing)
      -- place a random stone node
      local stack = ItemStack("default:stone_" .. math.random(1,4))
      local ret = minetest.item_place(stack, placer, pointed_thing)
      return ItemStack("default:stone " ..
         itemstack:get_count() - (1 - ret:get_count()))
   end,
})

for i = 2, 4 do
   minetest.register_node("default:stone_" .. i, {
      description = "Stone",
      tiles = {"default_stone_" .. i .. ".png"},
      drop = "default:cobble",
      groups = {cracky = 3, stone = 1, attached_node = 1},
      sounds = default.node_sound_stone_defaults()
})
end


<ignore>I think but not certain, this random math also grabs "none" as well randomly? Because once in a while when I right click to place, the place sound is there but no node.<fixed>

Anyway, I'll figure it out eventually.

My plan is to make this an available feature, but to try to figure out how to give it an on/off option (off by default)

As well as to figure out how to work it into mapgen so when the world loads the basic "natural" nodes (such as stone) it loads using this random feature to produce a nicer visual (less of a pattern appearance)
While definitely not needing to change default_stone to default_stone_1. Because the first placement of default stone, I lose that original node and the maths only run through the other 3 nodes from there on rather than all 4

All I did texture-wise, was to duplicate default stone 3 times and name those default_stone_2, _3, and_4 and then switched them around quickly with Gimp and used these for testing
So there is then default_stone, default_stone_2, default_stone_3, default_stone_4

Looking for feedback, and anyone interested with more code experience than me, if interested and want to help : )
(I'm not proud :D )
Last edited by TumeniNodes on Fri Feb 10, 2017 00:47, edited 4 times in total.
Flick?... Flick who?
 

User avatar
TumeniNodes
Member
 
Posts: 1335
Joined: Fri Feb 26, 2016 19:49
GitHub: TumeniNodes

Re: Automatic, random node placement

by TumeniNodes » Thu Feb 09, 2017 01:13

aha... just figured out one piece.

Simply make a duplicate of default_stone, leave it alone and rename the duplicate to default_stone_1 :P tada!
and then change line 214 of nodes.lua from>
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
for i = 2, 4 do
to>
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
for i = 1, 4 do


Now I have 4 variants of default stone I can place automatically, and at random (I'm so happy) :D

I realize this is not brilliant or genius... just copying an existing code but, for me, it suddenly give me a feature which I have been craving for building as well as hopefully providing a more natural visual scene to the landscape.

And..., it is easy to use in any mode where one might want to add a few variants of certain textures.

>edit: but now I find a very odd issue... if I go to a mountainside, of stone... and attempt to place stone against it using this set up... the new node shows for a fraction of a second, then disappears.... (very interesting)

^>edit: figured out the above issue. mistake on my part, I should have removed "attached_node = 1".
I also re-entered "not_in_creative_inventory = 1" for nodes default_stone_1, 4

All works like a charm now. Now just need to figure out how to set it with an on/off option.
As well as how to work this into the mapgen.
Flick?... Flick who?
 

User avatar
TumeniNodes
Member
 
Posts: 1335
Joined: Fri Feb 26, 2016 19:49
GitHub: TumeniNodes

Re: Automatic, random texture placement

by TumeniNodes » Thu Feb 09, 2017 19:11

So the code looks like this now.

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.register_node("default:stone", {
   description = "Stone",
   tiles = {"default_stone.png"},
   groups = {cracky = 3, stone = 1},
   drop = 'default:cobble',
   legacy_mineral = true,
   sounds = default.node_sound_stone_defaults(),

   on_place = function(itemstack, placer, pointed_thing)
      -- place a random stone node
      local stack = ItemStack("default:stone_" .. math.random(1,4))
      local ret = minetest.item_place(stack, placer, pointed_thing)
      return ItemStack("default:stone " ..
         itemstack:get_count() - (1 - ret:get_count()))
   end,
})

for i = 1, 4 do
   minetest.register_node("default:stone_" .. i, {
      description = "Stone",
      tiles = {"default_stone_" .. i .. ".png"},
      drop = "default:cobble",
      groups = {cracky = 3, stone = 1, not_in_creative_inventory = 1},
      sounds = default.node_sound_stone_defaults()
})
end


And for textures, simply make 4 duplicates of default_stone. Use Gimp (or your preferred software) to flip 3 of them around horiz. and vert.
Then rename these 4 new textures default_stone_1, _2, _3, and _4.
the same will need to be done for any texture pack you want to use this with

And it does not matter which texture you want to add this to (I'm only using stone as an example)
But, all the texture variants need to line up with one another at all four edges

Fire up MT and start placing stone.

I am now able to reorganize a mod I was working on a while back where I use variants of a few textures (like brick and cobble, etc.), and now it works exactly as I wanted it to.
And I am really hoping I can get this all to work nicely with on/off option per individual mods (like default), and with mapgen (with on/off as well) so people can enjoy it, without any negative impact on MT whether it is off or on.
Flick?... Flick who?
 

User avatar
TumeniNodes
Member
 
Posts: 1335
Joined: Fri Feb 26, 2016 19:49
GitHub: TumeniNodes

Re: Automatic, random texture placement

by TumeniNodes » Sun Feb 12, 2017 16:31

this quick thread is copied from mapgen questions to here, so it does not clutter the mapgen questions section

Are we able to set more than one material for mapgen nodes? Or is there a magical way to use a string of nodes?

In other words I have this

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
 minetest.register_alias("mapgen_stone", "default:stone_"..1,4)

which only reads default_stone_1.

I have tried numerous ways including e.g:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.register_alias("mapgen_stone", "default:stone_".. math.random1,4))

or something like that (I've tried so many methods I cant recall now :P )
But that last method created a funny event.... using a dummy DB, it cycles through the stones 1 thru 4 each time I start MT... So, one time it will use default_stone_1..., close out, restart and it uses Default_stone_3, and so on... : /

I am not sure if anyone has followed or had interest in my experiment here
But what I am trying to figure out, is "if" I can use the multiple versions of default_stone to load during map generation, so they are randomly generated, giving a less tiled visual.

I even tried using

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.register_alias("mapgen_stone", "default:stone_".. i)

but this just .... : / actually, I forget what that did... :D

Anyway... any help is greatly appreciated. Because I have NO idea what the heck I'm doing here :P

And if it is, that there can be only one alias, and a string is undoable.... well, then that's okey dokey too

----------
burli wrote:There is a discussion to use animated stripes. Correctly there is no way to use multiple nodes or textures, AFAIK


----------
Hmm..., using animated strips might require using layers and calling mapgen to randomly choose between frame numbers...
Sounds... interesting but, I'm not sure I understand how that might be more logical, practical, or even different than just using additional textures?
Is there a link to such conversation I can review?

I just really wish I were able to figure this out though but, I simply am not that fluent or functional with coding.
I keep going back and trying to read more about applying Lua but, I'm just not "wired" right for coding languages :(

I honestly feel though, that there must be some way to achieve this... and will keep plugging away... even though most I try will probably be waaaaay completely incorrect :P

And I get distracted and bored, extremely easil........ (oooohhh what's that?...)

---------
burli wrote:Here is something on Github https://github.com/minetest/minetest/issues/2746

And this issue was closed https://github.com/minetest/minetest/issues/2747


---------
Last edited by TumeniNodes on Sun Feb 12, 2017 17:45, edited 2 times in total.
Flick?... Flick who?
 

User avatar
TumeniNodes
Member
 
Posts: 1335
Joined: Fri Feb 26, 2016 19:49
GitHub: TumeniNodes

Re: Automatic, random texture placement

by TumeniNodes » Sun Feb 12, 2017 16:51

Thank you burli.

My idea is a bit different (I think)

I would use individual textures to achieve the idea. But, only for the natural nodes (meaning stone, grass, desert stone, maybe the sand nodes, etc.)

It would add anywhere from 2-4 new textures for each and, would be an "on/off" feature (off by default)

Anything using the feature aside from these basic terrain nodes would be up to mods.

And when the feature is off, all revert to the original "first" texture.
Which means not all TPs would have to support the function.

Or, if variant textures do not exist in a TP, the feature only grabs texture #1 and skips the others?

I think after initial mapgen, sqlite3 would handle remembering which is where?
(which suddenly poses the issue, "so how does it change it if the feature is turned on?") grrrrr.

Anyway, this appears to be a talk to myself thread but, that's ok, because I have a strong interest in this feature :P
Flick?... Flick who?
 

User avatar
TumeniNodes
Member
 
Posts: 1335
Joined: Fri Feb 26, 2016 19:49
GitHub: TumeniNodes

Re: Automatic, random texture placement

by TumeniNodes » Mon Feb 13, 2017 05:35

Ok, mapgen plans = scrapped... (for now?) :P

I'll release a mod using what there is anyway..., soon-ish : )
Flick?... Flick who?
 

paramat
Member
 
Posts: 2662
Joined: Sun Oct 28, 2012 00:05
GitHub: paramat

Re: Automatic, random texture placement

by paramat » Wed Feb 15, 2017 03:14

To change nodes on mapgen you would use a 'mapgen object' lua voxelmanipulator in an 'on generated' function to process all stone nodes and replace each with a random variant. If you study the code of a lua mapgen that will show how to do this.
 

User avatar
TumeniNodes
Member
 
Posts: 1335
Joined: Fri Feb 26, 2016 19:49
GitHub: TumeniNodes

Re: Automatic, random texture placement

by TumeniNodes » Wed Feb 15, 2017 03:17

paramat wrote:To change nodes on mapgen you would use a 'mapgen object' lua voxelmanipulator in an 'on generated' function to process all stone nodes and replace each with a random variant. If you study the code of a lua mapgen that will show how to do this.


Like the one qwertymine has been working on? (or am I being a dummy again?) :P
Flick?... Flick who?
 

paramat
Member
 
Posts: 2662
Joined: Sun Oct 28, 2012 00:05
GitHub: paramat

Re: Automatic, random texture placement

by paramat » Wed Feb 15, 2017 03:55

It's quite simple, just simplify and alter this code https://github.com/PilzAdam/nether/blob/d6d388b1c78edbe63c337c64b4919efabf3078b7/init.lua#L424
Line 424 onwards.
You can remove 'vm:update_liquids()' from the end.
 

User avatar
TumeniNodes
Member
 
Posts: 1335
Joined: Fri Feb 26, 2016 19:49
GitHub: TumeniNodes

Re: Automatic, random texture placement

by TumeniNodes » Wed Feb 15, 2017 04:01

paramat wrote:It's quite simple, just simplify and alter this code https://github.com/PilzAdam/nether/blob/d6d388b1c78edbe63c337c64b4919efabf3078b7/init.lua#L424
Line 424 onwards.
You can remove 'vm:update_liquids()' from the end.


Awesome! Thank you very much.
I'll start working with this in the next few days.
Flick?... Flick who?
 

paramat
Member
 
Posts: 2662
Joined: Sun Oct 28, 2012 00:05
GitHub: paramat

Re: Automatic, random texture placement

by paramat » Fri Feb 17, 2017 19:17

Since you're exchanging stone for stone you probably don't need to recalculate lighting either, so try without vm:set lighting, vm:calc lighting.
 

User avatar
TumeniNodes
Member
 
Posts: 1335
Joined: Fri Feb 26, 2016 19:49
GitHub: TumeniNodes

Re: Automatic, random texture placement

by TumeniNodes » Tue Feb 21, 2017 01:18

paramat wrote:Since you're exchanging stone for stone you probably don't need to recalculate lighting either, so try without vm:set lighting, vm:calc lighting.


Thank you.
Flick?... Flick who?
 


Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 59 guests

cron