mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-14 19:32:17 +01:00
WIP item meta API
This commit is contained in:
parent
70191e23e9
commit
0ab66113c8
@ -1,6 +1,7 @@
|
|||||||
package net.minestom.server.item;
|
package net.minestom.server.item;
|
||||||
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.minestom.server.item.metadata.ItemMeta;
|
||||||
import org.jetbrains.annotations.Contract;
|
import org.jetbrains.annotations.Contract;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@ -14,6 +15,7 @@ public class Item {
|
|||||||
|
|
||||||
private final Material material;
|
private final Material material;
|
||||||
private final int amount;
|
private final int amount;
|
||||||
|
//private final ItemMeta meta;
|
||||||
private final Component displayName;
|
private final Component displayName;
|
||||||
private final List<Component> lore;
|
private final List<Component> lore;
|
||||||
|
|
||||||
@ -60,6 +62,10 @@ public class Item {
|
|||||||
return withAmount(intUnaryOperator.applyAsInt(amount));
|
return withAmount(intUnaryOperator.applyAsInt(amount));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public <T extends ItemMeta> @NotNull Item withMeta(Class<T> metaType, Consumer<T> metaConsumer) {
|
||||||
|
return builder().meta(metaType, metaConsumer).build();
|
||||||
|
}
|
||||||
|
|
||||||
@Contract(pure = true)
|
@Contract(pure = true)
|
||||||
public @Nullable Component getDisplayName() {
|
public @Nullable Component getDisplayName() {
|
||||||
return displayName;
|
return displayName;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package net.minestom.server.item;
|
package net.minestom.server.item;
|
||||||
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.minestom.server.item.metadata.ItemMeta;
|
||||||
import org.jetbrains.annotations.Contract;
|
import org.jetbrains.annotations.Contract;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@ -8,6 +9,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class ItemBuilder {
|
public class ItemBuilder {
|
||||||
|
|
||||||
@ -27,6 +29,12 @@ public class ItemBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Contract(value = "_, _ -> this")
|
||||||
|
public <T extends ItemMeta> @NotNull ItemBuilder meta(Class<T> metaType, Consumer<T> metaConsumer) {
|
||||||
|
// TODO
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Contract(value = "_ -> this")
|
@Contract(value = "_ -> this")
|
||||||
public @NotNull ItemBuilder displayName(@Nullable Component displayName) {
|
public @NotNull ItemBuilder displayName(@Nullable Component displayName) {
|
||||||
this.displayName = displayName;
|
this.displayName = displayName;
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
package net.minestom.server.item;
|
||||||
|
|
||||||
|
public class ItemMetaBuilder {
|
||||||
|
|
||||||
|
}
|
@ -29,6 +29,7 @@ import net.minestom.server.inventory.PlayerInventory;
|
|||||||
import net.minestom.server.item.Item;
|
import net.minestom.server.item.Item;
|
||||||
import net.minestom.server.item.ItemStack;
|
import net.minestom.server.item.ItemStack;
|
||||||
import net.minestom.server.item.Material;
|
import net.minestom.server.item.Material;
|
||||||
|
import net.minestom.server.item.metadata.WritableBookMeta;
|
||||||
import net.minestom.server.network.ConnectionManager;
|
import net.minestom.server.network.ConnectionManager;
|
||||||
import net.minestom.server.ping.ResponseDataConsumer;
|
import net.minestom.server.ping.ResponseDataConsumer;
|
||||||
import net.minestom.server.utils.Position;
|
import net.minestom.server.utils.Position;
|
||||||
@ -65,14 +66,24 @@ public class PlayerInit {
|
|||||||
//inventory.setItemStack(3, new ItemStack(Material.DIAMOND, (byte) 34));
|
//inventory.setItemStack(3, new ItemStack(Material.DIAMOND, (byte) 34));
|
||||||
|
|
||||||
{
|
{
|
||||||
Item item = Item.builder(Material.STONE)
|
Item item = Item.builder(Material.WRITABLE_BOOK)
|
||||||
.amount(5)
|
.amount(5)
|
||||||
|
.meta(WritableBookMeta.class, writableBookMeta -> {
|
||||||
|
writableBookMeta.setTitle("Title");
|
||||||
|
})
|
||||||
.displayName(Component.text("displayName"))
|
.displayName(Component.text("displayName"))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
item = item.with(itemBuilder -> itemBuilder
|
item = item.with(itemBuilder -> itemBuilder
|
||||||
.amount(10)
|
.amount(10)
|
||||||
|
.meta(WritableBookMeta.class, writableBookMeta -> {
|
||||||
|
writableBookMeta.setTitle("Title2");
|
||||||
|
})
|
||||||
.lore(Component.text("Lore")));
|
.lore(Component.text("Lore")));
|
||||||
|
|
||||||
|
item = item.withMeta(WritableBookMeta.class, writableBookMeta -> {
|
||||||
|
writableBookMeta.setTitle("Title3");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user