Jump to content

Recommended Posts

Posted

Hey guys,

I'm having some problems getting some subBlocks to work properly. At them moment I have everything working texture and render-wise for when the blocks is in the inventory. But as soon as I place them, they just show up as the purple/black blocks.

 

I use this code to set a resource location for each subBlock

Item leaf = Item.getItemFromBlock(myBlocks.leaves);
ModelBakery.registerItemVariants(leaf, new ResourceLocation("em:leaves_maple"), new ResourceLocation("em:leaves_poplar"));

 

But I think that only adds a resource location for the item. And the block itself still doesn't know where to look for it's resource. I'm having a hard time figuring out how to fix this, maybe someone here knows what to do, and can help me. :)

Posted

You have to call ModelLoader.setCustomModelResourceLocation to actually bind the model. registerItemVariants simply tells the game "hey, I am going to use this model at some point, please make sure it's loaded". setCustomModelResourceLocation includes registerItemVariants, so no need to call it yourself.

 

Okay, so just to be sure. I should replace the registerItemVariants with this?

ModelLoader.setCustomModelResourceLocation(leaf, 0, new ModelResourceLocation("em:leaves_maple"));
ModelLoader.setCustomModelResourceLocation(leaf, 1, new ModelResourceLocation("em:leaves_poplar"));

 

And is that all?

 

I can't seem to get this to work at all

Posted

If you don't specify a variant for the ModelResourceLocation it will use "normal". If you want the game to simply load an item model (without creating a blockstates file) you need to use "inventory" as the variant.

 

I appreciate your help, but I just can't get this to work. I strongly believe that I'm doing something wrong, but I have been working with this problem most of the day. So I can't really concentrate any more, so I will get back to it tomorrow, maybe the issue will just pop up. But after looking at it a bit closer, I can see that the code is looking a lot like the code I use for registering.

public static void registerSubBlocksRender(Block block, int meta, String name)
{
Item item = Item.getItemFromBlock(block);
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, meta, new ModelResourceLocation(Reference.MOD_ID + ":" + item.getUnlocalizedName().substring(5) + "_" + name, "inventory"));
}

 

Maybe they do the same thing? I really don't know at this point.

Posted

That is a horrible way to do it.

The

ItemModelMesher

is deprecated, you should be using

ModelLoader

like I mentioned above. Note that as opposed to the

ItemModelMesher

it must be called in preInit.

Moreover please don't use the unlocalized name for the model name.

Really, all you need is:

new ModelResourceLocation(myItem.getRegistryName(), "inventory")

 

I just tried to do what you suggested, and now everything is fucked xD

None of my block have any textures, should I be using .setRegistryName() instead of .setUnlocalizedName() on my blocks aswell.

Sorry for being such a huge noob, right now. It's just that the other way have always worked for me without any problems, and most tutorials I have seen seems to be doing the same thing. So I have actually never used .getRegistryName()

Posted

Well, getRegistryName only works if you name your models the same as the registry name of your block (you know what that is, right?).

You should either be using

GameRegistry.register(<thing>, <resourcelocation>)

or

<thing>.setRegistryName; GameRegistry.register(thing)

. Everything else should either be crashing or produce a deprecation warning.

I believe I got it now, but I will have to do it tomorrow. But once again thanks for your help, I hope I can get it to work now :)

Posted

Well, getRegistryName only works if you name your models the same as the registry name of your block (you know what that is, right?).

You should either be using

GameRegistry.register(<thing>, <resourcelocation>)

or

<thing>.setRegistryName; GameRegistry.register(thing)

. Everything else should either be crashing or produce a deprecation warning.

 

This might be a silly question, but can the unlocalized name and the registry name be the same? Or do they have to be different?

Posted

They can be the same.

Okay, so I have managed to get this to work with all my items. But for some reason the game crashes when I do it with my blocks. Is there something special that I need to do for blocks?

 

Here's the crash report

 

---- Minecraft Crash Report ----

// Don't be sad, have a hug! <3

 

Time: 26-06-16 00:48

Description: Initializing game

 

java.lang.NullPointerException: Initializing game

