Search in sources :

Example 1 with GrassBlock

use of net.minecraft.world.level.block.GrassBlock in project EdenRing by paulevsGitch.

the class BalloonMushroomTreeFeature method place.

@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featurePlaceContext) {
    WorldGenLevel level = featurePlaceContext.level();
    BlockPos center = featurePlaceContext.origin();
    Random random = featurePlaceContext.random();
    Block below = level.getBlockState(center.below()).getBlock();
    if (!(below instanceof GrassBlock) && below != Blocks.DIRT) {
        return false;
    }
    MutableBlockPos pos = center.mutable();
    int h = MHelper.randRange(5, 9, random);
    for (int i = 1; i <= h; i++) {
        pos.setY(center.getY() + i);
        if (!level.getBlockState(pos).isAir()) {
            h = i - 1;
        }
    }
    if (h < 5) {
        h = random.nextInt(4);
        pos.setY(center.getY());
        BlockState tall = EdenBlocks.TALL_BALLOON_MUSHROOM.defaultBlockState();
        for (byte i = 0; i <= h; i++) {
            BlockState state = tall.setValue(EdenBlockProperties.TEXTURE_4, (int) i);
            if (i == h)
                state = state.setValue(EdenBlockProperties.TEXTURE_4, 3);
            if (level.getBlockState(pos.above()).isAir()) {
                BlocksHelper.setWithoutUpdate(level, pos, state);
                pos.setY(pos.getY() + 1);
            } else {
                state = state.setValue(EdenBlockProperties.TEXTURE_4, 3);
                BlocksHelper.setWithoutUpdate(level, pos, state);
                return true;
            }
        }
        return true;
    }
    BlockState stem = EdenBlocks.BALLOON_MUSHROOM_STEM.defaultBlockState();
    if (h > 5 && random.nextInt(6) == 0) {
        for (int i = 0; i < h; i++) {
            pos.setY(center.getY() + i);
            BlocksHelper.setWithoutUpdate(level, pos, stem);
        }
        BlockState head = EdenBlocks.BALLOON_MUSHROOM_BLOCK.defaultBlockState();
        BlockState fur = stem.setValue(EdenBlockProperties.BALLOON_MUSHROOM_STEM, BalloonMushroomStemState.FUR);
        for (int x = -1; x < 2; x++) {
            pos.setX(center.getX() + x);
            for (int z = -1; z < 2; z++) {
                pos.setZ(center.getZ() + z);
                pos.setY(center.getY() + h - 1);
                if (level.getBlockState(pos).isAir()) {
                    BlocksHelper.setWithoutUpdate(level, pos, fur);
                }
                for (int y = 0; y < 3; y++) {
                    pos.setY(center.getY() + h + y);
                    if (level.getBlockState(pos).isAir()) {
                        BlocksHelper.setWithoutUpdate(level, pos, head);
                    }
                }
            }
        }
    } else {
        BlockState thin = stem.setValue(EdenBlockProperties.BALLOON_MUSHROOM_STEM, BalloonMushroomStemState.THIN);
        BlockState thin_up = stem.setValue(EdenBlockProperties.BALLOON_MUSHROOM_STEM, BalloonMushroomStemState.THIN_TOP);
        int hMax = h - 1;
        for (int i = 0; i < h; i++) {
            pos.setY(center.getY() + i);
            BlocksHelper.setWithoutUpdate(level, pos, i == hMax ? thin_up : thin);
        }
        pos.setY(center.getY() + h);
        BlocksHelper.setWithoutUpdate(level, pos, EdenBlocks.BALLOON_MUSHROOM_BLOCK);
    }
    return true;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) Random(java.util.Random) GrassBlock(net.minecraft.world.level.block.GrassBlock) Block(net.minecraft.world.level.block.Block) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos) BlockPos(net.minecraft.core.BlockPos) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos) WorldGenLevel(net.minecraft.world.level.WorldGenLevel) GrassBlock(net.minecraft.world.level.block.GrassBlock)

Example 2 with GrassBlock

use of net.minecraft.world.level.block.GrassBlock in project EdenRing by paulevsGitch.

the class EdenBlocks method init.

