mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
Add merge level limit (#32)
Add merge level limit (aka "max before merge" or "disable merge over")
This commit is contained in:
parent
a915d5ad80
commit
a00bb919f4
5 changed files with 128 additions and 7 deletions
|
|
@ -30,7 +30,7 @@ public class MainConfigGui extends ChestGui {
|
||||||
public void init(PacketManager packetManager) {
|
public void init(PacketManager packetManager) {
|
||||||
Pattern pattern = new Pattern(
|
Pattern pattern = new Pattern(
|
||||||
GuiSharedConstant.EMPTY_GUI_FULL_LINE,
|
GuiSharedConstant.EMPTY_GUI_FULL_LINE,
|
||||||
"012304567",
|
"012345678",
|
||||||
"Q00000000"
|
"Q00000000"
|
||||||
);
|
);
|
||||||
PatternPane pane = new PatternPane(0, 0, 9, 3, pattern);
|
PatternPane pane = new PatternPane(0, 0, 9, 3, pattern);
|
||||||
|
|
@ -62,6 +62,18 @@ public class MainConfigGui extends ChestGui {
|
||||||
GuiItem enchantLimitItem = GuiGlobalItems.goToGuiItem(enchantLimitItemstack, new EnchantLimitConfigGui());
|
GuiItem enchantLimitItem = GuiGlobalItems.goToGuiItem(enchantLimitItemstack, new EnchantLimitConfigGui());
|
||||||
pane.bindItem('2', enchantLimitItem);
|
pane.bindItem('2', enchantLimitItem);
|
||||||
|
|
||||||
|
// enchant level limit item
|
||||||
|
ItemStack enchantMergeLimitItemstack = new ItemStack(Material.ENCHANTED_BOOK);
|
||||||
|
ItemMeta enchantMergeLimitMeta = enchantMergeLimitItemstack.getItemMeta();
|
||||||
|
assert enchantMergeLimitMeta != null;
|
||||||
|
|
||||||
|
enchantMergeLimitMeta.setDisplayName("§aEnchantment Merge Limit");
|
||||||
|
enchantMergeLimitMeta.setLore(Collections.singletonList("§7Click here to open enchantment merge limit menu"));
|
||||||
|
enchantMergeLimitItemstack.setItemMeta(enchantMergeLimitMeta);
|
||||||
|
|
||||||
|
GuiItem enchantMergeLimitItem = GuiGlobalItems.goToGuiItem(enchantMergeLimitItemstack, new EnchantMergeLimitConfigGui());
|
||||||
|
pane.bindItem('3', enchantMergeLimitItem);
|
||||||
|
|
||||||
// enchant cost item
|
// enchant cost item
|
||||||
ItemStack enchantCostItemstack = new ItemStack(Material.EXPERIENCE_BOTTLE);
|
ItemStack enchantCostItemstack = new ItemStack(Material.EXPERIENCE_BOTTLE);
|
||||||
ItemMeta enchantCostMeta = enchantCostItemstack.getItemMeta();
|
ItemMeta enchantCostMeta = enchantCostItemstack.getItemMeta();
|
||||||
|
|
@ -72,7 +84,7 @@ public class MainConfigGui extends ChestGui {
|
||||||
enchantCostItemstack.setItemMeta(enchantCostMeta);
|
enchantCostItemstack.setItemMeta(enchantCostMeta);
|
||||||
|
|
||||||
GuiItem enchantCostItem = GuiGlobalItems.goToGuiItem(enchantCostItemstack, new EnchantCostConfigGui());
|
GuiItem enchantCostItem = GuiGlobalItems.goToGuiItem(enchantCostItemstack, new EnchantCostConfigGui());
|
||||||
pane.bindItem('3', enchantCostItem);
|
pane.bindItem('4', enchantCostItem);
|
||||||
|
|
||||||
// Enchantment Conflicts item
|
// Enchantment Conflicts item
|
||||||
ItemStack enchantConflictItemstack = new ItemStack(Material.OAK_FENCE);
|
ItemStack enchantConflictItemstack = new ItemStack(Material.OAK_FENCE);
|
||||||
|
|
@ -84,7 +96,7 @@ public class MainConfigGui extends ChestGui {
|
||||||
enchantConflictItemstack.setItemMeta(enchantConflictMeta);
|
enchantConflictItemstack.setItemMeta(enchantConflictMeta);
|
||||||
|
|
||||||
GuiItem enchantConflictItem = GuiGlobalItems.goToGuiItem(enchantConflictItemstack, EnchantConflictGui.getInstance());
|
GuiItem enchantConflictItem = GuiGlobalItems.goToGuiItem(enchantConflictItemstack, EnchantConflictGui.getInstance());
|
||||||
pane.bindItem('4', enchantConflictItem);
|
pane.bindItem('5', enchantConflictItem);
|
||||||
|
|
||||||
// Group config items
|
// Group config items
|
||||||
ItemStack groupItemstack = new ItemStack(Material.CHEST);
|
ItemStack groupItemstack = new ItemStack(Material.CHEST);
|
||||||
|
|
@ -97,7 +109,7 @@ public class MainConfigGui extends ChestGui {
|
||||||
|
|
||||||
GuiItem groupConfigItem = GuiGlobalItems.goToGuiItem(groupItemstack, GroupConfigGui.getInstance());
|
GuiItem groupConfigItem = GuiGlobalItems.goToGuiItem(groupItemstack, GroupConfigGui.getInstance());
|
||||||
|
|
||||||
pane.bindItem('5', groupConfigItem);
|
pane.bindItem('6', groupConfigItem);
|
||||||
|
|
||||||
// Unit repair item
|
// Unit repair item
|
||||||
ItemStack unirRepairItemstack = new ItemStack(Material.DIAMOND);
|
ItemStack unirRepairItemstack = new ItemStack(Material.DIAMOND);
|
||||||
|
|
@ -109,7 +121,7 @@ public class MainConfigGui extends ChestGui {
|
||||||
unirRepairItemstack.setItemMeta(unitRepairMeta);
|
unirRepairItemstack.setItemMeta(unitRepairMeta);
|
||||||
|
|
||||||
GuiItem unitRepairItem = GuiGlobalItems.goToGuiItem(unirRepairItemstack, UnitRepairConfigGui.getInstance());
|
GuiItem unitRepairItem = GuiGlobalItems.goToGuiItem(unirRepairItemstack, UnitRepairConfigGui.getInstance());
|
||||||
pane.bindItem('6', unitRepairItem);
|
pane.bindItem('7', unitRepairItem);
|
||||||
|
|
||||||
// Custom recipe item
|
// Custom recipe item
|
||||||
ItemStack customRecipeItemstack = new ItemStack(Material.CRAFTING_TABLE);
|
ItemStack customRecipeItemstack = new ItemStack(Material.CRAFTING_TABLE);
|
||||||
|
|
@ -121,7 +133,7 @@ public class MainConfigGui extends ChestGui {
|
||||||
customRecipeItemstack.setItemMeta(customRecipeMeta);
|
customRecipeItemstack.setItemMeta(customRecipeMeta);
|
||||||
|
|
||||||
GuiItem customRecipeItem = GuiGlobalItems.goToGuiItem(customRecipeItemstack, CustomRecipeConfigGui.getInstance());
|
GuiItem customRecipeItem = GuiGlobalItems.goToGuiItem(customRecipeItemstack, CustomRecipeConfigGui.getInstance());
|
||||||
pane.bindItem('7', customRecipeItem);
|
pane.bindItem('8', customRecipeItem);
|
||||||
|
|
||||||
// quit item
|
// quit item
|
||||||
ItemStack quitItemstack = new ItemStack(Material.BARRIER);
|
ItemStack quitItemstack = new ItemStack(Material.BARRIER);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,60 @@
|
||||||
|
package xyz.alexcrea.cuanvil.gui.config.global;
|
||||||
|
|
||||||
|
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||||
|
import xyz.alexcrea.cuanvil.enchant.CAEnchantment;
|
||||||
|
import xyz.alexcrea.cuanvil.gui.config.settings.IntSettingsGui;
|
||||||
|
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
public class EnchantMergeLimitConfigGui extends AbstractEnchantConfigGui<IntSettingsGui.IntSettingFactory> {
|
||||||
|
|
||||||
|
private static final String SECTION_NAME = "disable-merge-over";
|
||||||
|
|
||||||
|
private static EnchantMergeLimitConfigGui INSTANCE = null;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public static EnchantMergeLimitConfigGui getInstance() {
|
||||||
|
return INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor of this Global gui for enchantment level limit settings.
|
||||||
|
*/
|
||||||
|
public EnchantMergeLimitConfigGui() {
|
||||||
|
super("§8Enchantment Maximum Merge Level");
|
||||||
|
if(INSTANCE == null) INSTANCE = this;
|
||||||
|
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IntSettingsGui.IntSettingFactory createFactory(CAEnchantment enchant) {
|
||||||
|
String key = enchant.getKey().getKey().toLowerCase(Locale.ROOT);
|
||||||
|
String prettyKey = CasedStringUtil.snakeToUpperSpacedCase(key);
|
||||||
|
|
||||||
|
return new IntSettingsGui.IntSettingFactory(prettyKey + " Merge Limit", this,
|
||||||
|
SECTION_NAME + '.' + key, ConfigHolder.DEFAULT_CONFIG,
|
||||||
|
Arrays.asList(
|
||||||
|
"§7Maximum merge level for for " + prettyKey,
|
||||||
|
"",
|
||||||
|
"§7For example, if set to §e2§7, §alvl1 §7+ §alvl1 §7of will give a §alvl2",
|
||||||
|
"§7But §alvl2 §7+ §alvl2 §7will not give a §clv3§7.",
|
||||||
|
"§7Will still not merge above max enchantment level",
|
||||||
|
"§e-1 §7(default) will set the merge limit to enchantment's maximum level"
|
||||||
|
),
|
||||||
|
-1, 255, -1,
|
||||||
|
1, 5, 10, 50, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GuiItem itemFromFactory(CAEnchantment enchantment, IntSettingsGui.IntSettingFactory inventoryFactory) {
|
||||||
|
return inventoryFactory.getItem(
|
||||||
|
Material.ENCHANTED_BOOK,
|
||||||
|
inventoryFactory.getTitle());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -41,6 +41,8 @@ object ConfigOptions {
|
||||||
const val ENCHANT_LIMIT_ROOT = "enchant_limits"
|
const val ENCHANT_LIMIT_ROOT = "enchant_limits"
|
||||||
const val ENCHANT_VALUES_ROOT = "enchant_values"
|
const val ENCHANT_VALUES_ROOT = "enchant_values"
|
||||||
|
|
||||||
|
const val DISABLE_MERGE_OVER_ROOT = "disable-merge-over"
|
||||||
|
|
||||||
// Keys for specific enchantment values
|
// Keys for specific enchantment values
|
||||||
private const val KEY_BOOK = "book"
|
private const val KEY_BOOK = "book"
|
||||||
private const val KEY_ITEM = "item"
|
private const val KEY_ITEM = "item"
|
||||||
|
|
@ -110,6 +112,9 @@ object ConfigOptions {
|
||||||
// Default value for an enchantment multiplier
|
// Default value for an enchantment multiplier
|
||||||
private const val DEFAULT_ENCHANT_VALUE = 0
|
private const val DEFAULT_ENCHANT_VALUE = 0
|
||||||
|
|
||||||
|
// Default max before merge disabled (negative mean enabled)
|
||||||
|
const val DEFAULT_MAX_BEFORE_MERGE_DISABLED = -1;
|
||||||
|
|
||||||
// -------------
|
// -------------
|
||||||
// Get methods
|
// Get methods
|
||||||
// -------------
|
// -------------
|
||||||
|
|
@ -374,4 +379,33 @@ object ConfigOptions {
|
||||||
return DEFAULT_ENCHANT_VALUE
|
return DEFAULT_ENCHANT_VALUE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the given [enchantmentName]'s level before merge is disabled
|
||||||
|
* a negative value would mean never disabled
|
||||||
|
*/
|
||||||
|
fun maxBeforeMergeDisabled(enchantment: CAEnchantment): Int {
|
||||||
|
return maxBeforeMergeDisabled(enchantment.enchantmentName)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the given [enchantmentName]'s level before merge is disabled
|
||||||
|
* a negative value would mean never disabled
|
||||||
|
*/
|
||||||
|
private fun maxBeforeMergeDisabled(enchantmentName: String) : Int {
|
||||||
|
// find if set
|
||||||
|
val path = "${DISABLE_MERGE_OVER_ROOT}.$enchantmentName"
|
||||||
|
|
||||||
|
val value = CustomAnvil.instance
|
||||||
|
.config
|
||||||
|
.getInt(path, DEFAULT_MAX_BEFORE_MERGE_DISABLED)
|
||||||
|
.takeIf { it in ENCHANT_LIMIT_RANGE }
|
||||||
|
?: DEFAULT_MAX_BEFORE_MERGE_DISABLED;
|
||||||
|
|
||||||
|
if((value == DEFAULT_MAX_BEFORE_MERGE_DISABLED) && (enchantmentName == "sweeping_edge")){
|
||||||
|
return maxBeforeMergeDisabled("sweeping")
|
||||||
|
}
|
||||||
|
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,11 @@ object EnchantmentUtil {
|
||||||
}
|
}
|
||||||
// ... and they're the same level
|
// ... and they're the same level
|
||||||
else {
|
else {
|
||||||
// try to increase the enchantment level by 1
|
// We test if it is allowed to merge at this level
|
||||||
|
val maxBeforeDisabled = ConfigOptions.maxBeforeMergeDisabled(enchantment)
|
||||||
|
if((maxBeforeDisabled > 0) && (oldLevel >= maxBeforeDisabled)) return@forEach
|
||||||
|
|
||||||
|
// Now we increase the enchantment level by 1
|
||||||
var newLevel = oldLevel + 1
|
var newLevel = oldLevel + 1
|
||||||
newLevel = max(min(newLevel, maxLevel), oldLevel)
|
newLevel = max(min(newLevel, maxLevel), oldLevel)
|
||||||
this[enchantment] = newLevel
|
this[enchantment] = newLevel
|
||||||
|
|
|
||||||
|
|
@ -271,6 +271,17 @@ enchant_values:
|
||||||
item: 8
|
item: 8
|
||||||
book: 4
|
book: 4
|
||||||
|
|
||||||
|
# Disable enchantment merging for level above the set value
|
||||||
|
# Enchantment merging is when, for example, 2 unbreaking II book combine to give sharpness III
|
||||||
|
# But Enchantment above this value can still be applied. following the previous example, we could still apply a unbreaking III book to a sword
|
||||||
|
# Even if disable-merge-over of unbreaking is set to 2
|
||||||
|
# -1 mean enchantment merge for this enchantment is not disabled. default to -1 if absent.
|
||||||
|
disable-merge-over:
|
||||||
|
# Sharpness is set to -1. it equivalent to it not being set to anything (and work as vanilla)
|
||||||
|
sharpness: -1
|
||||||
|
# If uncommented. 2 unbreaking II book would not give an unbreaking III book. but unbreaking III book can still be applied
|
||||||
|
#unbreaking: 2
|
||||||
|
|
||||||
# Whether to show debug logging
|
# Whether to show debug logging
|
||||||
debug_log: false
|
debug_log: false
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue