Skip to content

Commit

Permalink
give middle names to villagers spawned without breeding
Browse files Browse the repository at this point in the history
  • Loading branch information
SeriousGuy888 committed Jan 7, 2022
1 parent e4fbef4 commit 93ed7d9
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ public class VillagerRegistrationUtil {
private final String[] firstNames = config.getStringList("names.first").toArray(new String[0]);
private final String[] lastNames = config.getStringList("names.last").toArray(new String[0]);

private final boolean enableMiddleNames = config.getBoolean("naming.middle_names.enabled");
private final double middleNameChance = config.getDouble("naming.middle_names.chance_percentage");

private final Random random = new Random();

public void nameBredVillager(Villager child, Villager mother, Villager father) {
Expand All @@ -37,7 +34,7 @@ public void nameBredVillager(Villager child, Villager mother, Villager father) {
}

// if percentage chance, give the child a middle name
String childFullName = enableMiddleNames && random.nextInt(100) <= middleNameChance
String childFullName = shouldUseMiddleName()
? String.format("%s %s %s", childFirstName, childMiddleName, childLastName)
: String.format("%s %s", childFirstName, childLastName);
child.setCustomName(childFullName);
Expand All @@ -46,6 +43,11 @@ public void nameBredVillager(Villager child, Villager mother, Villager father) {
private String getLastNameOfName(String name) {
return name.substring(name.lastIndexOf(" ") + 1);
}
private boolean shouldUseMiddleName() {
final boolean enableMiddleNames = config.getBoolean("naming.middle_names.enabled");
final double middleNameChance = config.getDouble("naming.middle_names.chance_percentage");
return enableMiddleNames && new Random().nextInt(100) <= middleNameChance;
}

private String getRandomFirstName() {
return firstNames[random.nextInt(firstNames.length)];
Expand All @@ -54,6 +56,8 @@ private String getRandomLastName() {
return lastNames[random.nextInt(lastNames.length)];
}
public String getRandomFullName() {
return String.format("%s %s", getRandomFirstName(), getRandomLastName());
return shouldUseMiddleName()
? String.format("%s %s %s", getRandomFirstName(), getRandomLastName(), getRandomLastName())
: String.format("%s %s", getRandomFirstName(), getRandomLastName());
}
}

0 comments on commit 93ed7d9

Please sign in to comment.