https://www.youtube.com/watch?v=SqMGHoBOeYY
Fork the project from https://github.com/FabricMC/fabric-example-mod
Fabric Properties Bring the latest version information from https://fabricmc.net/use and copy it
Mod Properties
net. in maven_group. net.handle name.MOD name is appropriate (it's really appropriate, so check later if you have a habitDependencies Good as it is
Execute gradlew genSources, gradlew vs code from the VS code terminal. It takes a lot of time.
at the beginning ofsrc / main / resources / fablic.mod.json`. Hereafter, this is called "MOD_ID".in the same file as appropriate. Is it okay to saygroup name.mod name`?
Change the latter section if you feel like changingCreate the same folder and class as the entry point under src / main / java. Like src / main / java / net / handle name / mod name / mod name.java.
Write the following code in the entry point class
ExampleMod.java
package net.realanalysis.testmod;
import net.fabricmc.api.ModInitializer;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.Item;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
public class ExampleMod implements ModInitializer{
    public static final Item FABRIC_ITEM = new Item(new Item.Settings().group(ItemGroup.MISC));
    //Definition of the item itself
    @Override
    public void onInitialize() {
        Registry.register(Registry.ITEM, new Identifier("MOD_ID","Item name"), FABRIC_ITEM);
        //Item registration
    }
}
This will add an item without texture
Click the bug mark to the left of the VS code and click the start button above the sidebar to launch Minecraft
Create a class that inherits the ʻITEM` class in the same folder as the entry point
TestItem.java
package net.realanalysis.testmod;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
import net.minecraft.world.World;
public class TestItem extends Item{
	public TestItem(Settings item$Settings_1) {
		super(item$Settings_1);
                //The constructor calls the superclass as it is
	}
    
    @Override
    public TypedActionResult<ItemStack> use(World world, PlayerEntity playerEntity, Hand hand){
        playerEntity.playSound(SoundEvents.BLOCK_WOOL_BREAK, 1.0F, 1.0F);
        return new TypedActionResult<ItemStack>(ActionResult.SUCCESS, playerEntity.getStackInHand(hand));
        //Right-click to make the sound of breaking wool
    }
}
Then rewrite the entry point class like this
ExampleMod.java
package net.realanalysis.testmod;
import net.fabricmc.api.ModInitializer;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.Item;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
public class ExampleMod implements ModInitializer{
    public static final Item FABRIC_ITEM = new TestItem(new Item.Settings().group(ItemGroup.MISC));
    //I made it a definition in my own class
    @Override
    public void onInitialize() {
        Registry.register(Registry.ITEM, new Identifier("MOD_ID","Item name"), FABRIC_ITEM);
        //Item registration
    }
}
Right-click and you should hear a sound.
Create the following JSON file in src \ main \ resources \ assets \ Mod_ID \ models \ item.
Item name.json
{
    "parent" :"item/generated",
    "textures" : {
        "layer0" : "MOD_ID:item/Item name"
    }
}
If you put a 16 * 16 transparent PNG image in src \ main \ resources \ assets \ testmod \ textures \ item, the item should be that image.
Recommended Posts