-
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial update for 1.20.3 * neoforge: `SquaremapPlayerCapability` -> `SquaremapPlayerData` * neoforge: update `mods.toml` * Update Paper platform * Add config migration for grass to short_grass rename * Refactor rename config migration * build cleanup * Ignore unclaimed annotation warnings * 1.20.4 * Update Fabric platform * neoforge: Replace use of FMLJavaModLoadingContext * neoforge: bump runtime adventure
- Loading branch information
Showing
20 changed files
with
198 additions
and
111 deletions.
There are no files selected for viewing
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
79 changes: 79 additions & 0 deletions
79
common/src/main/java/xyz/jpenilla/squaremap/common/config/Transformations.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,79 @@ | ||
package xyz.jpenilla.squaremap.common.config; | ||
|
||
import io.leangen.geantyref.TypeToken; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
import org.checkerframework.checker.nullness.qual.NonNull; | ||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
import org.checkerframework.framework.qual.DefaultQualifier; | ||
import org.spongepowered.configurate.ConfigurateException; | ||
import org.spongepowered.configurate.ConfigurationNode; | ||
import org.spongepowered.configurate.serialize.SerializationException; | ||
import org.spongepowered.configurate.transformation.TransformAction; | ||
import xyz.jpenilla.squaremap.common.util.CheckedConsumer; | ||
|
||
@DefaultQualifier(NonNull.class) | ||
final class Transformations { | ||
private Transformations() { | ||
} | ||
|
||
static Set<String> maybeMinecraft(final String name) { | ||
return Set.of(name, "minecraft:" + name); | ||
} | ||
|
||
static TransformAction eachMapChild(final CheckedConsumer<ConfigurationNode, ConfigurateException> action) { | ||
return (path, node) -> { | ||
final Set<Object> childKeys = node.childrenMap().keySet(); | ||
for (final Object childKey : childKeys) { | ||
final ConfigurationNode childNode = node.node(childKey); | ||
action.accept(childNode); | ||
} | ||
return null; | ||
}; | ||
} | ||
|
||
// expects nodes to be round-trip representable as List<String> or Map<String, String> | ||
static void applyMapKeyOrListValueRenames(final List<ConfigurationNode> sections, final Map<Set<String>, String> renames) throws SerializationException { | ||
for (final ConfigurationNode sectionNode : sections) { | ||
if (sectionNode.isList()) { | ||
final List<String> list = Objects.requireNonNull(sectionNode.getList(String.class)); | ||
boolean anyRemoved = false; | ||
for (final Map.Entry<Set<String>, String> renameEntry : renames.entrySet()) { | ||
boolean removed = false; | ||
for (final String from : renameEntry.getKey()) { | ||
removed |= list.remove(from); | ||
} | ||
if (removed) { | ||
list.add(renameEntry.getValue()); | ||
} | ||
anyRemoved |= removed; | ||
} | ||
if (anyRemoved) { | ||
sectionNode.setList(String.class, list); | ||
} | ||
} else if (sectionNode.isMap()) { | ||
final TypeToken<Map<String, String>> type = new TypeToken<>() {}; | ||
final Map<String, String> map = Objects.requireNonNull(sectionNode.get(type)); | ||
boolean anyRemoved = false; | ||
for (final Map.Entry<Set<String>, String> renameEntry : renames.entrySet()) { | ||
@Nullable String removed = null; | ||
for (final String from : renameEntry.getKey()) { | ||
final @Nullable String remove = map.remove(from); | ||
if (remove != null) { | ||
removed = remove; | ||
} | ||
} | ||
if (removed != null) { | ||
map.put(renameEntry.getValue(), removed); | ||
anyRemoved = true; | ||
} | ||
} | ||
if (anyRemoved) { | ||
sectionNode.set(type, map); | ||
} | ||
} | ||
} | ||
} | ||
} |
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.