diff options
author | Lyft <127234178+Lyfts@users.noreply.github.com> | 2024-09-28 16:33:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-28 14:33:57 +0000 |
commit | e08a304cd38f54d023a9ac4534bcd20d10cdd7c9 (patch) | |
tree | 7b5b6eec14c969038d5f25cb3129f8b800d43c3a /src/main/java/gregtech/common | |
parent | b8eac286d452e9b0ab1c16cd12524c47c25c6d94 (diff) | |
download | GT5-Unofficial-e08a304cd38f54d023a9ac4534bcd20d10cdd7c9.tar.gz GT5-Unofficial-e08a304cd38f54d023a9ac4534bcd20d10cdd7c9.tar.bz2 GT5-Unofficial-e08a304cd38f54d023a9ac4534bcd20d10cdd7c9.zip |
Give ore mixes localized names (#3290)
Co-authored-by: Martin Robertz <dream-master@gmx.net>
Diffstat (limited to 'src/main/java/gregtech/common')
-rw-r--r-- | src/main/java/gregtech/common/OreMixBuilder.java | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/src/main/java/gregtech/common/OreMixBuilder.java b/src/main/java/gregtech/common/OreMixBuilder.java index cd8d14c884..86453ca0a8 100644 --- a/src/main/java/gregtech/common/OreMixBuilder.java +++ b/src/main/java/gregtech/common/OreMixBuilder.java @@ -1,5 +1,6 @@ package gregtech.common; +import java.util.Arrays; import java.util.HashMap; import java.util.Map; @@ -16,7 +17,8 @@ public class OreMixBuilder { public boolean enabledByDefault = true; public Map<String, Boolean> dimsEnabled = new HashMap<>(); public int minY, maxY, weight, density, size; - public Materials primary, secondary, between, sporadic; + public Materials primary, secondary, between, sporadic, representative; + public String localizedName; public OreMixBuilder name(String name) { this.oreMixName = name; @@ -65,6 +67,10 @@ public class OreMixBuilder { public OreMixBuilder primary(Materials primary) { this.primary = primary; + if (representative == null || localizedName == null) { + representative = primary; + localizedName = primary.mLocalizedName; + } return this; } @@ -83,4 +89,31 @@ public class OreMixBuilder { return this; } + /** + * Sets the localized name for the ore mix based on the provided materials. + * If more than one material is provided, their localized names are concatenated + * with commas, last comma is replaced by "&". + * + * @param materials The materials to be used for localization. The first material + * in the array will be used to represent to ore mix in GUI's. + * If none are provided the {@link #primary} will be used. + */ + public OreMixBuilder localize(Materials... materials) { + if (materials.length > 1) { + String localizedName = String.join( + ", ", + Arrays.stream(materials) + .map(material -> material.mLocalizedName) + .toArray(String[]::new)); + int index = localizedName.lastIndexOf(", "); + if (index != -1) { + localizedName = localizedName.substring(0, index) + " & " + localizedName.substring(index + 2); + } + this.localizedName = localizedName; + } else { + this.localizedName = materials[0].mLocalizedName; + } + this.representative = materials[0]; + return this; + } } |