Jump to content

Generate Trees with Items


NoobminecraftModder
 Share

Recommended Posts

answer two questions and I promise you will have your solution.

 

1. How do you generate trees when the generator has decided where, how does it create a tree at location x,y,z ?

 

2. How do you do something when an item is used? :)

If you guys dont get it.. then well ya.. try harder...

Link to comment
Share on other sites

Ok...

 

1. The trees were generated in my generator file.



	//RubberTree Generierung
	for(int i = 0; i < 3; i++){
		int randPosX = chunkX + rand.nextInt(16);
		int randPosY = rand.nextInt(90);
		int randPosZ  = chunkZ + rand.nextInt(16);

		(new WorldGenRubberTree(false, 6, 0, 0, false)).generate(world, rand, randPosX, randPosY, randPosZ);

	}

 

 

2. I don't know eactly what you mean^^

But I think so:

public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World,EntityPlayer par3EntityPlayer) {//Do something}

Link to comment
Share on other sites

2. Correct!

 

1. Almost, this is where it decides where to generate it, the WorldGenRubberTree.generate() is where it acctually creates the tree.

Take a look into that method and see if you can find how it's working and where it acctually genereates the tree?

 

 

If you guys dont get it.. then well ya.. try harder...

Link to comment
Share on other sites

hmm... I think I've found the solution.

 

    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];

                            if (k1 != 0 &&
                               !block.isLeaves(par1World, l1, i1, j1) &&
                                k1 != Block.grass.blockID &&
                                k1 != Block.dirt.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, copper.rubberTreeLeaf.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, copper.rubberTreeLog.blockID, this.metaWood);

                            if (this.vinesGrow && j1 > 0)
                            {
                                if (par2Random.nextInt(3) > 0 && par1World.isAirBlock(par3 - 1, par4 + j1, par5))
                                {
                                    this.setBlockAndMetadata(par1World, par3 - 1, par4 + j1, par5, Block.vine.blockID, ;
                                }

                                if (par2Random.nextInt(3) > 0 && par1World.isAirBlock(par3 + 1, par4 + j1, par5))
                                {
                                    this.setBlockAndMetadata(par1World, par3 + 1, par4 + j1, par5, Block.vine.blockID, 2);
                                }

                                if (par2Random.nextInt(3) > 0 && par1World.isAirBlock(par3, par4 + j1, par5 - 1))
                                {
                                    this.setBlockAndMetadata(par1World, par3, par4 + j1, par5 - 1, Block.vine.blockID, 1);
                                }

                                if (par2Random.nextInt(3) > 0 && par1World.isAirBlock(par3, par4 + j1, par5 + 1))
                                {
                                    this.setBlockAndMetadata(par1World, par3, par4 + j1, par5 + 1, Block.vine.blockID, 4);
                                }
                            }
                        }
                    }

                    if (this.vinesGrow)
                    {
                        for (j1 = par4 - 3 + l; j1 <= par4 + l; ++j1)
                        {
                            k1 = j1 - (par4 + l);
                            i2 = 2 - k1 / 2;

                            for (j2 = par3 - i2; j2 <= par3 + i2; ++j2)
                            {
                                for (k2 = par5 - i2; k2 <= par5 + i2; ++k2)
                                {
                                    Block block = Block.blocksList[par1World.getBlockId(j2, j1, k2)];
                                    if (block != null && block.isLeaves(par1World, j2, j1, k2))
                                    {
                                        if (par2Random.nextInt(4) == 0 && par1World.getBlockId(j2 - 1, j1, k2) == 0)
                                        {
                                            this.growVines(par1World, j2 - 1, j1, k2, ;
                                        }

                                        if (par2Random.nextInt(4) == 0 && par1World.getBlockId(j2 + 1, j1, k2) == 0)
                                        {
                                            this.growVines(par1World, j2 + 1, j1, k2, 2);
                                        }

                                        if (par2Random.nextInt(4) == 0 && par1World.getBlockId(j2, j1, k2 - 1) == 0)
                                        {
                                            this.growVines(par1World, j2, j1, k2 - 1, 1);
                                        }

                                        if (par2Random.nextInt(4) == 0 && par1World.getBlockId(j2, j1, k2 + 1) == 0)
                                        {
                                            this.growVines(par1World, j2, j1, k2 + 1, 4);
                                        }
                                    }
                                }
                            }
                        }

                        if (par2Random.nextInt(5) == 0 && l > 5)
                        {
                            for (j1 = 0; j1 < 2; ++j1)
                            {
                                for (k1 = 0; k1 < 4; ++k1)
                                {
                                    if (par2Random.nextInt(4 - j1) == 0)
                                    {
                                        i2 = par2Random.nextInt(3);
                                        this.setBlockAndMetadata(par1World, par3 + Direction.offsetX[Direction.rotateOpposite[k1]], par4 + l - 5 + j1, par5 + Direction.offsetZ[Direction.rotateOpposite[k1]], Block.cocoaPlant.blockID, i2 << 2 | k1);
                                    }
                                }
                            }
                        }
                    }

                    return true;
                }
                else
                {
                    return false;
                }
            }
        }
        else
        {
            return false;
        }
    }

