-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate to json for groups and add icon editing
- Loading branch information
1 parent
5072d77
commit f66210c
Showing
13 changed files
with
228 additions
and
44 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
common/src/main/java/earth/terrarium/heracles/api/groups/Group.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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package earth.terrarium.heracles.api.groups; | ||
|
||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
import earth.terrarium.heracles.api.quests.QuestIcon; | ||
import earth.terrarium.heracles.api.quests.QuestIcons; | ||
import net.minecraft.network.chat.CommonComponents; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.util.ExtraCodecs; | ||
|
||
import java.util.Optional; | ||
|
||
public record Group( | ||
Optional<QuestIcon<?>> icon, | ||
Component title, | ||
Component description | ||
) { | ||
|
||
public static final Codec<Group> CODEC = RecordCodecBuilder.create(instance -> instance.group( | ||
QuestIcons.CODEC.optionalFieldOf("icon").forGetter(Group::icon), | ||
ExtraCodecs.COMPONENT.fieldOf("title").forGetter(Group::title), | ||
ExtraCodecs.COMPONENT.fieldOf("description").forGetter(Group::description) | ||
).apply(instance, Group::new)); | ||
|
||
public Group(String id) { | ||
this(Optional.empty(), Component.nullToEmpty(id), CommonComponents.EMPTY); | ||
} | ||
|
||
public Group withIcon(QuestIcon<?> icon) { | ||
return new Group(Optional.of(icon), this.title, this.description); | ||
} | ||
|
||
public Group withTitle(Component title) { | ||
return new Group(this.icon, title, this.description); | ||
} | ||
|
||
public Group withDescription(Component description) { | ||
return new Group(this.icon, this.title, description); | ||
} | ||
|
||
@SuppressWarnings("OptionalUsedAsFieldOrParameterType") | ||
public Group edit(Optional<QuestIcon<?>> icon, Optional<Component> title, Optional<Component> description) { | ||
return new Group( | ||
this.icon.or(() -> icon), | ||
title.orElse(this.title), | ||
description.orElse(this.description) | ||
); | ||
} | ||
} |
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
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
Oops, something went wrong.