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.

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

Featured Replies

Posted

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

  • 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

  • Author

Thanks for the reply.

The Registration and all that stuff is working and I'm doing it like you said.

image.thumb.png.abb0cf78a39ecc6421b2488981204e3e.png

I split it up into multiple classes and not all in one.

I can see my items/blocks ingame. But the item got this purple/black texture.

I was in the bathroom so I couldn't respond quickly, hahaha...

I think the problem may come from the .json files of assets /% modid% / models / item

Edited by Gianka1485

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.

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.

When you want a block to have a texture, it must have the following information (although it may vary):

 

{
  "parent": "examplemod:block/example_block"
}

 

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.

  • Author
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

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.