at erfurt.eadore.init.EadoreBlocks.registerRenderTest(EadoreBlocks.java:135)

at erfurt.eadore.init.EadoreBlocks.registerRenders(EadoreBlocks.java:94)

at erfurt.eadore.proxy.ClientProxy.preInit(ClientProxy.java:25)

at erfurt.eadore.EadoreMod.preInit(EadoreMod.java:31)

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:561)

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:228)

at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:206)

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:135)

at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:584)

at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:249)

at net.minecraft.client.Minecraft.startGame(Minecraft.java:472)

at net.minecraft.client.Minecraft.run(Minecraft.java:381)

at net.minecraft.client.main.Main.main(Main.java:118)

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 erfurt.eadore.init.EadoreBlocks.registerRenderTest(EadoreBlocks.java:135)

at erfurt.eadore.init.EadoreBlocks.registerRenders(EadoreBlocks.java:94)

at erfurt.eadore.proxy.ClientProxy.preInit(ClientProxy.java:25)

at erfurt.eadore.EadoreMod.preInit(EadoreMod.java:31)

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:561)

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:228)

at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:206)

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:135)

at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:584)

at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:249)

at net.minecraft.client.Minecraft.startGame(Minecraft.java:472)

 

-- Initialization --

Details:

Stacktrace:

at net.minecraft.client.Minecraft.run(Minecraft.java:381)

at net.minecraft.client.main.Main.main(Main.java:118)

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)

 

-- System Details --

Details:

Minecraft Version: 1.9

Operating System: Windows 10 (amd64) version 10.0

Java Version: 1.8.0_77, Oracle Corporation

Java VM Version: Java HotSpot 64-Bit Server VM (mixed mode), Oracle Corporation

Memory: 630649160 bytes (601 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB)

JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M

IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0

FML: MCP 9.23 Powered by Forge 12.16.1.1887 4 mods loaded, 4 mods active

States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored

UCH mcp{9.19} [Minecraft Coder Pack] (minecraft.jar)

UCH FML{8.0.99.99} [Forge Mod Loader] (forgeSrc-1.9-12.16.1.1887.jar)

UCH Forge{12.16.1.1887} [Minecraft Forge] (forgeSrc-1.9-12.16.1.1887.jar)

UCE em{1.0.b} [Eadore mod] (bin)

Loaded coremods (and transformers):

GL info: ' Vendor: 'NVIDIA Corporation' Version: '4.5.0 NVIDIA 368.39' Renderer: 'GeForce GTX 670/PCIe/SSE2'

Launched Version: 1.9

LWJGL: 2.9.4

OpenGL: GeForce GTX 670/PCIe/SSE2 GL version 4.5.0 NVIDIA 368.39, NVIDIA Corporation

GL Caps: Using GL 1.3 multitexturing.

Using GL 1.3 texture combiners.

Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported.

Shaders are available because OpenGL 2.1 is supported.

VBOs are available because OpenGL 1.5 is supported.

 

Using VBOs: No

Is Modded: Definitely; Client brand changed to 'fml,forge'

Type: Client (map_client.txt)

Resource Packs:

Current Language: English (US)

Profiler Position: N/A (disabled)

CPU: 4x Intel® Core i5-3570K CPU @ 3.40GHz

 

 

I use this code for registering render

public static void registerRender(Block block)
{
Item item = Item.getItemFromBlock(block);
ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(item.getRegistryName(), "inventory"));
}

Posted

That means there is no ItemBlock registered for the block.

 

I have made this method that creates the ItemBlock, as well as giving it the resourcelocation.

public static void registerBlock(Block block)
{
	GameRegistry.register(block);
	GameRegistry.register(new ItemBlock(block).setRegistryName(block.getRegistryName()));

	Item item = Item.getItemFromBlock(block);
	ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(item.getRegistryName(), "inventory"));
}

 

Now I kinda want to know how I can make similarly method for subBlocks?

 

What I have worked on, but it doesn't seem to work.

