Skip to main content

Crop API

The crop API is for registering carrot-like age crops and their generated seed item. It is separate from environment state; callbacks may use state handles, but state registration belongs to the environment API.

Entry Point

What you wantEntry pointReturns
Register a crop block and seed itemcrop("id")CropBuilder<RegistryCore>
Register a crop inside another chaincrop(parent, "id")CropBuilder<P>

CropBuilder

MethodParametersDescription
properties(modifier)UnaryOperator<BlockBehaviour.Properties>Configure crop block properties
growthRoll(callback)RegistryLibCropBlock.GrowthRollDecide whether a random tick may advance growth
onHarvest(callback)RegistryLibCropBlock.HarvestCallbackRun server harvest logic before right-click replanting
rightClickHarvest(enabled)booleanEnable or disable mature right-click harvest
seedItem(configurator)Consumer<ItemBuilder<Item, RegistryCore>>Configure the generated seed item
produce(supplier)Supplier<? extends Item>Configure mature crop loot
stageTextures(textures...)TextureRef...Generate crop stage blockstate/model data
register()-Register crop block and seed item, returning BlockEntry<RegistryLibCropBlock>
build()-Register and return the parent chain object

RegistryLibCropBlock

RegistryLibCropBlock extends vanilla CropBlock.

BehaviorNotes
Max age7, matching vanilla carrot-style crops
Random tickCalls growthRoll before vanilla crop growth
Seed itemSupplied by the generated seed entry
Mature right-clickOptional; enabled by default
Harvest callbackRuns on the server before drops and replanting

Callback Types

@FunctionalInterface
public interface GrowthRoll {
boolean shouldGrow(BlockState state, ServerLevel level, BlockPos pos, RandomSource random);
}
@FunctionalInterface
public interface HarvestCallback {
void onHarvest(BlockState state, Level level, BlockPos pos, Player player);
}

See Also