Hey everyone if you’re new to the channel I’m machine Builder and I’m all about creating amazing addons for Minecraft Bedrock Edition and inspiring and helping other people to do the same in this video you’ll learn how to make a basic script in your add-ons but before We get into this I’d like to mention I have a Discord server with a wonderful active community so feel free to join in the discussions and request video ideas you’d like to see in the future there should be a link somewhere down in the description below but with no further Ado let’s get right into this so in this tutorial will’ll cover how to set up a basic Behavior pack with support for scripts we’ll also cover how to write a script that listens to different events in the world and responds to them in certain ways this is intended to get you Familiarized with how the scripting system in Minecraft Bedrock Edition actually works so that you can see the potential capabilities and then create your own fun and interactive systems so before we properly start there are a couple things to consider and get to know throughout this video we’ll be Making use of JavaScript JavaScript is often called JS so if I call it JS during the video just know that I’m referring to this the same thing if you don’t know what JavaScript is Javascript is a programming language mostly used for web development to make websites more interactive for users we however Won’t be using JavaScript for web development in this tutorial but instead to create Minecraft add-ons now if you don’t know JavaScript and want to learn which I’d highly recommend there are plenty of resources available online a great one I’d personally recommend as I’ve used it before is W3 schools there Will be a link to that in the description below titled W3 schools JavaScript tutorial if you’d like to check out again I cannot stress this enough learning JavaScript will help you immensely if you want to use it in your add-ons now some notes about the API as I mentioned earlier we’ll be using JavaScript to create Minecraft add-ons this is a relatively new system so there are many things that may be missing from the API provided to us and as an important clarification an API is how we interact with the Minecraft world the developers of Minecraft have provided us with a collection of functions we can Use to do specific things in the world or listen to specific events without this we wouldn’t be able to do anything really so new features are constantly being added to the API so if something’s missing at the moment there’s a good chance it will be added in Future so I’m interrupt in the middle of this video to give you a very important reminder um 94.4% of you guys are boring people apparently I didn’t make the rules but according to this you are and then only 5.6% of you are cool people so I think you know what to do there make sure you smash that subscribe button and lightly tap the like button and also leave a comment to let me know what you thought of this video anyway let’s get right back to the video so this is how we create a Behavior pack if you don’t already have a pack and don’t know how to this is a quick guide on the Bedrock Wiki there will be a link to this in the description titled Bedrock wiki-pr setup so read through the intro section here and then down to the BP manifest over Here so I’ll just quickly follow this guide and set up a pack so here we now have an example pack copied from the wiki and all we have in here is a manifest so if we go ahead and open this manifest up any text editor I’ll be going through different editor types Later but for now we’ll just double click it to open it in default so this might be notepad this might be Visual Studio code this could be whatever you’ve said before now you’ll notice we’re missing uu IDs here these are just three dots and we need a uu ID So Reading a little bit further down the Bedrock Wiki article we can see what a u ID is a uu ID is a universally unique identifier this identifies your pack for other programs so Minecraft and it looks something like this so it’s a bunch of random letters and numbers in a format So if you go over here and click this link it will take you to this website called online uuid generator if we click refresh we’ll get a new uuid each time so we can just click copy here then open up our code editor again or whatever file we’re editing and paste that in Instead of the three dots make sure you leave these quotes here because they are essential for the format I’ll just zoom in so you guys can see this better so we have our uuid and the quotes around it if you have syntax highlighting it’ll be very obvious if it’s correct because if it Isn’t it’ll show you that there are errors so now if we refresh this again to get another uid and now we copy this again head back over here paste that into the second new uid again make sure you have these quotes they’re very important so now that we have a behavior Pack with our manifest we can go ahead and add a module to the Manifest a module here tells the game what functionality our pack should have so creating a script in our add-on will need to let the game know that we want to use scrip in in this module you can Tell the game where our script file is located typically this is called main.js so we’ll stick with that convention for clarity you’ll notice we already have an entry in the module section this module tells the game that our pack is a behavior pack so let’s go ahead and add Our scripting module for that you can copy all of this area copy that paste it make sure you add a comma after the first one so that the formatting is correct and now in here we want to change type to script like that we’ll need a new uu ID So we’ll go ahead and grab one from the generator our version can remain the same and then we need a new attribute called entry and make sure you add a comma after this version list and use quotes to name your attributes so you want colum and then more quotes here and You can type scripts main.js so this is our entry point that Minecraft will identify and run now there’s one last thing we need to do with our manifest which is add a dependency the dependency section in a manifest tells the game which other packs or content is required when this Pack is applied to a world or used in any way the dependency we need to add here is the scripting module and the version that we’d like to use I know it seems a little odd since I just said that we told the game we wanted to use Scripting in the module section over here but here in the dependencies is where we’ll tell the game which version of scripts would’ like to use and which specific pieces of the script API we’d like the only one we’ll use in this tutorial is at Minecraft SL server but There are other modules of the API which provide different functionality which we’ll cover in later videos so to add this section we’re going to add a comma after this main list here for modules and then again add a new attribute it’s called dependencies like That and then in here we have a list so that is these square brackets and then we need the curly brackets and here we need an attribute called module name so if we type that in add colums and then more quotes type at Minecraft SLS server So now this tells the game we want the Minecraft SL server module and if we add a comma so we want another attribute called version and in this we need to find the stable version for Minecraft server scripts so this is wave plays script API mpm detector and there’ll be a link for This in the description um titled script API mpms from wave plays so if we go ahead and click server cuz that’s the one we’re using you can then see this version here is 1.7.0 so after the last at that’s the version we want so we can copy that and Paste it directly into here so now we have this here as of this video this is the latest version so if you’re copying this video very close in the future you can just go ahead and use this version so now our manifest is all set up Properly and we can finally get onto the more exciting content of this tutorial which is actually creating our script so in our Behavior pack we want to right click and create a new folder we call this one scripts because this is where our scripts will be housed just for Clarity and keeping the code neat so if we go into here we can then create a new file we can just make a text document and change the file extension to main.js Windows will prompt you to make sure you want to change it so just click yes if you don’t have file extensions You can go up here click View and then file name extensions so without that you won’t be able to change the name extension but with it you can so now that we have our main.js file there’s one thing we have to do before we can start editing it and that is choosing an Editor so if you head over to the description there should be a link titled software and preparation and we need to choose an Editor to use so if you’re on a Windows PC I’d recommend vs code or Bridge however if you’re on a mobile device I’d recommend this page Checking it out and going through the list of different editors that you can use on those devices so for configuring Visual Studio code as well there is a big list of things you can do here that all add in that typing hinting that I was using earlier when making the Manifest so if you’re not using vs code you can skip to the timestamp on screen now but if you are I’ll quickly walk you through how to get Auto completions in your editor so for this we’ll need to install the mpm package for types for the minecr script API npm stands for Node package manager but I won’t go into detail about that in this tutorial as the video will be far too long and boring so in short npm allows you to install packages for JavaScript and we’ll be installing the Minecraft script API package so that Visual Studio code Can give us hints as we type so if you don’t already have npm you can download it using the link in the description titled downloading and installing nodejs and npm so on this website you can see some basic information of how to install this but this is currently using npm Which you obviously don’t have so you can’t download the latest version so scroll down here to OSX or Windows node installers and here we have the nodejs download page so heading over here we can see we have the windows installer Mac OS installer and source code all you Need to worry about is the windows installer so just download the version you like best which is MSI usually and then just download the version which corresponds to your system architecture so typically that would be 64-bit but it might be 32bit so just make sure you know that One so now that we’ve got mpm set up and installed we can use the npm install command or shorthand npmi command in a terminal window to open a terminal window in the Windows operating system head over to the windows icon or click the windows logo key on your keyboard and type in CMD so here we have our Command Prompt if we open that up we’ll get this new window which is the command prompt home so keep this window open for now as we’ll come back to it shortly so now we need to figure out what the current Latest version of the npm package is so we can head over to the page for this package by simply searching on Google for mpm npm Minecraft server so if we enter this it should come up as the first version Minecraft for/ server so clicking on this link the page should look something Like this Minecraft SLS server because that is the module version we’re using and this contains the types related to manipulating Minecraft world including entities blocks dimensions and more so this is exactly what we need there is also some documentation for this over here by just clicking on this link you Can get taken to the official learn microsoft.com website eventually it will load there we go so you can see there are a bunch of different things you can use but we won’t go into detail about this documentation site in this video so if we goe back over to this site and we Take a look on the right side of the screen you can see what version is currently the latest this is the version we want to install because it is currently the most recently updated stable version so we’ve already found this before by using the wave plays mpm Types get up and we’ve already said that in our manifest but at least we know we can find it here as well so also if you’d like to see other versions of the package you can head over to the versions tab on the mpm site Or you can go back to this W of plays website and click on this one server again so here we have stable which is the current stable version of script in a stable version of the game and then we have stable beta so this is for the Stable version of the game but beta scripts and then we have preview so these are stable scripts in preview and then these are beta scripts in preview so really don’t worry about these because these can all change and break your code so really all I like to use Here is stable so if we go ahead and just click this you can see copied the command and this is the install command that we’ll be using so back in our terminal now we can paste the command in press enter and you’ll see we are installing the types so you’ll see our Result is removed one package change one package and audited blah blah blah as long as there’s no error that’s all right this is my result because I already had the pack installed but now I’ve just update it again so if this didn’t work for you and you get some Errors please recheck the steps for installing npm and if that doesn’t work again try restarting your PC but if nothing’s working don’t worry this isn’t a required step it’s just something optional to help you work workflow so you don’t have to feel worried about not Having it so now we go into the code editing just open this up in whatever code editor you’re using I’m using visual studio code insiders that doesn’t really matter though we’ve already discussed that so now we have to write our script so here we’re going to import World from @ Minecraft SL server so what this here does this is our module name that we’ve set a dependency for in our pack so this will be valid and then here we have world so world is how we access events and do things to the Minecraft World I will go over this later when we look at the documentation but for now just know that’s what we need so now let’s quickly create a hello world setup so that we can validate that our code does work so for that we want world do send message send message should have a Capital m and no spaces but a lowercase S at the start so here we can put a string in which is two double quotes or two single quotes or also two of these funky keys so we’re going to use double quotes for now just to not confuse anything and let’s type in hello World and we need to end our line with semicolons we don’t really need to but it’s good practice to so in our world editing Behavior pack section we have pack. name pack. description it’s called this because we didn’t actually set a name or description in the Manifest but We can go ahead and just activate this and now we have it in our world just as a quick side note this is where we can set our name so if we wanted this to be like scripting tutorial we can do that and then pack. description we can Set this to whatever we want so this is the pack description like that and now if we go back out of the world editing and back in we’ll see these updated so just to check that we now have scripting tutorial this is the pack description so this ensures that you’re using the right Pack if you set a name so now if we go ahead and play This World open it up let the game load you’ll see check out chat there’s nothing but if we type SL reload you can then see Hello World we don’t have anything in the chat initially because The world technically loaded before we spawned in but by using the SL reload command it reloads all function and script files from all Behavior packs so this basically tells the game to rerun our main.js code it’s very useful for development because we can constantly update without having to leave the world So now let’s take a look at how Scripts an add functionality that add-ons couldn’t do without them one example of this is listening for Block breaking events however there are plenty of other events that you can listen for and respond to accordingly to give your add-on that extra level of interaction With the world so here we have Jay’s docs which are linked in the description below titled as Jay’s script API docs so if we head over here to the game version we’re using which is 1.2.5 you can see that on the main menu of Minecraft down here in the bottom right corner 1.20.1 So the latest version will always have three numbers here like 1 20 50 and then the latest preview version will have four numbers like this so we always want the stable version so if we go ahead and click this and now we have all the modules listed that we have access to With the script API but what we want here is at Minecraft for/ server and then the version we’re using which is 1.7.0 so clicking this we can then see a list of everything we get access to with the script API now there are plenty of classes listed here but we’ll focus on One for this video and that is world so if we scroll down to world you can see we have World open this up it’s capitalized here so this one here with lowercase is just a variable which is simply an instance of this class so the real class we’re using Is capital World here and then we have properties and then in here the important thing is after events so if we open up after events you can see we get the access to the property so where this is in the world that’s just scrolling down and then you can see this this is An instance of the class world after events so if we click this you can now see everything we get access to in the after events of the world so there’s also world before events but that won’t be covered in this video now in here we See a list of every event we can listen for note that because these are after events we technically get to listen for the event being completed rather than when the event starts but again I won’t go into more depth than that with the difference between before and after Events so the event here we’ll focus on is player break block so you see here player break block if we go ahead and click this you can see this is just like scrolling down again and we can see what class it actually is so usually a class Is capital to start with so if we go ahead and click this we can see where the actual event signal is and an event signal is just how we listen to an event so it has a subscribe method and an unsubscribe method but if we go down Here to the Subscribe method we can see the argument and if we click on this link here that will take us to where we actually see the data for our event so these are different attributes and we can see that the event gives us things like the block that was impacted by the Event the data of the block that was broken the dimension where this happened the item that the player was using both before and after the break you can see that before and after and then also the player who broke the block so now let’s go ahead and make use of what we’ve just Found we will just extend our code slightly to listen for this event so we know it’s in world do after events like that and then we know it’s called player break block because that is the signal and now if we run the Subscribe function which I Just showed you and then in here we need a function which takes one argument called Data so data in here is actually an instance of this class which shows us all these properties that we just talked about earlier so now copying this hello world example I can just take that paste That here change this text and say a player broke a block with an exclamation point so now if we head back into the world with some random cave sounds it seems and then we break a block we can see the chat message says a player broke a block that’s exactly what we Want so now let’s go ahead and use some of those attributes that we just saw so say for example we want to say the player name who broke the block we can add a space here and then add data player. name so data. player here is This variable here so player if we click this and then click this again to get the class you can see this is a class player and a player has the properties name which is the actual name of the player which is exactly what we want here so now we should see the player Name in the chat and if we just check that that works by running SL reload again the reload command is great and now we can fill that back in break some more blocks you can see it’s my name it’s a bit of a weird name because I’m not Signed in but that is my name so now we’ve validated that our pack actually works and that the script all works as expected so really what you’ve learned in this video is you now have a basic understanding of what JavaScript is you know where to go to learn JavaScript and you’ve been familiarized With the layout of scripts how to import modules which modules are available and then how to write some basic JavaScript code to listen to events and do something in response make sure to like the video If you enjoyed it and leave a comment for any future video suggestions Addon Creations or ious Concepts You’ like to see me work on and make sure to smash that subscribe button too so you don’t miss any future videos like these thank you for taking your time and making it this far through the video I cannot express it enough how much your Support means to me and don’t forget I’ve got some great new tutorials coming up soon Video Information
This video, titled ‘Beginner’s Guide to Minecraft Bedrock Scripting’, was uploaded by MACHINE_BUILDER on 2024-02-02 12:00:00. It has garnered views and [vid_likes] likes. The duration of the video is or seconds.
In this video you’ll learn how to add JavaScript code to your addons and packs to create a more fun and exciting experience, …