User Tools

Site Tools


tutorial:shield

This is an old revision of the document!


Making a Custom Shield in Minecraft [1.20]

Congrats! You just learned how to create your custom sword in the last tutorial! Now imagine you want to shield yourself from that sword if your friend got it. If you made it too op, a regular shield won't do. So we will see how to make a custom shield.
Luckily, CrimsonDawn45 has already made a library to help with this! If he didn't, you probably would be sitting here for the next hour to follow this tutorial, so thanks CrimsonDawn45!

Library source is available at https://github.com/CrimsonDawn45/Fabric-Shield-Lib

Library compiled as a jar is available at https://www.curseforge.com/minecraft/mc-mods/fabric-shield-lib

Adding the library to your project

Add the following code to the files mentioned:

gradle.properties

fabric_shield_lib_version=1.7.2-1.20.4
midnightlib_version=1.5.2-fabric
mod_menu_version=9.0.0-pre.1
fabricasm_version=2.3


build.gradle (under dependencies)

	modImplementation "com.github.CrimsonDawn45:Fabric-Shield-Lib:v${project.fabric_shield_lib_version}"
 
	modImplementation "com.terraformersmc:modmenu:${project.mod_menu_version}"
 
	modImplementation "maven.modrinth:midnightlib:${project.midnightlib_version}"
 
	modImplementation "com.github.Chocohead:Fabric-ASM:v${project.fabricasm_version}"


At the time of writing, latest project.fabric_shield_lib_version should be 1.7.2-1.20.4. This page will be updated whenever a new update comes out.

build.gradle (inside repositories, the one above dependencies)

	maven {url = 'https://jitpack.io'}
	maven {url "https://maven.terraformersmc.com/releases/"}
	maven {url = "https://api.modrinth.com/maven"}


Midnight Lib and FabricASM are included in FabricShieldLib release (.jar on Curseforge/Modrinth) but need to be used as dependencies when developing

Adding a custom shield

If you want your shield to support banner decoration on your shield, please skip to the next section
On to the non-boring steps! We will now make a custom shield!

If you have followed the above steps correctly and refreshed the project, then you will have the fabric shield api installed.
If so, the first step to do is create a new instance of an Item like:

public static final Item NETHERITE_SHIELD = new FabricShieldItem(new FabricItemSettings().maxDamage(2500), 10, 13, Items.NETHERITE_INGOT); // FabricShieldItem(settings.maxDamage(durability), cooldownTicks, enchantability, repairItems)

Then, we have to register it, like so:

Registry.register(Registries.ITEM, new Identifier("examplemod", "netherite_shield"), NETHERITE_SHIELD);

If you want to add your shield to a creative tab, add this into your onInitialize() method:

ItemGroupEvents.modifyEntriesEvent(ItemGroups.COMBAT).register(entries -> {
	entries.add(NETHERITE_SHIELD);
});

And our shield is (code-wise) done!
Now, we have to create the textures and models of the shield.
For the texture, you can use anything. A good place to start is to look at Mojang's shield texture and change it. Put it in resources/assets/examplemod/textures/item/netherite_shield.png
Now, for the models, we have to write a few .json files.

Inside resources/assets/examplemod/models/item/, create a netherite_shield.json file and put this inside it:

{
    "parent":"fabricshieldlib:item/fabric_shield",
    "textures":{
        "shield":"examplemod:item/netherite_shield"
    },
    "overrides": [
        {
            "predicate": {
                "blocking": 1
            },
            "model": "examplemod:item/netherite_shield_blocking"
        }
    ]
}


In the same folder, create another file, netherite_shield_blocking.json, and put his inside it:

{
  "parent": "fabricshieldlib:item/fabric_shield_blocking"
}


Lastly, create a shields.json file in resources/data/c/tags/items/shields.json and add your shield to it:

{
  "replace": false,
  "values": [
    "examplemod:netherite_shield"
  ]
}


Don't forget to add it to en_us.json in resources/assets/lang/en_us.json

{
  "item.examplemod.netherite_shield": "Netherite Shield"
}


And with that, your shield is done!

tutorial/shield.1703189593.txt.gz · Last modified: 2023/12/21 20:13 by cringestar_boi