Skip to content

Commit

Permalink
Fixed a bug with OptionalEntry
Browse files Browse the repository at this point in the history
Also added DefaultValueEntry.makeOptional()
  • Loading branch information
MehradN committed Jul 5, 2023
1 parent ab887e2 commit eca955d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ parchment_version=1.19.4:2023.06.26
loader_version=0.14.21

# Mod Properties
mod_version=1.2.0
mod_version=1.3.0
maven_group=ir.mehradn
archives_base_name=mehrad-config

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,23 @@ protected DefaultValueEntry(String name, @NotNull T defaultValue) {
*
* @param fallbackEntry the config entry that should provide the default value, avoid using a config entry from the same config
* @return an optional entry
* @see OptionalEntry
* @see OptionalEntry#OptionalEntry(ConfigEntry, ConfigEntry)
*/
public OptionalEntry<T> makeOptional(ConfigEntry<T> fallbackEntry) {
return new OptionalEntry<>(this, fallbackEntry);
}

/**
* Creates an optional entry from this config entry. If you use this overload, you must call {@link OptionalEntry#setFallbackEntry} as soon as
* possible before using any of the other methods, doing otherwise will cause unexpected behaviours.
*
* @return an optional entry
* @see OptionalEntry#OptionalEntry(ConfigEntry)
*/
public OptionalEntry<T> makeOptional() {
return new OptionalEntry<>(this);
}

@Override
public String getName() {
return this.name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public JsonElement toJson() {

@Override
public void fromJson(JsonElement json) {
this.hasValue = true;
this.optionalEntry.fromJson(json);
}

Expand All @@ -139,6 +140,7 @@ public void writeToBuf(FriendlyByteBuf buf) {

@Override
public void readFromBuf(FriendlyByteBuf buf) {
this.hasValue = true;
this.optionalEntry.readFromBuf(buf);
}

Expand Down

0 comments on commit eca955d

Please sign in to comment.