mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 08:14:00 +02:00
remove rename pdc on paper lore append
This commit is contained in:
parent
bf4395ba3f
commit
d679cd73f9
2 changed files with 55 additions and 39 deletions
|
|
@ -76,8 +76,10 @@ object AnvilMergeLogic {
|
||||||
val amount: Int
|
val amount: Int
|
||||||
val recipe: AnvilCustomRecipe?
|
val recipe: AnvilCustomRecipe?
|
||||||
|
|
||||||
constructor(item: ItemStack?, cost: CustomCraftCost,
|
constructor(
|
||||||
amount: Int, recipe: AnvilCustomRecipe?) : super(item, cost, true) {
|
item: ItemStack?, cost: CustomCraftCost,
|
||||||
|
amount: Int, recipe: AnvilCustomRecipe?
|
||||||
|
) : super(item, cost, true) {
|
||||||
this.customCraftCost = cost
|
this.customCraftCost = cost
|
||||||
this.amount = amount
|
this.amount = amount
|
||||||
this.recipe = recipe
|
this.recipe = recipe
|
||||||
|
|
@ -96,7 +98,8 @@ object AnvilMergeLogic {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun doRenaming(inventory: AnvilInventory,
|
fun doRenaming(
|
||||||
|
inventory: AnvilInventory,
|
||||||
player: Player, first: ItemStack
|
player: Player, first: ItemStack
|
||||||
): AnvilResult {
|
): AnvilResult {
|
||||||
val resultItem = DependencyManager.cloneItem(player, first)
|
val resultItem = DependencyManager.cloneItem(player, first)
|
||||||
|
|
@ -115,14 +118,18 @@ object AnvilMergeLogic {
|
||||||
return AnvilResult(result, cost)
|
return AnvilResult(result, cost)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun processDialogPCD(it: ItemMeta, player: HumanEntity) {
|
private fun processDialogPCD(meta: ItemMeta, player: HumanEntity) {
|
||||||
|
val text = AnvilRenameDialogUtil.anvilRenameDialog.currentText(player)
|
||||||
|
return processPCD(meta, player, text)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun processPCD(meta: ItemMeta, player: HumanEntity, text: String?) {
|
||||||
val keepDialog = ConfigOptions.canUseDialogRename(player) && ConfigOptions.shouldKeepRenameText
|
val keepDialog = ConfigOptions.canUseDialogRename(player) && ConfigOptions.shouldKeepRenameText
|
||||||
|
|
||||||
val pdc = it.persistentDataContainer
|
val pdc = meta.persistentDataContainer
|
||||||
if (!keepDialog)
|
if (!keepDialog)
|
||||||
pdc.remove(AnvilRenameDialog.PCD_KEEP_RENAME_TEXT_KEY)
|
pdc.remove(AnvilRenameDialog.PCD_KEEP_RENAME_TEXT_KEY)
|
||||||
else {
|
else {
|
||||||
val text = AnvilRenameDialogUtil.anvilRenameDialog.currentText(player)
|
|
||||||
if (text == null || text.isBlank())
|
if (text == null || text.isBlank())
|
||||||
pdc.remove(AnvilRenameDialog.PCD_KEEP_RENAME_TEXT_KEY)
|
pdc.remove(AnvilRenameDialog.PCD_KEEP_RENAME_TEXT_KEY)
|
||||||
else pdc.set(AnvilRenameDialog.PCD_KEEP_RENAME_TEXT_KEY, PersistentDataType.STRING, text)
|
else pdc.set(AnvilRenameDialog.PCD_KEEP_RENAME_TEXT_KEY, PersistentDataType.STRING, text)
|
||||||
|
|
@ -138,7 +145,8 @@ object AnvilMergeLogic {
|
||||||
if (ConfigOptions.renameColorPossible && renameText != null) {
|
if (ConfigOptions.renameColorPossible && renameText != null) {
|
||||||
val component = AnvilColorUtil.handleColor(
|
val component = AnvilColorUtil.handleColor(
|
||||||
renameText,
|
renameText,
|
||||||
AnvilColorUtil.renamePermission(player))
|
AnvilColorUtil.renamePermission(player)
|
||||||
|
)
|
||||||
|
|
||||||
if (component != null) {
|
if (component != null) {
|
||||||
renameText = MiniMessageUtil.legacy_mm.serialize(component)
|
renameText = MiniMessageUtil.legacy_mm.serialize(component)
|
||||||
|
|
@ -160,7 +168,8 @@ object AnvilMergeLogic {
|
||||||
renameText == "" ||
|
renameText == "" ||
|
||||||
//TODO on recent paper check effective name instead
|
//TODO on recent paper check effective name instead
|
||||||
renameText == CasedStringUtil.snakeToUpperSpacedCase(resultItem.type.name.lowercase())
|
renameText == CasedStringUtil.snakeToUpperSpacedCase(resultItem.type.name.lowercase())
|
||||||
)) {
|
)
|
||||||
|
) {
|
||||||
it.setDisplayName(renameText)
|
it.setDisplayName(renameText)
|
||||||
processDialogPCD(it, player)
|
processDialogPCD(it, player)
|
||||||
resultItem.itemMeta = it
|
resultItem.itemMeta = it
|
||||||
|
|
|
||||||
|
|
@ -119,7 +119,8 @@ class AnvilResultListener : Listener {
|
||||||
// Unit repair
|
// Unit repair
|
||||||
val unitRepairResult = AnvilMergeLogic.testUnitRepair(
|
val unitRepairResult = AnvilMergeLogic.testUnitRepair(
|
||||||
inventory, player,
|
inventory, player,
|
||||||
leftItem, rightItem)
|
leftItem, rightItem
|
||||||
|
)
|
||||||
if (unitRepairResult.isEmpty()) {
|
if (unitRepairResult.isEmpty()) {
|
||||||
onUnitRepairExtract(
|
onUnitRepairExtract(
|
||||||
rightItem, event, player, inventory,
|
rightItem, event, player, inventory,
|
||||||
|
|
@ -153,9 +154,11 @@ class AnvilResultListener : Listener {
|
||||||
if (recipe.removeExactLinearXp) rawCost
|
if (recipe.removeExactLinearXp) rawCost
|
||||||
else AnvilXpUtil.calculateLevelForXp(rawCost)
|
else AnvilXpUtil.calculateLevelForXp(rawCost)
|
||||||
|
|
||||||
CustomAnvil.log("gamemode: ${player.gameMode != GameMode.CREATIVE}, " +
|
CustomAnvil.log(
|
||||||
|
"gamemode: ${player.gameMode != GameMode.CREATIVE}, " +
|
||||||
"cost: $finalCost, level: ${player.level}, " +
|
"cost: $finalCost, level: ${player.level}, " +
|
||||||
"result: ${player.totalExperience < finalCost} ${player.level < finalCost}")
|
"result: ${player.totalExperience < finalCost} ${player.level < finalCost}"
|
||||||
|
)
|
||||||
|
|
||||||
if (player.gameMode != GameMode.CREATIVE) {
|
if (player.gameMode != GameMode.CREATIVE) {
|
||||||
if (ConfigOptions.shouldUseMoney(player)) {
|
if (ConfigOptions.shouldUseMoney(player)) {
|
||||||
|
|
@ -486,6 +489,10 @@ class AnvilResultListener : Listener {
|
||||||
paperCopy = rightItem.clone()
|
paperCopy = rightItem.clone()
|
||||||
paperCopy.amount = 1
|
paperCopy.amount = 1
|
||||||
paperMeta.setComponentDisplayName(null)
|
paperMeta.setComponentDisplayName(null)
|
||||||
|
|
||||||
|
// Remove pcd name
|
||||||
|
AnvilMergeLogic.processPCD(paperMeta, player, null)
|
||||||
|
|
||||||
paperCopy.itemMeta = paperMeta
|
paperCopy.itemMeta = paperMeta
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue