[JAVA] MOD development notes using Minecraft 14.4 Fabric API # 1

Target

Exhibit

https://www.youtube.com/watch?v=SqMGHoBOeYY

Preparation

Fork the project from https://github.com/FabricMC/fabric-example-mod

Mod basic information setting 1

Fabric Properties Bring the latest version information from https://fabricmc.net/use and copy it

Mod Properties

Dependencies Good as it is

Dependent source preparation

Execute gradlew genSources, gradlew vs code from the VS code terminal. It takes a lot of time.

Mod basic information setting 2

Creating an entry point

Create 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.

Add item

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

Verification

Click the bug mark to the left of the VS code and click the start button above the sidebar to launch Minecraft

Initialize in your own class

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.

texture

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

MOD development notes using Minecraft 14.4 Fabric API # 1
Development of Flink using DataStream API
[Rails 6] API development using GraphQL (Query)
minecraft1.14.4 MOD development memorandum 1 [Original recipe]
Error summary when creating Minecraft MOD development environment
DSL development using ANTLR 4.7.1