tutorial:shield
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tutorial:shield [2023/12/21 20:15] – cringestar_boi | tutorial:shield [2025/06/21 18:39] (current) – updated to 1.21.4 cringestar_boi | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Making a Custom Shield in Minecraft [1.20] ====== | + | ====== Making a Custom Shield in Minecraft [1.19-1.21.4] ====== |
+ | :!: The tutorial depends on third-party libraries. | ||
- | Congrats! You just learned how to create your custom | + | Congrats! You just learned how to create your custom |
- | Luckily, CrimsonDawn45 has already made a library to help with this! If he didn' | + | |
- | Library | + | Luckily, StellarWind22 has already made a library to help with this! If she didn' |
+ | |||
+ | The library | ||
Library compiled as a jar is available at https:// | Library compiled as a jar is available at https:// | ||
Line 10: | Line 12: | ||
===== Adding the library to your project ===== | ===== Adding the library to your project ===== | ||
- | Add the following code to the files mentioned:\\ \\ | + | Add the following code to the files mentioned: |
- | **gradle.properties**\\ | + | |
- | <code java> | + | **gradle.properties** |
- | fabric_shield_lib_version=1.7.2-1.20.4 | + | <file properties gradle.properties> |
- | midnightlib_version=1.5.2-fabric | + | fabric_shield_lib_version=1.8.0-1.21.4 |
- | mod_menu_version=9.0.0-pre.1 | + | mod_menu_version=13.0.0 |
+ | midnightlib_version=1.6.6-fabric | ||
fabricasm_version=2.3 | fabricasm_version=2.3 | ||
- | </code>\\ | + | </file> |
- | **build.gradle** (under dependencies)\\ | + | |
- | <code java> | + | |
- | modImplementation " | + | |
+ | **build.gradle** (under '' | ||
+ | <file groovy build.gradle> | ||
+ | modImplementation " | ||
modImplementation " | modImplementation " | ||
- | |||
modImplementation " | modImplementation " | ||
- | |||
modImplementation " | modImplementation " | ||
- | </code>\\ | + | </file> |
- | At the time of writing, | + | At the time of writing, |
- | **build.gradle** (inside repositories, the one above dependencies)\\ | + | * **1.21.4** ('' |
- | <code java> | + | * **1.21.2** - **1.21.3** ('' |
+ | * **1.21** - **1.21.1** ('' | ||
+ | * **1.20.5** - **1.20.6** ('' | ||
+ | * **1.20.2** - **1.20.4** ('' | ||
+ | * **1.20** - **1.20.1** ('' | ||
+ | * **1.19.3** - **1.19.4** ('' | ||
+ | * **1.19** - **1.19.2** ('' | ||
+ | * **1.18.2** ('' | ||
+ | * **1.17.1** ('' | ||
+ | **build.gradle** (inside | ||
+ | <file groovy build.gradle> | ||
maven {url = ' | maven {url = ' | ||
maven {url " | maven {url " | ||
maven {url = " | maven {url = " | ||
- | </code> | + | </file> |
- | __// | + | __// |
===== Adding a custom shield ===== | ===== Adding a custom shield ===== | ||
- | **If you want your shield to support banner decoration on your shield, please skip to the next section**\\ | + | **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.\\ | + | On to the non-boring steps! We will now make a custom shield! |
- | If so, the first step to do is create a new instance of an Item like: | + | |
- | <code java> | + | If you have followed the above steps correctly and refreshed the project, then you will have the FabricShieldLib |
- | public static final Item NETHERITE_SHIELD = new FabricShieldItem(new FabricItemSettings().maxDamage(2500), 10, 13, Items.NETHERITE_INGOT); | + | |
+ | If so, the first step to do is create a new instance of an '' | ||
+ | <code java TutorialItems> | ||
+ | public final class TutorialItems { | ||
+ | // ... | ||
+ | | ||
+ | | ||
+ | // ... | ||
+ | } | ||
</ | </ | ||
- | Then, we have to register | + | If you want to add your shield to a [[itemgroup|item groups]], for example, the " |
+ | |||
+ | < | ||
+ | public class ExampleMod implements ModInitializer { | ||
+ | ... | ||
+ | @Override | ||
+ | public void onInitialize() { | ||
+ | ... | ||
+ | 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' | ||
+ | |||
+ | Now, for the models, we have to write a few .json files. | ||
+ | |||
+ | Inside '' | ||
+ | |||
+ | <file javascript resources/ | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | In the same folder, create another file, '' | ||
+ | <file javascript resources/ | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Then, as a [[tags|conventional tag]], create a '' | ||
+ | <code javascript resources/ | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | ] | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Lastly, to make it enchantable, | ||
+ | <code javascript resources/ | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | ] | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Don't forget to add it to **en_us.json** in '' | ||
+ | <code javascript resources/ | ||
+ | { | ||
+ | " | ||
+ | } | ||
+ | </ | ||
+ | And with that, your non-decorateable shield is done! | ||
+ | |||
+ | ===== Adding a custom shield with banner support ===== | ||
+ | The process is slightly different if you want to make your shield accept banners and decorateable | ||
+ | |||
+ | We still make the item in the same way, just make it a '' | ||
+ | <code java TutorialItems> | ||
+ | public static final Item NETHERITE_BANNER_SHIELD = register(" | ||
+ | </ | ||
+ | If you want to add your shield to a [[itemgroup|item groups]], for example, the " | ||
+ | < | ||
+ | public class ExampleMod implements ModInitializer { | ||
+ | @Override | ||
+ | public void onInitialize() { | ||
+ | ItemGroupEvents.modifyEntriesEvent(ItemGroups.COMBAT).register(entries -> { | ||
+ | // ... | ||
+ | entries.add(NETHERITE_BANNER_SHIELD); | ||
+ | }); | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Now the item is created, we need to set up its rendering. For these steps, we are going to be working in our client mod initializer, | ||
+ | |||
+ | First, we will need to create an '' | ||
<code java> | <code java> | ||
- | Registry.register(Registries.ITEM, new Identifier(" | + | @Environment(EnvType.CLIENT) |
+ | public class ExampleModClient implements ClientModInitializer { | ||
+ | public static final EntityModelLayer NETHERITE_BANNER_SHIELD_MODEL_LAYER = new EntityModelLayer(Identifier.of("tutorial", "netherite_banner_shield")," | ||
+ | |||
+ | @Override | ||
+ | public void onInitializeClient() { | ||
+ | |||
+ | } | ||
+ | } | ||
</ | </ | ||
- | If you want to add your shield to a creative tab, add this into your '' | + | Next, we will register out '' |
<code java> | <code java> | ||
- | ItemGroupEvents.modifyEntriesEvent(ItemGroups.COMBAT).register(entries -> { | + | @Environment(EnvType.CLIENT) |
- | entries.add(NETHERITE_SHIELD); | + | public class ExampleModClient implements ClientModInitializer { |
- | }); | + | |
+ | public static final EntityModelLayer NETHERITE_SHIELD_MODEL_LAYER = new EntityModelLayer(Identifier.of(" | ||
+ | |||
+ | @Override | ||
+ | public void onInitializeClient() | ||
+ | EntityModelLayerRegistry.registerModelLayer(NETHERITE_BANNER_SHILED_MODEL_LAYER, | ||
+ | } | ||
+ | } | ||
</ | </ | ||
- | And our shield is (code-wise) done!\\ | + | Then we will create |
- | Now, we have to create | + | |
- | For the texture, you can use anything. A good place to start is to look at Mojang' | + | |
- | Now, for the models, we have to write a few .json files.\\ | + | |
+ | <code java> | ||
+ | @Environment(EnvType.CLIENT) | ||
+ | public class ExampleModClient implements ClientModInitializer { | ||
+ | public static final EntityModelLayer NETHERITE_SHIELD_MODEL_LAYER = new EntityModelLayer(Identifier.of(" | ||
+ | | ||
+ | public static ShieldEntityModel modelNetheriteShield; | ||
- | Inside '' | + | @Override |
+ | public void onInitializeClient() { | ||
+ | EntityModelLayerRegistry.registerModelLayer(NETHERITE_SHIELD_MODEL_LAYER, ShieldEntityModel:: | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | And then register that shield model, | ||
+ | |||
+ | <code java> | ||
+ | @Environment(EnvType.CLIENT) | ||
+ | public class ExampleModClient implements ClientModInitializer { | ||
+ | public static final EntityModelLayer NETHERITE_SHIELD_MODEL_LAYER = new EntityModelLayer(Identifier.of(" | ||
+ | | ||
+ | public static ShieldEntityModel modelNetheriteShield; | ||
+ | |||
+ | @Override | ||
+ | public void onInitializeClient() { | ||
+ | EntityModelLayerRegistry.registerModelLayer(NETHERITE_SHIELD_MODEL_LAYER, | ||
+ | | ||
+ | ShieldSetModelCallback.EVENT.register((loader) -> { | ||
+ | modelNetheriteShield = new ShieldEntityModel(loader.getModelPart(netherite_banner_shield_model_layer)); | ||
+ | return ActionResult.PASS; | ||
+ | }); | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Next, we have to create our two '' | ||
+ | <code java> | ||
+ | @Environment(EnvType.CLIENT) | ||
+ | public class ExampleModClient implements ClientModInitializer { | ||
+ | |||
+ | public static final EntityModelLayer netherite_banner_shield_model_layer = new EntityModelLayer(Identifier.of(" | ||
+ | |||
+ | public static ShieldEntityModel modelNetheriteShield; | ||
+ | |||
+ | public static final SpriteIdentifier NETHERITE_BANNER_SHIELD_BASE = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, | ||
+ | public static final SpriteIdentifier NETHERITE_BANNER_SHIELD_BASE_NO_PATTERN = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, | ||
+ | |||
+ | @Override | ||
+ | public void onInitializeClient() { | ||
+ | EntityModelLayerRegistry.registerModelLayer(NETHERITE_SHIELD_MODEL_LAYER, | ||
+ | | ||
+ | ShieldSetModelCallback.EVENT.register((loader) -> { | ||
+ | modelNetheriteShield = new ShieldEntityModel(loader.getModelPart(netherite_banner_shield_model_layer)); | ||
+ | return ActionResult.PASS; | ||
+ | }); | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Finally, we will want to go back to our item and add a component to it to store its model information like so: | ||
+ | |||
+ | <code java> | ||
+ | public static final Item NETHERITE_BANNER_SHIELD = register(" | ||
+ | settings -> new FabricBannerShieldItem(settings, | ||
+ | new Item.Settings().maxDamage(2500).component(FabricShieldLib.MODEL_COMPONENT, | ||
+ | new FabricShieldModelComponent( | ||
+ | ExampleModClient.NETHERITE_BANNER_SHIELD_BASE.getTextureId(), | ||
+ | ExampleModClient.NETHERITE_BANNER_SHIELD_BASE_NO_PATTERN.getTextureId(), | ||
+ | ExampleModClient.netherite_banner_shield_model_layer.toString() // Your model layer, from the client initializer | ||
+ | ))); | ||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | That is all of our code done, we only have a few json files to make. | ||
+ | |||
+ | First, create a '' | ||
+ | <code javascript resources/ | ||
+ | { | ||
+ | " | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | ] | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Next, inside '' | ||
+ | <code javascript resources/ | ||
+ | { | ||
+ | " | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | In the same folder, create another file, '' | ||
+ | <code javascript resources/ | ||
+ | { | ||
+ | " | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | For this next step, you will add a '' | ||
+ | |||
+ | Then, you will move both of these textures into '' | ||
+ | |||
+ | Next, create a '' | ||
+ | <code javascript resources/ | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | ] | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Finally create a '' | ||
+ | <code javascript resources/ | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | ] | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Don't forget to add it to **en_us.json** in '' | ||
<code javascript> | <code javascript> | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | And now your shield is fully completed and supports banner decoration! | ||
+ | ===== Changes for 1.21.3 ===== | ||
+ | If you are working in 1.21.3, **follow the changes for all higher versions first**, then change the FabricShieldLib and FAPI versions accordingly and change your other dependencies to these versions:\\ | ||
+ | |||
+ | <file properties gradle.properties> | ||
+ | mod_menu_version=12.0.0-beta.1 | ||
+ | midnightlib_version=1.6.4-fabric | ||
+ | </ | ||
+ | |||
+ | Next, remove the '' | ||
+ | |||
+ | <code java> | ||
+ | ... | ||
+ | import static com.github.crimsondawn45.fabricshieldlib.initializers.FabricShieldLibClient.renderBanner; | ||
+ | ... | ||
+ | public class ExampleModClient implements ClientModInitializer { | ||
+ | ... | ||
+ | @Override | ||
+ | public void onInitializeClient() { | ||
+ | ... | ||
+ | BuiltinItemRendererRegistry.INSTANCE.register(ExampleMod.NETHERITE_BANNER_SHIELD, | ||
+ | renderBanner(stack, | ||
+ | //The first five parameters are taken from the method, while the last 3 you provide yourself. | ||
+ | //You will provide the model, and then your 2 sprite identifiers in the order of SHIELD_NAME_BASE and then SHIELD_NAME_BASE_NOPATTERN. | ||
+ | }); | ||
+ | ... | ||
+ | } | ||
+ | ... | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Finally, change the following models to these formats: (netherite_shield_blocking.json will be unchanged) | ||
+ | |||
+ | <file javascript resources/ | ||
{ | { | ||
" | " | ||
" | " | ||
- | " | + | " |
}, | }, | ||
" | " | ||
Line 80: | Line 392: | ||
" | " | ||
}, | }, | ||
- | " | + | " |
} | } | ||
] | ] | ||
} | } | ||
- | </code>\\ | + | </file> |
- | In the same folder, create another file, '' | + | <code javascript |
- | <code javascript> | + | |
{ | { | ||
- | " | + | " |
- | } | + | " |
- | </ | + | { |
- | + | " | |
- | Lastly, create a '' | + | "blocking": |
- | <code javascript> | + | }, |
- | { | + | "model": "tutorial:item/ |
- | "replace": | + | } |
- | "values": | + | |
- | | + | |
] | ] | ||
} | } | ||
- | </ | + | </ |
- | Don't forget to add it to **en_us.json** in '' | + | <code javascript |
- | <code javascript> | + | |
{ | { | ||
- | "item.examplemod.netherite_shield": "Netherite Shield" | + | "parent":" |
+ | " | ||
+ | | ||
+ | } | ||
} | } | ||
- | </ | + | </ |
- | And with that, your non-decorateable | + | |
+ | ===== Changes for 1.21.1 ===== | ||
+ | If you are working in 1.21.1, **follow the changes for all higher versions first**, then change the FabricShieldLib and FAPI versions accordingly and change your other dependencies to these versions:\\ | ||
+ | |||
+ | <file properties gradle.properties> | ||
+ | mod_menu_version=11.0.1 | ||
+ | midnightlib_version=1.5.8-fabric | ||
+ | </ | ||
+ | |||
+ | Then, update | ||
+ | |||
+ | <code java> | ||
+ | public static final Item NETHERITE_SHIELD = register(new FabricShieldItem(new Item.Settings().maxDamage(2500), | ||
+ | </ | ||
+ | or | ||
+ | <code java> | ||
+ | public static final Item NETHERITE_BANNER_SHIELD = register(new FabricBannerShieldItem(new Item.Settings().maxDamage(2500), | ||
+ | </ | ||
+ | |||
+ | ===== Changes for 1.20.6 ===== | ||
+ | If you are working in 1.20.6, **follow the changes for all higher versions first**, then change the FabricShieldLib and FAPI versions accordingly and change your other dependencies to these versions: | ||
+ | |||
+ | <file properties gradle.properties> | ||
+ | mod_menu_version=10.0.0-beta.1 | ||
+ | midnightlib_version=1.5.5-fabric | ||
+ | </ | ||
+ | |||
+ | Next, change all instances of '' | ||
+ | |||
+ | Then, change your '' | ||
+ | |||
+ | Finally, move your '' | ||
+ | |||
+ | ===== Changes for 1.20.4 ===== | ||
+ | If you are working in 1.20.4, **follow the changes for all higher versions first**, then change the FabricShieldLib and FAPI versions accordingly and change your other dependencies to these versions: | ||
+ | |||
+ | **gradle.properties** | ||
+ | <file properties gradle.properties> | ||
+ | midnightlib_version=1.5.2-fabric | ||
+ | mod_menu_version=9.0.0-pre.1 | ||
+ | </ | ||
+ | |||
+ | Additionally, | ||
+ | |||
+ | ===== Changes for 1.20.1 ===== | ||
+ | If you are working in 1.20.1, **follow the changes for all higher versions first**, then change the FabricShieldLib and FAPI versions accordingly and change your other dependencies to these versions: | ||
+ | |||
+ | **gradle.properties** | ||
+ | <file properties gradle.properties> | ||
+ | midnightlib_version=1.4.1-fabric | ||
+ | mod_menu_version=7.1.0 | ||
+ | </ | ||
+ | |||
+ | ===== Changes for 1.19 ===== | ||
+ | If you are working in 1.19, **follow the changes for all higher versions first**, then change the FabricShieldLib and FAPI versions accordingly and change your other dependencies to these versions: | ||
+ | |||
+ | **gradle.properties** | ||
+ | <file properties gradle.properties> | ||
+ | midnightlib_version=1.0.0-fabric | ||
+ | mod_menu_version=4.2.0-beta.2 | ||
+ | </ | ||
- | ===== Adding a custom shield with banner support ===== | ||
- | If you want to make your shield accept banners and decorateable like a vanilla shield, the process is slightly different. |
tutorial/shield.1703189743.txt.gz · Last modified: 2023/12/21 20:15 by cringestar_boi