| 1 | package net.minecraft.client.renderer.texture;
|
| 2 |
|
| 3 | import java.awt.Graphics;
|
| 4 | import java.awt.image.BufferedImage;
|
| 5 | import java.awt.image.ImageObserver;
|
| 6 | import java.io.IOException;
|
| 7 | import java.io.InputStream;
|
| 8 | import java.util.List;
|
| 9 | import net.minecraft.block.material.MapColor;
|
| 10 | import net.minecraft.client.resources.IResourceManager;
|
| 11 | import net.minecraft.item.EnumDyeColor;
|
| 12 | import net.minecraft.util.MathHelper;
|
| 13 | import net.minecraft.util.ResourceLocation;
|
| 14 | import org.apache.logging.log4j.LogManager;
|
| 15 | import org.apache.logging.log4j.Logger;
|
| 16 |
|
| 17 | public class LayeredColorMaskTexture extends AbstractTexture
|
| 18 | {
|
| 19 | /** Access to the Logger, for all your logging needs. */
|
| 20 | private static final Logger LOG = LogManager.getLogger();
|
| 21 |
|
| 22 | /** The location of the texture. */
|
| 23 | private final ResourceLocation textureLocation;
|
| 24 | private final List<String> field_174949_h;
|
| 25 | private final List<EnumDyeColor> field_174950_i;
|
| 26 |
|
| 27 | public LayeredColorMaskTexture(ResourceLocation textureLocationIn, List<String> p_i46101_2_, List<EnumDyeColor> p_i46101_3_)
|
| 28 | {
|
| 29 | this.textureLocation = textureLocationIn;
|
| 30 | this.field_174949_h = p_i46101_2_;
|
| 31 | this.field_174950_i = p_i46101_3_;
|
| 32 | }
|
| 33 |
|
| 34 | public void loadTexture(IResourceManager resourceManager) throws IOException
|
| 35 | {
|
| 36 | this.deleteGlTexture();
|
| 37 | BufferedImage bufferedimage;
|
| 38 |
|
| 39 | try
|
| 40 | {
|
| 41 | BufferedImage bufferedimage1 = TextureUtil.readBufferedImage(resourceManager.getResource(this.textureLocation).getInputStream());
|
| 42 | int i = bufferedimage1.getType();
|
| 43 |
|
| 44 | if (i == 0)
|
| 45 | {
|
| 46 | i = 6;
|
| 47 | }
|
| 48 |
|
| 49 | bufferedimage = new BufferedImage(bufferedimage1.getWidth(), bufferedimage1.getHeight(), i);
|
| 50 | Graphics graphics = bufferedimage.getGraphics();
|
| 51 | graphics.drawImage(bufferedimage1, 0, 0, (ImageObserver)null);
|
| 52 |
|
| 53 | for (int j = 0; j < 17 && j < this.field_174949_h.size() && j < this.field_174950_i.size(); ++j)
|
| 54 | {
|
| 55 | String s = (String)this.field_174949_h.get(j);
|
| 56 | MapColor mapcolor = ((EnumDyeColor)this.field_174950_i.get(j)).getMapColor();
|
| 57 |
|
| 58 | if (s != null)
|
| 59 | {
|
| 60 | InputStream inputstream = resourceManager.getResource(new ResourceLocation(s)).getInputStream();
|
| 61 | BufferedImage bufferedimage2 = TextureUtil.readBufferedImage(inputstream);
|
| 62 |
|
| 63 | if (bufferedimage2.getWidth() == bufferedimage.getWidth() && bufferedimage2.getHeight() == bufferedimage.getHeight() && bufferedimage2.getType() == 6)
|
| 64 | {
|
| 65 | for (int k = 0; k < bufferedimage2.getHeight(); ++k)
|
| 66 | {
|
| 67 | for (int l = 0; l < bufferedimage2.getWidth(); ++l)
|
| 68 | {
|
| 69 | int i1 = bufferedimage2.getRGB(l, k);
|
| 70 |
|
| 71 | if ((i1 & -16777216) != 0)
|
| 72 | {
|
| 73 | int j1 = (i1 & 16711680) << 8 & -16777216;
|
| 74 | int k1 = bufferedimage1.getRGB(l, k);
|
| 75 | int l1 = MathHelper.func_180188_d(k1, mapcolor.colorValue) & 16777215;
|
| 76 | bufferedimage2.setRGB(l, k, j1 | l1);
|
| 77 | }
|
| 78 | }
|
| 79 | }
|
| 80 |
|
| 81 | bufferedimage.getGraphics().drawImage(bufferedimage2, 0, 0, (ImageObserver)null);
|
| 82 | }
|
| 83 | }
|
| 84 | }
|
| 85 | }
|
| 86 | catch (IOException ioexception)
|
| 87 | {
|
| 88 | LOG.error((String)"Couldn\'t load layered image", (Throwable)ioexception);
|
| 89 | return;
|
| 90 | }
|
| 91 |
|
| 92 | TextureUtil.uploadTextureImage(this.getGlTextureId(), bufferedimage);
|
| 93 | }
|
| 94 | }
|
| 95 |
|