So you want to learn how to use the scripting API but don’t really know where to get started or you’ve tried to follow other tutorials and they don’t really explain everything that well so that’s where this tutorial is supposed to come into play I’m going to be trying To teach you everything possible as well as teaching you how to learn on your own without relying on tutorials because I’ll be honest tutorials aren’t the best it’s always better to follow a tutorial after you’ve looked at documentation and cannot figure it out you’re not always going to find the actual solution Everything through a tutorial so that is where looking through the official documentation to find out what you want to do or see if it’s even possible is very helpful all right so anyways the first thing you’re going to want to do is download visual studio code with the Download in the description down below you’re also going to want to get Bridge as well as node.js all three of those are very simple to download and install so go ahead and just install them and then once you have them installed go ahead and open Bridge now that bridge is Open we’re going to want to create a new project or if you have an existing project just go ahead and open that if not and you’ve never used Bridge before go ahead and tick whichever one you want for scripting you’re always going to want a behavior pack but you don’t need A resource pack um if you go down to experimental options you need to turn on beta apis that is going to enable the scripts then go down to individual individual options turn off literally everything we don’t need any of this unless doing like custom blocks and custom items then you might need item Texture The Sounds uh flipbook textures terrain texture that’s for blocks but for this example we’re not going to be using any of that we can go ahead and rename this to scripting this is whatever you want it to be called I’m going to call it scripting API tutorial And add a project description if you want you don’t actually have to do this then go to the project prefix you can change this and I highly recommend that you do this is basically when you do SLG give and normally by default you would be doing like SLG give Minecraft stick Well this would be SLG ja stick or whatever your custom prefix is and then you’re adding your block or item name after that go ahead and add your project author I recommend to leave the target version to whatever it is and you can tick this then click create now you have A basic pack there is going to be a couple issues if you were to try to add this to a world already it’s going to throw errors basically because things are out of date if you go down to your manifest you can actually go down here and under Minecraft server as of the Most recent version it is 1.8.0 and then in the UI it is 1.2.0 I don’t believe they ever updated game test and I believe it’s actually deprecated so I I think you should be able to remove this but I’m not really sure so I’m just going to leave it there For now that’s basically it now if you press contrl s after changing that and then add it to a world so go ahead and load up Minecraft all right so go ahead and load up Minecraft create a new world or load up an existing world and just Make sure to add your behavior pack for this it is the scripting API tutorial go down to examples and make sure to turn on beta apis this is going to enable scripting then do whatever you want to your world click create and now you should have scripting enabled um one way To check is going to to here and click on Creator content log history and this should show you any errors that happen inside your script so right now it says does not contain main file main.js the reason it’s saying that is because my main.js is actually empty if I were to Add some code to it it would fix that issue um for now I’m going to go ahead and clear that go back to Bridge and what we’re going to want to do is go into here the first thing you’re going to want is to import your world from Your server so import world and this is going to be from Minecraft you’re going to want to do an at symbol Minecraft SLS server now we have imported our world if we go back to Minecraft without closing the world it doesn’t matter if you you could close it and reopen it it’ll do The same thing and type SL reload and then we go back to our settings you can see it didn’t actually show the error this time the reason is because we added that that one line a code it was basically just saying that your main.js is empty from here we’re actually going To switch out of bridge go ahead and keep it open because you are going to have to click this refresh project button every time you want the script files to register back to Minecraft and once you change them in Visual Studio but now go ahead and open Visual Studio Code all right inside of Visual Studio code you’re going to see this blank project thing go ahead and click Explorer and open folder this is where you’re going to find your project folder and go ahead and click on it if you don’t know where your project actually Is go over back into Bridge click this three dots and click open project folder Now find this this is the project that I want to be using copy that path go back to visual studio code and paste that into here now you’re going to want to go Ahead and click on Behavior pack and select folder and now you could see your behavior pack in your script file starting off you’re not actually going to be able to see much like if I type in World dot it it’s not going to show any examples of anything so what you’re Going to want to do is click up here where it says terminal new terminal and make sure that you already have node.js installed using the download link in the description once that’s installed you’re going to want to go over to the official documentation of Minecraft and this is What it’s going to take you to and then click on scripting go to use Visual Studio code and copy this right here now go back and go into your terminal paste that in and click enter what that did is it added these node modules for the Minecraft common And Minecraft server if you go back to the documentation you can actually see if I go down to reference documentation scripting apis you can actually see common is right here and server is right here and everything inside a server is right here so you can get like the Entity you get item Stacks which basically has the amount of the items and the item type and stuff uh you can get world and this is what we’re going to be using to register functions and stuff so go back to visual studio code and now if we type in World dot you can Actually see world. before events and world. after events as well as all of these other things you can call so like I could call world. getall players and that will basically return a list of all the players in the game but what we’re going to be doing is world. after events And then item use you’re also going going to want to do do subscribe you’re going to do that on any function using after events or before events and then inside of here let’s do event this is just the event name it’s going to be returning a item use after event so if We go back to the documentation we can click on after events and these are all the after events we can use so let’s find item use and you can see right here it is a item use after event signal if we click on that it returns an item use After event so that’s basically what we’re naming this event and inside of this event it’s going to house a source and a item stack so what that means is now that we have have this named event we can go ahead and do this equal sign and the little carrot thing or whatever They’re called and now inside of here we can actually check if event. item stack now that pops up and you can see that’s because of in here we have the item stack we can actually click on item stack here and see everything that the item stack has so we have the amount is Stackable keep on death lock mode max amount name tag type type ID and this is actually we’re going to what we’re going to be using to check what kind of item it is so go back into Visual Studio item stack. type ID is equal and when you’re Inside of an if statement and you’re checking if something is equal to something you’re not going to use one equal sign because that’s setting that’s basically trying to set type ID equal to this you’re going to be using two um I believe in JavaScript it’s a little different and sometimes people use three Equal signs I don’t exactly know the reasoning for that I use two and it seems to work every time so you can go ahead and stick with two it’s fine and then you’re going to type your item that you’re going to want to check for let’s Go ahead and type in Minecraft p in Stick just for an example and then we’re going to use these little squiggly brackets and inside of here now we can run everything that’s going to happen when the player uses an item that’s basically the same as right clicking With the stick for this example we can go ahead and just apply maybe some knock back to the player so so if we go back to the documentation go back a couple things actually right here we can look at event. source would get us the player Cuz it’s going to return a player and inside a player we can actually see everything that we can call on the player so not only can we see everything that’s inside of the player but it also extends The Entity class which means if we click on this we can also get Everything from the entity inside of the player so we can get the location is swimming it’s sprinting is in water basically everything like the ID what dimension it’s in and this is all very very useful stuff as well as we can do add tag at apply damage apply impulse apply knockback and that’s Actually the one that we’re going to be using right now so we can do apply knockback we could read down here and right here it looks like it takes a direction for the X and the Z and then the horizontal strength and the vertical strength so it’s going to take in four Things so we can do event. source cuz it’s going to return the player dot apply knockback and then you can see right here because we imported the Minecraft server we can actually see the direction Z Direction X and this is basically everything it’s going to pass in so we could do one One and then for the strength let’s do like two and two now we can end that with a semicolon and if we head back into Minecraft we can type in slash reload and if I go ahead and give myself a stick right now and right click it does Nothing the reason it’s doing nothing right now is because you actually have to go to Bridge and click refresh project that’s going to apply the changes to the pack based on anything that’s actually changed so if I close this and now reopen it you can actually See everything to change so go back to Minecraft do SL reload and right click see I just applied knockback every time I click the stick but there’s one issue with this you see I’m always getting launched in this same direction if I I turn around I’m always getting launched This way let’s turn this to noon and we can see that better if I go way over here stand right here right click I’m going that direction if I turn this way I’m going that direction no matter what way I’m facing I’m going to be going That way the reason is because if we go back to the code we are applying it one on the X and one on the Z so go back to Minecraft SL game ru uh show coordinates true so one on the Z is this direction and one on the x is This direction so we’re always applying it this way so how do we get it to apply based on the player’s facing Direction well that’s actually pretty simple if we go back to the code we can actually use event. source. get view Direction and that’s going to return a vector 3 and we Only want the X and the Z so we can do dox paste that over here and then type inz so if we go ahead refresh project go back to Minecraft reload that now we right Click you can now see that we’re actually going forward every time we click it so if I click it this way it also makes me go that way let’s go ahead and turn this down on the y direction to like let’s say 0.1 or 0.2 and then Change this to like four so it’s extreme on the forward Direction refresh go back to the game reload now let’s right click if I right click it you can see I’m actually going flying in a forward Direction it’s very cool instead of applying knockback maybe let’s spawn a animal there’s actually a Few ways to do this one way we’re just going to do the easy way event do Source cuz now we have the player and if we go back to the documentation we can actually see all the way down towards the bottom I believe we should see run command async and Basically we don’t need this to return anything but we can go back we can do run command async and this is going to take in a string a string is basically something with quotes so like uh it’s kind of hard to describe exactly what a String is but think of like a page in a book that would all be a string like or a sentence that is a string an integer or an INT is a whole number so one 2 3 4 1 -23 a float is a decimal number so 1.1 1.01 1.02 uh 3.1 any of those and that is kind of where we are going to be inputting a string into this and this right here is actually a string you can tell because it quotes as well as this right here if you look at the very top It says item stack. type ID is a string same with uh let’s say right here if we hover over that that’s an item used after event so if we go ahead and copy that back into here you can actually see it shows us exactly what that is and That’s very handy when you’re trying to figure out what something is or how to use something but anyways we want to run a command this command if we hover over this it’s going to say runs a particular command synchronously so basically instead of trying to run it like right Away in that specific frame or whatever it’s going to try to run it whenever it can run it so let’s say we were running this when a entity dies but the player’s dead you can’t actually run it on the player so if you’re running asynchronously it’s going to run the Next time it can run there is a maximum Q of 128 so you can only have 120 in a tick and there’s 20 ticks per second so that’s quite a bit of commands you could line up basically it says right here command to run note the command string Should not start with a slash so we’re actually not going to use a slash in this and we’re going to type in summon Pig but we want it to summon on the player right now it would actually default to the player but I think what We should do is maybe let’s spawn it two blocks above the player well how do we do that we could actually type this this and this but instead of this middle one let’s actually do plus and do event. source. location doy and we can do plus Two then plus put quotes again and then for here we’re going to do space and then that basically with this is is adding some data into a string so summon Pig with the current location plus the Y position plus two plus two plus the current Z position so now if we save That go back to bridge refresh project go back to Minecraft now if we reload and right click it’s doing nothing why is it doing nothing oh well I I guess it’s not doing nothing it’s just spawning way too high so if I were to go way over here and right click we should See a pig P fall from the sky yep there we go so I don’t actually know why that pig is falling from such a high height but one way we can actually check right now is Maybe by just using say so let’s go ahead and do say instead of spawning A pig and right here we’re going to add event. Source do location. X Plus and actually let’s go ahead and make a new value for this so let’s do let boords equal event. source. location and now instead of calling all of this we could actually just do chords dox plus let do A space in between cords doy plus space plus chords. Z and let’s go ahead and add a comma here and a comma here and now if we go ahead and save that back to bridge refresh and check now if I right click this we can actually see the exact Coordinates of where the player is standing so if we go back to the code and and to chords y + 2 that was what was giving us that weird error before well not an error but you could see look at that that is why it’s because we’re Adding to the strings so it’s not adding the two numbers together it’s actually doing 68 and then adding that digit onto the end of it so what we could do instead is do let y pause that’s just going to be a y position equal to event. source. location or actually we could do Cord now because we have that new Value Plus two and so now that’s actually because chords is a vector 3 and this is returning a number and it’s not a string it’s actually going to add the two numbers together so yuse we could replace this right here with Y pause now We save it go back refresh reload now we right click and now you can see it’s actually working so now we can actually use that again for our summon command so basically all I did was summon Pig space make sure there’s a space here then add the coordinate X add another Space add the Y pause another space and then the Z so now if I were to go ahead and save that and reload if I right click you can actually see a bunch of pig spawn that’s every time I right click with this thing Well now I kind of want the pig to spawn Maybe 10 blocks in whatever Direction I’m facing so what we can actually do is go back to the code and use a instead of the source. location we can actually use the view direction that we were using From earlier and instead of YP we’re actually going to get rid of that and use plus chords do y go ahead and make sure to save that go back to Minecraft reload and now if I right click click nothing’s happening why is that okay so I just set It to the same say command and now you can actually see the coordinates are something very bizarre the reason for that is because it’s actually using the rotational value in like a normalized thing so it’s like if I were to look at exactly zero right here like basically if I line myself up Directly with this line that should be basically zero on the X and if I were to line myself up like basically right there that should be like 0 0 but anyways instead of get view direction we could actually add another variable because that is giving us the correct Direction but we don’t want to be spawning it in the direction we’d actually want it to be spawning it in coordinate space so we can do let chords equal event. source. location now we are going to be adding that let’s add the direction to the chords so what we could do is Chords. X Plus equal dur dox chords doy plus equal dur doy chords. Z plus equals d. Z what that’s basically going to be doing is adding the direction in a normal value so it’s only going to ever be a slightly larger distance now if we go ahead and save that go back to Minecraft you can actually see that it’s adding to it by a slightly bigger number so instead of just saying let’s actually add a second line so we can get the say command as well as a maybe let’s say particle okay I believe that is how you Use it so I think it’s just particle and then the uh particle that you want to use and then the coordinates so and now if we right click we should be getting some particles oh yeah we are you can see them they’re just inside of the player so if I Like run you’ll see that it is actually spawning them like on the player’s feet well I don’t actually want that so what we can do is we can add one to the Y and then we can times all of these values by two because I kind of want them to be a Little bit further in front and make sure to put these in parentheses the reason you want to put them in parenthesis is because we want to add one to the total we don’t want to be timesing two by one or we don’t want to be adding 2 + 1 then timesing that by This cuz it’s going to be going by the order of exponents so like pemos or whatever and so we don’t want that to happen we want to make sure that this runs first and that’s basically just going to multiply our 0 to one value by Two so so it’s actually going to be like one block forward rather than like 0.5 or whatever and then we can go ahead and save that and this is also going to be putting it at the center of the player’s positioning so instead of actually adding one let’s add 1.5 cuz that’ll put It closer to the player’s head and now if I right click you can see it’s actually spawning it wherever I look pretty cool right now what if we want every entity maybe to teleport there we could do teleport entity type equals not player and then TP them all at those Coordinates and if I press right click spawns everything right there it’s pretty cool isn’t it it’s almost like I’m dragging them around so basically if I turn around it should make them all teleport that way then this way let go and they should all fall awesome now instead of actually Doing just two we could actually times this by like five five to make it quite a bit farther and now if I do it you can see they’re actually quite a bit further away now so that’s actually going to be it for this first tutorial um if you guys want more of These scripting tutorials it be just make sure to let me know and I’ll definitely be willing to make more of these it’s actually pretty cool what you can do with the scripting as well as if you guys just want regular like add-on tutorials like creating custom blocks creating custom texture packs skin packs Anything uh just make sure to let me know and I’ll basically get to whatever I have time to get to so that’s pretty much it hope you guys learned something new and I’ll see you guys next time Video Information
This video, titled ‘Scripting API Tutorial | Minecraft Bedrock Part 1’, was uploaded by Jaden Allen on 2024-02-03 02:00:20. It has garnered 428 views and 37 likes. The duration of the video is 00:23:41 or 1421 seconds.
Downloads Bridge: https://bridge-core.app/guide/download/ Visual Studio Code: https://code.visualstudio.com/download node.js: https://nodejs.org/en/download/current
Official Documentation: https://learn.microsoft.com/en-us/minecraft/creator/?view=minecraft-bedrock-stable
0:00 Intro 1:00 Setting up a blank pack 4:43 Setting up Visual Studio Code 6:42 Scripting
#minecraft #minecraftbedrock #scripting