tutorial:shield
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| tutorial:shield [2025/06/18 00:49] – cringestar_boi | tutorial:shield [2025/11/13 23:28] (current) – Updated to 1.21.5 and added and added a section on the conditional model format needed to make the shield work bouncingelf10 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Making a Custom Shield in Minecraft [1.19-1.21.1] ====== | + | ====== Making a Custom Shield in Minecraft [1.19-1.21.5] ====== |
| :!: The tutorial depends on third-party libraries. | :!: The tutorial depends on third-party libraries. | ||
| Congrats! You just learned how to create your custom tools 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. | Congrats! You just learned how to create your custom tools 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, StellarWind22 has already made a library to help with this! If she didn' | + | Luckily, StellarWind22 has already made a library to help with this! If she didn' |
| - | The library source is available at https:// | + | The library source is available at https:// |
| Library compiled as a jar is available at https:// | Library compiled as a jar is available at https:// | ||
| Line 16: | Line 16: | ||
| **gradle.properties** | **gradle.properties** | ||
| <file properties gradle.properties> | <file properties gradle.properties> | ||
| - | fabric_shield_lib_version=1.7.2-1.21.1 | + | fabric_shield_lib_version=1.8.3-1.21.5 |
| - | midnightlib_version=1.5.8-fabric | + | mod_menu_version=14.0.0 |
| - | mod_menu_version=11.0.1 | + | midnightlib_version=1.7.3+1.21.4-fabric |
| fabricasm_version=2.3 | fabricasm_version=2.3 | ||
| </ | </ | ||
| + | |||
| + | Find the corresponding mod versions for your Minecraft version | ||
| **build.gradle** (under '' | **build.gradle** (under '' | ||
| Line 30: | Line 32: | ||
| </ | </ | ||
| - | At the time of writing, the latest project.fabric_shield_lib_version should be 1.7.2, which supports versions: | + | At the time of writing, |
| + | * **1.21.5** ('' | ||
| + | * **1.21.4** ('' | ||
| + | * **1.21.2** - **1.21.3** ('' | ||
| * **1.21** - **1.21.1** ('' | * **1.21** - **1.21.1** ('' | ||
| * **1.20.5** - **1.20.6** ('' | * **1.20.5** - **1.20.6** ('' | ||
| Line 55: | Line 60: | ||
| If you have followed the above steps correctly and refreshed the project, then you will have the FabricShieldLib installed. | If you have followed the above steps correctly and refreshed the project, then you will have the FabricShieldLib installed. | ||
| - | If so, the first step to do is create a new instance of an '' | + | If so, the first step to do is create a new instance of an '' |
| <code java TutorialItems> | <code java TutorialItems> | ||
| public final class TutorialItems { | public final class TutorialItems { | ||
| // ... | // ... | ||
| - | public static final Item NETHERITE_SHIELD = register(new FabricShieldItem(new Item.Settings().maxDamage(2500), 10, 13, Items.NETHERITE_INGOT)," | + | public static final Item NETHERITE_SHIELD = register(" |
| - | //The constructor for the item takes in the following values: FabricBannerShieldItem(settings.maxDamage(durability), | + | //The constructor for the item takes in the following values: FabricBannerShieldItem(settings.maxDamage(durability), |
| // ... | // ... | ||
| } | } | ||
| Line 69: | Line 74: | ||
| < | < | ||
| public class ExampleMod implements ModInitializer { | public class ExampleMod implements ModInitializer { | ||
| + | ... | ||
| @Override | @Override | ||
| public void onInitialize() { | public void onInitialize() { | ||
| + | ... | ||
| ItemGroupEvents.modifyEntriesEvent(ItemGroups.COMBAT).register(entries -> { | ItemGroupEvents.modifyEntriesEvent(ItemGroups.COMBAT).register(entries -> { | ||
| entries.add(NETHERITE_SHIELD); | entries.add(NETHERITE_SHIELD); | ||
| }); | }); | ||
| + | ... | ||
| } | } | ||
| + | ... | ||
| } | } | ||
| </ | </ | ||
| Line 90: | Line 99: | ||
| <file javascript resources/ | <file javascript resources/ | ||
| { | { | ||
| - | | + | |
| - | " | + | " |
| - | " | + | " |
| - | }, | + | } |
| - | " | + | |
| - | { | + | |
| - | " | + | |
| - | " | + | |
| - | }, | + | |
| - | " | + | |
| - | } | + | |
| - | ] | + | |
| } | } | ||
| </ | </ | ||
| Line 111: | Line 112: | ||
| " | " | ||
| " | " | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | Assuming you've made the Item correctly, you should' | ||
| + | <file javascript resources/ | ||
| + | { | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | }, | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | } | ||
| } | } | ||
| } | } | ||
| Line 148: | Line 167: | ||
| We still make the item in the same way, just make it a '' | We still make the item in the same way, just make it a '' | ||
| <code java TutorialItems> | <code java TutorialItems> | ||
| - | public static final Item NETHERITE_BANNER_SHIELD = register(new FabricBannerShieldItem(new Item.Settings().maxDamage(2500), 10, 13, Items.NETHERITE_INGOT), | + | public static final Item NETHERITE_BANNER_SHIELD = register(" |
| </ | </ | ||
| If you want to add your shield to a [[itemgroup|item groups]], for example, the " | If you want to add your shield to a [[itemgroup|item groups]], for example, the " | ||
| Line 255: | Line 274: | ||
| </ | </ | ||
| - | Finally, we are going to register | + | 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> | <code java> | ||
| - | @Environment(EnvType.CLIENT) | + | public static final Item NETHERITE_BANNER_SHIELD = register(" |
| - | public class ExampleModClient implements ClientModInitializer { | + | settings -> new FabricBannerShieldItem(settings, |
| - | public static final EntityModelLayer netherite_banner_shield_model_layer = new EntityModelLayer(Identifier.of(" | + | new Item.Settings().maxDamage(2500).component(FabricShieldLib.MODEL_COMPONENT, |
| + | new FabricShieldModelComponent( | ||
| + | ExampleModClient.NETHERITE_BANNER_SHIELD_BASE.getTextureId(), //Your base texture, from the client initializer | ||
| + | ExampleModClient.NETHERITE_BANNER_SHIELD_BASE_NO_PATTERN.getTextureId(), //Your no-pattern texture, from the client initializer | ||
| + | ExampleModClient.netherite_banner_shield_model_layer.toString() // Your model layer, from the client initializer | ||
| + | ))); | ||
| - | 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; | ||
| - | }); | ||
| - | |||
| - | 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. | ||
| - | }); | ||
| - | } | ||
| - | } | ||
| - | </ | ||
| That is all of our code done, we only have a few json files to make. | That is all of our code done, we only have a few json files to make. | ||
| Line 302: | Line 308: | ||
| Next, inside '' | Next, inside '' | ||
| - | <code javascript resources/ | + | <code javascript resources/ |
| { | { | ||
| - | " | + | " |
| - | " | + | |
| - | { | + | |
| - | " | + | |
| - | " | + | |
| - | }, | + | |
| - | " | + | |
| - | } | + | |
| - | ] | + | |
| } | } | ||
| </ | </ | ||
| In the same folder, create another file, '' | In the same folder, create another file, '' | ||
| - | <code javascript resources/ | + | <code javascript resources/ |
| { | { | ||
| - | " | + | " |
| - | " | + | |
| - | " | + | |
| - | } | + | |
| } | } | ||
| </ | </ | ||
| Line 375: | Line 370: | ||
| And now your shield is fully completed and supports banner decoration! | 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/ | ||
| + | { | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | }, | ||
| + | " | ||
| + | { | ||
| + | " | ||
| + | " | ||
| + | }, | ||
| + | " | ||
| + | } | ||
| + | ] | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | <code javascript resources/ | ||
| + | { | ||
| + | " | ||
| + | " | ||
| + | { | ||
| + | " | ||
| + | " | ||
| + | }, | ||
| + | " | ||
| + | } | ||
| + | ] | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | <code javascript resources/ | ||
| + | { | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ===== 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 your Item registries to match the old method at the [[items]] tutorial. Your item registry lines would look like this: | ||
| + | |||
| + | <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 ===== | ===== Changes for 1.20.6 ===== | ||
| - | If you are working in 1.20.6, first change the FabricShieldLib and FAPI versions accordingly and change your other dependencies to these versions:\\ | + | If you are working in 1.20.6, |
| <file properties gradle.properties> | <file properties gradle.properties> | ||
| Line 391: | Line 475: | ||
| ===== Changes for 1.20.4 ===== | ===== Changes for 1.20.4 ===== | ||
| - | If you are working in 1.20.4, **follow the changes for 1.20.6 | + | If you are working in 1.20.4, **follow the changes for all higher versions |
| **gradle.properties** | **gradle.properties** | ||
| Line 400: | Line 484: | ||
| Additionally, | 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 ===== | ===== Changes for 1.19 ===== | ||
| - | If you are working in 1.19, **follow the changes for 1.20.6 and 1.20.4 | + | If you are working in 1.19, **follow the changes for all higher versions |
| **gradle.properties** | **gradle.properties** | ||
| Line 409: | Line 502: | ||
| mod_menu_version=4.2.0-beta.2 | mod_menu_version=4.2.0-beta.2 | ||
| </ | </ | ||
| + | |||
tutorial/shield.1750207754.txt.gz · Last modified: 2025/06/18 00:49 by cringestar_boi