diff --git a/changelog.md b/changelog.md index e26abc9efd..e4da936c83 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,7 @@ +# 7.5.11 + +* Fixed a crash + # 7.5.10 * Fixed data loading issues on systems with locales having non-western digits. diff --git a/common/src/main/java/net/mca/Config.java b/common/src/main/java/net/mca/Config.java index ca03c650ba..565d11ea82 100644 --- a/common/src/main/java/net/mca/Config.java +++ b/common/src/main/java/net/mca/Config.java @@ -275,7 +275,7 @@ public static File getConfigFile() { public void autocomplete() { for (Traits.Trait trait : Traits.Trait.values()) { - enabledTraits.putIfAbsent(trait.name(), true); + enabledTraits.putIfAbsent(trait.id(), true); } } diff --git a/common/src/main/java/net/mca/entity/ai/Traits.java b/common/src/main/java/net/mca/entity/ai/Traits.java index c6bfe3dbe1..e1b4b3dada 100644 --- a/common/src/main/java/net/mca/entity/ai/Traits.java +++ b/common/src/main/java/net/mca/entity/ai/Traits.java @@ -16,32 +16,32 @@ public class Traits { private static final CDataParameter TRAITS = CParameter.create("traits", new NbtCompound()); - public static final List TRAIT_LIST = new ArrayList<>(); - - public static Trait LEFT_HANDED = registerTrait("left_handed", 1.0F, 0.5F, false); - public static Trait COLOR_BLIND = registerTrait("color_blind", 1.0F, 0.5F); - public static Trait HETEROCHROMIA = registerTrait("heterochromia", 1.0F, 0.5F); - public static Trait LACTOSE_INTOLERANCE = registerTrait("lactose_intolerance", 1.0F, 1.0F); - public static Trait COELIAC_DISEASE = registerTrait("coeliac_disease", 1.0F, 1.0F, false); // TODO: Implement for 7.4 - public static Trait DIABETES = registerTrait("diabetes", 1.0F, 1.0F, false); // TODO: Implement for 7.4 - public static Trait DWARFISM = registerTrait("dwarfism", 1.0F, 1.0F); - public static Trait ALBINISM = registerTrait("albinism", 1.0F ,1.0F); - public static Trait VEGETARIAN = registerTrait("vegetarian", 1.0F, 1.0F, false); // TODO: Implement for 7.4 - public static Trait BISEXUAL = registerTrait("bisexual", 1.0F, 0.0F); - public static Trait HOMOSEXUAL = registerTrait("homosexual", 1.0F, 0.0F); - public static Trait ELECTRIFIED = registerTrait("electrified", 0.0F, 0.0F, false); - public static Trait SIRBEN = registerTrait("sirben", 0.025F, 1.0F, true); - public static Trait RAINBOW = registerTrait("rainbow", 0.05F, 0.0F); + public static final Map TRAIT_REGISTRY = new HashMap<>(); + + public static Trait LEFT_HANDED = registerTrait("LEFT_HANDED", 1.0F, 0.5F, false); + public static Trait COLOR_BLIND = registerTrait("COLOR_BLIND", 1.0F, 0.5F); + public static Trait HETEROCHROMIA = registerTrait("HETEROCHROMIA", 1.0F, 0.5F); + public static Trait LACTOSE_INTOLERANCE = registerTrait("LACTOSE_INTOLERANCE", 1.0F, 1.0F); + public static Trait COELIAC_DISEASE = registerTrait("COELIAC_DISEASE", 1.0F, 1.0F, false); // TODO: Implement for 7.4 + public static Trait DIABETES = registerTrait("DIABETES", 1.0F, 1.0F, false); // TODO: Implement for 7.4 + public static Trait DWARFISM = registerTrait("DWARFISM", 1.0F, 1.0F); + public static Trait ALBINISM = registerTrait("ALBINISM", 1.0F, 1.0F); + public static Trait VEGETARIAN = registerTrait("VEGETARIAN", 1.0F, 1.0F, false); // TODO: Implement for 7.4 + public static Trait BISEXUAL = registerTrait("BISEXUAL", 1.0F, 0.0F); + public static Trait HOMOSEXUAL = registerTrait("HOMOSEXUAL", 1.0F, 0.0F); + public static Trait ELECTRIFIED = registerTrait("ELECTRIFIED", 0.0F, 0.0F, false); + public static Trait SIRBEN = registerTrait("SIRBEN", 0.025F, 1.0F); + public static Trait RAINBOW = registerTrait("RAINBOW", 0.05F, 0.0F); + public static Trait UNKNOWN = registerTrait("UNKNOWN", 0.0F, 0.0F, false); public static Trait registerTrait(String id, float chance, float inherit, boolean usableOnPlayer) { Trait trait = new Trait(id, chance, inherit, usableOnPlayer); - TRAIT_LIST.add(trait); + TRAIT_REGISTRY.put(id, trait); return trait; } + public static Trait registerTrait(String id, float chance, float inherit) { - Trait trait = new Trait(id, chance, inherit); - TRAIT_LIST.add(trait); - return trait; + return registerTrait(id, chance, inherit, true); } public static class Trait { @@ -57,31 +57,24 @@ public static class Trait { this.usableOnPlayer = usableOnPlayer; } - Trait(String id, float chance, float inherit) { - this(id, chance, inherit, true); - } - - public String name() { + public String id() { return this.id; } - public static List values() { - return TRAIT_LIST; + public static Collection values() { + return TRAIT_REGISTRY.values(); } public static Trait valueOf(String id) { - for (Trait t : TRAIT_LIST) { - if (t.name().equals(id)) return t; - } - return null; + return TRAIT_REGISTRY.getOrDefault(id, UNKNOWN); } public Text getName() { - return Text.translatable("trait." + name().toLowerCase(Locale.ENGLISH)); + return Text.translatable("trait." + id().toLowerCase(Locale.ROOT)); } public Text getDescription() { - return Text.translatable("traitDescription." + name().toLowerCase(Locale.ENGLISH)); + return Text.translatable("traitDescription." + id().toLowerCase(Locale.ROOT)); } public boolean isUsableOnPlayer() { @@ -89,7 +82,7 @@ public boolean isUsableOnPlayer() { } public boolean isEnabled() { - return Config.getServerConfig().enabledTraits.get(name()); + return Config.getServerConfig().enabledTraits.getOrDefault(id(), false); } } @@ -114,7 +107,7 @@ public Set getInheritedTraits() { } public boolean hasTrait(VillagerLike target, Trait trait) { - return target.getTrackedValue(TRAITS).contains(trait.name()); + return target.getTrackedValue(TRAITS).contains(trait.id()); } public boolean hasTrait(Trait trait) { @@ -122,7 +115,7 @@ public boolean hasTrait(Trait trait) { } public boolean hasTrait(String trait) { - if (Trait.valueOf(trait) != null ) { + if (Trait.valueOf(trait) != null) { return hasTrait(entity, Trait.valueOf(trait)); } return false; @@ -138,19 +131,19 @@ public boolean hasSameTrait(Trait trait, VillagerLike other) { public void addTrait(Trait trait) { NbtCompound traits = entity.getTrackedValue(TRAITS).copy(); - traits.putBoolean(trait.name(), true); + traits.putBoolean(trait.id(), true); entity.setTrackedValue(TRAITS, traits); } public void removeTrait(Trait trait) { NbtCompound traits = entity.getTrackedValue(TRAITS).copy(); - traits.remove(trait.name()); + traits.remove(trait.id()); entity.setTrackedValue(TRAITS, traits); } //initializes the genes with random numbers public void randomize() { - float total = (float)Trait.values().stream().mapToDouble(tr -> tr.chance).sum(); + float total = (float) Trait.values().stream().mapToDouble(tr -> tr.chance).sum(); for (Trait t : Trait.values()) { float chance = Config.getInstance().traitChance / total * t.chance; if (random.nextFloat() < chance && t.isEnabled()) { diff --git a/common/src/main/java/net/mca/entity/ai/gpt3Modules/TraitsModule.java b/common/src/main/java/net/mca/entity/ai/gpt3Modules/TraitsModule.java index 16d0b6c68b..ca790a9bee 100644 --- a/common/src/main/java/net/mca/entity/ai/gpt3Modules/TraitsModule.java +++ b/common/src/main/java/net/mca/entity/ai/gpt3Modules/TraitsModule.java @@ -32,7 +32,7 @@ public class TraitsModule { public static void apply(List input, VillagerEntityMCA villager, ServerPlayerEntity player) { if (Config.getInstance().villagerChatAIIntelligence >= 1) { for (Traits.Trait trait : villager.getTraits().getTraits()) { - input.add(traitDescription.getOrDefault(trait.name(), "$villager has " + translate(trait.name()) + ". ")); + input.add(traitDescription.getOrDefault(trait.id(), "$villager has " + translate(trait.id()) + ". ")); } } } diff --git a/common/src/main/resources/assets/mca/lang/en_us.json b/common/src/main/resources/assets/mca/lang/en_us.json index b0877a5c93..85f8ad9404 100644 --- a/common/src/main/resources/assets/mca/lang/en_us.json +++ b/common/src/main/resources/assets/mca/lang/en_us.json @@ -257,6 +257,7 @@ "trait.left_handed": "Left Handed", "trait.electrified": "Electrified", "trait.rainbow": "Rainbow", + "trait.unknown": "Unknown", "traitDescription.lactose_intolerance": "Intolerant to lactose.", "traitDescription.coeliac_disease": "Gets massive diarrhea on gluten.", "traitDescription.diabetes": "Sugar bad.", @@ -270,7 +271,8 @@ "traitDescription.homosexual": "Can have attraction to the same gender.", "traitDescription.left_handed": "Uses their left-hand as their dominant hand.", "traitDescription.electrified": "Struck by lightning.", - "traitDescription.rainbow": "Colored using Jebs secret source.", + "traitDescription.rainbow": "Colored using Jebs secret sauce.", + "traitDescription.unknown": "Once this villager had a trait, but is now lost to time.", "sirben": "*random Sirben noises*",