Skip to content

Commit

Permalink
Merge branch '1.19.2' into 1.19.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke100000 committed Nov 1, 2023
2 parents 4b96cfc + 088419c commit bae18b7
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 42 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/java/net/mca/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
71 changes: 32 additions & 39 deletions common/src/main/java/net/mca/entity/ai/Traits.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,32 @@
public class Traits {
private static final CDataParameter<NbtCompound> TRAITS = CParameter.create("traits", new NbtCompound());

public static final List<Trait> 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<String, Trait> 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 {
Expand All @@ -57,39 +57,32 @@ 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<Trait> values() {
return TRAIT_LIST;
public static Collection<Trait> 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() {
return usableOnPlayer;
}

public boolean isEnabled() {
return Config.getServerConfig().enabledTraits.get(name());
return Config.getServerConfig().enabledTraits.getOrDefault(id(), false);
}
}

Expand All @@ -114,15 +107,15 @@ public Set<Trait> 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) {
return hasTrait(entity, trait);
}

public boolean hasTrait(String trait) {
if (Trait.valueOf(trait) != null ) {
if (Trait.valueOf(trait) != null) {
return hasTrait(entity, Trait.valueOf(trait));
}
return false;
Expand All @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class TraitsModule {
public static void apply(List<String> 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()) + ". "));
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion common/src/main/resources/assets/mca/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand All @@ -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*",

Expand Down

0 comments on commit bae18b7

Please sign in to comment.