tutorial:shield
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
tutorial:shield [2022/09/05 19:20] – updated versions cringestar_boi | tutorial:shield [2023/12/21 20:15] – 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.20] ====== |
- | + | ||
- | ====== Making a Custom Shield in Minecraft [1.18-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 15: | Line 13: | ||
**gradle.properties**\\ | **gradle.properties**\\ | ||
<code java> | <code java> | ||
- | fabric_shield_lib_version=1.6.0-1.19 | + | fabric_shield_lib_version=1.7.2-1.20.4 |
+ | midnightlib_version=1.5.2-fabric | ||
+ | mod_menu_version=9.0.0-pre.1 | ||
+ | fabricasm_version=2.3 | ||
</ | </ | ||
**build.gradle** (under dependencies)\\ | **build.gradle** (under dependencies)\\ | ||
<code java> | <code java> | ||
- | modImplementation " | + | modImplementation " |
- | </ | + | |
- | At the time of writing, latest project.fabric_shield_lib_version should be 1.5.3-1.18. 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 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 | + | |
- | </ | + | |
- | + | ||
- | **(These versions will be updated in this wiki alongside the mod version)** | + | |
- | + | ||
- | **build.gradle** (under dependencies)\\ | + | |
- | <code java> | + | |
- | + | ||
- | modApi(" | + | |
- | exclude(group: | + | |
- | } | + | |
- | include(" | + | |
- | modCompileOnly modRuntimeOnly (" | + | modImplementation |
- | exclude(group: | + | |
- | } | + | |
- | modImplementation("com.github.Chocohead: | + | modImplementation "maven.modrinth:midnightlib:${project.midnightlib_version}" |
- | exclude (group: " | + | |
- | } | + | |
- | include(" | + | |
+ | modImplementation " | ||
</ | </ | ||
- | **build.gradle** (under repositories, | + | At the time of writing, latest project.fabric_shield_lib_version should be 1.7.2-1.20.4. This page will be updated whenever a new update comes out.\\ \\ |
+ | **build.gradle** (inside | ||
<code java> | <code java> | ||
- | maven { url " | + | maven {url = ' |
- | maven { url " | + | maven {url " |
+ | maven {url = " | ||
</ | </ | ||
+ | |||
+ | __// | ||
===== Adding a custom shield ===== | ===== Adding a custom shield ===== | ||
- | **If you want your shield to support banner decoration, | + | **If you want your shield to support banner decoration |
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.\\ | ||
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); | + | public static final Item NETHERITE_SHIELD = new FabricShieldItem(new FabricItemSettings().maxDamage(2500), |
</ | </ | ||
Line 76: | Line 51: | ||
<code java> | <code java> | ||
- | Registry.register(Registry.ITEM, new Identifier(" | + | Registry.register(Registries.ITEM, new Identifier(" |
</ | </ | ||
- | And our shield is done!\\ | + | If you want to add your shield to a creative tab, add this into your '' |
+ | <code java> | ||
+ | ItemGroupEvents.modifyEntriesEvent(ItemGroups.COMBAT).register(entries -> { | ||
+ | entries.add(NETHERITE_SHIELD); | ||
+ | }); | ||
+ | </ | ||
+ | |||
+ | And our shield is (code-wise) | ||
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 | + | For the texture, you can use anything. A good place to start is to look at Mojang's shield |
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: \\ | + | |
+ | |||
+ | Inside '' | ||
<code javascript> | <code javascript> | ||
{ | { | ||
Line 100: | Line 85: | ||
} | } | ||
</ | </ | ||
- | Put it in '' | + | |
- | For the blocking model, use this: \\ | + | In the same folder, create another file, '' |
<code javascript> | <code javascript> | ||
{ | { | ||
Line 107: | Line 92: | ||
} | } | ||
</ | </ | ||
- | Plop it in resources/ | + | |
- | Don't forget to add it to **en_us.json** in '' | + | Lastly, create a ''shields.json'' |
<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 | ||
- | </ | ||
- | |||
- | |||
- | This is where mixins get involved. | ||
- | |||
- | First 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, | ||
+ | Don't forget to add it to **en_us.json** in '' | ||
<code javascript> | <code javascript> | ||
{ | { | ||
- | | + | "item.examplemod.netherite_shield": "Netherite Shield" |
- | | + | |
- | " | + | |
- | "net.fabricmc.ExampleMod" | + | |
- | ], | + | |
- | " | + | |
- | | + | |
- | ] | + | |
- | } | + | |
- | [...] | + | |
} | } | ||
- | </ | + | </ |
- | + | And with that, your non-decorateable | |
- | Ok, so now that is done, we can work in our client initializer. | + | |
- | + | ||
- | First, we will need to create an '' | + | |
- | <code java> | + | |
- | public class ExampleModClient implements ClientModInitializer { | + | |
- | + | ||
- | public static final EntityModelLayer NETHERITE_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_SHIELD_MODEL_LAYER, | + | |
- | } | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | Then we will register our 2 '' | + | |
- | + | ||
- | <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_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. | + | |
- | + | ||
- | 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; | + | |
- | 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 class RendererMixin { | + | |
- | private ShieldEntityModel modelNetheriteShield; | + | |
- | 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; | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | 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, | + | |
- | + | ||
- | @Final | + | |
- | @Shadow | + | |
- | private EntityModelLoader entityModelLoader; | + | |
- | + | ||
- | + | ||
- | @Inject(method = " | + | |
- | private void setModelNetheriteShield(CallbackInfo ci){ | + | |
- | this.modelNetheriteShield = new ShieldEntityModel(this.entityModelLoader.getModelPart(ExampleModClient.NETHERITE_SHIELD_MODEL_LAYER)); | + | |
- | } | + | |
- | + | ||
- | @Inject(method = " | + | |
- | 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 | + | |
- | public void onInitializeClient() { | + | |
- | + | ||
- | } | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | Before we do any work in our client mod initializer, | + | |
- | + | ||
- | <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> | + | |
- | public class ExampleModClient implements ClientModInitializer { | + | |
- | + | ||
- | @Override | + | |
- | public void onInitializeClient() { | + | |
- | 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. | + | |
- | + | ||
- | 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_TEXTURE, | + | |
- | 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, | + | |
- | + | ||
- | @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 ''// | + | |
- | '' | + | |
- | } | + | |
- | } | + | |
- | + | ||
- | + | ||
- | } | + | |
- | </ | + | |
- | + | ||
- | 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.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, | + | |
- | + | ||
- | <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> | + | |
- | public class ExampleModClient implements ClientModInitializer { | + | |
- | + | ||
- | @Override | + | |
- | public void onInitializeClient() { | + | |
- | ClientSpriteRegistryCallback.event(SpriteAtlasTexture.BLOCK_ATLAS_TEX).register((atlasTexture, | + | |
- | 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, | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | 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, 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.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 // | + | |
- | + | ||
- | <code java> | + | |
- | public static final Item NETHERITE_SHIELD = new FabricBannerShieldItem(new FabricItemSettings().maxDamage(2500).group(ItemGroup.COMBAT), | + | |
- | </ | + | |
- | + | ||
- | The only thing we will need to do now is to add a simple mixin. | + | |
- | + | ||
- | 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 static final Identifier NETHERITE_SHIELD_BASE = new Identifier(" | + | |
- | private static final Identifier NETHERITE_SHIELD_BASE_NO_PATTERN = new Identifier(" | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | 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 = new Identifier(" | + | |
- | private static final Identifier NETHERITE_SHIELD_BASE_NO_PATTERN = new Identifier(" | + | |
- | + | ||
- | @Inject(method = " | + | |
- | 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 ''// | + | |
- | FabricShieldBannerRendering.render(stack, | + | |
- | callbackInfo.cancel(); | + | |
- | } | + | |
- | } | + | |
- | + | ||
- | + | ||
- | } | + | |
- | </ | + | |
- | + | ||
- | That is now all of the complicated things | + | |
- | + | ||
- | 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> | + | |
- | { | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | } | + | |
- | </ | + | |
- | Now your shield | + | ===== Adding a custom |
+ | If you want to make your shield accept banners and decorateable like a vanilla shield, the process is slightly different. |
tutorial/shield.txt · Last modified: 2024/07/03 07:08 by solidblock