owned this note
owned this note
Published
Linked with GitHub
# Minecraft Modding - Part 1
## Setting up the Environment
[Java 16](https://www.oracle.com/java/technologies/javase-downloads.html) - The current Java version supported by the Fabric Mod
[IntelliJ IDEA](https://www.jetbrains.com/idea/download/#section=windows) - Recommended: Community
- We will use this application to build out our Java code for the mod
[WinRAR](https://www.rarlab.com/download.htm) - Recommended: WinRAR x64 (64 bit) 6.02 - For macOS, No need to for zip software
- Merely to unzip files, unneeded if familiar with Git
Clone the following [Fabric Mod Example](https://github.com/FabricMC/fabric-example-mod/) from the Fabric API
## Reading Material
[Fabric API Wiki Page](https://fabricmc.net/wiki/tutorial:migratemappings)
The plugin can be found in the IntelliJ plugin repository, so you can install it using IntelliJ's internal plugin browser by navigating to File → Settings → Plugins, then clicking the Marketplace tab and searching for Minecraft.
[Intro to Modding with Fabric](https://fabricmc.net/wiki/tutorial:introduction)
Please read to gain an understanding of the different tools/dependencies and concepts that have already been created in the past.
### Third Party Libraries
[3rd party library mods](https://fabricmc.net/wiki/documentation:libraries)
### Applying changes without restarting Minecraft
- Reload changed classes
In Eclipse or **Intellij IDEA**, run Minecraft in **debug mode**. To apply changes in code, click the build button in Intellij IDEA or save in Eclipse. Note: this only allows you to change method bodies. If you do any other kind of change, You will have to restart. However, if you use DCEVM *(Not supported by Java 11+)*, you will be able to do most changes, including adding and removing methods and classes.
- Reload assets
After you make changes to assets such as textures and block/item models, you can rebuild the project and press F3 + T to apply changes without restarting Minecraft. More specifically, this is how to reload anything the mod provides as a resource pack.
- Reload data
You can apply any changes made in the data/ directory such as recipes, loot tables and tags by rebuilding the project and then using the in-game command /reload. More specifically, this reloads anything the mod provides as a data pack.
## Add a new item
- Create new directories under resources/assets
- assets/tutorial/item
```
// Create fabric_item.json
{
"parent": "item/generated",
"textures": {
"layer0": "tutorial:item/divine_sword"
}
}
```
- assets/textures/item
- Place png texture  -> https://i.imgur.com/QVsnzAH.png
- Create new directories under our example to customize our item
- example/item/misc/Heart.java
```
// Create our item
public class Heart extends Item {
public Heart(Settings settings) {
super(settings);
}
@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity playerEntity, Hand hand) {
playerEntity.playSound(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0F, 1.0F);
return TypedActionResult.success(playerEntity.getStackInHand(hand));
}
}
```
- Define our Heart and get ready to run our new minecraft fabric mod
```
public class ExampleMod implements ModInitializer {
// An instance of our new item that only stacks 5 times
public static final Heart HEART =
new Heart(new FabricItemSettings().group(ItemGroup.MISC).maxCount(5));
@Override
public void onInitialize() {
Registry.register(Registry.ITEM, new Identifier("tutorial", "heart"), HEART);
}
}
```
To run our minecraft mod, go to to the right panel and click on Gradle
Gradle > Tasks > fabric > runClient
### Enhancements
- [ ] Make the item a Food item
- [ ] Give status effects
- [ ] Make the name of the item, "Hearty Meal"
To make an item a Food Item, we can reinit our item as an instance of itself and then group the item as FOOD. Then we can declare a new FoodComponent with some status effects.
```
public static final Item HEART =
new Heart(new Item.Settings().group(ItemGroup.FOOD).maxCount(5).food(new FoodComponent.Builder().hunger(2).saturationModifier(4f).snack().alwaysEdible().statusEffect(new StatusEffectInstance(StatusEffects.HEALTH_BOOST, 20*3), 0.75f).build()));
```
Let's rename our item to "Heaty Meal" and do away with the java syntax of "item.tutorial.heart". Create a new directory under tutorial named lang.
tutorial/lang/en_us.json
```
{
"item.tutorial.heart": "Hearty Meal"
}
```
All newly made and renamed items can exist above.
## End of Workshop # 1
# Minecraft Modding - Part 2
## Overview
In the previous section, you created a generic item that was able to be used by right-clicking, which you were then challenged to make an edible item. The new task is to instead create an item that acts like a tool. This documentation will walk you through how to create a new type of pickaxe and a new type of sword. We will create an Emerald tier of tools (which can be relatively easy to change and toy with) and set predefined attributes to this tier to easy expand into other tools.
You can follow along with this workshop [here](https://fabricmc.net/wiki/tutorial:tools) on the fabric website.
## Tool Tier
Within the fabricmc package, create a new package titled accordingly to our current project. I went with "EmeraldTier".
Make a new class titled something like "EmeraldTool". Within this class, we'll start with the skeleton of the following:
```
public class EmeraldTool implements ToolMaterial {
public static final EmeraldTool INSTANCE = new EmeraldTool();
@Override
public int getDurability() {
return 0;
}
@Override
public float getMiningSpeedMultiplier() {
return 0.0F;
}
@Override
public float getAttackDamage() {
return 0.0F;
}
@Override
public int getMiningLevel() {
return 0;
}
@Override
public int getEnchantability() {
return 0;
}
@Override
public Ingredient getRepairIngredient() {
return Ingredient.ofItems(Items.X);
}
}
```
The beginning declaration says that we are creating a new tool class that can then be easily reused for when we make our actual tools later. The second line lets us apply those attributes to an item we declare as an EmeraldTool. Next are all the attributes of those tools.
- getDurability sets the tool durability. The number correlated directly to the number of uses the tool has
- getMiningSpeedMultiplier sets the minng speed for breaking valid blocks with such a tool. This multiplier is based off off your hand's mining speed
- getAttackDamage sets the damage bonus that all tools in this class recieve. This is separate from attack bonuses from tools (like how swords and axes how higher base damage)
- getMiningLevel sets how tough of blocks tools in this class can break. This is mainly for pickaxes; a higher level (up to 4) means the tool can break tougher blocks like obsidian and ancient debris
- getEnchantability sets the probabilities for getting stronger enchantments on tools of this class. Higher numbers means better chances for stronger enchantments
- getRepairIngredient sets the item type needed to repair this tool class at an anvil. This requires you to know the item ID used by the code, not what appears in game (ex. emerald in Items.E)
Follow [this link](https://minecraft.fandom.com/wiki/Tiers) to get an idea of how the base game's tiers are structured so you can play around with the numbers.
DO NOT delete the F symbol on this numbers, they declare those numbers to be float-points. Other than that, replace any of those numbers and play around with them as you would like.
## Specific Tool Classes
For some reason, pickaxes, axes, and hoes require a little bit of extra work to get them working. Fortunately, this is very easy, so we'll go ahead and cover it now.
Next to your EmeraldTier class, make a new class titled something like "EmeraldPickaxeTool". Within it, copy the following code:
```
public class EmeraldPickaxeItem extends PickaxeItem {
public EmeraldPickaxeItem(ToolMaterial material, int attackDamage, float attackSpeed, Settings settings) {
super(material, attackDamage, attackSpeed, settings);
}
}
```
In full honestly, I have no idea why we need to do this for these three tools and not swords or shovels, but they don't work without it.
## Setting Up Resources
Similarly to what you did in Part 1, we need to create resources for each of our tools to use. This includes a .json file and a .png file.
Within your main package, navigate to your resources/assets and make a new folder. Let's call it something like "emeraldtools". Like last time, we'll need two folders here, which we'll put the files for the sword first:
- ...emeraldtools/models/item/emerald_sword.json
- ...emeraldtools/textures/item/emerald_sword.png
For the .json files, you can use the following template:
```
{
"parent": "item/generated",
"textures": {
"layer0": "emeraldtools:item/emerald_sword"
}
}
```
This tells the code to look for the emerald_sword.png file in the textures resources. So now we better add that.
You can use this texture  -> https://i.imgur.com/yH8bufm.png if you would so like, or you can make your own. Item textures are made in 16x16 pixel squares, so any software than can make transparent png's will do.
## Adding Your New Tool
Now we need to move back to our main class and add the lines to first declare than register our new tool. Tools follow this format:
```
public static ToolItem <NAME> = new <TOOL>Item(<CLASS>, int baseDamage, float swingSpeed (written as a negative number), new Item.Settings().group(ItemGroup.COMBAT));
```
This is lengthy and annoying to navigate through, so it may serve you well to ENTER around the commas to make a more readable list of attributes. Nevertheless, for our emerald sword, the declaration should look something like this:
```
public static ToolItem EMERALD_SWORD = new SwordItem(EmeraldItem.INSTANCE, 4, -2.4F, new Item.Settings().group(ItemGroup.COMBAT));
```
As for the pickaxe, once you have created the .json and .png files for it in the resources, you can declare very similarly, but instead of using "SwordItem", use the name of the custom class you made before, like how I used "EmeraldPickaxeTool".
Lastly, we need to register our item. The registry goes similarly as before:
```
Registry.register(Registry.ITEM, new Identifier("emeraldtools", "emerald_sword"), EMERALD_SWORD);
```
This points it to the .json file so that it can properly texture and render the item. And at last, you've added a brand new sword to the game! Go into Creative Mode and check the Combat tab at the bottom, and you should see the emerald sword there. Go ahead and play around with all of its attributes to make sure they're working similarly to how you coded them.
## Enhancements
From here, you are let free to expand on these items as you would like. Here's a small checklist of ideas for you to get some ideas of how you'd like to expand this mod:
- [ ] Create an emerald pickaxe
- [ ] Create an emerald shovel, and hoe
- [ ] Add renames to all the items, so they don't show their ID's
- [ ] Add [crafting recipes](https://fabricmc.net/wiki/tutorial:recipes) for each of these items
- [ ] Add these items to loot pools (dungeon chests, villager trades, enemy drops, or otherwise)