From 45612344a91cec0c4b358672a851c212c06fb84d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20M=C3=BCller?= <34514239+appgurueu@users.noreply.github.com> Date: Wed, 15 Aug 2018 20:48:11 +0200 Subject: [PATCH] Add files via upload --- MithrilGalvorn.java | 57 ++++++++++++++++++++++++++++++++ TPCreator.java | 80 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 137 insertions(+) create mode 100644 MithrilGalvorn.java create mode 100644 TPCreator.java diff --git a/MithrilGalvorn.java b/MithrilGalvorn.java new file mode 100644 index 0000000..0a70143 --- /dev/null +++ b/MithrilGalvorn.java @@ -0,0 +1,57 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package mithrilgalvorn; + +import java.awt.Color; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import javax.imageio.ImageIO; + +/** + * + * @author lars + */ +public class MithrilGalvorn { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) throws IOException { + // TODO code application logic here + String[][] parts = {{"3d_armor", "chestplate", "leggings", "boots", "helmet"}, {"shields", "shield"}}; + Object[][] colors = {{"mithril", 300, 300, 255}, {"galvorn", 33, 33, 33}}; + for (String[] pa: parts) { + for (int i = 1; i < pa.length; i++) { + String p=pa[i]; + for (String suffix : new String[]{".png", "_preview.png"}) { + String file = pa[0]+"_" + p + "_steel" + suffix; + System.out.println(System.getProperty("user.home") + "/.minetest/games/magicctf/mods/"+pa[0]+"/textures/" + file); + BufferedImage im = ImageIO.read(new File(System.getProperty("user.home") + "/.minetest/games/magicctf/mods/"+pa[0]+"/textures/" + file)); + for (Object[] o : colors) { + BufferedImage res = new BufferedImage(im.getWidth(), im.getHeight(), BufferedImage.TYPE_INT_ARGB); + for (int x = 0; x < im.getWidth(); x++) { + for (int y = 0; y < im.getHeight(); y++) { + Color col = new Color(im.getRGB(x, y), true); + float r = Math.min(1, ((int) (o[1]) / 255.0f) * (float) col.getRed() / 255.0f); + float g = Math.min(1, ((int) (o[2]) / 255.0f) * (float) col.getGreen() / 255.0f); + float b = Math.min(1, ((int) (o[3]) / 255.0f) * (float) col.getBlue() / 255.0f); + if (col.getAlpha() != 0 && col.getRed() != 0 && col.getBlue() != 0 && col.getGreen() != 0) { + col = new Color(r, g, b, col.getAlpha() / 255.0f); + } else { + col = new Color(0, 0, 0, 0); + } + res.setRGB(x, y, col.getRGB()); + } + } + ImageIO.write(res, "PNG", new File(System.getProperty("user.home") + "/.minetest/games/magicctf/mods/"+pa[0]+"/textures/"+pa[0]+"_" + p + "_" + o[0].toString() + suffix)); + } + } + } + } + } + +} diff --git a/TPCreator.java b/TPCreator.java new file mode 100644 index 0000000..8363c37 --- /dev/null +++ b/TPCreator.java @@ -0,0 +1,80 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package appguru; + +import java.awt.Color; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import java.util.HashMap; +import javax.imageio.ImageIO; + +/** + * + * @author lars + */ +public class TPCreator { + + public static HashMap overlays=new HashMap(); + static { + overlays.put("default_fence_overlay.png",new Color(255,126,126)); + overlays.put("farming_cotton.png",new Color(0,0,0)); + } + /** + * @param args the command line arguments + */ + public static void main(String[] args) throws IOException { + File[] mods=new File(System.getProperty("user.home")+"/.minetest/games/magicctf/mods").listFiles(); + float REDUCE=8; + for (File mod:mods) { + File tex=new File(mod.getCanonicalPath()+File.separator+"textures"); + if (!tex.exists()) { + continue; + } + + for (File img:tex.listFiles()) { + Color c=overlays.get(img.getName()); + BufferedImage image=ImageIO.read(img); + if (image==null) { System.out.println(img);continue; } + String ext=""; + + for (int i=img.getName().length()-1; i > -1; i--) { + if (img.getName().charAt(i) == '.') { + break; + } + ext=img.getName().charAt(i)+ext; + } + BufferedImage result; + if (ext.equals("png")) { + result=new BufferedImage(image.getWidth(),image.getHeight(),BufferedImage.TYPE_INT_ARGB); + } + else { + result=new BufferedImage(image.getWidth(),image.getHeight(),BufferedImage.TYPE_INT_RGB); + } + try { + for (int x=0; x < image.getWidth(); x++) { + for (int y=0; y < image.getHeight(); y++) { + Color col=new Color(image.getRGB(x, y),true); + if (!(c != null && c.getRed() == col.getRed() && c.getBlue() == col.getBlue() && c.getGreen() == col.getGreen()) && col.getAlpha() != 0) { + float r=Math.round(col.getRed()/255.0f*REDUCE)/REDUCE; + float g=Math.round(col.getGreen()/255.0f*REDUCE)/REDUCE; + float b=Math.round(col.getBlue()/255.0f*REDUCE)/REDUCE; + col=new Color(r,g,b,col.getAlpha()/255.0f); + } + else { col=new Color(0,0,0,0); } + result.setRGB(x,y,col.getRGB()); + } + } + } catch (Exception e) {System.out.println(img.getName());continue;} + try { + if (!ImageIO.write(result, ext, new File(System.getProperty("user.home")+"/.minetest/textures/High Contrast/"+img.getName()))) { System.out.println("FAIL"); } + + } catch (Exception e) {System.out.println(img.getName());} + } + } + } + +}