Skip to content

Commit

Permalink
merge two toString
Browse files Browse the repository at this point in the history
Signed-off-by: Glease <4586901+Glease@users.noreply.github.com>
  • Loading branch information
Glease committed Jan 4, 2023
1 parent 4cf2a40 commit 1809a33
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/main/java/gregtech/api/enums/Materials.java
Original file line number Diff line number Diff line change
Expand Up @@ -1467,7 +1467,7 @@ public Materials(
aColor);
mExtraData = aExtraData;
mMaterialList.addAll(aMaterialList);
if (mMaterialList.size() == 1) mChemicalFormula = mMaterialList.get(0).toStringSingle();
if (mMaterialList.size() == 1) mChemicalFormula = mMaterialList.get(0).toString(true);
else
mChemicalFormula = mMaterialList.stream()
.map(MaterialStack::toString)
Expand Down
18 changes: 5 additions & 13 deletions src/main/java/gregtech/api/objects/MaterialStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,29 +40,21 @@ public boolean equals(Object aObject) {

@Override
public String toString() {
return toString(false);
}

public String toString(boolean single) {
String temp1 = "", temp2 = mMaterial.getToolTip(true), temp3 = "", temp4 = "";
if (mAmount > 1) {
temp4 = GT_Utility.toSubscript(mAmount);
}
if (mMaterial.mMaterialList.size() > 1 || isMaterialListComplex(this)) {
if ((!single || mAmount > 1) && isMaterialListComplex(this)) {
temp1 = "(";
temp3 = ")";
}
return temp1 + temp2 + temp3 + temp4;
}

public String toStringSingle() {
String temp1 = "", temp2 = mMaterial.getToolTip(true), temp3 = "", temp4 = "";
if (mAmount > 1) {
temp4 = GT_Utility.toSubscript(mAmount);
if (mMaterial.mMaterialList.size() > 1 || isMaterialListComplex(this)) {
temp1 = "(";
temp3 = ")";
}
}
return temp1 + temp2 + temp3 + temp4;
}

private boolean isMaterialListComplex(MaterialStack materialStack) {
if (materialStack.mMaterial.mMaterialList.size() > 1) {
return true;
Expand Down

0 comments on commit 1809a33

Please sign in to comment.