For crafting, what you could do is make a hash list, at startup: you generate a list of the same size as the recipe list, calculate a hash for each of them and put the hashes in the new list, then when crafting: you could calculate the current recipe hash, and check for each of them in that list, it gives better performances on bigger recipe list, but it can have some performances drawbacks when the current recipe match the first one in the list (idk if that makes sense). What you could do is to mix both too, when the searching time become too long, you switch the the hash list technique (with pre-calculated hashes). I think you could maybe add a main menu and procedural worldgen next, could be very interresting i think. Multithreading nightmare will be on it's way to haunt you tho. Btw doing everything on the server is an aweful technique, while yes it works well on single player, on multiplayer: it will be a nightmare for the ones with poor connection quality. What you could do instead is to do server logic on both client and server, that way it could benefits some players. Also, instead of sending each data separately, you could send them all at once each frames, if no data needs to be sent, it sends nothing. (if you don't do that already) Anyway, good video.
yo so yes a hash would work probably, but that system is not worth optimizing since it will probably literally be the last one to cause performance problems. So to answer the other part of the comment, I actually already have procedural world gen with structures, I have a video on that, and also I do actually have a lot of predictions on the client, you can search my videos on that if you want to know more details 💪 And I also have multi threading on the server
i'd use a tree instead of a hash list. You only have n checks to do at most no matter the recipe, n being the number of cells in your crafting grid. I'm not good at explaining so here is how i see it: if the only recipe was a wooden pickaxe, here is what it would look like: `{"plank": {"plank": {"plank": {"": {"stick": {"": {"": {"stick": {"": "wooden_pickaxe"}}}}}}}}}` if the only recipe is a crafting table: `{"": {"": {"": {"": {"plank": {"plank": {"": {"plank": {"plank": "crafting_table"}}}}}, "plank": {"plank": {"": {"plank": {"plank": {"": "crafting_table"}}}}}}}, "plank": {"plank": {"": {"plank": {"plank": {"": {"": {"": "crafting_table"}}}}}}}}, "plank": {"plank": {"": {"plank": {"plank": {"": {"": {"": {"": "crafting_table"}}}}}}}}}` now the 2 merged together: `{"plank": {"plank": {"plank": {"": {"stick": {"": {"": {"stick": {"": "wooden_pickaxe"}}}}}},"": {"plank": {"plank": {"": {"": {"": {"": "crafting_table"}}}}}}}},"": {"": {"": {"": {"plank": {"plank": {"": {"plank": {"plank": "crafting_table"}}}}},"plank": {"plank": {"": {"plank": {"plank": {"": "crafting_table"}}}}}}},"plank": {"plank": {"": {"plank": {"plank": {"": {"": {"": "crafting_table"}}}}}}}}}` But heh, what do i know, it probably has many flaws.
@@lowlevelgamedev9330 it may be worth it to optimize it for the sake of the server, as wasting cpu time on stuff like that will make a noticible difference in how many clients it can support at once when you get more recipies, especially if modding support is added. You could put it on a list of easy optimizations tho, and then forget about it for now.
I feel like 6:20 Could be solved at 0(1) constant time using a hashing, since you can check if a certain item at a certain position matches a hash and allow the player to create the item.
yes totally, tho there is no need to do that besides as an exercise. There are other systems that are actually slow and really need optimization that I should work on next.
this wouldn't work alone since recipes sometimes can be done different ways, but since the same recipe have always the same amount of the same items, you could build a dictionary hash, yeah and boi would that be fast af
instead of checking all the recipes ones per frame from 0 to N, make it start searching at X where X is the last successfully found recipe. also, since your server has to perform the crafting checks, too a 100 player server is 8.100.000 checks in your scenario. There is a reason for mods like FastWorkbench and FastFurnace.
yeah honestly idk why he doesn't precalculate all possible crafting recipes as a hash, and only send the packet (hash) for confirmation when he ends up clicking on the item he gets from the craft.
@@depralexcrimson well, you could get hash collisions, and you'd need to verify that the player has the material to craft it. So, some of the things feel warranted, but there are some trivial optimizations that don't require a complete rework so there is imho no reason not to use those...
@@Soraphis91Hash collisions could be a feature rather than a bug - consider when mods have conflicting recipes. And either way it would drastically reduce the number of direct recipe-recipe comparisons which might be expensive for certain recipes such as metadata or script dependent.
@@RRKS_TF sure, you can have some form of buckets that allow you to reduce the number of checks, but the guy before proposed only sending the hash (between server and client) but that would not be enough information, to identify what has been crafted.
@@Soraphis91 you would only need to include an extra 8 bytes at most though even 2 would likely be enough to uniquely identify recipes from hash collisions or duplicate recipes. Alternatively you could have the hash map + buckets store an offset into a global list of all recipes. Though it doesn't really matter because this is not something that he really needs to do, he has done recipes and no plan to support user-defined recipes.
for the verification of crafting, you can make an id of the recipe of the player in the player's crafting table and then search in a look up table the item that supposed to be crafted. for example: if the gold nugget recipe id is 33 (34 if in top center, 35 if in top right ect...) then the item id will be item_id_look_up_table[33]
each item has an ID so you should add each item ID in a crafting recipe together and that gives the hash of that crafting ID. then you use a hashmap and do the same thing in the crafting recipe to get what recipe the person is trying to build. if there are multiple recipes with the same hash then you can create a loop and do your solution for finding the correct recipe. This does mean every recipe would be shapeless so you could also add code to make sure its in the correct recipe
Yo GameDev how much time it took you to let's say be at ease with OpenGL? Appriciate the content that you make keep it up! (ps sorry for my bad english :-) )
my biggest issue with performance is generally if i know it will scale badly i always try to optimize it even tho my optimisation sometimes causes more overhead and would only be worth it if my system actually needs to scale
yes that is an issue, you have to understand that nothing is free, adding an optimization is not free, it takes time and adds complexity to your code, and that is very important. So if you optimize a system that will never scale, not only you risk making it performe worse, because lol you are not google you don't search over milions of elements, but you increase your code complexity for no reason
you said you're planning on adding things like extra-big crafting tables and more inventory slots, so i don't know if it's really a "minecraft clone." do you want to go more in an RPG direction like terraria?
Amazing ideas presented, but, have you thought abbout modding (adds many blocs and recipes)? And what about functional blocks like a furnace or modded minecraft blocks like the Extreme Crafting Station or AE2 system? Wouldn't it be better to make your system handle 2^32 items or recipes?
minecraft's first moddability/expandability thoughs came really late in the dev process you know ? modding will probably be added in 5 devlogs or maybe more. And to be honest, mojang is trying to remove modding from minecraft by trying to stop updates to mc java. Just, the lack of moddability isn't a big deal yet.
ok so I don't think I will add moding. I will defenetly add things like chests or furnaces tho 💪. The system can already hold thousands and thousands of items and blocks and crafting recepies, so I won't ever have a problem
Why not make a hash that holds the data of all items in the crafting table instead of manually checking. I think with some good implementation there would be flexibility with the crafting.
Could you make for example book item contain some form of id that will be used later when player use the book then player do separete request to the server to retrieve content of the book or save new content?
yo so, I mean cpp has a few usefull features, I use cpp like it is c, but if you want c thats ok. About lua, I don't really like the idea of using a scripting language for game programming, like the idea is that you can let artists code, but you are not an artist you are a programmer so you don't get much benefit. So I have some videos to help beginners start making games from scratch maybe those will help 💪💪
can you add a texture pack system like minecraft has? you can have a directory assets/resources/textures/blocks and assets/resources/textures/items and entites and so on
does the crafting grid take into account mirroring like minecraft does because you can craft things horizontally mirrored also how will shapeless recipes get slotted into the system
yo so I havent implemented this but it is very easy, I will just add flags to recepies for miroring or shapeless. Right now I just have a flag that allows for recepies to use any wood type 💪💪
honestly it is hot worth the effort. As I have my code now its way easier to check for specific cases like shapeless recepies or recepies that also read the metadata of items. Adding an optimization is never free. It takes time and it usually removes code flexibility
revision number cannot be exploited if the rule is predictable? like increase with one? if i know that server will invalidate my action, i can send in the next package the illegal item by knowing the next revision number
Good question. No because I don't only check the revision number but also the item. The server know my exact state so he knows if I introduce a random new item
Interestingly getting to 5 digit recipes isn't hard in minecraft itself. Especially modded. Also you are not accouting for things like automation. Though a "last recipe cache" would help drastically there. Also the reason people say its a bad way of checking recipes is because minecraft already showed how it can be done better. Simply have a way of checking things per recipe type. Its very unlikely you reach an early out anyways in the first place. Shaped recipes for example can be optimized by using a recipe size compare. (Aka how big the grid being used is, EDIT: I mean slots being used in the inventory. A simple rectangle compare of width/height) That discards recipes that dont have the same shape without testing its contents. Shapeless recipes can just compare in the beginning how many items are present in the grid and if the number doesnt match then thats skipped. After that you dont compare slots but lists of elements. There are more types of recipes but they usually extend these two usually and just need a hook at the initial comparing stage. And both of these requirements for each recipe type can be precomputed (lazily) and are effectively reducing the slowness of recipe comparison... Technically minecraft does more than that but these are the biggest optimizations that are actually free since you generate caches 1x that are faster to generate then comparing 9 recipes.
I mean that is true but optimizing this system would be a waste of tine since it is literally the last system in the game that can cause lag problems. I have to optimize rendering networking chunks and others before this one. So I would just add code complexity for no reason
like my point is I could optimize it and give you the 2 versions of the game, and you would never be able to guess not even after profiling the game, which version is the optimized one
@@lowlevelgamedev9330 WTF youtube. Not telling me that this comment was answered to. I saw your second video and read these two comments. But doesn't your answer proof my point in the first place? (Especially your second comment) Yes when you only apply the optimization to "That part of the game" but nothing else you wouldn't notice it. But if you repeat the sentiment you are suggesting you run in the exact issue because it is a death of 1000 needles. There are simple optimizations that have barely any complexity increase in them but lets you early out of an rather complex check in the first place then you gain a lot without investing a lot. And your argument that "I have worse systems to invest", kinda proofs that point in the first place. I don't argue that you shouldn't micro optimize, and that is true, but your cases and the example shown on both sides proof the point that i am making is right. Yes PCs are fast to have 1-2-3 or 15 slow systems. But after a certain point you will be caught up by your "its fast enough" suggestion. And that clearly happend due to your argumentation. Anyways. I think microoptimization isn't a good idea in the beginning, but early outs and optimized design choices (aka using sets instead of lists for checking if something is inside) should be at least applied. Small note: I hope you wouldn't think that I am a beginner. I am just more into optimization than the average coder :) Also what i am making a optimization can be the difference between a 45GB file and a 2-4GB file :)
Why make 2 functions that do the same thing, craft4 and craft9 should easily be made into one, either with a switch case + argument with enum like CraftingType::Inventory and CraftingType::Bench or pass the argument of 4 and 9 based on whether player inventory is open or not if the player is crafting for (int i = 0; i < arg; i++), or if you want to do it the ugly/fast way just check if player inventory is open or not that way you can figure out whether it's a crafting bench (9 slots) or inventory crafting (4 slots), plus on top of that I saw that you do Item(); in the recipe thing (also misspelt recepie), why allocate a whole ass structure that does nothing instead of passing NULL as a sign of "nothing", seems like a waste of memory and additional performance that could be gained(unless im wrong). Also IDK why you would want to know on which slot everything is in the player's inventory, seems like a HUGE waste of bandwidth especially for those on metered connections, it would make much more sense if you did all the inventory sorting on client side as long as the items+count match on server-client there shouldn't be a problem at all, you could just make whatever inventory QoL stuff you want to execute on the client strictly in the client code, and execute those functions by communication via packets, this seems like a much friendlier approach for the overall performance of the server, this way u keep the security of cheating and also offload the sorting and stuff to the actual player/client, so you avoid doing unnecessary stuff on the server, could even save the order in a json file or something on the client cache folder, imho when you do the chest inventories and other stuff you could also make better decisions than minecraft like doing caching on both client and server, for example if u don't do anything with the inventory - no updates whatsoever, then you avoid sending useless packets to server, like minecraft does when you open an inventory even if you don't do anything you are sending useless packets.
ok so to answer the first function, I have 2 functions craft 4 and craft 9, but craft 4 reuses craft 9, so it is just for convinience. Keep in mind that I take an array of 4 and an array of 9 elements, to call this functions, and the memory ordering is not the same, so craft 4 takes that elements and rearanges them to call craft 9 corectly. For optimization related things, in order to pass null I would need to take pointers to those elements, and that can cause other problems and indirections that can cause in the end maybe even performance problems. Regardless, this system is not worth optimizing, it is very fast as it is, I don't think you could even measure its cost, the game runs even in debug mode at 60 fps, the bottleneck is the gpu stuff and chunk building. So what matrers most here is how well I am able to maintain this system. And how it id right now it is quite convinient to work with
and for the second question, I wanted to do that but you can't really do it. Imagine closing the game, the server needs to know how to save your inventory exactly, also because of the example that I showed in the video. So the server needs to know exactly my inventory. This is not really a problem tho, keep in mind that I send a packet only when I move an item, and that packet is actually very small, like it doesn't have the whole item data in it. And I don't send packets when nothing changes.
to put it simply, what you are sugesting works on paper but if you try to do it, you will see that there will be many problems, the server needs to be able to do a lot of things, so in the end you can't get away with it not knowing your state. The server decides if I take items because otherwise, if the client needs to decide that, I need to add a ton of logic to accunt for undoing an illegal item take (if someone else took it before you)
@@lowlevelgamedev9330 I am impressed of your work, very good. I wish more people that are aspiring to become game developers could watch this just so people could understand why coding close to the metal is always going to be the optimum for making games running fast and efficient. Keep up the good work.
I thought of that but the solution isnt really much better, and it is way slower, so if chains will remain for now. They are also very fast as you will see in today's video
@@lowlevelgamedev9330 That would be an extremely bad idea. My Codeeditor suggests words and when I use a word from german or something else the code editor goes crazy and tries to correct me which is annoying af
I mean I don't see why should I do that, an item is just an int. And sure polymorphism sounds cool but than I need to alocate all the items on the heap to use them so no thank you. I can just do that like I currently do it
than how will the server save your inventory lol? Also its easier to do this and than the server can handle item pickup than pick the item up myself and than undo that. Also how can the server know if it is possible for me to pick up an item since the arangement of the inventory items matters
@@lowlevelgamedev9330 when you exit game, server saves items with their positions. arrangement of the inventory don`t matter since you can only pick items that in your inventory. good luck having more than 10 players without lags with current networking style
Your implementation of networking won't be as cross platform as you'd like as it doesn't respect endianness nor the sizes of primitives (you send the struct raw data)
so first of all, the game wouldn't work on a x32 bit machine :))) You need a decent gpu to play it. So I don't really care about little endian, is there any modern desktop architecture that uses big endian?
@@lowlevelgamedev9330 Didn't think about the GPU ! True for the endianness, there isn't much computers still using it to this day. I was more thinking about aligns and types size but if you keep a single version of it on a same architecture I guess that's fine !
Something that Minecraft does under the hood that you might want to steal is that the inventory has a Cursor slot to store items you picked up with the mouse. If you close the inv, if the inv closes because someone broke the source block or you die, items in the cursor slot drop to the ground.
I mean yes but I still need to add various items metadata things like enchantments. So I supppse I will add books why not but with a smaller text size, and I'll see how it goes
For crafting, what you could do is make a hash list, at startup: you generate a list of the same size as the recipe list, calculate a hash for each of them and put the hashes in the new list, then when crafting: you could calculate the current recipe hash, and check for each of them in that list, it gives better performances on bigger recipe list, but it can have some performances drawbacks when the current recipe match the first one in the list (idk if that makes sense). What you could do is to mix both too, when the searching time become too long, you switch the the hash list technique (with pre-calculated hashes).
I think you could maybe add a main menu and procedural worldgen next, could be very interresting i think. Multithreading nightmare will be on it's way to haunt you tho.
Btw doing everything on the server is an aweful technique, while yes it works well on single player, on multiplayer: it will be a nightmare for the ones with poor connection quality. What you could do instead is to do server logic on both client and server, that way it could benefits some players. Also, instead of sending each data separately, you could send them all at once each frames, if no data needs to be sent, it sends nothing. (if you don't do that already)
Anyway, good video.
yo so yes a hash would work probably, but that system is not worth optimizing since it will probably literally be the last one to cause performance problems. So to answer the other part of the comment, I actually already have procedural world gen with structures, I have a video on that, and also I do actually have a lot of predictions on the client, you can search my videos on that if you want to know more details 💪 And I also have multi threading on the server
i'd use a tree instead of a hash list. You only have n checks to do at most no matter the recipe, n being the number of cells in your crafting grid.
I'm not good at explaining so here is how i see it:
if the only recipe was a wooden pickaxe, here is what it would look like:
`{"plank": {"plank": {"plank": {"": {"stick": {"": {"": {"stick": {"": "wooden_pickaxe"}}}}}}}}}`
if the only recipe is a crafting table:
`{"": {"": {"": {"": {"plank": {"plank": {"": {"plank": {"plank": "crafting_table"}}}}}, "plank": {"plank": {"": {"plank": {"plank": {"": "crafting_table"}}}}}}}, "plank": {"plank": {"": {"plank": {"plank": {"": {"": {"": "crafting_table"}}}}}}}}, "plank": {"plank": {"": {"plank": {"plank": {"": {"": {"": {"": "crafting_table"}}}}}}}}}`
now the 2 merged together:
`{"plank": {"plank": {"plank": {"": {"stick": {"": {"": {"stick": {"": "wooden_pickaxe"}}}}}},"": {"plank": {"plank": {"": {"": {"": {"": "crafting_table"}}}}}}}},"": {"": {"": {"": {"plank": {"plank": {"": {"plank": {"plank": "crafting_table"}}}}},"plank": {"plank": {"": {"plank": {"plank": {"": "crafting_table"}}}}}}},"plank": {"plank": {"": {"plank": {"plank": {"": {"": {"": "crafting_table"}}}}}}}}}`
But heh, what do i know, it probably has many flaws.
@@lowlevelgamedev9330 it may be worth it to optimize it for the sake of the server, as wasting cpu time on stuff like that will make a noticible difference in how many clients it can support at once when you get more recipies, especially if modding support is added. You could put it on a list of easy optimizations tho, and then forget about it for now.
@@kiryonnakira7566 this looks good
I feel like 6:20 Could be solved at 0(1) constant time using a hashing, since you can check if a certain item at a certain position matches a hash and allow the player to create the item.
yes totally, tho there is no need to do that besides as an exercise. There are other systems that are actually slow and really need optimization that I should work on next.
this wouldn't work alone since recipes sometimes can be done different ways, but since the same recipe have always the same amount of the same items, you could build a dictionary hash, yeah
and boi would that be fast af
@@kitamashi That's the thing, you could easly add a branch or two to fix that.
Please man I’m shitting myself watching these because there’s no hand sway
😂😂 okok fain I'll add it
Bruh it’s so BAD
Same...
Gotta say I always turn off bobbing, thought a lot of people did, makes me confused with the jitter tbh
5:20 Monday left me broken
Avicii 🔥
Amazing job man!
thats awesome. after finishing the project you may add the forge/fabric mod support.
instead of checking all the recipes ones per frame from 0 to N, make it start searching at X where X is the last successfully found recipe.
also, since your server has to perform the crafting checks, too a 100 player server is 8.100.000 checks in your scenario. There is a reason for mods like FastWorkbench and FastFurnace.
yeah honestly idk why he doesn't precalculate all possible crafting recipes as a hash, and only send the packet (hash) for confirmation when he ends up clicking on the item he gets from the craft.
@@depralexcrimson well, you could get hash collisions, and you'd need to verify that the player has the material to craft it. So, some of the things feel warranted, but there are some trivial optimizations that don't require a complete rework so there is imho no reason not to use those...
@@Soraphis91Hash collisions could be a feature rather than a bug - consider when mods have conflicting recipes. And either way it would drastically reduce the number of direct recipe-recipe comparisons which might be expensive for certain recipes such as metadata or script dependent.
@@RRKS_TF sure, you can have some form of buckets that allow you to reduce the number of checks, but the guy before proposed only sending the hash (between server and client) but that would not be enough information, to identify what has been crafted.
@@Soraphis91 you would only need to include an extra 8 bytes at most though even 2 would likely be enough to uniquely identify recipes from hash collisions or duplicate recipes. Alternatively you could have the hash map + buckets store an offset into a global list of all recipes. Though it doesn't really matter because this is not something that he really needs to do, he has done recipes and no plan to support user-defined recipes.
for the verification of crafting, you can make an id of the recipe of the player in the player's crafting table and then search in a look up table the item that supposed to be crafted. for example: if the gold nugget recipe id is 33 (34 if in top center, 35 if in top right ect...) then the item id will be item_id_look_up_table[33]
each item has an ID so you should add each item ID in a crafting recipe together and that gives the hash of that crafting ID. then you use a hashmap and do the same thing in the crafting recipe to get what recipe the person is trying to build.
if there are multiple recipes with the same hash then you can create a loop and do your solution for finding the correct recipe. This does mean every recipe would be shapeless so you could also add code to make sure its in the correct recipe
You are a living legend really just want to make games like you
thx bro 💪💪 I believe in you
You should add JSON serialisation, so new recipes (and other things) can be added with just JSON files
Data driven is the keyword
Wish me luck I am trying to make a Mario type game in python. And I found your tutorials very useful
good luck ❤️
7:19 ah yes recepie
Yo GameDev how much time it took you to let's say be at ease with OpenGL? Appriciate the content that you make keep it up! (ps sorry for my bad english :-) )
Just get started :-)
6:22 It should not even be once per frame but rather once per item inserted, so the performance really does not matter that much.
The metadata is nbt, you can just use that in the item data struct
Or you can use something more performant the CPP way...
Gotta add 3d block previews in the inventory
It would be cool to write some code to render the blocks automatically into a texture, tho that will take some time, will see
Monday left me broken
my biggest issue with performance is generally if i know it will scale badly i always try to optimize it even tho my optimisation sometimes causes more overhead and would only be worth it if my system actually needs to scale
yes that is an issue, you have to understand that nothing is free, adding an optimization is not free, it takes time and adds complexity to your code, and that is very important. So if you optimize a system that will never scale, not only you risk making it performe worse, because lol you are not google you don't search over milions of elements, but you increase your code complexity for no reason
you said you're planning on adding things like extra-big crafting tables and more inventory slots, so i don't know if it's really a "minecraft clone." do you want to go more in an RPG direction like terraria?
really cool dude
Amazing ideas presented, but, have you thought abbout modding (adds many blocs and recipes)? And what about functional blocks like a furnace or modded minecraft blocks like the Extreme Crafting Station or AE2 system? Wouldn't it be better to make your system handle 2^32 items or recipes?
minecraft's first moddability/expandability thoughs came really late in the dev process you know ? modding will probably be added in 5 devlogs or maybe more. And to be honest, mojang is trying to remove modding from minecraft by trying to stop updates to mc java. Just, the lack of moddability isn't a big deal yet.
ok so I don't think I will add moding. I will defenetly add things like chests or furnaces tho 💪. The system can already hold thousands and thousands of items and blocks and crafting recepies, so I won't ever have a problem
I think a modern CPU can handle at least some millions of items pretty darn fast
why does the camera movement not seem really smooth like in the original minecraft ?
yo so I have optimized the game but I still have a wierd lag spike that I still haven't figured out how to fix :((
@@lowlevelgamedev9330Look into profiler libraries
Why not make a hash that holds the data of all items in the crafting table instead of manually checking. I think with some good implementation there would be flexibility with the crafting.
Could you make for example book item contain some form of id that will be used later when player use the book then player do separete request to the server to retrieve content of the book or save new content?
yes but that would really overcomplicate the code by a lot so it is not worth it
I'm a student at a boarding, and I don't feel like learning c++, but I planned to use C and lua to make it give me help I want to pass my final exam
yo so, I mean cpp has a few usefull features, I use cpp like it is c, but if you want c thats ok. About lua, I don't really like the idea of using a scripting language for game programming, like the idea is that you can let artists code, but you are not an artist you are a programmer so you don't get much benefit. So I have some videos to help beginners start making games from scratch maybe those will help 💪💪
What libraries are you using?
No one gonna mention how the recipes in code are called "recepie".... now im hungry and want a recepie.... whatever that is
jokes aside cool vid 😎
Wouldn’t having a vector allow for DDOS attacks? Like the book exploit that happened in Java Minecraft?
I mean I will have a maximum size for items, I still have to take care of that tho
You're so awesome.
thank you 💪💪
can you add a texture pack system like minecraft has? you can have a directory assets/resources/textures/blocks and assets/resources/textures/items and entites and so on
I just did it 😂😂😂😂 fr, like I just pushed 30 min ago, you can find some ss on my discord server
When hand sway?
I have seen 3 people making minecraft clone with different languages.
does the crafting grid take into account mirroring like minecraft does
because you can craft things horizontally mirrored
also how will shapeless recipes get slotted into the system
yo so I havent implemented this but it is very easy, I will just add flags to recepies for miroring or shapeless. Right now I just have a flag that allows for recepies to use any wood type 💪💪
just code minecraft from scratch and then add it to this minecraft clone all together duh
why didn't I think of that 🤔
i understand that you don't need to optimise crafting recipes, but how about store a hash value for the recipes?
honestly it is hot worth the effort. As I have my code now its way easier to check for specific cases like shapeless recepies or recepies that also read the metadata of items. Adding an optimization is never free. It takes time and it usually removes code flexibility
revision number cannot be exploited if the rule is predictable? like increase with one? if i know that server will invalidate my action, i can send in the next package the illegal item by knowing the next revision number
Good question. No because I don't only check the revision number but also the item. The server know my exact state so he knows if I introduce a random new item
Interestingly getting to 5 digit recipes isn't hard in minecraft itself. Especially modded.
Also you are not accouting for things like automation.
Though a "last recipe cache" would help drastically there.
Also the reason people say its a bad way of checking recipes is because minecraft already showed how it can be done better.
Simply have a way of checking things per recipe type.
Its very unlikely you reach an early out anyways in the first place.
Shaped recipes for example can be optimized by using a recipe size compare. (Aka how big the grid being used is, EDIT: I mean slots being used in the inventory. A simple rectangle compare of width/height)
That discards recipes that dont have the same shape without testing its contents.
Shapeless recipes can just compare in the beginning how many items are present in the grid and if the number doesnt match then thats skipped.
After that you dont compare slots but lists of elements.
There are more types of recipes but they usually extend these two usually and just need a hook at the initial comparing stage.
And both of these requirements for each recipe type can be precomputed (lazily) and are effectively reducing the slowness of recipe comparison...
Technically minecraft does more than that but these are the biggest optimizations that are actually free since you generate caches 1x that are faster to generate then comparing 9 recipes.
I mean that is true but optimizing this system would be a waste of tine since it is literally the last system in the game that can cause lag problems. I have to optimize rendering networking chunks and others before this one. So I would just add code complexity for no reason
like my point is I could optimize it and give you the 2 versions of the game, and you would never be able to guess not even after profiling the game, which version is the optimized one
@@lowlevelgamedev9330 WTF youtube. Not telling me that this comment was answered to.
I saw your second video and read these two comments.
But doesn't your answer proof my point in the first place? (Especially your second comment)
Yes when you only apply the optimization to "That part of the game" but nothing else you wouldn't notice it.
But if you repeat the sentiment you are suggesting you run in the exact issue because it is a death of 1000 needles.
There are simple optimizations that have barely any complexity increase in them but lets you early out of an rather complex check in the first place then you gain a lot without investing a lot.
And your argument that "I have worse systems to invest", kinda proofs that point in the first place.
I don't argue that you shouldn't micro optimize, and that is true, but your cases and the example shown on both sides proof the point that i am making is right.
Yes PCs are fast to have 1-2-3 or 15 slow systems. But after a certain point you will be caught up by your "its fast enough" suggestion.
And that clearly happend due to your argumentation.
Anyways. I think microoptimization isn't a good idea in the beginning, but early outs and optimized design choices (aka using sets instead of lists for checking if something is inside) should be at least applied.
Small note:
I hope you wouldn't think that I am a beginner.
I am just more into optimization than the average coder :)
Also what i am making a optimization can be the difference between a 45GB file and a 2-4GB file :)
finally, minecraft jedrock edition
minecraft c++ edition
@@NovaCraftRealest that's called minecraft bedrock lmao
@@darkfllamewas just gonna say that
Imi place directia in care iei jocul
Why make 2 functions that do the same thing, craft4 and craft9 should easily be made into one, either with a switch case + argument with enum like CraftingType::Inventory and CraftingType::Bench or pass the argument of 4 and 9 based on whether player inventory is open or not if the player is crafting for (int i = 0; i < arg; i++), or if you want to do it the ugly/fast way just check if player inventory is open or not that way you can figure out whether it's a crafting bench (9 slots) or inventory crafting (4 slots), plus on top of that I saw that you do Item(); in the recipe thing (also misspelt recepie), why allocate a whole ass structure that does nothing instead of passing NULL as a sign of "nothing", seems like a waste of memory and additional performance that could be gained(unless im wrong).
Also IDK why you would want to know on which slot everything is in the player's inventory, seems like a HUGE waste of bandwidth especially for those on metered connections, it would make much more sense if you did all the inventory sorting on client side as long as the items+count match on server-client there shouldn't be a problem at all, you could just make whatever inventory QoL stuff you want to execute on the client strictly in the client code, and execute those functions by communication via packets, this seems like a much friendlier approach for the overall performance of the server, this way u keep the security of cheating and also offload the sorting and stuff to the actual player/client, so you avoid doing unnecessary stuff on the server, could even save the order in a json file or something on the client cache folder, imho when you do the chest inventories and other stuff you could also make better decisions than minecraft like doing caching on both client and server, for example if u don't do anything with the inventory - no updates whatsoever, then you avoid sending useless packets to server, like minecraft does when you open an inventory even if you don't do anything you are sending useless packets.
ok so to answer the first function, I have 2 functions craft 4 and craft 9, but craft 4 reuses craft 9, so it is just for convinience. Keep in mind that I take an array of 4 and an array of 9 elements, to call this functions, and the memory ordering is not the same, so craft 4 takes that elements and rearanges them to call craft 9 corectly. For optimization related things, in order to pass null I would need to take pointers to those elements, and that can cause other problems and indirections that can cause in the end maybe even performance problems. Regardless, this system is not worth optimizing, it is very fast as it is, I don't think you could even measure its cost, the game runs even in debug mode at 60 fps, the bottleneck is the gpu stuff and chunk building. So what matrers most here is how well I am able to maintain this system. And how it id right now it is quite convinient to work with
and for the second question, I wanted to do that but you can't really do it. Imagine closing the game, the server needs to know how to save your inventory exactly, also because of the example that I showed in the video. So the server needs to know exactly my inventory. This is not really a problem tho, keep in mind that I send a packet only when I move an item, and that packet is actually very small, like it doesn't have the whole item data in it. And I don't send packets when nothing changes.
to put it simply, what you are sugesting works on paper but if you try to do it, you will see that there will be many problems, the server needs to be able to do a lot of things, so in the end you can't get away with it not knowing your state. The server decides if I take items because otherwise, if the client needs to decide that, I need to add a ton of logic to accunt for undoing an illegal item take (if someone else took it before you)
Oooo nice!!!
Now make minecraft client that can connect to minecraft servers. Like uis246/AltCraft
How fast is the startup time? (I wonder because it takes forever with Java version)
honestly it is pretty fast, in a few secconds you are in the game
@@lowlevelgamedev9330 I am impressed of your work, very good. I wish more people that are aspiring to become game developers could watch this just so people could understand why coding close to the metal is always going to be the optimum for making games running fast and efficient. Keep up the good work.
are you a Romanian?
You made a typo in the description. Line 1 last word. Cline => Clone
how i dowload
is your camera position wrong?
I don't think so, the fov is wierd tho, I'll change it
@@lowlevelgamedev9330 alright, I can't wait to see what it looks like!
You better work on the lighting next or ima crash out 🙏🏿 👅
TODO(you): Fix typo "recepie" -> "recipe"
1:52 Jesus christ, that will end in 100s of if-else... you need a mpre generic way
I thought of that but the solution isnt really much better, and it is way slower, so if chains will remain for now. They are also very fast as you will see in today's video
I'd recommend installing a spellchecker into your code editor. That way you'll automatically learn better English writing while coding.
that would not be a bad idea, tho I don't really like the idea of it
@@lowlevelgamedev9330 I'm recommending it, because I'm always spotting spelling errors when you show code on screen 😅
@@lowlevelgamedev9330 That would be an extremely bad idea. My Codeeditor suggests words and when I use a word from german or something else the code editor goes crazy and tries to correct me which is annoying af
esti Român frate?
foarte posibil 👀
impossible level 😦😦
Using C++ but not using classes with inheritance for the Item data structure? Kinda sus
I mean I don't see why should I do that, an item is just an int. And sure polymorphism sounds cool but than I need to alocate all the items on the heap to use them so no thank you. I can just do that like I currently do it
server don't really need to know where item is located, bad networking programming detected
than how will the server save your inventory lol? Also its easier to do this and than the server can handle item pickup than pick the item up myself and than undo that. Also how can the server know if it is possible for me to pick up an item since the arangement of the inventory items matters
@@lowlevelgamedev9330 when you exit game, server saves items with their positions. arrangement of the inventory don`t matter since you can only pick items that in your inventory.
good luck having more than 10 players without lags with current networking style
Your implementation of networking won't be as cross platform as you'd like as it doesn't respect endianness nor the sizes of primitives (you send the struct raw data)
You could at the very least use fixed size types like std::uint8t so that it would be usable on a x32 machine architecture
so first of all, the game wouldn't work on a x32 bit machine :))) You need a decent gpu to play it. So I don't really care about little endian, is there any modern desktop architecture that uses big endian?
@@lowlevelgamedev9330 Didn't think about the GPU ! True for the endianness, there isn't much computers still using it to this day.
I was more thinking about aligns and types size but if you keep a single version of it on a same architecture I guess that's fine !
Really was nitpicking lol, great project anyway !
Something that Minecraft does under the hood that you might want to steal is that the inventory has a Cursor slot to store items you picked up with the mouse. If you close the inv, if the inv closes because someone broke the source block or you die, items in the cursor slot drop to the ground.
yess, I actually have that, I just have to add the drop to the ground part when you close the inventory
fix your hand bruv and the fov
ye I will fix that in the next video
cまけ
I have a feeling I know what that means 😂😂
@@lowlevelgamedev9330 cmake
second
10th comment
Books can be used to "break" Minecraft for item duping. I would just not implement books altogether. There's only a marginal use for them anyway
Can't you just do it right?
I mean yes but I still need to add various items metadata things like enchantments. So I supppse I will add books why not but with a smaller text size, and I'll see how it goes
@@lowlevelgamedev9330 yeah, smaller text size would work
@@trashtrash2169 no. Why would you ever even suggest that?
@@mansurbm_ Damn.