Page 1 of 1

Japaneses Trees[V 1.0]

PostPosted: Thu Nov 01, 2012 17:03
by OdnetninI
If you want this type of trees continue reading:
Image

I added to the engine, Japanese Trees.

How to Compile: https://github.com/celeron55/minetest/blob/stable-0.4/README.txt

First Open src/subgame.cpp

For 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
std::string getGameName(const std::string &game_path)
{
    std::string conf_path = game_path + DIR_DELIM + "game.conf";
    Settings conf;
    bool succeeded = conf.readConfigFile(conf_path.c_str());
    if(!succeeded)
        return "";
    if(!conf.exists("name"))
        return "";
    return conf.get("name");
}


Change for 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
bool japanese = false;

std::string getGameName(const std::string &game_path)
{
    std::string conf_path = game_path + DIR_DELIM + "game.conf";
    Settings conf;
    bool succeeded = conf.readConfigFile(conf_path.c_str());
    if(!succeeded)
        return "";
    if(!conf.exists("name"))
        return "";

/*
        Japanese
    */
    if(!conf.exists("JapaneseTree"))
        japanese = false;
    else {
        if (stoi(conf.get("JapaneseTree")) == 1)
            japanese = true;

        else
            japanese = false;
    }

    return conf.get("name");
}


Now open src/mapgen.cpp


Add 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
extern bool japanese;


Before:

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
namespace mapgen


Now Change 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
void make_tree(ManualMapVoxelManipulator &vmanip, v3s16 p0,
        bool is_apple_tree, INodeDefManager *ndef)
{
    MapNode treenode(ndef->getId("mapgen_tree"));
    MapNode leavesnode(ndef->getId("mapgen_leaves"));
    MapNode applenode(ndef->getId("mapgen_apple"));

    s16 trunk_h = myrand_range(4, 5);
    v3s16 p1 = p0;
    for(s16 ii=0; ii<trunk_h; ii++)
    {
        if(vmanip.m_area.contains(p1))
            vmanip.m_data[vmanip.m_area.index(p1)] = treenode;
        p1.Y++;
    }

    // p1 is now the last piece of the trunk
    p1.Y -= 1;

VoxelArea leaves_a(v3s16(-2,-1,-2), v3s16(2,2,2));
    //SharedPtr<u8> leaves_d(new u8[leaves_a.getVolume()]);
    Buffer<u8> leaves_d(leaves_a.getVolume());
    for(s32 i=0; i<leaves_a.getVolume(); i++)
        leaves_d[i] = 0;

    // Force leaves at near the end of the trunk
    {
        s16 d = 1;
        for(s16 z=-d; z<=d; z++)
        for(s16 y=-d; y<=d; y++)
        for(s16 x=-d; x<=d; x++)
        {
            leaves_d[leaves_a.index(v3s16(x,y,z))] = 1;
        }
    }

    // Add leaves randomly
    for(u32 iii=0; iii<7; iii++)
    {
        s16 d = 1;

        v3s16 p(
            myrand_range(leaves_a.MinEdge.X, leaves_a.MaxEdge.X-d),
            myrand_range(leaves_a.MinEdge.Y, leaves_a.MaxEdge.Y-d),
            myrand_range(leaves_a.MinEdge.Z, leaves_a.MaxEdge.Z-d)
        );

        for(s16 z=0; z<=d; z++)
        for(s16 y=0; y<=d; y++)
        for(s16 x=0; x<=d; x++)
        {
            leaves_d[leaves_a.index(p+v3s16(x,y,z))] = 1;
        }
    }

    // Blit leaves to vmanip
    for(s16 z=leaves_a.MinEdge.Z; z<=leaves_a.MaxEdge.Z; z++)
    for(s16 y=leaves_a.MinEdge.Y; y<=leaves_a.MaxEdge.Y; y++)
    for(s16 x=leaves_a.MinEdge.X; x<=leaves_a.MaxEdge.X; x++)
    {
        v3s16 p(x,y,z);
        p += p1;
        if(vmanip.m_area.contains(p) == false)
            continue;
        u32 vi = vmanip.m_area.index(p);
        if(vmanip.m_data[vi].getContent() != CONTENT_AIR
                && vmanip.m_data[vi].getContent() != CONTENT_IGNORE)
            continue;
        u32 i = leaves_a.index(x,y,z);
        if(leaves_d[i] == 1) {
            bool is_apple = myrand_range(0,99) < 10;
            if(is_apple_tree && is_apple) {
                vmanip.m_data[vi] = applenode;
            } else {
                    vmanip.m_data[vi] = leavesnode;
                }
            }
        }
    }
}


