Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added some new methods and updated food #85

Closed
Closed
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
61 changes: 58 additions & 3 deletions src/main/kotlin/io/github/dockyardmc/item/ItemBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import io.github.dockyardmc.player.ProfilePropertyMap
import io.github.dockyardmc.registry.Items
import io.github.dockyardmc.registry.registries.Item
import io.github.dockyardmc.scroll.CustomColor
import io.github.dockyardmc.sounds.Sound
import java.util.*

class ItemBuilder() {
Expand Down Expand Up @@ -68,6 +69,16 @@ class ItemBuilder() {
return this
}

/**
* Set the lore of the item
*
* @param lore String
* @return ItemBuilder
*/
fun withLore(lore: String): ItemBuilder {
return withLore(listOf(lore))
}

/**
* Adds a line of lore to the item
*
Expand All @@ -79,6 +90,11 @@ class ItemBuilder() {
return this
}

fun addLore(lore: List<String>): ItemBuilder {
itemStack.lore.addAll(lore, true)
return this
}

/**
* Set the custom model data of the item
*
Expand Down Expand Up @@ -199,17 +215,35 @@ class ItemBuilder() {
* Set the food of the item
*
* @param nutrition Int
* @param giveSaturation Boolean (default false)
* @param saturation Float (default 1f)
* @param canAlwaysEat Boolean (default true)
* @param secondsToEat Float (default 2f)
* @return ItemBuilder
*
* @throws IllegalArgumentException if the item is not a consumable
*/
@Deprecated("Breaks in 1.21.2. Will be reworked in the future")
fun withFood(nutrition: Int, saturation: Float = 1f, canAlwaysEat: Boolean = true): ItemBuilder {
if (!itemStack.components.hasType(ConsumableItemComponent::class)) {
throw IllegalArgumentException("Item must be consumable")
}
itemStack.components.addOrUpdate(FoodItemComponent(nutrition, saturation, canAlwaysEat))
return this
}

/**
* Set the consumable of the item
*
* @param consumeSeconds Float (default 1.6f)
* @param animation ConsumableAnimation (default EAT)
* @param sound Sound
* @param hasConsumeParticles Boolean (default true)
* @param consumeEffects List<ConsumeEffect>
* @return ItemBuilder
*/
fun withConsumable(consumeSeconds: Float = 1.6f, animation: ConsumableAnimation = ConsumableAnimation.EAT, sound: Sound, hasConsumeParticles: Boolean = true, consumeEffects: List<ConsumeEffect>): ItemBuilder {
itemStack.components.addOrUpdate(ConsumableItemComponent(consumeSeconds, animation, sound, hasConsumeParticles, consumeEffects))
return this
}

/**
* Sets position for a compass to point to
*
Expand Down Expand Up @@ -260,4 +294,25 @@ class ItemBuilder() {
return this
}

/**
* Hides the additional tooltip of the item
*
* @return ItemBuilder
*/
fun hideAdditionalTooltip(): ItemBuilder {
itemStack.components.addOrUpdate(HideAdditionalTooltipItemComponent())
return this
}


/**
* Hides the tooltip of the item
*
* @return ItemBuilder
*/
fun hideTooltip(): ItemBuilder {
itemStack.components.addOrUpdate(HideTooltipItemComponent())
return this
}

}