Add files via upload

master
Lars Müller 2018-08-15 20:48:11 +02:00 committed by GitHub
parent db949a9bf9
commit 45612344a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 137 additions and 0 deletions

57
MithrilGalvorn.java Normal file
View File

@ -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));
}
}
}
}
}
}

80
TPCreator.java Normal file
View File

@ -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<String,Color> 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());}
}
}
}
}