I’ve added a lot of custom storage to Minecraft and in today’s video I’m going to be teaching you guys how to add your own custom swords to the game in today’s data pack tutorial the first step in this process is probably to add the custom texture to the item that you’re Actually wanting to make so in this case my sword is red and I believe this is my knock sword texture I’ve actually already made a tutorial on adding custom textured items to the game and so you should check out that tutorial if you have not already done so to learn how to Actually make a custom textured sword in today’s video I’m going to be teaching you guys how to actually make the sword have functionality to it the first step that I take when making a data pack is to determine what exactly your goal is so in this case I’m wanting to make a Custom sword but what exactly does that mean defining exactly what we’re looking for in our data pack is really important because it allows us to break down that goal into multiple steps that we can tackle one at a time so in this case I want to be able to take a custom sword So this is a stone sword with custom model data 3 that is my Notch Apple sword and I want to be able to detect when I hit a mob with the sword and I want a custom thing to happen at that mob and you’ll notice that as we defined That we got quite a few ands into that sentence and so specifically what I’m needing is I need a way to detect that I hit a mob a way to determine that it’s the custom sword rather than just a regular stone sword and then I need to know which which mob I actually hit and where it is so the cool thing is now that we have a list of what we need to do we can pretty easily incrementally tackle it so let me jump into the code and explain what we’re going to do opening my data pack with Visual Studio code you can see that I have defined the three steps that we’re going to try to take which are determined when we hit a mob determine if a custom sword was held and then determine who and where the model hit is I’ll be developing this data pack Using MCB so if you want to follow along I do have a tutorial on how to set up that tool basically it’s a quick tool that compiles a single file down into multiple functions to generate your data back for you really helpful I have a Tutorial on how to set it up and how to use it go watch that LinkedIn that I card in the top right now the best way to actually determine if the player has hit a mob is to use an advancement to set up an advancement we will want to Go to our data pack go to the data folder go to whatever you are naming your data pack in this case I’m going with sword tutorial and we’ll have a functions folder probably already for wherever you put your functions but we’ll want to create a new folder and call this advancements so Inside your advancements folder you can create a text document except we’re going to not have the extension V Dot text instead we’re going to have a b dot Json and we can name this whatever we want I’m going to go with deal damage hit enter you will get a warning saying that If you change the file extension it could break it will not break though so then inside of your deal damage.json file we’re going to actually create an advancement there are generators for this I’m going to link the advancement generator that I personally use it’s made by mizod And uh he did a fantastic job on making a pretty accessible and easy to use generator using the generator got me this and so an advancement is basically a condition and then when that condition is met you can set up a reward that’s that’s all that in advancement really is So we’re setting up what the requirement is and the requirement is simply player hurt entity meaning the player is hurting an entity right and if that condition is met then we’re rewarded by running this function so we need to have a function in our sword tutorial pack named deal damage so I’ll create that in just a second by the way this is probably a good time to mention that I will be putting the download for this tutorial data pack in the video’s description it should be the top link so all of these uh advancements and other stuff that we’re going to be Using later in the tutorial you can just grab from there and you won’t need to type all of this out it should be a little bit easier for you guys so then you can just configure them uh like whatever your pack name is you’ll put it here right pack name Whatever your pack name is put it there and then as long as you have a function called deal damage this will work but I do not have a function named deal damage let’s create one so function deal damage and uh do it like that of course that’s How you do it in MCB if I was making this data pack normally I would want to navigate to my functions folder and then create a.mc function file named deal damage right and I can open this up one thing that you’ll notice is if I type something here like say hi Hi it’s going to also show up here right so that’s basically what uh MCB is doing stuff that I type in here shows up in here okay so technically we have sort of accomplished our goal number one which was to determine when we hit a mob there Is a problem and I’m going to show you it right now so in Minecraft I can hit reload and if I spawn in a cow and punch it awesome so I I said hi right well here’s the problem if I punch another cow it’s not going to run again that’s because I Actually have the advancement so if we run something like advancement uh Grant myself only and then this is uh called swords tutorial right sword tutorial deal damage the game says that I already have it but if I were to remove it or revoke it from myself when I punch Another mob I’m going to end up being able to say hi again right so that means that this Command right here is pretty important so in our data pack if we were to put this command into the deal damage function uh essentially we’re going to just revoke the deal damage advancement So if you think about what’s happening now I punch a mob I get an advancement right I meet this condition so I get this reward which is to run this function so I run this function and then I take it away from myself so that I’m primed next time to be able to Do it again so if we go over to Minecraft hit reload now every time I punch a cow I got thrown off there for a second because I still had deal damage so I can’t run the first time but now that I don’t have it and I punch the mob every Time I punch it it’s going to say hi right this applies to me using my sword using a stone sword using my fist whatever anytime I deal damage we run the command so first thing off of our objective list is complete okay so next up we need to determine if I’m using This specific custom sword rather than just any stone sword right so again this stone sword if you recall is just a stone sword with custom model data 3 and that’s how I get uh the texture applied so you might be thinking maybe why don’t we just check for a stone sword with Custom model data 6370003 that’s an okay method it works most of the time but suppose we were to have also an iron sword with this same number well we could have an issue if we forget to check for the stone sword part so instead I like to do a thing where you Add a custom tag to the item so this can be named literally whatever you want I’m going to go with custom item and then one if we hit enter here there’s no difference between these two items except this one has a custom tag you can check that if we want to run Data get entity at self selected item you’ll see this is a stone sword it has taken zero durability loss we know what the custom model data is and it has custom item colon one or yeah well this one does not have custom items so there is a Slight difference there right so at this point in our data pack we actually have two choices we can go uh very inefficient but easy route or we can go a slightly more difficult but much more efficient route and I’ll teach you guys both because they’re both valuable to Know so uh the first option is to just run with an execute command go execute as myself and then check if the NBT of my selected item which I was looking at earlier right selected item if the tag of my selected item is we called it custom item one right Then run say hi right so if we go back to Minecraft we can test this out so if we spawn in a cow you’ll remember this item here this is the one with custom item that that tag there so hit the cow with with either of these items nothing happens but if you Hit it with this sword now the uh command runs and that’s nice and all but an NBT check like we’re doing here to actually determine what the sword is is pretty much the most uh lag intensive test that we could be running our alternative is to go with what’s known as a predicate So this goes in a folder uh next to our advancements and functions folder called the predicate folder and inside of here you can put Json files similar to advancements basically a predicate is kind of sort of an advancement except instead of being a criteria that is met and then we get a Reward it’s just a criteria that we can check and now data packs do allow you to have folders inside of folder so you could put this literally wherever you want I would suggest in this case because we’re going to do a holding item check essentially let’s make another Folder and we’re just going to call it holding Aida and then I’m here this is where we’re going to put our Dot case on file now I actually already have this file made because I I use the generator because why type it all out but you can see we have a customsword.json and Essentially this is pretty similar to this is the advancement that we were looking at earlier right where we have a requirement and a reward except for this instead we have a condition and no reward or anything so in this case we’re checking the Entergy properties of myself And then we’re checking if the equipment in my main hand has the tag of custom tag one which I need to make sure I change this to item because we called our sword custom item not custom tag by the way while I’m at it I might as well Tell you about the site MC stacker I know I’ve mentioned it in some of my previous tutorials but it’s a really powerful generator to get all sorts of uh useful commands generated in this case I’m using a give command for a stone sword with custom model data of 6370003 right and then a custom tag here of custom item one like we had in the video so this generates the exact same thing that I had been doing in game except we can also add a custom name to it so we’re going to go custom item or let’s say custom sort name And then if you set the italics to be false uh it’s going to look the best in Minecraft we can run this and you’ll see now we have custom sword name showing up so uh that’s how my swords and other items work they just have a custom texture and A custom name so once you have that now you’re pretty much set um so let’s move on with the tutorial though maybe it is worth noting I added a give function to get this item just in case uh you guys are messing around with this pack that’s how you could get it Okay Side Track aside sorry about that got a little distracted but we have this predicate right I’m the custom item if if it has that in the main hand that is how this is going to check so how do we actually use this predicate well a predicate uses an execute if or unless Command so we can do unless predicate or if predicate those are pretty much our only options except you could also uh in the selector you can do execute as a self predicate whatever I like to keep it clean and just do if predicate and in this case this is the only predicate we Have so just pack name the folder we put it in which was holding item and then the name of it so custom sort and you’ll see when we run this I’m holding a stone sword right now so the test failed what if I hold the custom sword the test will pass And again this is just a more efficient way of determining if the item we’re holding is actually the right item so it’s a little bit more annoying to set up which is why I wanted to teach you guys both methods and so that means that if we go Back to our data pack and we put this uh predicate command to Executive predicate pack name path to predicate we can run say predicate works or whatever we want and if we save that hop over to Minecraft hit reload cow cool predicate works ignore predicate true in there I might Have messed up my recordings like five times on that so we finished up one we finished up two now we just need to figure out step three and step three is a little bit annoying because there’s no foolproof method to actually get it to work we can only get like a 99 accurate Method however one thing that we do know is that we’re going to need to execute as at entity right because we’re not executing as players anymore so we’re going to need to be able to execute as entities problem is here there’s actually a lot of entities in the game That we really shouldn’t be able to hit with our sword like if you think about it like type I don’t know here here’s a good example I mean arrow is a good example Minecart is a good example uh armor stand that’s a good example we don’t Probably want to actually be able to hit these entities with our custom swords and that’s where another folder gets added to this list so we have our functions our advancements our predicates and now we’re going to want to add tags specifically and here we are going to want to add an entity types Folder so we have tags and then entity types there are other types of tags you can make for items and blocks and I think structures as well maybe a few others but the main thing that we’re wanting right now are entity tax so we are going to make two of those well Actually I’m just going to copy paste over one that I’ve made because uh I’m not typing this all out again you don’t need to either feel free to just copy paste it from the download in the video’s description this is basically a list of every Minecraft mob in the game so essentially We just have a list of values right they’re all separated by commas and so we’re going to say Minecraft player Minecraft Bat mushrooms so on and so forth for all uh 70 something mobs in the game took a little bit to actually write this so I’m not going to make you Guys do it yourself however what you need to know about a tag is actually how to use it right so we have it it’s in the pack uh and how we’re going to actually use this is if we have a selector of all entities we can choose The type that they are and Minecraft actually has a fair amount of tags themselves these are these are entity tags so arrows would contain all the arrow types so I think that would be tipped arrows and uh golden arrows or whatever they’re called glowing arrows right uh and so you’ll notice what they’re Doing here is they’re adding a little hashtag in front of it so if we do hashtag Uh custom what’s this pack called swords tutorial that’s right tutorial and then this is uh called mobs you’ll see if we run this every player every cow every villager is going to say their name right but So as we were to like place down some item frames place down some armor stands they’re not on the the list right so they’re not going to say anything where if we didn’t have this if we just did add e cool well all of the items that are on The ground are going to say stuff all the item frames all the armor stands we don’t want that we just want the the mobs that we can actually deal damage to so with the tag actually set up what we want to do is we can do uh as at entity I remember it was type equals hashtag and then um sword tutorial and then this was mobs so technically this would work so now whenever I uh hit a mob while I’m holding this custom sword every mob in the world is going to say this right but that’s not what we’re Running we’re wanting only mobs that have just been hurt so what we’re going to want to do I mean we might as well cut down the distance uh because I would assume that we don’t want mobs that are a thousand blocks away to be checked to see if they were hit Which is not going to happen so we can cut down the distance to like some arbitrary amount this doesn’t matter too much what does matter is we want to actually end up having to do an NBT check for the hurt time that’s not the right thing part time of The actual entities Minecraft has this kind of interesting mechanic where when you hit a mod where a mob takes damage at all it gets invulnerability for 10 game ticks which is half a second and this is actually really useful because it’s a timer we can we can tap onto so That means that what we’re now doing is we’re looking for mobs within 10 blocks of us that have been hurt on the same game tick that I swung my sword so this is pretty foolproof because for the most part there aren’t going to be two mobs getting hurt at the exact same time In that close of a vicinity sometimes it could be false though I mean there’s actually been situations where I’ve been able to hit myself with this kind of funny I’m going to also show you guys the fix for that bug uh it’s really simple but Uh we can confirm that this works now if we hit save switch back over to Minecraft reload the game and go punch a cow again so you’ll see now instead of me saying that the predicate works now the cow is saying it let’s change this to something a bit More visual though we can run a particle flame let’s say it’s at one block up at this location with a fairly low speed and we’ll just do like 30 of them might as well force it to happen hit save Minecraft hit reload hit a cow died by the way only problem with the System if you kill the mob on your hit doesn’t actually detect that you hit them because there’s no mob to actually run the command so it’s a bit of a drawback because uh sometimes that will happen but now that we actually have it set up you’ll notice If I don’t want to hit kill the cow Flames will appear at the location oh and I think it is worth noting there’s literally pretty much no way to uh determine where an entity died after it’s dead because you can’t execute added identity so this is kind of the best we got unfortunately Um but yeah so technically this is a custom sort if you think about it it’s historic that when I hit a mob it does the thing at that mob but as I did mention there is a bit of a bug with this right now where the attacker could technically hit themselves with their Own sword which doesn’t make any sense so let’s fix that really simple fix just give the attacker a tag of something like uh I well okay I can’t capitalize it and the attacker whatever you can name it literally whatever you want doesn’t matter very much but then in uh our Check for the mob right we can check if it’s a mob we can check the distance of it we can check if it’s being hurt but we can also check to see that it’s tag is not am the attacker so this means that as long as I am not the Person that attacked I can be hit by the sword but if I am the person that attacked then uh yeah I’m not able to be hurt by this sort on that specific game tick of course and then at the end we just have to make sure that we remove The tag once we’re done clean up everything otherwise uh we could have a potential issue of uh the tag that’s being left there you’ve got to make sure to clean up after yourself so in the same way uh we cleaned up after ourselves with the advancement And so now technically we have a custom sword like I was saying we got rid of that bug so it should be pretty pretty solid we could make multiple if we wanted to by just creating more predicate sword two sword three sword four and as long as in our data pack File so then if I create sort two hit enter uh then I probably want to call this custom item two right well now maybe custom item two it does smoke instead of flames and then in my give command instead of being called custom sword name we’ll call you custom sort 2 And we will give you a different texture and custom item two so now in Minecraft switching my monitors we can run the function where was it give items so now we have custom sword and custom sort 2 you’ll see custom sword one still does the Flames custom storage two now does smoke So cool now we can make as many custom storage as we want using this method it’s really easy to just copy paste and uh yeah let’s dive in a little bit into some of the cool stuff you could do with the custom sort so for starters don’t run a Particle command or whatever here that makes no sense instead run a function so we’re going to call you what if I could spell right you’ll be uh storage tutorial and then we’re going to call you what sword one and uh yeah we’ll do sword two as well why not And uh yeah we’ll need to get rid of the stuff after these functions and uh yeah then we can actually create the function so down here we’ll want to create function sword one and uh function sword two and it might actually be smarter if we put these in a folder so I’m going to create one of these this is how you do it in MCB of course but if you are doing it in your own data pack you would do it in the folder file structure so we could save this and I might as well add a Our smoke and Flames back because why not you’ll see on our file structure now we have a search folder and then we have our different functions here this is how you would want to set it up if you are not using MCB so what are some cool Stuff we could do in this actual functions well we could run literally whatever command we want so we could do whatever your imagination and skills allow you to of course but here’s some simple things to get started we could obviously run particles we could play a sound play sound event Is quite powerful maybe we go with firework rocket blast far we’re gonna just put that in the master Channel why not play it for all players at the location of the mob with uh volume one why not cool well we can try that in game and now When we hit a mob there’s a popping sound and the flames cool we can run multiple things at the mobs location but that’s a bit boring so what if we were to also uh I don’t know give it an effect of uh levitation for I don’t know 10 seconds with Low amplifier and then we can hide the particles cool so now if we reload and hit a cow it’s going to just slowly float into the air well that’s pretty cool very simple and uh yeah now we have a custom levitating sword cow you will be missed but what if we Want to do something a bit more complex than that well because this only runs the function a single time at the Cow sometimes it can be a little tricky to actually you know run a complex thing at the entity because I mean we can’t just like set the mob on on Fire or whatever with particles going everywhere the whole time but that’s because uh we’re just not ticking at the at the mob so why don’t we set up a tag and give this I don’t know we’re going to call it um hit by sword one Target I don’t know the names don’t Really matter too much I just like to make them pretty long so that you don’t have multiple with the same name might as well make them as descriptive as possible then on our tick function we could and by the way this is not optimal you could optimize this better but we could just Execute as the entity we know it should be the type of uh sword tutorial right sword tutorial mobs and then we also want to do tag is hit by sword one target and uh yeah we can run this at them to then run a function or in this case in MCB a block basically lets you create a function on the Fly uh this is just a automatically generated function so I could have this tick to say whatever I want so in this case now the cow when I hit it is going to just continuously spam the chat with high which means that We’re making progress now we’re ticking at an edge stick out so let’s do something a little bit more interesting cool so I think I’m going to uh set the levitation to be a little bit faster and then in my load function I’m going to add a scoreboard uh this is going to be Scoreboard objectives pad I’m just going to call this was timer and then it’s going to be a dummy objective uh you can name your timers and scoreboards whatever you want and it’s generally smart to have some sort of key term that relates to you so that other people Don’t have the same name as you because if you just went with timer there’s probably like a thousand other people that use timers one of their scoreboard names there aren’t very many people that you that use watch timer except for me please don’t use it because Obviously I use it but uh you can use something with you with your own name so in this case we have this timer going and that’s actually going to be pretty helpful because I’m going to uh scoreboard Players had to the timer so now we have a cow that’s Levitating into the air with a timer counting up we know that it’s going to levitate for uh we defined it as 10 seconds right we’re giving levitation for 10 seconds so we could have this timer count to 10 which is equal to 200. so we could say execute s scores Uh was timer if it’s 200 or greater let’s do something in this case we’re going to say uh we’ll just say explode why not uh you know what why say explode if I can just explode um summon TNT her let’s summon a fire now that’s something a TNT that’ll be more fun I’m summoning a TNT like this would just instantly explode so should be good uh we should probably create this as a separate function so that we can also kill ourself just in case the exploration for some reason doesn’t kill the cow then it’s not going to explode forever Um and this will probably look a bit better if we add a particle just always happening of particle firework at our current location in fact I think we could probably just literally leave it as particle firework and uh yeah let’s let’s see how this looks so back in Minecraft we now have custom Sword name and if we hit a mob with it it will slowly go up into the air and then explode perfect so yeah that’s how you can create custom swords in Minecraft the sky is pretty much the limit once you know how to detect the actual holding of a custom Sword the hitting with the custom sword and how to detect what mob was hit and so uh yeah I’m not gonna go too much further with the actual tutorial itself because at that point we’d just be going into General data pack creation stuff so if you did like the tutorial however make Sure to leave a like on it and I’m going to be making lots more of these tutorials in the future so leave a suggestion for what I should make a tutorial on next I’m thinking either Bose or pickaxes probably but I’ll let you guys decide so thanks so much for Watching and I will see you guys all in the very next video Video Information
This video, titled ‘Adding Custom Swords to Minecraft. Datapack Tutorial 4’, was uploaded by WASD Build Team on 2022-09-30 00:05:19. It has garnered 10684 views and 237 likes. The duration of the video is 00:31:31 or 1891 seconds.
Download the template datapack: https://www.dropbox.com/s/l2m5nqoo0s7vql7/WASD%20Custom%20Sword%20Tutorial.zip?dl=1
For direct help learning how to make datapacks, become a Patron: https://www.patreon.com/WASD_Build_Team
Download my datapacks: https://wasdbuildteam.website/data-packs/
Discord Link: https://discord.gg/yqk4VfA
Join our Patron server by supporting us on Patreon: Get exclusive datapack updates and entire packs. https://www.patreon.com/WASD_Build_Team
Learn about all the donation perks: https://wasdbuildteam.website/donate/
**My Favorite Minecraft Server Host** https://bisecthosting.com/WASD Use Code “WASD” for 25% off your first month!
Useful Website:
MCStacker: https://mcstacker.net/
Useful Minecraft Wiki Pages: https://minecraft.gamepedia.com/Commands https://minecraft.gamepedia.com/Data_Pack https://minecraft.gamepedia.com/Resource_Pack
Other Helpful Generators https://misode.github.io/loot-table/ https://misode.github.io/predicate/ https://misode.github.io/advancement/ https://misode.github.io/worldgen/