Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading