mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
last know xp bug fixed.
This commit is contained in:
parent
b5a2ae67fd
commit
8d4248f1ea
6 changed files with 40 additions and 36 deletions
|
|
@ -4,7 +4,7 @@ plugins {
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "io.delilaheve"
|
group = "io.delilaheve"
|
||||||
version = "1.1.3"
|
version = "1.1.4"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ import org.bukkit.inventory.AnvilInventory
|
||||||
import org.bukkit.inventory.InventoryView.Property.REPAIR_COST
|
import org.bukkit.inventory.InventoryView.Property.REPAIR_COST
|
||||||
import org.bukkit.inventory.ItemStack
|
import org.bukkit.inventory.ItemStack
|
||||||
import org.bukkit.inventory.meta.Repairable
|
import org.bukkit.inventory.meta.Repairable
|
||||||
|
import xyz.alexcrea.group.ConflictType
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -49,7 +50,7 @@ class AnvilEventListener : Listener {
|
||||||
val resultItem = first.clone()
|
val resultItem = first.clone()
|
||||||
resultItem.setEnchantmentsUnsafe(newEnchants)
|
resultItem.setEnchantmentsUnsafe(newEnchants)
|
||||||
|
|
||||||
var anvilCost = calculateCost(first, second, resultItem, player.hasPermission(UnsafeEnchants.bypassFusePermission))
|
var anvilCost = calculateCost(first, second, resultItem)
|
||||||
if (!first.isBook() && !second.isBook()) {
|
if (!first.isBook() && !second.isBook()) {
|
||||||
// we only need to be concerned with repair when neither item is a book
|
// we only need to be concerned with repair when neither item is a book
|
||||||
val repaired = resultItem.repairFrom(first, second)
|
val repaired = resultItem.repairFrom(first, second)
|
||||||
|
|
@ -114,7 +115,7 @@ class AnvilEventListener : Listener {
|
||||||
* Function to calculate most of the xp requirement for the anvil fuse
|
* Function to calculate most of the xp requirement for the anvil fuse
|
||||||
* Change result work penalty for future use
|
* Change result work penalty for future use
|
||||||
*/
|
*/
|
||||||
private fun calculateCost(left: ItemStack, right: ItemStack, result: ItemStack, bypassFuse: Boolean): Int{
|
private fun calculateCost(left: ItemStack, right: ItemStack, result: ItemStack): Int{
|
||||||
// Extracted From https://minecraft.fandom.com/wiki/Anvil_mechanics#Enchantment_equation
|
// Extracted From https://minecraft.fandom.com/wiki/Anvil_mechanics#Enchantment_equation
|
||||||
// Calculate work penality
|
// Calculate work penality
|
||||||
val leftPenality = (left.itemMeta as? Repairable)?.repairCost ?: 0
|
val leftPenality = (left.itemMeta as? Repairable)?.repairCost ?: 0
|
||||||
|
|
@ -125,22 +126,26 @@ class AnvilEventListener : Listener {
|
||||||
var illegalPenalty = 0
|
var illegalPenalty = 0
|
||||||
|
|
||||||
val rightIsFormBook = right.isBook()
|
val rightIsFormBook = right.isBook()
|
||||||
val resultEnchs = result.findEnchantments().keys
|
val resultEnchs = result.findEnchantments()
|
||||||
|
val resultEnchsKeys = HashSet(resultEnchs.keys)
|
||||||
|
|
||||||
for (enchantment in right.findEnchantments()) {
|
for (enchantment in right.findEnchantments()) {
|
||||||
// count enchant as illegal enchant if it conflicts with another enchant or not in result
|
// count enchant as illegal enchant if it conflicts with another enchant or not in result
|
||||||
if(!bypassFuse && (
|
if((enchantment.key !in resultEnchsKeys)){
|
||||||
(enchantment.key !in resultEnchs) ||
|
resultEnchsKeys.add(enchantment.key)
|
||||||
UnsafeEnchants.conflictManager.isConflicting(resultEnchs,result.type,enchantment.key)
|
val conflictType = UnsafeEnchants.conflictManager.isConflicting(resultEnchsKeys,result.type,enchantment.key)
|
||||||
)){
|
resultEnchsKeys.remove(enchantment.key)
|
||||||
// There may an issue when illegal enchant are trying to combine
|
|
||||||
// at least that what I think, but can't find why
|
if(ConflictType.BIG_CONFLICT == conflictType){
|
||||||
illegalPenalty += ConfigOptions.sacrificeIllegalCost
|
illegalPenalty += ConfigOptions.sacrificeIllegalCost
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
// We know "enchantment.key in resultEnchs" true
|
||||||
|
val resultLevel = resultEnchs[enchantment.key]!!
|
||||||
|
|
||||||
val enchantmentMultiplier = ConfigOptions.enchantmentValue(enchantment.key, rightIsFormBook)
|
val enchantmentMultiplier = ConfigOptions.enchantmentValue(enchantment.key, rightIsFormBook)
|
||||||
val value = enchantment.value * enchantmentMultiplier
|
val value = resultLevel * enchantmentMultiplier
|
||||||
UnsafeEnchants.log("Value for ${enchantment.key.enchantmentName} level ${enchantment.value} is $value")
|
UnsafeEnchants.log("Value for ${enchantment.key.enchantmentName} level ${enchantment.value} is $value")
|
||||||
rightValue+=value
|
rightValue+=value
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import io.delilaheve.UnsafeEnchants
|
||||||
import org.bukkit.Material
|
import org.bukkit.Material
|
||||||
import org.bukkit.enchantments.Enchantment
|
import org.bukkit.enchantments.Enchantment
|
||||||
import org.bukkit.entity.HumanEntity
|
import org.bukkit.entity.HumanEntity
|
||||||
|
import xyz.alexcrea.group.ConflictType
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
|
||||||
|
|
@ -34,7 +35,7 @@ object EnchantmentUtil {
|
||||||
// Add the enchantment if it doesn't have conflicts, or, if player is allowed to bypass enchantment restrictions
|
// Add the enchantment if it doesn't have conflicts, or, if player is allowed to bypass enchantment restrictions
|
||||||
this[enchantment] = level
|
this[enchantment] = level
|
||||||
if(!player.hasPermission(UnsafeEnchants.bypassFusePermission) &&
|
if(!player.hasPermission(UnsafeEnchants.bypassFusePermission) &&
|
||||||
UnsafeEnchants.conflictManager.isConflicting(this.keys,mat,enchantment)){
|
(UnsafeEnchants.conflictManager.isConflicting(this.keys,mat,enchantment) != ConflictType.NO_CONFLICT)){
|
||||||
this.remove(enchantment)
|
this.remove(enchantment)
|
||||||
}
|
}
|
||||||
}else if(!keys.any { enchantment.conflictsWith(it) }){
|
}else if(!keys.any { enchantment.conflictsWith(it) }){
|
||||||
|
|
@ -45,7 +46,7 @@ object EnchantmentUtil {
|
||||||
// Enchantment already in result list
|
// Enchantment already in result list
|
||||||
else{
|
else{
|
||||||
// ... and they are conflicting
|
// ... and they are conflicting
|
||||||
if(UnsafeEnchants.conflictManager.isConflicting(this.keys,mat,enchantment)
|
if((UnsafeEnchants.conflictManager.isConflicting(this.keys,mat,enchantment) != ConflictType.NO_CONFLICT)
|
||||||
&& !player.hasPermission(UnsafeEnchants.bypassFusePermission)){
|
&& !player.hasPermission(UnsafeEnchants.bypassFusePermission)){
|
||||||
return@forEach
|
return@forEach
|
||||||
}
|
}
|
||||||
|
|
@ -73,20 +74,4 @@ object EnchantmentUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if a set of enchantments has any conflicts
|
|
||||||
*/
|
|
||||||
fun Map<Enchantment, Int>.hasConflicts() : Boolean {
|
|
||||||
forEach { (enchantment1, _) ->
|
|
||||||
val hasConflict = any { (enchantment2, _) ->
|
|
||||||
enchantment2.conflictsWith(enchantment1)
|
|
||||||
}
|
|
||||||
if (hasConflict) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -122,15 +122,28 @@ class EnchantConflictManager {
|
||||||
return group
|
return group
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isConflicting(base: Set<Enchantment>,mat: Material, newEnchant: Enchantment): Boolean{
|
fun isConflicting(base: Set<Enchantment>,mat: Material, newEnchant: Enchantment): ConflictType{
|
||||||
val conflictList = conflictMap[newEnchant] ?: return false
|
val conflictList = conflictMap[newEnchant] ?: return ConflictType.NO_CONFLICT
|
||||||
|
|
||||||
|
var result = ConflictType.NO_CONFLICT
|
||||||
for (conflict in conflictList) {
|
for (conflict in conflictList) {
|
||||||
if(!conflict.allowed(base,mat)) {
|
if(!conflict.allowed(base,mat)) {
|
||||||
return true
|
if(conflict.getEnchants().size <= 1){
|
||||||
|
result = ConflictType.SMALL_CONFLICT
|
||||||
|
}else{
|
||||||
|
return ConflictType.BIG_CONFLICT
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
enum class ConflictType(){
|
||||||
|
NO_CONFLICT,
|
||||||
|
SMALL_CONFLICT,
|
||||||
|
BIG_CONFLICT
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -18,7 +18,8 @@ remove_repair_limit: false
|
||||||
# Valid range of 0 - 255
|
# Valid range of 0 - 255
|
||||||
item_repair_cost: 2
|
item_repair_cost: 2
|
||||||
|
|
||||||
# Value added to the anvil when the sacrifice try to add illegal enchant to the item
|
# Value added to the anvil when a sacrifice enchantment conflict
|
||||||
|
# with one of the left item enchantment
|
||||||
#
|
#
|
||||||
# Valid range of 0 - 255
|
# Valid range of 0 - 255
|
||||||
sacrifice_illegal_enchant_cost: 1
|
sacrifice_illegal_enchant_cost: 1
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
main: io.delilaheve.UnsafeEnchants
|
main: io.delilaheve.UnsafeEnchants
|
||||||
name: UnsafeEnchantsPlus
|
name: UnsafeEnchantsPlus
|
||||||
prefix: UnsafeEnchants+
|
prefix: UnsafeEnchants+
|
||||||
version: 1.1.3
|
version: 1.1.4
|
||||||
description: Allow custom illegal enchantment
|
description: Allow custom illegal enchantment
|
||||||
api-version: 1.18
|
api-version: 1.18
|
||||||
load: POSTWORLD
|
load: POSTWORLD
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue