Jump to content

Recommended Posts

Posted (edited)

Hi all, I want to remaster trees in Minecraft to generate a world with trees that have a custom pattern. So I watched videos about it and I tried to reproduce the tree with already existing blocks (oak log, sapling, etc...). In the video the guy plants a tree and he has the wanted pattern but it doesn't work with mine. Can you help me (I'll remake the pattern later I just want to see how it works) ? Thank you and sorry for my english
 

package com.laurentoutang.hardmod.world.gen.feature;

import java.util.Random;

import net.minecraft.block.BlockLeaves;
import net.minecraft.block.BlockLog;
import net.minecraft.block.BlockOldLeaf;
import net.minecraft.block.BlockOldLog;
import net.minecraft.block.BlockPlanks;
import net.minecraft.block.BlockPlanks.EnumType;
import net.minecraft.block.BlockSapling;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.IChunkGenerator;
import net.minecraft.world.gen.feature.WorldGenAbstractTree;
import net.minecraftforge.common.IPlantable;
import net.minecraftforge.event.terraingen.DecorateBiomeEvent;
import net.minecraftforge.fml.common.IWorldGenerator;

public class WorldGenRemasteredOak extends WorldGenAbstractTree
{
	public static IBlockState LOG = Blocks.LOG.getDefaultState().withProperty(BlockOldLog.VARIANT, BlockPlanks.EnumType.OAK);
	public static IBlockState LEAF = Blocks.LEAVES.getDefaultState().withProperty(BlockOldLeaf.VARIANT, BlockPlanks.EnumType.OAK).withProperty(BlockLeaves.CHECK_DECAY, Boolean.valueOf(false));
	
	private int minHeight;
	private int varHeight;
	
	
	public WorldGenRemasteredOak(boolean notify) {
		super(false);
		minHeight = 12;
		varHeight = 3;
	}

	@Override
	public boolean generate(World worldIn, Random rand, BlockPos position) {
		
		int height = this.minHeight + rand.nextInt(varHeight);
		
		boolean flag = true;
		
		int x = position.getX();
		int y = position.getY();
		int z = position.getZ();
		
		for(int yPos = y; yPos <= y + 1 + height; yPos++)
		{
			int b0 = 2;
			if(yPos == y)
			{
				b0 = 1;
			}
			if(yPos >= y + 1 + height - 2)
			{
				b0 = 2;
			}
			BlockPos.MutableBlockPos mutable = new BlockPos.MutableBlockPos();
			
			for(int xPos = x - b0; xPos <= x + b0 && flag; xPos++)
			{
				for(int zPos = z - b0; zPos <= z + b0 && flag; zPos++)
				{
					if(yPos >= 0 && yPos < worldIn.getHeight())
					{
						if(!this.isReplaceable(worldIn, new BlockPos(xPos, yPos, zPos)))
						{
							flag = false;
						}						
					}
					else
					{
						flag = false;
					}
				}
			}
		}
		if(!flag)
		{
			return false;
		}
		else
		{
			BlockPos down = position.down();
			IBlockState state = worldIn.getBlockState(down);
			boolean isSoil = state.getBlock().canSustainPlant(state, worldIn, down, EnumFacing.UP, (BlockSapling)Blocks.SAPLING);
			if(isSoil && y < worldIn.getHeight() - height -1)
			{
				state.getBlock().onPlantGrow(state, worldIn, down, position);
				
				for(int yPos = y -3 + height; yPos <= y + height; yPos++)
				{
					int b1 = yPos - (y + height);
					int b2 = 1 - b1 /2;
					
					for(int xPos = x - b2; xPos <= x + b2; xPos++)
					{
						int b3 = xPos -x;
						for(int zPos = z - b2; zPos <= z + b2; zPos++)
						{
							int b4 = zPos-z;
							if(Math.abs(b3) != b2 || Math.abs(b4) != b2 || rand.nextInt(2) != 0 && b1 != 0)
							{
								BlockPos treePos = new BlockPos(xPos, yPos, zPos);
								IBlockState treeState = worldIn.getBlockState(treePos);
								if(treeState.getBlock().isAir(treeState, worldIn, position) || treeState.getBlock().isLeaves(treeState, worldIn, position))
								{
									this.setBlockAndNotifyAdequately(worldIn, treePos, LEAF);
									this.setBlockAndNotifyAdequately(worldIn, treePos.add(0,-0.25 * height, 0), LEAF);
									this.setBlockAndNotifyAdequately(worldIn, treePos.add(0,-0.5 * height, 0), LEAF);
								}
							}
						}
					}
				}
				for(int logHeight = 0; logHeight < height; logHeight++)
				{
					BlockPos up = position.up(logHeight);
					IBlockState logState = worldIn.getBlockState(up);
					if(logState.getBlock().isAir(logState, worldIn, position) || logState.getBlock().isLeaves(logState, worldIn, position))
					{ 
						this.setBlockAndNotifyAdequately(worldIn, position.up(logHeight), LOG);
					}
				}
				return true;
			}
		}
		return true;
	}
	
	

}
	

I'll see with the world generation later

Edited by LaurentOutang
Posted

I have a tutorial on custom trees here: http://jabelarminecraft.blogspot.com/p/minecraft-modding-custom-tree-with.html

 

What exactly is going wrong for you? The "pattern" can be made in any logical way, ultimately it is just a matter of placing blocks. If you want it to be regular you can have some loops, and if you want it to have some randomness you can add that. But it is just placing blocks so all you have to do is think through the logic of what you want.

 

 

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted (edited)

A normal oak is growing when i put bone meal on sapling. I'm expecting to have a tree taller than 12 blocks and with a thiner aspect maybe like a maple

Edited by LaurentOutang
Posted

Working fine with your tutorial :) thank you. Do you know if there is a file format which I can use (and a software) to design my tree that allows me not to do a line of code for each block. For example if I want to do a complex giant tree that doesn't follow any simple rule. Thank you

Posted

Yes, just create an array that contains the block positions. You can do this a couple ways. Simplest is to just have an array or List of block pos and loop through them. The block pos can be relative to the trunk base and just add it. With just some graph paper you can easily just sketch it out.

 

Another array format would just have a 2d array of Boolean for each layer of the tree to indicate where the leaves are.

 

However don't be adverse to simply coding it block by block. There is no shame in using brute force. It doesn't take that long to write out with cut and paste, and you just have to invest 10 minutes to code it. It gives full control and is less likely to be buggy than trying to be tricky.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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



×
×
  • Create New...

Important Information

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