示例#1
0
  public void loadTexture(IResourceManager resourceManager) throws IOException {
    this.deleteGlTexture();
    BufferedImage bufferedimage = null;

    for (String s : this.layeredTextureNames) {
      IResource iresource = null;

      try {
        if (s != null) {
          iresource = resourceManager.getResource(new ResourceLocation(s));
          BufferedImage bufferedimage1 = TextureUtil.readBufferedImage(iresource.getInputStream());

          if (bufferedimage == null) {
            bufferedimage =
                new BufferedImage(bufferedimage1.getWidth(), bufferedimage1.getHeight(), 2);
          }

          bufferedimage.getGraphics().drawImage(bufferedimage1, 0, 0, (ImageObserver) null);
        }

        continue;
      } catch (IOException ioexception) {
        LOGGER.error((String) "Couldn\'t load layered image", (Throwable) ioexception);
      } finally {
        IOUtils.closeQuietly((Closeable) iresource);
      }

      return;
    }

    TextureUtil.uploadTextureImage(this.getGlTextureId(), bufferedimage);
  }
示例#2
0
  @Override
  public void onResourceManagerReload(IResourceManager resourcemanager) {
    clearCache();

    // Load Properties and Colors
    IResourceManager rm = FMLClientHandler.instance().getClient().getResourceManager();
    props.clear();
    try {
      List<IResource> robjs =
          rm.getAllResources(
              getResourceManual(
                  "properties.txt")); // TODO 1.7.2: Make sure these load in the correct order
      for (IResource res : robjs) {
        props.load(res.getInputStream());
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
示例#3
0
  public static boolean checkTexturePack(IResourceManager par1ResourceManager) {
    init();
    for (int i = 0; i < allow.size(); i++) {
      String file = allow.get(i);
      try {
        IResource res = par1ResourceManager.getResource(new ResourceLocation(file));
        InputStream stream = res.getInputStream();
        BufferedImage img = ImageIO.read(stream);
        int pixnb = countTransparentPixels(img);

        // System.out.println("Check texture " + i + " transparency : " + file + " = " + pixnb);

        if (pixnb > 0) {
          new JOptionPane();
          JOptionPane.showMessageDialog(new Frame(), warning, "Alkazia", 0);
          System.exit(0);
        }
      } catch (IOException e) {
        // System.out.println("Check texture " + i + " transparency : " + file + " not found");
      }
    }

    return true;
  }
示例#4
0
    public TIntArrayList gettIntArrayList(IResourceManager mgr) {
      if (cols != null) return cols;

      cols = new TIntArrayList();
      int mult = this.color & 0xFFFFFF;
      float mr = 1, mg = 1, mb = 1;

      boolean hasMultiplier = mult != 0xFFFFFF;
      if (hasMultiplier) {
        mr = ProcessedTexture.rgb.getRed(mult) / 255F;
        mg = ProcessedTexture.rgb.getGreen(mult) / 255F;
        mb = ProcessedTexture.rgb.getBlue(mult) / 255F;
      }

      ResourceLocation loc = new ResourceLocation(this.texture);

      IResource resource;
      try {
        resource = mgr.getResource(completeResourceLocation(loc, maps[this.type]));
      } catch (IOException err) {
        try {
          resource = mgr.getResource(completeResourceLocation(loc, maps[this.type ^ 1]));
        } catch (IOException err2) {
          resource = null;
        }
      }

      if (resource != null) {
        InputStream inputStream = null;

        try {
          inputStream = resource.getInputStream();
          BufferedImage img2 = ImageIO.read(inputStream);
          int w = img2.getWidth();
          int h = img2.getHeight();
          int[] colorData = new int[w * h];
          img2.getRGB(0, 0, w, h, colorData, 0, w);
          for (int col : colorData) {
            if (ProcessedTexture.rgb.getAlpha(col) > 10) {
              int val = ProcessedTexture.makeSolidAlpha(col);
              if (hasMultiplier) {
                int r = (int) (ProcessedTexture.rgb.getRed(col) * mr);
                int g = (int) (ProcessedTexture.rgb.getGreen(col) * mg);
                int b = (int) (ProcessedTexture.rgb.getBlue(col) * mb);
                val = 0xFF000000 | (r << 16) | (g << 8) | (b);
              }

              cols.add(val);
            }
          }
        } catch (IOException ignore) {

        } finally {
          if (inputStream != null)
            try {
              inputStream.close();
            } catch (IOException ignore) {

            }
        }
      }
      return cols;
    }
示例#5
0
  public boolean load(IResourceManager manager, ResourceLocation location) {

    // get mipmapping level
    int mp = Minecraft.getMinecraft().gameSettings.mipmapLevels;

    // creates a buffer that will be used for our texture and the
    // various mip-maps
    // (mip-mapping is where you use smaller textures when objects are
    // far-away
    // see: http://en.wikipedia.org/wiki/Mipmap)
    // these will be generated from the base texture by Minecraft
    BufferedImage[] ore_image = new BufferedImage[1 + mp];

    BufferedImage stone_image;
    int w;

    AnimationMetadataSection animation;

    PngSizeInfo sizeInfo;

    try {
      IResource iresource = manager.getResource(getBlockResource(name));
      IResource iresourceBase = manager.getResource(getBlockResource(base));

      sizeInfo = new PngSizeInfo(manager.getResource(getBlockResource(name)).getInputStream());

      // load the ore texture
      BufferedImage read = ImageIO.read(iresource.getInputStream());
      ore_image[0] = read;

      // load animation
      animation = iresource.getMetadata("animation");

      // load the stone texture
      stone_image = ImageIO.read(iresourceBase.getInputStream());

      w = ore_image[0].getWidth();

      if (stone_image.getWidth() != w) {
        List resourcePacks = manager.getAllResources(getBlockResource(base));
        for (int i = resourcePacks.size() - 1; i >= 0; --i) {
          IResource resource = (IResource) resourcePacks.get(i);
          stone_image = ImageIO.read(resource.getInputStream());

          if (stone_image.getWidth() == w) break;
        }
      }
    } catch (IOException e) {
      e.printStackTrace();
      return true;
    }

    if (stone_image.getWidth() != w) {
      LogHelper.error(
          "Error generating texture" + name + ". Unable to find base texture with same size.");
      return true;
    }

    int h = ore_image[0].getHeight();

    // create an ARGB output image that will be used as our texture
    BufferedImage output_image = new BufferedImage(w, h, 2);

    // create some arrays t hold the pixel data
    // pixel data is in the form 0xaarrggbb
    int[] ore_data = new int[w * w];
    int[] stone_data = new int[w * w];

    stone_image.getRGB(0, 0, w, w, stone_data, 0, w);

    for (int y = 0; y < h; y += w) {
      // read the ARGB color data into our arrays
      ore_image[0].getRGB(0, y, w, w, ore_data, 0, w);

      // generate our new texture
      int[] new_data = createDenseTexture(w, ore_data, stone_data, renderType);

      // write the new image data to the output image buffer
      output_image.setRGB(0, y, w, w, new_data, 0, w);
    }

    // replace the old texture
    ore_image[0] = output_image;

    // load the texture
    try {
      this.loadSprite(sizeInfo, animation != null);
      ByteArrayOutputStream stream = new ByteArrayOutputStream();

      ImageIO.write(output_image, "PNG", stream);

      byte[] bytes = stream.toByteArray();
      this.loadSpriteFrames(
          new IResource() {
            @Nonnull
            @Override
            public ResourceLocation getResourceLocation() {
              return location;
            }

            @Nonnull
            @Override
            public InputStream getInputStream() {
              return new ByteArrayInputStream(bytes);
            }

            @Override
            public boolean hasMetadata() {
              return true;
            }

            @Nullable
            @Override
            public <T extends IMetadataSection> T getMetadata(String sectionName) {
              if ("animation".equals(sectionName)) {
                return (T) animation;
              }
              return null;
            }

            @Nonnull
            @Override
            public String getResourcePackName() {
              return "test";
            }

            @Override
            public void close() throws IOException {}
          },
          mp + 1);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }

    LogHelper.trace(
        "Dense Ores: Succesfully generated dense ore texture for '"
            + name
            + "' with background '"
            + base
            + "'. Place "
            + name
            + "_dense.png in the assets folder to override.");
    return false;
  }
  /**
   * Imports resources using the metadata from a resource pack.
   *
   * @param manager - the resource manager to use
   * @param data - the metadata that contains the resource names
   */
  private void importResources(IResourceManager manager, ModbuilderResource data) {
    ResourceDeserializer deserializer = new ResourceDeserializer();
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(BaseItemResource.class, deserializer);
    builder.registerTypeAdapter(BaseBlockResource.class, deserializer);
    builder.registerTypeAdapter(BaseStructureResource.class, deserializer);
    builder.registerTypeAdapter(BaseRecipe.class, deserializer);
    Gson gson = builder.create();

    Map<String, BaseBlockResource> blockResources = new HashMap<String, BaseBlockResource>();
    Map<String, BaseItemResource> itemResources = new HashMap<String, BaseItemResource>();
    for (String path : data.blocks) {
      try {
        ResourceLocation location =
            new ResourceLocation(BuilderMod.MODID + ":blocks/" + path + ".json");
        IResource resource = manager.getResource(location);
        BaseBlockResource blockResource =
            gson.fromJson(
                new InputStreamReader(resource.getInputStream()), BaseBlockResource.class);
        Block block = ResourceConverter.toEmptyBlock(blockResource);
        block.setUnlocalizedName(BuilderMod.MODID + "_" + path);
        if (!registeredBlocks.contains(path)) {
          registeredBlocks.add(path);
          blockModels.put(block, blockResource.model);
          customBlocks.put(path, block);
          blockResources.put(path, blockResource);
        }
      } catch (IOException e) {
        // ignore
      }
    }

    for (String path : data.items) {
      try {
        ResourceLocation location =
            new ResourceLocation(BuilderMod.MODID + ":items/" + path + ".json");
        IResource resource = manager.getResource(location);
        BaseItemResource itemResource =
            gson.fromJson(new InputStreamReader(resource.getInputStream()), BaseItemResource.class);
        Item item = ResourceConverter.toEmptyItem(itemResource);
        item.setUnlocalizedName(BuilderMod.MODID + "_" + path);
        if (!registeredItems.contains(path)) {
          registeredItems.add(path);
          itemModels.put(item, itemResource.model);
          customItems.put(path, item);
          itemResources.put(path, itemResource);
        }
      } catch (IOException e) {
        // ignore
      }
    }

    for (String path : blockResources.keySet()) {
      BaseBlockResource resource = blockResources.get(path);
      Block block = ResourceConverter.toBlock(customBlocks.get(path), resource);
      GameRegistry.registerBlock(block, path);
      if (resource.burntime != null) fuels.put(Item.getItemFromBlock(block), resource.burntime);
    }

    for (String path : itemResources.keySet()) {
      BaseItemResource resource = itemResources.get(path);
      Item item = ResourceConverter.toItem(customItems.get(path), resource);
      GameRegistry.registerItem(item, path);
      if (resource.burntime != null) fuels.put(item, resource.burntime);
    }

    for (String path : data.structures) {
      try {
        ResourceLocation location =
            new ResourceLocation(BuilderMod.MODID + ":structures/" + path + ".json");
        IResource resource = manager.getResource(location);
        BaseStructureResource structureResource =
            gson.fromJson(
                new InputStreamReader(resource.getInputStream()), BaseStructureResource.class);
        BuilderStruct structure = ResourceConverter.toStructure(structureResource);
        if (!registeredStructures.contains(path)) {
          registeredStructures.add(path);
          registry.structs.add(structure);
        }
      } catch (IOException e) {
        // ignore
      }
    }

    for (String path : data.recipes) {
      try {
        ResourceLocation location =
            new ResourceLocation(BuilderMod.MODID + ":recipes/" + path + ".json");
        String s = location.getResourcePath();
        IResource resource = manager.getResource(location);
        BaseRecipe recipe =
            gson.fromJson(new InputStreamReader(resource.getInputStream()), BaseRecipe.class);
        RecipeRegistry.register(recipe);
      } catch (IOException e) {
        // ignore
      }
    }
  }