Link to comment
Share on other sites

combine that into the onItemRightClick should do the trick yeah.

But I would like for you to look into it and understand how it makes the tree, it's really simple once you look past the cryptic and bad names :)

 

 

Also you could make it quite simple:

onItemRightClick(ItemStack item, World world,EntityPlayer player) {
MovingObjectPosition mop = player.rayTrace(10, 1.0F);  // This is the block or entity the player is looking at.
if (mop.typeOfHit == EnumMovingObjectType.TILE)  // If he targets a tile.
{ // Do the generate method on that tile:
             (new WorldGenRubberTree(false, 6, 0, 0, false)).generate(world, world.rand, mop.blockX, mop.blockY, mop.blockZ);   		
}
}

 

This should work, I think :P

I'm writing it from memory, normaly I would ask you to figure the rest yourself after telling you to combine the two codes.

But the "onItemRightClick" method didnt say which block you where aiming at so it involved rayTracing which I thought would be better to show you than to hint at :)

 

Hope it works and helps, and if it doesnt it should give you a huge clue to how you can solve it ;)

If you guys dont get it.. then well ya.. try harder...

Link to comment
Share on other sites

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

 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • This is my first time making a pack and i just wanted to add mods that i know or that look interesting. So When making the pack i get this error with Refined Storage https://pastebin.com/DxtTbVZW
    • Hello! When I'm trying to get items by tag during the recipe serialization, I'm getting an empty list. I have a guess that item tags're not loaded by the time minecraft loads my recipes. Here's my code: Class that saves information about ingredient's count Recipe serializer with some aux methods: Registry: Example of the json recipe file:  
    • I tried to install client forge on my linux desktop. But after "installation" it's missing forge[version].jar file in .minecraft/versions. I tried java 11 and 8 environment with same result. Here link to log file from installation: https://drive.google.com/file/d/1vtg9NT-WX5ilb1aNUvZlOv54gKWJuaT1/view?usp=share_link. I don't know what to do. I give for every directory permissions that I don't think that is issue. I will try check older versions if universal file work. Debian 11 (kernel 5.10)
    • I recently got error 1 in the launcher, so I restarted the .minecraft. After restarting it, I can't get the Forge 1.19.2 - 43.1.1 installer to run, I tried other versions and I get the same result, it opens a black box that closes instantly and nothing happens. I already tried to restart my pc, minecraft, update and reinstall java, run vanilla 1.19.2 and more recent versions of the game, disable Windows Firewall and antivirus and I still haven't solved it. Many times I installed forge and never ran into this problem. If I could receive assistance I would be very grateful.  
    • Here's the default loot table for gravel block: { "type": "minecraft:block", "pools": [ { "rolls": 1.0, "bonus_rolls": 0.0, "entries": [ { "type": "minecraft:alternatives", "children": [ { "type": "minecraft:item", "conditions": [ { "condition": "minecraft:match_tool", "predicate": { "enchantments": [ { "enchantment": "minecraft:silk_touch", "levels": { "min": 1 } } ] } } ], "name": "minecraft:gravel" }, { "type": "minecraft:alternatives", "conditions": [ { "condition": "minecraft:survives_explosion" } ], "children": [ { "type": "minecraft:item", "conditions": [ { "condition": "minecraft:table_bonus", "enchantment": "minecraft:fortune", "chances": [ 0.1, 0.14285715, 0.25, 1.0 ] } ], "name": "minecraft:flint" }, { "type": "minecraft:item", "name": "minecraft:gravel" } ] } ] } ] } ] } This is a finicky loot table. If I add anything to it, nothing drops. I've added pools, entries, children ... you name it. Does anyone know the particulars about this table? I mean, periodically gravel drops flint instead of a gravel block. I understand the condition that could drop flint if the block survives an explosion. Otherwise, it drops the gravel block itself. I would like to further understand why the use of `children` and the set of `chance` values given in the explosion child entry. What I do understand is that `"type" : "minecraft:alternatives"` means that if this child/entry is successful, then it stops generating loot for this entry/pool. How often does the flint drop and is that taken care of in another location? Is that in a `"condition" : "minecraft:table_bonus"` loot table? Hmmm... I'll have to go take a look and see if there is something called table_bonus.json.
  • Topics

×
×
  • Create New...

Important Information

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