For 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
void make_tree(ManualMapVoxelManipulator &vmanip, v3s16 p0,
        bool is_apple_tree, INodeDefManager *ndef)
{
    MapNode treenode(ndef->getId("mapgen_tree"));
    MapNode leavesnode(ndef->getId("mapgen_leaves"));
    MapNode Jleavesnode(ndef->getId("mapgen_leaves_japanese"));
    MapNode applenode(ndef->getId("mapgen_apple"));

    s16 trunk_h = myrand_range(4, 5);
    v3s16 p1 = p0;
    for(s16 ii=0; ii<trunk_h; ii++)
    {
        if(vmanip.m_area.contains(p1))
            vmanip.m_data[vmanip.m_area.index(p1)] = treenode;
        p1.Y++;
    }

    // p1 is now the last piece of the trunk
    p1.Y -= 1;

    VoxelArea leaves_a(v3s16(-2,-1,-2), v3s16(2,2,2));
    //SharedPtr<u8> leaves_d(new u8[leaves_a.getVolume()]);
    Buffer<u8> leaves_d(leaves_a.getVolume());
    for(s32 i=0; i<leaves_a.getVolume(); i++)
        leaves_d[i] = 0;

    // Force leaves at near the end of the trunk
    {
        s16 d = 1;
        for(s16 z=-d; z<=d; z++)
        for(s16 y=-d; y<=d; y++)
        for(s16 x=-d; x<=d; x++)
        {
            leaves_d[leaves_a.index(v3s16(x,y,z))] = 1;
        }
    }

    // Add leaves randomly
    for(u32 iii=0; iii<7; iii++)
    {
        s16 d = 1;

        v3s16 p(
            myrand_range(leaves_a.MinEdge.X, leaves_a.MaxEdge.X-d),
            myrand_range(leaves_a.MinEdge.Y, leaves_a.MaxEdge.Y-d),
            myrand_range(leaves_a.MinEdge.Z, leaves_a.MaxEdge.Z-d)
        );

        for(s16 z=0; z<=d; z++)
        for(s16 y=0; y<=d; y++)
        for(s16 x=0; x<=d; x++)
        {
            leaves_d[leaves_a.index(p+v3s16(x,y,z))] = 1;
        }
    }

    bool is_japanese = myrand_range(0,99) < 20;

    // Blit leaves to vmanip
    for(s16 z=leaves_a.MinEdge.Z; z<=leaves_a.MaxEdge.Z; z++)
    for(s16 y=leaves_a.MinEdge.Y; y<=leaves_a.MaxEdge.Y; y++)
    for(s16 x=leaves_a.MinEdge.X; x<=leaves_a.MaxEdge.X; x++)
    {
        v3s16 p(x,y,z);
        p += p1;
        if(vmanip.m_area.contains(p) == false)
            continue;
        u32 vi = vmanip.m_area.index(p);
        if(vmanip.m_data[vi].getContent() != CONTENT_AIR
                && vmanip.m_data[vi].getContent() != CONTENT_IGNORE)
            continue;
        u32 i = leaves_a.index(x,y,z);
        if(leaves_d[i] == 1) {
            bool is_apple = myrand_range(0,99) < 10;
            if(is_apple_tree && is_apple) {
                vmanip.m_data[vi] = applenode;
            } else {
                //JAPANESE
                if (japanese == true && is_japanese) {
                    vmanip.m_data[vi] = Jleavesnode;
                } else {
                    // Normal
                    vmanip.m_data[vi] = leavesnode;
                }
            }
        }
    }
}


