Jump to content

[SOLVED][1.6.4] Problem with tree height from sapling block


Recommended Posts

Posted

Hi hello, I'm doing a mod and I have a small problem but I don't know how to fix it.

 

I did a new world generation with my own world generator and my owns worldgentree and treemanager.

The new generation is working great but the only problem that I have is when I cut a tree and I used the

sapling from the tree, the new tree is my own custom tree which is great but the problem is that the height

of the new tree is not the height that I want. I'm looking in the code of the sapling to see which parameter

is the parameter that control the height and I did a lot of tests but I can't find. I was looking for information

of the vanilla sapling block to understand all the parameters but I didn't see a lot of information so I decided

to open a post to see if someone can tell me which parameter control in my code the height of the tree.

 

I'm going to show here the code of my sapling that grow the new tree and the code of my worldgentree.

 

Sapling code to grow the new tree

 

 

/**

    * Attempts to grow a sapling into a tree

    */

    public void growTree(World par1World, int par2, int par3, int par4, Random par5Random)

    {

        if (!TerrainGen.saplingGrowTree(par1World, par5Random, par2, par3, par4)) return;

 

        int l = par1World.getBlockMetadata(par2, par3, par4) & 3;

        Object object = null;

        int i1 = 0;

        int j1 = 0;

        boolean flag = false;

 

        /*if (l == 1)

        {

            object = new WorldGenTaiga2(true);

        }

        else if (l == 2)

        {

            object = new WorldGenForest(true);

        }

        */

        //else if (l == 3)

        if (l == 3)

        {

            for (i1 = 0; i1 >= -1; --i1)

            {

                for (j1 = 0; j1 >= -1; --j1)

                {

                    if (this.isSameSapling(par1World, par2 + i1, par3, par4 + j1, 3) && this.isSameSapling(par1World, par2 + i1 + 1, par3, par4 + j1, 3) && this.isSameSapling(par1World, par2 + i1, par3, par4 + j1 + 1, 3) && this.isSameSapling(par1World, par2 + i1 + 1, par3, par4 + j1 + 1, 3))

                    {

                        //object = new WorldGenHugeTrees(true, 4 + par5Random.nextInt(20), 3, 3);

                    object = new WorldGenTree(true, 4 + par5Random.nextInt(20), 3, 3, true);

                        flag = true;

                        break;

                    }

                }

 

                if (object != null)

                {

                    break;

                }

            }

 

            if (object == null)

            {

                j1 = 0;

                i1 = 0;

                //object = new WorldGenTree(true, 4 + par5Random.nextInt(7), 3, 3, false);

                object = new WorldGenTree(true, 4  + par5Random.nextInt(7), 3, 3, true);

            }

        }

        else

        {

            object = new WorldGenTree(true);

 

            if (par5Random.nextInt(10) == 0)

            {

                object = new WorldGenTree(true);

            }

        }

 

        if (flag)

        {

        par1World.setBlock(par2 + i1, par3, par4 + j1, 0, 0, 4);

            par1World.setBlock(par2 + i1 + 1, par3, par4 + j1, 0, 0, 4);

            par1World.setBlock(par2 + i1, par3, par4 + j1 + 1, 0, 0, 4);

            par1World.setBlock(par2 + i1 + 1, par3, par4 + j1 + 1, 0, 0, 4);

        }

        else

        {

            par1World.setBlock(par2, par3, par4, 0, 0, 10);

        }

 

        if (!((WorldGenerator)object).generate(par1World, par5Random, par2 + i1, par3, par4 + j1))

        {

            if (flag)

            {

            par1World.setBlock(par2 + i1, par3, par4 + j1, this.blockID, l, 4);

                par1World.setBlock(par2 + i1 + 1, par3, par4 + j1, this.blockID, l, 4);

                par1World.setBlock(par2 + i1, par3, par4 + j1 + 1, this.blockID, l, 4);

                par1World.setBlock(par2 + i1 + 1, par3, par4 + j1 + 1, this.blockID, l, 4);

               

            }

            else

            {

                par1World.setBlock(par2, par3, par4, this.blockID, l, 4);

            }

        }

    }

 

 

 

 

