I have two versions of essentially the same code, which I modified from zdoctor's code on adding custom plants to the game. Plants1 (https://github.com/TheWebExpert1/plants1) gives me an error (https://pastebin.com/RzGZrdSK), but it works -- the plants, seeds, everything. Plants2 (https://github.com/TheWebExpert1/plants2) does NOT give me the error, but neither does it give me a texture for the plant seeds. I want this to work, without errors.
Hey, I am not too good at coding, but I am guessing you are on 1.12? If you are not getting an error, than the line of code setting the texture is not running. Also, the problem can be that you are not setting the texture path correctly. The path should be: "Modid:Textures/Items/ItemName" If those are not the problem, then I don't know.
Yes, 1.12. Essentially, the path to the texture is right, afaik; it's just not showing up. With the error, the texture is showing up, but I'm getting an error. I want to eliminate the error, but keep the texture.
1. The code in you first repo is (no offense) seriously unorganized, unoptimized and cluttered. It's really hard for me to read. You really need to work on it. I haven't even looked at the second.
2. Your error is saying that forge/minecraft cannot find a model named strawberrycrop for your strawberry seeds item. You need to create a json model that matches the item's registry from meta name (because you that's what you're doing in your registerItemModels method).
Actually, there SHOULDN'T be an item with that name; the other repo uses EXACTLY the same code (for creating models) and yet produces NO error.
Unorganized: I thought it was pretty well organized, myself; I have each of the classes together in packages whose names make sense, organized by type. If there's a better way to organize the files, I would ABSOLUTELY like to know - after all, I'm striving for better!
Unoptimized: I'm not entirely certain what you mean by this; how do you go about optimizing the code? Please remember: over 90% of this code isn't even mine to start with; I had to take two different repos and put them together, then remove everything that wasn't relevant to what I wanted to do. There are a lot of things I wished I could combine (one class instead of two, or two instead of three); my attempts to do so were unsuccessful.
Cluttered: Personally, I don't see it; please give me an example of a "cluttered" section, and then your suggestion to unclutter it. As always, I am open to your comments and suggestions. You definitely know more than I do; I'm still learning.
You have to understand that almost blindly copying other people's code will not do anything for you. You must either understand what you're copying or not copy anything and do it on your own to actually learn.
Here's a break down of what you're doing wrong and some things that could be done better:
In short, it's best to split your mod into 3 packages: client, common and server. Things that are shared across the server and client (like items, blocks, etc) go into the common package. Things that are exclusive to either client or server (like models on the client) go into the corresponding packages.
Also I saw a lot of your code cluttered into one class (like in your registry class). I like to spread my code into related classes.
2. By unoptimized code I mean its effectiveness and its readability.
For example, I noticed you were iterating through a separate item list to register items in your registry class.
As for readability, you're doing a lot of unnecessary things your code. Examples from what I noticed are: many useless references (like saving the forge registry to a separate local variable, etc), useless code (like registering your item into a separate list in your registry class, getting the resource domain from registry names, interfaces/classes like Registration, etc), just generally long code that can easily be shortened. I also saw that you re-implement a lot of things vanilla has already done better than you (like crops, seeds). If you want to change some specific things then just extend a vanilla class and override/add something you need.
3. The code is also hard to read because it's very cluttered. Code (especially methods) is crammed together without any space between, curly brackets are misplaced, however this is quite trivial. And as stated above lots of code (methods, fields) are kept in completely unrelated classes (such as applying potion effects in your registry class, etc).
I'm going to publish my latest mod to github soon and I'll send you the link so you could take a look at how I structure my mods.
I think I understand part of what you're saying. Actually, I quite agree with you on the reimplementation issue and huge question marks on the code itself. 90% of what you're talking about is the code that I copied from this other person. I copied it because it WORKED. I wanted to add plants and seeds to my mod; he had working plants and seeds for 1.12; therefore, I copied his code. Now, I didn't change much -- there were things I *wanted* to change (i.e., combining two classes into one), but couldn't and things that I wondered about.
I would prefer to completely remove this code and replace it with something better - but I have yet to find either a piece of code or a tutorial that will work with 1.12. As always, I'm open to suggestions.
I've posted the full error at https://pastebin.com/pdN3EQGL in case it makes any difference. As I said, the OTHER version of the code works without the error, but has an issue with the textures for the seeds.
All in all, I'd much rather have a tutorial showing how to add plants & seeds - so I can LEARN the principles. Failing that, a working set of code I can add into my mod is fine; I read the code I copy in, trying to comprehend what it's doing & why.
I don't understand why people rely on tutorials so much. I think that looking at the vanilla code is really a no-brainer (at least to me).
I did the searching for you and all you need to do is to extend BlockCrops and override/define some methods. There are examples in vanilla like BlockBeetroot, BlockCarrot, BlockPotato.
And remember that it's always a good idea to look at how vanilla does things.
No, no, no. That's now what I meant. You need to prioritize forge's system over vanilla's. After all that's what forge is for. Since forge doesn't have any plant systems, you need to turn to vanilla. Register your blocks and items with forge's RegistryEvents, but have your block extend vanilla's BlockCrops.
EDIT: Also, you were copying vanilla's system incorrectly. All items are registered inside the Item class, not Items.
Initialize your seeds item as a simple ItemSeeds class and your food item as an ItemFood class, no need to extend them and create separate classes.
Ok, I've updated my code. I'm registering the block the way I'd usually do so, and the same with the Food and the Seeds. They're all being registered the same way I've registered everything else. I get the texture for the seeds; but when I plant them, I get a crash (https://pastebin.com/N295XUeF).
When initializing your item you pass a block that hasn't been registered yet.
1. That's a bad way to register blocks and items. I already told you to use registry events. You need to subscribe a method to the RegistryEvent.Register<IForgeRegistryEntry> and use the event's getRegistry() method to register your items/blocks. To create an event handler mark your class with @Mod.EventBusSubscriber, then make your event method static and mark it with @SubscribeEvent.
2. You need to initialize your items/blocks during registry, because a few of Item's methods and parameters rely on registries. For example, the block you're passing in is not yet registered when the item is initialized, hence the crash.
Didn't I already tell you about registry events and how to structure your code/mod before/in previous threads?
Ok, I downloaded your git for weapons; it's very interestingly organized. The main problem I have is knowing a). where to put the block classes; b). where to put the item classes; and c). where to put the registration for those. The code you posted doesn't actually add blocks or items to the game, as far as I can tell.
I tried looking at your lockpick mod, but there's so many errors that I can't see the forest for the trees. I like the organization of the first mod; there's a lot there that makes sense to me. Could you please give me an example, using your framework, which adds a block and an item, so I can see where you're doing it? I think I understand the structure, but I don't want to screw things up.
I don't understand why you need to download a git to view it, that's what github is for. Or do I have to teach you to navigate github? Also, don't look at the locks mod, it's the oldest I have made and haven't updated.
Ok, so I don't have much of a framework going on and I'd say it's not very hard to figure out what's what. For each registry entry (e.g. blocks, items, sounds, etc) I have an entry list class (e.g. BlockList, ItemList, etc) which stores all the references for its entry and registers the entries as well as their models (if they need them). To call these list classes I have a common event handler where all the registry events are kept and fired by forge automatically. To register any models I have a client event handler where all models are registered during the ModelRegistryEvent.
As I said in my previous post, my latest mod doesn't have many items/blocks going on since I'm working on the framework/api at the moment. I, however, provided you with an older repo for my "Runic inscription" mod which is similar, but has more examples/content. Here's a direct link to my older mod's ItemList as an example (which you could easily find yourself if you took the time). I honestly urge you to try to understand the code without my help. I think it's really not that hard and I've explained most of it to you anyway.
After reviewing BOTH your examples (the old & the new), I figured out what you were doing, and so duplicated it (https://github.com/TheWebExpert1/newplants). I have (apparently) a berry, plus seeds, which (when planted) produce a plant. There's only ONE problem: The program isn't finding either the textures or the lang.us file. I'm pretty sure the path is correct (and there aren't any errors), but still ... no textures, no proper names. This is odd. I'm sure it's something simple, though. The plant seemed to work when I sprinkled it with bonemeal, so I'm guessing that only the textures are the problem.
If I can fix THIS, then the rest (porting over the rest of my code to this new structure) should be fairly easy.
1. Good job at copying my repo almost whole including my mod's name and my name. You didn't event bother removing comments I made to myself. You're ignoring everything I told you about copying code.
2. Still you're not registering blocks properly... I said so many times that you need to use RegistryEvents, not using ForgeRegistries (who even told you to do that?!?)
Again I'm telling your for the second time, that it's much safer to initialize items/blocks DURING REGISTRY.
3. I'm presuming you're using 1.12? 1.12 forces lowercase format for almost all resources (including lang), if not all.
4. As for the block textures, first off I want you to show me your console log. Also, I'm not quite sure how to create a json model for a crop type. Again as I said before, you'd be better off looking at how vanilla does this. You have to look in minecraft's jar file for the models. You won't always be able to rely on me/other people to break it down for you.
I have two versions of essentially the same code, which I modified from zdoctor's code on adding custom plants to the game. Plants1 (https://github.com/TheWebExpert1/plants1) gives me an error (https://pastebin.com/RzGZrdSK), but it works -- the plants, seeds, everything. Plants2 (https://github.com/TheWebExpert1/plants2) does NOT give me the error, but neither does it give me a texture for the plant seeds. I want this to work, without errors.
Can anyone help me with this??
Hey, I am not too good at coding, but I am guessing you are on 1.12? If you are not getting an error, than the line of code setting the texture is not running. Also, the problem can be that you are not setting the texture path correctly. The path should be: "Modid:Textures/Items/ItemName" If those are not the problem, then I don't know.
Yes, 1.12. Essentially, the path to the texture is right, afaik; it's just not showing up. With the error, the texture is showing up, but I'm getting an error. I want to eliminate the error, but keep the texture.
1. The code in you first repo is (no offense) seriously unorganized, unoptimized and cluttered. It's really hard for me to read. You really need to work on it. I haven't even looked at the second.
2. Your error is saying that forge/minecraft cannot find a model named strawberrycrop for your strawberry seeds item. You need to create a json model that matches the item's registry from meta name (because you that's what you're doing in your registerItemModels method).
Actually, there SHOULDN'T be an item with that name; the other repo uses EXACTLY the same code (for creating models) and yet produces NO error.
Unorganized: I thought it was pretty well organized, myself; I have each of the classes together in packages whose names make sense, organized by type. If there's a better way to organize the files, I would ABSOLUTELY like to know - after all, I'm striving for better!
Unoptimized: I'm not entirely certain what you mean by this; how do you go about optimizing the code? Please remember: over 90% of this code isn't even mine to start with; I had to take two different repos and put them together, then remove everything that wasn't relevant to what I wanted to do. There are a lot of things I wished I could combine (one class instead of two, or two instead of three); my attempts to do so were unsuccessful.
Cluttered: Personally, I don't see it; please give me an example of a "cluttered" section, and then your suggestion to unclutter it. As always, I am open to your comments and suggestions. You definitely know more than I do; I'm still learning.
Ok, I was wrong. I think the error is saying that there is no model for the strawberry crop's itemblock.
You have to understand that almost blindly copying other people's code will not do anything for you. You must either understand what you're copying or not copy anything and do it on your own to actually learn.
Here's a break down of what you're doing wrong and some things that could be done better:
1. You're not following conventions. Here's a forge documentation page about structuring your mod. The important part is the packaging and naming schemes.
In short, it's best to split your mod into 3 packages: client, common and server. Things that are shared across the server and client (like items, blocks, etc) go into the common package. Things that are exclusive to either client or server (like models on the client) go into the corresponding packages.
Also I saw a lot of your code cluttered into one class (like in your registry class). I like to spread my code into related classes.
2. By unoptimized code I mean its effectiveness and its readability.
For example, I noticed you were iterating through a separate item list to register items in your registry class.
As for readability, you're doing a lot of unnecessary things your code. Examples from what I noticed are: many useless references (like saving the forge registry to a separate local variable, etc), useless code (like registering your item into a separate list in your registry class, getting the resource domain from registry names, interfaces/classes like Registration, etc), just generally long code that can easily be shortened. I also saw that you re-implement a lot of things vanilla has already done better than you (like crops, seeds). If you want to change some specific things then just extend a vanilla class and override/add something you need.
3. The code is also hard to read because it's very cluttered. Code (especially methods) is crammed together without any space between, curly brackets are misplaced, however this is quite trivial. And as stated above lots of code (methods, fields) are kept in completely unrelated classes (such as applying potion effects in your registry class, etc).
I'm going to publish my latest mod to github soon and I'll send you the link so you could take a look at how I structure my mods.
EDIT: Here's my latest project on github. Here's an older mod of mine, which has more content as an example.
Here are some points I usually follow:
1. Always to try to make reusable code. If a package has reusable code I like to move that code to an "api" sub-package.
2. Always split code into different relevant classes.
3. Indicate that a class is an interface or abstract by placing an 'I' or 'A' behind their names.
4. Always try to make use of inheritance (extend).
I think I understand part of what you're saying. Actually, I quite agree with you on the reimplementation issue and huge question marks on the code itself. 90% of what you're talking about is the code that I copied from this other person. I copied it because it WORKED. I wanted to add plants and seeds to my mod; he had working plants and seeds for 1.12; therefore, I copied his code. Now, I didn't change much -- there were things I *wanted* to change (i.e., combining two classes into one), but couldn't and things that I wondered about.
I would prefer to completely remove this code and replace it with something better - but I have yet to find either a piece of code or a tutorial that will work with 1.12. As always, I'm open to suggestions.
I've posted the full error at https://pastebin.com/pdN3EQGL in case it makes any difference. As I said, the OTHER version of the code works without the error, but has an issue with the textures for the seeds.
All in all, I'd much rather have a tutorial showing how to add plants & seeds - so I can LEARN the principles. Failing that, a working set of code I can add into my mod is fine; I read the code I copy in, trying to comprehend what it's doing & why.
I don't understand why people rely on tutorials so much. I think that looking at the vanilla code is really a no-brainer (at least to me).
I did the searching for you and all you need to do is to extend BlockCrops and override/define some methods. There are examples in vanilla like BlockBeetroot, BlockCarrot, BlockPotato.
And remember that it's always a good idea to look at how vanilla does things.
I'll give that a shot.
I'm obviously missing something. My pastebin is at https://pastebin.com/7EThA5nJ and my code is at https://github.com/TheWebExpert1/newplants. The code is basically unmodified from the beetroot, but there's an error crashing, and I don't know what to do about it.
Looks like you're requesting an item that doesn't exist or isn't registered in your initialization. I can't help you more because your repo is empty.
Forgot to process the upload.
No, no, no. That's now what I meant. You need to prioritize forge's system over vanilla's. After all that's what forge is for. Since forge doesn't have any plant systems, you need to turn to vanilla. Register your blocks and items with forge's RegistryEvents, but have your block extend vanilla's BlockCrops.
EDIT: Also, you were copying vanilla's system incorrectly. All items are registered inside the Item class, not Items.
Initialize your seeds item as a simple ItemSeeds class and your food item as an ItemFood class, no need to extend them and create separate classes.
Ok, I've updated my code. I'm registering the block the way I'd usually do so, and the same with the Food and the Seeds. They're all being registered the same way I've registered everything else. I get the texture for the seeds; but when I plant them, I get a crash (https://pastebin.com/N295XUeF).
When initializing your item you pass a block that hasn't been registered yet.
1. That's a bad way to register blocks and items. I already told you to use registry events. You need to subscribe a method to the RegistryEvent.Register<IForgeRegistryEntry> and use the event's getRegistry() method to register your items/blocks. To create an event handler mark your class with @Mod.EventBusSubscriber, then make your event method static and mark it with @SubscribeEvent.
2. You need to initialize your items/blocks during registry, because a few of Item's methods and parameters rely on registries. For example, the block you're passing in is not yet registered when the item is initialized, hence the crash.
Didn't I already tell you about registry events and how to structure your code/mod before/in previous threads?
Please try to listen and do what I say.
Ok, I downloaded your git for weapons; it's very interestingly organized. The main problem I have is knowing a). where to put the block classes; b). where to put the item classes; and c). where to put the registration for those. The code you posted doesn't actually add blocks or items to the game, as far as I can tell.
I tried looking at your lockpick mod, but there's so many errors that I can't see the forest for the trees. I like the organization of the first mod; there's a lot there that makes sense to me. Could you please give me an example, using your framework, which adds a block and an item, so I can see where you're doing it? I think I understand the structure, but I don't want to screw things up.
I don't understand why you need to download a git to view it, that's what github is for. Or do I have to teach you to navigate github? Also, don't look at the locks mod, it's the oldest I have made and haven't updated.
Ok, so I don't have much of a framework going on and I'd say it's not very hard to figure out what's what. For each registry entry (e.g. blocks, items, sounds, etc) I have an entry list class (e.g. BlockList, ItemList, etc) which stores all the references for its entry and registers the entries as well as their models (if they need them). To call these list classes I have a common event handler where all the registry events are kept and fired by forge automatically. To register any models I have a client event handler where all models are registered during the ModelRegistryEvent.
As I said in my previous post, my latest mod doesn't have many items/blocks going on since I'm working on the framework/api at the moment. I, however, provided you with an older repo for my "Runic inscription" mod which is similar, but has more examples/content. Here's a direct link to my older mod's ItemList as an example (which you could easily find yourself if you took the time). I honestly urge you to try to understand the code without my help. I think it's really not that hard and I've explained most of it to you anyway.
After reviewing BOTH your examples (the old & the new), I figured out what you were doing, and so duplicated it (https://github.com/TheWebExpert1/newplants). I have (apparently) a berry, plus seeds, which (when planted) produce a plant. There's only ONE problem: The program isn't finding either the textures or the lang.us file. I'm pretty sure the path is correct (and there aren't any errors), but still ... no textures, no proper names. This is odd. I'm sure it's something simple, though. The plant seemed to work when I sprinkled it with bonemeal, so I'm guessing that only the textures are the problem.
If I can fix THIS, then the rest (porting over the rest of my code to this new structure) should be fairly easy.
1. Good job at copying my repo almost whole including my mod's name and my name. You didn't event bother removing comments I made to myself. You're ignoring everything I told you about copying code.
2. Still you're not registering blocks properly... I said so many times that you need to use RegistryEvents, not using ForgeRegistries (who even told you to do that?!?)
Again I'm telling your for the second time, that it's much safer to initialize items/blocks DURING REGISTRY.
3. I'm presuming you're using 1.12? 1.12 forces lowercase format for almost all resources (including lang), if not all.
4. As for the block textures, first off I want you to show me your console log. Also, I'm not quite sure how to create a json model for a crop type. Again as I said before, you'd be better off looking at how vanilla does this. You have to look in minecraft's jar file for the models. You won't always be able to rely on me/other people to break it down for you.