Hello guys and welcome back to the man c’mon tutorial into his episode we’re going to doing custom commands as well as creating the teleporter block for our dimension so let’s get started so the first thing we want to do is create a new package inside of Hareide a mod Called a doc commands and create a new class called command dimension teleport this class is going to extend command base control shift over to import and then hover over and add a little unemployed methods at the top here we’re going to have something called aliases it’s a private final list of strengths Called aliases and these are things that can be used in place of the of the actual full command name so you’ll see in a minute equals lists dot some new ArrayList reference tomorrow d then after that there’s lots of different strings so we can use TP tp’ed in teepee dimension teleport Dimension and it’s teleport make sure to import Java dot util dot list into any of the lists so these are all the different things you can type so you can type TP type of TP dim TP dimension teleport mention and teleport and what your likes cute the same command we want To do the execute one for next so if arcs dot length is less than one so if there aren’t any arguments then return as you can’t run a command without arguments arguments are like things that such as the dimension ID to teleport to or the players teleport to In the normal dimension in the normal teleport command we’re going to need a couple variables string s equals args 0 this is the first argument there’s only one argument for this and then int dimension ID so this is the ID of the dimension your teleport to open up a Try-catch you have users for but basically it tries something and if that thing fails then it will send a message so try and then catch open brackets number format exception e sender dot send message a new text component string text formatting dots red plus dimension ID invalid so if the Try fails which will post some code name it then we will say that the dimension ID is invalid in the red to color and inside the try dimension equals integer dot sparse in s so in handy sorry so it looks for other minion ID instead of all The dimensions and see if they can find it if sender is an instance of entity player they will possible code in there in a minute for they get name function return and this will be the full name of the command mine is TP dimension get usage this will be returned and then This is how it’s supposed to work TP dimension then in triangles ID so this is the correct formatting so you TP dimension followed by the dimension how do you want to teleport to get aliases returned aliases check permission so this is like who can run this command anyone Cummins command So it’s returned true so now what goes inside of here well this is going to be the code for teleporting which runs but in different class I’m gonna put a package clock manage that util and it’s out of here I’m gonna put teleport this extends teleporter so we need a couple Of things private final world server world control shift alt import so the world server is just the world but you can also access things on the server side such as dimension handling and then private double X comma Y comma Z then we need the actual constructor which has World server world double X double y double Z is going to super off of the world this stop world equals world Vista x equals x this to y equals y and this does edge equals Z then it’s going to be two functions in here place in parcel this dot world dot Get blocked state new block cause integer this dot y and integer this das head entity got a stair position to X Y Zed entity dot motion x equals 0 f m2 c dot motion y equals 0 f and entity dot motion said equals 0 f so what this does Is when you click on the portal block or you execute the command it will place you into the actual portal block and make sure you’re not moving so it can teleport you that’s how it works and then we’re gonna have one of our own functions public static void teleport to dimension In here the parameters we’re going to have the player NC player player the dimension in two dimension and double-a test of all idols out controller so to import entity player then int old dimension equals player dots get NC world dot provider doctor get dimension entity player MP and supplier NP equals Racket entity player MP player and this NC player MP is just an entity player that can store lots of different values based around the player so if you look in here it stores the player’s health experience armor at all the information that the player has around them when they’re entering into a different Dimension and when you have transfer transforming between the client and the server then minecraft server server equals player dot get entity world doctor gets minecraft server you may remember a few of these values from when we create your structures and world server server or world server equals Server dot get world dimension then if world server is null or server is null throw new illegal argument exception dimension colon space plus dimension which is the mid dimension ID gloss space doesn’t exist so if it can’t find the world serve for the server then throw an Exception but if it can world server doctor gets minecraft server dot get to play a list dots transfer player to dimension and supply your MP dimension new teleport will server X why is that and player dot sets position and update X Y Zed so this is just guessing by the player Is in the world and then teleporting him to the new dimension and that is that utility commands are done and then in the if sender is instance of NC player do teleport dot teleport to dimension sender dimension ID sender dots get pause dot get X and copy this twice Before get Y and get it said I’m just a false sender open some brackets and put entity player and it’s important that you put return after the catch to make sure that this dimension ID is initialized if you don’t what return they won’t go through the try again Until it finds a correct dimension it will only go through it once meaning the dimension ID hasn’t actually been found and you’ll never actually teleport so once you’ve done that and give it a save and inside of the main there is going to be a new event handler called Server in it which is an FML server starting event and registry handler we are going to create a new public static void called server registries and in there we are going to put inside of that we have FML server starting event event and put a vent dot for Register server command new TP dimension command new command dimension teleport then back in main put registry handler dots server registries event now to create the block for teleporting if you want your teleporter block go into objects blocks and create a new class called block teleporter extend block base add the constructor set the Material the only thing that’ll be different is on block activated this is called when the block is right clicks if FMH mark world in dot is remotes so if the world is not remote teleport dots teleport to dimension player in use one of two ways actually the way I’m gonna Do it is very simple but we’re using your knowledge of G you eyes and containers you could create it so when you right-click it you open the GUI and a container where you can input the dimensions you want to teleport to and then you can teleport to that I’m gonna Do a lot more simple ways when I click on it it’ll tell pot to dimension to which is going to get the ID of my dimension which to do in the next episode come some of your player in dot you get its position dot get X copy it Three times change it to get Y and get his edge put get y plus five to make sure you not in the ground and return true else return false obviously to register that and blocking it and so on and so forth you can go and do that use Health but I’m going to demonstrate now how this works so now if you type it in /t p you can in click tab you can see there’s TP there’s tp’ed in this TV dimension I will just attach /tp dim and then you input a dimension ID negative One for the other zero for overworld and want the end so TP do dim one enter and it’ll load you into the end so just make a quick modification and inside of here you need to put if dimension ID equals one then teleport or teleport dimension When you’re in the end you have to tell teleport to a certain place I will just fall out and die so 0 55 0 else teleport is how Bob’s dimension and the code I had before as you can see we have to lead teleported to the correct location this Time except I was a bit too low so I’ll just that village I’ll just hop out 65 as we can clearly see it’s worked so if I do /t p DM minus 1 I’ll teleport to the nether and I’ll land in the nether right here with all the Pig Zombies and TPD m 0 I’ll spawn back in the overworld as you can see the command is clearly working if you create a block when you right-click it it won’t do anything as I don’t have dimension to yet so stay tuned for that on my channel They’ll be coming in the next week or so so thanks for watching mine has been hairy and good bye Video Information
This video, titled ‘Commands – Minecraft Modding Tutorial 1.12.2 – Episode 23’, was uploaded by Harry Talks on 2018-03-24 20:50:26. It has garnered 8104 views and 114 likes. The duration of the video is 00:19:32 or 1172 seconds.
Welcome to the commands tutorial and also the 1st part of the dimensions tutorial. Hope you enjoy!
Links GitHub: https://github.com/HarryTechRevs/MinecraftModding/tree/HarryTechRevs-1.12.2-Tutorials Discord: https://discordapp.com/invite/xwg8zQJ Playlist: https://www.youtube.com/playlist?list=PLiDUvCGH5WEUEV9nc0Ll2pzUFmSFc21uR Subscribe: http://tiny.cc/sub2harrytech Twitter: https://twitter.com/harrystechrevs