2018-10-13 23:46:30 +02:00
|
|
|
package de.ellpeck.naturesaura.blocks;
|
|
|
|
|
|
|
|
import de.ellpeck.naturesaura.gen.WorldGenAncientTree;
|
|
|
|
import de.ellpeck.naturesaura.reg.IModItem;
|
|
|
|
import de.ellpeck.naturesaura.reg.IModelProvider;
|
|
|
|
import de.ellpeck.naturesaura.reg.ModRegistry;
|
2019-11-04 19:08:49 +01:00
|
|
|
import net.minecraft.block.*;
|
|
|
|
import net.minecraft.block.material.Material;
|
2018-10-13 23:46:30 +02:00
|
|
|
import net.minecraft.block.state.BlockStateContainer;
|
|
|
|
import net.minecraft.util.math.AxisAlignedBB;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.world.IBlockAccess;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.event.terraingen.TerrainGen;
|
|
|
|
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
|
|
|
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
|
|
|
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
|
|
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
2019-11-04 19:08:49 +01:00
|
|
|
// Make this extend SaplingBlock?
|
|
|
|
public class BlockAncientSapling extends BushBlock implements IGrowable, IModItem, IModelProvider {
|
2018-10-13 23:46:30 +02:00
|
|
|
|
|
|
|
private static final AxisAlignedBB AABB = new AxisAlignedBB(
|
|
|
|
0.09999999403953552D, 0.0D, 0.09999999403953552D,
|
|
|
|
0.8999999761581421D, 0.800000011920929D, 0.8999999761581421D);
|
|
|
|
|
|
|
|
public BlockAncientSapling() {
|
2019-11-04 19:08:49 +01:00
|
|
|
super(ModBlocks.prop(Material.PLANTS).hardnessAndResistance(0.0F).sound(SoundType.PLANT));
|
2018-11-29 17:58:47 +01:00
|
|
|
ModRegistry.add(this);
|
2018-10-13 23:46:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public AxisAlignedBB getBoundingBox(BlockState state, IBlockAccess source, BlockPos pos) {
|
2018-10-13 23:46:30 +02:00
|
|
|
return AABB;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public void updateTick(World world, BlockPos pos, BlockState state, Random rand) {
|
2018-10-13 23:46:30 +02:00
|
|
|
if (!world.isRemote) {
|
|
|
|
super.updateTick(world, pos, state, rand);
|
|
|
|
|
|
|
|
if (world.getLightFromNeighbors(pos.up()) >= 9 && rand.nextInt(7) == 0) {
|
|
|
|
this.grow(world, rand, pos, state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getBaseName() {
|
|
|
|
return "ancient_sapling";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public BlockState getStateFromMeta(int meta) {
|
|
|
|
return this.getDefaultState().withProperty(SaplingBlock.STAGE, meta);
|
2018-10-13 23:46:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public int getMetaFromState(BlockState state) {
|
|
|
|
return state.getValue(SaplingBlock.STAGE);
|
2018-10-13 23:46:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected BlockStateContainer createBlockState() {
|
2019-10-20 22:30:49 +02:00
|
|
|
return new BlockStateContainer(this, SaplingBlock.STAGE);
|
2018-10-13 23:46:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public boolean canGrow(World world, BlockPos pos, BlockState state, boolean isClient) {
|
2018-10-13 23:46:30 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public boolean canUseBonemeal(World world, Random rand, BlockPos pos, BlockState state) {
|
2018-10-13 23:46:30 +02:00
|
|
|
return world.rand.nextFloat() < 0.45F;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public void grow(World world, Random rand, BlockPos pos, BlockState state) {
|
|
|
|
if (state.getValue(SaplingBlock.STAGE) == 0) {
|
|
|
|
world.setBlockState(pos, state.cycleProperty(SaplingBlock.STAGE), 4);
|
2018-10-13 23:46:30 +02:00
|
|
|
} else if (TerrainGen.saplingGrowTree(world, rand, pos)) {
|
|
|
|
new WorldGenAncientTree(true).generate(world, rand, pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|