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 [2023/12/17 01:07] – finally updated this page cringestar_boitutorial:shield [2023/12/21 21:42] – added banner section, still incomplete though cringestar_boi
Line 40: Line 40:
  
 ===== Adding a custom shield ===== ===== Adding a custom shield =====
-**If you want your shield to support banner decoration on your shield, there are extra steps that will be covered after the main creation.(STILL BEING REMADE)**\\+**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!\\ \\  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 fabric shield api installed.\\ 
Line 89: Line 89:
 <code javascript> <code javascript>
 { {
-  "parent": "fabricshieldlib:item/fabric_shield_blocking"+  "parent": "fabricshieldlib:item/fabric_shield_blocking"
 +  "textures":
 +    "shield":"examplemod:item/netherite_shield" 
 +  }
 } }
 </code>\\  </code>\\ 
Line 109: Line 112:
 } }
 </code>\\  </code>\\ 
-And with that, your shield is done!+And with that, your non-decorateable shield is done! 
 + 
 +===== 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. 
 + 
 +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), 10, 13, Items.NETHERITE_INGOT); // FabricBannerShieldItem(settings.maxDamage(durability), cooldownTicks, enchantability, repairItems) 
 +</code> 
 + 
 +Then, we have to register it: 
 +  
 +<code java> 
 +Registry.register(Registries.ITEM, new Identifier("examplemod", "netherite_banner_shield"), NETHERITE_BANNER_SHIELD); 
 +</code> 
 + 
 +If you want to add your shield to a creative tab, add this into your ''onInitialize()'' method: 
 +<code java> 
 +ItemGroupEvents.modifyEntriesEvent(ItemGroups.COMBAT).register(entries -> { 
 + entries.addAfter(Items.SHIELD,NETHERITE_BANNER_SHIELD); 
 +}); 
 +</code> 
 + 
 +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, which should already be set up for you in the fabric example mod. 
 + 
 + 
 +First, we will need to create an ''EntityModelLayer'' to use later. 
 +<code java> 
 +public class ExampleModClient implements ClientModInitializer { 
 + 
 +    public static final EntityModelLayer netherite_banner_shield_model_layer = new EntityModelLayer(new Identifier("examplemod", "netherite_banner_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_banner_shield_model_layer, ShieldEntityModel::getTexturedModelData); 
 +    } 
 +
 +</code> 
 + 
 +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("examplemod", "netherite_shield"),"main"); ​ 
 +     
 +    public static ShieldEntityModel modelNetheriteShield; 
 + 
 +    @Override 
 +    public void onInitializeClient() { 
 +        EntityModelLayerRegistry.registerModelLayer(NETHERITE_SHIELD_MODEL_LAYER, ShieldEntityModel::getTexturedModelData); 
 +    } 
 +
 +</code> 
 + 
 +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("examplemod", "netherite_shield"),"main"); ​ 
 +     
 +    public static ShieldEntityModel modelNetheriteShield; 
 + 
 +    @Override 
 +    public void onInitializeClient() { 
 +        EntityModelLayerRegistry.registerModelLayer(NETHERITE_SHIELD_MODEL_LAYER, ShieldEntityModel::getTexturedModelData); 
 +         
 +        ShieldSetModelCallback.EVENT.register((loader) -> { 
 +     modelNetheriteShield = new ShieldEntityModel(loader.getModelPart(netherite_banner_shield_model_layer)); 
 +     return ActionResult.PASS; 
 + }); 
 +    } 
 +
 +</code> 
 + 
 +Next, we have to create our two ''SpriteIdentifiers'', 
 +<code java> 
 +public class ExampleModClient implements ClientModInitializer { 
 + 
 + public static final EntityModelLayer netherite_banner_shield_model_layer = new EntityModelLayer(new Identifier("examplemod", "netherite_banner_shield"),"main"); 
 + 
 + public static ShieldEntityModel modelNetheriteShield; 
 + 
 + public static final SpriteIdentifier NETHERITE_BANNER_SHIELD_BASE = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, new Identifier("examplemod", "entity/netherite_banner_shield_base")); 
 + public static final SpriteIdentifier NETHERITE_BANNER_SHIELD_BASE_NO_PATTERN = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, new Identifier("examplemod", "entity/netherite_banner_shield_base_nopattern")); 
 + 
 + @Override 
 + public void onInitializeClient() { 
 +            EntityModelLayerRegistry.registerModelLayer(NETHERITE_SHIELD_MODEL_LAYER, ShieldEntityModel::getTexturedModelData); 
 +         
 +            ShieldSetModelCallback.EVENT.register((loader) -> { 
 +         modelNetheriteShield = new ShieldEntityModel(loader.getModelPart(netherite_banner_shield_model_layer)); 
 +         return ActionResult.PASS; 
 +     }); 
 +
 +
 +</code> 
 + 
 +Finally, we are going to register our shield with the ''BuiltinItemRendererRegistry'', 
 +<code java> 
 +public class ExampleModClient implements ClientModInitializer { 
 + 
 + public static final EntityModelLayer netherite_banner_shield_model_layer = new EntityModelLayer(new Identifier("examplemod", "netherite_banner_shield"),"main"); 
 + 
 + public static ShieldEntityModel modelNetheriteShield; 
 + 
 + public static final SpriteIdentifier NETHERITE_BANNER_SHIELD_BASE = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, new Identifier("examplemod", "entity/netherite_banner_shield_base")); 
 + public static final SpriteIdentifier NETHERITE_BANNER_SHIELD_BASE_NO_PATTERN = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, new Identifier("examplemod", "entity/netherite_banner_shield_base_nopattern")); 
 + 
 + @Override 
 + public void onInitializeClient() { 
 +            EntityModelLayerRegistry.registerModelLayer(NETHERITE_SHIELD_MODEL_LAYER, ShieldEntityModel::getTexturedModelData); 
 +         
 +            ShieldSetModelCallback.EVENT.register((loader) -> { 
 +         modelNetheriteShield = new ShieldEntityModel(loader.getModelPart(netherite_banner_shield_model_layer)); 
 +         return ActionResult.PASS; 
 +     }); 
 +  
 +            BuiltinItemRendererRegistry.INSTANCE.register(ExampleMod.NETHERITE_BANNER_SHIELD, (stack, mode, matrices, vertexConsumers, light, overlay) -> { 
 + renderBanner(stack, matrices, vertexConsumers, light, overlay, modelNetheriteShield, NETHERITE_BANNER_SHIELD_BASE, NETHERITE_BANNER_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 all of our code done, we only have a few .json files to make. **WILL FINISH THIS SECTION SOON**
tutorial/shield.txt · Last modified: 2024/07/03 07:08 by solidblock