-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a91a9e0
commit 2329d67
Showing
8 changed files
with
60 additions
and
33 deletions.
There are no files selected for viewing
15 changes: 13 additions & 2 deletions
15
api/src/main/java/kr/toxicity/libraries/datacomponent/api/DataComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,21 @@ | ||
package kr.toxicity.libraries.datacomponent.api; | ||
|
||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonObject; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
|
||
public interface DataComponent { | ||
void set(@NotNull ItemAdapter adapter); | ||
@Nullable default <T> T get(@NotNull DataComponentType<T> type) { | ||
var get = getToJson(type); | ||
return get != null ? type.codec().decode(get) : null; | ||
} | ||
@Nullable JsonElement getToJson(@NotNull DataComponentType<?> type); | ||
@NotNull | ||
JsonObject get(); | ||
JsonObject getToJson(); | ||
default boolean has(@NotNull DataComponentType<?> type) { | ||
return get(type) != null; | ||
} | ||
void set(@NotNull ItemAdapter adapter); | ||
} |
8 changes: 7 additions & 1 deletion
8
api/src/main/java/kr/toxicity/libraries/datacomponent/api/wrapper/ArmorTrim.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
package kr.toxicity.libraries.datacomponent.api.wrapper; | ||
|
||
import kr.toxicity.libraries.datacomponent.api.Codec; | ||
import kr.toxicity.libraries.datacomponent.api.NMS; | ||
import kr.toxicity.libraries.datacomponent.api.TrimPattern; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public record ArmorTrim(@NotNull TrimMaterial material, @NotNull TrimPattern pattern, boolean showInTooltip) { | ||
public record ArmorTrim(@NotNull TrimMaterial material, @NotNull TrimPattern pattern, boolean showInTooltip) implements ComponentData<ArmorTrim> { | ||
@Override | ||
public Codec<ArmorTrim> codec() { | ||
return NMS.nms().trim().codec(); | ||
} | ||
} |
9 changes: 8 additions & 1 deletion
9
api/src/main/java/kr/toxicity/libraries/datacomponent/api/wrapper/FoodProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,17 @@ | ||
package kr.toxicity.libraries.datacomponent.api.wrapper; | ||
|
||
import kr.toxicity.libraries.datacomponent.api.Codec; | ||
import kr.toxicity.libraries.datacomponent.api.NMS; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.List; | ||
|
||
public record FoodProperties(int nutrition, float saturation, boolean canAlwaysEat, float eatSeconds, @NotNull List<PossibleEffect> effects) { | ||
public record FoodProperties(int nutrition, float saturation, boolean canAlwaysEat, float eatSeconds, @NotNull List<PossibleEffect> effects) implements ComponentData<FoodProperties> { | ||
public record PossibleEffect(@NotNull MobEffectInstance effect, float probability) { | ||
} | ||
|
||
@Override | ||
public Codec<FoodProperties> codec() { | ||
return NMS.nms().food().codec(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters