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
- 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 )