Jump to content

[1.12] Using an image generated at startup as a block's texture


iWasHere

Recommended Posts

Hiya! I'm trying to accomplish a few tasks at startup, and anything related to it that I can find was only relevant in 1.7.10.

I'm trying to accomplish the following:

  • Grab a block's texture (This works)
  • Put an overlay on the texture (This works, I get a BufferedImage that I can do whatever with. I was only able to do this after the Blockstates have been registered, currently the modified textures are just dumped into a folder under /config/mod. Since this is after TextureStitchEvent, the textures themselves won't exist until after the user launches the game to generate them for the first time, but this isn't too much of a concern to me.)
  • Add the texture to the TextureMap (No idea how to accomplish this)
  • Add a new simple cube model with this new texture on all sides, and have a Block use it

 

Now, the largest issue here is that the blocks that I'm taking the textures of aren't static; the blocks are pulled from a config so the user may select any block they desire the mod to work with. I can't get past adding the new texture to the TextureMap, and I can't find anything at all about adding new models outside of JSON (which doesn't allow them to be generated like I need them to be). I've discovered DynamicTexture, but based on what I've seen I probably don't want to be using that for textures that remain static after startup. Any advice would be appreciated, and thank you for reading. ❤️

Link to comment
Share on other sites

Use the TextureStitchEvent to add the texture to the TextureMap.

 

You could load a dummy model (who’s parent is block/cube_all) in the ModelBakeEvent, then copy the dummy model, retexture & bake the copy and apply the copies to your blocks.

 

I haven’t dealt with custom models for a while and that approach may not be the best, but it’s how I would do it.

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

I haven't done this since 1.7, but as far as I know the same process should still work.

 

And the reason I haven't done it since 1.7 is that there's no need to: you can just have a two layer block model instead.

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

Thank you for the input, guys.

Because the texture is an outside resource (it's located in the config folder), I have no idea how to load it in, as it isn't in my mod's assets directory. I went with DynamicTexture but I really don't think I should be. I was able to load the dummy model, but I'm unsure of how to actually bake it.

 

This is my TextureStitchEvent. It reads in the image fine, I /think/ it's being registered to the TextureMap, but I still get a missing texture error .

    @SubscribeEvent(priority = EventPriority.LOW)
    public static void preStitch(TextureStitchEvent.Pre event) {
        try {
            BufferedImage image = ImageIO.read(new File("config/compax/cache/minecraft-dirt_x1.png"));

            ResourceLocation location = Minecraft.getMinecraft().getTextureManager().getDynamicTextureLocation("compax:dirt_x1", new DynamicTexture(image));
            TextureAtlasSprite sprite = event.getMap().registerSprite(location);
            event.getMap().setTextureEntry(sprite);

            Compax.logger.info("Added this: " + sprite.toString());
        }
        catch (IOException e) {
            Compax.logger.error("Error reading in texture:\n" + e.getLocalizedMessage());
        }
    }

 

The missing texture error. It's probably the lack of the resource manager?

[17:01:07] [Client thread/ERROR] [FML.TEXTURE_ERRORS]:   DOMAIN dynamic/compax
[17:01:07] [Client thread/ERROR] [FML.TEXTURE_ERRORS]: --------------------------------------------------
[17:01:07] [Client thread/ERROR] [FML.TEXTURE_ERRORS]:   domain dynamic/compax is missing 1 texture
[17:01:07] [Client thread/ERROR] [FML.TEXTURE_ERRORS]:     domain dynamic/compax is missing a resource manager - it is probably a side-effect of automatic texture processing
[17:01:07] [Client thread/ERROR] [FML.TEXTURE_ERRORS]: -------------------------
[17:01:07] [Client thread/ERROR] [FML.TEXTURE_ERRORS]:     The missing resources for domain dynamic/compax are:
[17:01:07] [Client thread/ERROR] [FML.TEXTURE_ERRORS]:       textures/dirt_x1_1.png

 

Here's my ModelBakeEvent, runs without error. I'm not sure how to use the texture I added to the TextureMap when retexturing the model here (instead I'm using a texture I have included within my mod's assets folder for the time being). In addition, I have no idea how to actually bake the model.

    @SubscribeEvent
    public static void modelBake(ModelBakeEvent event) {
        Compax.logger.info("Loading models");
        try {
            IModel cube = ModelLoaderRegistry.getModel(new ModelResourceLocation(Compax.MODID + ":dummy"));
            ImmutableMap.Builder<String, String> texMap = new ImmutableMap.Builder<>();
            texMap.put("all", "compax:block/compact_x2");
            IModel newCube = cube.retexture(texMap.build());
        }
        catch (Exception e) {
            Compax.logger.error("Couldn't load models:\n" + e.getLocalizedMessage());
        }
    }

 

A two layer block model might be easier, but I still need to generate these models and apply the textures to them anyways. Sorry about the wall of text, I figured I might as well give as much information as I can. Thank you for your help!

Link to comment
Share on other sites

13 hours ago, iWasHere said:

Because the texture is an outside resource (it's located in the config folder)

Why is it there? If users want to change it they can do so with a resource pack.

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

Can you back up and explain why you’re doing all of this?

From what I understand you’re

1) saving the texture of a model to a file

2) using that texture in the next game, when the texture already exists in the texture map from the model you originally got it from

3) Ignoring resource pack changes in between runs (using the old texture when the pack has changed)

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

17 hours ago, iWasHere said:

It's not that if they want to change it. It's placed there because I pull block textures from BlockStates which can only be done after texture stitching. The files are stored there so that I can load them in the next time the game is launched.

This makes no sense to me. You're "pulling textures from blackstates" huh, what?

 

Again, you vcan have a model with 2 textures per face (one of which points at a texture from your mod and one that does not) just fine with the existing system.

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

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.