Search in sources :

Example 1 with CropBlock

use of net.minecraft.world.level.block.CropBlock in project AlexsMobs by Alex-the-666.

the class CrowAICircleCrops method pollinate.

private void pollinate() {
    if (crow.level.getBlockState(blockPos).getBlock() instanceof CropBlock) {
        CropBlock block = (CropBlock) crow.level.getBlockState(blockPos).getBlock();
        int cropAge = crow.level.getBlockState(blockPos).getValue(block.getAgeProperty());
        if (cropAge > 0) {
            crow.level.setBlockAndUpdate(blockPos, crow.level.getBlockState(blockPos).setValue(block.getAgeProperty(), cropAge - 1));
        } else {
            crow.level.destroyBlock(blockPos, true);
        }
        stop();
    } else {
        crow.level.destroyBlock(blockPos, true);
        stop();
    }
    tryTicks = 1200;
}
Also used : CropBlock(net.minecraft.world.level.block.CropBlock)

Example 2 with CropBlock

use of net.minecraft.world.level.block.CropBlock in project AlexsMobs by Alex-the-666.

the class HummingbirdAIPollinate method isGrowable.

private boolean isGrowable(BlockPos pos, ServerLevel world) {
    BlockState blockstate = world.getBlockState(pos);
    Block block = blockstate.getBlock();
    return block instanceof CropBlock && !((CropBlock) block).isMaxAge(blockstate);
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) CropBlock(net.minecraft.world.level.block.CropBlock) Block(net.minecraft.world.level.block.Block) CropBlock(net.minecraft.world.level.block.CropBlock)

Example 3 with CropBlock

use of net.minecraft.world.level.block.CropBlock in project Create by Creators-of-Create.

the class HarvesterMovementBehaviour method isValidCrop.

public boolean isValidCrop(Level world, BlockPos pos, BlockState state) {
    boolean harvestPartial = AllConfigs.SERVER.kinetics.harvestPartiallyGrown.get();
    boolean replant = AllConfigs.SERVER.kinetics.harvesterReplants.get();
    if (state.getBlock() instanceof CropBlock) {
        CropBlock crop = (CropBlock) state.getBlock();
        if (harvestPartial)
            return state.getValue(crop.getAgeProperty()) != 0 || !replant;
        return crop.isMaxAge(state);
    }
    if (state.getCollisionShape(world, pos).isEmpty() || state.getBlock() instanceof CocoaBlock) {
        for (Property<?> property : state.getProperties()) {
            if (!(property instanceof IntegerProperty))
                continue;
            IntegerProperty ageProperty = (IntegerProperty) property;
            if (!property.getName().equals(BlockStateProperties.AGE_1.getName()))
                continue;
            int age = state.getValue(ageProperty).intValue();
            if (state.getBlock() instanceof SweetBerryBushBlock && age <= 1 && replant)
                continue;
            if (age == 0 && replant || !harvestPartial && (ageProperty.getPossibleValues().size() - 1 != age))
                continue;
            return true;
        }
    }
    return false;
}
Also used : IntegerProperty(net.minecraft.world.level.block.state.properties.IntegerProperty) CocoaBlock(net.minecraft.world.level.block.CocoaBlock) SweetBerryBushBlock(net.minecraft.world.level.block.SweetBerryBushBlock) CropBlock(net.minecraft.world.level.block.CropBlock)

Example 4 with CropBlock

use of net.minecraft.world.level.block.CropBlock in project Cyclic by Lothrazar.

the class HarvestUtil method getAgeProp.

public static IntegerProperty getAgeProp(BlockState blockState) {
    if (blockState.getBlock() instanceof CropBlock) {
        CropBlock crops = (CropBlock) blockState.getBlock();
        // better mod compatibility if they dont use 'age'
        return crops.getAgeProperty();
    }
    String age = CropBlock.AGE.getName();
    ResourceLocation bid = blockState.getBlock().getRegistryName();
    if (CompatConstants.RESYNTH.equalsIgnoreCase(bid.getNamespace())) {
        // some silly old mods dont use age for compatibility
        // https://github.com/Resynth-Minecraft-Mod/Resynth-Mod/blob/a9f47439d103c1c17ca7a4ffd05c2dc0397e5e5f/src/main/java/com/ki11erwolf/resynth/plant/block/BlockBiochemicalPlant.java#L59
        // so we hack it
        age = CompatConstants.RESYNTH_GROWTH_STAGE;
    }
    for (Property<?> p : blockState.getProperties()) {
        if (p != null && p.getName() != null && p instanceof IntegerProperty && p.getName().equalsIgnoreCase(age)) {
            return (IntegerProperty) p;
        }
    }
    // IGrowable is useless here, i tried. no way to tell if its fully grown, or what age/stage its in
    return null;
}
Also used : IntegerProperty(net.minecraft.world.level.block.state.properties.IntegerProperty) ResourceLocation(net.minecraft.resources.ResourceLocation) CropBlock(net.minecraft.world.level.block.CropBlock)

Example 5 with CropBlock

use of net.minecraft.world.level.block.CropBlock in project Atum2 by TeamMetallurgy.

the class AtumFarmTask method isValidPosForFarming.

private boolean isValidPosForFarming(BlockPos pos, ServerLevel serverworld) {
    BlockState blockstate = serverworld.getBlockState(pos);
    Block block = blockstate.getBlock();
    Block block1 = serverworld.getBlockState(pos.below()).getBlock();
    return block instanceof CropBlock && ((CropBlock) block).isMaxAge(blockstate) || blockstate.isAir() && block1 instanceof FertileSoilTilledBlock;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) FertileSoilTilledBlock(com.teammetallurgy.atum.blocks.vegetation.FertileSoilTilledBlock) FertileSoilTilledBlock(com.teammetallurgy.atum.blocks.vegetation.FertileSoilTilledBlock) CropBlock(net.minecraft.world.level.block.CropBlock) Block(net.minecraft.world.level.block.Block) CropBlock(net.minecraft.world.level.block.CropBlock)

Aggregations

CropBlock (net.minecraft.world.level.block.CropBlock)9 BlockState (net.minecraft.world.level.block.state.BlockState)5 Block (net.minecraft.world.level.block.Block)4 ItemStack (net.minecraft.world.item.ItemStack)3 IntegerProperty (net.minecraft.world.level.block.state.properties.IntegerProperty)3 FertileSoilTilledBlock (com.teammetallurgy.atum.blocks.vegetation.FertileSoilTilledBlock)2 StemBlock (net.minecraft.world.level.block.StemBlock)2 SweetBerryBushBlock (net.minecraft.world.level.block.SweetBerryBushBlock)2 IHarvesterOverride (com.lothrazar.cyclic.api.IHarvesterOverride)1 WaterBlock (net.mehvahdjukaar.selene.blocks.WaterBlock)1 BlockPos (net.minecraft.core.BlockPos)1 ResourceLocation (net.minecraft.resources.ResourceLocation)1 ServerLevel (net.minecraft.server.level.ServerLevel)1 SimpleContainer (net.minecraft.world.SimpleContainer)1 BlockPosTracker (net.minecraft.world.entity.ai.behavior.BlockPosTracker)1 WalkTarget (net.minecraft.world.entity.ai.memory.WalkTarget)1 Item (net.minecraft.world.item.Item)1 CocoaBlock (net.minecraft.world.level.block.CocoaBlock)1 NetherWartBlock (net.minecraft.world.level.block.NetherWartBlock)1 VoxelShape (net.minecraft.world.phys.shapes.VoxelShape)1