====== Adding a Custom Crop ====== This tutorial will cover adding a simple crop similar to carrots or wheat. When creating this custom crop you will need the following items: * Custom Seed item * Registry for the crop block and seed item * A class for your crop block * Models and a blockstate for your crop block ===== Creating the Crop Block Class ===== In order to create a crop we need a class for the block. You will need to make a class with your crop name and make it extend ''CropBlock''. You'll want to add your ''AbstractBlock.Settings'' and create a shape for the crop. public class CustomCropBlock extends CropBlock { public CustomCropBlock(AbstractBlock.Settings settings) { super(settings); } } Once you've configured that, you can define your seed item and add an outline shape. Each ''Block.createCubiodShape'' defines the hitbox size for each growth stage of the crop. You can configure the values to your liking, or do nothing while directly using the vanilla one inherited from ''CropBlock'', which will be identical to the shape for wheat. We haven't added our seed item yet so you can use something else temporarily. Here is what the code should look like with your cuboid shape, seed item, and outline shape: public class CustomCropBlock extends CropBlock { private static final VoxelShape[] AGE_TO_SHAPE = new VoxelShape[]{Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 2.0D, 16.0D), Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 3.0D, 16.0D), Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 4.0D, 16.0D), Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 5.0D, 16.0D), Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 6.0D, 16.0D), Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 7.0D, 16.0D), Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 8.0D, 16.0D), Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 9.0D, 16.0D) }; public CustomCropBlock(AbstractBlock.Settings settings) { super(settings); } @Override protected ItemConvertible getSeedsItem() { return TutorialItems.CUSTOM_SEEDS; } @Override protected VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { return AGE_TO_SHAPE[getAge(state)]; } } ===== Registering your Crop and Seed Item ===== Now we need to register our crop and the item to use for our seed. The seed model and class (including the static ''register'' method we use for convenience) will not be covered in this tutorial but you can refer to the [[items]] and [[blocks]] page. It is important to use ''AliasedBlockItem'' to make sure your seed item is bound to your crop block. public static final CropBlock CUSTOM_CROP = register("custom_crop", new CustomCropBlock(AbstractBlock.Settings.create().nonOpaque().noCollision().ticksRandomly().breakInstantly().sounds(BlockSoundGroup.CROP))); public static final Item CUSTOM_SEEDS = register("custom_seeds", new AliasedBlockItem(TutorialBlocks.CUSTOM_CROP, new Item.Settings())); You also probably want the ''BlockRenderMapLayer'' to give your crop a transparent cutout (see [[blockappearance]]). Do that in your client initializer: @Environment(EnvType.CLIENT) public class ExampleModClient implements ClientModInitializer { // ... @Override public void onInitializeClient() { // ... BlockRenderLayerMap.INSTANCE.putBlocks(RenderLayer.getCutout(), TutorialBlocks.CUSTOM_CROP); } } ===== Creating our Blockstate and Models ===== Now that we have finished the registry and code, we can add our models. The example below shows a simple growth stage model that uses the ''minecraft:block/crop'' format. You may also use ''minecraft:block/cross'' for a cross model shape. You **must** have a separate model for each growth stage you will have. This example shows a singular stage but you can copy it and replace the "0" with your growth stage number. { "parent": "minecraft:block/crop", "textures": { "crop": "tutorial:block/custom_crop_stage0" } } Lastly you will want to create a blockstate for your crop which registers your model for each age of your crop: { "variants": { "age=0": { "model": "tutorial:block/custom_crop_stage0" }, "age=1": { "model": "tutorial:block/custom_crop_stage0" }, "age=2": { "model": "tutorial:block/custom_crop_stage1" }, "age=3": { "model": "tutorial:block/custom_crop_stage1" }, "age=4": { "model": "tutorial:block/custom_crop_stage2" }, "age=5": { "model": "tutorial:block/custom_crop_stage2" }, "age=6": { "model": "tutorial:block/custom_crop_stage3" }, "age=7": { "model": "tutorial:block/custom_crop_stage3" } } } ===== Loot Table ===== The block also needs a loot table, or it will drop nothing when mined. However, you can directly imitate vanillas. For example, copy vanilla's ''data/minecraft/loot_table/blocks/wheat.json'' into your mod's ''src/main/resources/data/tutorial/loot_table/blocks/custom_crop.json'', and replace related IDs. You can also use [[datagen loot|data generators]] to generate loot tables. ===== Crop Block Finished! ===== If you completed all parts of this tutorial correctly, you should now have a working crop! Your crop will be usable with bone meal and can only be placed on farmland with your seed item. You can also add other interesting funcionalities for the crops!