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 revisionBoth sides next revision
tutorial:shield [2022/01/01 00:37] – old revision restored (2021/12/27 20:29) cringestar_boitutorial:shield [2022/01/01 01:04] – added 1.14 section for banner support again cringestar_boi
Line 577: Line 577:
             //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.
 '' ''
 +        }
 +    }
 +
 +    
 +}
 +</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();
         }         }
     }     }
tutorial/shield.txt · Last modified: 2024/01/14 18:05 by cringestar_boi