Jump to content

[1.17.1] Rendering item of a block with texture in a subfolder not working


MyNameIsJan

Recommended Posts

Hello,

when I try to render an item for a block it complains that it can't find the texture. The block is rendered fine and working but the item seems to be unable to find the texture. If the texture is NOT in a subfolder it's working for the item too.

Here some screenshot I think are helpful to get a clear view of what I have.

Here is where the item of the block get its texture:

image.thumb.png.8abb939a8cabcbdb2d903846c05b7423.png

Here is the folder structure of the textures. As I mentioned before, when I put "block/generator_front" into the "new ResourceLocation()" and put the png file directly under "/block" and not "block/generator" it works.

image.png.3ea0ee70fa205f667b5d428a026be17e.png

This is where the block is rendered and is getting its texture:

image.thumb.png.902266df4b09b3d83f1d4f3026f01bfa.png

And of course the error that is been thrown:

image.thumb.png.e3ab127ee2378911131070013c240771.png

 

Thanks for any help.

Edited by MyNameIsJan
Link to comment
Share on other sites

  • MyNameIsJan changed the title to [1.17.1] Rendering item of a block with texture in a subfolder not working

I think you should do it the old way, you should register the item in the items initializer, example:

 

public class GWorldItems {
    public static final DeferredRegister<Item> ITEMS;

    public static final RegistryObject<Item> EXAMPLE_DUST;
    public static final RegistryObject<Item> EXAMPLE_GEM;
    public static final RegistryObject<Item> EXAMPLE_BLOCK;

    static {
        ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, "examplemod");

        EXAMPLE_DUST = ITEMS.register("example_dust", () -> {
            return new Item((new Properties()).tab(ExampleMod.examplemod));
        });
        EXAMPLE_GEM = ITEMS.register("example_gem", () -> {
            return new Item((new Properties()).tab(ExampleMod.examplemod));
        });
        EXAMPLE_BLOCK = ITEMS.register("example_ore", () -> {
            return new BlockItem((Block) ExampleBlocks.EXAMPLE_ORE.get(), (new Properties()).tab(ExampleMod.examplemod));
        });
    }
}

This is how it has always worked and will always work.

Edited by Gianka1485
Link to comment
Share on other sites

The second argument of withExistingParent is the path to a model file to use as a parent, not a texture. For basic block items, the model normally uses the block model as the parent, rather than specifying individual textures.

I use this helper method in my BlockStateProvider implementation to generate block item models that simply extend the block model. You can see an example of this here.

On a side note, the DeferredRegister instance should always be created in the same class as it's used in; don't put the DeferredRegister and RegistryObject fields in separate classes.

  • Thanks 1

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.

Link to comment
Share on other sites

2 minutes ago, Choonster said:

The second argument of withExistingParent is the path to a model file to use as a parent, not a texture. For basic block items, the model normally uses the block model as the parent, rather than specifying individual textures.

I use this helper method in my BlockStateProvider implementation to generate block item models that simply extend the block model. You can see an example of this here.

On a side note, the DeferredRegister instance should always be created in the same class as it's used in; don't put the DeferredRegister and RegistryObject fields in separate classes.

Better explained impossible.

Link to comment
Share on other sites

26 minutes ago, Choonster said:

The second argument of withExistingParent is the path to a model file to use as a parent, not a texture. For basic block items, the model normally uses the block model as the parent, rather than specifying individual textures.

I use this helper method in my BlockStateProvider implementation to generate block item models that simply extend the block model. You can see an example of this here.

On a side note, the DeferredRegister instance should always be created in the same class as it's used in; don't put the DeferredRegister and RegistryObject fields in separate classes.

Thanks a lot. And also for the little side note ;) Just one question... why do they have to be in one class? I know that the block needs to be registered before the item so as long as I take care of that it should be fine, right? Or is this some best practice?

If you got any further advice I'll take them :P 

Have a nice rest of the day

Edited by MyNameIsJan
Link to comment
Share on other sites

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.