2018-10-13 23:46:30 +02:00
|
|
|
package de.ellpeck.naturesaura.blocks;
|
|
|
|
|
2020-01-29 00:40:28 +01:00
|
|
|
import de.ellpeck.naturesaura.data.BlockStateGenerator;
|
|
|
|
import de.ellpeck.naturesaura.data.ItemModelGenerator;
|
2020-02-25 15:14:56 +01:00
|
|
|
import de.ellpeck.naturesaura.gen.ModFeatures;
|
2020-01-29 01:34:58 +01:00
|
|
|
import de.ellpeck.naturesaura.reg.*;
|
|
|
|
import net.minecraft.client.renderer.RenderType;
|
2021-12-15 14:26:42 +01:00
|
|
|
import net.minecraft.core.BlockPos;
|
|
|
|
import net.minecraft.server.level.ServerLevel;
|
|
|
|
import net.minecraft.world.level.BlockGetter;
|
|
|
|
import net.minecraft.world.level.Level;
|
|
|
|
import net.minecraft.world.level.block.*;
|
|
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
|
|
import net.minecraft.world.level.block.state.StateDefinition;
|
|
|
|
import net.minecraft.world.level.material.Material;
|
|
|
|
import net.minecraft.world.phys.shapes.CollisionContext;
|
|
|
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
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;
|
2020-01-29 01:34:58 +01:00
|
|
|
import java.util.function.Supplier;
|
2018-10-13 23:46:30 +02:00
|
|
|
|
2021-12-15 14:26:42 +01:00
|
|
|
public class BlockAncientSapling extends BushBlock implements BonemealableBlock, IModItem, ICustomBlockState, ICustomItemModel, ICustomRenderType {
|
|
|
|
|
|
|
|
protected static final VoxelShape SHAPE = box(2.0D, 0.0D, 2.0D, 14.0D, 12.0D, 14.0D);
|
2018-10-13 23:46:30 +02:00
|
|
|
|
|
|
|
public BlockAncientSapling() {
|
2021-12-15 14:26:42 +01:00
|
|
|
super(Properties.of(Material.GRASS).strength(0.0F).sound(SoundType.GRASS));
|
2018-11-29 17:58:47 +01:00
|
|
|
ModRegistry.add(this);
|
2018-10-13 23:46:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-12-15 14:26:42 +01:00
|
|
|
public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, CollisionContext context) {
|
2020-01-21 21:04:44 +01:00
|
|
|
return SHAPE;
|
2018-10-13 23:46:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-12-04 15:40:09 +01:00
|
|
|
public void randomTick(BlockState state, ServerLevel level, BlockPos pos, Random random) {
|
|
|
|
if (!level.isClientSide) {
|
|
|
|
super.randomTick(state, level, pos, random);
|
2018-10-13 23:46:30 +02:00
|
|
|
|
2021-12-15 14:26:42 +01:00
|
|
|
if (level.getLightEmission(pos.above()) >= 9 && random.nextInt(7) == 0)
|
|
|
|
this.performBonemeal(level, random, pos, state);
|
2018-10-13 23:46:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getBaseName() {
|
|
|
|
return "ancient_sapling";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-12-15 14:26:42 +01:00
|
|
|
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
2020-01-21 21:04:44 +01:00
|
|
|
builder.add(SaplingBlock.STAGE);
|
2018-10-13 23:46:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-12-15 14:26:42 +01:00
|
|
|
public boolean isValidBonemealTarget(BlockGetter p_50897_, BlockPos p_50898_, BlockState p_50899_, boolean p_50900_) {
|
2018-10-13 23:46:30 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-12-15 14:26:42 +01:00
|
|
|
public boolean isBonemealSuccess(Level level, Random rand, BlockPos pos, BlockState state) {
|
|
|
|
return level.random.nextFloat() < 0.45F;
|
2018-10-13 23:46:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-12-15 14:26:42 +01:00
|
|
|
public void performBonemeal(ServerLevel level, Random rand, BlockPos pos, BlockState state) {
|
|
|
|
if (state.getValue(SaplingBlock.STAGE) == 0) {
|
|
|
|
level.setBlock(pos, state.cycle(SaplingBlock.STAGE), 4);
|
2021-12-04 15:40:09 +01:00
|
|
|
} else if (ForgeEventFactory.saplingGrowTree(level, rand, pos)) {
|
2021-12-15 14:26:42 +01:00
|
|
|
ModFeatures.Configured.ANCIENT_TREE.place(level, level.getChunkSource().getGenerator(), rand, pos);
|
2018-10-13 23:46:30 +02:00
|
|
|
}
|
|
|
|
}
|
2020-01-29 00:40:28 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void generateCustomBlockState(BlockStateGenerator generator) {
|
|
|
|
generator.simpleBlock(this, generator.models().cross(this.getBaseName(), generator.modLoc("block/" + this.getBaseName())));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void generateCustomItemModel(ItemModelGenerator generator) {
|
|
|
|
generator.withExistingParent(this.getBaseName(), "item/generated").texture("layer0", "block/" + this.getBaseName());
|
|
|
|
}
|
2020-01-29 01:34:58 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Supplier<RenderType> getRenderType() {
|
2021-12-15 14:26:42 +01:00
|
|
|
return RenderType::cutoutMipped;
|
2020-01-29 01:34:58 +01:00
|
|
|
}
|
2018-10-13 23:46:30 +02:00
|
|
|
}
|