Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.chef.mod.generate.features;
- import java.util.Random;
- import com.chef.mod.init.MyBlocks;
- import net.minecraft.block.Block;
- import net.minecraft.block.state.IBlockState;
- import net.minecraft.init.Blocks;
- import net.minecraft.util.BlockPos;
- import net.minecraft.world.World;
- import net.minecraft.world.gen.feature.WorldGenAbstractTree;
- public class WorldGenMangoTree extends WorldGenAbstractTree {
- public WorldGenMangoTree() {
- super(false);
- }
- @Override
- public boolean generate(World worldIn, Random rand, BlockPos pos) {
- int x = pos.getX();
- int y = pos.getY();
- int z = pos.getZ();
- Block block = worldIn.getBlockState(pos).getBlock();
- while (worldIn.isAirBlock(pos) && y > 0) {
- y--;
- }
- if (block != Blocks.grass && block != Blocks.dirt) {
- return false;
- } else {
- for (int i = -2; i <= 2; i++) {
- for (int j = -2; j <= 2; j++) {
- if (worldIn.isAirBlock(new BlockPos(x + i, y - 1, z + j)) && worldIn.isAirBlock(new BlockPos(x + i, y - 2, z + j)) && !worldIn.isAirBlock(new BlockPos(x + i, y, z + j))) {
- return false;
- }
- }
- }
- int baseLength = 4 + rand.nextInt(6);
- int branches = 2 + rand.nextInt(4);
- int h = 0;
- block.onPlantGrow(worldIn, new BlockPos(x, y - 1, z), pos);
- for (int i = 0; i < baseLength; i++) {
- buildBlock(worldIn, new BlockPos(x, y + h, z), Blocks.log.getDefaultState(), 1);
- h++;
- }
- generateTop(worldIn, new BlockPos(x, y + h, z));
- return true;
- }
- }
- public void generateTop(World world, BlockPos pos) {
- int x = pos.getX();
- int y = pos.getY();
- int z = pos.getZ();
- //Top of the tree
- for (int i = -1; i < 2; i++)
- {
- for (int j = -1; j < 2; j++)
- {
- buildBlock(world, new BlockPos(x + i, y + 2, z + j), MyBlocks.mango_leaves.getDefaultState(), 1);
- }
- }
- //One beneath the top
- for (int i = -2; i < 3; i++)
- {
- for (int j = -1; j < 2; j++)
- {
- buildBlock(world, new BlockPos(x + i, y + 1, z + j), MyBlocks.mango_leaves.getDefaultState(), 1);
- buildBlock(world, new BlockPos(x + j, y + 1, z + i), MyBlocks.mango_leaves.getDefaultState(), 1);
- }
- }
- //Two beneath the top
- for (int i = -2; i < 3; i++) {
- for (int j = -2; j < 3; j++) {
- buildBlock(world, new BlockPos(x + i, y, z + j), MyBlocks.mango_leaves.getDefaultState(), 1);
- }
- }
- buildBlock(world, pos, Blocks.log.getDefaultState(), 1);
- buildBlock(world, new BlockPos(x, y + 1, z), Blocks.log.getDefaultState(), 1);
- }
- public void buildBlock(World world, BlockPos pos, IBlockState state, int meta) {
- if (world.isAirBlock(pos) || world.getBlockState(pos).getBlock().isLeaves(world, pos)) {
- world.setBlockState(pos, state.getBlock().getDefaultState(), meta);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement