Japaneses Trees[V 1.0]

For people working on the C++ code.
Post Reply
OdnetninI
Member
Posts: 38
Joined: Sun Oct 21, 2012 08:20

Japaneses Trees[V 1.0]

by OdnetninI » Post

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/b ... README.txt

First Open src/subgame.cpp

For this:

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:

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:

Code: Select all

extern bool japanese;
Before:

Code: Select all

namespace mapgen
Now Change this:

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:

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:

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:

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:

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 ... leaves.png

Bye

User avatar
PilzAdam
Member
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam
Location: Germany

by PilzAdam » Post

It would be better to create a mod that uses on_generate and sets some trees to japanese trees. That is easier to use.

OdnetninI
Member
Posts: 38
Joined: Sun Oct 21, 2012 08:20

by OdnetninI » Post

yeah, but i want to learn how internal game works, and i get this with engine.
Last edited by OdnetninI on Thu Nov 01, 2012 17:09, edited 1 time in total.

User avatar
Mito551
Member
Posts: 1271
Joined: Sat Jun 16, 2012 15:03

by Mito551 » Post

great! this is beatiful!

User avatar
GloopMaster
Member
Posts: 213
Joined: Wed Aug 01, 2012 18:03
Location: http://minetest.net/forum/

by GloopMaster » Post

they're called sakura trees. Just a heads-up ;)
Meow.

That is all.

User avatar
CaKeSs
Member
Posts: 48
Joined: Sat Oct 13, 2012 02:48
Location: Philippines

by CaKeSs » Post

First, I thought it was Bonsai.
lalalalala, Hit, dig, break, collect! -JusticeV before he fell in lava.
|Youtube||Unrealsoftware Account|Granite Mod|

OdnetninI
Member
Posts: 38
Joined: Sun Oct 21, 2012 08:20

by OdnetninI » Post

SOrry CaKeSs, they are sakura trees

Michael Eh?
Member
Posts: 391
Joined: Sun Jan 01, 2012 17:21

by Michael Eh? » Post

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.

User avatar
Menche
Member
Posts: 1001
Joined: Sat Jul 02, 2011 00:43
IRC: Menchers
In-game: Menche
Location: An island in a lava lake.

by Menche » Post

Probably the recommended way to implement tree is with L-Systems in lua.
An innocent kitten dies every time you top-post.

Spots
Member
Posts: 124
Joined: Tue Jul 24, 2012 12:12
Location: Outta my mind someplace.

by Spots » Post

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

Michael Eh?
Member
Posts: 391
Joined: Sun Jan 01, 2012 17:21

by Michael Eh? » Post

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.

User avatar
Gambit
Member
Posts: 453
Joined: Sat Oct 29, 2011 19:31
Location: United States

by Gambit » Post

Rename it "sakura", it's more easier to go by since that's what they're called.
Current Projects: MineToon | PixelBOX
Gambit's Checkmate Server - 43.65.296.232 - port: 30001

Jordach
Member
Posts: 4534
Joined: Mon Oct 03, 2011 17:58
GitHub: Jordach
IRC: Jordach
In-game: Jordach
Location: Blender Scene

by Jordach » Post

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!

User avatar
VanessaE
Moderator
Posts: 4655
Joined: Sun Apr 01, 2012 12:38
GitHub: VanessaE
IRC: VanessaE
In-game: VanessaE
Location: Western NC
Contact:

by VanessaE » Post

If someone can come up with a nice L-Systems model and biome information for me, I'll add this to moretrees.
You might like some of my stuff: Plantlife ~ More Trees ~ Home Decor ~ Pipeworks ~ HDX Textures (64-512px)

User avatar
Mito551
Member
Posts: 1271
Joined: Sat Jun 16, 2012 15:03

by Mito551 » Post

Image

that?
Last edited by Mito551 on Tue Feb 12, 2013 17:31, edited 1 time in total.

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests