tutorial:crops
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tutorial:crops [2022/12/21 01:41] – item groups in 1.19.3 haykam | tutorial:crops [2025/04/01 12:05] (current) – fix typo solidblock | ||
---|---|---|---|
Line 10: | Line 10: | ||
===== Creating the Crop Block Class ===== | ===== 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 '' | + | 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 '' |
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
public class CustomCropBlock extends CropBlock { | public class CustomCropBlock extends CropBlock { | ||
- | private static final VoxelShape[] AGE_TO_SHAPE = new VoxelShape[]{Block.createCuboidShape(0.0D, | ||
- | Block.createCuboidShape(0.0D, | ||
- | Block.createCuboidShape(0.0D, | ||
- | Block.createCuboidShape(0.0D, | ||
- | Block.createCuboidShape(0.0D, | ||
- | Block.createCuboidShape(0.0D, | ||
- | Block.createCuboidShape(0.0D, | ||
- | Block.createCuboidShape(0.0D, | ||
- | }; | ||
- | |||
public CustomCropBlock(AbstractBlock.Settings settings) { | public CustomCropBlock(AbstractBlock.Settings settings) { | ||
super(settings); | super(settings); | ||
Line 31: | Line 21: | ||
</ | </ | ||
- | Once you've configured that, you need to define your seed item and add an outline shape. We haven' | + | Once you've configured that, you can define your seed item and add an outline shape. |
+ | |||
+ | We haven' | ||
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
Line 49: | Line 41: | ||
} | } | ||
- | | + | |
- | return | + | protected |
+ | return | ||
} | } | ||
| | ||
- | | + | |
- | return AGE_TO_SHAPE[(Integer)state.get(this.getAgeProperty())]; | + | protected |
+ | return AGE_TO_SHAPE[getAge(state)]; | ||
} | } | ||
} | } | ||
Line 61: | Line 55: | ||
===== Registering your Crop and Seed Item ===== | ===== 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 will not be covered in this tutorial but you can refer to the [[tutorial:items|Item]] page. It is important | + | Now we need to register our crop and the item to use for our seed. The seed model and class (including the static '' |
- | <code java [enable_line_numbers=" | + | <code java [enable_line_numbers=" |
- | public | + | // For versions before 1.21.2: |
+ | | ||
+ | |||
+ | // For version 1.21.2 and later: | ||
+ | public static final Block CUSTOM_CROP = register(" | ||
+ | </ | ||
- | public static final CropBlock CUSTOM_CROP_BLOCK | + | <code java [enable_line_numbers=" |
+ | // For version before 1.21.2: | ||
+ | | ||
+ | |||
+ | // For version 1.21.2 and later: | ||
+ | public static final Item CUSTOM_SEEDS = register(" | ||
+ | </ | ||
- | public static final Item CUSTOM_SEEDS | + | > In the [[blocks]] tutorial, we wrote the '' |
+ | > <code java TutorialBlocks.java> | ||
+ | // ... | ||
+ | | ||
+ | |||
+ | // ... | ||
+ | |||
+ | private static Block registerBlockOnly(String path, Function< | ||
+ | final Identifier identifier = Identifier.of(" | ||
+ | final RegistryKey< | ||
- | @Override | + | return Blocks.register(registryKey, factory, settings); |
- | public void onInitialize() { | + | } |
- | Registry.register(Registries.BLOCK, new Identifier(" | + | |
- | Registry.register(Registries.ITEM, | + | |
- | + | ||
- | } | + | |
- | } | + | |
</ | </ | ||
- | You also probably want the '' | + | You also probably want the '' |
- | <code java [enable_line_numbers=" | + | <code java [enable_line_numbers=" |
@Environment(EnvType.CLIENT) | @Environment(EnvType.CLIENT) | ||
- | public class TutorialModClient | + | public class ExampleModClient |
- | | + | // ... |
- | | + | |
- | | + | |
- | | + | public void onInitializeClient() { |
+ | // ... | ||
+ | | ||
+ | } | ||
} | } | ||
</ | </ | ||
Line 98: | Line 110: | ||
" | " | ||
" | " | ||
- | " | + | " |
} | } | ||
} | } | ||
</ | </ | ||
- | Lastly you will want to create a blockstate | + | Lastly you will want to create a blockstates definition |
- | <code JavaScript src/ | + | <code JavaScript src/ |
{ | { | ||
" | " | ||
" | " | ||
- | " | + | " |
}, | }, | ||
" | " | ||
- | " | + | " |
}, | }, | ||
" | " | ||
- | " | + | " |
}, | }, | ||
" | " | ||
- | " | + | " |
}, | }, | ||
" | " | ||
- | " | + | " |
}, | }, | ||
" | " | ||
- | " | + | " |
}, | }, | ||
" | " | ||
- | " | + | " |
}, | }, | ||
" | " | ||
- | " | + | " |
} | } | ||
} | } | ||
} | } | ||
</ | </ | ||
+ | |||
+ | > The seeds item also need a corresponding item model and item models definition (for version 1.21.4 an later), which will not be explained in length here. | ||
+ | |||
+ | ===== 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' | ||
===== Crop Block Finished! ===== | ===== 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. | + | 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! |
tutorial/crops.1671586873.txt.gz · Last modified: 2022/12/21 01:41 by haykam