diff options
Diffstat (limited to 'src/main/kotlin/repo/item')
-rw-r--r-- | src/main/kotlin/repo/item/SBItemId.kt | 2 | ||||
-rw-r--r-- | src/main/kotlin/repo/item/SBItemProperty.kt | 8 | ||||
-rw-r--r-- | src/main/kotlin/repo/item/SBRecombobulator.kt | 38 |
3 files changed, 45 insertions, 3 deletions
diff --git a/src/main/kotlin/repo/item/SBItemId.kt b/src/main/kotlin/repo/item/SBItemId.kt index fcafff0..0a93609 100644 --- a/src/main/kotlin/repo/item/SBItemId.kt +++ b/src/main/kotlin/repo/item/SBItemId.kt @@ -16,7 +16,7 @@ object SBItemId : SBItemProperty.State<SkyblockId>() { override fun applyToStack(stack: ItemStack, store: SBItemData, value: SkyblockId?): ItemStack { val id = value ?: SkyblockId.NULL - return RepoManager.getNEUItem(id).asItemStack(idHint = id) + return RepoManager.getNEUItem(id).asItemStack(idHint = id).copy() } override val order: Int diff --git a/src/main/kotlin/repo/item/SBItemProperty.kt b/src/main/kotlin/repo/item/SBItemProperty.kt index 55b8f01..fd85251 100644 --- a/src/main/kotlin/repo/item/SBItemProperty.kt +++ b/src/main/kotlin/repo/item/SBItemProperty.kt @@ -8,7 +8,7 @@ import moe.nea.firmament.util.compatloader.CompatLoader /** * A property of a skyblock item. Not every skyblock item must have this property, but some should. * - * Access to this class should be limited to [State.bindWith] and [SBItemData.getData]. + * Access to this class should be limited to [State.bind] and [SBItemData.getData]. * @see State */ abstract class SBItemProperty<T> { @@ -36,8 +36,12 @@ abstract class SBItemProperty<T> { * to change the state of an item, including its rendering as a vanilla [ItemStack]. */ abstract class State<T> : SBItemProperty<T>() { + /** + * Apply the stored info back to the item stack. If possible [stack] should be modified and returned directly, + * instead of creating a new [ItemStack] instance. Information stored here should be recovered using [fromStack]. + */ abstract fun applyToStack(stack: ItemStack, store: SBItemData, value: T?): ItemStack - fun bindWith(data: T) = BoundState(this, data) + fun bind(data: T) = BoundState(this, data) } /** diff --git a/src/main/kotlin/repo/item/SBRecombobulator.kt b/src/main/kotlin/repo/item/SBRecombobulator.kt new file mode 100644 index 0000000..8798493 --- /dev/null +++ b/src/main/kotlin/repo/item/SBRecombobulator.kt @@ -0,0 +1,38 @@ +package moe.nea.firmament.repo.item + +import com.google.auto.service.AutoService +import net.minecraft.item.ItemStack +import net.minecraft.nbt.NbtInt +import moe.nea.firmament.repo.set +import moe.nea.firmament.util.extraAttributes +import moe.nea.firmament.util.mc.modifyLore +import moe.nea.firmament.util.modifyExtraAttributes +import moe.nea.firmament.util.skyblock.Rarity + +@AutoService(SBItemProperty::class) +object SBRecombobulator : SBItemProperty.State<Boolean>() { + override fun applyToStack( + stack: ItemStack, + store: SBItemData, + value: Boolean? + ): ItemStack { + if (value != true) return stack + stack.modifyLore { lore -> + Rarity.recombobulateLore(lore) + } + stack.modifyExtraAttributes { + it["rarity_upgrades"] = NbtInt.of(1) + } + return stack + } + + override fun fromStack( + stack: ItemStack, + store: SBItemData + ): Boolean? { + return stack.extraAttributes.getInt("rarity_upgrades") > 0 + } + + override val order: Int + get() = -100 +} |