-
Notifications
You must be signed in to change notification settings - Fork 3
SmithingTransformRecipe inproper itemmeta handling #53
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,31 @@ | ||
package com.mineinabyss.looty.features.recipes | ||
|
||
import com.mineinabyss.geary.papermc.datastore.decodePrefabs | ||
import com.mineinabyss.geary.papermc.datastore.* | ||
import com.mineinabyss.geary.papermc.tracking.items.components.SetItemIgnoredProperties | ||
import com.mineinabyss.geary.papermc.tracking.items.migration.SetItemIgnoredPropertyListener | ||
import com.mineinabyss.geary.prefabs.PrefabKey | ||
import com.mineinabyss.idofront.items.editItemMeta | ||
import com.mineinabyss.idofront.messaging.broadcast | ||
import com.mineinabyss.idofront.messaging.broadcastVal | ||
import com.mineinabyss.idofront.nms.nbt.fastPDC | ||
import com.mineinabyss.idofront.serialization.SerializableItemStack | ||
import com.mineinabyss.idofront.serialization.toSerializable | ||
import org.bukkit.Bukkit | ||
import org.bukkit.Keyed | ||
import org.bukkit.Material | ||
import org.bukkit.event.EventHandler | ||
import org.bukkit.event.EventPriority | ||
import org.bukkit.event.Listener | ||
import org.bukkit.event.inventory.CraftItemEvent | ||
import org.bukkit.event.inventory.PrepareAnvilEvent | ||
import org.bukkit.event.inventory.PrepareItemCraftEvent | ||
import org.bukkit.event.inventory.PrepareSmithingEvent | ||
import org.bukkit.inventory.ItemStack | ||
import org.bukkit.inventory.ShapedRecipe | ||
import org.bukkit.inventory.ShapelessRecipe | ||
import org.bukkit.inventory.SmithingTransformRecipe | ||
import org.bukkit.inventory.meta.Damageable | ||
import java.util.* | ||
|
||
class RecipeCraftingSystem : Listener { | ||
/** | ||
|
@@ -27,4 +47,34 @@ class RecipeCraftingSystem : Listener { | |
inventory.result = null | ||
} | ||
} | ||
|
||
@EventHandler | ||
fun PrepareSmithingEvent.onCustomSmithingTransform() { | ||
// Smithing will cache the last recipe, so even with 0 input | ||
// recipe will return as not null if say a Diamond Hoe was put in before | ||
if (inventory.contents.any { it?.isEmpty != false }) return | ||
// Return if no item is custom, as then vanilla should handle it fine | ||
if (inventory.contents.none { it?.fastPDC?.hasComponentsEncoded == true }) return | ||
|
||
val (template, mineral) = (inventory.inputTemplate ?: return) to (inventory.inputMineral ?: return) | ||
val equipment = inventory.inputEquipment ?: return | ||
|
||
val inputGearyEntity = equipment.fastPDC?.decodePrefabs()?.firstOrNull() ?: return | ||
val smithingTransformRecipes = Bukkit.recipeIterator().asSequence().filter { (it as? SmithingTransformRecipe)?.result?.fastPDC?.hasComponentsEncoded == true }.filterIsInstance<SmithingTransformRecipe>() | ||
val customRecipeResult = smithingTransformRecipes.filter { it.template.test(template) && it.addition.test(mineral) && it.base.itemStack.itemMeta?.persistentDataContainer?.decodePrefabs()?.firstOrNull() == inputGearyEntity }.firstOrNull()?.result | ||
var recipeResultItem = (customRecipeResult ?: ItemStack.empty()).let { result?.toSerializable()?.toItemStack(it, EnumSet.of(SerializableItemStack.Properties.DISPLAY_NAME)) } | ||
|
||
recipeResultItem = recipeResultItem?.editItemMeta { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this part necessary? the toItemStack should override as needed and keep the displayName if the ignored property is set. Is this maybe covering some case I'm not considering? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. newResult is applied ontop of oldResult so it does indeed require to fix that afterwards from my testing to get correct behaviour |
||
displayName( | ||
equipment.fastPDC?.decode<SetItemIgnoredProperties>()?.let { properties -> | ||
persistentDataContainer.encode(properties) | ||
if (SerializableItemStack.Properties.DISPLAY_NAME in properties.ignore && result?.itemMeta?.hasDisplayName() == true) | ||
result?.itemMeta?.displayName()?.compact() | ||
else displayName()?.compact() | ||
} ?: displayName()?.compact() | ||
) | ||
} | ||
|
||
result = recipeResultItem | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of moving here vs in install?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mostly because before we would need to re-register to get all custom recipes
mostly forgot to remove it from some testing tbh