Skip to content

Commit

Permalink
feat: rework spirit name generation
Browse files Browse the repository at this point in the history
- Allow custom spirit names alongside random generated ones ("usePossibleSpiritNamesChance")
- Extend generation algorithm with more syllables for grater name variety

Closes #895
  • Loading branch information
klikli-dev committed Feb 17, 2023
1 parent a06546b commit c1279c3
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,10 @@

package com.github.klikli_dev.occultism.common.item.debug;

import com.github.klikli_dev.occultism.common.entity.spirit.SpiritEntity;
import com.github.klikli_dev.occultism.common.entity.job.SpiritJob;
import com.github.klikli_dev.occultism.registry.OccultismEntities;
import com.github.klikli_dev.occultism.registry.OccultismSpiritJobs;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
Expand All @@ -53,30 +45,31 @@ public DebugWandItem(Properties properties) {
public InteractionResult useOn(UseOnContext context) {

if (!context.getLevel().isClientSide) {
// Player player = context.getPlayer();
//
Player player = context.getPlayer();

// ItemStack spirit = new ItemStack(OccultismItems.MINER_DEBUG_UNSPECIALIZED.get());
// spirit.getItem().onCreated(spirit, context.getLevel(), context.getPlayer());
// ItemHandlerHelper.giveItemToPlayer(player, spirit);
//context.getPlayer().sendMessage(Component.literal(TextUtil.generateName()), Util.NIL_UUID);

//set up the foliot entity
BlockPos target = context.getClickedPos().above();
SpiritEntity spirit = OccultismEntities.MARID.get().create(context.getLevel());
spirit.absMoveTo(target.getX(), target.getY(), target.getZ(),
context.getLevel().random.nextInt(360), 0);
spirit.setCustomName(Component.literal("Testguy"));
spirit.finalizeSpawn((ServerLevel) context.getLevel(), context.getLevel().getCurrentDifficultyAt(target),
MobSpawnType.MOB_SUMMONED, null,
null);
spirit.tame(context.getPlayer());
//set up the job
SpiritJob job = OccultismSpiritJobs.CRUSH_TIER4.get().create(spirit);
job.init();
spirit.setJob(job);
// context.getPlayer().sendSystemMessage(Component.literal(TextUtil.generateName()));

spirit.setSpiritMaxAge(60 * 60 * 3); //3 hours max age
context.getLevel().addFreshEntity(spirit);
//set up the foliot entity
// BlockPos target = context.getClickedPos().above();
// SpiritEntity spirit = OccultismEntities.MARID.get().create(context.getLevel());
// spirit.absMoveTo(target.getX(), target.getY(), target.getZ(),
// context.getLevel().random.nextInt(360), 0);
// spirit.setCustomName(Component.literal("Testguy"));
// spirit.finalizeSpawn((ServerLevel) context.getLevel(), context.getLevel().getCurrentDifficultyAt(target),
// MobSpawnType.MOB_SUMMONED, null,
// null);
// spirit.tame(context.getPlayer());
// //set up the job
// SpiritJob job = OccultismSpiritJobs.CRUSH_TIER4.get().create(spirit);
// job.init();
// spirit.setJob(job);
//
// spirit.setSpiritMaxAge(60 * 60 * 3); //3 hours max age
// context.getLevel().addFreshEntity(spirit);

}
return InteractionResult.SUCCESS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ public static class RitualSettings {
public final DoubleValue ritualDurationMultiplier;

public final ConfigValue<List<String>> possibleSpiritNames;
public final DoubleValue usePossibleSpiritNamesChance;


public RitualSettings(ForgeConfigSpec.Builder builder) {
builder.comment("Ritual Settings").push("rituals");
Expand Down Expand Up @@ -236,9 +238,17 @@ public RitualSettings(ForgeConfigSpec.Builder builder) {
.defineInRange("ritualDurationMultiplier", 1.0, 0.05, Double.MAX_VALUE);

this.possibleSpiritNames =
builder.comment("By default spirit names are generated at random from lists of possible syllables. " +
"If you instead want to specify the possible spirit names directly, configure a list of values here.")
.define("possibleSpiritNames", new ArrayList<String>());
builder.comment("By default spirit names are generated randomly. " +
"This list can be used as an additional source of spirit names, or even a full replacement, depending on the configuration of \"usePossibleSpiritNamesChance\".")
.define("possibleSpiritNames", new ArrayList<>());

this.usePossibleSpiritNamesChance =
builder.comment(
"0.0 (default) to only use random names.",
"1.0 to only use the names in \"possibleSpiritNames\"",
"0.1-0.9 to use a mix of both, the higher the value the higher the chance of using a name from this list instead of a random name.",
"Will be ignored if \"possibleSpiritNames\" is empty.")
.defineInRange("usePossibleSpiritNamesChance", 0.0, 0.0, 1.0);

builder.pop();
}
Expand Down
20 changes: 11 additions & 9 deletions src/main/java/com/github/klikli_dev/occultism/util/TextUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@

public class TextUtil {

//region Fields
private static final Map<String, String> MOD_NAME_TO_ID = new HashMap<String, String>();
private static final String[] SYLLABLE1 = {"Kr", "Ca", "Ra", "Mrok", "Cru", "Ray", "Bre", "Zed", "Drak", "Mor", "Jag", "Mer", "Jar", "Mjol", "Zork", "Mad", "Cry", "Zur", "Creo", "Azak", "Azur", "Rei", "Cro", "Mar", "Luk", "Bar"};
private static final Map<String, String> MOD_NAME_TO_ID = new HashMap<>();

//KliKli: Obvious :)
//Xalmas: You know why!
//Toastbroat: You know why!
Expand All @@ -55,13 +54,12 @@ public class TextUtil {
//Vemerion: Sooo many new familiars! <3
//Eqis: the long-awaited additional spirit miner tiers
private static final String[] EASTER_EGGS = {"KliKli", "Xalmas", "Toastbroat", "Najlitarvan", "TheBoo", "Ridanisaurus", "Legiaseth", "Vallen", "Vemerion", "Eqis"};
private static final String[] SYLLABLE2 = {"air", "ir", "mi", "sor", "mee", "clo", "red", "cra", "ark", "arc", "miri", "lori", "cres", "mur", "zer", "marac", "zoir", "slamar", "salmar", "urak", "tim"};
private static final String[] SYLLABLE3 = {"d", "ed", "ark", "arc", "es", "er", "der", "tron", "med", "ure", "zur", "cred", "mur", "aeus"};
private static final String[] SYLLABLE1 = {"Kr", "Ca", "Ra", "Mrok", "Cru", "Ray", "Bre", "Zed", "Drak", "Mor", "Jag", "Mer", "Jar", "Mjol", "Zork", "Mad", "Cry", "Zur", "Creo", "Azak", "Azur", "Rei", "Cro", "Mar", "Luk", "Bar", "Gor", "Rak", "Thr", "Nar", "Vor", "Fir", "Trin", "Drog", "Karn", "Gar", "Ulf", "Hroth", "Ald", "Yng", "Styr", "Eir", "Ein", "Sig", "Ket", "Erl", "Haf", "Bryn", "Nid", "Grim", "Hol", "Fen", "Sigr", "Geir", "Hyr", "Val", "Har", "Kol", "Eyr"};
private static final String[] SYLLABLE2 = {"air", "ir", "mi", "sor", "mee", "clo", "red", "cra", "ark", "arc", "miri", "lori", "cres", "mur", "zer", "marac", "zoir", "slamar", "salmar", "urak", "tim", "jor", "vyr", "dor", "thor", "kyl", "lyn", "wyn", "wynn", "lond", "rond", "vond", "dorn", "korn", "morn", "gorn", "thorn", "worn", "norn", "rinn", "dell", "bell", "vell", "fell", "kell", "zell", "nir", "fir", "mir", "tir", "sir", "vir", "zir", "lir", "jyr", "ryl", "rym", "lym", "lyn", "ryn", "myr", "myl", "myn", "ryn"};
private static final String[] SYLLABLE3 = {"d", "ed", "ark", "arc", "es", "er", "der", "tron", "med", "ure", "zur", "cred", "mur", "aeus", "th", "vyr", "dor", "morn", "born", "thorn", "fyr", "lyr", "ryth", "ryn", "drin", "dryn", "kyr", "kyn", "lynd", "lind", "lyne", "line", "ryne", "rine", "thyr", "thyre", "vyn", "vin", "vyne", "vine", "rynne", "rinne", "syr", "syrn", "zirn", "zirne", "kyl", "kylle", "dor", "dorne", "lor", "lorne", "morn", "morne", "thorn", "thorne", "vyrn", "vyrne", "wyrm"};
private static final Random random = new Random();
private static boolean modNamesInitialized = false;
//endregion Fields

//region Static Methods
public static void initializeModNames() {
modNamesInitialized = true;
for (IModInfo info : ModList.get().getMods()) {
Expand Down Expand Up @@ -146,14 +144,18 @@ public static String formatLargeNumber(int number) {
*/
public static String generateName() {
var possibleSpiritNames = Occultism.SERVER_CONFIG.rituals.possibleSpiritNames.get();
if (!possibleSpiritNames.isEmpty()) {
var usePossibleSpiritNames = random.nextDouble() > Occultism.SERVER_CONFIG.rituals.usePossibleSpiritNamesChance.get();

//if possible spirit names is not empty, and the random chance is met we use a name from the list
if (!possibleSpiritNames.isEmpty() && usePossibleSpiritNames) {
return random.nextInt(20) == 0 ?
EASTER_EGGS[random.nextInt(EASTER_EGGS.length)] :
possibleSpiritNames.get(random.nextInt(possibleSpiritNames.size()));
}

//otherwise we go with the default behaviour, which is random names
return random.nextInt(20) == 0 ? EASTER_EGGS[random.nextInt(
EASTER_EGGS.length)] : SYLLABLE1[random.nextInt(SYLLABLE1.length)] + SYLLABLE2[random.nextInt(SYLLABLE2.length)] +
SYLLABLE3[random.nextInt(SYLLABLE3.length)];
}
//endregion Static Methods
}

0 comments on commit c1279c3

Please sign in to comment.