Skip to content

Commit bcd42c1

Browse files
committed
1.0.7
1 parent c9d800a commit bcd42c1

16 files changed

Lines changed: 367 additions & 75 deletions

File tree

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/src/main/java/kr/toxicity/libraries/datacomponent/api/Codec.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package kr.toxicity.libraries.datacomponent.api;
22

3+
import com.google.gson.JsonArray;
34
import com.google.gson.JsonElement;
45
import com.google.gson.JsonPrimitive;
56
import org.jetbrains.annotations.NotNull;
67

8+
import java.util.ArrayList;
9+
import java.util.List;
710
import java.util.function.Function;
811

912
@SuppressWarnings("unused")
@@ -12,8 +15,6 @@ public interface Codec<T> {
1215
JsonElement encode(@NotNull T t) throws IllegalStateException;
1316
@NotNull
1417
T decode(@NotNull JsonElement t) throws IllegalStateException;
15-
@NotNull
16-
Class<T> returnType();
1718

1819
Codec<Integer> INTEGER = of(Integer.TYPE, JsonPrimitive::new, JsonElement::getAsInt);
1920
Codec<String> STRING = of(String.class, JsonPrimitive::new, JsonElement::getAsString);
@@ -31,13 +32,9 @@ public interface Codec<T> {
3132
return decoder.apply(t);
3233
}
3334

34-
@Override
35-
public @NotNull Class<T> returnType() {
36-
return tClass;
37-
}
3835
};
3936
}
40-
default <R> @NotNull Codec<R> map(@NotNull Class<R> rClass, @NotNull Converter<R, T> converter) {
37+
default <R> @NotNull Codec<R> map(@NotNull Converter<R, T> converter) {
4138
return new Codec<>() {
4239
@Override
4340
public @NotNull JsonElement encode(@NotNull R r) throws IllegalStateException {
@@ -48,10 +45,22 @@ public interface Codec<T> {
4845
public @NotNull R decode(@NotNull JsonElement t) throws IllegalStateException {
4946
return converter.asWrapper(Codec.this.decode(t));
5047
}
48+
};
49+
}
50+
default Codec<List<T>> list() {
51+
return new Codec<>() {
52+
@Override
53+
public @NotNull JsonArray encode(@NotNull List<T> t) throws IllegalStateException {
54+
var array = new JsonArray();
55+
t.forEach(e -> array.add(Codec.this.encode(e)));
56+
return array;
57+
}
5158

5259
@Override
53-
public @NotNull Class<R> returnType() {
54-
return rClass;
60+
public @NotNull List<T> decode(@NotNull JsonElement t) throws IllegalStateException {
61+
var list = new ArrayList<T>();
62+
t.getAsJsonArray().forEach(e -> list.add(Codec.this.decode(e)));
63+
return list;
5564
}
5665
};
5766
}

api/src/main/java/kr/toxicity/libraries/datacomponent/api/Converter.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.jetbrains.annotations.NotNull;
44

5+
import java.util.List;
56
import java.util.function.Function;
67

78
public interface Converter<T, R> {
@@ -34,4 +35,17 @@ default Converter<R, T> reversed() {
3435
}
3536
};
3637
}
38+
default Converter<List<T>, List<R>> list() {
39+
return new Converter<>() {
40+
@Override
41+
public @NotNull List<R> asVanilla(@NotNull List<T> list) {
42+
return list.stream().map(Converter.this::asVanilla).toList();
43+
}
44+
45+
@Override
46+
public @NotNull List<T> asWrapper(@NotNull List<R> rs) {
47+
return rs.stream().map(Converter.this::asWrapper).toList();
48+
}
49+
};
50+
}
3751
}

api/src/main/java/kr/toxicity/libraries/datacomponent/api/NMS.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import org.bukkit.inventory.ItemStack;
66
import org.jetbrains.annotations.NotNull;
77

8+
import java.util.List;
9+
810
@SuppressWarnings("unused")
911
public interface NMS {
1012
static @NotNull NMS nms() {
@@ -24,14 +26,18 @@ public interface NMS {
2426
@NotNull
2527
DataComponentType<Component> customName();
2628
@NotNull
27-
DataComponentType<ItemLore> itemLore();
29+
DataComponentType<Component> itemName();
30+
@NotNull
31+
DataComponentType<ItemLore> lore();
2832
@NotNull
2933
DataComponentType<Rarity> rarity();
3034
@NotNull
3135
DataComponentType<AdventureModePredicate> canPlaceOn();
3236
@NotNull
3337
DataComponentType<AdventureModePredicate> canBreak();
3438
@NotNull
39+
DataComponentType<CustomModelData> customModelData();
40+
@NotNull
3541
DataComponentType<Integer> repairCost();
3642
@NotNull
3743
DataComponentType<Unit> creativeSlotLock();
@@ -65,4 +71,14 @@ public interface NMS {
6571
DataComponentType<ArmorTrim> trim();
6672
@NotNull
6773
DataComponentType<BlockItemStateProperties> blockState();
74+
@NotNull
75+
DataComponentType<CustomData> entityData();
76+
@NotNull
77+
DataComponentType<CustomData> bucketEntityData();
78+
@NotNull
79+
DataComponentType<CustomData> blockEntityData();
80+
@NotNull
81+
DataComponentType<Integer> ominousBottleAmplifier();
82+
@NotNull
83+
DataComponentType<List<String>> recipes();
6884
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package kr.toxicity.libraries.datacomponent.api.wrapper;
2+
3+
import org.jetbrains.annotations.NotNull;
4+
5+
import java.util.Map;
6+
7+
public record CompoundTag(@NotNull Map<String, Tag<?>> tags) {
8+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package kr.toxicity.libraries.datacomponent.api.wrapper;
2+
3+
import kr.toxicity.libraries.datacomponent.api.Codec;
4+
import kr.toxicity.libraries.datacomponent.api.NMS;
5+
import org.jetbrains.annotations.NotNull;
6+
7+
public record CustomData(@NotNull CompoundTag tag) implements ComponentData<CustomData> {
8+
@Override
9+
public Codec<CustomData> codec() {
10+
return NMS.nms().entityData().codec();
11+
}
12+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package kr.toxicity.libraries.datacomponent.api.wrapper;
2+
3+
public record CustomModelData(int value) {
4+
}

api/src/main/java/kr/toxicity/libraries/datacomponent/api/wrapper/ItemLore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
public record ItemLore(@NotNull List<Component> lines, @NotNull List<Component> styledLines) implements ComponentData<ItemLore> {
1111
@Override
1212
public Codec<ItemLore> codec() {
13-
return NMS.nms().itemLore().codec();
13+
return NMS.nms().lore().codec();
1414
}
1515
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package kr.toxicity.libraries.datacomponent.api.wrapper;
2+
3+
import org.jetbrains.annotations.NotNull;
4+
5+
import java.util.UUID;
6+
7+
public record Tag<T>(@NotNull Type<T> type, @NotNull T value) {
8+
9+
public static final Type<Byte> BYTE = new Type<>(Byte.class);
10+
public static final Type<Short> SHORT = new Type<>(Short.class);
11+
public static final Type<Integer> INT = new Type<>(Integer.class);
12+
public static final Type<Long> LONG = new Type<>(Long.class);
13+
public static final Type<UUID> UUID = new Type<>(UUID.class);
14+
public static final Type<Float> FLOAT = new Type<>(Float.class);
15+
public static final Type<String> STRING = new Type<>(String.class);
16+
public static final Type<Double> DOUBLE = new Type<>(Double.class);
17+
18+
public static final Type<byte[]> BYTE_ARRAY = new Type<>(byte[].class);
19+
public static final Type<int[]> INT_ARRAY = new Type<>(int[].class);
20+
public static final Type<long[]> LONG_ARRAY = new Type<>(long[].class);
21+
22+
public record Type<T>(@NotNull Class<T> valueType) {
23+
}
24+
}

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ allprojects {
1111
apply(plugin = "java")
1212

1313
group = "kr.toxicity.libraries.datacomponent"
14-
version = "1.0.6"
14+
version = "1.0.7"
1515

1616
repositories {
1717
mavenCentral()

0 commit comments

Comments
 (0)