How can I set the texture of a block to an existing vanilla texture, say minecraft:stone_slab_top? It seems setBlockTextureName() doesn't do anything at all.
Just how do I set a mod's block's texture to use a vanilla texture?
It seems you might be following some sort of tutorial developed for older versions of Forge. I am not up to date on 1.15.2 Forge modding, but afaik the texture does not need to be specified within the registry of the block (only the unlocalized name). Once the name is set, the game will look for a valid blockstate json file in the resources/assets/<modid>/models/block/ directory. So what you simply need to do there is add a json file which specifies the texture to be used to "minecraft:stone_slab_top" for both the block rendered in the world and the item rendered in the inventory.
I am explicitly trying to make mods for 1.7.10. There are no blockstate jsons in this version. I am not familiar with programming for the newer versions. Any version after 1.7.10 is new. This includes 1.8, 1.9, 1.10, 1.11, 1.12, 1.13, 1.14, 1.15, 1.16.1.
Add "minecraft:" and the texture path if you're putting in the texture where a string goes. If you're doing it where an IIcon variable is needed, get the block's texture. Such as Block.sandstone.getBlockTextureFromSide(2).
Haha I figured it out but this site is so inactive I'm not even sure everyone here deserves to no if no one is online.
This is kind of pretentious. People don't deserve to know since the forums are inactive? Are you insinuating because this forum is inactive and not everyone has hours to dedicate on here that its users don't deserve to be shared knowledge they share for free every day? I'm no moderator, but I don't think that kind of mindset is welcome here.
1. That wasn't a question, it was a statement. 2. My apologies.
My bad, I've misinterpreted the first statement as a question somehow, despite it clearly not being a question, sorry.
Great that you got it solved, and I now see what was wrong, I have no idea how I didn't notice that earlier.
I don't know if you ever solved this but you need to use "Block.block.getIcon" within your own "getIcon" method (icons are (re)initialized and point to a different object after the game (re)loads its resources and simply getting the icon and passing it into the constructor will result in an "orphaned" object when the resources are loaded (the reference in "Blocks.double_stone_slab" will change but not the reference in your own block's class); actually, I'd expect that "getIcon" returns null until the game has loaded resources for the first time, which only happens after block initialization, and would result in the missing icon texture; maybe Forge works a bit differently but either way the icon object will become invalid, especially if the texture atlas changes (the icon object stores its texture atlas coordinates so this would explain why it gives bizarre results).
For example, this is how I use vanilla icons for one of my own blocks, which replaces vanilla ores with a block that uses a transparent overlay over a base texture which is determined by its metadata (note that I'm using MCP for 1.6.4 but it should work the same way):
public Icon getIcon(int side, int meta)
{
switch (meta)
{
default:
case STONE:
return Block.stone.getIcon(side, BlockStoneTMCW.STONE);
case SANDSTONE:
return Block.sandStone.getIcon(side, BlockSandstoneTMCW.SANDSTONE);
case QUARTZ_SANDSTONE:
return Block.sandStone.getIcon(side, BlockSandstoneTMCW.QUARTZ_SANDSTONE);
case RED_SANDSTONE:
return Block.sandStone.getIcon(side, BlockSandstoneTMCW.RED_SANDSTONE);
case HARDENED_CLAY:
return Block.hardenedClay.getIcon(side, 0);
case SNOW:
return Block.blockSnow.getIcon(side, 0);
case PACKED_ICE:
return Block.packedIce.getIcon(side, BlockPackedIce.PACKED_ICE);
case BLUE_ICE:
return Block.packedIce.getIcon(side, BlockPackedIce.BLUE_ICE);
case NETHERRACK:
// Only gold ore has a netherrack variant
return (this.blockID == BlockStates.oreGold ? this.netherGoldIcon : this.blockIcon);
}
}
So the problem was that I am getting a blocks icon before the icon was loaded? I guess that makes sense. I believe I solved the problem by storing a reference to the original block instead of the block icon, and then returning originalblock.getIcon() because when getIcon is called the original blocks icon was presumably initialized. I do like your ores having a transparent overlay, looks cool.
I tried this:
And used it like this:
I ended up with something like this.
How can I set the texture of a block to an existing vanilla texture, say minecraft:stone_slab_top? It seems setBlockTextureName() doesn't do anything at all.
Just how do I set a mod's block's texture to use a vanilla texture?
It seems you might be following some sort of tutorial developed for older versions of Forge. I am not up to date on 1.15.2 Forge modding, but afaik the texture does not need to be specified within the registry of the block (only the unlocalized name). Once the name is set, the game will look for a valid blockstate json file in the resources/assets/<modid>/models/block/ directory. So what you simply need to do there is add a json file which specifies the texture to be used to "minecraft:stone_slab_top" for both the block rendered in the world and the item rendered in the inventory.
For further information regarding the subject you may want to refer to https://mcforge.readthedocs.io/en/latest/models/introduction/ and further subtitles handling the model files of blocks (and items).
Have the day you deserve.
I am explicitly trying to make mods for 1.7.10. There are no blockstate jsons in this version. I am not familiar with programming for the newer versions. Any version after 1.7.10 is new. This includes 1.8, 1.9, 1.10, 1.11, 1.12, 1.13, 1.14, 1.15, 1.16.1.
Add "minecraft:" and the texture path if you're putting in the texture where a string goes. If you're doing it where an IIcon variable is needed, get the block's texture. Such as Block.sandstone.getBlockTextureFromSide(2).
I tried that, but the texture of the block still just looks like a texture atlas, not the top or side or whatever texture of sandstone.
Here's what I have so far:
And here's the class I defined for SmoothBlock:
I get a strange block whose texture resembles a texture atlas. What am I doing wrong and how do I fix it?
I don't understand the question.
This is kind of pretentious. People don't deserve to know since the forums are inactive? Are you insinuating because this forum is inactive and not everyone has hours to dedicate on here that its users don't deserve to be shared knowledge they share for free every day? I'm no moderator, but I don't think that kind of mindset is welcome here.
1. That wasn't a question, it was a statement. 2. My apologies.
My bad, I've misinterpreted the first statement as a question somehow, despite it clearly not being a question, sorry.
Great that you got it solved, and I now see what was wrong, I have no idea how I didn't notice that earlier.
1 year later
In hindsight that latest comment was rude so my apologies
I don't know if you ever solved this but you need to use "Block.block.getIcon" within your own "getIcon" method (icons are (re)initialized and point to a different object after the game (re)loads its resources and simply getting the icon and passing it into the constructor will result in an "orphaned" object when the resources are loaded (the reference in "Blocks.double_stone_slab" will change but not the reference in your own block's class); actually, I'd expect that "getIcon" returns null until the game has loaded resources for the first time, which only happens after block initialization, and would result in the missing icon texture; maybe Forge works a bit differently but either way the icon object will become invalid, especially if the texture atlas changes (the icon object stores its texture atlas coordinates so this would explain why it gives bizarre results).
For example, this is how I use vanilla icons for one of my own blocks, which replaces vanilla ores with a block that uses a transparent overlay over a base texture which is determined by its metadata (note that I'm using MCP for 1.6.4 but it should work the same way):
TheMasterCaver's First World - possibly the most caved-out world in Minecraft history - includes world download.
TheMasterCaver's World - my own version of Minecraft largely based on my views of how the game should have evolved since 1.6.4.
Why do I still play in 1.6.4?
So the problem was that I am getting a blocks icon before the icon was loaded? I guess that makes sense. I believe I solved the problem by storing a reference to the original block instead of the block icon, and then returning originalblock.getIcon() because when getIcon is called the original blocks icon was presumably initialized. I do like your ores having a transparent overlay, looks cool.