NaturesAura/src/main/java/de/ellpeck/naturesaura/blocks/BlockAncientSapling.java

71 lines
2.4 KiB
Java
Raw Normal View History

2018-10-13 23:46:30 +02:00
package de.ellpeck.naturesaura.blocks;
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;
2020-01-21 21:04:44 +01:00
import net.minecraft.state.StateContainer;
2018-10-13 23:46:30 +02:00
import net.minecraft.util.math.BlockPos;
2020-01-21 21:04:44 +01:00
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.world.IBlockReader;
2018-10-13 23:46:30 +02:00
import net.minecraft.world.World;
2020-01-21 21:04:44 +01:00
import net.minecraftforge.event.ForgeEventFactory;
2018-10-13 23:46:30 +02:00
import java.util.Random;
2019-11-04 19:08:49 +01:00
public class BlockAncientSapling extends BushBlock implements IGrowable, IModItem, IModelProvider {
2020-01-21 21:04:44 +01:00
protected static final VoxelShape SHAPE = Block.makeCuboidShape(2.0D, 0.0D, 2.0D, 14.0D, 12.0D, 14.0D);
2018-10-13 23:46:30 +02:00
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
2020-01-21 21:04:44 +01:00
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
return SHAPE;
2018-10-13 23:46:30 +02:00
}
@Override
2020-01-21 21:04:44 +01:00
public void randomTick(BlockState state, World world, BlockPos pos, Random random) {
2018-10-13 23:46:30 +02:00
if (!world.isRemote) {
2020-01-21 21:04:44 +01:00
super.randomTick(state, world, pos, random);
2018-10-13 23:46:30 +02:00
2020-01-21 21:04:44 +01:00
if (world.getLight(pos.up()) >= 9 && random.nextInt(7) == 0) {
this.grow(world, random, pos, state);
2018-10-13 23:46:30 +02:00
}
}
}
@Override
public String getBaseName() {
return "ancient_sapling";
}
@Override
2020-01-21 21:04:44 +01:00
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
builder.add(SaplingBlock.STAGE);
2018-10-13 23:46:30 +02:00
}
@Override
2020-01-21 21:04:44 +01:00
public boolean canGrow(IBlockReader worldIn, 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) {
2020-01-21 21:04:44 +01:00
if (state.get(SaplingBlock.STAGE) == 0) {
world.setBlockState(pos, state.cycle(SaplingBlock.STAGE), 4);
} else if (ForgeEventFactory.saplingGrowTree(world, rand, pos)) {
2020-01-21 23:02:39 +01:00
// TODO generate tree
//new WorldGenAncientTree(true).generate(world, rand, pos);
2018-10-13 23:46:30 +02:00
}
}
}