Jump to content

[SOLVED][1.10.2] Mapping Block to its Textures


Furgl

Recommended Posts

Hello,

 

My friend and I are working on a mod that would require getting the textures that a block uses.

 

Currently, we are using ItemModelMesherForge's locations field (of type IdentityHashMap<Item, TIntObjectHashMap<ModelResourceLocation>>) to map an ItemBlock and its metadata to its ResourceLocation. From there, we modify the ResourceLocation and use it to find the ItemBlock's .json file and look for the textures it uses. The problem is, for many items, the item's .json references a parent block .json that might have the textures or might reference another .json and so on and so forth. The .jsons may also have variants that can further complicate finding the textures.

 

I know it's possible for us to check all of the .json files and find the textures we're looking for, but I would imagine that there's an easier way to do this (since Minecraft/Forge do it), but I haven't been able to find anything promising after looking around in the code for a while.

 

Does anyone know of an easier way to map a given block to its textures?

 

Thanks in advance!

Link to comment
Share on other sites

Hello,

 

My friend and I are working on a mod that would require getting the textures that a block uses.

 

Currently, we are using ItemModelMesherForge's locations field (of type IdentityHashMap<Item, TIntObjectHashMap<ModelResourceLocation>>) to map an ItemBlock and its metadata to its ResourceLocation. From there, we modify the ResourceLocation and use it to find the ItemBlock's .json file and look for the textures it uses. The problem is, for many items, the item's .json references a parent block .json that might have the textures or might reference another .json and so on and so forth. The .jsons may also have variants that can further complicate finding the textures.

 

I know it's possible for us to check all of the .json files and find the textures we're looking for, but I would imagine that there's an easier way to do this (since Minecraft/Forge do it), but I haven't been able to find anything promising after looking around in the code for a while.

 

Does anyone know of an easier way to map a given block to its textures?

 

Thanks in advance!

Do not know where the textures are actually stored, but they are loaded at runtime, so if you trace the rendering of a block back far enough you are sure to find the textures themselves, but you may need to use reflection to get them.

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.

Link to comment
Share on other sites

Do not know where the textures are actually stored, but they are loaded at runtime, so if you trace the rendering of a block back far enough you are sure to find the textures themselves, but you may need to use reflection to get them.

From what we understand, the locations of the textures are stored in either the block's model json in minecraft:models/block/, the item's model json in minecraft:models/item/, or the block's blockstate json in minecraft:blockstates/. But it can be a maze navigating through the jsons trying to find where they are.

 

I've tried tracing the rendering, but haven't found anything.

Link to comment
Share on other sites

What specifically do you need them for? We can give much better help if we know what you're trying to do.

 

We're creating armor that uses the textures of blocks, so I don't think there's any other way to do it without mapping blocks to their textures at runtime.

 

Are you making dirt armour, obsidian armour, etc? Or are you making armour that's a bit like TiCon tools?

Link to comment
Share on other sites

Are you making dirt armour, obsidian armour, etc? Or are you making armour that's a bit like TiCon tools?

 

We're making armor specifically for each block, like dirt armor or obsidian armor.

 

Unless you are making a metric ton of armours, it's better to do the textures manually. I think I know where to start if you need to create textures dynamically, however it is rather complicated. Additionally dynamically created textures won't necessarily look good, as not all textures tile well.

Link to comment
Share on other sites

Do you need to get this texture at runtime or can you simply create a texture for each block's armour on disk?

 

If you do need to get the texture at runtime, you can use the particle texture of the block's model.

 

If your armour stores an

IBlockState

, use

BlockModelShapes#getTexture

to get the particle texture of that state's model. If your armour stores an

ItemStack

, use

ItemModelMesher#getParticleIcon

to get the particle texture of that item's model.

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

Unless you are making a metric ton of armours, it's better to do the textures manually. I think I know where to start if you need to create textures dynamically, however it is rather complicated. Additionally dynamically created textures won't necessarily look good, as not all textures tile well.

 

We want to have our armors work with modded blocks, so we can't pre-make the textures ourselves.

 

Do you need to get this texture at runtime or can you simply create a texture for each block's armour on disk?

 

If you do need to get the texture at runtime, you can use the particle texture of the block's model.

 

If your armour stores an

IBlockState

, use

BlockModelShapes#getTexture

to get the particle texture of that state's model. If your armour stores an

ItemStack

, use

ItemModelMesher#getParticleIcon

to get the particle texture of that item's model.

 

We need to get the texture at runtime.

 

Using the particle texture works pretty well, and it's a lot easier than the methods we were using to get the textures before. Thank you!

 

