Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hi guys,

 

So I have a problem which I cannot wrap my head around.

 

To give you an idea of how my code works, I'll show you how I register my items (which works).

 

When I register an item, I use the following to do so:

 

public void register(CTBasicItem item, String id, String type) {
    this.setUnlocalizedName(Reference.resource.PREFIX + id);

    registerTexture(item, id, type);

    GameRegistry.registerItem(item, id);
}

private void registerTexture(CTBasicItem item, String id, String type) {
    ModelLoader.setCustomModelResourceLocation(item, 0,
			new ModelResourceLocation(Reference.resource.PREFIX +
					"items/" + type + "/" + id,
					"inventory"));

}

 

As previously mentioned, when using the above code on an item, it works perfectly.

Reference.resource.PREFIX = comtech + ":"

"items/" is the subdirectory of "item"

"type" is the subdirectory of "items". (could be dusts/ or ingots/, etc)

 

However if I change the registerTexture to:

 

private void registerTexture(CTBasicBlock block, String id, String type) {
	ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), 0,
			new ModelResourceLocation(Reference.resource.PREFIX +
					"blocks/" + type + "/" + id,
					"inventory"));

}

 

And try to run minecraft, it crashes... it crashes hard with the following error:

 

 

 

Time: 29/02/16 17:05
Description: Initializing game

java.lang.NullPointerException: Initializing game
at com.jamierhys.comtech.blocks.base.CTBasicBlock.registerTexture(CTBasicBlock.java:49)
at com.jamierhys.comtech.blocks.base.CTBasicBlock.register(CTBasicBlock.java:36)
at com.jamierhys.comtech.blocks.ores.Ore_Aluminium.<init>(Ore_Aluminium.java:17)
at com.jamierhys.comtech.blocks.ores.ModOres.init(ModOres.java:36)
at com.jamierhys.comtech.blocks.init.ModBlocks.init(ModBlocks.java:16)
at com.jamierhys.comtech.proxy.ClientProxy.preInit(ClientProxy.java:21)
at com.jamierhys.comtech.main.ComTechMain.preInit(ComTechMain.java:40)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:560)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
at com.google.common.eventbus.EventBus.post(EventBus.java:275)
at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:211)
at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:189)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
at com.google.common.eventbus.EventBus.post(EventBus.java:275)
at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:118)
at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:556)
at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:243)
at net.minecraft.client.Minecraft.startGame(Minecraft.java:451)
at net.minecraft.client.Minecraft.run(Minecraft.java:360)
at net.minecraft.client.main.Main.main(Main.java:116)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
at GradleStart.main(GradleStart.java:26)


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Stacktrace:
at com.jamierhys.comtech.blocks.base.CTBasicBlock.registerTexture(CTBasicBlock.java:49)
at com.jamierhys.comtech.blocks.base.CTBasicBlock.register(CTBasicBlock.java:36)
at com.jamierhys.comtech.blocks.ores.Ore_Aluminium.<init>(Ore_Aluminium.java:17)
at com.jamierhys.comtech.blocks.ores.ModOres.init(ModOres.java:36)
at com.jamierhys.comtech.blocks.init.ModBlocks.init(ModBlocks.java:16)
at com.jamierhys.comtech.proxy.ClientProxy.preInit(ClientProxy.java:21)
at com.jamierhys.comtech.main.ComTechMain.preInit(ComTechMain.java:40)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:560)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
at com.google.common.eventbus.EventBus.post(EventBus.java:275)
at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:211)
at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:189)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
at com.google.common.eventbus.EventBus.post(EventBus.java:275)
at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:118)
at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:556)
at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:243)
at net.minecraft.client.Minecraft.startGame(Minecraft.java:451)

-- Initialization --
Details:
Stacktrace:
at net.minecraft.client.Minecraft.run(Minecraft.java:360)
at net.minecraft.client.main.Main.main(Main.java:116)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
at GradleStart.main(GradleStart.java:26)

 

 

 

Now I can see there is a nullpointerexception but I cannot figure out how to fix it...

 

Anyone got any ideas?

ModelLoader

and

ModelResourceLocation

are client-only classes. If you register models from common code instead of from your client proxy, you'll crash the dedicated server.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

  • Author

ModelLoader

and

ModelResourceLocation

are client-only classes. If you register models from common code instead of from your client proxy, you'll crash the dedicated server.

 

That isnt the problem, the call for that IS coming from the client proxy and not my common proxy.

 

 

Register the block with the GameRegistry first, otherwise getItemFromBlock will not work.

 

That worked and now minecraft is launching. But I'm still having an issue with it not finding my .json files.

 

I want to use a custom path in my blockstates... see below to how I want it.

 

Here's my file structure:

 

|---blockstates/

|                        |---- blocks/

|                                          |--- ores/

|                                                        |--- ore_aluminium.json

|

|---- models/

                  |--- block/

                  |              |--- blocks/

                  |                              |--- ores/

                  |                                            |--- ore_aluminium.json

                  |

                  |--- item/

                                |--- blocks/

                                                |--- ores/

                                                              |--- ore_aluminium.json

 

As you can see I want my ores in blockstates/blocks/ores/  but the only problem is that unless it's in just blockstates, it won't work... is there a way to tell forge to look there instead?

ModelLoader

and

ModelResourceLocation

are client-only classes. If you register models from common code instead of from your client proxy, you'll crash the dedicated server.

 

That isnt the problem, the call for that IS coming from the client proxy and not my common proxy.

 

The code you posted shows

registerTexture

being called in the same method as

GameRegistry.registerItem

. Do you have a separate registration method for the dedicated server?

 

I realise it's not causing the issue that this thread is about, but it will cause issues if you don't separate client-only code properly.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.