Skip to content
Nick DeGruccio edited this page May 1, 2023 · 3 revisions

When it comes to items with Impactor, this API component aims to serve as a means of creating an easier configuration in regards to creating an item. At its core, Impactor provides the ImpactorItemStack, which is meant for simple items that carry no additional metadata that change how the item appears. However, this interface was designed to be extended, and as such, we can create custom item stacks that maintain the metadata types we aim to worry about!


Creating an ItemStack

When it comes to creating an ItemStack, we should look into ImpactorItemStack for the provided static builder suppliers. For instance, we can create a basic ItemStack starting with the following: ImpactorItemStack.basic(). This provides us with the base builder for an item stack, and permits for a set of common metadata fields that can be applied to all items. At its core, Impactor provides support for the following metadata fields:

Field Description
Title A custom name that an item stack will use as its display name
Lore Additional lines of text that can be viewed when hovering over an item stack
Quantity The size of the stack
Enchantments A set of enchantments that are applied to an item stack
Damage The amount of damage applied to a stack (Overridden by Unbreakable)
Unbreakable States that the item should not receive durability damage
Tooltip Flags (MetaFlag) Flags that are capable of hiding specific attributes when hovering over an item stack

Additionally, you can make use of ImpactorItemStackBuilder#glow(), which effectively applies a generic enchantment and the enchantment meta flag to force an item to glow with the enchantment effect, yet not detail the enchantment applied.

Examples

Below, we detail a few cases of creating an item. These examples will create different types of item stacks, each with their own set of metadata details.

Diamond

In this example, we will create a diamond with the title of A colorful diamond!. Additionally, the title will be styled with the following RGB color: #4287f5 #4287f5. Finally, this will apply the enchantment glow effect, yet hide metadata regarding the applied enchantment.

ImpactorItemStack diamond = ImpactorItemStack.basic()
        .type(ItemTypes.DIAMOND)
        .title(Component.text("A colorful diamond!").color(TextColor.color(0x42, 0x87, 0xf5)))
        .glow()
        .build();

Player Heads / Mod Skulls

In this set of examples, we create a skull for both a player and a skeleton. First, lets see how to create a skeleton skull...

SkullStack skeleton = ImpactorItemStack.skull()
        .mob(SkullStack.SkullType.SKELETON)
        .title(Component.text("A skeleton skull").color(NamedTextColor.YELLOW))
        .quantity(1)
        .build();

Here, we've created a skeleton skull with a yellow display name of "A skeleton skull". The stack, despite the default, is also specified to be a stack size of 1.

Next, lets look at how to create a player skull. When creating a player skull, there's additional functionality outside of specifying just a type of skull. The SkullStackBuilder#player comes in two forms. One which accepts a UUID, and another which accepts a string specification, and an additional boolean value that indicates whether it's a player name, or a base64 encoded texture signature. In this particular example, we will create a skull using a username of a player. Additionally, you might notice the use of a method named mini. This is making use of Kyori's Adventure MiniMessage Library, which is on its path to becoming the replacement standard for text using & for color codes.

SkullStack player = ImpactorItemStack.skull()
        .player("NickImpact", false)
        .title(mini("<gradient:green:blue>NickImpact's Skull"))
        .lore(Lists.newArrayList(mini("<gray>A skull of a really cool guy")))
        .unbreakable()
        .quantity(1)
        .build();

Custom Item Stacks

As we can see with the SkullStack, this type of stack is actually an extension of the ImpactorItemStack. It specifies a few additional details about the resulting ItemStack, and is capable of being built just like any other ItemStack.

Clone this wiki locally