123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- package me.km.blocks.leaves;
- import java.util.Random;
- import net.minecraft.block.Block;
- import net.minecraft.block.material.Material;
- 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.gen.feature.WorldGenAbstractTree;
- public class WorldGenTree extends WorldGenAbstractTree
- {
- private final IBlockState log;
- private final IBlockState leaf;
- public WorldGenTree(boolean notify, IBlockState log, IBlockState leaf)
- {
- super(notify);
- this.log = log;
- this.leaf = leaf;
- }
-
- @Override
- protected boolean canGrowInto(Block blockType)
- {
- Material material = blockType.getDefaultState().getMaterial();
- return material == Material.AIR || material == Material.LEAVES ||
- blockType == Blocks.GRASS || blockType == Blocks.DIRT ||
- blockType == Blocks.LOG || blockType == Blocks.LOG2 ||
- blockType == Blocks.SAPLING || blockType == Blocks.VINE ||
- blockType instanceof BlockLeaves;
- }
- @Override
- public boolean generate(World worldIn, Random rand, BlockPos pos)
- {
- int i = rand.nextInt(3) + 5;
- boolean flag = true;
- if(pos.getY() >= 1 && pos.getY() + i + 1 <= 256)
- {
- for(int j = pos.getY(); j <= pos.getY() + 1 + i; j++)
- {
- int k = 1;
- if (j == pos.getY())
- {
- k = 0;
- }
- if (j >= pos.getY() + 1 + i - 2)
- {
- k = 2;
- }
- BlockPos.MutableBlockPos mPos = new BlockPos.MutableBlockPos();
- for(int x = pos.getX() - k; x <= pos.getX() + k && flag; x++)
- {
- for(int z = pos.getZ() - k; z <= pos.getZ() + k && flag; z++)
- {
- if(j >= 0 && j < worldIn.getHeight())
- {
- if(!this.isReplaceable(worldIn, mPos.setPos(x, j, z)))
- {
- flag = false;
- }
- }
- else
- {
- flag = false;
- }
- }
- }
- }
- if(!flag)
- {
- return false;
- }
- else
- {
- BlockPos down = pos.down();
- IBlockState state = worldIn.getBlockState(down);
- boolean isSoil = state.getBlock().canSustainPlant(state, worldIn, down, EnumFacing.UP, (net.minecraft.block.BlockSapling) Blocks.SAPLING);
- if(isSoil && pos.getY() < worldIn.getHeight() - i - 1)
- {
- state.getBlock().onPlantGrow(state, worldIn, down, pos);
- for(int y = pos.getY() - 3 + i; y <= pos.getY() + i; y++)
- {
- int k = y - (pos.getY() + i);
- int l = 1 - k / 2;
- for(int x = pos.getX() - l; x <= pos.getX() + l; x++)
- {
- int j = x - pos.getX();
- for(int z = pos.getZ() - l; z <= pos.getZ() + l; z++)
- {
- int m = z - pos.getZ();
- if(Math.abs(j) != l || Math.abs(m) != l || rand.nextInt(2) != 0 && k != 0)
- {
- BlockPos blockpos = new BlockPos(x, y, z);
- IBlockState state2 = worldIn.getBlockState(blockpos);
- if(state2.getBlock().isAir(state2, worldIn, blockpos) || state2.getBlock().isAir(state2, worldIn, blockpos))
- {
- this.setBlockAndNotifyAdequately(worldIn, blockpos, leaf);
- }
- }
- }
- }
- }
- for(int j = 0; j < i; j++)
- {
- BlockPos upN = pos.up(j);
- IBlockState state2 = worldIn.getBlockState(upN);
- if (state2.getBlock().isAir(state2, worldIn, upN) || state2.getBlock().isLeaves(state2, worldIn, upN))
- {
- this.setBlockAndNotifyAdequately(worldIn, pos.up(j), log);
- }
- }
- return true;
- }
- else
- {
- return false;
- }
- }
- }
- else
- {
- return false;
- }
- }
- }
|