I have a mod that I am porting to 1.9.4 that accesses block textures and uses them to create new textures. In 1.7.10, I used something like this:
//textureName is the name of the icon on the side of the block (icon 3) with metadata = 0
String textureName = block.getIcon(3, 0).getIconName();
String textureLocation = "minecraft:textures/blocks/" + textureName + ".png";
//finds theResourceLocation with the textureLocation string
ResourceLocation location = new ResourceLocation(textureLocation);
//For grass, for example, the textureLocation string would be "minecraft:textures/blocks/grass_side.png"
This isn't all of the code I used in that version, but it serves for showing purposes.
Now that .json files are used with block models and states, this seems a little more complicated. In 1.9.4, is there a simple way to call a block texture based on block side and metadata? I am unfamiliar with how .json files work and that is why I am asking.
After digging around, ModelBlock.class seems to have a texture "Map" read from the .json file, but I don't know how to call a block's model block.
Okay wait what are you trying to figure out? You're trying to get the models for each block? And why 1.9.4? What's so great about that version? Why not just go to 1.11.2? It's for the most part the same as 1.8/1.9/1.10, with the whole JSON thing. So you can achieve the same result but with a different version and some smaller differences.
Now onto your main question:
It is recommended that you have a common side class and a client side class. The common one will be a common side event bus subscriber that will have methods that subscribe to the RegistryEvent.Register<[Item|Block]> where the generic type param is either Item or Block, which implement IForgeRegistryEntry. Then you just call RegistryEvent.Register<[Item or Block]>#getRegistry()#register or registerAll and pass in all the items or blocks according to what you're trying to register. In this version you have to create the itemblocks for your blocks, and you register your item blocks in the item registry event. Then the client side event bus subscriber class will have methods that subscribe to the ModelRegistryEvent and you don't need to directly access the event, you just need to register your model resource locations during the event, which whatever is in the method will be executed during the model registry phase. So for this you will need to just have one method that subscribes to that event, but in that you need to call other methods that register items and blocks. Then you just create a blockstates package in your assets where your blocks will point to your models depending on certain variants. You can specify what textures goes to what side by doing this (furnace example):
P.S.: Everything I said is for 1.11.2, but if you wanna stay in 1.9.4 (for whatever reason) then you'll need to adjust it a bit so that it works for 1.9.4.
Thanks for the reply alexcouch! Yes, you're right, I should probably just go to 1.11.2, I just wasn't sure how many differences in rendering there were between versions and I decided to go from the bottom up.
I guess I wasn't as descriptive as I thought. I'm updating my Ore Sheep Mod. Each of the sheep has a texture that corresponds to a block. What I need to do is access each block's texture so I can create entity textures while the game is running. When I get the block texture, I have a class that copies the texture several times in a specific pattern and stores it as a DynamicTexture. That way, I don't have to manually create a texture for every single block, the game just does it. Then, each ore sheep calls their respective DynamicTexture as it is rendered.
My question is, how do I access the different texture names of each block? For example, if I need the grass texture, I need the textureName to show as "grass_side" or "grass_top", not just "grass."
That's actually really interesting. I've never thought of doing this before.
You might actually have to create your own set up so that it gets the texture for you. So you might have to do something like this:
create a package that will hold all of the classes needed to retrieve the texture location. To do this, I would have a method take in a resource location. Then get that resource location. Then find a way (I don't know how to, look into the forge code or something) and find a way to retrieve the variant responsible for getting a texture of like "all" or "up" or "down" then just get the texture location, then load it up into the sheep's texture information. I would have to look around myself but I don't have time right now, so go ahead and look around and hopefully someone else can provide a bit more detail about this kind of thing.
Rollback Post to RevisionRollBack
If you would like to get a hold of me somehow, then my discord is @Alex Couch#5275.
Thanks alexchouch! I've been looking around a bit and that's why I mentioned the ModelBlock class because it has a method that seems to create a map of all of the textures of each block.
You'll need to get the IBakedModel for the block and then get the texture locations from that. Either use the model's particle texture or the texture from one of the model's BakedQuads.
These texture locations are actually the names of sprites on the block texture atlas, they don't necessarily correspond to texture files on disk. This means you should get the textures from the atlas rather than reading them from a file.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Also, while it would be best to get the textures algorithmically, it might simply be easier to make your own texture file that contains all the known ores and get the textures from there or otherwise just copy the texture resources. The main issue would be that it would only show vanilla textures and not honor resource packs, so if you can do it algorithmically definitely do that. But if you get stuck making it work, it might go a long way to simply do it manually.
Two questions with this: First, is there a better way than using getDefaultState? I get the feeling this won't support blocks with metadata like stone, for example, that have multiple sub blocks.
Second, how can I get a BufferedImage from the TextureAtlasSprite? Is it possible to get a ResourceLocation or DynamicTexture from the TextureAtlasSprite? I will use the BufferedImage to create the entity texture by duplicating the block's texture multiple times over the entity texture.
This way should be mod compatible too, not just vanilla compatible.
Two questions with this: First, is there a better way than using getDefaultState? I get the feeling this won't support blocks with metadata like
stone, for example, that have multiple sub blocks.
Store the full IBlockState rather than just the Block.
Second, how can I get a BufferedImage from the TextureAtlasSprite? Is it possible to get a ResourceLocation or DynamicTexture from the TextureAtlasSprite? I will use the BufferedImage to create the entity texture by duplicating the block's texture multiple times over the entity texture.
JEI has code to get a TextureAtlasSprite from an IBlockState or ItemStack (this returns the particle texture) and to get a BufferedImage from a TextureAtlasSpritehere.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Sorry for not replying sooner, I was so excited it worked!
I used the code in my previous post and used the code found in your link to convert theTextureAtlasSprite[/i] and it worked perfectly!
I'm not sure yet how the BakedQuads work yet, but using the following line where block = Blocks.GRASS gives me the side texture. I'll have to keep studying this...
You're passing EnumFacing.NORTH to IBakedModel.getQuads, so it's returning the quads for the north face of the model.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Hello,
I have a mod that I am porting to 1.9.4 that accesses block textures and uses them to create new textures. In 1.7.10, I used something like this:
This isn't all of the code I used in that version, but it serves for showing purposes.
Now that .json files are used with block models and states, this seems a little more complicated. In 1.9.4, is there a simple way to call a block texture based on block side and metadata? I am unfamiliar with how .json files work and that is why I am asking.
After digging around, ModelBlock.class seems to have a texture "Map" read from the .json file, but I don't know how to call a block's model block.
Thanks for any and all help!
Okay wait what are you trying to figure out? You're trying to get the models for each block? And why 1.9.4? What's so great about that version? Why not just go to 1.11.2? It's for the most part the same as 1.8/1.9/1.10, with the whole JSON thing. So you can achieve the same result but with a different version and some smaller differences.
Now onto your main question:
It is recommended that you have a common side class and a client side class. The common one will be a common side event bus subscriber that will have methods that subscribe to the RegistryEvent.Register<[Item|Block]> where the generic type param is either Item or Block, which implement IForgeRegistryEntry. Then you just call RegistryEvent.Register<[Item or Block]>#getRegistry()#register or registerAll and pass in all the items or blocks according to what you're trying to register. In this version you have to create the itemblocks for your blocks, and you register your item blocks in the item registry event. Then the client side event bus subscriber class will have methods that subscribe to the ModelRegistryEvent and you don't need to directly access the event, you just need to register your model resource locations during the event, which whatever is in the method will be executed during the model registry phase. So for this you will need to just have one method that subscribes to that event, but in that you need to call other methods that register items and blocks. Then you just create a blockstates package in your assets where your blocks will point to your models depending on certain variants. You can specify what textures goes to what side by doing this (furnace example):
Except for the parent model should be whatever you want it to be, and most likely you would want "block/cube" or "block/cube_all".
Below is an example of what I am trying to say so you can get a grasp of what I'm talking about.
This example is literally the same as what I said, except the common and client are combined into one class.
Registry Handler
Blocks Init
Items Init
P.S.: Everything I said is for 1.11.2, but if you wanna stay in 1.9.4 (for whatever reason) then you'll need to adjust it a bit so that it works for 1.9.4.
If you would like to get a hold of me somehow, then my discord is @Alex Couch#5275.
Thanks for the reply alexcouch! Yes, you're right, I should probably just go to 1.11.2, I just wasn't sure how many differences in rendering there were between versions and I decided to go from the bottom up.
I guess I wasn't as descriptive as I thought. I'm updating my Ore Sheep Mod. Each of the sheep has a texture that corresponds to a block. What I need to do is access each block's texture so I can create entity textures while the game is running. When I get the block texture, I have a class that copies the texture several times in a specific pattern and stores it as a DynamicTexture. That way, I don't have to manually create a texture for every single block, the game just does it. Then, each ore sheep calls their respective DynamicTexture as it is rendered.
My question is, how do I access the different texture names of each block? For example, if I need the grass texture, I need the textureName to show as "grass_side" or "grass_top", not just "grass."
Thanks a bunch!
That's actually really interesting. I've never thought of doing this before.
You might actually have to create your own set up so that it gets the texture for you. So you might have to do something like this:
create a package that will hold all of the classes needed to retrieve the texture location. To do this, I would have a method take in a resource location. Then get that resource location. Then find a way (I don't know how to, look into the forge code or something) and find a way to retrieve the variant responsible for getting a texture of like "all" or "up" or "down" then just get the texture location, then load it up into the sheep's texture information. I would have to look around myself but I don't have time right now, so go ahead and look around and hopefully someone else can provide a bit more detail about this kind of thing.
If you would like to get a hold of me somehow, then my discord is @Alex Couch#5275.
Thanks alexchouch! I've been looking around a bit and that's why I mentioned the ModelBlock class because it has a method that seems to create a map of all of the textures of each block.
However, I don't know how to call a block's ModelBlock using just the instantiated block. If there are any better ideas too, I'm all ears!
Thanks for the help!
You'll need to get the IBakedModel for the block and then get the texture locations from that. Either use the model's particle texture or the texture from one of the model's BakedQuads.
These texture locations are actually the names of sprites on the block texture atlas, they don't necessarily correspond to texture files on disk. This means you should get the textures from the atlas rather than reading them from a file.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Also, while it would be best to get the textures algorithmically, it might simply be easier to make your own texture file that contains all the known ores and get the textures from there or otherwise just copy the texture resources. The main issue would be that it would only show vanilla textures and not honor resource packs, so if you can do it algorithmically definitely do that. But if you get stuck making it work, it might go a long way to simply do it manually.
Hey, this is looking promising! I used the line below:
Two questions with this: First, is there a better way than using getDefaultState? I get the feeling this won't support blocks with metadata like stone, for example, that have multiple sub blocks.
Second, how can I get a BufferedImage from the TextureAtlasSprite? Is it possible to get a ResourceLocation or DynamicTexture from the TextureAtlasSprite? I will use the BufferedImage to create the entity texture by duplicating the block's texture multiple times over the entity texture.
This way should be mod compatible too, not just vanilla compatible.
Thanks!
Store the full IBlockState rather than just the Block.
JEI has code to get a TextureAtlasSprite from an IBlockState or ItemStack (this returns the particle texture) and to get a BufferedImage from a TextureAtlasSprite here.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Sorry for not replying sooner, I was so excited it worked!
I used the code in my previous post and used the code found in your link to convert theTextureAtlasSprite[/i] and it worked perfectly!
I'm not sure yet how the BakedQuads work yet, but using the following line where block = Blocks.GRASS gives me the side texture. I'll have to keep studying this...
You're passing EnumFacing.NORTH to IBakedModel.getQuads, so it's returning the quads for the north face of the model.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.