Posted October 14, 201411 yr 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
October 14, 201411 yr 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
October 14, 201411 yr 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
October 14, 201411 yr 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
October 14, 201411 yr 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
October 14, 201411 yr 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
October 16, 201411 yr 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.