Skip to content

Commit 7378aa5

Browse files
committed
Update banners for 1.21 tags
1 parent b88dd66 commit 7378aa5

File tree

1 file changed

+126
-103
lines changed

1 file changed

+126
-103
lines changed

Diff for: src/org/jmc/models/Banner.java

+126-103
Original file line numberDiff line numberDiff line change
@@ -33,60 +33,57 @@ public class Banner extends BlockModel {
3333
* Pattern Layer List
3434
* */
3535

36-
private static Set<NamespaceID> exportedMaterials = new HashSet<>();
36+
private static final Set<NamespaceID> exportedMaterials = new HashSet<>();
3737

3838
private static boolean firstReadError = true;
3939
/**
4040
* Class for Banner Pattern Layer
4141
*/
4242
public static class BannerPattern {
4343

44-
private int color = 0;
45-
private String pattern = "";
44+
private String color = "white";
45+
private NamespaceID pattern = NamespaceID.fromString("base");
4646

47-
public int getColor() {
47+
public String getColor() {
4848
return color;
4949
}
5050

51-
public void setColor(int color) {
51+
public void setColor(String color) {
5252
this.color = color;
5353
}
5454

55-
public String getPattern() {
55+
public NamespaceID getPattern() {
5656
return pattern;
5757
}
5858

59-
public void setPattern(String pattern) {
59+
public void setPattern(NamespaceID pattern) {
6060
this.pattern = pattern;
6161
}
6262

6363
public String toString() {
64-
return this.pattern + this.color;
64+
return this.pattern.path + "_" + this.color;
6565
}
6666
}
6767

6868
/**
6969
* Creates a uniq string for combination of patterns
7070
* @return
7171
*/
72-
private String createPatternHash(int baseColorIndex, ArrayList<BannerPattern> patternList) {
73-
String hashSource = "";// + baseColorIndex + "";
72+
private String createPatternHash(ArrayList<BannerPattern> patternList) {
73+
StringBuilder hashSource = new StringBuilder();
7474
int count = 0;
7575
for (BannerPattern bp : patternList) {
7676
if (count++ != 0) {
77-
hashSource += "-";
77+
hashSource.append("-");
7878
}
79-
hashSource += bp.toString();
79+
hashSource.append(bp.toString());
8080
}
81-
return hashSource;
81+
return hashSource.toString();
8282
}
8383

8484
@Override
8585
public void addModel(ChunkProcessor obj, ThreadChunkDeligate chunks, int x, int y, int z, BlockData data, NamespaceID biome) {
8686

87-
//Log.info("Banner ***************************");
88-
89-
9087
// get banner type from block config
9188
String bannerType = getConfigNodeValue("bannertype", 0);
9289
if (bannerType == null)
@@ -142,70 +139,63 @@ public void addModel(ChunkProcessor obj, ThreadChunkDeligate chunks, int x, int
142139
}
143140
};
144141

145-
int baseColorIndex = -1;
146142
ArrayList<BannerPattern> patternList = new ArrayList<BannerPattern>();
147-
148-
String bid = data.id.path;
149-
if (bid.startsWith("white"))
150-
baseColorIndex = 0;
151-
else if (bid.startsWith("orange"))
152-
baseColorIndex = 1;
153-
else if (bid.startsWith("magenta"))
154-
baseColorIndex = 2;
155-
else if (bid.startsWith("light_blue"))
156-
baseColorIndex = 3;
157-
else if (bid.startsWith("yellow"))
158-
baseColorIndex = 4;
159-
else if (bid.startsWith("lime"))
160-
baseColorIndex = 5;
161-
else if (bid.startsWith("pink"))
162-
baseColorIndex = 6;
163-
else if (bid.startsWith("gray"))
164-
baseColorIndex = 7;
165-
else if (bid.startsWith("light_gray"))
166-
baseColorIndex = 8;
167-
else if (bid.startsWith("cyan"))
168-
baseColorIndex = 9;
169-
else if (bid.startsWith("purple"))
170-
baseColorIndex = 10;
171-
else if (bid.startsWith("blue"))
172-
baseColorIndex = 11;
173-
else if (bid.startsWith("brown"))
174-
baseColorIndex = 12;
175-
else if (bid.startsWith("green"))
176-
baseColorIndex = 13;
177-
else if (bid.startsWith("red"))
178-
baseColorIndex = 14;
179-
else if (bid.startsWith("black"))
180-
baseColorIndex = 15;
181-
182-
// base Color
143+
144+
String baseColor;
145+
String bid = data.id.path;
146+
if (bid.endsWith("_standing_banner")) {
147+
baseColor = bid.replace("_standing_banner", "");
148+
} else if (bid.endsWith("_wall_banner")) {
149+
baseColor = bid.replace("_wall_banner", "");
150+
} else if (bid.endsWith("_banner")) {
151+
baseColor = bid.replace("_banner", "");
152+
} else {
153+
Log.debugOnce("Unable to get base banner color from id! " + bid);
154+
baseColor = "white";
155+
}
156+
157+
// base Color
183158
BannerPattern bpBase = new BannerPattern();
184-
bpBase.setColor(baseColorIndex);
185-
bpBase.setPattern("base");
159+
bpBase.setColor(baseColor);
160+
bpBase.setPattern(NamespaceID.fromString("base"));
186161
patternList.add(bpBase);
187162

188163
// get banner layer information
189164
TAG_Compound tag = chunks.getTileEntity(x, y, z);
190-
if (tag != null) {
191-
TAG_List patternsTag = (TAG_List) tag.getElement("Patterns");
192-
193-
if (patternsTag != null) {
194-
for (NBT_Tag pattern : patternsTag.elements) {
195-
TAG_Compound c_pattern = (TAG_Compound) pattern;
196-
BannerPattern bp = new BannerPattern();
197-
bp.setColor((int) ((TAG_Int) c_pattern.getElement("Color")).value);
198-
bp.setPattern((String) ((TAG_String) c_pattern.getElement("Pattern")).value);
199-
patternList.add(bp);
200-
}
201-
}
202-
}
165+
if (tag != null) {
166+
TAG_List patternsTag = (TAG_List) tag.getElement("patterns");
167+
if (patternsTag == null) {
168+
patternsTag = (TAG_List) tag.getElement("Patterns");
169+
}
170+
if (patternsTag != null) {
171+
for (NBT_Tag pattern : patternsTag.elements) {
172+
TAG_Compound c_pattern = (TAG_Compound) pattern;
173+
BannerPattern bp = new BannerPattern();
174+
175+
NBT_Tag colorTag = c_pattern.getElement("color");
176+
if (colorTag != null) {
177+
bp.setColor(((TAG_String) colorTag).value);
178+
} else {
179+
int colorId = ((TAG_Int) c_pattern.getElement("Color")).value;
180+
bp.setColor(colorIdToName(colorId));
181+
}
182+
183+
TAG_String patternTag = (TAG_String) c_pattern.getElement("pattern");
184+
if (patternTag != null) {
185+
bp.setPattern(NamespaceID.fromString(patternTag.value));
186+
} else {
187+
patternTag = (TAG_String) c_pattern.getElement("Pattern");
188+
// put old name patterns under jmc to be picked up later
189+
bp.setPattern(new NamespaceID("jmc2obj", patternTag.value));
190+
}
191+
192+
patternList.add(bp);
193+
}
194+
}
195+
}
203196

204197
// use material hash (to generate unique material name and images)
205-
String bannerTexName = "banner_";
206-
if (baseColorIndex > -1) {
207-
bannerTexName+= createPatternHash(baseColorIndex, patternList);
208-
}
198+
String bannerTexName = "banner_" + createPatternHash(patternList);
209199
NamespaceID bannerTexId = new NamespaceID("jmc2obj", "banner/" + bannerTexName);
210200

211201

@@ -242,9 +232,6 @@ private boolean generateBannerImage(NamespaceID materialImageName, ArrayList<Ban
242232
return false;
243233
}
244234
if (backgroundImage == null) return false;
245-
246-
// todo - do something with the basecolor here...
247-
// Log.info(" - Base Color: " + baseColorIndex);
248235

249236
// create a new image (this one is the target!)
250237
BufferedImage combined = new BufferedImage(backgroundImage.getWidth(), backgroundImage.getHeight(), BufferedImage.TYPE_INT_ARGB);
@@ -258,7 +245,14 @@ private boolean generateBannerImage(NamespaceID materialImageName, ArrayList<Ban
258245
// pattern source image
259246
BufferedImage patternSource;
260247
try {
261-
TextureEntry te = Registries.getTexture(new NamespaceID("jmc2obj", "banner/pattern_" + bp.getPattern()));
248+
TextureEntry te;
249+
NamespaceID patternName = bp.getPattern();
250+
if (patternName.namespace.equals("jmc2obj")) {
251+
// old style pattern names get found by textures.json source id override
252+
te = Registries.getTexture(new NamespaceID("jmc2obj", "banner/pattern_" + patternName.path));
253+
} else {
254+
te = Registries.getTexture(new NamespaceID("minecraft", "entity/banner/" + patternName.path));
255+
}
262256
if (te == null) return false;
263257
patternSource = te.getImage();
264258
} catch (IOException e) {
@@ -270,7 +264,7 @@ private boolean generateBannerImage(NamespaceID materialImageName, ArrayList<Ban
270264
BufferedImage patternImage = new BufferedImage(patternSource.getWidth(), patternSource.getHeight(), BufferedImage.TYPE_INT_ARGB);
271265

272266
// draw into layer..
273-
Color layerColor = getColorById(bp.getColor());
267+
Color layerColor = getColorByName(bp.getColor());
274268
float layerComps[] = layerColor.getComponents(null);
275269

276270
for(int x=0; x<patternSource.getWidth(); x++) {
@@ -315,33 +309,62 @@ private boolean generateBannerImage(NamespaceID materialImageName, ArrayList<Ban
315309
}
316310

317311
/**
318-
* Banner Pattern colorId to rgb
319-
* @param colorId
320-
* @return
312+
* Banner Pattern colorName to rgb
313+
* @param colorName
314+
* @return the Color for the color name
321315
*/
322-
private Color getColorById(int colorId) {
323-
Color mappedColor = new Color(0, 0, 0);
324-
325-
switch(colorId) {
326-
case 0: mappedColor = new Color(255, 255, 255); break;//White
327-
case 1: mappedColor = new Color(216, 127, 51); break;//Orange
328-
case 2: mappedColor = new Color(178, 76, 216); break;//Magenta
329-
case 3: mappedColor = new Color(80, 153, 216); break;//Light Blue
330-
case 4: mappedColor = new Color(229, 200, 51); break;//Yellow
331-
case 5: mappedColor = new Color(120, 190, 23); break;//Lime
332-
case 6: mappedColor = new Color(242, 127, 165); break;//Pink
333-
case 7: mappedColor = new Color(76, 76, 76); break;//Grey
334-
case 8: mappedColor = new Color(153, 153, 153); break;//Light Grey
335-
case 9: mappedColor = new Color(76, 127, 153); break;//Cyan
336-
case 10: mappedColor = new Color(127, 63, 178); break;//Purple
337-
case 11: mappedColor = new Color(51, 76, 178); break;//Blue
338-
case 12: mappedColor = new Color(102, 76, 51); break;//Brown
339-
case 13: mappedColor = new Color(102, 127, 51); break;//Green
340-
case 14: mappedColor = new Color(153, 51, 51); break;//Red
341-
case 15: mappedColor = new Color(0, 0, 0); break;//Blacke
342-
}
343-
return mappedColor;
344-
}
316+
private Color getColorByName(String colorName) {
317+
switch(colorName) {
318+
case "white": return new Color(255, 255, 255);
319+
case "orange": return new Color(216, 127, 51);
320+
case "magenta": return new Color(178, 76, 216);
321+
case "light_blue": return new Color(80, 153, 216);
322+
case "yellow": return new Color(229, 200, 51);
323+
case "lime": return new Color(120, 190, 23);
324+
case "pink": return new Color(242, 127, 165);
325+
case "gray": return new Color(76, 76, 76);
326+
case "light_gray": return new Color(153, 153, 153);
327+
case "cyan": return new Color(76, 127, 153);
328+
case "purple": return new Color(127, 63, 178);
329+
case "blue": return new Color(51, 76, 178);
330+
case "brown": return new Color(102, 76, 51);
331+
case "green": return new Color(102, 127, 51);
332+
case "red": return new Color(153, 51, 51);
333+
case "black": return new Color(0, 0, 0);
334+
default:
335+
Log.errorOnce("Unknown banner color " + colorName, null, false);
336+
return new Color(255, 0, 0);
337+
}
338+
}
339+
340+
/**
341+
* Banner Pattern colorId to name
342+
* @param colorId
343+
* @return name of the color id
344+
*/
345+
private String colorIdToName(int colorId) {
346+
switch(colorId) {
347+
case 0: return "white";
348+
case 1: return "orange";
349+
case 2: return "magenta";
350+
case 3: return "light_blue";
351+
case 4: return "yellow";
352+
case 5: return "lime";
353+
case 6: return "pink";
354+
case 7: return "gray";
355+
case 8: return "light_gray";
356+
case 9: return "cyan";
357+
case 10: return "purple";
358+
case 11: return "blue";
359+
case 12: return "brown";
360+
case 13: return "green";
361+
case 14: return "red";
362+
case 15: return "black";
363+
default:
364+
Log.errorOnce("Unknown banner colorID " + colorId, null, false);
365+
return "black";
366+
}
367+
}
345368

346369
/**
347370
* Add Banner to Outputfile

0 commit comments

Comments
 (0)