In game development, calculating block positions within chunks requires using modulo operations (position mod 16) to determine local coordinates within a 16x16x16 chunk. A critical challenge is handling negative coordinates, where C++'s modulo operator returns negative values (e.g., -1 mod 16 = -1), unlike Python which returns positive values (15). To ensure consistent positive results across languages, developers can use the formula: (a % b + b) % b, which guarantees the result is always within the range [0, b-1]. This mathematical approach is essential for implementing accurate block detection, collision systems, and terrain generation in voxel-based games like Minecraft clones.
Inmersión profunda
Prerrequisito
- No hay datos disponibles.
Próximos pasos
- No hay datos disponibles.
Inmersión profunda
Bug fixing and adding block breaking to my Raylib Minecraft CloneAñadido:
Yo, what's up YouTube? Uh, in the last stream, this is what we managed to implement this custom block hover. And look at how when the mouse is it's at the block, but it needs to be uh exactly at the model for it to actually register.
Yeah, custom block hover.
And for the flower, it's different. And look at how you can highlight the block behind it.
That's really cool.
This is what we did the last time. And it's a big improvement even from the Java clone.
Um, we can even Why don't I even run the Java clone?
Uh while the Java clone is loading so that I can show you the difference how big it is. And for this stream I was thinking like in the previous stream I told you guys um today we will probably add the player and collision. Well, I was thinking about it and I was like, "I think I think there is something even more important than uh the player."
Uh yeah. So, this is the block hover from the Java clone. Look at how it's always the same. I mean here if you want to look past the grass to there and even with torches especially with torches you place a torch you want to do something with the block around it and you cannot but this time in the C++ clone now we have this custom collision boxes so now we have access to the block behind it and we even tested it with this anvil which is the like as complicate of a shape you can get and it works. That's super awesome, man. That's super awesome.
Uh, and I promised you guys we'll do the player today, but I was thinking about it. Yeah, wait a minute. I was thinking about it and I think, look at this.
Isn't this a bigger priority? making the terrain infinite because this is not Minecraft. It's not infinite terrain. I think we can actually make it infinite very easily.
Uh and I think that's a priority and to celebrate it um making the terrain infinite. I was thinking we can even um we can add a biome and I was thinking to add the snow biome to celebrate uh adding endless terrain and as an sorry to switching up the plan. Yeah, here like I have all of this complicated clone Java clone with inventory with everything, but when you get to the edge and there's nothing there like and I think it would be really cool if we made the terrain endless.
I think that would be really cool. And the player will have to wait a bit. The player will have to wait a bit.
But it would be really cool if we made it endless.
I still can't believe we have the custom shapes. And look how we can target the block underneath it. That's so cool, man. And the and this block we can target. And look, even with through here, we are targeting the block behind it through this little uh space there. And now we are targeting this, man. This is so cool, man.
So, we'll make the terrain endless.
That's what I want to do today. That's what I'll attempt to do.
We can always switch to something else since I've titled the stream. Uh making a Minecraft clone. It's not something specific. So, we can make changes on the fly.
Yeah. But the custom block is amazing.
Um, we could we could make it we could u also just do the player. We could also just do the player to have a player that walks around and maybe do the UI to maybe do the UI as well. H if we are going to make a decision on what are we going to do, it has to be now.
And so I'm thinking about it.
Which one would be cooler?
Which one would be more satisfying?
So what are the options from here on out?
or what to add.
Um, there are a couple of options actually. I'm the reason I ask is I'm not sure if we should really add the endless terrain now. So, what are the options?
We could add lighting, but that would only change here the shadows. It's not that big of a deal.
Am I hovering the air block?
I shouldn't be.
Um, we could add lighting sure we could add lighting, but that would add only here a little bit of shadows. It will be a lot of work just for that. It's not worth it.
I have to figure out this invalid block ID. What's up with that call stack?
Get block. Oh, it's in the raycast. Huh?
here.
Get block ID invalid.
Oh, it's a big number.
Current block 48 and 16.
48 is three. I should have access to that.
Um, when doesn't have current block.
Yeah, I don't know.
So, what are the options from here on out?
What are the options from here on out?
H for this stream. Uh I stated that I want to have Okay, let's make this bigger because I'm reaching the top of the world.
Uh instead of height of world height, let's make it 15.
And when generating the subchunk uh where is the noise here? here.
H minus 20.
So, we lower the world to be bit further down. And let's change the player spawn position to be zero.
And let's start it.
Come on, man. Work with me.
Now I've broken the game.
Uh, let's have the target be equal camera position minus um plus 01.
Okay, this is vector 3 and sub chunk here noise it's from 0 to one.
So from 0 to 10 0 to 10 and if I subtract let's subtract five it will be from minus5 to 5 the surface level from minus 5 to 5.
Yo, what's up?
What?
Oh, there is no damn it.
Uh, it shouldn't go minus. It shouldn't go minus at all.
So from it should be uh how much is the height? The height is 15 * 16 240 let's have 100 + the noise. So from 100 to 110 will be the terrain. Let's do it even 25. from 100 to 125.
And let's set our position.
Um, yo, what's up?
What's up, Apple Caution One?
Yo, Pesa, big fan. Yo, what's up? Uh, this auto translate translates your message to I seen big fan. I have to hover it to see the original message.
H. Uh, let's set the position to be 110. No, 125.
Yeah, that's it.
Now world generation is all slower.
Huh.
Weird.
H.
So, um, for today, Damn it.
I cannot even talk for one minute without an exception. Uh it's from the raycast.
Let's stop the raycast from constantly making exceptions so we can actually start on uh implementing a new feature.
Where is the raycast?
Where is the ray cast?
It's in the main CPP and it's what was it?
Yeah, it's in the while loop here. It's in here searching for block. If it couldn't find a block, if um if it's still searching for a block, we need to set the blockover ID equal air, let's say.
and um h and block over ID. And when we are drawing the where is it? Draw crosshair here. We draw the block hover if Yeah. If we are searching for a block to just not draw the the block hover. I also making Minecraft clone on Roblox. Going pretty good so far. Uh Roblox is a good choice to play around with it. It looks all right.
I haven't tried it, but it looks all right.
Uh here we can even remove this.
Yeah.
H Now the block hole is not working at all.
Um what happened with the block hole here?
Oh, if we are not searching, if we are not searching, sorry.
Yeah.
And now the block hole is perfect.
Yeah. Yeah. It's so cool, man. Now, hey, what's this exception? I always get it.
What am I doing wrong?
It's trying. Yeah, like I get it. Like I get what's what it's complaining about.
I'm trying to get the uh block when the ID is like an very very big ID and there is it cannot convert it to a existing block because this ID doesn't exist and I have an exception here that to tell me I'm trying to convert an invalid ID.
Sure, but why am I getting it here? It's it's again in the blockore.
It's again in the block hole in the raycast.
And why would here it would be such a big number.
Oh, you know what we can do?
We can um put here invalid ID and it will always be the last one here. Look at how it automatically increases. This will always be the last possible highest number ID which is now nine. And every time we add an ID, it should be u between these two, not after the invalid ID for sure. And now we can actually test it here.
If ID is negative or if it's if ID is uh equal to or higher than invalid ID, we can catch it way earlier.
And what's up?
What is complaining about now?
Man, someday I'll just switch to Neo Vim because this intellisense is just horrible, man. Horrible.
It was like this and this was perfect. I add this. Oh, come on.
I add this.
Oh, should be like that. Sorry.
Yeah, if it's like that. Where else do I have this? It's in get block. Oh, here it's in the default.
Yeah, let's start it now. We should get the error way earlier so we can debug it.
Yeah. Why do we get the highlight here?
Oh, because it's probably saying it's a grass block.
Um H here.
F10.
Air. It's there.
Huh?
Yeah, it's air.
Why is air?
Okay, let's continue.
And this is zero.
And this stays as true.
Oh, no. But yeah, let's continue.
This is air.
This is still air. Oh. Uh, let's put it here.
Grass block.
grass block.
Um, get block type.
Why do I get a grass block when looking up the sky?
Block origin. The Y is 128.
H can I get go back?
I cannot.
H Why am I getting a grass block there?
Get block type.
Let's search for grass block.
Let's stop this.
Come on, man. Grass block.
No. No.
No.
No.
Here.
Here.
This is for get neighbor block data.
Oh, here it should be air.
What's up, man? What happened?
This should be air.
The issue with setting this as air is that it will render the mesh of the out of it will render the mesh of the outside.
It's still cover why is it Oh my god, man. Why is it hovering there?
Oh, it's still generating the world.
Still generating, huh?
And the ID is invalid.
ID is in. Oh, I get it.
I get it.
Here.
I don't need to do this. Yes. Yes. Yes.
I get it.
Should be this.
Shouldn't be this. I get it.
We're still hovering the Oh my god. I thought I got it.
I thought I got it.
You can't make Minecraft clone on Roblox. Well, he cannot make like a one to one because if you really want to make a one to one clone, you use Java and OpenG do it exactly like Notch did it. But you can get something that looks like Minecraft and it's pretty close.
There's nothing wrong in trying.
He'll learn a lot.
Subjunk reference here blocks grass block grass block air grass air it's perfect. Yes, this is very good.
That is perfect. And here the ID is wrong.
Position to index local block position.
Yo, why is the Y 16?
That shouldn't be possible.
That shouldn't be possible. The Y should uh it should be from 0 to 15.
That That shouldn't be possible at all.
So, the air gets outlined when it's on subchunk border.
Well, I'm not sure. I'm not sure. I have to um to be actually sure it's there. Uh I need to in the text box out output the block hover type. But before that this is a bigger priority.
This is a bigger priority.
The local block position shouldn't be 16. And I have to see why did we get to this point.
position to index a flop on block position.
And where am I getting this?
This is a function get blocked type. Oh, it's inside of position details. Yeah, this class has this variable.
Yeah. Okay. Let's look at where do we increase the y or maybe where do we actually calculate it? Maybe upon calculation that happens here. It's the block origin minus the subchunk origin.
Yeah, sure. Nothing wrong with that.
here.
No, here. If the Y is the size is 16 minus one is 15. If Y is 15 or more, I set it back to zero.
If it's 15 or more, else at most it would be 14. Increasing by one, it's 15. This is not the issue.
It's not that function.
And here I set it to 15. Still it's not here. The issue the only possible place it could become 16 is here. It's here.
Uh and we can create a break point.
We can create a break point here. uh on the condition that on the condition that the y equals 16.
Yeah, I think this will catch it. And let's try to catch the same error.
Really? We caught it that soon.
Yeah, I have to look into it.
Uh, is my chat bugged or no? Test. Uh, your chat I don't think it's bugged. I can see you last five messages at least.
Yeah, I can see them as well.
So here the sub chunk origin is 112 and this is 128.
Yeah, it's 16. And why do we get into this case? What's the position?
This is the position.
This is the position.
Let's Let's capture it and go to the Man, I really wanted to do other progress on other things. not have to deal with the block hover, but here we are.
Damn it. Um, and so the local block position Y shouldn't be 16. Let's focus on it. Just on it.
Uh, we calculate the subchunk origin Y.
Oh. Uh, it's first I set it to be the position divided by 16.
Okay.
So, the position 127 uh this divide by 16 then I floor it. So 7.9 becomes a 7 * 16 is 112.
112.
And the block origin um block origin we round it.
We round it 127.5.
Rounding it becomes 128.
128 and we subtract them and it become 16. Yeah, the math is correct.
Um, yo, bets a big fan of you, dude.
Thank you. Are you going to make it so we can download? Uh, probably never because I'm using copyrighted resources.
More fans, floor fans, floor fans.
Um, this shouldn't be possible. The local block position shouldn't be 16 for sure.
And this crashes the game.
Uh, how do I do it in Java? We'll do the same calculation with how I do it in Java.
Uh, where's my position details? It's here.
Here.
Because in Java, I don't have that problem. I I don't have that problem.
So the chunk origin is floor diff and I round the position before I do it.
Oh wait a minute before I divide it I round it.
I didn't know that.
And block origin. I just round it.
Interesting.
And here.
Wait a minute. Local block position.
I also Yeah. I get the Yeah. And I subtracted. Yeah. Yeah. The only difference I noticed is I need to round the position.
So here I round it and divide by 16.0F then F4 then by 16.
Oh my god. Let's see what did I break.
Huh?
Did I Did I break it?
Well, the block hover is now very very bad. Extremely bad.
But other than that, at least there's no Now we don't get the exception where local block is 16. And why did we get the Oh my god.
Why is the world breaking?
Why? For a second there, the world was breaking.
Yo, this is a nice spot.
So why is now the block hover hovering the air block I'm at and why man what's happening man what's happening Yo, what's happening?
What the I'm tripping, man. What's happening?
Yeah, let's close it.
Oh, Okay, I wanted to make progress making the terrain endless, but I broke the entire game.
I broke the entire game.
I'm confused on why the game started acting like it's possessed.
It's as if the game was possessed, man.
It was very weird.
H Let me think about it. Let's actually I have an idea.
But this will this will be I have an idea on what to do.
Um but it's going to be risky.
Now I'm like here I had a game-breaking bug.
I had a bug here and I fixed it by doing it exactly like I do it in Java, but that caused some very weird additional problems that I don't want to solve.
Instead, I'll change it.
Instead, I'll change it to be exactly like in Minecraft.
And as a reference, we'll look at the Minecraft wiki.
wiki.
And here they say on how to get the uh the chunk coordinates and I'll have to do it like they do it.
H I'll have to do it like they do it. Look at how they only floor they only divide the coordinates by 16 and floor it.
That's it.
Where floor is the largest previous integer.
So 27.18 is 27.
The coordinates of a block within a chunk can be found. The coordinates of a block within a chunk can be found by taking the coordinate mod 16.
For example, if the x coordinate of a player is 27, uh the player is on chunk 1 minus one and at 11 one within the chunk. This is what we'll use. Exactly. That Yes. Yes. Yes. Yes. Yes. That's what we're going to use. So, we remove all of these around. We remove them.
We remove this. We divide by 16 and floor it.
And then to get the actual coordinate we have to multiply by 16 again.
Then instead of calculating the block origin we'll calculate the local block position first which will be which will be what?
Uh mod 16.
So, position X mod 16, position mod 16, position Z mod 16.
Yeah. What's the issue?
Vector three was the issue.
Um here um was this one 23 34 block position.
Yeah. Okay. It's here in the block position. Okay. If it's 16 16 Yes, it works perfectly. Okay. If it's 16.5.8.2 8 9 17 Huh.
Yomi, what's up? What's going on?
I think I need to floor it here.
Need to I think I need to floor it.
Um, okay. Okay. Okay. Let's copy this.
No, let's uh this will be on the X and this is position X mod 16 and floor.
I have no idea. Uh, can I see the progress? Yes, of course. Are you going to remake cave game for April Fools?
No.
Why would I do cave game? Why would I do it?
Um, CPP mod number Yes. Yes. Yes.
Number module 2. Yeah.
So, what's up?
I floor it, which should return an integer, right?
A float. It returns a float. What the position X? Why do I have to do it in this way?
Position X.
Man, that's so annoying.
Y and Z.
Y and Z.
Y and Z.
Sure. And now I'll calculate the block origin.
Block origin will be the subchunk origin plus the local block position.
Yeah. And here let's test it.
This will break everything probably.
Oh, what's up?
Our local block position is super weird number.
My mouth was rock here. I have Florida H.
Let's add a conditional where log of X, Y, and Z.
Oh my god.
X, Y, and Z.
Okay. Okay.
Running now.
Uh oh Uh the Z is minus one. Oh the Z is minus one. We have negative numbers.
We have negative numbers.
Uh negative local block is wrong obviously.
here. Oh, come on, man. Here. When the position is negative, how do they handle it?
When the block position is, let's do here. 0 0 only on the x-axis.
So, 0 1 2 3 4 5 7 8 9. Okay. Okay. What if it's 1.1 2.3 4 6 is the same? Okay. What if it's minus h why - 2 - 3 - 4 weird.
So, it's not just the module.
How are we going to handle this?
How if it's one?
If it's one, yeah, it's 16 per chunk. I get that.
And I'm trying from the block position to get the local block coordinates within the chunk. Here they just use module 16.
Oh, and even here minus 15. Let's do minus5.
That's one. But if we do 15, that's 15.
H minus 15.
Man, I hate math.
- 15 is one.
So if it's uh let's um let's here let's do a break point when it's negative conditions when position X is negative or position Y is negative or position Z It's negative.
And let's run it.
Yes, it stopped.
Oh, can can't we get a more normal position?
What are these positions, man?
Damn it.
Okay. How much is Yeah, position X is minus one. Subjunk origin X is -6 which is minus one.
So here min -1. Yeah it's minus one. And here it's 15. But for me it's -1 because it's min -1 module 16 equals for me minus one.
But uh but here minus one module module 16 is 15.
to add 16.
Oh, if it's negative. Okay, so um Okay, we add 16. Okay, what if it's 16 here? It's zero. Okay, what if it's 32?
It's still Z. Oh, no. Okay. Okay, let's do if it's uh 17 17 we add 16 it's -1 and -1 mod 16 is 15.
Yeah. Okay.
Yeah.
How did you know? How did you know? I think that's that would solve it.
Okay. What if we do um because 16 - 1 = 15.
So -5 + 16 = 1.
Oh, I get it. Yo. Hello. What's up, creeper?
Yeah, I got it. Uh, but let's test with the bigger number one last time.
Minus 33.
- 33.
- 33 + 16 is this.
And this mod 7 mod 16 is 15.
Yeah, it it it was that simple.
We have geniuses in chat.
So here plus 16 should be working.
But now the block hover is broken.
But at least there are no errors. I think so.
The number of 16s you have to add to make it not negative is the number of chunks you're going back. Oh, so what you're saying adding 16 once will not be enough.
Now we can test it.
Put a condition on break point.
Where is local block position?
Local block position X negative or if the Z is negative or if the Y is negative.
Let's do it like that. And see if it break points there.
Um, yeah, we have it.
Oh, because uh we have a conditional break point there, it slows down everything.
Yeah, that will not work.
That slows it down too much, right?
Yeah, I think it slows it down way too much.
Uh, it stopped.
Local block position is negative. Okay, let's see um what change we have to do.
Hold on. I just described how module works. Maybe 116. If it's negative, then module works.
Yeah, we let's see now uh which side is negative.
The x is negative. Okay, let's see what's up with the x.
The x is -6.
Well, this should be what?
-6 + 16 should be zero. Why is it minus one?
Uh, today I'm trying to solve a gamebreaking bug.
I was going to add something else like the player or infinite endless terrain, but we got stopped from a game breaking buck.
Sadly, it's one of those days.
It's one of those days.
Um position x x position y this is minus one but um uh let's see what's um position x and floor it what do we get we get -7 yo - 17.
Okay, let's uh copy this value here. Let's copy this value and test it here.
-6 something something H.
Okay. What if we remove this?
Okay. If it's exactly -6, it will be + 16. It will become zero.
And yeah, module 16, it's zero. Sure. If it's 16 something, it will become 17 + 16, it's minus one.
-1 module 16 is 15.
So why is my math giving a different result here? It's giving minus one and that's wrong.
-1 module 16 minus one.
Wait a minute.
Um CPP module.
Um module Modulo model operator X mod Y then Y is -1 mod 16 is 15 but in my in C++ minus one oh do we need to do brackets No, we don't need to. Yeah, it's still the same.
Why is it different the math here?
That's very confusing.
Here it gives me 15.
That's very confus. Oh. Uh, let's see if the order is wrong.
He uh x and y x mod y so min -1 mod 16 right yeah if x is not completely divisible by 16 then the result will be the remainder in the range This in the browser it compensates when the result is negative looks like in CPP and doesn't.
That's very weird.
I'm getting different result uh C++ modulo are there alternative alternatives the remainder of division of a by b the remainder so let's divide 1 / 16 that's uh this minus 0 something something and the remainder so 16 uh the wait a minute uh a module b returns remainder of division of a by B.
So here 5 module 2 gives one because um 5 / 2 is like uh it's should be like if we remove the remainder but why is it different with the negative numbers negative number module with negative numbers. Yeah. Yeah. Yeah.
This this this.
Yeah. Let's do a simple example. So, we uh online CPP.
Let's do an online CPP in here.
Okay. Understand? Here let's do 10 / two.
10 / two. Five.
Five. Sure. Now 10 module 2 is zero because it's divisible. It's divisible. There are no remainders.
So um let's do no let's do four. It's a lower number.
So it's easier. Uh, and let's do minus4.
That should be minus2 minus 2. Let's do module should be zero. Zero minus 4 mod 2. Here is zero as well. Sure.
Perfect. Let's do three.
Let's do three. It's one because uh inside of three you have two and the remainder one.
Well, let's do -3 minus one.
Let's do here minus 3 mod to 1 and here it's minus one.
Um, don't tell me the whole stream will be struggling with basic math.
Let's see what this guy has to say. If is J then would there be what are you on about? Similarly, why is he using this word like Iing?
Just use AB.
So here min -4.
Yeah, here minus 3 module 3 will be zero because it's divisible.
And here with three is divisible. When we do module 3, we'll get a number from zero to two for sure.
So when we do module 16, we should get a number from 0 to 15 for sure.
Yeah. Um and here and look at how there are no negative numbers. They are always from zero to the number minus one. Always.
Always.
And why in C++ do we get a minus one?
Let's try here. The minus4 it's minus one.
-4 -3 uh -2. Let's do minus2.
It's -2.
So, it's giving me these numbers but with a negative sign.
So, if I do min -4, yeah, it's giving me here the one with the negative, but it should be giving me from here the two.
If minus one were one there be a break in the pattern when going from there is not and yeah let's do min -4 mod 3 here it's two it's two yeah there'll be a breaking pattern when going from minus one to zero note that there is not in significant number of language where oh yes yes yes note that there is a not insignificant number of languages where minus one Audio 3 is minus one which does introduce a break in the pattern but at least is still on an ascending sequence until interrupts around H. Yeah. So he says there are languages where the module is different and the C++ came out to be one of those um C++ module different with negative with negative numbers is different isn't the module operator but the division remainder.
Oh, so if in case your integer rounds towards zero will be and we have in order to get a positive result for the mod operate you need to add the divisor in case the remainder was oh come on man.
So here a module b should be what the are you doing man? A module b plus b and the whole thing module b I just want a module.
Damn it.
Like sure if we use this uh the formula this guy gives us we'll have the same module for sure like here if we use this sure it will probably work but I want you I just want to see are there other alternatives man that was very surprising module negative numbers this.
Yeah.
Python gives a three. No. C++.
Oh, come on.
Python program gives us three. So, - 7 mod 5. - 7 mod 5. Yeah, it should be three. The Python program gives us three as the remainder. Meanwhile, C++ gives us minus2. Yes, that's the problem.
Uh the reason uh Python uses flo division to find modules, remainder, dividend, divisor, quotient and quotant can be computed from.
Yeah. Um uh this formula seems to work in the browser. Yeah. Um, like I said, most likely it works. Like you've tried it, you confirm it works, but it uses two modules.
I just want to be sure is there an alternative that's like the module is not fast operation and doing it two times like I want to see if there is an alternative something that doesn't use two modules uh from divisor floor division In Python for division used to determine the remainder truncate version is used to determine the the main remainder.
So in Python they use this floor in C++ they use this trunk which don't which makes it to minus1 and this makes it to minus2.
Oh.
Oh. So if it's this formula we can just do this formula.
We can just do this formula.
And yeah, and they say this will fix it.
Uh, let's let's actually open up the Where is my Yeah, this is my online this. So here he says here he says it's - 7 - 5 * - 7 by Five.
Do I need to include cmaf minus two? Yes. And so here if we use floor minus two uh why is this a five?
Uh excuse me -7 / 5. Let's use the trunk.
Yeah, it's minus2. And with the Python version, let's do this before.
Minus two. Uh what if we make them as floats?
Three. Yeah, now it's three.
Drunk.
It's minus two. Yeah. Yeah. Let's do the floor.
Oh my god, I didn't know this.
And where we can make it into a function.
We can make it into a function. But where should I declare it?
Where should I declare it?
Um globals in line int mode mod load B return uh A B A B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B.
Sure.
But um is it okay that they're floats?
Uh let's check here.
Um - 7.5 mod 5.
This is 2.5 - 7.5.
7.5.
Two.
Let's remove. Let's floor it here.
Three.
2.5.
Yeah, it's wrong.
Um, three.
H.
Not sure.
Um, modulo operation formula.
Um many implementations use truncated division for which the quotient is defined is the yeah C++ uses trunk and Python uses four which is what we want truncation to zero in digit does according to equation one the remainder have the same sign Sure.
Floor division. This is what we want.
Yeah.
The rounding down common pitfalls I don't care.
Performance issues. module operations might be implemented such that um yeah I know there are performance issues that's why I didn't want to use two modules uh properties ah in programming languages C++ oh fot mod fod integer floating point rounded remainder.
Wait a minute.
Yeah, this is truncated the percent and if F mode and F mode truncated remainder rounded post plus post plus post plus post plus post plus post plus post plus post plus post plus post plus post remainder um std remainder let's use that uh let's test it in the let's test it where's my testing place. Where is it?
Where is it?
Online CPP here. Um.
Oh, come on, man.
Uh remainder min - 7 and five uh - 2 - 7 mod 5 three.
Come on. Didn't they say remainder uses floor mode minus two?
Then one you on about where's my wiki page?
It's here.
Yeah, they said it's rounded remainder.
They said it's rounded, huh?
Oh, no. Round it. No, that doesn't No, no, no. It should be flirt. It should be flirt. Should be flirt.
So there isn't a function that uses it.
Where was Python?
Java floor mort.
Yes.
And Python. Where is Python?
Python.
Flirt. Yeah, for them it's flirt. And they have a truncated version and a rounded version. They have everything interesting. And in C++ it's either truncated or rounded.
Uh C++ floor module.
Well, yeah, they al they also use this.
Oh, we'll we can just use it. Why not?
We can just use it. Remainder file is similar for integer operations.
Yeah, it says it's similar, but it's surrounded. It's not floor.
It's rounded.
Uh let's compare minus 7 and five.
Yeah, it's the same result like one.
What is he on about?
end line.
Um yeah, here uh we can just use the like it. We'll use the two modules like why not?
Yeah, but it uses integers.
Yeah, why not? Why not? If it causes some issues, we'll figure it out.
Uh, Lord M.
Yeah, let's just use this and if it causes issues, we'll figure it out.
Uh, and let's test it actually.
Um here and we need to move it to the top minus 7 and five three. Yeah. Um yeah, we'll just move on with this.
And annoyingly, an hour and a half was for like man. An hour and a half was for like nothing, man. This ruins it. Uh, subchunk. No position details. Where was the game breaking book? Here.
Uh, let me think about it.
Uh, should I still add the 16? Oh, yes.
Yes, I think. And here only here we do by 16.
And here it's Y and here it's Z. And what's the condition? Oh, I removed it and I cannot bring it back.
I lost the conditional block position X if it's negative.
That was the problem.
Here Y and here Z.
Let's start it.
This should solve the buck.
Where's the terrain?
Where's the terrain?
Um, let's close it actually and give it another chance.
It's way old.
It's probably because of the debug debugging that it's so slow.
Let's remove the break point or disable it at least. And let's without debugging to test it.
Yeah.
But look at how slow it is, man.
And it's so slow.
It's so slow.
Barely managing. Let's go to the release version.
The release version will be faster for sure. But damn, let's do the release.
Let's build it.
Yeah, the release is okay.
The release is okay.
Uh since the second module is always within the range, make a lookup table with premputed values.
H I can do it.
Why not?
But it would be good to uh benchmark the difference of is there's an if it makes an actual difference to to see how much time it takes to generate the terrain with how it is now and with with the additional change of um but here this will give from 0 to 15.
Oh wait actually no uh that's not true this um like if this is like negative number this can be negative like the problem we were having then plus this uh I think this makes it positive yeah but u it's it's okay uh in the release version. It's okay.
Uh let's bring back the block cover.
Let's bring back the block over the block hover. What's the issue with it now?
Where is it?
It's inside of main and Sure. Here. Sure. Here. Now, where is the block origin now that we do not around it?
I'm not sure where the block origin is.
Let's assume we don't need this.
Let's assume it. So, we will not need it here.
Huh.
This is a gamble, I'm assuming, and it didn't work.
Um um uh I'll have to put a break point here to see if we are ever inside of this.
Uh yeah, here. But this needs to stop.
um what you suggested I'll think about it for another time. It's for increase of performance which we don't need right now but I'll leave it for later in here.
Let's debug this part to see if we ever have a block hover without the drawing. Okay. Block hover.
We don't have it.
Uh, are we in debugging?
Yeah, we're in debugging mode. We never reach here. Current position.
Sure. Get block type.
Um, get collision boxes.
Sure. Here. Block origin.
Block origin. H.
Let's actually start it and look at the tree for example.
Um, and stop it here.
We should be looking at the tree grass block. No.
Why is it targeting the grass block?
It missed the tree.
Current block uh chunk subchunk origin it's zeros and local block position is this.
And so block origin is this.
I'm not sure, man.
I'm not sure where exactly in the block hover is it breaking.
Where exactly is it breaking?
Yeah, boomer.
It should be correct. Actually, it should be correct because this is the block origin. Before the block origin was right in the center of the block and now it should be at the bottom left towards us.
And uh for example the grass block uh block hover the from is zero. So it's perfect. And the two is uh should be one.
So it should cover the entire block in here.
Yeah. This should work. Yeah. But it doesn't work. That's the confusing part.
Not at any moment do we get inside of this. Not at any moment because I put a break point and it didn't activate.
We get the camera position. We get the direction. We get the Yes. Step. Sure.
All of this is perfect. This no problem.
Current block. Oh, let's look at the constrictors.
block origin and order. Sure.
We get this.
Yeah, it should be should be all right.
Uh, let's go to position details the constructor. So let's say we have u 0 0 on the subchunk.
Sure. And let's say local block position 0 y 0 and the x let's say it's one. Uh let's say it's zero. Block origin will be zero. Now let's say we go to the right it will be one and block origin will be one.
block origin will be one.
But if it's 0.5 position, if it's 0.5, it will be flo.
Yeah. So 0.
Wait a minute.
Yeah. When we do the ray cast and we want to get the block. Let's say where is the wiki page here. Let's say all of these are zeros. And let's say we check for 0.5.
That's still the zero block.
0.9 only when it's one that's when we are in the next block.
So in the ray cast here current ray position if we are at 0.5 it will give us the block origin of zero here.
Yeah, I see. No, no issues.
So, if I put a break point and we fly around, the raycast doesn't hit a block at any moment. At any moment.
That's impossible.
That's really impossible.
Even if we are inside of the terrain, the rakas should hit a block. At least one block.
At least one block. We never go here.
But we for sure go here. Yeah, we for sure get here.
Uh let's go inside of this loop.
The from is zeros and the two is 16.
So min is uh let's look at where's the block origin.
Block origin 74 73 72.
So min is 74 7372 is the block origin itself the minimum and the maximum is 75 7473 perfect and here current ray position is 74 94 four.
Yo, that's wrong. That's very wrong.
That's completely wrong. Since the Y is 121, the block at 12.
Where's What do we get here? Subchunk origin is 64s.
64s and that's wrong. The the subchunk origin is wrong.
Oh man, am I stupid or something?
Here it's position Y, position Z.
I must be stupid.
Okay, we the debug started automatically.
Yes, we get a block hover.
We get a block hover.
Um, with some issues.
With some issues.
It's catching the block even here.
Yeah. Now it will be easy to solve.
Now, this should be an easy problem to solve.
It should be uh yeah, let's uh go to the drawing here. Let's remove this part.
I don't think we need it.
Oh, we definitely need it.
We definitely need it.
Uh yeah. So, what's up here?
Oh, the the block hover is being drawn from the center.
You know what? Let's draw the block type.
The block type that would be more useful than the drawing.
So we are hovering the leaf and here the is the the lock.
Now this is one.
This is three.
Somewhere there's an error somewhere.
I'm not sure where exactly.
Yeah, the uh the grid is offset by 0.5 in every direction because of rounding somewhere.
Well, the what we changed is here. Um, yeah, there we definitely removed the rounding here.
Uh, here before I got the block origin by rounding the position coordinates. So if we were looking at 0.9 it would uh increase it to one but now we lower it so it brings it back to zero. Like before the origin was at the center of the block. Now the origin should be at the bottom left and like negative on the Z.
And that change needs to be uh handled.
And I thought I handled it uh in the ray cast here. Where was it? Where is the ray cast? Here um no here. uh here for calculating the min and max here before I was adding the I was subtracting the 0.5 so that I'm at the uh the corner of the block so that I can I can have the minimum and the maximum of the block coordinates. And now since we don't have the rounding I don't subtract the 0.5 and I thought that would be it. Uh, we can bring it back just to see what's up.
Just to see what's the difference.
We can bring it back. Here we brought it back. Now it's like before. And let's see what the change is.
Uh, now now it looks better actually.
Now it looks better. Uh so don't tell me we have to add it. No.
Uh let me think about it.
Yeah, here it's perfect.
Uh here it's not downwards. downwards. It is not.
We need to move it.
Uh let me let's let's just focus on the Y direction.
It started um the Y is perfect on the positive and on the negative it stops here at the 0.5.
down here. There's no access at the 0.5. It stops. It's It thinks the minimum is here at the center.
That's weird.
So if it thinks the minimum as said the block is at the center, what if we subtract one?
What if we subtract one?
Uh, it's worse. So, what if we uh bring it back 0.5 but add add it?
Uh, that should be better.
Now it's worse.
What about minus one?
minus one.
Um, doesn't let me undo it like it was before.
Oh.
I don't know, man. I wanted to work on uh something else, not to solve bucks.
I didn't want to solve bugs today.
So, the book origin man, the uh let's uh do go in 2D. In 2D will be a lot easier.
Uh where are my cubes?
here are some cubes.
Now um now now if we had a point in space let's say this is the positive x this is the let's say this is the positive x and this is the positive let's say it's the y doesn't matter.
And let's say this is 0 0.
So, and here it should be 1 one.
All right.
Uh, and um, if we get here to the wiki, if we're block position 0 0, it's 0 0.
And if it's 0.8, look at how it's still zero. So that means if we get a point here, it will bring it back here.
But before I was and it has to be even if it's 0.99999, it's still zero. But if it's one then is the next box. So if it's no matter where you touch here, it will bring you back here.
But if we go outside of here, this will now be one and it will be here. Before how what how was it before? Before Before if before if you landed like this is 0.5 uh if you landed anywhere here it would move you. So if you landed here it would move you here.
Uh h so h let me think about this. Man, I hate situations like this because this is it's much more fun to work on the other things.
If I had an an intern, I would be like, "Figure this out." And I would handle more fun problems.
Um H.
But always, no matter if we're rounding or flooring, it will land at one of these. Always. The block origin will always be one of these. So, I am changing the wrong spot is what I'm saying here. I'm I'm changing the wrong spot.
I'm changing the wrong spot. Actually um so here the raycast position is the camera position and we add to it small steps every time.
every time in the direction of the camera. This is perfect. We don't need to touch that for sure. Now here, here is where the change is.
It's this part. This is where we get the block origin.
And the difference is that before if we are at this position, it will give us this block origin. And now it gives us this block origin. That's the main difference. That's it. That's it.
It's giving us a different block origin.
Uh huh.
And h it's giving us a different block origin and it's like working as expected.
It's working as expected.
I hope it's free and good luck. Thank you, Susette.
Thank you.
Uh we get the block ID. This uh so this part this is the change we made. So like we cannot do anything different here like uh this is the change we made and this is how it should work.
So, if we're going to make a change to fix the problem, it's not here. It's somewhere else.
Here. Get block type. Current block. Get block type. Oh, position to index. Local block position.
Is there a change here?
Is there a change here?
Will I get the local and No, that's that should be all right.
That should be all right.
Uh then getting the block. That's okay.
This is okay. And here this is okay. So now we are here.
Collision box. Then this is okay. So we are again at this point.
So now before and now we start from the block origin and I want the minimum and the maximum.
I want the minimum and the maximum. So what I wanted is no matter what the block origin is even if it's this or this I want to get the minimum which is this and the maximum which is this.
That's what I want.
and h and before I needed an offset like here I add an offset of 0.5 before I needed that since if I landed here if I was looking here and I got this block origin um I would need to offset myself here like um actually how much will be the offset? It's difficult to see since this gap shouldn't be here.
Uh let's move them closer like this.
And so if I'm here a 0.5 increase let's calculate the middle this 0.5 increase is here but it's on the Z as well.
It's on the Z as well.
That's weird.
But if it was here, it's still inside.
And if it's here, it's still inside.
So what my code was before? If the I check anywhere close to it the origin it will work h because uh it will give me anywhere here it will give me this position and now that's not the case now it's anywhere here.
So, I should remove this like I did.
That should be gone.
That should be gone.
And let's look at when we draw it.
when we are drawing it.
Maybe the issue is when we are drawing it since I didn't make a change there.
And most likely I have to do here I get the hover block collision boxes config size and offset.
The size is uh fine. The size is fine.
Let's look at the offset.
The offset I get the xaxis plus half the size because oh let's check it out here.
Now we are within a block.
We are within a block. We have this part. This is the origin. We want to draw for example this collision box.
For example, this and let's look at the X H. And before let's say Nor is more at the center.
And let's say this is like this is eight and let's say this is uh so here it's eight.
Where's the previous drawing? We had a good drawing. Well, relatively good.
Where was my previous drawing?
I don't have it here. No.
Uh, I had a very good drawing here. Yes. Yes. Yes. Yes. Well, it's not perfect.
Uh so this is 0 0 166 16 and I calculated here if the size was six and the center was 8.
Mhm. And now the center is down here actually.
And here to calculate this H I did the eight.
Yo, what's up? The real splits was cooking.
I'm just noticing your profile picture.
What's up with your profile picture?
Uh so we have eight minus half the height. So minus how much uh the height is 12?
Uh so it's six. Yeah. So 8 - So 8 - 6 is 2.
No. 12 - 6.
No. 8 - 8 - 6 and 8 + 6 for this top part.
No, now it should be uh here.
I'm confused.
Let's start it.
So, what's the issue? Okay, look at how uh let's focus on this axis on the Y and the this is let's say it's the X uh positive X negative X. Sure. And this is the Y. Perfect. Now, uh, here I think we'll be able to figure out what's the issue with the blockover because it's not working properly since we had to fix a bug.
Now, my position is here.
It's not working.
Let's ignore the Y. Let's just focus on the X.
This is the middle point.
So to the left of the middle point, it's not working.
It needs to be offset.
Huh.
Yeah, I I was also thinking it's half a block off, but like half a block off.
Huh?
Okay. So, if it's half a block off, when I'm going when am I going to target the flower?
Yeah, here is the flower. What about on the Y?
Yeah, here.
But now still six.
Half a block off.
If it's half a block off, why is it still targeting that? Oh, maybe because I need to go more back.
Yeah, more back.
Okay, let's Okay, half a block off.
Let's subtract backward 0.5 on just on the X. Where are we going to subtract it? Let's go to the raycast. And here h Okay, let's subtract it. Um let's subtract it here.
Uh 0.5 F. But it was before like that.
Uh vector 3 just on deck. I just want to focus on decks.
Where's the positive? And this is the positive X now.
Okay, look at how perfectly it matches here.
But yeah, again it stops here.
This is a void. This is empty.
This is no block.
And only half of this block is working.
Oh my god.
Only half of it is working.
This half is not working.
Why?
Wait a minute. Oh, I get it.
I get it. The problem is way deeper than that.
I get it.
Um, the mesh drawing is the issue.
When we draw the mesh, where is the generator? Because I had there a unit cube template. I had a unit cube here. Um, and somewhere I do I change it here somewhere.
Subtract value. Yeah.
Conditional add face. Yeah. here 0.5 F.
Do I do it anywhere else?
Only here.
Let's not subtract 0.5 F now.
Sure.
So, what's up?
Yeah. Now the origin is down there like it's supposed.
Yes.
And now let's now let's fix it.
Now we can do the other changes that I wanted to do here.
And we need to change the drawing here.
That will solve it.
That Oh my god, that didn't solve it. That made it worse. Uh, it should be Oh, I shouldn't subtract. I should not I should not here at offset.
Yeah, finally.
Finally.
Yeah, finally. Now we have block.
Oh, and I have to fix these rotations with the mesh.
Yeah. Um, we fixed the block hover, but the change was very significant. We had to change like the change was very significant.
Uh, I have to go back to the mesh template and when we do the rotation here, let's remove this.
Let's try it.
Yeah, the grass is perfect now. Yeah.
Yes. Yes. Yes.
Finally.
Finally. No more issues.
It took me two hours to fix book.
Two hours.
That was very annoying.
But now our coordinates are exactly like in Minecraft, exactly like Minecraft.
Uh so for this stream, for this stream like now we're back at the start. Uh so for this stream uh what I wanted was um here. Look at how it has an end. I wanted for this dream to make this endless.
That's what I wanted.
But I also but I also was wondering if there is something else that's better use of our time. So what the options are to make the terrain endless. This is option one.
Uh option two is to add the player so that we can walk around.
Um is there option three?
Um adding the player will need to have collisions as well.
H option three. Is there an option three?
Option three is the sky, the sun and moon.
H I think the endless terrain is more important because like come on this is not Minecraft if the terrain is stuck like this. I think we should do the endless terrain.
Um this is why we don't like books.
Yeah, I hate books. Do you want to make it one to one? Well, I'm trying to. I vote to make player.
Uh, the reason I want the endless terrain is because we already have done the player, but we haven't done we have we haven't yet done the endless terrain even in my biggest Minecraft clone.
Uh, and I think it would be interesting if we have endless terrain because we already have player in Java and it would be cool and because if we manage to make the terrain endless, I want to add the snow biome like that. That's my reasoning to push for endless terrain.
I want to add the snow biome.
So, we could have falling snow. We could have snow blocks.
I think endless terrain would be cool and I don't think it would be that hard.
Um, but there is there's one issue. The whole terrain is static. I don't have block breaking in uh the C++ one. It would make it easier to attend this terrain if we have block breaking. so that we can see how is it possible to update the in relip to update the terrain the mesh because here I in opengill I know how to do it but in relip I'm still not sure so we should add block breaking first that's it let's add block breaking first and then the endless terrain I've I've decided I've decided um the player Dudes the sun the trail chamber is going to be a nightmare. C++ is a nightmare in itself.
Yeah. Um we'll go all of these. We'll have a stream just for the player and we'll have a stream just for the sun, moon, and clouds. But for this stream, I think uh it will make the other additions way easier. So let's add block breaking and then endless terrain.
and then endless terrain.
So, block breaking and then endless terrain. That will be this stream.
That will be this stream. I'll be right back. I need 2 minutes.
I'm back.
Uh, so what's the reasoning for making Minecraft clone? I've seen plenty of people actually doing the same. It's just like a project to see if you can do it or are you looking this going somewhere? Um, the main reason is to learn game development, how a game like Minecraft is made.
That's it. It's not that deep. It's it's that simple. And I learned a lot and I found because of it ra and open and C++.
I've learned a lot. The only issue is I don't have an original game. That's the only issue. But it's a it's not that u big of a price to pay and I can focus just on programming. I don't have to create assets. I can reuse Minecraft's assets. Yeah. Let's make it endless.
Let's make this endless.
Oh no. Let's make block breaking and then endless because I need to see how to update the mesh itself and let's commit it.
Let's remove the here.
Where is it? This. Let's remove it.
And let's commit it.
Uh what should be the commit?
Floor block core dets instead of round.
That's it. H. So uh for block destroying blocks h destroying blocks.
Destroying blocks.
It's when we left click if if uh mouse if key no where's lip cheat mouse is mouse Mouse button pressed released pressed. Let's do that. If mouse button pressed, mouse button left.
So if we left click and um we are not searching for the block with the ray cast.
So we have a block hover.
Um good luck mate. This is great project for learning. Yeah, thank you. I'm back.
I can do some rel in regular C. Nice.
That's cool.
So, here for destroying a block, we want uh let's get the position details.
Set block type.
Huh.
Um, hover block hover set block type to air.
That's it.
And now we need to redraw the chunk.
H, we need to redraw it.
How are we going to do that?
How are we going to do that?
I have set the block we destroyed to be of type air and I have access to the current subchunk where the block is.
I need to set I need to uh generate the model once more.
So can I do what functions do I have?
Get block type H.
Uh let's look at the terrain generation here.
Here this generate mesh. Let's do that here.
subjunk origin generate mesh.
Let's attempt to do that.
Okay, we left click.
And what happened?
What's the error?
We actually manage.
We iterate through all the blocks.
We do all the calculations.
Oh because the threat is still not Yeah, I get it. I get it.
Here I need to use this the mutx lock.
I think because this is still generating. Can I have to wait it out?
Okay, this is destroyed. There is no block here.
Uh, but it's still rendering.
Um, how is this even understandable?
What do you mean? I cannot understand what you're saying.
Yeah, this block is destroyed.
Uh, but it's still rendering.
Yeah, I'm destroying the blocks, but the mesh is still rendering as it was.
H.
Uh, let's think about it.
So I'm telling it to generate the mesh which will calculate the position, normals, UVs, colors, indices.
Sure.
It will go through all the blocks, do all the calculations, it will calculate indices and it will h here. I set up the mesh and mesh generated is true and I need to generate the model as well.
generate model.
Um, what texture should I use Atlas?
Excuse me.
Yeah, I need to generate the model. I already have a model. Sure, but I already have a model, but I want to do it as the easiest way possible.
No way that was your Minecraft clone. It looks generally indistinguishable from normal Minecraft, aside from the look of the leaves.
Well, I cannot uh change your If you cannot believe it, I cannot do anything about that.
Um, here I generate the terrain.
This generate mesh. No, the draw. Let's look at the draw.
Where is the draw?
Where do I draw them? Here. I need the the shader or the Which one do I need?
Both. I need both.
Uhhuh.
Okay, it worked.
Uh, but let's wait it out to generate everything.
Okay, it generated everything.
Okay, it's technically working, but uh it's creating a new mesh all the time and that's a no no.
And we need to update the neighboring blocks as well.
We need to update the neighboring subchunk model as well.
And we need to do it properly, man.
We need to do it properly because here I regenerate a new model and a new mesh.
And what I actually should do is reuse it because I I where is it here in the mesh? I allocate memory. I allocate memory. I should reuse that memory.
And I should set the mesh when I create it to be uh dynamic.
Um or was it for the model or was it when I upload the mesh?
Upload mesh. Yeah. here. This should be true to make it dynamic.
Yeah, dynamic which uh just uses the instead of um where was it?
Uh which just for the vertex buffer uses dynamic draw instead of static draw.
This means the buffer will be changed.
It will be updated for open gel and I need to update it. Uhhuh.
Um Ray lip update mesh dynamic mesh.
Update mesh buffer.
Update which calls J buffer.
updates an existing allocated memory and we cannot add we cannot change the size. This is the most difficult part.
This is the most difficult part for updating the mesh since it's the most difficult part because at when we first render the mesh it uses like let's say 100 vertices. It's a lot more than that but let's say it's 100.
But if we add a block this as vertices we need more space. So we need to and we cannot increase it. So beforehand we should allocate enough memory but how much memory how much memory like and I'm thinking I should leave it as static and I should uh just delete it the mesh and load it again. I think that would be the simplest thing just the mesh to leave the model but to delete the to update the mesh itself because I don't know how much size I would need and for example I have so many sub chunks that are just filled with air no vertices zero vertices and if I have to allocate like a lot of space for every subchunk There will be a lot of sub chunks that will stay as air forever, but they would have allocated memory without me ever using it just so that the mesh can be dynamic and I can reuse it just for that. And I'm not sure if it's worth it.
No way. That was your M. Oh, yeah. Okay.
You should make the leaves look better after that. What do you mean to make them look better? The leaves aren't casting any shadows currently.
So, like, are you saying I need a shader or to add lighting? Um, like this is the Java clone. Do you mean this like this is my Java clone?
I don't know what the heavy cord is.
Yeah, I think we should delete the mesh.
So here of false to leave it as static.
H.
So when we uh when we change the mesh when we change the subchunk when we destroy a block we we can use the generate mesh function. Sure.
And can we check subchunk mesh here? Um, if if can we check for the mesh if subchunk mesh ID is different then zero to unload it.
Unload mesh sub chunk mesh and then to continue onwards.
Or maybe to just Okay. Will we ever reach here?
Let's test it.
We have to wait out the generation and that's so annoying.
Okay, generated.
And let's see now if we destroy this.
Yeah, we go here and it should unload.
Yeah, I think that will be our solution.
We unload the mesh and create a new mesh.
And it's not slow.
It's not slow. That makes it easier.
That makes it easier. And now we need to Yeah, here we need to update neighboring subchunks.
Uh how how I'll think about it. I'll be right back.
I need 2 minutes.
Yeah, I'm back. You still got the HalfLife movement, right?
Uh, yeah, I have it, but it's in the Java clone. In the C++, we don't have the player, so we don't have the Half-Life movement.
And while I was gone, I was thinking about it. The destruction of destruction of blocks. Uh I'm not not actually doing it right.
We need to make a separate function here. We unload the mesh. That's okay.
That's fine. Um we need a separate function because here we generate a model, a new model. We can reuse the old one.
We can reuse the old one.
Uh so subchunk can make a function void.
What should it be called?
Redraw.
Um uh update model mesh maybe.
And here we call generate mesh and we call um uh let's just use that actually and see what happens. Let's remove this generate model and here update model mesh.
Let's just call that.
Yo, we lost the mesh. We lost the mesh.
The entire mesh. We lost it.
We lost the mesh.
Uh, we need to connect the mesh with the new mesh with the model.
So we we create the new mesh.
Come on.
Um here we update the new we create the new mesh. And for the model subchunk model, here transform. Sure. Mesh count. Sure.
Meshes.
Size of mesh.
Size of mesh.
Sure, we can do this. Yes, let's do this.
That's what we need to do.
Uh, subchunk mesh. That's it.
Now we wait since all there's a lot happening.
Come on.
Hey, it's still like that.
Why?
Damn it.
Why is it still like that?
Uh, let's see what's up. Uh the draw mesh generated.
Um mesh generated model generated.
Vertex count H.
Oh, I don't upload the mesh.
I don't upload it.
Yeah, now it should work.
And let's switch to release since it's faster.
Yeah.
Now we reuse the model, but we just uh update the mesh and give it to the existing model instead of recreating a new model. And now let's see here. We need to update the same way the neighbors the same way.
And we can do it here.
Uh let's copy this function and go to the position details here.
Let's do a void the same function here here and like this.
If subjunk is not no pointer like that update model mesh Um h this is should be like before should be like before.
Difference is now we can just do the position details.
Update model mesh. Now it should be like before.
Difference is there we can do some um we can make it target the neighboring subchunk as well. Now we can target the neighbor.
Can target the neighbor.
Let's target the neighbor.
Uh actually here. Here we'll do it like in I do it in Java. I do it differently. I set flux. I set the position as dirty.
which says the chunk is dirty, but we don't need to bother with that.
Here I get top chunk neighborh.
H yeah, let's do it like in Java and we'll have block breaking here.
Uh actually we had a moment where we got all the neighbors here like this.
We can do the same in the position details here.
like that sub chunk size like that.
And this is our current sub chunk.
H. Yeah, we need to update our own mesh.
Good. and subchunk.
We need to update our own mesh, but we also need to do a couple of if checks.
Couple of if checks.
Let's remove this.
Let's remove this. No, there should be no pointer.
This should be subjunk size like that.
Uh, let me think about it.
Uh actually subchunk what do I do here? This is the local block position needs to be lower case then world.
I get it. I get it. I get it. I just need this.
So, this is top.
This is top.
This is bottom.
Uh, down.
This is south.
I need to update the neighboring sub chunks when I update one. This is north.
This is east.
This is west.
Right.
Uh so it should be update mesh model.
like that.
Down, south, north, east, west.
Done.
Now we should have deletion of blocks.
Yes. And we should be updating the neighboring the neighbors as well.
Yes. And this is happening on the main threat. I'm not using a separate threat actually.
Yeah, that's so cool.
We can delete blocks.
Yes.
And look at how cool it is with the custom block hover. Now look how we can delete the block behind this.
Yo, look at the accuracy.
We can delete blocks. Oh, what happened?
Exception.
Oh, come on.
Access violation.
Uh, what's the issue?
Because I was clicking too much.
Yeah.
Yeah. Uh, nice, bro. I love coding. It's so fun. I hope it becomes like Minecraft. Thank you. Thank you.
I don't think uh this this happened when we clicked a lot.
Yeah.
Uh, so we can update the mesh.
So, we should be able to have infinite terrain generation.
Uh let's commit this can destroy blocks.
Um let's make the world smaller like size of five and see what happens.
Yeah.
And can we make the camera speed faster?
Camera.
Camera.
No speed.
Camera three.
Camera.
Custom. First person.
Third person. Interesting. Custom. Yo, what's this?
Update camera mode. Camera modes.
If it's custom, we'll handle it ourselves.
If it's orbital, H.
else.
H relip camera movement.
Okay.
Camera modes. Yes. This what I want to test. This is mode three. This is first person. What's the difference?
Three.
Oh, first person doesn't allow me to go down. Three allows me to go down and up.
Yo, third person I can look at the cube. Yo, third person I can look at the cube.
That's the only difference. It renders something there.
orbital. It uh goes around a point and that's it. So let's uh and I cannot set the speed sadly.
Uhh.
Where is There should be a speed here.
The camera move forward. Camera move speed. Where is this?
Where is camera move speed?
Here. Camera move speed. Is this?
It's this.
Okay. Probably I can set it somewhere.
Find all references.
Where is this?
Let's change it to 15. And let's make this to be uh not free but first person.
Let's make it first person.
Yeah, now it's faster.
But I want to go up and down and it doesn't allow me.
Then let's make it um camera free.
Let's make it camera free then.
Yeah.
So, uh let's make the terrain endless.
Let's make it endless.
Uh, nice, bro. Uh, I'm very good at coding with L, but it I don't know about C++. Oh, this looks like L.
No way, dude. Are you sure you won't get copyrighted? I hope so. I don't get As long as he doesn't promote it, he shouldn't get a copyright.
Yeah, for uh a year has passed and I have more than a year has passed and I haven't got any copyrights.
Let's see now. Uh make terrain generate when get close so PC doesn't crash.
H uh what we managed to do today like 3 hours passed like usually I ended 3 hours and the rain generation I want to do it in one single stream. Uh maybe um this should be it. Uh but for this stream we managed to fix a very annoying bug with the block hover. The block hover is now absolutely perfect and it's exactly like in Minecraft. uh for the block positions, the block positions origins, it's exactly like Minecraft and that took two hours. For the rest of the stream, for the last 1 hour, we managed to have uh block destruction and the block destruction just creates a new mesh. It deletes the old one.
It deletes the old mesh and for the model, it switches to the new mesh. And that's it.
And since we're at 3 hours, um I think it would be best to leave whatever else we decide to do for a a new stream. I want uh because whatever we start to do today, even if it's sun, even if it's um endless terrain, uh there is a big chance if we start now after 3 hours that we'll have to we will not be able to finish it for the entire stream because at most we'll have two hours and I don't and I don't think two hours will be comfortable to finish whatever else we decide to do. I think that would be best.
And uh this will also give me some free time to maybe work on the next video since we have a lot of streams. And the latest YouTube video is on me implementing skeletons. But that was Java. And here we have the Rail project.
And this will give me time to work on a new video on to update those guys that only watch YouTube videos that we are now on Railip.
But we got quite far actually. Like I'm surprised like this is my favorite part, the custom block.
Yeah, I think it would be wise to uh end it here and tomorrow to start um the new feature. And I'm thinking uh the new feature should be the endless trade.
I think the new feature should be the endless train, but we need to have enough time for it.
Uh, did you know the Minecraft world is bigger than Neptune? Well, the Minecraft world is uh infinite actually. Well, not maybe it's not actually actually infinite since I have for the positions floats and the floats are not infinite.
Yeah, I I'll end this stream here.
Yeah, I'll end it here. Yeah, but we got we got some progress.
Yeah, that'll be it.
Yeah, we'll continue tomorrow.
Videos Relacionados
Agentforce NOW AMA: Build with React and Salesforce Multi-Framework
SalesforceDevs
490 views•2026-05-28
How agent o11y differs from traditional o11y — Phil Hetzel, Braintrust
aiDotEngineer
450 views•2026-05-28
Re: 🗣️📍theprophedu📍2026 GST 103 CLASS (E-EXAM REVISION)
theprophedu
636 views•2026-06-04
WEB TECHNOLOGIES UNIT-2 | Degree 4th sem BCOM Computers web technologies unit-2 full explanation💯✅
LearnwithSahera
1K views•2026-05-29
More tests are always better? How to use AI to identify tests that bring little value
Alliance4Qualification
335 views•2026-05-29
Search Algorithms Explained in 60 Seconds! 🤖💨
samarthtuliofficial
218 views•2026-06-01
People of Game of Thrones using JavaScript DOM
AltCampus
296 views•2026-05-30
Instagram accounts got PWNed
EricParker
13K views•2026-06-03











