mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-08-28 08:25:56 +02:00
Compare commits
12 commits
23c7b0c753
...
2a5eb8fdd7
| Author | SHA1 | Date | |
|---|---|---|---|
| 2a5eb8fdd7 | |||
| 8b5202e562 | |||
| f4e07247e2 | |||
| d3cc101bed | |||
| dc84ab7303 | |||
| af9050eb15 | |||
| d174988dc5 | |||
| 0fb8d33f6a | |||
| 4942f3c0d2 | |||
| 1d59f033b8 | |||
| 2147384823 | |||
| 3b708302bc |
5 changed files with 23 additions and 38 deletions
|
|
@ -285,14 +285,14 @@ public class EnchantCostSettingsGui extends IntSettingsGui {
|
|||
*/
|
||||
@Override
|
||||
public int getConfiguredValue() {
|
||||
return ConfigOptions.INSTANCE.enchantmentValue(enchantment, false, false);
|
||||
return ConfigOptions.INSTANCE.enchantmentValue(enchantment, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The configured value for the enchant setting book value.
|
||||
*/
|
||||
public int getConfiguredBookValue() {
|
||||
return ConfigOptions.INSTANCE.enchantmentValue(enchantment, false, true);
|
||||
return ConfigOptions.INSTANCE.enchantmentValue(enchantment, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ import xyz.alexcrea.cuanvil.listener.PrepareAnvilListener
|
|||
import xyz.alexcrea.cuanvil.update.ModrinthUpdateChecker
|
||||
import xyz.alexcrea.cuanvil.update.PluginSetDefault
|
||||
import xyz.alexcrea.cuanvil.update.UpdateHandler
|
||||
import xyz.alexcrea.cuanvil.update.UpdateUtils
|
||||
import xyz.alexcrea.cuanvil.util.MetricsUtil
|
||||
import java.io.File
|
||||
import java.io.FileReader
|
||||
|
|
@ -224,8 +223,7 @@ open class CustomAnvil : JavaPlugin() {
|
|||
val version = description.version
|
||||
val featured = if(version.contains("dev")) null else true
|
||||
|
||||
ModrinthUpdateChecker(modrinthPluginID, loader,
|
||||
UpdateUtils.currentMinecraftVersion().toString())
|
||||
ModrinthUpdateChecker(modrinthPluginID, loader, null)
|
||||
.setFeatured(featured)
|
||||
.setOnError {
|
||||
logger.log(Level.WARNING, "error trying to fetch latest update", it)
|
||||
|
|
|
|||
|
|
@ -86,7 +86,6 @@ object ConfigOptions {
|
|||
|
||||
// Keys for specific enchantment values
|
||||
private const val KEY_BOOK = "book"
|
||||
private const val KEY_BOOK_ON_BOOK = "book_on_book"
|
||||
private const val KEY_ITEM = "item"
|
||||
|
||||
// Debug flag
|
||||
|
|
@ -579,15 +578,14 @@ object ConfigOptions {
|
|||
*/
|
||||
fun enchantmentValue(
|
||||
enchantment: CAEnchantment,
|
||||
isToBook: Boolean,
|
||||
isFromBook: Boolean,
|
||||
isFromBook: Boolean
|
||||
): Int {
|
||||
// Test namespace
|
||||
var limit = enchantmentValue(enchantment.key.toString(), isToBook, isFromBook)
|
||||
var limit = enchantmentValue(enchantment.key.toString(), isFromBook)
|
||||
if (limit != null) return limit
|
||||
|
||||
// Test legacy (name only)
|
||||
limit = enchantmentValue(enchantment.enchantmentName, isToBook, isFromBook)
|
||||
limit = enchantmentValue(enchantment.enchantmentName, isFromBook)
|
||||
if (limit != null) return limit
|
||||
|
||||
// get default (and test old legacy if present)
|
||||
|
|
@ -601,22 +599,13 @@ object ConfigOptions {
|
|||
*/
|
||||
private fun enchantmentValue(
|
||||
enchantmentName: String,
|
||||
isToBook: Boolean,
|
||||
isFromBook: Boolean,
|
||||
isFromBook: Boolean
|
||||
): Int? {
|
||||
val typeKey = if (isFromBook) KEY_BOOK else KEY_ITEM
|
||||
val path = "${ENCHANT_VALUES_ROOT}.${enchantmentName}.$typeKey"
|
||||
|
||||
val config = ConfigHolder.DEFAULT_CONFIG.config
|
||||
if(isFromBook && isToBook) {
|
||||
val specialPath = "${ENCHANT_VALUES_ROOT}.${enchantmentName}.$KEY_BOOK_ON_BOOK"
|
||||
|
||||
if(config.isInt(specialPath))
|
||||
return config.getInt(specialPath)
|
||||
.takeIf { it >= DEFAULT_ENCHANT_VALUE }
|
||||
}
|
||||
|
||||
return config.getInt(path, DEFAULT_ENCHANT_VALUE - 1)
|
||||
return CustomAnvil.instance
|
||||
.config
|
||||
.getInt(path, DEFAULT_ENCHANT_VALUE - 1)
|
||||
.takeIf { it >= DEFAULT_ENCHANT_VALUE }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ import xyz.alexcrea.cuanvil.dependency.economy.EconomyManager
|
|||
import xyz.alexcrea.cuanvil.group.ConflictType
|
||||
import xyz.alexcrea.cuanvil.util.AnvilTitleUtil
|
||||
import xyz.alexcrea.cuanvil.util.dialog.AnvilRenameDialogUtil
|
||||
import kotlin.math.sqrt
|
||||
|
||||
object AnvilXpUtil {
|
||||
|
||||
|
|
@ -36,8 +35,7 @@ object AnvilXpUtil {
|
|||
inventory: AnvilInventory,
|
||||
view: InventoryView,
|
||||
player: Player,
|
||||
result: AnvilResult
|
||||
) {
|
||||
result: AnvilResult) {
|
||||
if(result.item == null) {
|
||||
onNoResult(player, view)
|
||||
return
|
||||
|
|
@ -248,8 +246,7 @@ object AnvilXpUtil {
|
|||
fun getRightValues(left: ItemStack, right: ItemStack, result: ItemStack, cost: AnvilCost) {
|
||||
// Calculate right value and illegal enchant penalty
|
||||
|
||||
val isToBook = left.isEnchantedBook()
|
||||
val isFromBook = right.isEnchantedBook()
|
||||
val rightIsFormBook = right.isEnchantedBook()
|
||||
val rightEnchs = EnchantmentApi.getEnchantments(right)
|
||||
val resultEnchs = EnchantmentApi.getEnchantments(result)
|
||||
val resultEnchsKeys = HashMap(resultEnchs)
|
||||
|
|
@ -277,13 +274,14 @@ object AnvilXpUtil {
|
|||
// We know "enchantment.key in resultEnchs" true
|
||||
val resultLevel = resultEnchs[enchantment.key]!!
|
||||
|
||||
val enchantmentMultiplier = ConfigOptions.enchantmentValue(enchantment.key, isFromBook, isToBook)
|
||||
val enchantmentMultiplier = ConfigOptions.enchantmentValue(enchantment.key, rightIsFormBook)
|
||||
val value = resultLevel * enchantmentMultiplier
|
||||
CustomAnvil.log("Value for sacrifice item ${enchantment.key.enchantmentName} level ${enchantment.value} is $value ($resultLevel * $enchantmentMultiplier)")
|
||||
rightValue += value
|
||||
|
||||
}
|
||||
if(ConfigOptions.includeLeftEnchantmentForCost) {
|
||||
val leftIsFormBook = left.isEnchantedBook()
|
||||
val leftEnchs = EnchantmentApi.getEnchantments(left)
|
||||
for (enchantment in leftEnchs) {
|
||||
// Do not process enchantment that are present on the sacrifice
|
||||
|
|
@ -291,7 +289,7 @@ object AnvilXpUtil {
|
|||
|
||||
val resultLevel = resultEnchs.getOrDefault(enchantment.key, 0)
|
||||
|
||||
val enchantmentMultiplier = ConfigOptions.enchantmentValue(enchantment.key, isFromBook, isToBook)
|
||||
val enchantmentMultiplier = ConfigOptions.enchantmentValue(enchantment.key, leftIsFormBook)
|
||||
val value = resultLevel * enchantmentMultiplier
|
||||
CustomAnvil.log("Value for left item ${enchantment.key.enchantmentName} level ${enchantment.value} is $value ($resultLevel * $enchantmentMultiplier)")
|
||||
leftValue += value
|
||||
|
|
@ -314,15 +312,15 @@ object AnvilXpUtil {
|
|||
*/
|
||||
fun calculateLevelForXp(xp: Int): Int {
|
||||
return when {
|
||||
xp <= 352 -> (sqrt((xp + 9).toDouble()) - 3).toInt()
|
||||
xp <= 352 -> (Math.sqrt((xp + 9).toDouble()) - 3).toInt()
|
||||
xp <= 1507 -> {
|
||||
val inner = (2.0 / 5.0) * (xp - 7839.0 / 40.0)
|
||||
(81.0 / 10.0 + sqrt(inner)).toInt()
|
||||
(81.0 / 10.0 + Math.sqrt(inner)).toInt()
|
||||
}
|
||||
|
||||
else -> {
|
||||
val inner = (2.0 / 9.0) * (xp - 54215.0 / 72.0)
|
||||
(325.0 / 18.0 + sqrt(inner)).toInt()
|
||||
(325.0 / 18.0 + Math.sqrt(inner)).toInt()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,8 +49,8 @@ public class DefaultConfigTests extends SharedCustomAnvilTest {
|
|||
CAEnchantment enchantment = CAEnchantmentRegistry.getInstance().getByKey(key);
|
||||
Assertions.assertNotNull(enchantment, "Enchantment was somehow not found");
|
||||
|
||||
int itemValue = ConfigOptions.INSTANCE.enchantmentValue(enchantment, false, false);
|
||||
int bookValue = ConfigOptions.INSTANCE.enchantmentValue(enchantment, false, true);
|
||||
int itemValue = ConfigOptions.INSTANCE.enchantmentValue(enchantment, false);
|
||||
int bookValue = ConfigOptions.INSTANCE.enchantmentValue(enchantment, true);
|
||||
|
||||
EnchantmentRarity rarity = enchantment.defaultRarity();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue