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.

Featured Replies

Posted

I am currently trying to write a minimap addon and I am desperately trying to find a method that allows me to get a block's top texture reliably.

 

So far I tried to get the texture directly from the IIcon by casting it to a TextureAtlasSprite if possible, but that is limited to only a few blocks.

 

I also tried to fetch the image directly from the texture that holds the block faces, but that feels very hacky to me and requires exact timing to actually get the block texture properly.

 

Is there a better/reliable way to get the top texture of any block that has one?

My Mods

 

New Dawn - A completely new terrain engine for Minecraft

TwoTility - Blocks and Items for a better Minecraft

TwoGraves - Keeps your items safe on death

  • Author

Thanks, but that's the part I already know. ;)

 

I am looking to access the pixel data from that icon, but I don't know hot to get it.

My Mods

 

New Dawn - A completely new terrain engine for Minecraft

TwoTility - Blocks and Items for a better Minecraft

TwoGraves - Keeps your items safe on death

  • Author

That was my second try, however the texture I get is very strange and does not include many blocks that are present in the world. The UV of leaves for example points to an empty part of that texture, and I am not sure yet why. It might be an error on my part, but then I figure that at some point the textures are loaded from disk anyway, so why get them via texture buffer?

 

As far as I understand it, there has to be some point where the texture files are actually loaded from disk in the form of a BufferedImage. What I would like to do is to either somehow do the same, or to intercept that either while it is loading or at a later time if that image data is kept in memory afterwards.

My Mods

 

New Dawn - A completely new terrain engine for Minecraft

TwoTility - Blocks and Items for a better Minecraft

TwoGraves - Keeps your items safe on death

  • Author

The way I want them to use I would only read them once, then reduce them to a single pixel value and cache that.

 

So is there a way to do that other than to use the texture memory?

My Mods

 

New Dawn - A completely new terrain engine for Minecraft

TwoTility - Blocks and Items for a better Minecraft

TwoGraves - Keeps your items safe on death

  • Author

Would you have an example code for that by any chance? I am trying to figure out how to load those for a while now and can't seem to find a working example.

My Mods

 

New Dawn - A completely new terrain engine for Minecraft

TwoTility - Blocks and Items for a better Minecraft

TwoGraves - Keeps your items safe on death

  • Author

Thank you, I'll give it a try.

 

My Mods

 

New Dawn - A completely new terrain engine for Minecraft

TwoTility - Blocks and Items for a better Minecraft

TwoGraves - Keeps your items safe on death

  • Author

Took a little more try and error, but finally I got it.

 

For future reference, this is how you load any texture from a given block IIcon (use block.getIcon to get that icon):

 

  
/* Returns the pixel data of the texture described by icon in ARGB format */
static int[] loadTexture(final IIcon icon) {
    try {
      final ResourceLocation resourceLocation = getResourceLocation(icon.getIconName());
      final IResourceManager resourceManager = Minecraft.getMinecraft().getResourceManager();
      final IResource resource = resourceManager.getResource(resourceLocation);
      final InputStream in = resource.getInputStream();
      final BufferedImage image = ImageIO.read(in);
      return image.getRGB(0, 0, image.getWidth(), image.getHeight(), null, 0, image.getWidth());
    } catch (Exception e) {
      FMLLog.log(Level.ERROR, e, "Unable to load texture '%s'", icon.getIconName());
    }
    return null;
  }

  static ResourceLocation getResourceLocation(final String blockTexture) {
    String domain = "minecraft";
    String path = blockTexture;
    final int domainSeparator = blockTexture.indexOf(':');

    if (domainSeparator >= 0) {
      path = blockTexture.substring(domainSeparator + 1);

      if (domainSeparator > 1) {
        domain = blockTexture.substring(0, domainSeparator);
      }
    }

    final String resourcePath = "textures/blocks/" + path + ".png";  // base path and PNG are hardcoded in Minecraft
    return new ResourceLocation(domain.toLowerCase(), resourcePath);
  }

My Mods

 

New Dawn - A completely new terrain engine for Minecraft

TwoTility - Blocks and Items for a better Minecraft

TwoGraves - Keeps your items safe on death

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.