tutorial:shield
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tutorial:shield [2024/01/14 18:05] – fixed model cringestar_boi | tutorial:shield [2024/09/29 19:35] (current) – updated with 1.21 guide and past guides cringestar_boi | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Making a Custom Shield in Minecraft [1.19-1.20] ====== | + | ====== Making a Custom Shield in Minecraft [1.19-1.21.1] ====== |
+ | :!: The tutorial depends on third-party libraries. | ||
+ | |||
+ | 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, StellarWind22 has already made a library to help with this! If she didn' | Luckily, StellarWind22 has already made a library to help with this! If she didn' | ||
Line 10: | 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> | + | **gradle.properties** |
- | fabric_shield_lib_version=1.7.2-1.20.4 | + | <file properties gradle.properties> |
- | midnightlib_version=1.5.2-fabric | + | fabric_shield_lib_version=1.7.2-1.21.1 |
- | mod_menu_version=9.0.0-pre.1 | + | midnightlib_version=1.5.8-fabric |
+ | mod_menu_version=11.0.1 | ||
fabricasm_version=2.3 | fabricasm_version=2.3 | ||
- | </code>\\ | + | </file> |
- | **build.gradle** (under dependencies)\\ | + | |
- | <code java> | + | **build.gradle** (under |
+ | <file groovy build.gradle> | ||
modImplementation " | modImplementation " | ||
- | |||
modImplementation " | modImplementation " | ||
- | |||
modImplementation " | modImplementation " | ||
- | |||
modImplementation " | modImplementation " | ||
- | </code>\\ | + | </file> |
At the time of writing, the latest project.fabric_shield_lib_version should be 1.7.2, which supports versions: | 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.5** - **1.20.6** ('' | ||
* **1.20.2** - **1.20.4** ('' | * **1.20.2** - **1.20.4** ('' | ||
* **1.20** - **1.20.1** ('' | * **1.20** - **1.20.1** ('' | ||
Line 36: | Line 39: | ||
* **1.18.2** ('' | * **1.18.2** ('' | ||
* **1.17.1** ('' | * **1.17.1** ('' | ||
- | **build.gradle** (inside repositories, the one above dependencies)\\ | + | **build.gradle** (inside |
- | <code java> | + | <file groovy build.gradle> |
maven {url = ' | maven {url = ' | ||
maven {url " | maven {url " | ||
maven {url = " | maven {url = " | ||
- | </code> | + | </file> |
__// | __// | ||
===== Adding a custom shield ===== | ===== Adding a custom shield ===== | ||
- | **If you want your shield to support banner decoration on your shield, please skip to the next section**\\ | + | **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!\\ \\ | + | |
- | If you have followed the above steps correctly and refreshed the project, then you will have the FabricShieldLib installed.\\ | + | |
- | If so, the first step to do is create a new instance of an Item like: | + | |
- | <code java> | + | |
- | public static final Item NETHERITE_SHIELD = new FabricShieldItem(new FabricItemSettings().maxDamage(2500), | + | |
- | </ | + | |
- | Then, we have to register it, like so: | + | On to the non-boring steps! We will now make a custom shield! |
- | + | ||
- | <code java> | + | |
- | Registry.register(Registries.ITEM, | + | |
- | </ | + | |
- | If you want to add your shield | + | If you have followed the above steps correctly and refreshed the project, then you will have the FabricShieldLib installed. |
- | <code java> | + | |
- | ItemGroupEvents.modifyEntriesEvent(ItemGroups.COMBAT).register(entries -> { | + | If so, the first step to do is create |
- | entries.add(NETHERITE_SHIELD); | + | <code java TutorialItems> |
- | }); | + | public final class TutorialItems { |
+ | // ... | ||
+ | public static final Item NETHERITE_SHIELD = register(new FabricShieldItem(new FabricItemSettings().maxDamage(2500), 10, 13, Items.NETHERITE_INGOT), | ||
+ | //The constructor for the item takes in the following values: FabricBannerShieldItem(settings.maxDamage(durability), cooldownTicks, | ||
+ | // ... | ||
+ | } | ||
</ | </ | ||
- | And our shield is (code-wise) done!\\ | + | If you want to add your shield to a [[itemgroup|item groups]], for example, |
- | 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 to look at Mojang' | + | |
- | Now, for the models, we have to write a few .json files.\\ | + | |
+ | < | ||
+ | public class ExampleMod implements ModInitializer { | ||
+ | @Override | ||
+ | public void onInitialize() { | ||
+ | ItemGroupEvents.modifyEntriesEvent(ItemGroups.COMBAT).register(entries -> { | ||
+ | entries.add(NETHERITE_SHIELD); | ||
+ | }); | ||
+ | } | ||
+ | } | ||
+ | </ | ||
- | Inside '' | + | And our shield is (code-wise) done! |
- | <code javascript> | + | 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 to look at Mojang' | ||
+ | |||
+ | Now, for the models, we have to write a few .json files. | ||
+ | |||
+ | Inside '' | ||
+ | |||
+ | <file javascript | ||
{ | { | ||
" | " | ||
" | " | ||
- | " | + | " |
}, | }, | ||
" | " | ||
Line 86: | Line 99: | ||
" | " | ||
}, | }, | ||
- | " | + | " |
} | } | ||
] | ] | ||
} | } | ||
- | </code>\\ | + | </file> |
In the same folder, create another file, '' | In the same folder, create another file, '' | ||
- | <code javascript> | + | <file javascript |
{ | { | ||
" | " | ||
" | " | ||
- | " | + | " |
} | } | ||
} | } | ||
- | </code>\\ | + | </file> |
- | Lastly, create a '' | + | Then, as a [[tags|conventional tag]], create a '' |
- | <code javascript> | + | <code javascript |
{ | { | ||
" | " | ||
" | " | ||
- | "examplemod: | + | "tutorial: |
] | ] | ||
} | } | ||
- | </ | + | </ |
- | Don't forget | + | Lastly, |
- | <code javascript> | + | <code javascript |
{ | { | ||
- | "item.examplemod.netherite_shield": | + | |
+ | " | ||
+ | " | ||
+ | ] | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Don't forget to add it to **en_us.json** in '' | ||
+ | <code javascript resources/ | ||
+ | { | ||
+ | | ||
} | } | ||
</ | </ | ||
Line 123: | Line 146: | ||
The process is slightly different if you want to make your shield accept banners and decorateable like a vanilla shield. | 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 FabricBannerShieldItem: | + | We still make the item in the same way, just make it a '' |
- | <code java> | + | <code java TutorialItems> |
- | public static final Item NETHERITE_BANNER_SHIELD = new FabricBannerShieldItem(new FabricItemSettings().maxDamage(2500), | + | public static final Item NETHERITE_BANNER_SHIELD = register(new FabricBannerShieldItem(new FabricItemSettings().maxDamage(2500), |
</ | </ | ||
- | + | If you want to add your shield to a [[itemgroup|item groups]], for example, the " | |
- | Then, we have to register it: | + | |
- | <code java> | + | <yarncode |
- | Registry.register(Registries.ITEM, | + | public class ExampleMod implements ModInitializer { |
- | </ | + | |
- | + | | |
- | If you want to add your shield to a creative tab, add this into your '' | + | ItemGroupEvents.modifyEntriesEvent(ItemGroups.COMBAT).register(entries -> { |
- | <code java> | + | // ... |
- | ItemGroupEvents.modifyEntriesEvent(ItemGroups.COMBAT).register(entries -> { | + | |
- | entries.addAfter(Items.SHIELD, | + | }); |
- | }); | + | } |
- | </code> | + | } |
+ | </yarncode> | ||
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, | 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, | ||
- | |||
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 160: | 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_shield_model_layer, ShieldEntityModel:: | + | EntityModelLayerRegistry.registerModelLayer(NETHERITE_BANNER_SHILED_MODEL_LAYER, ShieldEntityModel:: |
} | } | ||
} | } | ||
Line 174: | Line 197: | ||
<code java> | <code java> | ||
+ | @Environment(EnvType.CLIENT) | ||
public class ExampleModClient implements ClientModInitializer { | public class ExampleModClient implements ClientModInitializer { | ||
- | + | | |
- | | + | |
| | ||
public static ShieldEntityModel modelNetheriteShield; | public static ShieldEntityModel modelNetheriteShield; | ||
Line 190: | Line 213: | ||
<code java> | <code java> | ||
+ | @Environment(EnvType.CLIENT) | ||
public class ExampleModClient implements ClientModInitializer { | public class ExampleModClient implements ClientModInitializer { | ||
- | + | | |
- | | + | |
| | ||
public static ShieldEntityModel modelNetheriteShield; | public static ShieldEntityModel modelNetheriteShield; | ||
Line 210: | Line 233: | ||
Next, we have to create our two '' | Next, we have to create our two '' | ||
<code java> | <code java> | ||
+ | @Environment(EnvType.CLIENT) | ||
public class ExampleModClient implements ClientModInitializer { | public class ExampleModClient implements ClientModInitializer { | ||
- | public static final EntityModelLayer netherite_banner_shield_model_layer = new EntityModelLayer(new Identifier(" | + | public static final EntityModelLayer netherite_banner_shield_model_layer = new EntityModelLayer(Identifier.of("tutorial", " |
public static ShieldEntityModel modelNetheriteShield; | public static ShieldEntityModel modelNetheriteShield; | ||
- | public static final SpriteIdentifier NETHERITE_BANNER_SHIELD_BASE = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, | + | 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, | + | public static final SpriteIdentifier NETHERITE_BANNER_SHIELD_BASE_NO_PATTERN = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, |
@Override | @Override | ||
Line 233: | Line 257: | ||
Finally, we are going to register our shield with the '' | Finally, we are going to register our shield with the '' | ||
<code java> | <code java> | ||
+ | @Environment(EnvType.CLIENT) | ||
public class ExampleModClient implements ClientModInitializer { | public class ExampleModClient implements ClientModInitializer { | ||
- | + | public static final EntityModelLayer netherite_banner_shield_model_layer = new EntityModelLayer(Identifier.of("tutorial", " | |
- | public static final EntityModelLayer netherite_banner_shield_model_layer = new EntityModelLayer(new Identifier(" | + | |
public static ShieldEntityModel modelNetheriteShield; | public static ShieldEntityModel modelNetheriteShield; | ||
- | public static final SpriteIdentifier NETHERITE_BANNER_SHIELD_BASE = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, | + | 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, | + | public static final SpriteIdentifier NETHERITE_BANNER_SHIELD_BASE_NO_PATTERN = new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, |
@Override | @Override | ||
Line 257: | Line 281: | ||
} | } | ||
} | } | ||
- | </ | + | </ |
- | That is all of our code done, we only have a few .json files to make. \\ | + | That is all of our code done, we only have a few json files to make. |
- | First, create a '' | + | First, create a '' |
- | + | <code javascript | |
- | Inside of it, you will have to list your '' | + | |
- | <code javascript> | + | |
{ | { | ||
" | " | ||
{ | { | ||
" | " | ||
- | " | + | " |
}, | }, | ||
{ | { | ||
" | " | ||
- | " | + | " |
} | } | ||
] | ] | ||
Line 279: | Line 301: | ||
</ | </ | ||
- | Next, inside '' | + | Next, inside '' |
- | + | <code javascript | |
- | <code javascript> | + | |
{ | { | ||
" | " | ||
Line 289: | Line 310: | ||
" | " | ||
}, | }, | ||
- | " | + | " |
} | } | ||
] | ] | ||
} | } | ||
- | </ | + | </ |
In the same folder, create another file, '' | In the same folder, create another file, '' | ||
- | <code javascript> | + | <code javascript |
{ | { | ||
" | " | ||
" | " | ||
- | " | + | " |
} | } | ||
} | } | ||
- | </ | + | </ |
- | For this next step, you will add a '' | + | For this next step, you will add a '' |
- | Then, you will need to make a '' | + | |
Then, you will move both of these textures into '' | Then, you will move both of these textures into '' | ||
- | Lastly, create a '' | + | Next, create a '' |
- | <code javascript> | + | <code javascript |
{ | { | ||
" | " | ||
" | " | ||
- | "examplemod: | + | "tutorial: |
] | ] | ||
} | } | ||
- | </ | + | </ |
+ | |||
+ | Finally create a '' | ||
+ | <code javascript resources/ | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | ] | ||
+ | } | ||
+ | </ | ||
Don't forget to add it to **en_us.json** in '' | Don't forget to add it to **en_us.json** in '' | ||
<code javascript> | <code javascript> | ||
{ | { | ||
- | "item.examplemod.netherite_banner_shield": | + | "item.tutorial.netherite_banner_shield": |
- | "item.examplemod.netherite_banner_shield.red": | + | "item.tutorial.netherite_banner_shield.red": |
- | "item.examplemod.netherite_banner_shield.orange": | + | "item.tutorial.netherite_banner_shield.orange": |
- | "item.examplemod.netherite_banner_shield.yellow": | + | "item.tutorial.netherite_banner_shield.yellow": |
- | "item.examplemod.netherite_banner_shield.lime": | + | "item.tutorial.netherite_banner_shield.lime": |
- | "item.examplemod.netherite_banner_shield.green": | + | "item.tutorial.netherite_banner_shield.green": |
- | "item.examplemod.netherite_banner_shield.light_blue": | + | "item.tutorial.netherite_banner_shield.light_blue": |
- | "item.examplemod.netherite_banner_shield.cyan": | + | "item.tutorial.netherite_banner_shield.cyan": |
- | "item.examplemod.netherite_banner_shield.blue": | + | "item.tutorial.netherite_banner_shield.blue": |
- | "item.examplemod.netherite_banner_shield.purple": | + | "item.tutorial.netherite_banner_shield.purple": |
- | "item.examplemod.netherite_banner_shield.magenta": | + | "item.tutorial.netherite_banner_shield.magenta": |
- | "item.examplemod.netherite_banner_shield.pink": | + | "item.tutorial.netherite_banner_shield.pink": |
- | "item.examplemod.netherite_banner_shield.brown": | + | "item.tutorial.netherite_banner_shield.brown": |
- | "item.examplemod.netherite_banner_shield.white": | + | "item.tutorial.netherite_banner_shield.white": |
- | "item.examplemod.netherite_banner_shield.light_gray": | + | "item.tutorial.netherite_banner_shield.light_gray": |
- | "item.examplemod.netherite_banner_shield.gray": | + | "item.tutorial.netherite_banner_shield.gray": |
- | "item.examplemod.netherite_banner_shield.dark_gray": | + | "item.tutorial.netherite_banner_shield.dark_gray": |
- | "item.examplemod.netherite_banner_shield.black": | + | "item.tutorial.netherite_banner_shield.black": |
} | } | ||
</ | </ | ||
And now your shield is fully completed and supports banner decoration! | And now your shield is fully completed and supports banner decoration! | ||
+ | |||
+ | ===== Changes for 1.20.6 ===== | ||
+ | If you are working in 1.20.6, first change the FabricShieldLib and FAPI versions accordingly and change your other dependencies to these versions:\\ | ||
+ | |||
+ | <file properties gradle.properties> | ||
+ | mod_menu_version=10.0.0-beta.1 | ||
+ | midnightlib_version=1.5.5-fabric | ||
+ | </ | ||
+ | |||
+ | Next, change all instances of '' | ||
+ | |||
+ | Then, change your '' | ||
+ | |||
+ | Finally, move your '' | ||
+ | |||
+ | ===== Changes for 1.20.4 ===== | ||
+ | If you are working in 1.20.4, **follow the changes for 1.20.6 first**, then change the FabricShieldLib and FAPI versions accordingly and change your other dependencies to these versions:\\ | ||
+ | |||
+ | **gradle.properties** | ||
+ | <file properties gradle.properties> | ||
+ | midnightlib_version=1.5.2-fabric | ||
+ | mod_menu_version=9.0.0-pre.1 | ||
+ | </ | ||
+ | |||
+ | Additionally, | ||
===== Changes for 1.19 ===== | ===== Changes for 1.19 ===== | ||
- | If you are working in 1.19, make sure to change the FabricShieldLib and FAPI versions accordingly | + | If you are working in 1.19, **follow the changes for 1.20.6 and 1.20.4 first**, then change the FabricShieldLib and FAPI versions accordingly and change your other dependencies to these versions:\\ |
**gradle.properties** | **gradle.properties** | ||
- | <code java> | + | <file properties gradle.properties> |
midnightlib_version=1.0.0-fabric | midnightlib_version=1.0.0-fabric | ||
mod_menu_version=4.2.0-beta.2 | mod_menu_version=4.2.0-beta.2 | ||
- | </code> | + | </file> |
tutorial/shield.1705255555.txt.gz · Last modified: 2024/01/14 18:05 by cringestar_boi