User Tools

Site Tools


tutorial:crops

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
tutorial:crops [2021/06/24 21:10] – created crop block page (feel free to make changes) safrotutorial:crops [2023/11/18 08:44] (current) solidblock
Line 61: Line 61:
 ===== 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 you add ''AlisasedBockItem'' to make sure your seed item is bound to your crop block. You also probably want the ''BlockRenderMapLayer'' to make your crop a transparent cutout+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 you add ''AliasedBlockItem'' to make sure your seed item is bound to your crop block.
  
 <code java [enable_line_numbers="true"]> <code java [enable_line_numbers="true"]>
 public class TutorialMod implements ModInitializer { public class TutorialMod implements ModInitializer {
  
- public static final CropBlock CUSTOM_CROP_BLOCK = new CustomCropBlock(AbstractBlock.Settings.of(Material.PLANT).nonOpaque().noCollision().ticksRandomly().breakInstantly().sounds(BlockSoundGroup.CROP));+ public static final CropBlock CUSTOM_CROP_BLOCK = new CustomCropBlock(AbstractBlock.Settings.create().nonOpaque().noCollision().ticksRandomly().breakInstantly().sounds(BlockSoundGroup.CROP));
  
- public static final Item CUSTOM_SEEDS = new AliasedBlockItem(TutorialMod.CUSTOM_CROP_BLOCK, new Item.Settings().group(ItemGroup.MISC));+ public static final Item CUSTOM_SEEDS = new AliasedBlockItem(TutorialMod.CUSTOM_CROP_BLOCK, new Item.Settings());
  
  @Override  @Override
  public void onInitialize() {  public void onInitialize() {
- BlockRenderLayerMap.INSTANCE.putBlocks(RenderLayer.getCutout(), CUSTOM_CROP_BLOCK); + Registry.register(Registries.BLOCK, new Identifier("tutorial","custom_crop_block"), CUSTOM_CROP_BLOCK); 
- + Registry.register(Registries.ITEM, new Identifier("tutorial","custom_seeds"), CUSTOM_SEEDS);
- Registry.register(Registry.BLOCK, new Identifier("tutorial","custom_crop_block"), CUSTOM_CROP_BLOCK); +
- Registry.register(Registry.ITEM, new Identifier("tutorial","custom_seeds"), CUSTOM_SEEDS);+
  
  }  }
 +}
 +</code>
 +
 +You also probably want the ''BlockRenderMapLayer'' to give your crop a transparent cutout. Do that in your client initializer:
 +
 +<code java [enable_line_numbers="true"]>
 +@Environment(EnvType.CLIENT)
 +public class TutorialModClient implements ClientModInitializer {
 +       @Override
 +       public void onInitializeClient() {
 +               BlockRenderLayerMap.INSTANCE.putBlocks(RenderLayer.getCutout(), CUSTOM_CROP_BLOCK);
 +       }
 } }
 </code> </code>
  
 ===== 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 ''minecraft:block/crop'' format. You may also use ''minecraft:block/cross'' for a cross model shape. You **must** have a seperate 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. +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. 
  
 <code JavaScript src/main/resources/assets/tutorial/models/block/custom_crop_stage0.json> <code JavaScript src/main/resources/assets/tutorial/models/block/custom_crop_stage0.json>
Line 128: Line 138:
 ===== Crop Block Finished! ===== ===== Crop Block Finished! =====
  
-If you completely all parts of this tutorial correctly, you should now having work 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 working crop! Your crop will be usable with bone meal and can only be placed on farmland with your seed item. 
tutorial/crops.1624569036.txt.gz · Last modified: 2021/06/24 21:10 by safro