diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/button/ItemButton.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/button/ItemButton.kt index 53ce2f703..692ad796b 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/button/ItemButton.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/button/ItemButton.kt @@ -199,20 +199,22 @@ class ItemButton @JvmOverloads constructor( } companion object { + @Suppress("UnstableApiUsage") private fun getCheatItemStack(currentStack: ItemStack, click: Click): ItemStack { - val clonedUnknown = currentStack.clone() - val rebarItem = RebarItem.fromStack(clonedUnknown) - - if (rebarItem == null) { + val itemSchema = RebarItemSchema.fromStack(currentStack) + if (itemSchema == null) { // Item is not Rebar - val type = Registry.MATERIAL.get(clonedUnknown.type.key)!! - val amount = if (click.clickType.isShiftClick) { type.maxStackSize } else { 1 } - val clonedNotRebar = ItemStack(type, amount) + val type = Registry.MATERIAL.get(currentStack.type.key)!! + val amount = if (click.clickType.isShiftClick) type.maxStackSize else 1 + val clonedNotRebar = ItemStack.of(type, amount) + clonedNotRebar.copyDataFrom(currentStack) { + it != DataComponentTypes.ITEM_NAME && it != DataComponentTypes.LORE + } return clonedNotRebar } else { // Rebar item handling - val clonedRebar = rebarItem.schema.getItemStack() - clonedRebar.amount = if (click.clickType.isShiftClick) { clonedRebar.maxStackSize } else { 1 } + val amount = if (click.clickType.isShiftClick) 99 else 1 // the schema will automatically cap the amount to the max stack size + val clonedRebar = itemSchema.getItemStack(amount) return clonedRebar } } diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/item/RebarItemSchema.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/item/RebarItemSchema.kt index aeeb5a47b..f26d6c8b6 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/item/RebarItemSchema.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/item/RebarItemSchema.kt @@ -19,6 +19,7 @@ import org.bukkit.NamespacedKey import org.bukkit.inventory.ItemStack import org.jetbrains.annotations.Contract import java.lang.invoke.MethodHandle +import kotlin.math.min /** * Stores information about a Rebar item type, including its key, template [ItemStack], class, and @@ -49,7 +50,7 @@ class RebarItemSchema @JvmOverloads internal constructor( * Return's a clone of the [template] [ItemStack] */ @JvmOverloads - fun getItemStack(count: Int = 1): ItemStack = template.asQuantity(count) + fun getItemStack(count: Int = 1): ItemStack = template.asQuantity(min(count, template.maxStackSize)) /** * Return's a new instance of the [RebarItem] from the [itemClass] using a copy of the [template] [ItemStack] diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/recipe/vanilla/Crafting.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/recipe/vanilla/Crafting.kt index b56061a44..eb25f345a 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/recipe/vanilla/Crafting.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/recipe/vanilla/Crafting.kt @@ -83,7 +83,7 @@ sealed class AShapelessRecipeWrapper(recipe: CraftingRecipe) : CraftingRecipeWra .addIngredient('6', getDisplaySlot(6)) .addIngredient('7', getDisplaySlot(7)) .addIngredient('8', getDisplaySlot(8)) - .addIngredient('r', recipe.result) + .addIngredient('r', ItemButton.of(recipe.result)) .build() private fun getDisplaySlot(index: Int): Item {