tutorial:crops
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
tutorial:crops [2021/06/24 21:10] – created crop block page (feel free to make changes) safro | 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() { | + | } |
- | BlockRenderLayerMap.INSTANCE.putBlocks(RenderLayer.getCutout(), CUSTOM_CROP_BLOCK); | + | </ |
- | Registry.register(Registry.BLOCK, | + | You also probably want the '' |
- | Registry.register(Registry.ITEM, | + | |
- | } | + | <code java [enable_line_numbers=" |
+ | @Environment(EnvType.CLIENT) | ||
+ | public class ExampleModClient implements ClientModInitializer { | ||
+ | // ... | ||
+ | |||
+ | @Override | ||
+ | public void onInitializeClient() { | ||
+ | // ... | ||
+ | BlockRenderLayerMap.INSTANCE.putBlocks(RenderLayer.getCutout(), | ||
+ | | ||
} | } | ||
</ | </ | ||
===== Creating our Blockstate and Models ===== | ===== 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 '' | + | 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 '' |
<code JavaScript src/ | <code JavaScript src/ | ||
Line 88: | 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 completely | + | If you completed |
tutorial/crops.1624569036.txt.gz · Last modified: 2021/06/24 21:10 by safro