My WorldGenTree

 

 

package JavaBuckets.Modium.Main;

 

import java.util.Random;

 

import net.minecraft.block.Block;

import net.minecraft.block.BlockSapling;

import net.minecraft.world.World;

import net.minecraft.world.gen.feature.WorldGenerator;

import net.minecraftforge.common.ForgeDirection;

 

public class WorldGenTree extends WorldGenerator

{

/** The minimum height of a generated tree. */

private final int minTreeHeight;

/** True if this tree should grow Vines. */

private final boolean vinesGrow;

/** The metadata value of the wood to use in tree generation. */

private final int metaWood;

/** The metadata value of the leaves to use in tree generation. */

private final int metaLeaves;

public WorldGenTree(boolean par1)

{

        this(par1, 4, 0, 0, false);

}

public WorldGenTree(boolean par1, int par2, int par3, int par4, boolean par5)

{

        super(par1);

        this.minTreeHeight = par2;

        this.metaWood = par3;

        this.metaLeaves = par4;

        this.vinesGrow = par5;

}

public boolean generate(World par1World, Random par2Random, int par3, int par4, int par5)

{

        int l = par2Random.nextInt(3) + this.minTreeHeight;

        boolean flag = true;

        if (par4 >= 1 && par4 + l + 1 <= 256)

        {

                int i1;

                byte b0;

                int j1;

                int k1;

                for (i1 = par4; i1 <= par4 + 1 + l; ++i1)

                {

                        b0 = 1;

                        if (i1 == par4)

                        {

                                b0 = 0;

                        }

                        if (i1 >= par4 + 1 + l - 2)

                        {

                                b0 = 2;

                        }

                        for (int l1 = par3 - b0; l1 <= par3 + b0 && flag; ++l1)

                        {

                                for (j1 = par5 - b0; j1 <= par5 + b0 && flag; ++j1)

                                {

                                        if (i1 >= 0 && i1 < 256)

                                        {

                                                k1 = par1World.getBlockId(l1, i1, j1);

                                                Block block = Block.blocksList[k1];

                                                boolean isAir = par1World.isAirBlock(l1, i1, j1);

                                                if (!isAir &&

                                                        !block.isLeaves(par1World, l1, i1, j1) &&

                                                        k1 != MainClass.TeRGrass.blockID && //What blocks the tree will generate on

                                                        k1 != MainClass.ModiumBlock.blockID &&

                                                        !block.isWood(par1World, l1, i1, j1))

                                                     

                                                {

                                                        flag = false;

                                                }

                                        }

                                        else

                                        {

                                                flag = false;

                                        }

                                }

                        }

                }

                if (!flag)

                {

                        return false;

                }

                else

                {

                        i1 = par1World.getBlockId(par3, par4 - 1, par5);

                        Block soil = Block.blocksList[i1];

                        boolean isSoil = (soil != null && soil.canSustainPlant(par1World, par3, par4 - 1, par5, ForgeDirection.UP, (BlockSapling)Block.sapling));

                        if (isSoil && par4 < 256 - l - 1)

                        {

                                soil.onPlantGrow(par1World, par3, par4 - 1, par5, par3, par4, par5);

                                b0 = 3;

                                byte b1 = 0;

                                int i2;

                                int j2;

                                int k2;

                                for (j1 = par4 - b0 + l; j1 <= par4 + l; ++j1)

                                {

                                        k1 = j1 - (par4 + l);

                                        i2 = b1 + 1 - k1 / 2;

                                        for (j2 = par3 - i2; j2 <= par3 + i2; ++j2)

                                        {

                                                k2 = j2 - par3;

                                                for (int l2 = par5 - i2; l2 <= par5 + i2; ++l2)

                                                {

                                                        int i3 = l2 - par5;

                                                        if (Math.abs(k2) != i2 || Math.abs(i3) != i2 || par2Random.nextInt(2) != 0 && k1 != 0)

                                                        {

                                                                int j3 = par1World.getBlockId(j2, j1, l2);

                                                                Block block = Block.blocksList[j3];

                                                                if (block == null || block.canBeReplacedByLeaves(par1World, j2, j1, l2))

                                                                {

                                                                        this.setBlockAndMetadata(par1World, j2, j1, l2, MainClass.TeRTreeLeavesForest.blockID, this.metaLeaves);

                                                                }

                                                        }

                                                }

                                        }

                                }

                                for (j1 = 0; j1 < l; ++j1)

                                {

                                        k1 = par1World.getBlockId(par3, par4 + j1, par5);

                                        Block block = Block.blocksList[k1];

                                        if (k1 == 0 || block == null || block.isLeaves(par1World, par3, par4 + j1, par5))

                                        {

                                                this.setBlockAndMetadata(par1World, par3, par4 + j1, par5, MainClass.TeRTreeWoodForest.blockID, this.metaWood);

                                        }

                                }

                                return true;

                        }

                        else

                        {

                                return false;

                        }

                }

        }

        else

        {

                return false;

        }

}

}

 

 

 

