drafts:items
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
drafts:items [2023/09/13 18:46] – removed - external edit (Unknown date) 127.0.0.1 | drafts:items [2024/06/30 00:02] (current) – ↷ Links adapted because of a move operation banana | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Adding an Item (SIMPLIFIED ENGLISH DRAFT) ====== | ||
+ | **NOTE: This isn't really a serious draft of any kind. It was just made to demonstrate how an article would look like if translated to a simplified, controlled form of English (specifically, | ||
+ | |||
+ | ==== Introduction ==== | ||
+ | |||
+ | Adding a basic item is one of the first things to do when learning how to make a mod. To add an item, you must make an ''< | ||
+ | |||
+ | In all of the tutorials, the " | ||
+ | |||
+ | ==== Add the item to the register ==== | ||
+ | |||
+ | First, make an instance of <yarn class_1792> | ||
+ | |||
+ | < | ||
+ | public class ExampleMod implements ModInitializer { | ||
+ | |||
+ | // an instance of our new item | ||
+ | public static final class_1792 EXAMPLE_ITEM = new class_1792(new FabricItemSettings()); | ||
+ | [...] | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Then, you must add the item to the item register with the " | ||
+ | Use the ''< | ||
+ | |||
+ | * Registry Type, which is the register to add the item to | ||
+ | * <yarn class_2960>, | ||
+ | * Content, which is the item's properties. | ||
+ | |||
+ | You must call the method during initialization. The location of the method in your code is not important. | ||
+ | |||
+ | The identifier argument is made of two strings -- the modid and the item's name. Pass in the constant you made in the first step as the content argument. | ||
+ | |||
+ | < | ||
+ | public class ExampleMod implements ModInitializer { | ||
+ | |||
+ | // an instance of our new item | ||
+ | public static final class_1792 EXAMPLE_ITEM = new class_1792(new FabricItemSettings()); | ||
+ | |||
+ | @Override | ||
+ | public void onInitialize() { | ||
+ | class_2378.method_10230(class_7923.field_41178, | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | Your have added an item to Minecraft! Run the run config '' | ||
+ | |||
+ | {{: | ||
+ | |||
+ | You can also call the method when you make the constant in the first step. This can simplify the code. | ||
+ | < | ||
+ | public class ExampleMod implements ModInitializer { | ||
+ | |||
+ | // an instance of our new item | ||
+ | public static final class_1792 EXAMPLE_ITEM = | ||
+ | class_2378.method_10230(class_7923.field_41178, | ||
+ | new class_1792(new FabricItemSettings())); | ||
+ | |||
+ | @Override | ||
+ | public void onInitialize() { | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ==== Add a texture for the item ==== | ||
+ | |||
+ | To add a texture for the item, you must have an item model json file and a texture image. You must add these to your resource directory. The direct path of each is: | ||
+ | |||
+ | Item model: .../ | ||
+ | Item texture: .../ | ||
+ | |||
+ | Our example texture can be found [[https:// | ||
+ | |||
+ | If you added your item to the register correctly in the first step, your game will send a warning to the log similar to this: | ||
+ | |||
+ | [Server-Worker-1/ | ||
+ | It usefully tells you where the game expects your asset(s) to be found -- when you are not sure that something is correct, look at the log. | ||
+ | |||
+ | A basic item model template is: | ||
+ | <code JavaScript> | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | The parent of your item changes how the item is rendered when held in the hand. Use " | ||
+ | |||
+ | When you have [[tutorial: | ||
+ | |||
+ | {{: | ||
+ | |||
+ | ==== Creating a Custom Item class ==== | ||
+ | |||
+ | To add more behavior to the item, it is necessary to create a custom Item class. You must pass in an Item.Settings object in the constructor. | ||
+ | < | ||
+ | public class ExampleItem extends class_1792 { | ||
+ | |||
+ | public ExampleItem(class_1793 settings) { | ||
+ | super(settings); | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | A custom item class can do many things. For example, this class tells the item make a sound when it is used. | ||
+ | < | ||
+ | public class ExampleItem extends class_1792 { | ||
+ | |||
+ | public ExampleItem(class_1793 settings) { | ||
+ | super(settings); | ||
+ | } | ||
+ | |||
+ | @Override | ||
+ | public class_1271< | ||
+ | playerEntity.method_5783(class_3417.field_14983, | ||
+ | return class_1271.method_22427(playerEntity.method_5998(hand)); | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | To add the changes to the game, replace the old <yarn class_1792> | ||
+ | < | ||
+ | public class ExampleMod implements ModInitializer { | ||
+ | |||
+ | // an instance of our new item | ||
+ | public static final ExampleItem EXAMPLE_ITEM = new ExampleItem(new FabricItemSettings()); | ||
+ | [...] | ||
+ | } | ||
+ | </ | ||
+ | If you completed all the steps correctly, the item will make a sound when it is used. | ||
+ | |||
+ | ==== Changing the stack size of the item ==== | ||
+ | |||
+ | To change the maximum size of a stack of that item, use use ''< | ||
+ | < | ||
+ | public class ExampleMod implements ModInitializer { | ||
+ | |||
+ | // An instance of our new item, where the maximum stack size is 16 | ||
+ | public static final ExampleItem EXAMPLE_ITEM = new ExampleItem(new FabricItemSettings().method_7889(16)); | ||
+ | [...] | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ==== Make your item usable as a fuel or be compostable ==== | ||
+ | |||
+ | If you want to let the item be used as fuel in a furnace, you can add it to the '' | ||
+ | <code java> | ||
+ | public class ExampleMod implements ModInitializer { | ||
+ | [...] | ||
+ | | ||
+ | @Override | ||
+ | public void onInitialize() { | ||
+ | [...] | ||
+ | FuelRegistry.INSTANCE.add(EXAMPLE_ITEM, | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | You can also add it to the '' | ||
+ | ==== Next Steps ==== | ||
+ | [[tutorial: |