zh_cn:tutorial:crops
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
zh_cn:tutorial:crops [2022/05/04 12:53] – solidblock | zh_cn:tutorial:crops [2025/04/01 12:05] (current) – fix typo solidblock | ||
---|---|---|---|
Line 10: | Line 10: | ||
===== 创建作物类 ===== | ===== 创建作物类 ===== | ||
- | 为创建自定义作物,我们需要先创建一个方块类。你需要用你的作物名称命名你的类,并且继承 '' | + | 为创建自定义作物,我们需要先创建一个方块类。你需要用你的作物名称命名你的类,并且继承 '' |
<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: | ||
</ | </ | ||
- | 配置完成后,你需要定义你的种子物品并添加外观性状。我们还没有添加种子物品,因此暂时先使用其他的。下面的代码,使用长方体形状、种子物品和外观形状应该是这样子: | + | 配置完成后,你需要定义你的种子物品并添加外观形状。每个 '' |
+ | |||
+ | 我们还没有添加种子物品,因此暂时先使用其他的。下面的代码,使用长方体形状、种子物品和外观形状应该是这样子: | ||
<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)]; | ||
} | } | ||
} | } | ||
</ | </ | ||
- | ===== 注册您的作为和种子物品 ===== | + | ===== 注册你的作物和种子物品 ===== |
- | 现在需要注册作物和用作种子的物品。本教程不介绍种子模型和类,请参考 [[items]] 页面。特别要注意,要添加 '' | + | 现在需要注册作物和用作种子的物品。种子模型和类(包括为方便而用的静态 '' |
- | <code java [enable_line_numbers=" | + | <code java [enable_line_numbers=" |
- | public | + | // 对于 1.21.2 之前的版本: |
+ | | ||
+ | |||
+ | // 对于 1.21.2 及之后的版本: | ||
+ | public static final Block CUSTOM_CROP = register(" | ||
+ | </ | ||
- | public static final CropBlock CUSTOM_CROP_BLOCK | + | <code java [enable_line_numbers=" |
+ | // 对于 1.21.2 之前的版本: | ||
+ | | ||
+ | |||
+ | // 对于 1.21.2 及之后的版本: | ||
+ | public static final Item CUSTOM_SEEDS = register(" | ||
+ | </ | ||
- | public static final Item CUSTOM_SEEDS | + | > 在[[blocks|添加方块]]教程中,我们写的 '' |
+ | > <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(Registry.BLOCK, new Identifier(" | + | |
- | Registry.register(Registry.ITEM, | + | |
- | + | ||
- | } | + | |
- | } | + | |
</ | </ | ||
- | 你很可能还需要 '' | + | 你很可能还需要 '' |
- | <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: | ||
" | " | ||
" | " | ||
- | " | + | " |
} | } | ||
} | } | ||
</ | </ | ||
- | 最后,您还需要为您的作物创建方块状态,以给作物的每个生长阶段都注册单独的模型。 | + | 最后,您还需要为您的作物创建方块状态映射,以给作物的每个生长阶段都分配单独的模型。 |
- | <code JavaScript src/ | + | <code JavaScript src/ |
{ | { | ||
" | " | ||
" | " | ||
- | " | + | " |
}, | }, | ||
" | " | ||
- | " | + | " |
}, | }, | ||
" | " | ||
- | " | + | " |
}, | }, | ||
" | " | ||
- | " | + | " |
}, | }, | ||
" | " | ||
- | " | + | " |
}, | }, | ||
" | " | ||
- | " | + | " |
}, | }, | ||
" | " | ||
- | " | + | " |
}, | }, | ||
" | " | ||
- | " | + | " |
} | } | ||
} | } | ||
} | } | ||
</ | </ | ||
+ | |||
+ | > 种子物品也需要对应的物品模型和物品模型映射(对于 1.21.4 及之后的版本),具体做法参见 [[items]],这里不作详细描述。 | ||
+ | |||
+ | ===== 战利品表 ===== | ||
+ | 方块还需要战利品表,否则被破坏后什么也不会掉落。不过,你可以直接模仿原版的。例如,复制原版的 '' | ||
===== 大功告成! ===== | ===== 大功告成! ===== | ||
如果你正确完成了本教程的所有部分,那么你现在就应该有一个生效的作物了!这个作物可以用骨粉催熟,并且只能用种子物品放置在耕地上。 | 如果你正确完成了本教程的所有部分,那么你现在就应该有一个生效的作物了!这个作物可以用骨粉催熟,并且只能用种子物品放置在耕地上。 |
zh_cn/tutorial/crops.1651668835.txt.gz · Last modified: 2022/05/04 12:53 by solidblock