mirror of
https://github.com/Minestom/Minestom.git
synced 2024-11-07 03:10:19 +01:00
Add generic to Tag#NBT
This commit is contained in:
parent
36e2c2b78a
commit
66145a53c6
@ -62,7 +62,7 @@ public class Tag<T> {
|
||||
@Contract(value = "_, _ -> new", pure = true)
|
||||
public <R> Tag<R> map(@NotNull Function<T, R> readMap,
|
||||
@NotNull Function<R, T> writeMap) {
|
||||
return new Tag<R>(key,
|
||||
return new Tag<>(key,
|
||||
// Read
|
||||
nbtCompound -> {
|
||||
final var old = readFunction.apply(nbtCompound);
|
||||
@ -155,17 +155,15 @@ public class Tag<T> {
|
||||
(nbtCompound, value) -> nbtCompound.setString(key, value));
|
||||
}
|
||||
|
||||
public static @NotNull Tag<NBT> NBT(@NotNull String key) {
|
||||
public static <T extends NBT> @NotNull Tag<T> NBT(@NotNull String key) {
|
||||
return new Tag<>(key,
|
||||
nbt -> {
|
||||
var currentNBT = nbt.get(key);
|
||||
|
||||
final var currentNBT = nbt.get(key);
|
||||
// Avoid a NPE when cloning a null variable.
|
||||
if (currentNBT == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return currentNBT.deepClone();
|
||||
return (T) currentNBT.deepClone();
|
||||
},
|
||||
((nbt, value) -> nbt.set(key, value.deepClone())));
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ import net.minestom.server.tag.TagWritable;
|
||||
import net.minestom.server.utils.NamespaceID;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jglrxavpok.hephaistos.nbt.NBT;
|
||||
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
||||
import org.jglrxavpok.hephaistos.nbt.NBTList;
|
||||
import org.jglrxavpok.hephaistos.nbt.NBTTypes;
|
||||
@ -23,11 +22,11 @@ import java.util.List;
|
||||
public class CampfireHandler implements BlockHandler {
|
||||
|
||||
public static final Tag<List<ItemStack>> ITEMS = Tag.View(new TagSerializer<>() {
|
||||
private final Tag<NBT> internal = Tag.NBT("Items");
|
||||
private final Tag<NBTList<NBTCompound>> internal = Tag.NBT("Items");
|
||||
|
||||
@Override
|
||||
public @Nullable List<ItemStack> read(@NotNull TagReadable reader) {
|
||||
NBTList<NBTCompound> item = (NBTList<NBTCompound>) reader.getTag(internal);
|
||||
NBTList<NBTCompound> item = reader.getTag(internal);
|
||||
List<ItemStack> result = new ArrayList<>();
|
||||
assert item != null;
|
||||
item.forEach(nbtCompound -> {
|
||||
|
Loading…
Reference in New Issue
Block a user