Thanks.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hi,  I'm using Forge 47.3.0 for Minecraft 1.20.1 I apologise if this is obvious I am very new to modding for Minecraft. I sucessfully made a mod that launched without errors or crashes (without it doing anything) but in order to add the features I need, I need to add "Custom Portal API [Forge]" as a dependency. However no matter the way I've tried to acheive this, it crashes. I am pretty sure it's not the way I'm putting it in the repositories, the dependencies or the way I'm refrencing it, as I've a hundred diffrent combinations and multiple Maven methods. And on all those diffrent variations I still get this crash: pastebin.com/UhumzZCZ Any tips would be invaluable as I've been loosing my mind over this!
    • Hi, i'm really having problems trying to set the texture to my custom item. I thought i'm doing everything correctly, but all i see is the missing texture block for my item. I am trying this for over a week now and getting really frustrated. The only time i could make the texture work, was when i used an older Forge version (52.0.1) for Minecraft (1.21.4). Was there a fundamental change for textures and models somewhere between versions that i'm missing? I started with Forge 54.1.0 and had this problem, so in my frustration i tried many things: Upgrading to Forge 54.1.1, created multiple new projects, workspaces, redownloaded everything and setting things up multiple times, as it was suggested in an older thread. Therea are no errors in the console logs, but maybe i'm blind, so i pasted the console logs to pastebin anyway: https://pastebin.com/zAM8RiUN The only time i see an error is when i change the models JSON file to an incorrect JSON which makes sense and that suggests to me it is actually reading the JSON file.   I set the github repository to public, i would be so thankful if anyone could take a look and tell me what i did wrong: https://github.com/xLorkin/teleport_pug_forge   As a note: i'm pretty new to modding, this is my first mod ever. But i'm used to programming. I had some up and downs, but through reading the documentation, using google and experimenting, i could solve all other problems. I only started modding for Minecraft because my son is such a big fan and wanted this mod.
    • Please read the FAQ (link in orange bar at top of page), and post logs as described there.
    • Hello fellow Minecrafters! I recently returned to Minecraft and realized I needed a wiki that displays basic information easily and had great user navigation. That’s why I decided to build: MinecraftSearch — a site by a Minecraft fan, for Minecraft fans. Key Features So Far Straight-to-the-Point Info: No extra fluff; just the essentials on items, mobs, recipes, loot and more. Clean & Intuitive Layout: Easy navigation so you spend less time scrolling and more time playing. Optimized Search: Search for anything—items, mobs, blocks—and get results instantly. What I’m Thinking of Adding More data/information: Catch chances for fishing rod, traveling villager trades, biomes info and a lot more. The website is still under development and need a lot more data added. Community Contributions: Potential for user-uploaded tips for items/mobs/blocks in the future. Feature Requests Welcome: Your ideas could shape how the wiki evolves! You can see my roadmap at the About page https://minecraftsearch.com/about I’d love for you to check out MinecraftSearch and see if it helps you find the info you need faster. Feedback is crucial—I want to develop this further based on what the community needs most, so please let me know what you think. Thanks, and happy crafting!
    • Instructions on how to install newer Java can be found in the FAQ
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.