This repository is the setup for a workshop to teach the basics of programming by creating a modification for Minecraft. It is based on the Fabric Example Mod.
If you want to create your own mod, but have no idea where to start, you can follow this video on YouTube to set everything up on your PC. You can find more information about the Fabric Minecraft Mod in the official wiki. To create textures for Minecraft you can use the Nova Skin Editor.
If you have IntelliJ and a JDK > version 17 ready, just checkout this repository and open the build.gradle file as new IntelliJ project.
Gradle will automatically setup everything for you.
To run Minecraft add the run configuration Add configuration -> Application -> Minecraft Client.
For further setup instructions please see the fabric wiki page that relates to the IDE that you are using.
- Decide with the participants on a name for the mod and rename the following files and properties accordingly
gradle.properties->maven-groupgradle.properties->archives_base_namesrc/main/java/net/fabricmc/example/ExampleMod.javasrc/main/java/net/fabricmc/example/mixin/ExampleMixin.javasrc/main/resources/fabric.mod.json->entrypoints->mainsrc/main/resources/modid.mixins.json->ExampleMixin
- Add a new sword to the game in the file Mod.java.
- In the
onInitializemethod, create a new variableItem newSword. - Initialize
newSwordwith a newSwordItemand use the following parameters (IntelliJ will handle all imports for you):ToolMaterials.DIAMONDto give the sword a material- Let the group decide for a number to use as
attackDamage(15 is very powerful, for reference). - Use
2.0for another float for the attack speed. - Use
FabricItemSettings().group(ItemGroup.COMBAT)as settings to give the sword a group. This is important, because it sets the group where you can find your sword later in the inventory in creative mode.
- Register the new item in the game by adding
net.minecraft.util.registry.Registry.register(Registry.ITEM, new Identifier("modid", "new_sword"), newSword); - The game should run properly and you should have the new item without texture in the combat group in the creative mode inventory.
- In the
- Decide for a name for the new sword
- Add the file
src/main/resources/assets/modid/lang/en_us.json - Set the name in this file in the following format:
{ "item.modid.new_sword": "<your_name>" }
- Add the file
- Add a texture for the new sword
- Go to the NovaSkinEditor and create a texture for the new item together.
- Download the new icon and place it under
src/main/resources/assets/modid/textures/item/new_sword.png. - To add the texture and metadata for the new item create the file
src/main/resources/assets/modid/models/item/new_sword.jsonwith the following content to reference the new icon.
{ "parent": "item/generated", "textures": { "layer0": "modid:item/new_sword" } }- The new icon should now show up for the new item.
- Implement logic to give the player the new sword if a specific formation of special blocks is broken in correct order (for example if emerald blocks in the shape of a sword are broken from top to bottom). You can use the following snippets:
PlayerBlockBreakEvents.AFTER.register(((world, player, position, state, blockEntity) -> {}));to register code that should be executed whenever the player breaks a block.player.getInventory().offerOrDrop(newSword.getDefaultStack());to give the new sword to the player.state.isOf(Blocks.EMERALD_BLOCK)to check if the broken block is an emerald block.
This template is available under the CC0 license. Feel free to learn from it and incorporate it in your own projects.