Skip to content

Commit

Permalink
Rename MaterialId::tryCreate to tryParse
Browse files Browse the repository at this point in the history
More consistent with the Mojmap name
  • Loading branch information
KnightMiner committed Feb 6, 2022
1 parent 23b7244 commit 05f009e
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public Object getCacheKey(IToolStackView tool, ModifierEntry entry) {
private static MaterialId getMaterial(IToolStackView tool, Modifier modifier) {
String material = tool.getPersistentData().getString(modifier.getId());
if (!material.isEmpty()) {
return MaterialId.tryCreate(material);
return MaterialId.tryParse(material);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public boolean matches(ItemStack stack) {
* @return Material ID, or null if invalid
*/
@Nullable
public static MaterialId tryCreate(String string) {
public static MaterialId tryParse(String string) {
try {
return new MaterialId(string);
} catch (ResourceLocationException resourcelocationexception) {
Expand All @@ -54,7 +54,7 @@ public static MaterialId tryCreate(String string) {

/** Shared logic for {@link #fromJson(JsonObject, String)} and {@link #convertJson(JsonElement, String)} */
private static MaterialId parse(String text, String key) {
MaterialId location = tryCreate(text);
MaterialId location = tryParse(text);
if (location == null) {
throw new JsonSyntaxException("Expected " + key + " to be a Resource location, was '" + text + "'");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public static void addDefaultSubItems(IModifiable item, List<ItemStack> itemList
String showOnlyId = Config.COMMON.showOnlyToolMaterial.get();
boolean added = false;
if (!showOnlyId.isEmpty()) {
MaterialId materialId = MaterialId.tryCreate(showOnlyId);
MaterialId materialId = MaterialId.tryParse(showOnlyId);
if (materialId != null) {
IMaterial material = MaterialRegistry.getMaterial(materialId);
if (material != IMaterial.UNKNOWN) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static MaterialIdNBT readFromNBT(@Nullable Tag nbt) {

List<MaterialId> materials = listNBT.stream()
.map(Tag::getAsString)
.map(MaterialId::tryCreate)
.map(MaterialId::tryParse)
.filter(Objects::nonNull)
.collect(Collectors.toList());
return new MaterialIdNBT(materials);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public static MaterialNBT readFromNBT(@Nullable Tag nbt) {

List<IMaterial> materials = listNBT.stream()
.map(Tag::getAsString)
.map(MaterialId::tryCreate)
.map(MaterialId::tryParse)
.filter(Objects::nonNull)
.map(MaterialRegistry::getMaterial)
.collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private static Optional<MaterialId> getMaterialId(@Nullable CompoundTag nbt) {
return Optional.ofNullable(nbt)
.map(compoundNBT -> compoundNBT.getString(NBTTags.PART_MATERIAL))
.filter(string -> !string.isEmpty())
.map(MaterialId::tryCreate);
.map(MaterialId::tryParse);
}

@Override
Expand Down Expand Up @@ -69,7 +69,7 @@ public void fillItemCategory(CreativeModeTab group, NonNullList<ItemStack> items
String showOnlyId = Config.COMMON.showOnlyPartMaterial.get();
boolean added = false;
if (!showOnlyId.isEmpty()) {
MaterialId materialId = MaterialId.tryCreate(showOnlyId);
MaterialId materialId = MaterialId.tryParse(showOnlyId);
if (materialId != null) {
IMaterial material = MaterialRegistry.getMaterial(materialId);
if (material != IMaterial.UNKNOWN && !material.isHidden() && canUseMaterial(material)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class EmbellishmentModifier extends SingleUseModifier {

@Override
public Component getDisplayName(IToolStackView tool, int level) {
MaterialId location = MaterialId.tryCreate(tool.getPersistentData().getString(getId()));
MaterialId location = MaterialId.tryParse(tool.getPersistentData().getString(getId()));
if (location != null) {
IMaterial material = MaterialRegistry.getMaterial(location);
TextColor color = material.getColor();
Expand Down

0 comments on commit 05f009e

Please sign in to comment.