93 lines
3.6 KiB
Java
93 lines
3.6 KiB
Java
/*
|
|
* Decompiled with CFR 0.152.
|
|
*
|
|
* Could not load the following classes:
|
|
* com.mojang.datafixers.kinds.App
|
|
* com.mojang.datafixers.kinds.Applicative
|
|
* com.mojang.serialization.MapCodec
|
|
* com.mojang.serialization.codecs.RecordCodecBuilder
|
|
*/
|
|
package net.minecraft.world.level.block;
|
|
|
|
import com.mojang.datafixers.kinds.App;
|
|
import com.mojang.datafixers.kinds.Applicative;
|
|
import com.mojang.serialization.MapCodec;
|
|
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.server.level.ServerLevel;
|
|
import net.minecraft.util.RandomSource;
|
|
import net.minecraft.world.level.BlockGetter;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.level.LevelReader;
|
|
import net.minecraft.world.level.block.Block;
|
|
import net.minecraft.world.level.block.BonemealableBlock;
|
|
import net.minecraft.world.level.block.VegetationBlock;
|
|
import net.minecraft.world.level.block.grower.TreeGrower;
|
|
import net.minecraft.world.level.block.state.BlockBehaviour;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraft.world.level.block.state.StateDefinition;
|
|
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
|
import net.minecraft.world.level.block.state.properties.IntegerProperty;
|
|
import net.minecraft.world.phys.shapes.CollisionContext;
|
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
|
|
|
public class SaplingBlock
|
|
extends VegetationBlock
|
|
implements BonemealableBlock {
|
|
public static final MapCodec<SaplingBlock> CODEC = RecordCodecBuilder.mapCodec(i -> i.group((App)TreeGrower.CODEC.fieldOf("tree").forGetter(b -> b.treeGrower), SaplingBlock.propertiesCodec()).apply((Applicative)i, SaplingBlock::new));
|
|
public static final IntegerProperty STAGE = BlockStateProperties.STAGE;
|
|
private static final VoxelShape SHAPE = Block.column(12.0, 0.0, 12.0);
|
|
protected final TreeGrower treeGrower;
|
|
|
|
public MapCodec<? extends SaplingBlock> codec() {
|
|
return CODEC;
|
|
}
|
|
|
|
protected SaplingBlock(TreeGrower treeGrower, BlockBehaviour.Properties properties) {
|
|
super(properties);
|
|
this.treeGrower = treeGrower;
|
|
this.registerDefaultState((BlockState)((BlockState)this.stateDefinition.any()).setValue(STAGE, 0));
|
|
}
|
|
|
|
@Override
|
|
protected VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
|
|
return SHAPE;
|
|
}
|
|
|
|
@Override
|
|
protected void randomTick(BlockState state, ServerLevel level, BlockPos pos, RandomSource random) {
|
|
if (level.getMaxLocalRawBrightness(pos.above()) >= 9 && random.nextInt(7) == 0) {
|
|
this.advanceTree(level, pos, state, random);
|
|
}
|
|
}
|
|
|
|
public void advanceTree(ServerLevel level, BlockPos pos, BlockState state, RandomSource random) {
|
|
if (state.getValue(STAGE) == 0) {
|
|
level.setBlock(pos, (BlockState)state.cycle(STAGE), 260);
|
|
} else {
|
|
this.treeGrower.growTree(level, level.getChunkSource().getGenerator(), pos, state, random);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public boolean isValidBonemealTarget(LevelReader level, BlockPos pos, BlockState state) {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public boolean isBonemealSuccess(Level level, RandomSource random, BlockPos pos, BlockState state) {
|
|
return (double)level.random.nextFloat() < 0.45;
|
|
}
|
|
|
|
@Override
|
|
public void performBonemeal(ServerLevel level, RandomSource random, BlockPos pos, BlockState state) {
|
|
this.advanceTree(level, pos, state, random);
|
|
}
|
|
|
|
@Override
|
|
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
|
builder.add(STAGE);
|
|
}
|
|
}
|
|
|