User Tools

Site Tools


tutorial:shield

This is an old revision of the document!


Making a Custom Shield in Minecraft

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!

Adding the library to your project

Add the following code to the files mentioned:

gradle.properties

fabric_shield_lib_version=1.3.5


build.gradle (under dependencies)

modImplementation "com.github.CrimsonDawn45:Fabric-Shield-Lib:${project.fabric_shield_lib_version}-20w05b"


At the time of writing, latest project.fabric_shield_lib_version should be 1.3.5, and latest project.minecraft_version should be 21w05b. There is a wrong filename, which makes us have to use 20w05b rather than 21w05b. This page will be updated whenever a new update comes out.

build.gradle (under repositories)

maven { url 'https://jitpack.io' }


Adding a custom shield

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 FabricShield(new FabricItemSettings().group(ItemGroup.TAB_COMBAT), 10, 2500, 13, Items.NETHERITE_INGOT); // FabricShield(settings, cooldownTicks, durability, enchantability, repairItem)


Then, we have to register it, like so:

Registry.register(Registration.ITEMS, new Identifier("shieldtest", "netherite_shield"), NETHERITE_SHIELD)


And our shield is 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 looking at mojang's shield image and changing it. Put it in resources/textures/item/<filename>.png
Now, for the models, we have to write a few .json files.
For the model file without blocking, we use:

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


Put it in resources/models/item/netherite_shield.json
For the blocking model, use this:

{
    "parent":"fabricshieldlib:item/template_shield_blocking",
    "textures":{
        "shield":"moreshields:item/netherite_shield"
    }
}


Plop it in resources/models/item/netherite_shield_blocking.json
Don't forget to add it to en_us.json

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


And with that, your shield is done!

tutorial/shield.1626596136.txt.gz · Last modified: 2021/07/18 08:15 by legiblesleet827