User Tools

Site Tools


zh_cn:tutorial:crops

Differences

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

Link to this comparison view

Next revision
Previous revision
zh_cn:tutorial:crops [2021/11/09 11:16] – created breakicezh_cn:tutorial:crops [2023/11/18 08:44] (current) solidblock
Line 1: Line 1:
-====== 添加你的自定义作物 ======+====== 添加自定义作物 ======
  
-这篇教程教会如何添加一个小麦和胡萝卜那样的作物。如果你想创建属于你的作物的话需要以下物品:+教程教会如何添加像小麦和胡萝卜那样的作物。创建自定义的作物,需要以下这些事情:
  
-   * 自定义的种子 +   * 自定义的种子物品 
-   注册你的种子和作物方块 +   * 作物方块和种子物品的注册表 
-   * 作物方块+   * 作物方块类
    * 为你的作物设计的方块状态和模型    * 为你的作物设计的方块状态和模型
  
 ===== 创建作物类 ===== ===== 创建作物类 =====
  
-创建自定义作物我们需要先创建一个方块类。 你需要用你的作物名命名你的类并且让他继承 ''CropBlock''。 你需要添加 ''AbstractBlock.Settings'' 创建你的作物的形状。 Each ''Block.createCubiodShape'' defines the hitbox size for each growth stage of the crop. You can configure the values to your liking.  +为创建自定义作物我们需要先创建一个方块类。你需要用你的作物名命名你的类并且继承 ''CropBlock''。你需要添加 ''AbstractBlock.Settings'' 并为作物创建形状。每个 ''Block.createCubiodShape'' 都定义了作物在各生长阶段的碰撞箱大小。你可以根据自己的喜好来配置这些值。
  
 <code java [enable_line_numbers="true"]> <code java [enable_line_numbers="true"]>
Line 31: Line 31:
 </code> </code>
  
-Once you've configured that, you need to define your seed item and add an outline shape. 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:+配置完成后,你需要定义你的种子物品并添加外观性状。我们还没有添加种子物品,因此暂时先使用其他的。下面的代码,使用长方体形状、种子物品和外观形状应该是这样子:
  
 <code java [enable_line_numbers="true"]> <code java [enable_line_numbers="true"]>
Line 59: Line 59:
 </code> </code>
  
-===== 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.+现在需要注册作物和用作种子的物品。本教程不介绍种子模型和类,请参考 [[items]] 页面。特别要注意,要添加 ''AliasedBlockItem'' 以确保您的种子物品绑定到作物方块上。
  
 <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().group(ItemGroup.MISC));
Line 72: Line 72:
  @Override  @Override
  public void onInitialize() {  public void onInitialize() {
- Registry.register(Registry.BLOCK, new Identifier("tutorial","custom_crop_block"), CUSTOM_CROP_BLOCK); + Registry.register(Registries.BLOCK, new Identifier("tutorial","custom_crop_block"), CUSTOM_CROP_BLOCK); 
- Registry.register(Registry.ITEM, new Identifier("tutorial","custom_seeds"), CUSTOM_SEEDS);+ Registry.register(Registries.ITEM, new Identifier("tutorial","custom_seeds"), CUSTOM_SEEDS);
  
  }  }
Line 79: Line 79:
 </code> </code>
  
-You also probably want the ''BlockRenderMapLayer'' to give your crop a transparent cutout. Do that in your client initializer:+你很可能还需要 ''BlockRenderMapLayer'',这样你的作物才会显示为透明裁切的格式。在客户端初始化器中:
  
 <code java [enable_line_numbers="true"]> <code java [enable_line_numbers="true"]>
 +@Environment(EnvType.CLIENT)
 public class TutorialModClient implements ClientModInitializer { public class TutorialModClient implements ClientModInitializer {
        @Override        @Override
Line 90: Line 91:
 </code> </code>
  
-===== 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. +我们已经完成了注册和代码,现在需要添加模型。下面的例子展示了使用 ''minecraft:block/crop'' 格式的简单生长阶段模型。你也可以使用 ''minecraft:block/cross'' 以使用交叉形的模型。您**必须**为拥有的每个生长阶段创建一个单独的模型。这个例子只呈现了单一的阶段,你可以将“0”替换成对应的生长阶段的数字。
  
 <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 102: Line 103:
 </code> </code>
  
-Lastly you will want to create a blockstate for your crop which registers your model for each age of your crop:+最后,您还需要为您的作物创建方块状态,以给作物的每个生长阶段都注册单独的模型。
  
 <code JavaScript src/main/resources/assets/tutorial/blockstates/custom_crop_block.json> <code JavaScript src/main/resources/assets/tutorial/blockstates/custom_crop_block.json>
Line 135: Line 136:
 </code> </code>
  
-===== 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. +如果你正确完成了本教程的所有部分,那么你现在就应该有一个生效的作物了!这个作物可以用骨粉催熟,并且只能用种子物品放置在耕地上。
zh_cn/tutorial/crops.1636456591.txt.gz · Last modified: 2021/11/09 11:16 by breakice