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/17 01:07] – finally updated this page cringestar_boi | tutorial:shield [2024/01/14 18:05] (current) – fixed model cringestar_boi | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Making a Custom Shield in Minecraft [1.20] ====== | + | ====== Making a Custom Shield in Minecraft [1.19-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.\\ | 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, | + | Luckily, |
- | Library | + | The library |
Library compiled as a jar is available at https:// | Library compiled as a jar is available at https:// | ||
Line 29: | Line 29: | ||
</ | </ | ||
- | At the time of writing, latest project.fabric_shield_lib_version should be 1.7.2-1.20.4. | + | At the time of writing, |
+ | * **1.20.2** | ||
+ | * **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 repositories, | **build.gradle** (inside repositories, | ||
<code java> | <code java> | ||
Line 37: | Line 43: | ||
</ | </ | ||
- | __// | + | __// |
===== Adding a custom shield ===== | ===== Adding a custom shield ===== | ||
- | **If you want your shield to support banner decoration on your shield, | + | **If you want your shield to support banner decoration on your shield, |
On to the non-boring steps! We will now make 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 you have followed the above steps correctly and refreshed the project, then you will have the FabricShieldLib |
If so, the first step to do is create a new instance of an Item like: | If so, the first step to do is create a new instance of an Item like: | ||
<code java> | <code java> | ||
Line 89: | Line 95: | ||
<code javascript> | <code javascript> | ||
{ | { | ||
- | " | + | " |
+ | " | ||
+ | " | ||
+ | } | ||
} | } | ||
</ | </ | ||
Line 109: | Line 118: | ||
} | } | ||
</ | </ | ||
- | And with that, your shield is done! | + | And with that, your non-decorateable |
+ | |||
+ | ===== Adding a custom shield with banner support ===== | ||
+ | The process is slightly different if you want to make your shield accept banners and decorateable like a vanilla shield. | ||
+ | |||
+ | We still make the item in the same way, just make it a FabricBannerShieldItem: | ||
+ | <code java> | ||
+ | public static final Item NETHERITE_BANNER_SHIELD = new FabricBannerShieldItem(new FabricItemSettings().maxDamage(2500), | ||
+ | </ | ||
+ | |||
+ | Then, we have to register it: | ||
+ | |||
+ | <code java> | ||
+ | Registry.register(Registries.ITEM, | ||
+ | </ | ||
+ | |||
+ | If you want to add your shield to a creative tab, add this into your '' | ||
+ | <code java> | ||
+ | ItemGroupEvents.modifyEntriesEvent(ItemGroups.COMBAT).register(entries -> { | ||
+ | entries.addAfter(Items.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> | ||
+ | public class ExampleModClient implements ClientModInitializer { | ||
+ | |||
+ | public static final EntityModelLayer netherite_banner_shield_model_layer = new EntityModelLayer(new Identifier(" | ||
+ | |||
+ | @Override | ||
+ | public void onInitializeClient() { | ||
+ | |||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Next, we will register out '' | ||
+ | |||
+ | <code java> | ||
+ | public class ExampleModClient implements ClientModInitializer { | ||
+ | |||
+ | public static final EntityModelLayer NETHERITE_SHIELD_MODEL_LAYER = new EntityModelLayer(new Identifier(" | ||
+ | |||
+ | @Override | ||
+ | public void onInitializeClient() { | ||
+ | EntityModelLayerRegistry.registerModelLayer(netherite_banner_shield_model_layer, | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Then we will create our shield model, | ||
+ | |||
+ | <code java> | ||
+ | public class ExampleModClient implements ClientModInitializer { | ||
+ | |||
+ | public static final EntityModelLayer NETHERITE_SHIELD_MODEL_LAYER = new EntityModelLayer(new Identifier(" | ||
+ | |||
+ | public static ShieldEntityModel modelNetheriteShield; | ||
+ | |||
+ | @Override | ||
+ | public void onInitializeClient() { | ||
+ | EntityModelLayerRegistry.registerModelLayer(NETHERITE_SHIELD_MODEL_LAYER, | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | And then register that shield model, | ||
+ | |||
+ | <code java> | ||
+ | public class ExampleModClient implements ClientModInitializer { | ||
+ | |||
+ | public static final EntityModelLayer NETHERITE_SHIELD_MODEL_LAYER = new EntityModelLayer(new Identifier(" | ||
+ | |||
+ | 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> | ||
+ | public class ExampleModClient implements ClientModInitializer { | ||
+ | |||
+ | public static final EntityModelLayer netherite_banner_shield_model_layer = new EntityModelLayer(new Identifier(" | ||
+ | |||
+ | 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 are going to register our shield with the '' | ||
+ | <code java> | ||
+ | public class ExampleModClient implements ClientModInitializer { | ||
+ | |||
+ | public static final EntityModelLayer netherite_banner_shield_model_layer = new EntityModelLayer(new Identifier(" | ||
+ | |||
+ | 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. \\ | ||
+ | |||
+ | First, create a '' | ||
+ | |||
+ | Inside of it, you will have to list your '' | ||
+ | <code javascript> | ||
+ | { | ||
+ | " | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | ] | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Next, inside '' | ||
+ | |||
+ | <code javascript> | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | } | ||
+ | ] | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | In the same folder, create another file, '' | ||
+ | <code javascript> | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | For this next step, you will add a '' | ||
+ | Then, you will need to make a '' | ||
+ | |||
+ | Then, you will move both of these textures into '' | ||
+ | |||
+ | Lastly, create a '' | ||
+ | <code javascript> | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | ] | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Don't forget to add it to **en_us.json** in '' | ||
+ | <code javascript> | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | And now your shield is fully completed and supports banner decoration! | ||
+ | |||
+ | ===== Changes for 1.19 ===== | ||
+ | If you are working in 1.19, make sure to change the FabricShieldLib and FAPI versions accordingly as well as changing your Midnight Lib and Mod Menu dependencies to these versions: | ||
+ | **gradle.properties** | ||
+ | <code java> | ||
+ | midnightlib_version=1.0.0-fabric | ||
+ | mod_menu_version=4.2.0-beta.2 | ||
+ | </ |
tutorial/shield.1702775249.txt.gz · Last modified: 2023/12/17 01:07 by cringestar_boi