package net.minecraft.world.level.levelgen.feature; import com.mojang.serialization.Codec; import net.minecraft.core.BlockPos; import net.minecraft.world.level.WorldGenLevel; import net.minecraft.world.level.block.DoublePlantBlock; import net.minecraft.world.level.block.MossyCarpetBlock; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.levelgen.feature.configurations.SimpleBlockConfiguration; public class SimpleBlockFeature extends Feature { public SimpleBlockFeature(Codec codec) { super(codec); } @Override public boolean place(FeaturePlaceContext context) { SimpleBlockConfiguration simpleBlockConfiguration = context.config(); WorldGenLevel worldGenLevel = context.level(); BlockPos blockPos = context.origin(); BlockState blockState = simpleBlockConfiguration.toPlace().getState(context.random(), blockPos); if (blockState.canSurvive(worldGenLevel, blockPos)) { if (blockState.getBlock() instanceof DoublePlantBlock) { if (!worldGenLevel.isEmptyBlock(blockPos.above())) { return false; } DoublePlantBlock.placeAt(worldGenLevel, blockState, blockPos, 2); } else if (blockState.getBlock() instanceof MossyCarpetBlock) { MossyCarpetBlock.placeAt(worldGenLevel, blockPos, worldGenLevel.getRandom(), 2); } else { worldGenLevel.setBlock(blockPos, blockState, 2); } if (simpleBlockConfiguration.scheduleTick()) { worldGenLevel.scheduleTick(blockPos, worldGenLevel.getBlockState(blockPos).getBlock(), 1); } return true; } else { return false; } } }