tutorial:shield
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tutorial:shield [2022/12/17 15:22] – Registry.ITEM -> Registries.ITEM miir | tutorial:shield [2024/09/29 19:35] (current) – updated with 1.21 guide and past guides cringestar_boi | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | __**THIS PAGE SHOULD WORK FOR 1.17-1.19. THE 1.14-1.16 SECTIONS HAVE NOT BEEN TESTED IN A LONG TIME, SO THEY MAY NOT WORK.**__ | + | ====== Making a Custom Shield in Minecraft [1.19-1.21.1] ====== |
+ | :!: The tutorial depends on third-party libraries. | ||
- | ====== Making 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. |
- | 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 12: | Line 12: | ||
===== Adding the library to your project ===== | ===== Adding the library to your project ===== | ||
- | Add the following code to the files mentioned:\\ \\ | + | Add the following code to the files mentioned: |
- | **gradle.properties**\\ | + | |
- | <code java> | + | |
- | fabric_shield_lib_version=1.6.0-1.19 | + | |
- | </ | + | |
- | **build.gradle** (under dependencies)\\ | + | |
- | <code java> | + | |
- | modImplementation " | + | |
- | </ | + | |
- | 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, | + | |
- | <code java> | + | |
- | maven { url = ' | + | |
- | </ | + | |
- | __//**If you are doing this in Minecraft version | + | **gradle.properties** |
+ | <file properties gradle.properties> | ||
+ | fabric_shield_lib_version=1.7.2-1.21.1 | ||
+ | midnightlib_version=1.5.8-fabric | ||
+ | mod_menu_version=11.0.1 | ||
+ | fabricasm_version=2.3 | ||
+ | </file> | ||
- | **gradle.properties**\\ | + | **build.gradle** (under '' |
- | <code java> | + | <file groovy build.gradle> |
- | fabric_asm_version=2.3 | + | modImplementation "com.github.CrimsonDawn45: |
- | cloth_version=8.1.77 | + | modImplementation " |
- | mod_menu_version=4.0.6 | + | modImplementation "maven.modrinth: |
- | crowdlin_version=1.4+1.19 | + | modImplementation " |
- | </code>\\ | + | </file> |
- | **(These versions will be updated in this wiki alongside the mod version)** | + | At the time of writing, the latest project.fabric_shield_lib_version should be 1.7.2, which supports versions: |
+ | * **1.21** - **1.21.1** ('' | ||
+ | | ||
+ | * **1.20.2** - **1.20.4** ('' | ||
+ | * **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 '' | ||
+ | <file groovy build.gradle> | ||
+ | maven {url = ' | ||
+ | maven {url " | ||
+ | maven {url = " | ||
+ | </ | ||
- | **build.gradle** (under dependencies)\\ | + | __//**Midnight Lib and FabricASM are included in the FabricShieldLib release (.jar on Curseforge/ |
- | <code java> | + | |
- | modApi(" | + | ===== Adding a custom shield ===== |
- | exclude(group: | + | **If you want your shield to support banner decoration on your shield, please skip to the next section** |
- | } | + | |
- | include(" | + | |
- | modCompileOnly modRuntimeOnly (" | + | On to the non-boring steps! We will now make a custom shield! |
- | exclude(group: | + | |
- | } | + | |
- | modImplementation(" | + | If you have followed the above steps correctly and refreshed the project, then you will have the FabricShieldLib installed. |
- | exclude (group: " | + | |
- | } | + | |
- | include(" | + | |
- | </ | + | If so, the first step to do is create a new instance of an '' |
+ | <code java TutorialItems> | ||
+ | public final class TutorialItems { | ||
+ | // ... | ||
+ | public static final Item NETHERITE_SHIELD = register(new FabricShieldItem(new FabricItemSettings().maxDamage(2500), | ||
+ | //The constructor for the item takes in the following values: FabricBannerShieldItem(settings.maxDamage(durability), | ||
+ | // ... | ||
+ | } | ||
+ | </ | ||
- | **build.gradle** (under repositories, the one above dependencies)\\ | + | If you want to add your shield to a [[itemgroup|item groups]], for example, the "Combat" |
- | <code java> | + | |
- | maven { url "https:// | + | |
- | maven { url "https:// | + | |
- | </ | + | |
- | ===== Adding a custom shield ===== | + | <yarncode |
- | **If you want your shield to support banner decoration, there are extra steps that will be covered after the main creation.**\\ | + | public |
- | On to the non-boring steps! We will now make a custom shield!\\ \\ | + | @Override |
- | If you have followed the above steps correctly and refreshed the project, then you will have the fabric shield api installed.\\ | + | public void onInitialize() { |
- | If so, the first step to do is create a new instance of an Item like: | + | ItemGroupEvents.modifyEntriesEvent(ItemGroups.COMBAT).register(entries -> { |
- | <code java> | + | entries.add(NETHERITE_SHIELD); |
- | public | + | }); |
- | </code> | + | } |
+ | } | ||
+ | </yarncode> | ||
- | Then, we have to register it, like so: | + | And our shield is (code-wise) done! |
- | + | ||
- | <code java> | + | Now, we have to create the textures and models of the shield. |
- | Registry.register(Registries.ITEM, new Identifier(" | + | |
- | </code> | + | For the texture, you can use anything. A good place to start is to look at Mojang' |
- | And our shield is done!\\ | + | Now, for the models, we have to write a few .json files. |
- | 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' | + | Inside |
- | Now, for the models, we have to write a few .json files.\\ | + | |
- | For the model file without blocking, we use: \\ | + | <file javascript |
- | <code javascript> | + | |
{ | { | ||
" | " | ||
" | " | ||
- | " | + | " |
}, | }, | ||
" | " | ||
Line 95: | Line 99: | ||
" | " | ||
}, | }, | ||
- | " | + | " |
} | } | ||
] | ] | ||
} | } | ||
- | </code>\\ | + | </file> |
- | Put it in '' | + | |
- | For the blocking model, use this: \\ | + | In the same folder, create another file, '' |
- | <code javascript> | + | <file javascript |
{ | { | ||
- | " | + | " |
+ | " | ||
+ | " | ||
+ | } | ||
} | } | ||
- | </code>\\ | + | </file> |
- | Plop it in resources/ | + | |
- | Don't forget to add it to **en_us.json** in '' | + | Then, as a [[tags|conventional tag]], create a '' |
- | <code javascript> | + | <code javascript |
{ | { | ||
- | "item.examplemod.netherite_shield": "Netherite Shield" | + | "replace": |
+ | | ||
+ | " | ||
+ | ] | ||
} | } | ||
- | </ | ||
- | And with that, your shield is done! | ||
- | |||
- | |||
- | ===== 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 | ||
- | </ | ||
- | 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 | ||
</ | </ | ||
- | + | Lastly, to make it enchantable, | |
- | This is where mixins get involved. | + | < |
- | + | { | |
- | First thing you will want to do is to change | + | " |
- | + | " | |
- | < | + | " |
- | public static final Item NETHERITE_SHIELD = new FabricBannerShieldItem(new FabricItemSettings().maxDamage(2500).group(ItemGroup.COMBAT), | + | ] |
+ | } | ||
</ | </ | ||
- | Now, we have to register a few things | + | Don't forget to add it to **en_us.json** |
- | + | < | |
- | To create our '' | + | { |
- | + | " | |
- | < | + | |
- | public class ExampleModClient implements ClientModInitializer | + | |
- | | + | |
- | public void onInitializeClient() { | + | |
- | + | ||
- | } | + | |
} | } | ||
- | </ | + | </ |
+ | And with that, your non-decorateable shield is done! | ||
- | Before we do any work in our client mod initializer, | + | ===== 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 '' |
- | { | + | < |
- | [...] | + | |
- | " | + | |
- | | + | |
- | "net.fabricmc.ExampleMod" | + | |
- | ], | + | |
- | | + | |
- | " | + | |
- | ] | + | |
- | } | + | |
- | [...] | + | |
- | } | + | |
</ | </ | ||
+ | If you want to add your shield to a [[itemgroup|item groups]], for example, the " | ||
+ | |||
+ | < | ||
+ | public class ExampleMod implements ModInitializer { | ||
+ | @Override | ||
+ | public void onInitialize() { | ||
+ | ItemGroupEvents.modifyEntriesEvent(ItemGroups.COMBAT).register(entries -> { | ||
+ | // ... | ||
+ | entries.add(NETHERITE_BANNER_SHIELD); | ||
+ | }); | ||
+ | } | ||
+ | } | ||
+ | </ | ||
- | Ok, so now that is done, we can work in our client initializer. | + | Now the item is created, we need to set up its rendering. For these steps, we are going to be working |
First, we will need to create an '' | First, we will need to create an '' | ||
<code java> | <code java> | ||
+ | @Environment(EnvType.CLIENT) | ||
public class ExampleModClient implements ClientModInitializer { | public class ExampleModClient implements ClientModInitializer { | ||
- | + | | |
- | | + | |
@Override | @Override | ||
Line 193: | Line 182: | ||
<code java> | <code java> | ||
+ | @Environment(EnvType.CLIENT) | ||
public class ExampleModClient implements ClientModInitializer { | public class ExampleModClient implements ClientModInitializer { | ||
- | public static final EntityModelLayer NETHERITE_SHIELD_MODEL_LAYER = new EntityModelLayer(new Identifier(" | + | public static final EntityModelLayer NETHERITE_SHIELD_MODEL_LAYER = new EntityModelLayer(Identifier.of("tutorial", " |
@Override | @Override | ||
public void onInitializeClient() { | public void onInitializeClient() { | ||
- | | + | EntityModelLayerRegistry.registerModelLayer(NETHERITE_BANNER_SHILED_MODEL_LAYER, ShieldEntityModel:: |
} | } | ||
} | } | ||
</ | </ | ||
- | Then we will register | + | Then we will create |
<code java> | <code java> | ||
+ | @Environment(EnvType.CLIENT) | ||
public class ExampleModClient implements ClientModInitializer { | public class ExampleModClient implements ClientModInitializer { | ||
- | + | | |
- | | + | |
+ | public static ShieldEntityModel modelNetheriteShield; | ||
@Override | @Override | ||
public void onInitializeClient() { | public void onInitializeClient() { | ||
EntityModelLayerRegistry.registerModelLayer(NETHERITE_SHIELD_MODEL_LAYER, | EntityModelLayerRegistry.registerModelLayer(NETHERITE_SHIELD_MODEL_LAYER, | ||
- | ClientSpriteRegistryCallback.event(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE).register((atlasTexture, | ||
- | registry.register(new Identifier(" | ||
- | registry.register(new Identifier(" | ||
- | }); | ||
} | } | ||
} | } | ||
</ | </ | ||
- | And now we get to the mixin. Don't worry, its an easy one. | + | And then register that shield model, |
- | If this is your first time, [[tutorial: | ||
- | |||
- | We will make a class called '' | ||
<code java> | <code java> | ||
- | @Mixin (BuiltinModelItemRenderer.class) | + | @Environment(EnvType.CLIENT) |
- | public class RendererMixin { | + | public class ExampleModClient implements |
- | + | public static final EntityModelLayer NETHERITE_SHIELD_MODEL_LAYER | |
- | } | + | |
- | </ | + | |
- | + | ||
- | Then we will make the necessary '' | + | |
- | <code java> | + | |
- | @Mixin (BuiltinModelItemRenderer.class) | + | |
- | public class RendererMixin | + | |
- | | + | |
- | private static final SpriteIdentifier NETHERITE_SHIELD_BASE = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, | + | |
- | private static final SpriteIdentifier NETHERITE_SHIELD_BASE_NO_PATTERN = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | Next, we need to @Shadow the '' | + | |
- | <code java> | + | |
- | @Mixin (BuiltinModelItemRenderer.class) | + | |
- | public | + | |
- | private ShieldEntityModel modelNetheriteShield; | + | |
- | private | + | |
- | private static final SpriteIdentifier NETHERITE_SHIELD_BASE_NO_PATTERN = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, | + | |
- | + | ||
- | @Final | + | |
- | @Shadow | + | |
- | private EntityModelLoader entityModelLoader; | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | Now we will inject into the '' | + | |
- | <code java> | + | |
- | @Mixin (BuiltinModelItemRenderer.class) | + | |
- | public class RendererMixin { | + | |
- | | + | |
- | private static final SpriteIdentifier NETHERITE_SHIELD_BASE = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, | + | |
- | private static final SpriteIdentifier NETHERITE_SHIELD_BASE_NO_PATTERN = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, | + | |
- | + | ||
- | @Final | + | |
- | @Shadow | + | |
- | private EntityModelLoader entityModelLoader; | + | |
- | + | ||
- | + | ||
- | @Inject(method = " | + | |
- | private void setModelNetheriteShield(CallbackInfo ci){ | + | |
- | modelNetheriteShield = new ShieldEntityModel(this.entityModelLoader.getModelPart(ExampleModClient.NETHERITE_SHIELD_MODEL_LAYER)); | + | |
- | } | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | 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 static final SpriteIdentifier NETHERITE_SHIELD_BASE = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, | + | |
- | private static final SpriteIdentifier NETHERITE_SHIELD_BASE_NO_PATTERN = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, new Identifier("examplemod"," | + | |
- | + | ||
- | @Final | + | |
- | @Shadow | + | |
- | private EntityModelLoader entityModelLoader; | + | |
- | + | ||
- | + | ||
- | @Inject(method = " | + | |
- | private void setModelNetheriteShield(CallbackInfo ci){ | + | |
- | this.modelNetheriteShield = new ShieldEntityModel(this.entityModelLoader.getModelPart(ExampleModClient.NETHERITE_SHIELD_MODEL_LAYER)); | + | |
- | } | + | |
| | ||
- | | + | |
- | private void mainRender(ItemStack stack, ModelTransformation.Mode mode, MatrixStack matrices, VertexConsumerProvider vertexConsumers, | + | |
- | if (stack.isOf(ExampleMod.NETHERITE_SHIELD)) { | + | |
- | FabricShieldLibClient.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 ''// | + | |
- | '' | + | |
- | } | + | |
- | } | + | |
- | | ||
- | } | ||
- | </ | ||
- | |||
- | That is now all of the complicated things done! We now only need to change our existing model, add a '' | ||
- | |||
- | In your shield model, '' | ||
- | <code javascript> | ||
- | { | ||
- | " | ||
- | " | ||
- | { | ||
- | " | ||
- | " | ||
- | }, | ||
- | " | ||
- | } | ||
- | ] | ||
- | } | ||
- | </ | ||
- | |||
- | You also have to change your blocking model for your shield, '' | ||
- | |||
- | <code javascript> | ||
- | { | ||
- | " | ||
- | } | ||
- | </ | ||
- | |||
- | For this next step, you will add '' | ||
- | Then, you will need to make a '' | ||
- | |||
- | Then, you will move both of these textures into '' | ||
- | |||
- | For one last thing, you will need to add names for each of your shield color variants in '' | ||
- | <code javascript> | ||
- | { | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | } | ||
- | </ | ||
- | |||
- | ===== 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 | ||
- | </ | ||
- | \\ | ||
- | |||
- | Next thing you will want to do is to change // | ||
- | |||
- | <code java> | ||
- | public static final Item NETHERITE_SHIELD = new FabricBannerShieldItem(new FabricItemSettings().maxDamage(2500).group(ItemGroup.COMBAT), | ||
- | </ | ||
- | |||
- | Now, we have to register a few things in our '' | ||
- | |||
- | To create our '' | ||
- | |||
- | <code java> | ||
- | public class ExampleModClient implements ClientModInitializer { | ||
@Override | @Override | ||
public void onInitializeClient() { | public void onInitializeClient() { | ||
- | | + | EntityModelLayerRegistry.registerModelLayer(NETHERITE_SHIELD_MODEL_LAYER, |
+ | |||
+ | ShieldSetModelCallback.EVENT.register((loader) -> { | ||
+ | | ||
+ | return ActionResult.PASS; | ||
+ | }); | ||
} | } | ||
} | } | ||
</ | </ | ||
- | Before we do any work in our client mod initializer, we need to register its entrypoint in '' | + | Next, we have to create our two '' |
- | + | ||
- | <code javascript> | + | |
- | { | + | |
- | [...] | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | ], | + | |
- | " | + | |
- | " | + | |
- | ] | + | |
- | } | + | |
- | [...] | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | 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 '' | + | |
<code java> | <code java> | ||
+ | @Environment(EnvType.CLIENT) | ||
public class ExampleModClient implements ClientModInitializer { | public class ExampleModClient implements ClientModInitializer { | ||
- | @Override | + | public |
- | | + | |
- | ClientSpriteRegistryCallback.event(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE).register((atlasTexture, | + | |
- | registry.register(new Identifier("examplemod", "entity/ | + | |
- | registry.register(new Identifier(" | + | |
- | }); | + | |
- | } | + | |
- | } | + | |
- | </ | + | |
- | And now we get to the mixin. Don't worry, its an easy one. | + | public static ShieldEntityModel modelNetheriteShield; |
- | If this is your first time, [[tutorial: | + | public static final SpriteIdentifier NETHERITE_BANNER_SHIELD_BASE = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, Identifier.of(" |
- | + | public static final SpriteIdentifier NETHERITE_BANNER_SHIELD_BASE_NO_PATTERN = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, | |
- | We will make a class called '' | + | |
- | <code java> | + | |
- | @Mixin | + | |
- | public class RendererMixin { | + | |
+ | @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; | ||
+ | }); | ||
+ | } | ||
} | } | ||
</ | </ | ||
- | Then we will make the necessary | + | Finally, |
<code java> | <code java> | ||
- | @Mixin (BuiltinModelItemRenderer.class) | + | @Environment(EnvType.CLIENT) |
- | public class RendererMixin | + | public class ExampleModClient implements ClientModInitializer |
- | | + | public |
- | private | + | |
- | private static final SpriteIdentifier NETHERITE_SHIELD_BASE_NO_PATTERN = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | 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, | + | |
- | private static final SpriteIdentifier NETHERITE_SHIELD_BASE_NO_PATTERN = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, new Identifier("examplemod"," | + | |
- | + | ||
- | @Inject(method = " | + | |
- | private void mainRender(ItemStack stack, MatrixStack matrix, VertexConsumerProvider vertexConsumerProvider, | + | |
- | if (stack.getItem() == ExampleMod.NETHERITE_SHIELD)) { | + | |
- | FabricShieldLibClient.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 ''// | + | |
- | '' | + | |
- | } | + | |
- | } | + | |
- | + | public static ShieldEntityModel modelNetheriteShield; | |
- | } | + | |
- | </ | + | |
- | That is now all of the complicated things done! We now only need to change our existing model, add a '' | + | 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, Identifier.of(" | ||
- | In your shield model, '' | + | @Override |
- | <code javascript> | + | public void onInitializeClient() |
- | { | + | |
- | " | + | |
- | " | + | |
- | | + | modelNetheriteShield = new ShieldEntityModel(loader.getModelPart(netherite_banner_shield_model_layer)); |
- | | + | return ActionResult.PASS; |
- | " | + | |
- | }, | + | |
- | | + | |
- | } | + | renderBanner(stack, |
- | ] | + | |
+ | | ||
+ | } | ||
} | } | ||
</ | </ | ||
- | You also have to change your blocking model for your shield, '' | + | That is all of our code done, we only have a few json files to make. |
- | <code javascript> | + | First, create a '' |
+ | <code javascript | ||
{ | { | ||
- | "parent":" | + | "sources": |
+ | { | ||
+ | | ||
+ | " | ||
+ | }, | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | ] | ||
} | } | ||
</ | </ | ||
- | For this next step, you will add '' | + | Next, inside |
- | Then, you will need to make a '' | + | <code javascript |
- | + | ||
- | Then, you will move both of these textures into '' | + | |
- | + | ||
- | For one last thing, you will need to add names for each of your shield color variants in '' | + | |
- | <code javascript> | + | |
{ | { | ||
- | | + | |
- | " | + | "overrides": |
- | "item.examplemod.netherite_shield.orange": | + | |
- | "item.examplemod.netherite_shield.yellow": | + | "predicate": |
- | | + | "blocking": |
- | "item.examplemod.netherite_shield.green": | + | }, |
- | "item.examplemod.netherite_shield.light_blue": | + | "model": "tutorial:item/ |
- | " | + | |
- | "item.examplemod.netherite_shield.blue": "Blue Netherite Shield", | + | |
- | " | + | |
- | "item.examplemod.netherite_shield.magenta": " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | ===== 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 | + | |
- | </ | + | |
- | \\ | + | |
- | + | ||
- | Next thing you will want to do is to change // | + | |
- | + | ||
- | <code java> | + | |
- | public static final Item NETHERITE_SHIELD = new FabricBannerShieldItem(new FabricItemSettings().maxDamage(2500).group(ItemGroup.COMBAT), | + | |
- | </ | + | |
- | + | ||
- | Now, we have to register a few things in our '' | + | |
- | + | ||
- | To create our '' | + | |
- | + | ||
- | <code java> | + | |
- | public class ExampleModClient implements ClientModInitializer { | + | |
- | @Override | + | |
- | public void onInitializeClient() { | + | |
- | | + | |
} | } | ||
+ | ] | ||
} | } | ||
</ | </ | ||
- | Before we do any work in our client mod initializer, we need to register its entrypoint in '' | + | In the same folder, create another file, '' |
- | + | <code javascript | |
- | <code javascript> | + | |
{ | { | ||
- | | + | "parent":" |
- | | + | "textures":{ |
- | | + | "shield":" |
- | "net.fabricmc.ExampleMod" | + | |
- | ], | + | |
- | "client": | + | |
- | | + | |
- | ] | + | |
} | } | ||
- | [...] | ||
} | } | ||
</ | </ | ||
- | Ok, so now that is done, we can work in our client initializer. | + | For this next step, you will add a '' |
- | The only thing that we will need to do is register our 2 '' | + | Then, you will move both of these textures into '' |
- | <code java> | + | Next, create a '' |
- | public class ExampleModClient implements ClientModInitializer { | + | <code javascript |
- | + | ||
- | @Override | + | |
- | public void onInitializeClient() { | + | |
- | ClientSpriteRegistryCallback.event(SpriteAtlasTexture.BLOCK_ATLAS_TEX).register((atlasTexture, registry) -> { | + | |
- | registry.register(new Identifier(" | + | |
- | registry.register(new Identifier(" | + | |
- | }); | + | |
- | } | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | And now we get to the mixin. Don't worry, its an easy one. | + | |
- | + | ||
- | If this is your first time, [[tutorial: | + | |
- | + | ||
- | We will make a class called | + | |
- | <code java> | + | |
- | @Mixin (BuiltinModelItemRenderer.class) | + | |
- | public class RendererMixin { | + | |
- | + | ||
- | } | + | |
- | </ | + | |
- | + | ||
- | Then we will make the necessary '' | + | |
- | <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, | + | |
- | private static final SpriteIdentifier NETHERITE_SHIELD_BASE_NO_PATTERN = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEX, | + | |
- | } | + | |
- | </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, | + | |
- | private static final SpriteIdentifier NETHERITE_SHIELD_BASE_NO_PATTERN = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEX, | + | |
- | + | ||
- | @Inject(method = " | + | |
- | private void mainRender(ItemStack stack, ModelTransformation.Mode mode, MatrixStack matrices, VertexConsumerProvider vertexConsumers, | + | |
- | if (stack.getItem() == ExampleMod.NETHERITE_SHIELD)) { | + | |
- | FabricShieldLibClient.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 ''// | + | |
- | '' | + | |
- | } | + | |
- | } | + | |
- | + | ||
- | + | ||
- | } | + | |
- | </ | + | |
- | + | ||
- | That is now all of the complicated things done! We now only need to change our existing model, | + | |
- | + | ||
- | In your shield | + | |
- | <code javascript> | + | |
{ | { | ||
- | "parent":" | + | "replace": |
- | "overrides": [ | + | "values": [ |
- | { | + | "tutorial:netherite_banner_shield" |
- | " | + | ] |
- | | + | |
- | }, | + | |
- | " | + | |
- | } | + | |
- | | + | |
} | } | ||
</ | </ | ||
- | You also have to change your blocking model for your shield, | + | Finally create a '' |
- | + | <code javascript | |
- | <code javascript> | + | |
{ | { | ||
- | "parent":" | + | "replace": |
+ | | ||
+ | " | ||
+ | ] | ||
} | } | ||
</ | </ | ||
- | For this next step, you will add '' | + | Don't forget |
- | Then, you will need to make a '' | + | |
- | + | ||
- | Then, you will move both of these textures into '' | + | |
- | + | ||
- | For one last thing, you will need to add names for each of your shield color variants in '' | + | |
<code javascript> | <code javascript> | ||
{ | { | ||
- | | + | |
- | "item.examplemod.netherite_shield.red": "Red Netherite Shield", | + | "item.tutorial.netherite_banner_shield.red": "Red Netherite |
- | "item.examplemod.netherite_shield.orange": | + | "item.tutorial.netherite_banner_shield.orange": |
- | "item.examplemod.netherite_shield.yellow": | + | "item.tutorial.netherite_banner_shield.yellow": |
- | "item.examplemod.netherite_shield.lime": | + | "item.tutorial.netherite_banner_shield.lime": |
- | "item.examplemod.netherite_shield.green": | + | "item.tutorial.netherite_banner_shield.green": |
- | "item.examplemod.netherite_shield.light_blue": | + | "item.tutorial.netherite_banner_shield.light_blue": |
- | "item.examplemod.netherite_shield.cyan": | + | "item.tutorial.netherite_banner_shield.cyan": |
- | "item.examplemod.netherite_shield.blue": | + | "item.tutorial.netherite_banner_shield.blue": |
- | "item.examplemod.netherite_shield.purple": | + | "item.tutorial.netherite_banner_shield.purple": |
- | "item.examplemod.netherite_shield.magenta": | + | "item.tutorial.netherite_banner_shield.magenta": |
- | "item.examplemod.netherite_shield.pink": | + | "item.tutorial.netherite_banner_shield.pink": |
- | "item.examplemod.netherite_shield.brown": | + | "item.tutorial.netherite_banner_shield.brown": |
- | "item.examplemod.netherite_shield.white": | + | "item.tutorial.netherite_banner_shield.white": |
- | "item.examplemod.netherite_shield.light_gray": | + | "item.tutorial.netherite_banner_shield.light_gray": |
- | "item.examplemod.netherite_shield.gray": | + | "item.tutorial.netherite_banner_shield.gray": |
- | "item.examplemod.netherite_shield.dark_gray": | + | "item.tutorial.netherite_banner_shield.dark_gray": |
- | "item.examplemod.netherite_shield.black": | + | "item.tutorial.netherite_banner_shield.black": |
} | } | ||
- | </ | ||
- | ===== 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 | ||
</ | </ | ||
- | \\ | ||
- | Next thing you will want to do is to change // | + | And now your shield |
- | <code java> | + | ===== Changes for 1.20.6 ===== |
- | public static final Item NETHERITE_SHIELD | + | If you are working in 1.20.6, first change the FabricShieldLib and FAPI versions accordingly and change your other dependencies to these versions:\\ |
- | </ | + | |
- | The only thing we will need to do now is to add a simple mixin. | + | <file properties gradle.properties> |
+ | mod_menu_version=10.0.0-beta.1 | ||
+ | midnightlib_version=1.5.5-fabric | ||
+ | </ | ||
- | If this is your first time, [[tutorial: | + | Next, change all instances of '' |
- | We will make a class called | + | Then, change your '' |
- | <code java> | + | |
- | @Mixin (BuiltinModelItemRenderer.class) | + | |
- | public class RendererMixin { | + | |
- | } | + | Finally, move your '' |
- | </code> | + | |
- | Then we will make the necessary '' | + | ===== Changes for 1.20.4 ===== |
- | <code java> | + | If you are working in 1.20.4, **follow the changes for 1.20.6 first**, then change |
- | @Mixin (BuiltinModelItemRenderer.class) | + | |
- | public class RendererMixin { | + | |
- | private static final Identifier NETHERITE_SHIELD_BASE | + | |
- | private static final Identifier NETHERITE_SHIELD_BASE_NO_PATTERN | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | 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 // | + | |
- | + | ||
- | <code java> | + | |
- | @Mixin (BuiltinModelItemRenderer.class) | + | |
- | public class RendererMixin { | + | |
- | private static final Identifier NETHERITE_SHIELD_BASE | + | |
- | private static final Identifier NETHERITE_SHIELD_BASE_NO_PATTERN | + | |
- | + | ||
- | @Inject(method | + | |
- | | + | |
- | 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 ''// | + | |
- | FabricShieldBannerRendering.render(stack, | + | |
- | callbackInfo.cancel(); | + | |
- | } | + | |
- | } | + | |
- | | + | **gradle.properties** |
- | } | + | <file properties gradle.properties> |
- | </code> | + | midnightlib_version=1.5.2-fabric |
+ | mod_menu_version=9.0.0-pre.1 | ||
+ | </file> | ||
- | That is now all of the complicated things done! We now only need to change our existing model, add a '' | + | Additionally, |
- | In your shield model, '' | + | ===== Changes |
- | <code javascript> | + | If you are working in 1.19, **follow |
- | { | + | |
- | " | + | |
- | " | + | |
- | { | + | |
- | " | + | |
- | " | + | |
- | }, | + | |
- | " | + | |
- | } | + | |
- | ] | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | You also have to change your blocking model for your shield, '' | + | |
- | + | ||
- | <code javascript> | + | |
- | { | + | |
- | " | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | For this next step, you will add '' | + | |
- | Then, you will need to make a '' | + | |
- | + | ||
- | Then, you will move both of these textures into '' | + | |
- | + | ||
- | For one last thing, you will need to add names for each of your shield color variants in '' | + | |
- | <code javascript> | + | |
- | { | + | |
- | "item.examplemod.netherite_shield": | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | } | + | |
- | </ | + | |
- | Now your shield is done and has banner support! | + | **gradle.properties** |
+ | <file properties gradle.properties> | ||
+ | midnightlib_version=1.0.0-fabric | ||
+ | mod_menu_version=4.2.0-beta.2 | ||
+ | </ |
tutorial/shield.1671290577.txt.gz · Last modified: 2022/12/17 15:22 by miir