Fix for villager books

This commit is contained in:
BuildTools 2023-09-06 15:48:50 +05:00
parent 53b81df34b
commit f5109635ff
2 changed files with 16 additions and 8 deletions

View File

@ -117,6 +117,9 @@ public class Config {
"When enabled, passive enchantments (permanent potion effects, regeneration, etc.) will be applied to mobs as well.",
"Disable this if you're experiencing performance issues.");
public static final JOption<Boolean> ENCHANTMENTS_SINGLE_ENCHANT_IN_VILLAGER_BOOKS = JOption.create("Enchantments.Single_Enchant_In_Villager_Books", true,
"Sets whether or not enchanted books in villager trades will have only 1 enchant, vanilla or custom one.");
private static final JOption<Map<ObtainType, ObtainSettings>> OBTAIN_SETTINGS = new JOption<Map<ObtainType, ObtainSettings>>("Enchantments.Obtaining",
(cfg, path, def) -> Stream.of(ObtainType.values()).collect(Collectors.toMap(k -> k, v -> ObtainSettings.read(cfg, path + "." + v.getPathName()))),
() -> Stream.of(ObtainType.values()).collect(Collectors.toMap(k -> k, v -> new ObtainSettings(true, 4, 80D, 0, 2))),

View File

@ -106,12 +106,23 @@ public class EnchantUtils {
public static boolean populate(@NotNull ItemStack item, @NotNull ObtainType obtainType, @Nullable World world) {
AtomicBoolean status = new AtomicBoolean(false);
getPopulationCandidates(item, obtainType, world).forEach((enchantment, level) -> {
var population = getPopulationCandidates(item, obtainType, world);
if (obtainType == ObtainType.VILLAGER && item.getType() == Material.ENCHANTED_BOOK) {
if (Config.ENCHANTMENTS_SINGLE_ENCHANT_IN_VILLAGER_BOOKS.get() && !population.isEmpty()) {
getAll(item).keySet().forEach(enchantment -> remove(item, enchantment));
}
}
population.forEach((enchantment, level) -> {
if (add(item, enchantment, level, false)) {
status.set(true);
}
});
updateDisplay(item);
if (status.get()) {
updateDisplay(item);
}
return status.get();
}
@ -188,12 +199,6 @@ public class EnchantUtils {
enchRoll--;
}
if (!enchantsToAdd.isEmpty()) {
if (obtainType == ObtainType.VILLAGER && item.getType() == Material.ENCHANTED_BOOK && enchRoll == 1) {
getAll(item).keySet().forEach(enchantment -> remove(item, enchantment));
}
}
return enchantsToAdd;
}