User Tools

Site Tools


tutorial:shield

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
tutorial:shield [2021/10/17 22:31] – Changed lib cringestar_boitutorial:shield [2023/09/26 00:09] – added warning cringestar_boi
Line 1: Line 1:
-====== Making a Custom Shield in Minecraft ======+__**!!OUTDATED AND BEING WORKED ON !!**__ 
 + 
 +====== Making a Custom Shield in Minecraft [1.19-1.14] ======
  
 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.\\ 
Line 5: Line 7:
  
 Library source is available at https://github.com/CrimsonDawn45/Fabric-Shield-Lib 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 ===== ===== Adding the library to your project =====
Line 11: Line 15:
 **gradle.properties**\\  **gradle.properties**\\ 
 <code java> <code java>
-fabric_shield_lib_version=1.4.4+fabric_shield_lib_version=1.6.0-1.19
 </code>\\  </code>\\ 
 **build.gradle** (under dependencies)\\  **build.gradle** (under dependencies)\\ 
 <code java> <code java>
-modImplementation "com.github.CringeStar:Fabric-Shield-Lib:v${project.fabric_shield_lib_version}-${project.minecraft_version}"+modImplementation "com.github.CrimsonDawn45:Fabric-Shield-Lib:v${project.fabric_shield_lib_version}"
 </code>\\  </code>\\ 
-At the time of writing, latest project.fabric_shield_lib_version should be 1.4.4, and latest project.minecraft_version should be 1.17.1. This page will be updated whenever a new update comes out.\\ \\  +At the time of writing, latest project.fabric_shield_lib_version should be 1.6.0-1.19. This page will be updated whenever a new update comes out.\\ \\  
-**build.gradle** (under repositories)\\ +**build.gradle** (under repositories, the one above dependencies)\\ 
 <code java> <code java>
