Add experimental ItemStack#consume

This commit is contained in:
TheMode 2021-07-23 01:47:43 +02:00
parent 6c4cb66737
commit 7fae70ebc1

View File

@ -7,6 +7,7 @@ import net.minestom.server.item.rule.VanillaStackingRule;
import net.minestom.server.tag.Tag;
import net.minestom.server.tag.TagReadable;
import net.minestom.server.utils.NBTUtils;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -105,6 +106,12 @@ public final class ItemStack implements TagReadable, HoverEventSource<HoverEvent
return withAmount(intUnaryOperator.applyAsInt(amount));
}
@ApiStatus.Experimental
@Contract(value = "_, -> new", pure = true)
public @NotNull ItemStack consume(int amount) {
return stackingRule.apply(this, currentAmount -> currentAmount - amount);
}
@Contract(value = "_, _ -> new", pure = true)
public <T extends ItemMetaBuilder, U extends ItemMetaBuilder.Provider<T>> @NotNull ItemStack withMeta(Class<U> metaType, Consumer<T> metaConsumer) {
return builder().meta(metaType, metaConsumer).build();