mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-23 00:21:26 +01:00
Improve creation of item builder
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
83baabcbba
commit
e026a841ab
@ -11,7 +11,7 @@ import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
record ItemMetaImpl(TagHandler tagHandler) implements ItemMeta {
|
||||
static final ItemMeta EMPTY = new ItemMetaImpl(TagHandler.newHandler());
|
||||
static final ItemMetaImpl EMPTY = new ItemMetaImpl(TagHandler.newHandler());
|
||||
|
||||
@Override
|
||||
public <T> @UnknownNullability T getTag(@NotNull Tag<T> tag) {
|
||||
|
@ -129,7 +129,7 @@ public sealed interface ItemStack extends TagReadable, HoverEventSource<HoverEve
|
||||
@ApiStatus.Experimental
|
||||
@Contract(value = "_ -> new", pure = true)
|
||||
default @NotNull ItemStack withMeta(@NotNull ItemMeta meta) {
|
||||
return new ItemStackImpl(material(), amount(), meta);
|
||||
return ItemStackImpl.create(material(), amount(), meta);
|
||||
}
|
||||
|
||||
@Contract(value = "_, -> new", pure = true)
|
||||
|
@ -13,7 +13,7 @@ import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
record ItemStackImpl(Material material, int amount, ItemMeta meta) implements ItemStack {
|
||||
record ItemStackImpl(Material material, int amount, ItemMetaImpl meta) implements ItemStack {
|
||||
static final @NotNull StackingRule DEFAULT_STACKING_RULE;
|
||||
|
||||
static {
|
||||
@ -32,7 +32,7 @@ record ItemStackImpl(Material material, int amount, ItemMeta meta) implements It
|
||||
|
||||
static ItemStack create(Material material, int amount, ItemMeta meta) {
|
||||
if (amount <= 0) return AIR;
|
||||
return new ItemStackImpl(material, amount, meta);
|
||||
return new ItemStackImpl(material, amount, (ItemMetaImpl) meta);
|
||||
}
|
||||
|
||||
static ItemStack create(Material material, int amount) {
|
||||
@ -83,15 +83,15 @@ record ItemStackImpl(Material material, int amount, ItemMeta meta) implements It
|
||||
|
||||
@Contract(value = "-> new", pure = true)
|
||||
private @NotNull ItemStack.Builder builder() {
|
||||
return new Builder(material, amount, new ItemMetaImpl.Builder(TagHandler.fromCompound(meta.toNBT())));
|
||||
return new Builder(material, amount, new ItemMetaImpl.Builder(meta.tagHandler().copy()));
|
||||
}
|
||||
|
||||
static final class Builder implements ItemStack.Builder {
|
||||
final Material material;
|
||||
int amount;
|
||||
ItemMeta.Builder metaBuilder;
|
||||
ItemMetaImpl.Builder metaBuilder;
|
||||
|
||||
Builder(Material material, int amount, ItemMeta.Builder metaBuilder) {
|
||||
Builder(Material material, int amount, ItemMetaImpl.Builder metaBuilder) {
|
||||
this.material = material;
|
||||
this.amount = amount;
|
||||
this.metaBuilder = metaBuilder;
|
||||
@ -125,7 +125,7 @@ record ItemStackImpl(Material material, int amount, ItemMeta meta) implements It
|
||||
|
||||
@Override
|
||||
public ItemStack.@NotNull Builder meta(@NotNull UnaryOperator<ItemMeta.Builder> consumer) {
|
||||
this.metaBuilder = consumer.apply(metaBuilder);
|
||||
this.metaBuilder = (ItemMetaImpl.Builder) consumer.apply(metaBuilder);
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -142,7 +142,7 @@ record ItemStackImpl(Material material, int amount, ItemMeta meta) implements It
|
||||
return ItemStackImpl.create(material, amount, metaBuilder.build());
|
||||
}
|
||||
|
||||
private ItemStack.@NotNull Builder metaBuilder(@NotNull ItemMeta.Builder builder) {
|
||||
private ItemStack.@NotNull Builder metaBuilder(@NotNull ItemMetaImpl.Builder builder) {
|
||||
this.metaBuilder = builder;
|
||||
return this;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user