public static void registerSubBlock(Block block, int meta, String name)
{
	GameRegistry.register(block);
	GameRegistry.register(new ItemBlock(block).setRegistryName(block.getRegistryName()));

	Item item = Item.getItemFromBlock(block);
	ModelLoader.setCustomModelResourceLocation(item, meta, new ModelResourceLocation(item.getRegistryName() + "_" + name, "inventory"));
}

Posted

Why do you even register your block and it's model in the same method? These should be separate. The model registration must happen entirely in your ClientProxy (or other completely client-only classes).

 

I just thought it looked cleaner that way, but I have chanced it to be two different methods now, still doesn't work with the subBlocks.

 

These are my current methods in my block class

public static void registerBlock(Block block)
{
	GameRegistry.register(block);
	GameRegistry.register(new ItemBlock(block).setRegistryName(block.getRegistryName()));
}

public static void registerRender(Block block)
{
	Item item = Item.getItemFromBlock(block);
	ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(item.getRegistryName(), "inventory"));
}

public static void registerSubBlocksRender(Block block, int meta, String name)
{
	Item item = Item.getItemFromBlock(block);
	ModelLoader.setCustomModelResourceLocation(item, meta, new ModelResourceLocation(item.getRegistryName() + "_" + name, "inventory"));
}

 

And this is how my client-proxy class looks like

public class ClientProxy extends CommonProxy
{
@Override
public void preInit()
{
	myItems.init();
	myItems.register();
	myBlocks.init();
	myBlocks.register();

	registerRenders();
}

@Override
public void init()
{

}


@Override
public void registerRenders()
{
	myItems.registerRenders();
	myBlocks.registerRenders();
}

Posted

What is the issue now?

 

Well I have a few issues right now. First is that my subBlocks, seem to have the same name, so my lang file doesn't work anymore. Second is that the subBlocks still doesn't render when placed, but is rendered as items, in the inventory.

 

I use the methods I mentioned above for the registering, I believe that I need to do something with the unlocalized names. Not sure how to do it at this time, but I will be working on that.

 

I know you most be frustrated with me at this point, at least I would be... But I am learning a lot from this, so thank you :)

Posted

Unlocalized names are handled via a custom ItemBlock.

 

I got that working now. Just one last thing, it doesn't want to render the blocks... I don't understand why that is, as I have done everything you told me to. Most be something I do with my json files, only thing I can think might be the problem

Posted

  • This has to happen in preInit.
  • Why is this not happening on the server as well?

 

Now to your sub-model stuff. You are specifying "normal" as the variant. This means that the game will not even look into models/item. It will go straight for the blockstates file, which in this case fails, since they don't have a "normal" variant. I recommend you simply get rid of the models in models/item (no need to have them twice) and specify a variant that is actually present in the blockstates json.

 

Okay, so I've done some changes now, but it doesn't seem to work.

 

Just to be sure that I have got this right. This is how my blockstate files should look like, when I use ModelLoader.setCustomModelResourceLocation(item, meta, new ModelResourceLocation(item.getRegistryName() + "_" + name, "normal")) in my block class, right?

{
    "variants": {
        "normal": { "model": "em:planks_maple" }
    }
}

 

BTW how do I specify a variant like "normal" for logs and walls, as their json files are somewhat different.

 

Vanilla json for acacia log

{
    "variants": {
        "axis=y":  { "model": "acacia_log" },
        "axis=z":   { "model": "acacia_log", "x": 90 },
        "axis=x":   { "model": "acacia_log", "x": 90, "y": 90 },
        "axis=none": { "model": "acacia_bark" }
    }
}

Vanilla json for cobblestone wall

{
    "multipart": [
        {   "when": { "up": "true" },
            "apply": { "model": "cobblestone_wall_post" }
        },
        {   "when": { "north": "true" },
            "apply": { "model": "cobblestone_wall_side", "uvlock": true }
        },
        {   "when": { "east": "true" },
            "apply": { "model": "cobblestone_wall_side", "y": 90, "uvlock": true }
        },
        {   "when": { "south": "true" },
            "apply": { "model": "cobblestone_wall_side", "y": 180, "uvlock": true }
        },
        {   "when": { "west": "true" },
            "apply": { "model": "cobblestone_wall_side", "y": 270, "uvlock": true }
        }
    ]
}

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.