Minecraft Blogs / Tutorial

More Swords | Command Block Tutorial

  • 2,842 views, 5 today
  • 3
  • 2
Code202's Avatar Code202
Level 71 : Legendary Engineer
302
Hello! Today I've created a tutorial for you want to learn command blocks!

Click here to download mod.template!

Chapter 1: Setting up a working environment

ModName.cdx is the baseplate for my tutorial. For this tutorial, together we will create a "More Swords" mod. It will add 5 new swords into the game, the Earth Sword, Ice Sword, Water Sword, Fire Sword and Air Sword! They will all use particles, actions and crafting recipes, all the basics to a vanilla mod!

First off, we need to rename ModName to the name of our mod. Let’s call it "MoreSwords". Next we need to open up the file. Inside you'll see 6 folders. You can delete the folder called “textures”, we will not be using that. Everything else, though, is important.

Go into "elements". You can delete "block", "entity", "menu" and "player". You will be left only with "item" and "crafting". Now go into "item" and delete "item.slot". Then, exit out of that folder and enter the "crafting" folder. Delete everything but "crafting.floor". Congratulations, you have now successfully set up our working environment!

Chapter 2: Creating our first item

Go into "item", and then double click on "item.handheld" to open it up. You should see a slightly complex looking baseplate. So what is it doing? The first thing this code does it run an INIT (initialization, an initial value for an object or variable). This will run as soon as the mod is loaded into a world for the first time, meaning it will only ever activate once. Replace "itemname" with earthsword. Now, on the second string (or command), replace "itemid" with the id of the item. We will be using a wooden sword (don't worry, it will be completely revamped), so replace "itemid" with "wooden_sword". Next, replace "Item Name" with "Earth Sword". This is the ingame name of the item. It will appear when you hover over it. On the next line of code, you will see "/actionhere". This will bring us into actions.

The first action we will include will be the main ability of the item. Causing an explosion in the ground. This will be done when the player hits a mob. Underneath where the INIT is run, type "INIT:/scoreboard objectives add hit stat.damageDealt". Now you can replace "/execute @a[score_earthsword_min=1] ~ ~ ~ /actionhere" with "/execute @a[score_earthsword_min=1,score_hit_min=1] ~ ~ ~ /execute @e[rm=1,r=5] ~ ~ ~ /summon primed_tnt". This will cause an explosion when the player hits an entity. Now let’s add a particle.
Before we run the previous command that we just did, above it, type "/execute @a[score_earthsword_min=1,score_hit_min=1] ~ ~ ~ /execute @e[rm=1,r=5] ~ ~ ~ /particle blockcrack ~ ~ ~ 1 1 1 0.05 100 normal @a 2". This will cause a particle effect of dirt before the explosion happens.

Now the last thing you have to do is, underneath "/scoreboard players set @a earthsword 0", type "/scoreboard players set @a hit 0". This will stop everything from happening constantly. Now you have created your first item, the Earth Sword!

Chapter 3: Ice Sword

Now we must do exactly the same thing (execpt change a couple of variables)! Copy that entire section of code, and paste it underneath the first code (the Earth Sword), preferably one space between the two just to seperate them. Next, go ahead and replace "Earth Sword" with "Ice Sword", "earthsword" with "icesword" and "wooden_sword" with "diamond_sword" (because its blue, but it won’t be more or less OP!). Also, go back to the Earth Sword code and delete "/scoreboard players set @a hit 0". We won't be needing to run that twice!

Now to look at the particle effect. Replace where it says "normal @a 2" with "normal @a 79". 79 is the block id of ice. Replace "/execute @a[score_earthsword_min=1,score_hit_min=1] ~ ~ ~ /execute @e[rm=1,r=5] ~ ~ ~ /summon primed_tnt" with "/execute @a[score_icesword_min=1,score_hit_min=1] ~ ~ ~ /execute @e[rm=1,r=5] ~ ~ ~ /fill ~ ~ ~ ~ ~1 ~ ice 0 keep". This will entrap the entity you it in ice, until it suffocates. And you’re done! That’s two out of five!

Chapter 4: Fire Sword

Now do the same, you know what to do! Copy + Paste below, turn all the variables to "firesword", "Fire Sword" and the item id will be "golden_sword". Remove the command "/scoreboard players set @a hit 0" from the Ice Sword code, so it is now underneath the Fire Sword code. Next replace "/particle blockcrack ~ ~ ~ 1 1 1 0.05 100 normal @a 79" with "/particle flame ~ ~ ~ 1 1 1 0.05 100". Then, replace "/execute @a[score_icesword_min=1,score_hit_min=1] ~ ~ ~ /execute @e[rm=1,r=5] ~ ~ ~ /fill ~ ~ ~ ~ ~1 ~ ice 0 keep" with "/execute @a[score_firesword_min=1,score_hit_min=1] ~ ~ ~ /entitydata @e[rm=1,r=5] {Fire:1000s}". Finished! Now you have created a Fire Sword that will burn all entities that you attack!

Chapter 5: Air Sword

Hopefully you understand what we are doing now. Do exactly the same as last time for the variables, but replace the item id as "Iron Sword". Now that everything has been changed according to the Air Sword, you should have a whole new area for the Air Sword code. And again, delete "/scoreboard players set @a hit 0" for the Fire Sword, so it is only in the Air Sword code. Now for the particle. Replace the current particle command with this "/particle cloud ~ ~ ~ 1 1 1 0.05 100". This will create cloud particles around the entity that you hit. Then, replace "/execute @a[score_firesword_min=1,score_hit_min=1] ~ ~ ~ /entitydata @e[rm=1,r=5] {Fire:1000s}" with "/execute @a[score_airsword_min=1,score_hit_min=1] ~ ~ ~ /effect @e[rm=1,r=5] levitation 3 10 true". This will send any entity you hit flying into the air! Done, one more to go!

Chapter 6: Water Sword

The last sword, the Water Sword! Do as you did before, accept replace the item id with "diamond_sword". Replace "/particle cloud ~ ~ ~ 1 1 1 0.05 100" with "/particle splash ~ ~ ~ 1 1 1 0.05 100". Then, replace "/execute @a[score_airsword_min=1,score_hit_min=1] ~ ~ ~ /effect @e[rm=1,r=5] levitation 3 10 true" with "/execute @a[score_watersword_min=1,score_hit_min=1] ~ ~ ~ /effect @e[rm=1,r=5] slowness 3 3 true". This will slow down any entity you hit as if they were drenched with water! And also, don't forget to delete "/scoreboard players set @a hit 0" in the Air Sword code, so it only exits in the Water Sword code. Now we need to create the crafting recipes!

Bonus Chapter:

Try and create an Ender Sword based on what you know! You could use "/spreadplayers" or "/tp". Think of it as a little challange to test your programming knowledge!

Chapter 7: Crafting recipes

Save "item.handheld", it’s now finished, done! Go out of "item" and into "crafting", and open up "floor.crafting". Copy what you see four times, preferably with spaces in between, so you have five recipe codes in total. Replace "item" with an item id. For the first line of code, make the first "item" (ignore the 0, thats the damage value) with "iron_sword". Do this for every single "item' that comes after "FloorCrafting:" for each recipe (all five). You will craft each sword out of an iron sword and a selected item. Replace the second "item" on the first line of code with "dirt". This will create the Earth Sword. Then replace the third "item" with "wooden_sword", and "Item Name" with "Earth Sword". Do the same for each, remembering what sword you used for our custom swords. Make the Ice Sword's special item to craft it (like the dirt for the Earth Sword) "ice", the Fire Sword's is "blaze_powder", the Air Sword's is "quartz" (it matches the best), and the Water Sword's is "water_bucket". Now you have completed all of your sword's crafting recipes!

Chapter 8: Compiling the mod

Now comes the tricky part! You are going to need to go to "mrgarretto.com/cmdcombiner" then you need to click on “Other Combiners” and select the 1.11 version, though the combiner will always automatically be in the latest version, so you shouldn’t have to do this (if 1.11 is the latest version). If it doesn’t work, it probably means that MrGarretto hasn’t upDated the generator yet, in which case all you have to do is paste the command into “mrgarretto.com/entityconverter”. You can add signs to your mod and change the blocks for the module used, but first you need to get the code in the generator (credit to MrGarreto for the generator). Go into "item.handheld", copy all of that code and paste it into the generator. Do the same for the floor craftings. Now let’s give our mod a custom message when the mod starts up! Go into "text", then open up "display.start.game".

Inside of "display.start.game", replace "YourUsername" with your username! Then, replace "text" with any line of text you want. I am going to replace it with "Adds heaps of new, cool swords to Minecraft!". This will display when the mod loads up. Finally, paste all of that code into the generator too.

Then click "generate". It will generate a huge amount of compiled code. I will explain what to do with that later on.

Chapter 9: Playing with the mod ingame

I'm sure you've been really excited about this part, playing with these brand new items ingame! Now you have got your compiled code, create a new .zip (compressed) folder (this is to prevent anyone from changing any of your code), preferably do this in the Cindrex folder (the one you downloaded), and call it "MoreSwords". Inside of the Cindrex folder (since you can't actually add new files inside of a compressed one), create one new text documents (.txt) called "mod.install". Inside of that, copy and paste in the compiled mod code. Save that, and then go back into "MoreSwords" (not the compressed one, the one you did all your coding in) and open up "info". Then, open up "info". Fill that out. Add a description, mine is "Adds heaps of cool new swords into your Minecraft world! Loads of fun!". Then, after you’re done, copy and paste "cdx.info" into your "MoreSwords.zip" folder (the compressed one this time). Then cut and paste "mod.install" into "MoreSwords.zip". And you’re done! Now, all you need to do is to install your mod into your world by typing this command in chat "/give @p command_block". Place the command block down, copy and paste the compiled mod code into it, and then activate the command block however you want to! Then, your mod should be fully functional! If not, you’re probably made an error or a spelling mistake, but that’s fine, you can always go and fix that up. Have fun with the mod, and try to make your own items!

Written by Code202
Tags

Create an account or sign in to comment.

Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome