103 lines
8.3 KiB
Java
103 lines
8.3 KiB
Java
import java.awt.*;
|
|
import java.awt.image.BufferedImage;
|
|
import javax.imageio.ImageIO;
|
|
import java.nio.file.*;
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.security.MessageDigest;
|
|
import java.util.*;
|
|
import java.util.zip.*;
|
|
import java.io.*;
|
|
|
|
/** Code-native corner badges. Existing item artwork is referenced, never repainted. */
|
|
class BuildEquipmentIconPack {
|
|
static final Map<Character,String[]> FONT=Map.of(
|
|
'0',new String[]{"111","101","101","101","111"},
|
|
'I',new String[]{"111","010","010","010","111"},
|
|
'V',new String[]{"101","101","101","101","010"},
|
|
'X',new String[]{"101","101","010","101","101"});
|
|
static String numeral(int mark){if(mark==0)return "0";String out="";for(var e:new Object[][]{{10,"X"},{9,"IX"},{5,"V"},{4,"IV"},{1,"I"}})while(mark>=(int)e[0]){out+=e[1];mark-=(int)e[0];}return out;}
|
|
static BufferedImage badge(int mark,Color colour){
|
|
var image=new BufferedImage(32,32,BufferedImage.TYPE_INT_ARGB);var g=image.createGraphics();
|
|
// Top-left quality diamond; bottom-left numeral avoids native count at bottom-right.
|
|
g.setColor(new Color(8,12,12,230));g.fillRect(0,0,7,7);
|
|
g.setColor(colour);for(int y=0;y<5;y++){int width=5-2*Math.abs(y-2);g.fillRect(1+(5-width)/2,y+1,width,1);}
|
|
String text=numeral(mark);int width=text.length()*4-1;
|
|
g.setColor(new Color(8,12,12,230));g.fillRect(0,23,width+2,7);
|
|
g.setColor(colour);for(int n=0;n<text.length();n++){String[] rows=FONT.get(text.charAt(n));for(int y=0;y<5;y++)for(int x=0;x<3;x++)if(rows[y].charAt(x)=='1')g.fillRect(1+n*4+x,24+y,1,1);}
|
|
g.dispose();return image;
|
|
}
|
|
static byte[] png(BufferedImage image)throws Exception{var out=new ByteArrayOutputStream();ImageIO.write(image,"png",out);return out.toByteArray();}
|
|
static String hash(byte[] data,String algorithm)throws Exception{return HexFormat.of().formatHex(MessageDigest.getInstance(algorithm).digest(data));}
|
|
static void put(Map<String,byte[]> entries,String key,String value){if(entries.containsKey(key))throw new IllegalStateException("Refuse existing model overwrite: "+key);entries.put(key,value.getBytes(StandardCharsets.UTF_8));}
|
|
static BufferedImage tooltip(boolean frame,Color accent){
|
|
var image=new BufferedImage(16,16,BufferedImage.TYPE_INT_ARGB);var g=image.createGraphics();
|
|
if(frame){
|
|
g.setColor(new Color(1,8,6,240));g.drawRect(0,0,15,15);
|
|
g.setColor(accent.darker());g.drawRect(1,1,13,13);
|
|
g.setColor(accent);g.drawLine(2,1,13,1);g.drawLine(1,2,1,13);
|
|
g.setColor(new Color(accent.getRed(),accent.getGreen(),accent.getBlue(),65));g.drawRect(2,2,11,11);
|
|
for(int x:new int[]{1,12})for(int y:new int[]{1,12}){g.setColor(accent);g.fillRect(x,y,3,3);g.setColor(accent.brighter());g.fillRect(x+1,y+1,1,1);}
|
|
}else{
|
|
g.setColor(new Color(5,23,18,250));g.fillRect(0,0,16,16);
|
|
g.setColor(new Color(accent.getRed()/8+5,accent.getGreen()/8+12,accent.getBlue()/8+9,250));g.fillRect(3,3,10,10);
|
|
// Subtle repeating architectural cross motif in the tiled centre.
|
|
g.setColor(new Color(accent.getRed(),accent.getGreen(),accent.getBlue(),9));g.drawLine(6,8,10,8);g.drawLine(8,6,8,10);
|
|
}
|
|
g.dispose();return image;
|
|
}
|
|
static BufferedImage panel(int kind,Color accent){
|
|
var image=new BufferedImage(176,11,BufferedImage.TYPE_INT_ARGB);var g=image.createGraphics();
|
|
boolean stats=kind>=5;Color edge=stats?Color.decode("#477d73"):accent;
|
|
Color fill=stats?Color.decode(kind==5?"#173d36":"#102b29"):new Color(18+accent.getRed()/18,27+accent.getGreen()/22,22+accent.getBlue()/20);
|
|
g.setColor(fill);g.fillRect(0,0,176,11);g.setColor(edge);
|
|
g.drawLine(0,0,0,10);g.drawLine(175,0,175,10);
|
|
if(kind==0||kind==1||kind==2||kind==5){g.drawLine(0,0,175,0);g.fillRect(0,0,2,2);g.fillRect(174,0,2,2);}
|
|
if(kind==0||kind==1||kind==4||kind==7){g.drawLine(0,10,175,10);g.fillRect(0,9,2,2);g.fillRect(174,9,2,2);}
|
|
g.dispose();return image;
|
|
}
|
|
public static void main(String[] args)throws Exception{
|
|
Path base=Path.of(args[0]),manifest=Path.of(args[1]),output=Path.of(args[2]);
|
|
byte[] original=Files.readAllBytes(base);
|
|
if(!hash(original,"SHA-256").equals("9844af32f7f299788f23035b2ce1e7b0337a90d07d4c9b712bf73b40c05b20e8"))throw new IllegalArgumentException("Expected audited v4 base pack");
|
|
var entries=new LinkedHashMap<String,byte[]>();try(var zip=new ZipInputStream(new ByteArrayInputStream(original))){ZipEntry e;while((e=zip.getNextEntry())!=null){if(entries.put(e.getName(),zip.readAllBytes())!=null)throw new IllegalStateException("Duplicate ZIP entry");}}
|
|
var preview=new BufferedImage(1024,488,BufferedImage.TYPE_INT_RGB);var g=preview.createGraphics();g.setColor(Color.decode("#0a2119"));g.fillRect(0,0,1024,488);g.setColor(Color.decode("#f1d592"));g.setFont(new Font(Font.SANS_SERIF,Font.BOLD,24));g.drawString("DuneRealms · Quality & Mark",24,33);
|
|
int count=0;var qualityColours=new LinkedHashMap<String,Color>();
|
|
for(String line:Files.readAllLines(manifest)){
|
|
if(line.isBlank())continue;String[] fields=line.split("\t");if(fields.length!=3)throw new IllegalArgumentException("Invalid badge manifest");
|
|
String quality=fields[0];int mark=Integer.parseInt(fields[1]);Color colour=Color.decode(fields[2]);
|
|
qualityColours.putIfAbsent(quality,colour);
|
|
if(mark<0||mark>14||!quality.matches("common|uncommon|rare|very_rare|legendary|mythic"))throw new IllegalArgumentException("Invalid quality/mark");
|
|
String name=quality+"_mk"+mark,texture="dunerealms:item/quality/"+name;
|
|
BufferedImage icon=badge(mark,colour);entries.put("assets/dunerealms/textures/item/quality/"+name+".png",png(icon));
|
|
for(String slot:new String[]{"helmet","chestplate","leggings","boots"}){
|
|
String model="equipment/"+name+"_"+slot;
|
|
put(entries,"assets/dunerealms/items/"+model+".json","{\"model\":{\"type\":\"minecraft:model\",\"model\":\"dunerealms:item/"+model+"\"}}");
|
|
put(entries,"assets/dunerealms/models/item/"+model+".json","{\"parent\":\"minecraft:item/generated\",\"textures\":{\"layer0\":\"minecraft:item/netherite_"+slot+"\",\"layer1\":\""+texture+"\"}}");
|
|
}
|
|
int x=24+(count%5)*200,y=60+(count/5)*104;g.setColor(Color.decode("#19372c"));g.fillRoundRect(x,y,184,90,8,8);
|
|
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);g.drawImage(icon,x+8,y+8,64,64,null);
|
|
g.setColor(colour);g.setFont(new Font(Font.SANS_SERIF,Font.BOLD,14));g.drawString(quality.replace('_',' ').toUpperCase(),x+76,y+28);g.setFont(new Font(Font.MONOSPACED,Font.BOLD,16));g.drawString("MK "+numeral(mark),x+76,y+50);count++;
|
|
}
|
|
if(count!=16)throw new IllegalArgumentException("Expected 15 MK tiers plus Mythic XIV");
|
|
for(var quality:qualityColours.entrySet())for(boolean frame:new boolean[]{false,true}){
|
|
String file="assets/dunerealms/textures/gui/sprites/tooltip/quality/"+quality.getKey()+(frame?"_frame":"_background")+".png";
|
|
entries.put(file,png(tooltip(frame,quality.getValue())));
|
|
put(entries,file+".mcmeta","{\"gui\":{\"scaling\":{\"type\":\"nine_slice\",\"width\":16,\"height\":16,\"border\":4,\"stretch_inner\":false}}}");
|
|
}
|
|
var font=new StringBuilder("{\"providers\":[");int q=0;boolean comma=false;
|
|
for(var quality:qualityColours.entrySet()){
|
|
for(int kind=0;kind<8;kind++){
|
|
String file="gui/lore_panels/"+quality.getKey()+"-"+kind+".png";
|
|
entries.put("assets/dunerealms/textures/"+file,png(panel(kind,quality.getValue())));
|
|
if(comma)font.append(',');comma=true;
|
|
font.append("{\"type\":\"bitmap\",\"file\":\"dunerealms:").append(file).append("\",\"ascent\":8,\"height\":11,\"chars\":[\"\\u").append(String.format("%04x",0xe900+q*8+kind)).append("\"]}");
|
|
}q++;
|
|
}
|
|
font.append(",{\"type\":\"space\",\"advances\":{\"\\ue9ff\":-177");
|
|
for(int advance=0;advance<=176;advance++)font.append(",\"\\u").append(String.format("%04x",0xea00+advance)).append("\":").append(advance);
|
|
font.append("}}]}");put(entries,"assets/dunerealms/font/lore_panels.json",font.toString());
|
|
g.dispose();Files.createDirectories(output.toAbsolutePath().getParent());ImageIO.write(preview,"png",output.resolveSibling("equipment-quality-palette.png").toFile());
|
|
try(var zip=new ZipOutputStream(Files.newOutputStream(output))){for(var e:entries.entrySet()){var ze=new ZipEntry(e.getKey());ze.setTime(0);zip.putNextEntry(ze);zip.write(e.getValue());zip.closeEntry();}}
|
|
var data=Files.readAllBytes(output);System.out.println("SHA1="+hash(data,"SHA-1"));System.out.println("SHA256="+hash(data,"SHA-256"));System.out.println("entries="+entries.size());
|
|
}
|
|
}
|

Staff