your_game could be:
  • minetest
  • minimal
  • etc...

Now Open: games/your_game/mods/default/init.lua

Add 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_node("default:Jleaves", {
    description = "Japanese Leaves",
    drawtype = "allfaces_optional",
    visual_scale = 1.3,
    tiles = {"default_Jleaves.png"},
    paramtype = "light",
    groups = {snappy=3, leafdecay=3, flammable=2},
    drop = {
        max_items = 1,
        items = {
            {
                -- player will get sapling with 1/20 chance
                items = {'default:sapling'},
                rarity = 20,
            },
            {
                -- player will get leaves only if he get no saplings,
                -- this is because max_items is 1
                items = {'default:Jleaves'},
            }
        }
    },
    sounds = default.node_sound_leaves_defaults(),
})


Now open games/your_game/game.conf

Add:

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
JapaneseTree = 1


1 for activate, 0 disable.


Warring: it made that all new generated trees at any map chages. I recomed use a diferent minetest_game for every type of trees.

Now open games/your_game/mods/default/mapgen.lua

Add 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_leaves_japanese", "default:Jleaves")


For finish, add: Image, to games/your_game/mods/default/textures and rename it to: default_Jleaves.png

Download img: http://img803.imageshack.us/img803/7209/defaultjleaves.png

Bye

PostPosted: Thu Nov 01, 2012 17:07
by PilzAdam
It would be better to create a mod that uses on_generate and sets some trees to japanese trees. That is easier to use.

PostPosted: Thu Nov 01, 2012 17:09
by OdnetninI
yeah, but i want to learn how internal game works, and i get this with engine.

PostPosted: Thu Nov 01, 2012 18:36
by Mito551
great! this is beatiful!

PostPosted: Thu Nov 01, 2012 23:58
by GloopMaster
they're called sakura trees. Just a heads-up ;)

PostPosted: Sun Nov 11, 2012 04:13
by CaKeSs
First, I thought it was Bonsai.

PostPosted: Sun Nov 11, 2012 08:21
by OdnetninI
SOrry CaKeSs, they are sakura trees

PostPosted: Fri Jan 18, 2013 04:59
by Michael Eh?
Actually they are Cherry trees which bloom in spring. Sakura means Cherry.

However, if this could be opened up to allow hooks to allow for more Biomes like snow or return of Jungle trees. I think that would make the game more open to development.

Maybe allowing them in certain areas of the map like extreme East or West of the map or certain North-South (latitudes) or elevations.

Like Palm/coconut trees only beside water and normal sand.

PostPosted: Fri Jan 18, 2013 05:03
by Menche
Probably the recommended way to implement tree is with L-Systems in lua.

PostPosted: Fri Jan 18, 2013 05:18
by Spots
this would make a great mod or addition to the new trees , cherry blossoms in pink and red and hydrangea trees in pinks and blues

PostPosted: Tue Feb 05, 2013 16:36
by Michael Eh?
You are going to have to decide if you are going to include cherries and seedlings. maybe even cherry wood which would add some depth in colour. Alot of worlds buildings loose their organic look. Maybe along with bambo we can have an asian feel to the game which would bring in anime fans as well as Asian players.

PostPosted: Tue Feb 12, 2013 03:49
by Gambit
Rename it "sakura", it's more easier to go by since that's what they're called.

PostPosted: Tue Feb 12, 2013 07:45
by Jordach
Gambit wrote:Rename it "sakura", it's more easier to go by since that's what they're called.
And less time to type too!

PostPosted: Tue Feb 12, 2013 16:00
by VanessaE
If someone can come up with a nice L-Systems model and biome information for me, I'll add this to moretrees.

PostPosted: Tue Feb 12, 2013 17:31
by Mito551
Image

that?