Hello welcome to tutorial video 11 11 i can’t believe it right first thing we need to do then is let’s save our tutorial 10 code as tutorial 11 and this is all um if you go to the description there’s a link there that’ll take you to all of this code In case you wanted to copy it or paste anything from it et cetera et cetera and it’s also got all the assets that i use like the diamond axe or the the textures um even some models of like the axolotl and things like that they’re all there for you um Okay so i wanted to go to the future let’s go back to the future um mining um it’s been a long time coming sorry that you’ve had to wait until like tutorial 11 um to try this and i say try i think i’ve got i’ve got something working Behind the scenes um in this preparation code let’s see if we can um but it’s not finished so let’s just see if we can do some live coding and get something working ah right let’s just fire up the code and see what’s going on and i remember there was one bug I think was to do with when you build some blocks and then the axe kind of goes behind them or it’s supposed to be in front of everything i’m just gonna press g and do you remember um g in in our old code it stops generating the terrain Um so that we’ve got our i had 65 frames per second just there so that it’s a lot smoother for just um testing things oh right yeah the last thing we did was make these amazing trees okay so what i wanted to test was uh the Axe is appearing as it should it doesn’t matter how close we get to things technically speaking it should be like through that tree um but we want the axe to always appear so we use the always on top um set to true for the For the axe model um however if i go to build mode and then build some like stone bits now yeah the axe model there’s some kind of bug which means the axe is now not on top of of these blocks um i think the problem is because What we’re doing is if you remember from about five or six episodes ago this wireframe cube that we’ve got there is like a um as a a projection of where we’re going to build or indeed um delete things destroy things um it’s just a wireframe texture with some transparency on and What happens when we press the left mouse button um we duplicate the um what do you call it like the um a projected i think we call it what a block build tool entity i think that’s what we call it the bte let’s call it that the Build tool entity it’s just a a ghost cube that’s just floating there the bte we call it bte right and what we do is we duplicate the bte and then just give it the um block type that we want be it grass or ruby or whatever that is that’s ruby sorry Soil or stone there we go um and so by duplicating it we’re copying um the bt’s position and the size and the cube and the collider everything like that so well actually it doesn’t have a collider on the bt so we we have to add a collider to that as well Um and i think the reason why the axe is going behind is because we’re duplicating it so instead of duplicating let’s just create a new entity as we would and all we have to copy really is the bte position right so we’re in our main code a main module and there’s a bt And the building code and it’s just a cube with the white texture on and it’s got build distance yet thanks to ethan rodriguez um oh here are our stone grass soil and ruby so all those are are colors set to these it’s like um an enumerated type um set to these capitalized um Variables so um in the build tool where are we in the function build we’ve just got a temporary variable called e and that’s now going to house an entity that the duplicate function which is in a cena function returns it returns an entity and it copies or duplicates whatever Entity you pass in as an argument so instead of doing that let’s just comment it out and not delete the line yet but let’s just say well e could you just become an entity um the model type wants to be cube um i could just leave the collider as Cube i might just yeah i’ll just leave it as cubed that’s fine um the box collider should just be a cube but okay let’s change it let’s change it to box it shouldn’t make any difference however sometimes it’s good to do that actually it’s good to to try something that shouldn’t be any Different and then if you get a bug you know that it is different and something’s going on and it’s maybe worth trying things like that okay um right oh yes so then we want to say uh position equals spell that correctly uh the bt is position um And yet we’ve got our collider we’ve got the texture so by default it’s going to be stone text color is block type i’m sorry the stone text is monochrome isn’t it so that when we set the entity’s color that color shines through the monochrome and it can become Therefore any color that we want and then we’ve got like a little shake animation on as well which i don’t think happens in minecraft does it but um i think it looks quite quite good okay um right save that i should have added this to our to-do List so i can take it off um what is it the uh the draw order bug that accident being drawn in the order it should do so we’re dropping in from a very high height again i’m going to press g just to turn off the terrain generation while we’re testing And what do i oh yeah first i’ve got to build some things so f for build mode i’ll come down here and let’s build some things oh and the axe oh yeah look it’s hard to notice because now everything’s behaving as it should the axe is now not going behind um our Newly built blocks and we can delete blocks there we go notice as another kind of bug our wireframe when it’s over one of the built blocks because the wireframe block or the bte block existed beforehand the newer blocks are kind of being drawn over the top of them so we’re not seeing them We’re also that’s kind of happening what’s it called um zed fighting i think um so we’ve got this very nasty thing where we’ve got the wireframe the bte cube in exactly the same position as the terrain mesh and so that’s also fighting for position so we need to sort that that out Basically we could just change the size of the the bte very slightly um which is definitely okay now because we’re not going to duplicate it so the um the box uh the blocks that were building wouldn’t inherit uh the the different size and the size only has to be like 0.001 Difference and that will sort out the z fighting um anyway right what we now want to do is some mining so we can kind of do mining we can mine on um blocks that we’ve already built but we want to be able to again press the right mouse button And make that terrain move down or be deleted okay so i’ve got an idea right let’s just we’re up here so near future um what was that um the the axe draw bug bud bug and now i’ve just done that so i can put done Which is the whole point so a little bit of mining let’s let’s not put a question mark exciting let’s be confident let’s go and do that so we want to do that in this is in the wrong place we’ve got a build function but we haven’t got like a mine function Um so in in where are we it should be an input yeah in the input function um we’ve got ethan’s scroll up or scroll down to move uh the distance of where you’re building or mining uh we’ve got queue and escape for a quick we’ve got the g there for turning Off the the generating of the terrain um we’ve got um yeah here we are we’ve got the build function being called we press the left mouse button and when we press the right mouse up um we’re saying destroy whatever um block or entity that the mouse is pointing at And if it’s got a collider it can destroy it um otherwise it won’t be destroyed okay so what we want to do here is um our real real mining of the terrain okay now because we’re going to add some code in here really we want to tidy it Up and go to a function that that contains everything so let’s just uh cut all of that control x if you’re on windows key or a windows machine or like me if you’re on apple that’s command x to to cut and then i want to say uh mine do some mining So we need to go and write that function up here and we’ll do it underneath build up there so define uh mine now what we really should do this should be in its own module like we did in the last couple of videos um we should have a module that we kind of Import we can build a class that does all of this building stuff so it’s not in our main program because like now i’m going to add more lines that means our main program is getting a lot larger and it’s a lot harder to find things I might tidy that up in a future video what we’re going to do now or refactor that in a future video what we’re going to do now is uh just do it in here just to yeah also because it might not work it might not work right so i need to Talk you through what the plan is so let’s go to paint uh what’s it called paint.js oh no i’m too far away from my wifi um let’s just put in paint to come up with anything i paint paint js yes we’re here and we’re in dark mode wonderful okay So the idea is um that i have no idea what going to draw okay let’s try draw some terrain so here’s some terrain there we go um here’s vincent looking at us wow this is really good okay there’s vincent um i’m not going to draw the axle bottle Okay i’ll draw the axle off of right that is the axolotl um don’t act a lot like these like kind of things like that i don’t know right axolotl and um this is us here we are on the terrain now maybe i should use the mouse there we go Okay and what we want to do go to another another color is let’s say we’re going to mine this guy i could just fill it in green what we want to do is get all of the vertices so that means the corners of um wait a minute let’s draw that Over here let’s draw a 3d cube a 3d cube all cubes are 3d or if they’re not tell me in the comments okay so a lot of cubes there and then at the corner of our cube can you tell how many corners or these are called vertices And the lines in between each vertex is an edge okay so we’ve got eight in other words so for a cube we’ve got eight um and a way to kind of like i know we visualize this right here but a way to think about this is we’ve got a square And then a square and a square obviously has four corners of four vertices and so we’ve got two squares like that just all joined up it’s just two times the four corners or four vertices so we’ve got eight vertices eight v um and what we want to do because we’ve already Combined our sub cubes which no longer really exist they’re moving off to some other part of the terrain to generate that so we can’t use those sub cubes they’re they’re not in the place where we where we’re trying to do some mining what we’ve got instead Is a subset and i can’t remember how many um sub cubes that was made up out of but the sub cubes they’re just there for us a short amount of time and what they’re doing is just telling um a cena where the vertices are being placed where we want To place them then they’re moving off but they’re leaving the information there and then what we do is combine all that data into one model so that we can generate as we have been doing an infinite train or a very very large terrain and it still runs fine doing Uh using this kind of method we’re not really doing it well we’re not doing it the most efficient way but this way is fairly easy to code and it and it works fairly well um so what we have to do now is think about the subset and all of its vertices we Can’t there isn’t a cube to move so what we want to do is when we’re mining whoops i can’t get hold of this uh tool what’s going on oh there we go there’s a glitch in the matrix okay um what we want to do is Get hold of that cube and then move it down let’s say to give the illusion that we’ve um dug to a deeper level what we think is happening is that’s being like deleted and so we we and then we’re revealing the next layer but what We can do is to take that cube and move it down but as i’ve been saying we haven’t got a cube there it’s just these vertices that are part of a very large um area a whole subset of of where these sub cubes used to be so if we’re trying to to move A cube down actually we’re just moving everything down like that or we’re deleting the whole thing which isn’t what we want i’ve just beheaded myself and i took vincent’s bottom beak off i’m sorry um vincent so vertices why did i show you about the vertices well what we can do is we could Iterate over all the vertices that are in this position so our bte let’s say we’ve got our our floating hover ghost wireframe bte cube and it’s there what we can say is if you’re one of these vertices and you are within this distance away from the center point Or the position of our bte if you’re one of those vertices so let’s just say we’re in the middle of this cube there so what’s that distance it’s like let’s just use the x-axis um if we’re in the middle of the cube let’s just imagine and that’s one vertex There’s one vertex there that distance there is not going to be one it’s going to be half of a cube isn’t it so it’s going to be within 0.5 um so if the vertex is more than the bte position minus 0.5 and the vertex is less than um The x position plus 0.5 then it must be basically one of the vertices that makes up this single cube then we can ask those vertices that we’ve collected and there are only the eight of them so we only need to collect eight of them and then we can say i don’t know just Go to a completely different place i don’t think destroy i don’t know how to destroy them we could just empty it somehow i’m not sure how to do that but if we just said zero zero zero it would just move them over to zero zero zero and that kind of like change things So what we if we want to make them disappear we could like make them fly really high or really really low somewhere or we could just what’s probably more efficient just move them down one and it looks like we’re digging down okay enough explanation that well that’s the plan i love this diagram It looks amazing okay let’s go and try that so first we need to iterate over all the subsets that we have so we don’t know where we are on the terrain we want to go through all the subsets and check all the vertices um that they have right So we want to say um for i’m going to call it s for subsets in subsets so what that will do it’ll go through all of our subsets which is a list and so let’s say we have 10 subsets that’ll start with subset 0 now go subset 1 subset 2 all the way Up to subset 10 or the 10th subset which will be index 9. and then what we can do now because it’s just this loop is looping over all of the subsets and it will store each subset in this little variable that we’re temporarily making here called s what we Could do is for example say subsets position equals nothing so that’ll do it for all of the subsets that we’ve got um on our uh on our terrain so far actually what we want to do is yeah we want to just go around this loop for how many subsets we’ve got So we want to use range and we want the length of our subsets list and that’s how to do that so now s will not be each subset s is just going to be a number or an index integer from 0 to how many subsets we’ve got and it won’t Include this range function won’t include let’s say the length is 10 subsets it won’t include 10 it will include it right up to 9 so 1 less so that’s exactly what we need for example if we had 10 so now we can say 4 and we call it v in subsets s Dot we want to get hold of each subset model remember that model is going to be made up of loads of um cube positions where the sub cubes used to be and we want to get hold of the vertices there we go or the corners that make up that model Another word for that model is mesh okay so we’re getting hold of all of these guys in the subset now remember our subset isn’t just one cube like this it’s made up of loads of cubes um i can’t remember how many sub cubes we’ve got in each one now we’re using that s Variable there in the index position because that just gives us a number from zero to how many subsets we’ve got and this therefore this is now a nested loop so this inner one is going to go around for all the vertices in this subset and then when that’s finished The outer loop then says we’ll go on to the next subset and then again this line or this inner loop will go around all its vertices of the next subset and so on across all of the subsets that we’ve got so what we want to do in this inner loop And this inner iteration is then to ask the question which i’ve got in my diagram is that vertex close enough to our bt e cube’s position that y frame cube’s position if it is then we’re gonna um do something with that i’ll probably just move it down for now um okay so We want to say if um and i’ll put this in brackets just in case i need to go over another line which i think i will if v dot ah i want to say if the vertex and remember that each vertex is being stored in just a temporary variable here Which i’m calling v so i remember what it that it’s a vertex just like i’m an entity position i might put dot x but that won’t work a vertex is three numbers it’s x position it’s y position at z position in 3d space and that’s stored like a list so i want to Index x and so that’s going to be the first number so that’s the x position 1 is going to be the y position and 2 is going to be the uh z position x y z 0 1 2. easy as that so so if v which means x um is greater than Our vt e what’s going to be greater or equal to i guess our bt e um dot x minus 0.5 and i’ve gone to a new line here and the x position of the vertex is less or equal to our bte’s position x plus 0.5 so it’s x position it’s like within [Laughter] That doesn’t help does it me doing that with my hands i think i’ve explained this well enough on the diagram i’ll just carry on um now we’re going to do the y position so it’s going to be exactly the same except we’re going to v 1 that’s The y position so that’s got to be we’ll start with greater or equal to bt is y minus 0.5 so that’s kind of like under going underneath um and then oh i’m going to go on to z but i haven’t finished why have i and So the vertex has got to be less or equal to kind of the top of our wireframe cube so it’s going to be plus 0.5 and the final two now we’ve got the hang of it let’s just copy and paste that but we need to switch these to The z position which is two um and we need to position oh sorry use these is a z position so i want to go and comment this um is the vertex um close close enough to where we want to mine close enough to where we want to mine i.e our bte position and Yes yes it is so now remember i wanted to move it down so what we’re doing is getting hold of now although we’re doing one of these at a time we’re going to get hold of all of these that are close enough uh fingers crossed um to our bte wi-frame blocks position and So we want to get hold of the y component and then move it down by one block unit so that’s easy we can just get hold of v one which is the y remember x will be zero y is one z is two and we want to say u Minus equal one so that means go down one um okay let’s just leave a little message for ourselves we’ll say print hi mom i’m mining i need an escape character don’t i um there we go is that working um i think this works an escape character is just um because i’ve used a Single quote i could have just used double quotes um when i’m using this apostrophe this contractive apostrophe in the the word i’m in the pronoun i’m um then it think it thinks that that is the end of the string um but if i use this escape character which i think is the Backward slash then it ignores that next character is that correct we’ll see if that works so um what you also want to do no i’ll leave that that should just work or have some effect uh this is definitely not the finished product but let’s uh just have a look our code is Running at least we’re running g to stop uh building the terrain okay turn build mode on um we can build stuff and we can delete stuff and it says hi mom yeah you can see uh down there my console is saying the behind my i’m mining which means there were some vertices Close enough to this cube yeah actually if you think about it because this the the bt cube now is on top of the terrain there are at least four vertices that are within that are close enough i.e the the the um terrain blocks are just underneath it those top vertices are In exactly the same position as the bottom four vertices of our cube of our btq so we are mining but we can’t see the terrain changing that’s to try here so let’s close down there so we’re definitely mining and if i’m i’m scrolling up now you can’t really see That but i’ll try and scroll down we’ve got a lot of messages so we were doing some mining i.e if we’re printing out this debug line oh and by the way the escape character works that’s good um if we’re down here that means we’re going through all of the subsets on our Terrain going through all the vertices that’s eight vertices per q position and we are finding vertices that are contained within that area and then we’re printing that but nothing’s happening but we’re definitely getting hold of those affected vertices and we’re moving it down so the reason why nothing’s happening is because We’re changing the vertex but we’re not actually changing the mesh and therefore the model we’re not saying could you regenerate yourself according to the new position of your vertices because we’re going to we’re kind of going or we are going behind the scenes we’re going in depth into what makes up a model Namely we’re talking about the vertices and vertices by the way um are what make up triangles you get three vert vertices in a row and we know that they’re going to be joined up as a triangle that’s what makes up 3d shapes and things typically in computer graphics so what we want to Do now is say i’ll just do that before the debug line um we want to not do it here actually we should do it after we’ve gone through all the vertices we should then so i’ve just gone back one uh tab and we should then say um where are we subsets s model Uh generate i think that’s what i need model generate i probably got that up on the cena cheat sheet on the asina engine.org website which tells you how to do everything or most things um what am i actually looking for i’m looking for model um is it mesh yeah there we go So yeah we want this function generate call this after setting some of the variables to update it so we’ve changed some of the variables of our mesh of our model i.e the vertices so yeah then we need to generate right let’s now so we just added that one line And that’s just to tell our subsets or the affected subsets could you regenerate um okay so build mode now let’s try that again when we go actually on top of the terrain and it’s now frozen i think i’ve basically placed that um i’ve placed that um generate function in the wrong place so Let’s see if i can force quit out of python i crashed it oh i didn’t um i didn’t manage to crush it when i was uh preparing this but i’ve now crashed it so i’ve placed this in the wrong place let’s see if i can work it out live um Oh so i’m still within this loop aren’t i i need to go back oh i was still within the if um code block i needed to go at least there let’s see if that’s correct and actually we’ll move back our mining console log okay right build mode I try and do one on top of the terrain ah there we go look at that as if by magic we’ve deformed the terrain if i do it again it goes even lower so we are now technically mining um if you like this effect by the way where it kind of like warps The vertices then um build that in as a feature maybe or or at least now you can see what’s happening so we’ve got a problem we don’t leave it like this um what’s basically happening can you see what’s happening maybe pause the video if you want to think about it and guess And then i’ll pretend you’re back now so spoiler what’s happening is um in fact let me come off uh for a moment go back to where’s the amazing diagram here it is what’s happening is uh when we’re testing to see what vertices are within this area it’s not just grabbing this One cube but if you think about it neighboring cubes they’re vertices all the cubes that are kind of joined up there they’re going to share their positions so there’s going to be more than eight vertices and so it’s dragging all the kind of a pair of vertices from neighboring Cubes down so that’s what’s creating this horrible like warped effect so i came up with a solution in my preparation and i think it worked um so what we could do is i thought well what if we made every single cube on the terrain every sub cube which Provides the original positions of for our vertices what if we make them slightly smaller and then um and then we can change this to less than and not equal to and then it should only scoop up the eight vertices that we actually want to move And what we could also do is start the counter and also say we only want eight vertices so we could say v count equals zero so every time we’re checking um vertices if it is in position we’re going to say v count um increment by one plus equal one so v Count equals recount plus one um actually we should do the action first and then we can say if v count um equals eight so if you’ve done eight of them then break and that’ll just break out of these loops it’ll break okay um will it just break out the middle it might just So what we maybe let’s just put this v count here at the very start of looking through all the subsets um and then say break and now that we’re back into make sure i’m in the right position now now we’re in the original loop and we can say If v count because we can now refer to v count because it exists in our in our original loop um equals eight and then we’ll say the same thing break um i may be wrong there it may just break out of all of the loops that’s a good question Maybe help me out in the comments do some research or if you already know if you’re in a nested um loop if you break out the center one does that also break you out of the the large one i don’t think it does so i need to Do this kind of thing so we break out there and then we check again break out there um or actually what i really need to do there is continue no okay so so so what was i doing right so when we build our sub cubes so this is like video one or two Um i think actually the first video part one when we are creating our Subsets oh i’ve gone too far when i was talking i probably went over it there we go so instantiate our ghost subset cubes um yeah we’re like rotating them and disabling them we’re adding them to the sub cubes list we’ve got a texture on them what we also want to do Is say buddy your scale um is going to be scaled down to 0.999 of yourself or actually i’ll just put 0.9 and then you can actually see if there or we can see if they if they’re shrunk yes so now we’ve got smaller um cubes which Looks kind of cool again if you like this look or you think i could develop this to do something else um use it and you’re welcome but now let’s just test out our system well yeah a bonus is that we can see our um bte wireframe cube it now fits over the top Of our cubes which is really cool anyway let’s see if we can do some mining so i’ve selected that guy right click oh that was disappointing it didn’t work i’ve got my high mum hi mom hyman actually there are only four oh that was weird when i was on top of the terrain Hey my terrain’s actually oh no sorry i got distracted i thought my terrain was um in the wrong place for a second so something’s going wrong when i’m on top of them then they or sometimes they shrink they uh not shrink they go down i think i just accidentally killed the trees okay Let’s uh so now that we don’t we don’t see the gaps and i’m a bit confused why it wasn’t working i’ll check with my prepared code which was working um so we’ll go to 999 kind of percent of itself so this should look pretty much identical to What we had originally okay you can see a slight join between our vertices so let’s add another one so a tenth a hundred a thousandth a ten 000 difference which shouldn’t make a difference for our eye compared to the original version that makes all the difference for our Little algorithm there okay so i can see a little bit of tearing so again we might add another one um this looks fine so build mode let’s try selecting something okay it’s only finding three vertices and then it’s stopping so let’s come out of there let’s go back to my code I’ll put another nine on there one on here and let’s take out the second break and just see if that does the trick if it doesn’t what i’ll do is look at the code i might even pause the video so it’s a bit shorter for yourself Um although is it fun sometimes to watch debugging because it kind of i know when i’m watching coding videos it really helps me when i’m watching people debug anyway oh so it’s too tight actually i need to take off that nine and oh something’s happening there some of the vertices are being Removed right let’s i’m going to pause the video and sort this out and then i’ll be right back see you in a moment okay welcome back that was about 30 seconds i just had a look at my my previous code my prepare code i can see one difference let’s just see if that Makes the difference so have i taken off the nine i think i think i’ve taken off enough nines right um just so that our i guess we could make the the bte cube slightly bigger and therefore our terrain nicer let’s try that so 999 and Our bt eq that’s right at the top isn’t it with build stuff or close to the top there is it’s a cube so it’s scale um equals like the moment one i think so i’ll put 1.01 that should make it slightly bigger that doesn’t matter now remember because We’re not duplicating it when we’re building we are actually creating our own cube and we’re just copying the bte position so that should be fine and now here we are um attempting to mine and the only thing i did differently in my code was to general i’ll take out the mining Console log i did this generation um here which doesn’t seem very efficient it doesn’t seem the correct thing to do let’s just have a look so this is my code so i increase the vertex count break there and then generate that’s pretty bad isn’t it because um if we’re breaking there Then we’re not actually doing that line anyway i think we generate and then and was it the model subsets model not a mesh or anything okay right and have i used the same dimensions yeah minus five oh and equal to that’s a big difference that is a big difference Anyway let’s try this first and let’s see what difference makes the difference okay i’m glad i’ve got this on camera actually the debugging that kind of thing oh put build mode on and then again i’ve hit let’s put a bit more let’s go over here let’s make some more terrain go Into the forest and now i’ll switch off okay right build some rubies can i delete ruby yep so we can delete things in the same way right let’s try and mine through this shade can i use ethan’s yes there we go oh okay so it’s just taken off like four vertices That’s really strange okay so um let’s just try this so i put in my prepare code that there that doesn’t make sense to me this should make things worse if anything good news well if if i know what i’m now talking about um compared my past self made it work very very quickly Probably because i wasn’t on camera um but maybe my futures are i.e me now i’ve improved the efficiency of the mining because i’ve put the uh the generate function the correct place but maybe the parameters need to be different for the area where we’re measuring where the vertices are anyway Let’s try and mine that oh that almost this is really weird behavior i don’t know what it’s doing okay so that wasn’t a problem putting it there i’m gonna right let’s move this back to where i think it should go let’s just think about this so if our v count is zero At the very start of our all of our loops and we’re only looking for eight of them aren’t we then if we’ve actually found one and we’ve moved it we then want to increase our v count which we’re doing if we’ve moved eight then we break that makes sense um we want to Yeah be in here we want to yeah be in our outer loop then there oh sorry there now we want to say current subset regenerate um you know what it will only be able to collect eight if our algorithm is working correctly it can only collect eight so what we want to do Is take all this v count stuff out and have faith in our system also that won’t break us out in unexpected ways and then i want to change this to what i had in my prepared code oh yes because the neighboring cube has to be more than 0.5 away because it’s smaller Than one okay so that all looks fine i’m even gonna have some tea i press g i’ll have a bit more let’s have a bit more terrain over here let’s go either axolotl for um for moral support oh now i see the face of an axolotl it’s got its fans Which fan above and at the side of his head so i kind of drew it okay right um stop generating the code we’ve got vincent looking as well in front of the axolotl right click ah i think we just mined let’s try another One can i do it again right i need to be able to go down now oh we’re mining we’re mining so um what about can i mine there yes we’ve got real mining happening and there yes oh ethan rodriguez is scrolling up and down um really comes in handy here right mine And now scroll down mine scroll down okay that’s a little tricky right whoops i just built something mine lovely so we’re mining now a problem that we’ve got is um i can kind of see it working here there we go so two two issues one is really a problem is that The ghost terrain is still there remember we’re using the purlin noise independently of what we’ve done here so what we need to just do is say like we’ve done with the caves over here is basically use that dictionary system that we’ve already got ready and just say we’ve moved the the terrain Because we’ve done it here and then and look we absolutely fall down we move so we’ve just got to do that for these guys oh this is quite handy we can have a look at those terrains uh blocks that we’ve moved down lovely okay it’s beginning to work um the second Thing that we need to do let’s go and add this to a list we’ve done the mining uh if i just put vape very basic mining is working although we’ve done all the difficult stuff the really technical vertex stuff behind the scenes we’ve done and we’re almost on an hour what i Want to do is just before this hour so seven minutes six minutes five minutes is just be able to move down to to where we’ve mined two so let’s just open up our cave system module there it is cave system so we’ve got a cave dictionary and yeah at these locations We want to we want to set the height of the cave because what we’re doing at the moment is we’re checking if the cave is at a certain position but what we want to do is yeah check if there’s a cave there and then in here we want to say that the height Of the cave so if i now go to is it purling noise in here generate yeah so i’m in generate purlin noise and so what we passed in is a x and z position and oh and this is what our um scrolling down to our gravity system or in generate shell Yeah we’re also going what is the y position on the terrain of this at this position and we call that same function generate terrain and we we pass in our subject or our players x and z position uh plus two for our height um so it’s so that’s calling this um purlin function Uh generate purlin and this is the important bit so anush is our cave system so it uses that check cave function which we’re just looking at and then if it’s true i.e there’s a cave there then it moves us down by nine so we don’t want to do that we want to return Um we want check cave to return a number so we want to say if you um don’t equal none then um Y minus equals a noosh check cave x z which is gonna bow because um we’re calling that function twice when we only really need to call it once however we are doing this plant tree thing here so let’s just keep it like this and we can get it basically get it working And then refactor unless you see an obvious solution which i don’t right now okay i should do it should be fairly easy um so what we need this to do is to return oh it already does return sorry it returns where’s check cave oh it just it does return true or false So what i need you to do is um okay let’s just let’s try this return a temporary string so a temporary string is the value that our dictionary key has stored and we want to change this to not a string now but a number and we were at minus nine So these guys want to be minus nine what i’m thinking yeah what i’m thinking is that when we’ve mined we need to set the cave um we need to set our uh dictionary a dictionary sorry we need to enter into our cave system dictionary a new key At the position that we’re at and at the current height that we want that terrain to be so in fact while we’re here in our terrain system we need a new um uh make cave wait a minute so that’s building all the case so we Want to do a very similar thing to this but we can’t just put hard code in the position we don’t know what position we’re going to be at so we want to um pass in the position here and hopefully this code builds the uh the key for us the dictionary key So we want to actually use temp string again because it’s a different function so it’s a completely different variable temporary variable equals that lovely thing there i’m gonna i also copied the brackets just so that we can go to a different line there we go so that creates this little bit Based on whatever x and z we’ve passed in converts it to a string uses an integer so we’ve got just that single number if you remember from a previous bug when we first created this and then we want to create a new entry in our dictionary how do i do that do i Just say this cave dictionary i think i just do that is it square brackets afterwards and i just say temp string equals um oh and now we need the height i call it um yeah i’ll just call it height simplicity there we go um and that should store that value at this key Dictionary key location right okay so we’ve got that set up so we’re going to use that when we mine use our mind system oh we’ve gone over the hour um what we’re doing first so we’re checking the cave and we just want to get whatever height is at that key location so Um i can do i can close down my preparation code i’ve i’ve as you can probably tell i’ve gone beyond the preparation code now we’re just live coding the first time right um so where are we so we’re back in the generate purlin so we’re actually saying if a noosh check cave Doesn’t equal none because if we haven’t made a cave there we’ve not done any mining there won’t be a a dictionary key there so it’ll just be none so we’re then going to say y so that’s the return value of um the generate purlin function which is used by The subject the player when they’re walking around so this is basically going to be the player’s height the subject’s walking height um equals we just want to say what is oh no sorry we’ve got purlin noise there no we just want to say equals equals um yeah check cave there So can i just do that once can i let’s try let’s try and be good so we just want to say um uh what cave height equals that and then we can say if what cave height doesn’t equal none Then c just sorry y equals what cave height we want and we’ve gathered that from the check cave function here so check cave returns whatever value height we’ve got so our original cave should be minus nine which was doing exactly what this function was originally doing because we just said if there’s a Cave there decrease our height by nine so that should be oh it shouldn’t be exactly sorry yeah it’s not doing it there is it it’s slightly different now we’re setting them all to kind of minus nine anyway um that’s okay um this should really work with our um our mining system anyway Right so our mining system on a cave system is kind of overlapping um because they both involve holes in the terrain um else if so i think our tree system still works is that right as long as we have a mine somewhere we can plant a tree i think that’s still okay Um right and the final thing we just needed to do is yeah when we’re mining we need to go and use um there we go um we need to set the height to hmm ah so this is a little more difficult because we’re grabbing hold of eight vertices We’re gonna get all of them right so we want we kind of want the average position of them okay right let’s try and do that so we want to say um total y equals zero at the moment and then we’re going to say total y plus equal v one So every time we find a vertex so eight of them we want to add its height to this total y thing um and then at the end before we when we generate the model we’re going to say if total why um i was going to say right the problem is Now i was going to say well if it’s greater than zero but we’ve um okay but that’s to do with height so it might be zero right so we just want um v v change equals false okay v change equals false if we have changed something then v change equals true so if V change equals true then um total y equals total y divided by eight so that gives us our average height which should be our mean height which should be the position that we actually want and we’ll floor that do we want to floor that okay we’ll floor that To give us our minecrafty kind of thing well that’s going to be flawed later on okay we’ll leave it flawed now and then we’ll say now we want to get hold of anush which is our cave system um and we want to use make cave and we Just need to pass in the x z and the height okay i just had another idea which made this a lot simpler a noosh what’s it called make cave make cave and we want to pass in the x position so we could just get hold of our um vte X our b t e z remember that’s our wireframe so this was a position that we’re trying mine at so we’ve already got that position and i could have just said the bte y couldn’t i minus one instead of doing the whole average height thing let’s try the average height thing Since i’ve made it total uh why there we go right we need to comment some of this um record change of record change of height in cave dictionary um i’m kind of um record or note that we have made change gather Average height for cave dictionary right so just a little explanation of what these variables are doing so when we look at this on part 219 will know on earth what we were doing back here and presumably will be better coders better programmers in the future and so We’ll see this and we’ll be able to refactor it efficiently okay right let’s see if all of that kind of works together and we can kind of walk down into the cave that would mind oh yes the i was still in the cave system the other issue was If we’re just moving a single a single cube down i missed out well done if you spotted that 300 points to you um equals equals i’m not trying to assign true to that variable i’m saying is v change the same as true so i need two equal signs Um and i’ve done it here as well haven’t i oh no i’ve done it in the wrong place i am trying to say the change is true there and i’m saying is v change true there okay um what was i saying okay if we move one Block down we then need to like generate like the walls of the terrain what have i done there total y equals floor total y oh yeah sorry that’s not a uh a question or a or a function i don’t know why i put the code on there it’s because i’m getting Tired now and there was a an if statement and a a tab there i really hope this works i have no idea if it will everything looks okay but i suppose it does doesn’t it everything kind of looks okay when you try to run it um so g will stop generating the terrain To test because i’m saying that because we’re i’m running out of time here right so right click it’s moved down i can’t remember what’s supposed to be happening oh i’m supposed to walk on that so let’s lower all of these guys and just see if i can [Laughter] well good news is The terrain dictionary must be working something was happening there bad news is um the bad news is that this averaging of the height not working was it right so let’s just instead of using total y let’s just use our blocks position minus one our block i mean our bte our block tool Entity thing uh wireframe thing because remember that is in the position at the height that we’re mining at but it needs to be one lower so hence minus one right oh uh yeah okay so i can still mine sorry i’m struggling i need to definitely change the controls a little bit Sorry i’m being very slow i’m not meaning to be i’m just trying to do that right and we just what to someone let’s imagine someone just walked into the room it’s just watching this they’re just like what you’re just walking on some grass that’s that’s amazing it’s actually worked wow so There we go yes oh that’s brilliant so we’ve got a fully working kind of like mining system so what i need to do next time i’ll add this to our to-do list yes is we need to kind of like generate so there we’ve got a gap we just need to generate a A cube there where i’m kind of um pointing now with the wireframe um and i suppose we’ve already got a system what if we also want to kind of like build one around the corner but there’s already a block there maybe we’ve done some building there or a cave nearby Well we’ve already got a system that checks if a cube already exists somewhere um so we can can just test to see if something’s already there and um not build another cube there that’s what i was just trying to say okay right thank you very much for watching this One and we did it we can actually do some mining now see you next time goodbye Video Information
This video, titled ‘Minecraft in python (with Ursina): mining the terrain! – part 11’, was uploaded by Red Hen dev on 2021-08-15 20:36:25. It has garnered 967 views and 33 likes. The duration of the video is 01:15:16 or 4516 seconds.
Code and assets from video: https://github.com/RedHenDev/ursina_tutorials/tree/main/python_minecraft_tut_2021
Thank you for watching 🙂