minecraft-src/net/minecraft/world/level/levelgen/feature/SimpleBlockFeature.java
2025-07-04 03:15:13 +03:00

44 lines
1.6 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.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<SimpleBlockConfiguration> {
public SimpleBlockFeature(Codec<SimpleBlockConfiguration> codec) {
super(codec);
}
@Override
public boolean place(FeaturePlaceContext<SimpleBlockConfiguration> 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;
}
}
}