Jump to content

Recommended Posts

Posted

The registry events are preferred, but I noticed this:

 

https://github.com/Corgam/1.12/blob/master/src/main/java/corgam/slavicraft/items/_Items.java#L30

You use the ModelLoader (the more-correct method) here

https://github.com/Corgam/1.12/blob/master/src/main/java/corgam/slavicraft/blocks/_Blocks.java#L47

But use the ModelMesher (the absolutely-worst method) here.

 

WHY. Why would you mix these two methodologies together?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
  On 7/4/2017 at 7:10 PM, diesieben07 said:

Items must be registered in RegistryEvent.Register<Item>, item models must be registered in ModelRegistryEvent.

Expand  

And how do I use registry events exactly? I would love to see an example, it would help me a lot.

  • 2 weeks later...
Posted

Ok, I after one week break I tried to get it working, but still there is something wrong and I need help to understand it better.

 

Here are my files: 

 

EventHandler class:

  Reveal hidden contents

 

_Items class (ModItems):

  Reveal hidden contents

 ItemBlankRune class (class of the item that I try to get the texture working)(extends SlavicraftItem)

  Reveal hidden contents

SlavicraftItem class

  Reveal hidden contents

 

Posted
  On 7/18/2017 at 9:55 AM, Corgam said:

but still there is something wrong and I need help to understand it better.

Expand  

You missed the @EventBusSubscriber annotation at the top of your Event Handler class. AKA

@EventBusSubscriber
public class EventHandler...

 

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted (edited)
  On 7/18/2017 at 10:04 AM, Animefan8888 said:

You missed the @EventBusSubscriber annotation at the top of your Event Handler class. AKA

@EventBusSubscriber
public class EventHandler...

 

Expand  

I added it, but the texture only works when I reload resource packs (F3 + T) and I don't have a clue why.

(btw, what is the difference between @Mod.EventBusSubscriber and @EventBusSubscriber ? )

Edited by Corgam
Posted
  On 7/18/2017 at 10:29 AM, Corgam said:

I added it, but the texture only works when I reload resource packs (F3 + T) and I don't have a clue why.

(btw, what is the difference between @Mod.EventBusSubscriber and @EventBusSubscriber ? )

Expand  

Nothing, @Mod.EventBusSubscriber is just the whole name. EventBusSubscriber is within the Mod annotation class. Also you need to register your Items and Blocks in the RegistryEvent.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted (edited)

Here you go: https://github.com/Corgam/Items-problem

I tried to add:

 

@SubscribeEvent
    public void registerItems(RegistryEvent.Register<Item> event) {   
        _Items.register();
    }

 

But the game crashes: (there are also some other mods, but I think they don't interfere at all)

  Reveal hidden contents

 

Edited by Corgam
Posted
  On 7/18/2017 at 10:59 AM, Corgam said:

@SubscribeEvent
    public void registerItems(RegistryEvent.Register<Item> event) {   
        _Items.register();
    }

Expand  

This is not the proper way to register them. You must do event.getRegistry().register...

  • Like 1

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted
  On 7/18/2017 at 11:05 AM, Animefan8888 said:

This is not the proper way to register them. You must do event.getRegistry().register...

Expand  

so is this good?

 

@SubscribeEvent
    public void registerItems(RegistryEvent.Register<Item> event) {
        event.getRegistry().registerAll(***);
    }

And what do I write in *** blank ?

 

Posted (edited)
  1. Register methods must be static.
  2. You put what you register ;). You can create new items right in that event and then take them from @ObjectHolder class later, or do some form of storage (array, separate instances).
  3. To keep code clean, it's better to move your model registries into the model RegisterHandler and completely get rid of _Items class.
Edited by MrBendelScrolls
  • Like 1
Posted (edited)

I managed to get everything working, thanks! :D

(now I only need to write something to it to handle more items)

Are there benefits of using @ObjectHolders or arrays?

Here is code for others with the same problem to look at:

 

RegisterHandler class:

  Reveal hidden contents

 

Edited by Corgam
Posted
  On 7/18/2017 at 11:45 AM, Corgam said:

Are there benefits of using @ObjectHolders or arrays?

Expand  

@ObjectHolder as far as I know don't really have advantages or disadvantages in this case. Instead of an array I suggest a ArrayList. That way you have access to List#add. Also you will need to move your ModelRegistryEvent to another class or it will crash the dedicated server as it is a Client side only class. You also will need to put @SideOnly(SIde.CLIENT) at the top of your class.

  • Like 1

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted
  On 7/18/2017 at 12:02 PM, Animefan8888 said:

Also you will need to move your ModelRegistryEvent to another class or it will crash the dedicated server as it is a Client side only class. You also will need to put @SideOnly(SIde.CLIENT) at the top of your class.

Expand  

Helpful tips, thanks! :) 

Posted (edited)
  On 7/18/2017 at 12:02 PM, Animefan8888 said:

Also you will need to move your ModelRegistryEvent to another class or it will crash the dedicated server as it is a Client side only class. You also will need to put @SideOnly(SIde.CLIENT) at the top of your class.

Expand  

Isn't forge smart enough to call the method with ModelRegistryEvent on the client only?
I didn't have any problems with this being in the common class.
And, isn't @SideOnly kind of... "forbidden"?

Edited by MrBendelScrolls
  • Like 1
Posted (edited)
  On 7/18/2017 at 1:41 PM, MrBendelScrolls said:

Isn't forge smart enough to call the method with ModelRegistryEvent on the client only?
I didn't have any problems with this being in the common class.

Expand  

That has nothing to do with it. 

Pretend you are the JVM. When you load a class you need to check that the class contains valid code. Ie that every referenced class with its already loaded or can be found and loaded if it is needed. 

 

The JVM cannot predict whether or not a given method will execute, so it assumes that all of them will at some point. 

 

The JVM scans through your class, finds a reference to a ModelRegistryEvent, attempts to locate this class, and fails to do so.

Edited by Draco18s
  • Like 2

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

The problem is that all the client stuff isn't available on server. Should a server try to run a class that contains client code (even if its not directly executed) it will crash in almost all cases.

 

I would run a setup with two classes, a YourModItems class and a ClientRendererItems class.

YourModItems has a list of all your items and a method to register them that is started by the common proxy. Your ClientItemRenderer has a function that loops through all your items in the YourModItems class and registers the rendering stuff for them.

  • Like 1

Here could be your advertisement!

Posted (edited)
  On 7/18/2017 at 1:41 PM, MrBendelScrolls said:

Isn't forge smart enough to call the method with ModelRegistryEvent on the client only?
I didn't have any problems with this being in the common class.

Expand  

Yes, and I misspoke ModelRegistryEvent is not the Client Side only class (at least it is not marked with @SideOnly(Side.CLIENT)), but ModelLoader is. And if you compile a Common or Server class with ModelLoader referenced in it it will crash with a "Class Not Found Exception". Seeing as how the class doesn't exist in the servers files. 

Edited by Animefan8888
  • Like 1

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted
  On 7/18/2017 at 1:41 PM, MrBendelScrolls said:

Isn't forge smart enough to call the method with ModelRegistryEvent on the client only?
I didn't have any problems with this being in the common class.
And, isn't @SideOnly kind of... "forbidden"?

Expand  

Yes, Forge is - it will only call the method on the client. But like draco said, the JVM isn't clever enough to know the method won't get called, so it crashes as soon as it finds a reference to a nonexistent class.

 

You won't have any problems when you run code like that on the physical client because all the referenced classes are present - it's only the server that will crash.

 

@SideOnly isn't forbidden, it's just that it needs to be used correctly. People get mixed up about the difference between logical and physical sides - @SideOnly applies to physical sides.

  • Like 1
Posted
  On 7/18/2017 at 2:39 PM, MrBendelScrolls said:

However, no matter how hard I tried, I couldn't make it crash a single time

Expand  

I don't believe the crash will happen in a development environment possibly because the classes marked with @SIdeOnly(Side.CLIENT) still get compiled though that may just be me thinking wildly.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.