public static void init() {
    BlockRegistry.getModBlocks(EdenRing.MOD_ID).forEach(block -> {
        Properties properties = ((AbstractBlockAccessor) block).getSettings();
        Material material = ((AbstractBlockSettingsAccessor) properties).getMaterial();
        if (block instanceof BaseLeavesBlock) {
            TagAPI.addBlockTag(NamedMineableTags.HOE, block);
            TagAPI.addBlockTag(NamedBlockTags.LEAVES, block);
            TagAPI.addItemTag(NamedItemTags.LEAVES, block);
            ComposterAPI.allowCompost(0.3F, block);
        } else if (block instanceof GrassBlock) {
            TagAPI.addBlockTag(NamedMineableTags.SHOVEL, block);
            ShovelAPI.addShovelBehaviour(block, Blocks.DIRT_PATH.defaultBlockState());
            TillableBlockRegistry.register(block, HoeItem::onlyIfAirAbove, Blocks.FARMLAND.defaultBlockState());
        } else if (material == Material.PLANT || material == Material.REPLACEABLE_PLANT) {
            TagAPI.addBlockTag(NamedMineableTags.HOE, block);
            if (block.asItem() != Items.AIR) {
                ComposterAPI.allowCompost(0.1F, block);
            }
        } else if (material == Material.STONE || material == Material.METAL || material == Material.HEAVY_METAL || material == Material.AMETHYST) {
            TagAPI.addBlockTag(NamedMineableTags.PICKAXE, block);
        }
        if (block instanceof BaseVineBlock) {
            TagAPI.addBlockTag(NamedBlockTags.CLIMBABLE, block);
        }
    });
    BonemealAPI.addLandGrass(MYCOTIC_GRASS, EDEN_MYCELIUM);
    BonemealAPI.addLandGrass(EdenBiomes.GOLDEN_FOREST.getID(), GOLDEN_GRASS, EDEN_GRASS_BLOCK);
    BonemealAPI.addLandGrass(EdenBiomes.GOLDEN_FOREST.getID(), Blocks.GRASS, EDEN_GRASS_BLOCK);
    BonemealAPI.addSpreadableBlock(MOSSY_STONE, Blocks.STONE);
}
Also used : AbstractBlockAccessor(net.fabricmc.fabric.mixin.object.builder.AbstractBlockAccessor) BaseVineBlock(ru.bclib.blocks.BaseVineBlock) AbstractBlockSettingsAccessor(net.fabricmc.fabric.mixin.object.builder.AbstractBlockSettingsAccessor) WoodenComplexMaterial(ru.bclib.complexmaterials.WoodenComplexMaterial) ComplexMaterial(ru.bclib.complexmaterials.ComplexMaterial) Material(net.minecraft.world.level.material.Material) BaseLeavesBlock(ru.bclib.blocks.BaseLeavesBlock) Properties(net.minecraft.world.level.block.state.BlockBehaviour.Properties) EdenGrassBlock(paulevs.edenring.blocks.EdenGrassBlock) GrassBlock(net.minecraft.world.level.block.GrassBlock)

Aggregations

GrassBlock (net.minecraft.world.level.block.GrassBlock)2 Random (java.util.Random)1 AbstractBlockAccessor (net.fabricmc.fabric.mixin.object.builder.AbstractBlockAccessor)1 AbstractBlockSettingsAccessor (net.fabricmc.fabric.mixin.object.builder.AbstractBlockSettingsAccessor)1 BlockPos (net.minecraft.core.BlockPos)1 MutableBlockPos (net.minecraft.core.BlockPos.MutableBlockPos)1 WorldGenLevel (net.minecraft.world.level.WorldGenLevel)1 Block (net.minecraft.world.level.block.Block)1 Properties (net.minecraft.world.level.block.state.BlockBehaviour.Properties)1 BlockState (net.minecraft.world.level.block.state.BlockState)1 Material (net.minecraft.world.level.material.Material)1 EdenGrassBlock (paulevs.edenring.blocks.EdenGrassBlock)1 BaseLeavesBlock (ru.bclib.blocks.BaseLeavesBlock)1 BaseVineBlock (ru.bclib.blocks.BaseVineBlock)1 ComplexMaterial (ru.bclib.complexmaterials.ComplexMaterial)1 WoodenComplexMaterial (ru.bclib.complexmaterials.WoodenComplexMaterial)1