1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00

Merge pull request #3847 from Sefiraat/fix/enchantment_amount_fixes

Bandaid because of *someone*
This commit is contained in:
Sfiguz7 2023-06-11 00:55:15 +02:00 committed by GitHub
commit b783afd463
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 5 deletions

View File

@ -40,7 +40,7 @@ abstract class AbstractEnchantmentMachine extends AContainer {
private final ItemSetting<Boolean> useLevelLimit = new ItemSetting<>(this, "use-enchant-level-limit", false);
private final IntRangeSetting levelLimit = new IntRangeSetting(this, "enchant-level-limit", 0, 10, Short.MAX_VALUE);
private final ItemSetting<Integer> maxEnchants = new IntRangeSetting(this, "max-enchants", 0, 10, Short.MAX_VALUE);
private final ItemSetting<Boolean> useMaxEnchants= new ItemSetting<>(this, "use-max-encahnts", false);
private final ItemSetting<Boolean> useMaxEnchants= new ItemSetting<>(this, "use-max-enchants", false);
private final ItemSetting<Boolean> useIgnoredLores = new ItemSetting<>(this, "use-ignored-lores", false);
private final ItemSetting<List<String>> ignoredLores = new ItemSetting<>(this, "ignored-lores", Collections.singletonList("&7- &cCan't be used in " + this.getItemName()));
@ -91,7 +91,10 @@ abstract class AbstractEnchantmentMachine extends AContainer {
return false;
}
protected boolean isEnchantmentAmountAllowed(@Nonnull ItemStack item ) {
return !useMaxEnchants.getValue() || item.getEnchantments().size() >= maxEnchants.getValue();
protected boolean isEnchantmentAmountAllowed(int numberOfEnchants) {
if (!useMaxEnchants.getValue()) {
return true;
}
return numberOfEnchants <= maxEnchants.getValue();
}
}

View File

@ -94,7 +94,7 @@ public class AutoDisenchanter extends AbstractEnchantmentMachine {
}
}
if (isEnchantmentAmountAllowed(item)) {
if (!isEnchantmentAmountAllowed(enchantments.size())) {
return null;
}

View File

@ -120,7 +120,15 @@ public class AutoEnchanter extends AbstractEnchantmentMachine {
* When maxEnchants is set to -1 it will be ignored. When it's set to 0 it will not allow any enchants to go
* on an item. When maxEnchants is set to any other value it will allow that many enchants to go on the item.
*/
if (isEnchantmentAmountAllowed(target)) {
int preExistingEnchants = 0;
for (Map.Entry<Enchantment, Integer> entry : target.getEnchantments().entrySet()) {
if (meta.hasEnchant(entry.getKey())) {
preExistingEnchants++;
}
}
int totalEnchants = enchantments.size() + preExistingEnchants;
if (!isEnchantmentAmountAllowed(totalEnchants)) {
return null;
}