Hello and welcome to tutorial 21. where we are building some kind of Minecraft thing using just Python and we’re doing so by using Peta and lands a Cena module which you can find online with instructions of how to install it Etc so we would just well I was just introducing as many bugs As possible for example um when we mine some blocks collect them we can go to the inventory by pressing e in our system that brings up the main panel if I click on a on an item that we’ve collected we get the stack number so there are six Um there are six grass blocks collected there but then the the which is good so we coded that last time we’ve got text on the screen and we’re keeping track of the uh the number of uh collected Cubes but if I then go and collect some Stone it just Acts itself on top of the um the grass block so that’s um that’s not great which is weird because um if actually let’s just run the code again during um my earliest testing as long as I don’t go and create that text for instance lesson Stone there’s some grass Get some Stone get some grass let’s go and get some soil Etc look you can see that on the the hot bar which I’m calling the little inventory at the bottom that hot bar um is working correctly um the problem is only introduced when we just Select one of the uh the hot spots there so if I click on this guy presumably that’ll be okay but then if I go for soil will that go to on top of the grass block no so I can’t even um reproduce the bug in Essences anyway we saw the bug the first Time around and the problem is with what we were creating in the last video which is in the inventory system um and uh uh fixed position am I in the right place I am so there’s a function called fixed position which is part of the items class and so what this function Just to remind ourselves again is when we drag and drop um one of the items one of the little 2D um block types um I’ll go find the drop function there we go it cools the first thing it does is call this function fixed position Which just snaps it to the grid of our inventory but the problem that we’re having is down here so our new code so basically I’m saying there if the closest Hot Spot exists which means we found a new space to a hot spot to snap to The first thing we say is the position of our item on the inventory equals the position of that new hot spot so far so good then we say that this hot spot we’ve just found is occupied we say it’s item I.E the item that it’s got that it’s storing that’s hosting is This and this just refers to the the instance of an item belonging to this item class then we’re saying it’s this is very new we’re saying that hot spots stack now is whatever number of Stack we we had in the previous hotspot from from where we’ve dragged the item So that’s fine but then this is the problematic bit of code and it’s kind of like Legacy for my my old code I’m kind of saying if um we have dragged it from somewhere which is always going to be true so I’m really there just testing If we have dragged it from somewhere I.E it’s not just um being instantiated from somewhere else so I think I’ve put this in here to prevent an a previous bug which no longer will happen so well I say that we’ll find out so I think we can do away with that guy Um but then what I’m saying is this new line here actually that’s just sort out our indentation I can press shift and then the Tab Key and that like does an anti-tab it removes the tab which is very useful for multiple lines so just hold down the Shift key as you do it it’ll take away the tab very useful for Python programming this line is new as well we’re saying that if the current hotspot to the current place that an item is doesn’t equal the new hotspot then do some stuff now the reason why I’m checking to see if the the current hotspot and the new hotspot are different is because if we just click one of the items this function fixed position being called by the drop function will be called because the way a Cena has been built if it notices you click something then It’s assumed that you’ve kind of like dragged it but I didn’t want to go and find a completely new hotspot I just wanted to find the closest one which includes the one it’s already on so anyway this just means we can click items and the the item will stay where it is um But we’ve got to sort some things out we want to say well um if it well if it is a new hotspot then yet that new hotspot stack wants to be set to zero sorry the old hotspot wants to be set to zero so the old hot spot Will be the the item’s current hotspot apologies if this is confusing um then we also want to to overlay a load of spaces on top of the text display of of the the stack number so that makes it this the stack number disappear which which was useful but then um then We are updating um our hot spot oh yeah saying now our current hotspot will be this new one that we found um which we don’t need to do if they’re diff if they are the same so that needs to be part of um this indentation so This is the problem if we’re saying this current hotspot occupied is false and it doesn’t have any item that’s going to be bad news if it’s the same Hot Spot I.E we’re just vacating the hot spot where the item is and then we’re not moving it so that’s why we’re Getting that strange bug we’re basically emptying an occupied hotspot so I need to whoops I need to um cut those from there and place them there so I need to only empty them if it is sorry we only need to empty the old hotspot and say It’s got no item there if we are indeed moving to a different Hot Spot somewhere else in the inventory on the hot bar and then and then finally we can just update that this item has a new current spot I.E the place where it’s actually moved to um okay Right in that final bit we can leave alone it looks like yes there’s no available hotspots so just move to your old position right so let’s go and see if we can now avoid the bug we try and recreate the conditions so all I have to do is collect some grass There we go now if I click something different no now I have to bring up the Press e to toggle on the the inventory and I click my collected items now if I go and collect something should go to the next Hot Spot yes that’s brilliant and can I just drag Things around lovely so the text disappears from there and I still get three and I get three over here did I just collect three I’m just going to collect some more do some blister mining well you might not be able to see the stone it’s a very similar gray but it Has occupied the available hotspot um notice I’m collecting loads of things but we’re not updating the text on those Stacks so that would be useful to do and maybe we could make the text black as well and now I’m stuck but let’s go and see how many we’ve got we’ve got 11 there And look oh the text hasn’t disappeared from the hot bar nor has it disappeared there that one did disappear that’s interesting so we’re getting some uh text stuck and again when I toggle off uh the text isn’t disappearing okay so a couple of things to look at there right okay Here are my notes um for this video so bug I can text remaining when it shouldn’t so that we just saw that um items of different kinds overlapping that has been sorted done that deplete stack number when building and then of course trees that’s what we’d love to get to um good right Um so what was the text remain mentioned um ah let’s add another kind of like feature there we want the um um item stack text update upon uh collection that’s what should be happening so in our collectible system when we um call check pickup and we’ve picked up A collectible then we’re playing a noise and then we’re um calling the item static method new item and passing through what block type that collectible is so we go into the inventory system which is where the item class is the item class and we go down to um new item And then with using our stack check method to go and see have we already got some of that um block type on the Hotbar and if not then we have a look for a space if there is space on the hot bar then we increment sorry we begin a new stack um If it’s true is that in stack check oh there is if it’s true that’s when we increment uh stack uh so here I guess we need to also update the text on that on stack okay where is our text well there was actually another little bug oh it’s right here In the drop method um we were asking the current uh the The Hot Spot in question we were creating a text object but in fact later on in the video we added that as a property of every Hotspot from the get-go there we go so in the initializing function of Our hotspot every hotspot across the hot bar and on the main inventory panel we are giving it a stack record how many items it’s got in that position but also we’re saying it’s t it’s text display um is in text now the bug I was just talking about is Originally we were only creating that text on the fly as we dropped an item as we picked one up and all clicked on it as the case may be which we don’t need to do anymore we don’t need to create a new text item to put on top there so actually that’s Probably responsible for some of the buggy some of the buggy um Behavior we got because we’ve got multiple text entities flying around our UV UI so I want to say um the text objects dot text so the actual text it’s displaying is not a new text object but it’s just the message Or the string that we’re building up here I also mentioned that it would be nice if it were black there we go it might show up a little better if we want to change the position of it by the way we can fiddle around with its Dimensions here I’m not going to fiddle around with any UI coordinates they’re notoriously difficult um but there we go so we’ve got some we’ve got some text Behavior so this really shouldn’t stay in drop we should have its own dedicated um function I’ll know how General to make the function because I want to do This kind of thing again so yeah I want to say well let’s try and write it let’s write it just above here um so this is going to be a static method I.E it’s not going to belong whoops I was going to say it’s not going to belong to every instantiated Um where are we item no it’s going to be a general method this is going to be a general method to oh no it could I was gonna say um sorry because the stack number relates to a hotspot not an item and remember we’re inside the item Class however every item does have a current spot I.E the current place it’s it’s snapped to on the grid so actually we could make it a member function which feels right so let’s go for that so text and we’ll call it update sorry def update um stack text And because it’s a member function we want to include this keyword as a self-reference and then we want to do this kind of thing um display how many boxes I’ve got stack so I can move all of that into its own dedicated function and then just replace that with a call I Can say this Dot um update stack text fantastic so that just reproduces the behavior but ah now this is much tidier making sense and then hopefully we can use this so what it does is just get the current stack number and just update the current text Of the text object so it doesn’t create a new text object it just updates the text that it’s showing hopefully so I can call that in um check stack check there we go so now I can say um oh no this okay so this is a static method H dot item that so that’s how we can get the item in question so H dot item dot um update DAC text let’s see if that works oh that’s really satisfying we can see the numbers incrementing wow it’s worked it’s worked straight away notice how the panda is always around When things are going well when there are bugs can’t see them can’t find him whoa okay okay um what I didn’t like it’s like we don’t get a number one as you can see with the stone actually so if I go and click on the stone then we do Um I’m not sure about the black text Maybe we will increase the text scale so that was in um the inventory system in the hot bar sorry hot spot um class no it’s there we go scale we’ll go up to one point five five and Yes so we’ve got to think we didn’t get a number one because when do we get an item stack created well that is in the um new item function here we go there we go so when we first create one so just in here what we just need to do is Um after we’ve got our item and everything maybe before we break we just want to get hold of B which is the item that we’ve just created and we say update stack text so now we should see that up here I was just on the tip of my brain I had Some memory of in a previous so I wanted this previous uh tutorial to-do lists I had something The Sounds were picking up an item wasn’t that text for stacking info on inventory wow we’ve done that stacking behavior on inventory done that disabled Collectibles ah that was it if Far away from the subject or destroy Collectibles if lifespan expires so actually we’ll just replace that with this guy because there’s a simple way of doing that um using the destroy function actually built into a Cena so we’ll do that um sounds for picking up an item but yeah we’ve done that Um UI aspect ratio bug so that’s everything there okay so I can go and do that so um ah in the collectible system well this is weird I want to go to the initializing function don’t I so this is where we’re producing a an item instantiating a collectible I should say And the last thing we do is generate its model and then we should say um Set uh collectible to destroy after um some time and all we have to do is use the destroy method from a Cena ah we’ve got the red error wiggle because this module doesn’t know what destroying Means because from Asuna we are only importing discrete functions like entity vets do Vector 4 load model and audio we also need after a comma destroy that Imports and so now we can go down to where we were before so we’re in the initializing function of our collectible Object and we can say destroy this this object and then you put in the delay so we could say after how long should we should we give people well I’m going to say seven seconds that feels a bit short you could you know put in several minutes something like that Um let’s go and test that I’ve just um adjust my snood oh oh another thing I could do just looking at the terrain generating I found a slightly nicer balance of numbers I.E got if you cast your memory back to the subset with I.E how many blocks We’re creating within one subset area of a Terrain like a chunk and also the rate at which they’re generating and the total number of subsets are allowing ourselves if you balance those numbers you can get kind of faster terrain generation offset against like a smoother gameplay while the terrain is being generated I mean this is pretty good I mean I am recording I was going to say it just dipped to 12 frames per second but I am recording at the same time and it’s playable it is noticeably smooth that when you press G to toggle off the terrain generation it’s now silky smooth um Presumably in the future we’ll you know we’ll look back at optimizing some of that but also including an intelligent mechanism by which we could like monitor what the player is doing and then sometimes we could like hide the fact that we’re generating loads of terrain and keep the frame rate smooth Um that’s way off in the future but before that we’ve got like mobs and crafting and um biomes biomes would be a big one and this I think we’re making good progress in this tutorial so trees that’s the trees I’d also love something that’s not in Minecraft like rocks and weird formations Um I forgotten what we’re doing I should be collecting stuff aha and looking at our new font which is a bit bigger and we are getting stacks of one oh also oh yeah there’s a panda things is working things is working and so here he comes to bask in The glory get some credit um I don’t know why I’m kind of like picking on the panda we used to be good friends foreign chicken again oh did you see our collectibles let’s leave them there they’re all gonna disappear after seven seconds are you watching where are you going He’s watching oh look there you go brilliant so now that just say it’s like a weight off our shoulders we don’t have to worry about our um computers burning through Ram because it’s got loads of um collectibles um I’ve seen her has tidied them up nicely okay um let’s try and destroy the Success so if I move some tiles around press e at least the tile kind of disappeared this time but the text doesn’t okay I feel like I should move on to trees let’s just see if I can sort that bug um one thing is I’m not happy with the Color again I think white looks nicer um you can by the way add a background to your text which remind me in the comments to do maybe if you want that if you want to see that or maybe try out yourself if it does work let me know if it doesn’t let Me know you can um as well as commenting in um uh the comments section of YouTube you can also go to the GitHub issues page and you can include screenshots and we can have more of a discussion there about anything relating to this project if you prefer um I can’t find what I’m looking for while I’m talking here we are update stack text um yeah let’s change that back to White remembering we’re using these like HTML like tags to do that okay good um so yes we should have a toggle function um there we go hotspot toggle um Which will be in the hotspot class of course which is near the top of our module I could just use I should use the find um search kind of like function but I just scroll up and down um thank you so we want to find somewhere where we Can basically just say that the text is invisible or Vis sorry invisible if we’re on the um inventory uh so I’ve got toggle non-hot bar hotspot and their items yeah that’s what I want so for every hotspot if it’s gameplay mode I.E it’s not visible if you’re not visible And you’re not on the hot spot then visibility should be true that should affect all the that should affect the text as well I don’t know why it doesn’t so let’s try and say h dot t dot visible equals true if it’s not on the Hotbar we can say it’s text is false Let’s just give that a go if that doesn’t work I’ll um move on I’ll just add it to the to-do list and then we’ll have some more fun with trees have a our first one of trees yeah white looks kind of bougie kind of classy and luxurious nice okay good um So now if I put some of those guys onto the inventory at least they’re appearing e the text is weird the text is bit okay oh we need to put them back on that bar text does move across e text days wow wow Panda I’m even feeling friendly Towards you things are working very well okay so let’s quit that that goes down there and we’ll um save to save everything um so what can we say destroyed Collectibles if life’s fan expires done um text remaining when it shouldn’t done um item stat text update upon collection That’s now done oh this deplete the stack number when building we’ll leave that on the to-do list let’s go and plant some trees okay let’s keep this a short video 45 minutes so just over 10 minutes um what are we doing so mesh Terrain our old friend so mesh terrain module if You didn’t know or can’t remember is the module responsible for actually generating our terrain probably the most important module and my idea oh yes I was talking earlier about generating terrain more silkily I believe if I change that to 124 sub sorry 1024 subsets and then the sub width dropping to six We might get some nice uh um smoother generation let’s just have a look at my prepared code yeah 1024 and six and then in the main module we’re actually calling that generation function um we we I used to like have like a counter system and then generate a lot of Subsets in one like update frame in order to capitalize on on speed but that also knocks down the frame rate so let’s just see what I’m doing with those numbers plus equals one greater than one and then just generate it every frame basically something like that okay so let’s just reproduce that in The tutorial code so I’m back in the main module account it’s greater or equals one account equals one and just generate terrain okay just before starting the trees let’s just see how that feels yeah that is a bit smoother actually and it is pretty fast isn’t it let’s see if I can run And the terrain does generate beneath my feet or in front of my feet oh we almost fell off okay so that’s not bad so I haven’t got the fastest computer and I am recording and I’m kind of sprinting around changing direction I didn’t fall off the terrain which is good enough If I press G or if you press G to toggle that terrain Behavior then you can get your oh hello Panda you can get your 60 frames per second um I love this kind of creating like these strange roads Panda terrain roads um that’s a nice mechanic for a different kind of game Trees so back in mesh Terrain not getting distracted this time um what we essentially want to do is yes every time we place um a block so we’ve got generator block um or actually generate terrain so what terrain does is yes it’s in here because generate block is Kind of a general purpose function we might use it indeed to grow our trees um so we don’t want to grow trees upon trees and things like that but in generate terrain that’s where we’re looking at actually building our terrain and where we can think about caves and and other things um What we can do is inside this two-dimensional grid this Loop nested Loop where we’re just describing like a chunk area and we’re generating blocks within that grid uh we set the width by the way to six to six by six so it’s gonna be 36 at a time We can say every time I’m going to call the generate block function and place down like a grass block or a stone block by random we can say hmm shall we make a tree here and we can do that randomly to randomly Place trees or what is much better is to use purling Noise again so purling noise is the algorithm we’re using to decide not random terrain but predictably um Landscaping up and Downy undulating kind of train in the same way we could generate some purling noise separately to the terrain for areas of trees and basically for a a two-dimensional or a coordinate It can have like a a number attached to it that’s what the purling noise gives us and we can say if that number is high enough then put a tree there that’s what we’ll do so um yeah so we generate a block and then basically on top of that block should we Make a tree um Planet tree question mark Cherry planetary um foreign are we in a class yeah we are um so it’d be nice to have a static function within mesh Terrain um for planting trees so let’s I’m already doing this differently to my prepare code Which is not good news by the way [Laughter] right and okay death um plant tree um and we’re going to need um an exposition a z position and presumably that’s it presumably that’s it and with that x and z position we can decide we can um refer to our purling noise And we can um uh anyway build a tree right so I need to find what is my x and z position um oh I might also need the Y position here so it’s X Plus k y I guess that’ll be plus one I just want To build on top of that first block and then Z plus J there we go so that’ll all resolve to three numbers and X Y and Z position okay so that calls our new function which will nice and tightly will be up here right up here okay So now we need a y lovely um you might be thinking why do I put an underscore I don’t you don’t need to do that before this parameter it’s just so that I know that it’s a parameter of the function and it’s not some local variable it’s sometimes helpful to do that okay Um so then we want to we want to go and do some pearly noisy stuff so we need a new module for handling a tree system we need a tree system so new file um yeah it’s going to be a python file and I’ll call it the tree underscore system Dot py Foreign and I do want to save it in our tutorials yep that’s in the right place create file great okay our tree system so before I forget we do want to then um from tree system import asterisk import everything then yeah we need a function to Um oh we probably need yeah let’s create a class and we’ll call it uh tree well it’s a it’s a system so I call it tree system and um it can have a I don’t know if this is a nice way of doing it but like I’m addicted to static Methods now this is probably a silly way of doing things I don’t know um Define uh we’ll have a setup function where we um whoops where we are going to um create our create our um Department noise object and set things up there um and then we’re going to need like some Kind of like function to um generate tree and that’s where we’ll pass in um again presumably x y and Z we might not need the Y here um I’m just writing the past keyword as I’m kind of like sketching things out because python will crash if there’s Nothing within a function so you just write pass just to say don’t do anything but we’ll fill you in later okay so back to our mesh Terrain where were we um yeah we’re in plant tree and we haven’t got Parts in there so in here The first thing that we want to do is um from the tree system we want to say um tree system generate a tree at X y and z um it might be something like really we’re gonna well let’s go and uh see my prepare code for the purling noise stuff so This will begin to make sense so we need from the purlin module uh the purlin noise function first of all yep it’s been 45 minutes we must get a little bit of a tree a tree nub something happening before I give up so under an hour under an hour here we go Right so we’re in the tree system we’ve got some purling noise great actually prepare code um oh yeah so I’ve done tree system similar kind of thing um I think some of my syntax is wrong there right yes in a setup function here’s where we’re creating there’s not many lines but we’re saying Um we’re giving our tree system a property of some noise I’m calling it a noisy end an end from like um Lord of the Rings and then uh noisy because of purlin noise and all we have to do is to pass into the function the purlin noise function which we just imported How many octaves so that’s to do with kind of how the purling noise will be distributed all these numbers the density of certain areas on the if you imagine a map will be I.E where there will be trees and where there won’t be trees and then the seed is just like a Random number that you can put in okay um and then we can adjust the the distribution of the trees using that octaves number the seed number but also the frequency okay so let’s see if I can reproduce that without copying pasting um so yes we want to say um tree system dot um Uh noise equals purlin noise and then we pass in octaves of octaves equals I’ll put those on a new line octaves equals three octaves I’ll call it and then seed equals tree seed if you can say uh tree octaves equals 32 I think I had and then tree seed I’ll say 20 uh 22 since it’s 20 22. there we go so we’ve got our noise um object okay which we can then use in gen 3 we also need tree frequency which what did I set to 64. so the frequency is basically the the smoothness the higher the frequency The smoother or the more gradual a change over some Terrain in other words if we had we would have like loads of trees and then slightly less trees slightly less slightly less likely or slightly less as we move to different areas for a high frequency if we had a very low frequency number Um then it’ll be very Jagged like loads of trees here no trees no trees loads of trees or just trees kind of like dotted in like a random way around um I’ve just noticed that should be a property of the class not just a local function a local variable here so tree System Dot and I could call that freak actually frequency equals 64 was it I think it was 64. a voice belt system wrong up there and then wrong again there we go now we can all sleep at night oh pass we can take away good um so now In our grow tree or generate tree we are getting our purlin number so at this particular position we want to say are we going to grow a tree here or not based on the number from the purling noise there so we’re going to store that in local variable Tree system get a noise and I’m going to pass in oh it needs it looks like it needs a list so we’re putting things in square brackets and it’s going to be the X position divided by our frequency and the Z position divided by frequency And in fact that’s all put inside of a two pull I’m curious to experiment with that but I won’t do that here because I haven’t got time okay so we’re gonna say check whether or not check whether to generate a tree here so we’ll say um I just keep to tradition tree will be just W will there be a tree um actually I could just say I use the word tree tree equals um now there’s be Lords of the ringsy let’s say ant equals um our tree systems Dot noise is it called the boys I think that’s okay Systems got knives oh setup function we need to actually call that so when the mesh Terrain um Imports this module after we’ve defined the class we can call tree system setup there we go um that’s important so it’s noise this noise function or noise object it will return us um This this number determined by the pellet noise right so as I was saying this wants to be our X divided by um a tree system Dot frequency I don’t know why that’s not popping up a bit scared of that um and then Z divided by the tree system Dot frequency And that’s it and then wrap that in a tuple if you want to find exactly why it needs it in that form you can look to the the purling noise modules or look in an earlier episode where I first code the mesh terrain and that’s where we deal With perley noise we do need to revisit polar noise for saving and loading files and different biomes and things so we’ll get back to that later um okay now I think it’s useful or I have in my repair code just to to add one to that And then what we’re saying is well we’ve got our number which is not random but it’ll feel random but each position on the map is related to surrounding positions now so we don’t just get a random dispersal um prepare code that’s what I was after um tree system Yeah and then we’re just deciding two things if that number is greater than 1.435 and I found that just by trial and error seeing how many trees I get and things like that so this is stuff that we can play around with in the next video probably so if it’s greater than For 1.435 then return W so not just returning one or zero I.E make a tree or don’t make a tree we’re returning zero for don’t make a tree but W also tells us the strength of that kind of number so that’s useful because we could say we Forget a really big number let’s have a really big tree and that size will be related to other positions on the map so it makes sense to have loads of big trees over here and smaller trees and things like that because the environment works that way And we can fiddle with that Baseline but I love this kind of stuff this molding of the uh the environment of the world anyway let’s go and add that to our code and grow a tree so if end greater than 1.435 was it then return that number else um return zero Great okay so we’re finished with our tree system module remember to call the setup function of the tree system which will just run this static method to set up um the the noise object for a tree system so that only happens once and then we can keep calling this generator tree Query really and we don’t need to pass in the Y position so I can take that out if I go back to mesh terrain where we’re calling it so we’re calling that from plant tree oh look there’s tree sifter system there we go um we can Take out the Y there we do still maybe need the Y here because we need to know where to build a tree so now we can say I’ll use enter game ENT equals tree system because remember the the generate tree function returns that number um And then we can say if ant is 0 return there we go so we know we when we’re not building a tree but if we are building a tree then maybe you can we just want to go to build up a load of Cubes or generate blocks on top of each other set To the trees block type which we haven’t got yet um it’s not been an hour yet let’s keep going so we can say for I in range from well let’s go from well let’s just go from a y position which is remember one block above the terrain block so that’s good so we Can start at zero two maybe end let’s just put an end but that number presumes is going to be very low by the way when I was trionairing this I was just printing out into the console what numbers I was getting um let’s just say enter times 10. we Might get really tall trees or or something and then we just want to say um generate block so mesh Terrain generate block so I need an x a y and a z so X y z o and the Y is going to be plus I as we Go up the tree depending on how strong the tree number is um what else do we need for Generate block uh we need the subset so I need to pass that into the tree um function generate Terrain oh no I don’t doesn’t look like I need it okay But I can just copy is this stuff I just need an x y and a z that’s good news I can’t find the tree there it is right XYZ block type let’s just set it to concrete it’s got like white trees for now and laying terrain is bolts Oh I think that was because if we are laying terrain then in generate block where is it yeah if we are laying terrain then we get stone blocks and we get snow and things like that um which is going to be refactored that shouldn’t be in here in this function we Should do that in the terrain building um but just like a hacky thing to do um in other words um we don’t want to be laying terrain when we’re building a trick right have we got a tree surely not um oh good okay it says type error float Object cannot be interrupted as an integer so that’s in our going back in mesh terrain when we’re using a loop for Iron Range you can’t just use a floating number this must be an integer so if we just wrap that with some integer casting int wrap the floating number the naughty Little floating number in some brackets and that converts it to an integer so that wasn’t too bad a problem what’s the next problem will be oh no I didn’t think that’s gonna be one generate block missing one required positional argument Z did I not put Zed in there Well done if you spotted that swear I could X y Z I haven’t got the um I haven’t got the uh um commas mixed up or anything like that no no that’ll look fine uh let’s just run that again see the message I didn’t really look at in generate block concrete One missing one required positional argument let me pause the video okay I think I’ve solved it it’s because I’m getting too enthusiastic about static methods um we only have one instance of the mesh terrain so it’s not a waste if I make this a a member function so Generate block is not a static function but I’m treating it as though it were one so really it’s a member function so this generate block Um should not work that’s scary why are we getting that there oh because now it’s a member function I need a reference to itself as a first positional argument aha okay so that was a bit more of a scarier bug than we used to and that’s a good one I’m glad that we went through that together that can be um intimidating right we’re getting a similar thing going on here mesh terrain plant tree uh requires a positional argument line 176 that’s because I forgot to change this as well so plant tree is now not a static function It’s a member function this go on planetary please this mesh terrain going planetary I need to go and find out more about static methods and decorators and and architecture Within python talking of architecture we have concrete trees or concrete poles oh they’re great I love them okay can we mine them already Ah look at that yes and no what’s kind of cool is that because we’re we’re mining we’ve only anticipated mining the ground so at the moment wow it’s treating trees as digging under the ground so it’s creating these um walls of the terrain or soil deposits Which is kind of cool you can kind of like paint some landscape I’m holding that shift by the way to um mine really quickly that’s really cool right but notice the bottom of the trunk the bottom Cube works correctly that’s because there’s a gap or a gap block a secret invisible like a Block of air over every single terrain block which means that we don’t get blocks being generated like walls I call them walls don’t I soil walls um around anyway that’s something that we can sort out the next video what would be good is just to give our trees crowns Um which is the top part of the tree because we’ve gone over an hour I’m so annoyed I really thought I’d keep within 45 minutes um I’m going to treat myself to maybe copying and pasting my prepare code so although I have done it very differently I’ve done it much more neatly in uh the tutorial for you um so where will this be in the mesh Terrain um I do all of this in generate the terrain I in other words I haven’t made a special plant tree function there it is tree system grow a tree There’s the trunk which we’ve done now we need the crown let’s see if I can just Nick that I haven’t really looked at that properly this is really lazy uh so where do I need to be I need to be in plant tree or grow tree which is near the top There it is plant tree and so again I should just comment this so this is the trunk no this is the trunky wonky and this is the crown oops indenting is a little bit off uh shift tab shift tab there we go so for T in range so what I’m doing here I’ve got 14 in range for TT in range for TTT in range so a three-dimensional grid I’m describing there and it’s going from minus two to three so it’s um four uh in the X Direction Four in the Z Direction and then four in the y direction so in other words I’m just Creating a three-dimensional block of um or chunk of cubes and then I’m generating a block at those positions um but these are slightly off so I can keep the T the TT and the TTT but I also need to do this where am I doing it so the Y position Is going to be right at the top of the tree so actually I need to remove another Indian blog I don’t want to do that block of um four by four by four um every single time I make a trunk thank you just get my comments in the right place Oh this is eating up so many minutes so where does y want to be why wants to be plus um n times 10 I guess that would be the top of the tree um and then I want uh where is this x position oh I guess I can say Yeah that’s just underscore X isn’t it um and this should be just underscore Zed and yes we’ve got underscore y I knew we needed the Y to be passed in to the first thing okay there we’ve got it right so our Crown is just a really nice nested Loop 70 minutes Did we crash yes got an unexpected keyword oh tree is true okay so I’ve done something in my prepare code which I can quickly take out that’s not too bad that’s not too bad there we go um I won’t put Emerald up there let’s Put what would be funny on top of a tree like ice It’s a Kind of Blue again you don’t have to make trees with this you can now you know whoa make giant concrete mushrooms that’s really cool um the trees are actually I was gonna Say they’re too tall but no I love them this big um notice that our performance is still pretty good and we can you can play around with these weird growths whoops as much as you like there we go right thank you very much for watching we have trees slash concrete mushrooms Um and I’ll see you in the next video apologies if the end of this cuts off sometimes my software does that so I’ll do a weird pause at the end goodbye and this is the weird pause um which hopefully no one will see so it’s a quit out here Oh I know what I could do oh it’s pausing let’s go and go to the main module and say we’ve done the trees or started them at least ah we could do this next video let’s move you over there top 22. item one deplete stack one build and double goodbye Video Information
This video, titled ‘Python Minecraft with Ursina: trees and inventory bug fixes – part 21’, was uploaded by Red Hen dev on 2022-11-16 14:45:01. It has garnered 213 views and 15 likes. The duration of the video is 01:12:28 or 4348 seconds.
Time for trees. Or giant concrete mushrooms.
We also correct our stacking behaviour on the inventory, and remove any uncollected blocks that we have mined.
Code and assets from video: https://github.com/RedHenDev/ursina_tutorials/tree/main/python_meshCraft_tut_2021
Playlist: https://youtube.com/playlist?list=PLmP1LNMzp97rIbwnGHhjjobHHqWekxy8Y
Thanks for watching!