-allprojects { repositories { maven { url 'https://jitpack.io' } } }+ maven { url 'https://jitpack.io' } 
 +</code>\\  
 + 
 +__//**If you are doing this in Minecraft version 1.17 or higher or using FabricShieldLib version 1.5.0 or higher, add these things as well:**//__ 
 + 
 +**gradle.properties**\\  
 +<code java> 
 + fabric_asm_version=2.3 
 + cloth_version=8.1.77 
 + mod_menu_version=4.0.6 
 + crowdlin_version=1.4+1.19 
 +</code>\\  
 + 
 +**(These versions will be updated in this wiki alongside the mod version)** 
 + 
 +**build.gradle** (under dependencies)\\  
 +<code java> 
 + 
 + modApi("me.shedaniel.cloth:cloth-config-fabric:${project.cloth_version}") { 
 + exclude(group: "net.fabricmc.fabric-api"
 +
 + include("me.shedaniel.cloth:cloth-config-fabric:${project.cloth_version}"
 + 
 + modCompileOnly modRuntimeOnly ("com.terraformersmc:modmenu:${project.mod_menu_version}"),
 + exclude(group: "net.fabricmc.fabric-api"
 +
 + 
 + modImplementation("com.github.Chocohead:Fabric-ASM:v${project.fabric_asm_version}") { 
 + exclude (group: "net.fabricmc.fabric-api"
 +
 + include("com.github.Chocohead:Fabric-ASM:v${project.fabric_asm_version}"
 + 
 +</code>\\  
 + 
 +**build.gradle** (under repositories, the one above dependencies)\\  
 +<code java> 
 + maven { url "https://maven.shedaniel.me/"
 + maven { url "https://maven.terraformersmc.com/releases/" }
 </code>\\  </code>\\ 
  
Line 29: Line 70:
 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>
-public static final Item NETHERITE_SHIELD = new FabricShieldItem(new FabricItemSettings().maxDamage(2500).group(ItemGroup.COMBAT), 10, 13, Items.NETHERITE_INGOT, false); // FabricShieldItem(settings.maxDamage(durability), cooldownTicks, enchantability, repairItem, bannerSupport+public static final Item NETHERITE_SHIELD = new FabricShieldItem(new FabricItemSettings().maxDamage(2500).group(ItemGroup.COMBAT), 10, 13, Items.NETHERITE_INGOT); // FabricShieldItem(settings.maxDamage(durability), cooldownTicks, enchantability, repairItem) 
-</code>\\  +</code> 
-Then, we have to register it, like so:\\ + 
 +Then, we have to register it, like so: 
 + 
 <code java> <code java>
-Registry.register(Registry.ITEM, new Identifier("examplemod", "netherite_shield"), NETHERITE_SHIELD) +Registry.register(Registries.ITEM, new Identifier("examplemod", "netherite_shield"), NETHERITE_SHIELD); 
-</code>\\ +</code> 
 And our shield is done!\\  And our shield is done!\\ 
 Now, we have to create the textures and models of the shield.\\  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\\ +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/assets/examplemod/textures/item/<filename>.png''\\ 
 Now, for the models, we have to write a few .json files.\\  Now, for the models, we have to write a few .json files.\\ 
 For the model file without blocking, we use: \\  For the model file without blocking, we use: \\ 
 <code javascript> <code javascript>
 { {
-    "parent":"fabricshieldlib:item/fabric_shield_template",+    "parent":"fabricshieldlib:item/fabric_shield",
     "textures":{     "textures":{
         "shield":"examplemod:item/netherite_shield"         "shield":"examplemod:item/netherite_shield"
Line 56: Line 100:
 } }
 </code>\\  </code>\\ 
-Put it in resources/models/item/netherite_shield.json\\ +Put it in ''resources/assets/examplemod/models/item/netherite_shield.json''\\ 
 For the blocking model, use this: \\  For the blocking model, use this: \\ 
 <code javascript> <code javascript>
 { {
-  "parent": "fabricshieldlib:item/fabric_shield_blocking_template"+  "parent": "fabricshieldlib:item/fabric_shield_blocking"
 } }
 </code>\\  </code>\\ 
 Plop it in resources/models/item/netherite_shield_blocking.json\\ \\  Plop it in resources/models/item/netherite_shield_blocking.json\\ \\ 
-Don't forget to add it to **en_us.json**\\ +Don't forget to add it to **en_us.json** in ''resources/assets/lang/en_us.json''\\ 
 <code javascript> <code javascript>
 { {
Line 73: Line 117:
  
  
-===== Adding banner support to your shield =====+===== Adding banner support to your shield (1.17+) ===== 
 + 
 +If you are using 1.17/1.18 instead of 1.19, please change versions in **gradle.properties** to: 
 +<code java> 
 + fabric_shield_lib_version=1.5.3-1.18 
 + fabric_asm_version=2.3 
 + cloth_version=6.2.57 
 + mod_menu_version=3.0.1 
 + crowdlin_version=1.4+1.18 
 +</code> 
 +or 
 +<code java> 
 + fabric_shield_lib_version=1.5.3-1.17 
 + fabric_asm_version=2.3 
 + cloth_version=5.3.63 
 + mod_menu_version=2.0.15 
 + crowdlin_version=1.3+1.17 
 +</code> 
  
 This is where mixins get involved. This is where mixins get involved.
  
-First thing you will want to do is to change //bannerSupport// to //true// so that it will be able to be crafted with banners.+First thing you will want to do is to change //FabricShieldItem// to //FabricBannerShieldItem// so that it will be able to be crafted with banners.
  
-Next, we will need to create an ''EntityModelLayer'' to use laterI recommend making it in your main class.+<code java> 
 +public static final Item NETHERITE_SHIELD = new FabricBannerShieldItem(new FabricItemSettings().maxDamage(2500).group(ItemGroup.COMBAT), 10, 13, Items.NETHERITE_INGOT); // FabricBannerShieldItem(settings.maxDamage(durability), cooldownTicks, enchantability, repairItem) 
 +</code> 
 + 
 +Now, we have to register a few things in our ''ClientModInitalizer''. 
 + 
 +To create our ''ClientModInitalizer'', we will make a new class called ''ExampleModClient'' and implement ''ClientModInitializer''. We will also implement and override the method ''onInitializeClient'' **(If you already have a client initializer, you can skip these next 2 steps.)**
  
 <code java> <code java>
-public static final EntityModelLayer NETHERITE_SHIELD_MODEL_LAYER = new EntityModelLayer(new Identifier("examplemod", "netherite_shield"),"main"); ​+public class ExampleModClient implements ClientModInitializer { 
 +    @Override 
 +    public void onInitializeClient() 
 +     
 +    } 
 +}
 </code> </code>
- 
-And now we get to the mixin. Don't worry, the big bulk of it is just a copy-paste. 
  
-If this is your first time, [[tutorial:mixin_registration|here's how to register mixins on your fabric.mod.json]]+Before we do any work in our client mod initializer, we need to register its entrypoint in ''fabric.mod.json''
 + 
 +<code javascript> 
 +
 +  [...] 
 +  "entrypoints":
 +    "main":
 +      "net.fabricmc.ExampleMod" 
 +    ], 
 +    "client":
 +      "net.fabricmc.ExampleModClient" 
 +    ] 
 +  } 
 +  [...] 
 +
 +</code> 
 + 
 +Ok, so now that is done, we can work in our client initializer. 
 + 
 +First, we will need to create an ''EntityModelLayer'' to use later. 
 +<code java> 
 +public class ExampleModClient implements ClientModInitializer { 
 + 
 +    public static final EntityModelLayer NETHERITE_SHIELD_MODEL_LAYER = new EntityModelLayer(new Identifier("examplemod", "netherite_shield"),"main"); ​ 
 + 
 +    @Override 
 +    public void onInitializeClient() { 
 +     
 +    } 
 +
 +</code> 
 + 
 +Next, we will register out ''EntityModelLayer'' that we made previously.  
 + 
 +<code java> 
 +public class ExampleModClient implements ClientModInitializer { 
 + 
 +    public static final EntityModelLayer NETHERITE_SHIELD_MODEL_LAYER = new EntityModelLayer(new Identifier("examplemod", "netherite_shield"),"main"); ​ 
 + 
 +    @Override 
 +    public void onInitializeClient() { 
 +        EntityModelLayerRegistry.registerModelLayer(NETHERITE_SHIELD_MODEL_LAYER, ShieldEntityModel::getTexturedModelData); 
 +    } 
 +
 +</code> 
 + 
 +Then we will register our 2 ''SpriteIdentifier''s. 
 + 
 +<code java> 
 +public class ExampleModClient implements ClientModInitializer { 
 + 
 +    public static final EntityModelLayer NETHERITE_SHIELD_MODEL_LAYER = new EntityModelLayer(new Identifier("examplemod", "netherite_shield"),"main"); ​ 
 + 
 +    @Override 
 +    public void onInitializeClient() { 
 +        EntityModelLayerRegistry.registerModelLayer(NETHERITE_SHIELD_MODEL_LAYER, ShieldEntityModel::getTexturedModelData); 
 +        ClientSpriteRegistryCallback.event(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE).register((atlasTexture, registry) -> { 
 +            registry.register(new Identifier("examplemod", "entity/netherite_shield_base")); 
 +            registry.register(new Identifier("examplemod", "entity/netherite_shield_base_nopattern")); 
 +        }); 
 +    } 
 +
 +</code> 
 + 
 +And now we get to the mixin. Don't worry, its an easy one. 
 + 
 +If this is your first time, [[tutorial:mixin_registration|here's how to register mixins on your fabric.mod.json]] //__(Make sure to make a **client** mixin)__//
  
 We will make a class called ''RendererMixin'' and write: We will make a class called ''RendererMixin'' and write:
Line 94: Line 231:
 public class RendererMixin { public class RendererMixin {
  
-{+}
 </code> </code>
  
-Then we will make the necessary ''Spriteidentifier''s and a ''ShieldEntityModel''.+Then we will make the necessary ''Spriteidentifier''s and a ''ShieldEntityModel''. The ''Spriteidentifier''s will be the same as in your ''ClientModInitializer''.
 <code java> <code java>
 @Mixin (BuiltinModelItemRenderer.class) @Mixin (BuiltinModelItemRenderer.class)
Line 136: Line 273:
     @Inject(method = "reload", at = @At("HEAD"))     @Inject(method = "reload", at = @At("HEAD"))
     private void setModelNetheriteShield(CallbackInfo ci){     private void setModelNetheriteShield(CallbackInfo ci){
-        modelNetheriteShield = new ShieldEntityModel(this.entityModelLoader.getModelPart(ExampleMod.NETHERITE_SHIELD_MODEL_LAYER));+        modelNetheriteShield = new ShieldEntityModel(this.entityModelLoader.getModelPart(ExampleModClient.NETHERITE_SHIELD_MODEL_LAYER));
     }     }
 } }
Line 157: Line 294:
     @Inject(method = "reload", at = @At("HEAD"))     @Inject(method = "reload", at = @At("HEAD"))
     private void setModelNetheriteShield(CallbackInfo ci){     private void setModelNetheriteShield(CallbackInfo ci){
-        this.modelNetheriteShield = new ShieldEntityModel(this.entityModelLoader.getModelPart(ExampleMod.NETHERITE_SHIELD_MODEL_LAYER));+        this.modelNetheriteShield = new ShieldEntityModel(this.entityModelLoader.getModelPart(ExampleModClient.NETHERITE_SHIELD_MODEL_LAYER));
     }     }
          
Line 163: Line 300:
     private void mainRender(ItemStack stack, ModelTransformation.Mode mode, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay, CallbackInfo ci) {     private void mainRender(ItemStack stack, ModelTransformation.Mode mode, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay, CallbackInfo ci) {
         if (stack.isOf(ExampleMod.NETHERITE_SHIELD)) {         if (stack.isOf(ExampleMod.NETHERITE_SHIELD)) {
-            FabricShieldItem.renderBanner(stack, matrices, vertexConsumers, light, overlay, modelNetheriteShield, NETHERITE_SHIELD_BASE, NETHERITE_SHIELD_BASE_NO_PATTERN); +            FabricShieldLibClient.renderBanner(stack, matrices, vertexConsumers, light, overlay, modelNetheriteShield, NETHERITE_SHIELD_BASE, NETHERITE_SHIELD_BASE_NO_PATTERN); 
             //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.             //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.
 '' ''
Line 173: Line 310:
 </code>      </code>     
  
-There is one more big thing and five little things that we have left to do.+That is now all of the complicated things done! We now only need to change our existing model, add a ''nopattern'' texture, and move our textures to the locations we identified earlier. 
 + 
 +In your shield model, ''netherite_shield.json'' for us, we need to change the parent and remove the texture. 
 +<code javascript> 
 +
 +  "parent":"fabricshieldlib:item/fabric_banner_shield", 
 +    "overrides":
 +        { 
 +            "predicate":
 +                "blocking":
 +            }, 
 +            "model": "examplemod:item/netherite_shield_blocking" 
 +        } 
 +    ] 
 +
 +</code> 
 + 
 +You also have to change your blocking model for your shield, ''netherite_shield_blocking.json'' for us, to: 
 + 
 +<code javascript> 
 +
 +  "parent":"fabricshieldlib:item/fabric_banner_shield_blocking" 
 +
 +</code> 
 + 
 +For this next step, you will add ''_base_nopattern'' to your current shield texture, so ''netherite_shield'' to ''netherite_shield_base_nopattern''
 +Then, you will need to make a ''base'' version for your shield texture, so ''netherite_shield_base''. I recommend looking at the vanilla shield's ''base'' texture. 
 + 
 +Then, you will move both of these textures into ''resources/assets/<modid>/textures/entity''
 + 
 +For one last thing, you will need to add names for each of your shield color variants in ''en_us.json''
 +<code javascript> 
 +
 +    "item.examplemod.netherite_shield": "Netherite Shield", 
 +    "item.examplemod.netherite_shield.red": "Red Netherite Shield", 
 +    "item.examplemod.netherite_shield.orange": "Orange Netherite Shield", 
 +    "item.examplemod.netherite_shield.yellow": "Yellow Netherite Shield", 
 +    "item.examplemod.netherite_shield.lime": "Lime Netherite Shield", 
 +    "item.examplemod.netherite_shield.green": "Green Netherite Shield", 
 +    "item.examplemod.netherite_shield.light_blue": "Light Blue Netherite Shield", 
 +    "item.examplemod.netherite_shield.cyan": "Cyan Netherite Shield", 
 +    "item.examplemod.netherite_shield.blue": "Blue Netherite Shield", 
 +    "item.examplemod.netherite_shield.purple": "Purple Netherite Shield", 
 +    "item.examplemod.netherite_shield.magenta": "Magenta Netherite Shield", 
 +    "item.examplemod.netherite_shield.pink": "Pink Netherite Shield", 
 +    "item.examplemod.netherite_shield.brown": "Brown Netherite Shield", 
 +    "item.examplemod.netherite_shield.white": "White Netherite Shield", 
 +    "item.examplemod.netherite_shield.light_gray": "Light Gray Netherite Shield", 
 +    "item.examplemod.netherite_shield.gray": "Gray Netherite Shield", 
 +    "item.examplemod.netherite_shield.dark_gray": "Dark Gray Netherite Shield", 
 +    "item.examplemod.netherite_shield.black": "Black Netherite Shield" 
 +
 +</code>     
 + 
 +===== Adding banner support to your shield (1.16) ===== 
 + 
 +This is where mixins get involved. 
 + 
 +First, change the fabric_shield_lib in **gradle.properties** 
 +\\  
 +<code java> 
 +fabric_shield_lib_version=1.4.5-1.16 
 +</code> 
 +\\  
 + 
 +Next thing you will want to do is to change //FabricShieldItem// to //FabricBannerShieldItem// so that it will be able to be crafted with banners. 
 + 
 +<code java> 
 +public static final Item NETHERITE_SHIELD = new FabricBannerShieldItem(new FabricItemSettings().maxDamage(2500).group(ItemGroup.COMBAT), 10, 13, Items.NETHERITE_INGOT); // FabricBannerShieldItem(settings.maxDamage(durability), cooldownTicks, enchantability, repairItem) 
 +</code>
  
-We have to register our ''entityModelLayer'' and our ''SpriteIdentifiers'' in our ''ClientModInitalizer''.+Now, we have to register a few things in our ''ClientModInitalizer''.
  
 To create our ''ClientModInitalizer'', we will make a new class called ''ExampleModClient'' and implement ''ClientModInitializer''. We will also implement and override the method ''onInitializeClient'' **(If you already have a client initializer, you can skip these next 2 steps.)** To create our ''ClientModInitalizer'', we will make a new class called ''ExampleModClient'' and implement ''ClientModInitializer''. We will also implement and override the method ''onInitializeClient'' **(If you already have a client initializer, you can skip these next 2 steps.)**
Line 207: Line 413:
 Ok, so now that is done, we can work in our client initializer. Ok, so now that is done, we can work in our client initializer.
  
-First, we will register out ''EntityModelLayer'' that we made previously+The only thing that we will need to do is register our 2 ''SpriteIdentifier''s.
  
 <code java> <code java>
 public class ExampleModClient implements ClientModInitializer { public class ExampleModClient implements ClientModInitializer {
 +
     @Override     @Override
     public void onInitializeClient() {     public void onInitializeClient() {
-        EntityModelLayerRegistry.registerModelLayer(ExampleMod.NETHERITE_SHIELD_MODEL_LAYERShieldEntityModel::getTexturedModelData);+        ClientSpriteRegistryCallback.event(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE).register((atlasTexture, registry) -> { 
 +            registry.register(new Identifier("examplemod", "entity/netherite_shield_base")); 
 +            registry.register(new Identifier("examplemod""entity/netherite_shield_base_nopattern")); 
 +        });
     }     }
 } }
 </code> </code>
  
-Next we will register our 2 ''SpriteIdentifier''s.+And now we get to the mixin. Don't worry, its an easy one. 
 + 
 +If this is your first time, [[tutorial:mixin_registration|here's how to register mixins on your fabric.mod.json]] //__(Make sure to make a **client** mixin)__// 
 + 
 +We will make a class called ''RendererMixin'' and write: 
 +<code java> 
 +@Mixin (BuiltinModelItemRenderer.class) 
 +public class RendererMixin { 
 + 
 +
 +</code> 
 + 
 +Then we will make the necessary ''Spriteidentifier''s and a ''ShieldEntityModel''. The ''Spriteidentifier''s will be the same as in your ''ClientModInitializer''
 +<code java> 
 +@Mixin (BuiltinModelItemRenderer.class) 
 +public class RendererMixin { 
 +    private ShieldEntityModel modelNetheriteShield = new ShieldEntityModel; 
 +    private static final SpriteIdentifier NETHERITE_SHIELD_BASE = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, new Identifier("examplemod","entity/netherite_shield_base")); 
 +    private static final SpriteIdentifier NETHERITE_SHIELD_BASE_NO_PATTERN = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, new Identifier("examplemod","entity/netherite_shield_base_nopattern")); 
 +
 +</code>  
 +  
 +Now we get to the most important part of the mixin. We will inject a method to render a banner on our shield. 
 +   
 +<code java> 
 +@Mixin (BuiltinModelItemRenderer.class) 
 +public class RendererMixin { 
 +    private ShieldEntityModel modelNetheriteShield = new ShieldEntityModel; 
 +    private static final SpriteIdentifier NETHERITE_SHIELD_BASE = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, new Identifier("examplemod","entity/netherite_shield_base")); 
 +    private static final SpriteIdentifier NETHERITE_SHIELD_BASE_NO_PATTERN = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, new Identifier("examplemod","entity/netherite_shield_base_nopattern")); 
 +     
 +    @Inject(method = "render", at = @At("HEAD")) 
 +    private void mainRender(ItemStack stack, MatrixStack matrix, VertexConsumerProvider vertexConsumerProvider, int light, int overlay, CallbackInfo ci) { 
 +        if (stack.getItem() == ExampleMod.NETHERITE_SHIELD)) { 
 +            FabricShieldLibClient.renderBanner(stack, matrix, vertexConsumerProvider, light, overlay, modelFabricShield, NETHERITE_SHIELD_BASE, NETHERITE_SHIELD_BASE_NO_PATTERN);  
 +            //The first five parameters are taken from the method, while the last 3 you provide yourself. You will provide the model, and then your sprite identifiers in the order of ''//SHIELD_NAME//_BASE'' and then ''//SHIELD_NAME//_BASE_NOPATTERN. 
 +'' 
 +        } 
 +    } 
 + 
 +     
 +
 +</code>      
 + 
 +That is now all of the complicated things done! We now only need to change our existing model, add a ''nopattern'' texture, and move our textures to the locations we identified earlier. 
 + 
 +In your shield model, ''netherite_shield.json'' for us, we need to change the parent and remove the texture. 
 +<code javascript> 
 +
 +  "parent":"fabricshieldlib:item/fabric_banner_shield", 
 +    "overrides":
 +        { 
 +            "predicate":
 +                "blocking":
 +            }, 
 +            "model": "examplemod:item/netherite_shield_blocking" 
 +        } 
 +    ] 
 +
 +</code> 
 + 
 +You also have to change your blocking model for your shield, ''netherite_shield_blocking.json'' for us, to: 
 + 
 +<code javascript> 
 +
 +  "parent":"fabricshieldlib:item/fabric_banner_shield_blocking" 
 +
 +</code> 
 + 
 +For this next step, you will add ''_base'' to your current shield texture, so ''netherite_shield'' to ''netherite_shield_base''
 +Then, you will need to make a ''nopattern'' version for your shield texture, so ''netherite_shield_base_nopattern''. I recommend looking at the vanilla shield'''nopattern'' texture. 
 + 
 +Then, you will move both of these textures into ''resources/assets/<modid>/textures/entity''
 + 
 +For one last thing, you will need to add names for each of your shield color variants in ''en_us.json''
 +<code javascript> 
 +
 +    "item.examplemod.netherite_shield": "Netherite Shield", 
 +    "item.examplemod.netherite_shield.red": "Red Netherite Shield", 
 +    "item.examplemod.netherite_shield.orange": "Orange Netherite Shield", 
 +    "item.examplemod.netherite_shield.yellow": "Yellow Netherite Shield", 
 +    "item.examplemod.netherite_shield.lime": "Lime Netherite Shield", 
 +    "item.examplemod.netherite_shield.green": "Green Netherite Shield", 
 +    "item.examplemod.netherite_shield.light_blue": "Light Blue Netherite Shield", 
 +    "item.examplemod.netherite_shield.cyan": "Cyan Netherite Shield", 
 +    "item.examplemod.netherite_shield.blue": "Blue Netherite Shield", 
 +    "item.examplemod.netherite_shield.purple": "Purple Netherite Shield", 
 +    "item.examplemod.netherite_shield.magenta": "Magenta Netherite Shield", 
 +    "item.examplemod.netherite_shield.pink": "Pink Netherite Shield", 
 +    "item.examplemod.netherite_shield.brown": "Brown Netherite Shield", 
 +    "item.examplemod.netherite_shield.white": "White Netherite Shield", 
 +    "item.examplemod.netherite_shield.light_gray": "Light Gray Netherite Shield", 
 +    "item.examplemod.netherite_shield.gray": "Gray Netherite Shield", 
 +    "item.examplemod.netherite_shield.dark_gray": "Dark Gray Netherite Shield", 
 +    "item.examplemod.netherite_shield.black": "Black Netherite Shield" 
 +
 +</code>     
 + 
 +===== Adding banner support to your shield (1.15) ===== 
 + 
 +This is where mixins get involved. 
 + 
 +First, change the fabric_shield_lib in **gradle.properties** 
 +\\  
 +<code java> 
 +fabric_shield_lib_version=1.4.5-1.15 
 +</code> 
 +\\  
 + 
 +Next thing you will want to do is to change //FabricShieldItem// to //FabricBannerShieldItem// so that it will be able to be crafted with banners. 
 + 
 +<code java> 
 +public static final Item NETHERITE_SHIELD = new FabricBannerShieldItem(new FabricItemSettings().maxDamage(2500).group(ItemGroup.COMBAT), 10, 13, Items.NETHERITE_INGOT); // FabricBannerShieldItem(settings.maxDamage(durability), cooldownTicks, enchantability, repairItem) 
 +</code> 
 + 
 +Now, we have to register a few things in our ''ClientModInitalizer''
 + 
 +To create our ''ClientModInitalizer'', we will make a new class called ''ExampleModClient'' and implement ''ClientModInitializer''. We will also implement and override the method ''onInitializeClient'' **(If you already have a client initializer, you can skip these next 2 steps.)**
  
 <code java> <code java>
Line 224: Line 551:
     @Override     @Override
     public void onInitializeClient() {     public void onInitializeClient() {
-        EntityModelLayerRegistry.registerModelLayer(ExampleMod.NETHERITE_SHIELD_MODEL_LAYER, ShieldEntityModel::getTexturedModelData); +     
-        ClientSpriteRegistryCallback.event(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE).register((atlasTexture, registry) -> {+    } 
 +
 +</code> 
 + 
 +Before we do any work in our client mod initializer, we need to register its entrypoint in ''fabric.mod.json''
 + 
 +<code javascript> 
 +
 +  [...] 
 +  "entrypoints"
 +    "main"
 +      "net.fabricmc.ExampleMod" 
 +    ], 
 +    "client":
 +      "net.fabricmc.ExampleModClient" 
 +    ] 
 +  } 
 +  [...] 
 +
 +</code> 
 + 
 +Ok, so now that is done, we can work in our client initializer. 
 + 
 +The only thing that we will need to do is register our 2 ''SpriteIdentifier''s. 
 + 
 +<code java> 
 +public class ExampleModClient implements ClientModInitializer { 
 + 
 +    @Override 
 +    public void onInitializeClient({ 
 +        ClientSpriteRegistryCallback.event(SpriteAtlasTexture.BLOCK_ATLAS_TEX).register((atlasTexture, registry) -> {
             registry.register(new Identifier("examplemod", "entity/netherite_shield_base"));             registry.register(new Identifier("examplemod", "entity/netherite_shield_base"));
             registry.register(new Identifier("examplemod", "entity/netherite_shield_base_nopattern"));             registry.register(new Identifier("examplemod", "entity/netherite_shield_base_nopattern"));
Line 232: Line 589:
 } }
 </code> </code>
 +
 +And now we get to the mixin. Don't worry, its an easy one.
 +
 +If this is your first time, [[tutorial:mixin_registration|here's how to register mixins on your fabric.mod.json]] //__(Make sure to make a **client** mixin)__//
 +
 +We will make a class called ''RendererMixin'' and write:
 +<code java>
 +@Mixin (BuiltinModelItemRenderer.class)
 +public class RendererMixin {
 +
 +}
 +</code>
 +
 +Then we will make the necessary ''Spriteidentifier''s and a ''ShieldEntityModel''. The ''Spriteidentifier''s will be the same as in your ''ClientModInitializer''.
 +<code java>
 +@Mixin (BuiltinModelItemRenderer.class)
 +public class RendererMixin {
 +    private ShieldEntityModel modelNetheriteShield = new ShieldEntityModel;
 +    private static final SpriteIdentifier NETHERITE_SHIELD_BASE = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEX, new Identifier("examplemod","entity/netherite_shield_base"));
 +    private static final SpriteIdentifier NETHERITE_SHIELD_BASE_NO_PATTERN = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEX, new Identifier("examplemod","entity/netherite_shield_base_nopattern"));
 +}
 +</code> 
 + 
 +Now we get to the most important part of the mixin. We will inject a method to render a banner on our shield.
 +  
 +<code java>
 +@Mixin (BuiltinModelItemRenderer.class)
 +public class RendererMixin {
 +    private ShieldEntityModel modelNetheriteShield = new ShieldEntityModel;
 +    private static final SpriteIdentifier NETHERITE_SHIELD_BASE = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEX, new Identifier("examplemod","entity/netherite_shield_base"));
 +    private static final SpriteIdentifier NETHERITE_SHIELD_BASE_NO_PATTERN = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEX, new Identifier("examplemod","entity/netherite_shield_base_nopattern"));
 +    
 +    @Inject(method = "render", at = @At("HEAD"))
 +    private void mainRender(ItemStack stack, ModelTransformation.Mode mode, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay, CallbackInfo ci) {
 +        if (stack.getItem() == ExampleMod.NETHERITE_SHIELD)) {
 +            FabricShieldLibClient.renderBanner(stack, matrices, vertexConsumers, light, overlay, modelNetheriteShield, NETHERITE_SHIELD_BASE, NETHERITE_SHIELD_BASE_NO_PATTERN); 
 +            //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.
 +''
 +        }
 +    }
 +
 +    
 +}
 +</code>     
 +
 +That is now all of the complicated things done! We now only need to change our existing model, add a ''nopattern'' texture, and move our textures to the locations we identified earlier.
 +
 +In your shield model, ''netherite_shield.json'' for us, we need to change the parent and remove the texture.
 +<code javascript>
 +{
 +  "parent":"fabricshieldlib:item/fabric_banner_shield",
 +    "overrides": [
 +        {
 +            "predicate": {
 +                "blocking": 1
 +            },
 +            "model": "examplemod:item/netherite_shield_blocking"
 +        }
 +    ]
 +}
 +</code>
 +
 +You also have to change your blocking model for your shield, ''netherite_shield_blocking.json'' for us, to:
 +
 +<code javascript>
 +{
 +  "parent":"fabricshieldlib:item/fabric_banner_shield_blocking"
 +}
 +</code>
 +
 +For this next step, you will add ''_base'' to your current shield texture, so ''netherite_shield'' to ''netherite_shield_base''.
 +Then, you will need to make a ''nopattern'' version for your shield texture, so ''netherite_shield_base_nopattern''. I recommend looking at the vanilla shield's ''nopattern'' texture.
 +
 +Then, you will move both of these textures into ''resources/assets/<modid>/textures/entity''.
 +
 +For one last thing, you will need to add names for each of your shield color variants in ''en_us.json''.
 +<code javascript>
 +{
 +    "item.examplemod.netherite_shield": "Netherite Shield",
 +    "item.examplemod.netherite_shield.red": "Red Netherite Shield",
 +    "item.examplemod.netherite_shield.orange": "Orange Netherite Shield",
 +    "item.examplemod.netherite_shield.yellow": "Yellow Netherite Shield",
 +    "item.examplemod.netherite_shield.lime": "Lime Netherite Shield",
 +    "item.examplemod.netherite_shield.green": "Green Netherite Shield",
 +    "item.examplemod.netherite_shield.light_blue": "Light Blue Netherite Shield",
 +    "item.examplemod.netherite_shield.cyan": "Cyan Netherite Shield",
 +    "item.examplemod.netherite_shield.blue": "Blue Netherite Shield",
 +    "item.examplemod.netherite_shield.purple": "Purple Netherite Shield",
 +    "item.examplemod.netherite_shield.magenta": "Magenta Netherite Shield",
 +    "item.examplemod.netherite_shield.pink": "Pink Netherite Shield",
 +    "item.examplemod.netherite_shield.brown": "Brown Netherite Shield",
 +    "item.examplemod.netherite_shield.white": "White Netherite Shield",
 +    "item.examplemod.netherite_shield.light_gray": "Light Gray Netherite Shield",
 +    "item.examplemod.netherite_shield.gray": "Gray Netherite Shield",
 +    "item.examplemod.netherite_shield.dark_gray": "Dark Gray Netherite Shield",
 +    "item.examplemod.netherite_shield.black": "Black Netherite Shield"
 +}
 +</code>    
 +===== Adding banner support to your shield (1.14) =====
 +
 +This is where mixins get involved.
 +
 +First, change the fabric_shield_lib in **gradle.properties**
 +\\ 
 +<code java>
 +fabric_shield_lib_version=1.4.5-1.14
 +</code>
 +\\ 
 +
 +Next thing you will want to do is to change //FabricShieldItem// to //FabricBannerShieldItem// so that it will be able to be crafted with banners.
 +
 +<code java>
 +public static final Item NETHERITE_SHIELD = new FabricBannerShieldItem(new FabricItemSettings().maxDamage(2500).group(ItemGroup.COMBAT), 10, 13, Items.NETHERITE_INGOT); // FabricBannerShieldItem(settings.maxDamage(durability), cooldownTicks, enchantability, repairItem)
 +</code>
 +
 +The only thing we will need to do now is to add a simple mixin.
 +
 +If this is your first time, [[tutorial:mixin_registration|here's how to register mixins on your fabric.mod.json]] //__(Make sure to make a **client** mixin)__//
 +
 +We will make a class called ''RendererMixin'' and write:
 +<code java>
 +@Mixin (BuiltinModelItemRenderer.class)
 +public class RendererMixin {
 +
 +}
 +</code>
 +
 +Then we will make the necessary ''Identifier''s. They will be the path to your textures and the second one will have an additional **_nopattern** added to the file name.
 +<code java>
 +@Mixin (BuiltinModelItemRenderer.class)
 +public class RendererMixin {
 +    private static final Identifier NETHERITE_SHIELD_BASE = new Identifier("examplemod","entity/netherite_shield_base");
 +    private static final Identifier NETHERITE_SHIELD_BASE_NO_PATTERN = new Identifier("examplemod","entity/netherite_shield_base_nopattern");
 +}
 +</code> 
 + 
 +Now we get to the most important part of the mixin. We will inject a method to render a banner on our shield. **Do not forget to mark the inject with //cancellable = true//**
 +  
 +<code java>
 +@Mixin (BuiltinModelItemRenderer.class)
 +public class RendererMixin {
 +    private static final Identifier NETHERITE_SHIELD_BASE = new Identifier("examplemod","entity/netherite_shield_base");
 +    private static final Identifier NETHERITE_SHIELD_BASE_NO_PATTERN = new Identifier("examplemod","entity/netherite_shield_base_nopattern");
 +    
 +    @Inject(method = "render", at = @At("HEAD"), cancellable = true)
 +    private void mainRender(ItemStack stack, CallbackInfo callbackInfo) {
 +        if (stack.getItem() == ExampleMod.NETHERITE_SHIELD)) {
 +            //The first parameter is taken from the method, while you will provide your 2 identifiers in the order of ''//SHIELD_NAME//_BASE_NOPATTERN'' and then ''//SHIELD_NAME//_BASE''.
 +            FabricShieldBannerRendering.render(stack, NETHERITE_SHIELD_BASE_NO_PATTERN, NETHERITE_SHIELD_BASE);
 +            callbackInfo.cancel();
 +        }
 +    }
 +
 +    
 +}
 +</code>     
  
 That is now all of the complicated things done! We now only need to change our existing model, add a ''nopattern'' texture, and move our textures to the locations we identified earlier. That is now all of the complicated things done! We now only need to change our existing model, add a ''nopattern'' texture, and move our textures to the locations we identified earlier.
Line 238: Line 751:
 <code javascript> <code javascript>
 { {
-  "parent":"fabricshieldlib:item/fabric_shield_banner_support_template",+  "parent":"fabricshieldlib:item/fabric_banner_shield",
     "overrides": [     "overrides": [
         {         {
Line 254: Line 767:
 <code javascript> <code javascript>
 { {
-  "parent":"fabricshieldlib:item/fabric_shield_banner_support_blocking_template"+  "parent":"fabricshieldlib:item/fabric_banner_shield_blocking"
 } }
 </code> </code>
tutorial/shield.txt · Last modified: 2024/07/03 07:08 by solidblock