mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-27 11:38:03 +01:00
Offer default impl to create empty meta
This commit is contained in:
parent
731f571645
commit
c45f7b2067
@ -152,7 +152,7 @@ public class ItemMeta implements TagReadable, Writeable {
|
|||||||
|
|
||||||
@Contract(value = "-> new", pure = true)
|
@Contract(value = "-> new", pure = true)
|
||||||
protected @NotNull ItemMetaBuilder builder() {
|
protected @NotNull ItemMetaBuilder builder() {
|
||||||
ItemMetaBuilder result = metaBuilder.getSupplier().get();
|
ItemMetaBuilder result = metaBuilder.createEmpty();
|
||||||
ItemMetaBuilder.resetMeta(result, nbt);
|
ItemMetaBuilder.resetMeta(result, nbt);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -198,7 +198,15 @@ public abstract class ItemMetaBuilder implements TagWritable {
|
|||||||
|
|
||||||
public abstract void read(@NotNull NBTCompound nbtCompound);
|
public abstract void read(@NotNull NBTCompound nbtCompound);
|
||||||
|
|
||||||
protected abstract @NotNull Supplier<@NotNull ItemMetaBuilder> getSupplier();
|
protected @NotNull ItemMetaBuilder createEmpty() {
|
||||||
|
try {
|
||||||
|
var constructor = getClass().getDeclaredConstructor();
|
||||||
|
constructor.setAccessible(true);
|
||||||
|
return constructor.newInstance();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void mutateNbt(Consumer<MutableNBTCompound> consumer) {
|
protected void mutateNbt(Consumer<MutableNBTCompound> consumer) {
|
||||||
consumer.accept(nbt);
|
consumer.accept(nbt);
|
||||||
|
@ -129,10 +129,5 @@ public final class ItemStackBuilder {
|
|||||||
public void read(@NotNull NBTCompound nbtCompound) {
|
public void read(@NotNull NBTCompound nbtCompound) {
|
||||||
// Empty
|
// Empty
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected @NotNull Supplier<@NotNull ItemMetaBuilder> getSupplier() {
|
|
||||||
return DefaultMeta::new;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@ import org.jglrxavpok.hephaistos.nbt.NBTType;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
@ApiStatus.Experimental
|
@ApiStatus.Experimental
|
||||||
public class BundleMeta extends ItemMeta implements ItemMetaBuilder.Provider<BundleMeta.Builder> {
|
public class BundleMeta extends ItemMeta implements ItemMetaBuilder.Provider<BundleMeta.Builder> {
|
||||||
@ -71,10 +70,5 @@ public class BundleMeta extends ItemMeta implements ItemMetaBuilder.Provider<Bun
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected @NotNull Supplier<@NotNull ItemMetaBuilder> getSupplier() {
|
|
||||||
return Builder::new;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@ import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
|||||||
import org.jglrxavpok.hephaistos.nbt.NBTString;
|
import org.jglrxavpok.hephaistos.nbt.NBTString;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
public class CompassMeta extends ItemMeta implements ItemMetaBuilder.Provider<CompassMeta.Builder> {
|
public class CompassMeta extends ItemMeta implements ItemMetaBuilder.Provider<CompassMeta.Builder> {
|
||||||
|
|
||||||
@ -105,10 +104,5 @@ public class CompassMeta extends ItemMeta implements ItemMetaBuilder.Provider<Co
|
|||||||
this.lodestonePosition = new Vec(x, y, z);
|
this.lodestonePosition = new Vec(x, y, z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected @NotNull Supplier<ItemMetaBuilder> getSupplier() {
|
|
||||||
return Builder::new;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ import org.jglrxavpok.hephaistos.nbt.*;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
public class CrossbowMeta extends ItemMeta implements ItemMetaBuilder.Provider<SpawnEggMeta.Builder> {
|
public class CrossbowMeta extends ItemMeta implements ItemMetaBuilder.Provider<SpawnEggMeta.Builder> {
|
||||||
|
|
||||||
@ -170,11 +169,6 @@ public class CrossbowMeta extends ItemMeta implements ItemMetaBuilder.Provider<S
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected @NotNull Supplier<ItemMetaBuilder> getSupplier() {
|
|
||||||
return Builder::new;
|
|
||||||
}
|
|
||||||
|
|
||||||
private @NotNull NBTCompound getItemCompound(@NotNull ItemStack itemStack) {
|
private @NotNull NBTCompound getItemCompound(@NotNull ItemStack itemStack) {
|
||||||
NBTCompound compound = itemStack.getMeta().toNBT();
|
NBTCompound compound = itemStack.getMeta().toNBT();
|
||||||
return compound.modify(n -> {
|
return compound.modify(n -> {
|
||||||
|
@ -11,7 +11,6 @@ import org.jglrxavpok.hephaistos.nbt.NBTType;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
public class EnchantedBookMeta extends ItemMeta implements ItemMetaBuilder.Provider<EnchantedBookMeta.Builder> {
|
public class EnchantedBookMeta extends ItemMeta implements ItemMetaBuilder.Provider<EnchantedBookMeta.Builder> {
|
||||||
|
|
||||||
@ -60,10 +59,5 @@ public class EnchantedBookMeta extends ItemMeta implements ItemMetaBuilder.Provi
|
|||||||
NBTUtils.loadEnchantments(list.asListOf(), this::enchantment);
|
NBTUtils.loadEnchantments(list.asListOf(), this::enchantment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected @NotNull Supplier<ItemMetaBuilder> getSupplier() {
|
|
||||||
return Builder::new;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,6 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
public class FireworkEffectMeta extends ItemMeta implements ItemMetaBuilder.Provider<FireworkEffectMeta.Builder> {
|
public class FireworkEffectMeta extends ItemMeta implements ItemMetaBuilder.Provider<FireworkEffectMeta.Builder> {
|
||||||
|
|
||||||
private final FireworkEffect fireworkEffect;
|
private final FireworkEffect fireworkEffect;
|
||||||
@ -43,10 +41,5 @@ public class FireworkEffectMeta extends ItemMeta implements ItemMetaBuilder.Prov
|
|||||||
this.fireworkEffect = FireworkEffect.fromCompound(explosionCompound);
|
this.fireworkEffect = FireworkEffect.fromCompound(explosionCompound);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected @NotNull Supplier<ItemMetaBuilder> getSupplier() {
|
|
||||||
return Builder::new;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -8,7 +8,6 @@ import org.jglrxavpok.hephaistos.nbt.*;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
public class FireworkMeta extends ItemMeta implements ItemMetaBuilder.Provider<FireworkMeta.Builder> {
|
public class FireworkMeta extends ItemMeta implements ItemMetaBuilder.Provider<FireworkMeta.Builder> {
|
||||||
|
|
||||||
@ -75,10 +74,5 @@ public class FireworkMeta extends ItemMeta implements ItemMetaBuilder.Provider<F
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected @NotNull Supplier<ItemMetaBuilder> getSupplier() {
|
|
||||||
return Builder::new;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -8,8 +8,6 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
||||||
import org.jglrxavpok.hephaistos.nbt.NBTInt;
|
import org.jglrxavpok.hephaistos.nbt.NBTInt;
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
public class LeatherArmorMeta extends ItemMeta implements ItemMetaBuilder.Provider<LeatherArmorMeta.Builder> {
|
public class LeatherArmorMeta extends ItemMeta implements ItemMetaBuilder.Provider<LeatherArmorMeta.Builder> {
|
||||||
|
|
||||||
private final Color color;
|
private final Color color;
|
||||||
@ -52,10 +50,5 @@ public class LeatherArmorMeta extends ItemMeta implements ItemMetaBuilder.Provid
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected @NotNull Supplier<ItemMetaBuilder> getSupplier() {
|
|
||||||
return Builder::new;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
public class MapMeta extends ItemMeta implements ItemMetaBuilder.Provider<MapMeta.Builder> {
|
public class MapMeta extends ItemMeta implements ItemMetaBuilder.Provider<MapMeta.Builder> {
|
||||||
|
|
||||||
@ -156,11 +155,6 @@ public class MapMeta extends ItemMeta implements ItemMetaBuilder.Provider<MapMet
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected @NotNull Supplier<@NotNull ItemMetaBuilder> getSupplier() {
|
|
||||||
return Builder::new;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public record Decoration(String id, byte type, byte x, byte z, double rotation) {
|
public record Decoration(String id, byte type, byte x, byte z, double rotation) {
|
||||||
|
@ -12,7 +12,6 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
public class PlayerHeadMeta extends ItemMeta implements ItemMetaBuilder.Provider<PlayerHeadMeta.Builder> {
|
public class PlayerHeadMeta extends ItemMeta implements ItemMetaBuilder.Provider<PlayerHeadMeta.Builder> {
|
||||||
|
|
||||||
@ -86,10 +85,5 @@ public class PlayerHeadMeta extends ItemMeta implements ItemMetaBuilder.Provider
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected @NotNull Supplier<ItemMetaBuilder> getSupplier() {
|
|
||||||
return Builder::new;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,6 @@ import java.time.Duration;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
public class PotionMeta extends ItemMeta implements ItemMetaBuilder.Provider<PotionMeta.Builder> {
|
public class PotionMeta extends ItemMeta implements ItemMetaBuilder.Provider<PotionMeta.Builder> {
|
||||||
|
|
||||||
@ -109,10 +108,5 @@ public class PotionMeta extends ItemMeta implements ItemMetaBuilder.Provider<Pot
|
|||||||
this.color = new Color(color.getValue());
|
this.color = new Color(color.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected @NotNull Supplier<ItemMetaBuilder> getSupplier() {
|
|
||||||
return Builder::new;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,8 +7,6 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
public class SpawnEggMeta extends ItemMeta implements ItemMetaBuilder.Provider<SpawnEggMeta.Builder> {
|
public class SpawnEggMeta extends ItemMeta implements ItemMetaBuilder.Provider<SpawnEggMeta.Builder> {
|
||||||
|
|
||||||
private final EntityType entityType;
|
private final EntityType entityType;
|
||||||
@ -41,10 +39,5 @@ public class SpawnEggMeta extends ItemMeta implements ItemMetaBuilder.Provider<S
|
|||||||
public void read(@NotNull NBTCompound nbtCompound) {
|
public void read(@NotNull NBTCompound nbtCompound) {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected @NotNull Supplier<ItemMetaBuilder> getSupplier() {
|
|
||||||
return Builder::new;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -11,7 +11,6 @@ import org.jglrxavpok.hephaistos.nbt.*;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
public class WritableBookMeta extends ItemMeta implements ItemMetaBuilder.Provider<WritableBookMeta.Builder> {
|
public class WritableBookMeta extends ItemMeta implements ItemMetaBuilder.Provider<WritableBookMeta.Builder> {
|
||||||
|
|
||||||
@ -92,10 +91,5 @@ public class WritableBookMeta extends ItemMeta implements ItemMetaBuilder.Provid
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected @NotNull Supplier<ItemMetaBuilder> getSupplier() {
|
|
||||||
return WritableBookMeta.Builder::new;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
public class WrittenBookMeta extends ItemMeta implements ItemMetaBuilder.Provider<WrittenBookMeta.Builder> {
|
public class WrittenBookMeta extends ItemMeta implements ItemMetaBuilder.Provider<WrittenBookMeta.Builder> {
|
||||||
|
|
||||||
@ -158,10 +157,5 @@ public class WrittenBookMeta extends ItemMeta implements ItemMetaBuilder.Provide
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected @NotNull Supplier<ItemMetaBuilder> getSupplier() {
|
|
||||||
return Builder::new;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ import org.jglrxavpok.hephaistos.nbt.mutable.MutableNBTCompound;
|
|||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
@ -26,12 +25,6 @@ public class ItemMetaBuilderRegressions {
|
|||||||
// don't care
|
// don't care
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected @NotNull Supplier<@NotNull ItemMetaBuilder> getSupplier() {
|
|
||||||
// don't care
|
|
||||||
return () -> this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleCompound(@NotNull String key, @NotNull Consumer<@NotNull MutableNBTCompound> consumer) {
|
public void handleCompound(@NotNull String key, @NotNull Consumer<@NotNull MutableNBTCompound> consumer) {
|
||||||
super.handleCompound(key, consumer);
|
super.handleCompound(key, consumer);
|
||||||
|
Loading…
Reference in New Issue
Block a user