Is there an easy way to get a texture for a specific side of a block (one of the six faces of a cube, since we're only using blocks that are full cubes)?

Link to comment
Share on other sites

Probably not as easily.  And I can think of remarkably few cases where the particle texture is....not wrong, but misleading.

And one of those blocks are mine (the top and bottom faces are smooth stone, and so is the particle texture, but the side faces--the important information about the block*--was different).

 

*Yes, it was intentionally misleading.  If the player could not see the sides of the block there was no way to tell it apart from stone.  I even made WAILA respect this.

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.

Link to comment
Share on other sites

Probably not as easily.  And I can think of remarkably few cases where the particle texture is....not wrong, but misleading.

And one of those blocks are mine (the top and bottom faces are smooth stone, and so is the particle texture, but the side faces--the important information about the block*--was different).

 

*Yes, it was intentionally misleading.  If the player could not see the sides of the block there was no way to tell it apart from stone.  I even made WAILA respect this.

 

I figured it wouldn't be very easy. Oh, well. May have to settle for particle textures for the time being.

Link to comment
Share on other sites

We need to get the texture at runtime.

 

Using the particle texture works pretty well, and it's a lot easier than the methods we were using to get the textures before. Thank you!

 

Is there an easy way to get a texture for a specific side of a block (one of the six faces of a cube, since we're only using blocks that are full cubes)?

 

IBakedModel#getQuads

can give you the

BakedQuad

s for an

EnumFacing

and

BakedQuad#getSprite

can give you the texture of a

BakedQuad

.

 

If you're storing an

IBlockState

, you can use

BlockModelShapes#getModelForState

to get the

IBakedModel

. If you're storing an

ItemStack

, you can use

ItemModelMesher#getItemModel(ItemStack)

,

IBakedModel#getOverrides

and

ItemOverrideList#handleItemState

to get the

IBakedModel

.

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

IBakedModel#getQuads

can give you the

BakedQuad

s for an

EnumFacing

and

BakedQuad#getSprite

can give you the texture of a

BakedQuad

.

 

If you're storing an

IBlockState

, you can use

BlockModelShapes#getModelForState

to get the

IBakedModel

. If you're storing an

ItemStack

, you can use

ItemModelMesher#getItemModel(ItemStack)

,

IBakedModel#getOverrides

and

ItemOverrideList#handleItemState

to get the

IBakedModel

.

 

BakedQuads are perfect! Thank you so much, you saved us a lot of time and work!

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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello all! I'm currently trying to make the Biomes o' Plenty mod (1.12.2 version) compatible with my shaderpack (BSL v8.5). Even after I've already inserted a "shaders" folder with a correctly-formatted blocks.PROPERTIES file within the assets folder of the .jar, it still does not wave the textures from the mod. I definitely thought this was going to work since I noticed the 1.19.2 version of the mod laid it out exactly like that and it worked perfectly when my PC was able to run 1.19.2 Forge... ^^;;; Could there be some missing link I'm not getting at here?
    • After much experimentation I finally realised why this doesn't work and how to fix it. The critical component to understand here, is that ItemCraftedEvent is called before the crafting ingredients are purged from the crafting slots; this all happens in ResultSlot.java's onTake method: We can see here the first line fires checkTakeAchievements, this is what fires the ItemCraftedEvent (after a few method calls). Then we can see the purge behaviour. I worked around this by creating a CarverItem class, which uses hasCraftingRemainingItem and getCraftingRemainingItem to hook into ResultSlot.onTake: Now, I reconstruct my ItemCraftedEvent handler, and using some smart tags (which I omit for brevity), I handle two cases: 1. When crafting a carved item, I damage the tool used in the recipe 2. When crafting a carving tool from a repair recipe, I manually purge the input tools as with the new CarverItem class, as otherwise items would be duplicated   This has now greatly improved implementation, beyond my expectations, for the standard crafting table and the user's inventory crafting grid. A user can now click or shift-click 'carve' items, with no duplication or issues that I have spotted so far.  
    • Hi, I'm having issues launching my Forge 1.20.1 installation (47.2.0). I keep getting error code 1, and all the logs abruptly pause with the game attempting to open GL 4.6. Latest Crash: https://pastebin.com/zsP5Wipk Debug (No idea what the real name is) Log: https://pastebin.com/CzvqhNq0   Thanks for the help!
    • In the most up to date version of Allthemods 6 (v1.9.2) the stoned bee is not able to be interacted with apart from putting it into an empty bee jar. I can't breed the bee or put it into my aviary breeder. When I try to put it into the breeder it says import unsuccessful. The stoned bee is one of the most important bees for advancing in the mod so it is rather unfortunate that it is not working as intended.
    • Everytime I try to run the Forge 1.20.1 - 47.1.0 Installer, only appears an a black window and then closes. I don't appear the installing menu anymore.
  • Topics

×
×
  • Create New...

Important Information

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