29 lines
1.1 KiB
Java
29 lines
1.1 KiB
Java
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.levelgen.feature.configurations.ReplaceBlockConfiguration;
|
|
import net.minecraft.world.level.levelgen.feature.configurations.OreConfiguration.TargetBlockState;
|
|
|
|
public class ReplaceBlockFeature extends Feature<ReplaceBlockConfiguration> {
|
|
public ReplaceBlockFeature(Codec<ReplaceBlockConfiguration> codec) {
|
|
super(codec);
|
|
}
|
|
|
|
@Override
|
|
public boolean place(FeaturePlaceContext<ReplaceBlockConfiguration> context) {
|
|
WorldGenLevel worldGenLevel = context.level();
|
|
BlockPos blockPos = context.origin();
|
|
ReplaceBlockConfiguration replaceBlockConfiguration = context.config();
|
|
|
|
for (TargetBlockState targetBlockState : replaceBlockConfiguration.targetStates) {
|
|
if (targetBlockState.target.test(worldGenLevel.getBlockState(blockPos), context.random())) {
|
|
worldGenLevel.setBlock(blockPos, targetBlockState.state, 2);
|
|
break;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|