From 2765abf971b72b88e9876b66d94f054fd75d4892 Mon Sep 17 00:00:00 2001 From: Jonathan Coates Date: Sun, 28 Jul 2024 16:47:41 +0100 Subject: [PATCH] Udpate to latest Neo, Fabric and Parchment - Update to latest NeoForge, fixing issues with config API changes. Closes #1903. - Update to latest Fabric, switching to the ender pearl conventional tag, and new loot API. --- gradle/libs.versions.toml | 8 ++++---- .../computercraft/recipe/wireless_modem_normal.json | 0 .../mixin/ItemStackComponentizationFixMixin.java | 2 +- .../computercraft/shared/config/AddressRuleConfig.java | 7 +++++++ .../dan200/computercraft/shared/config/ConfigFile.java | 2 +- .../dan200/computercraft/shared/config/ConfigSpec.java | 4 ++-- .../shared/recipe/CustomShapedRecipe.java | 6 +++--- .../computercraft/recipe/wireless_modem_normal.json | 7 ------- .../dan200/computercraft/shared/ComputerCraft.java | 4 ++-- .../shared/platform/FabricConfigFile.java | 3 ++- .../shared/platform/PlatformHelperImpl.java | 2 +- projects/fabric/src/main/resources/fabric.mod.json | 2 +- .../main/java/dan200/computercraft/ComputerCraft.java | 4 +--- .../computercraft/shared/platform/ForgeConfigFile.java | 10 ++++++---- 14 files changed, 31 insertions(+), 30 deletions(-) rename projects/{forge => common}/src/generated/resources/data/computercraft/recipe/wireless_modem_normal.json (100%) delete mode 100644 projects/fabric/src/generated/resources/data/computercraft/recipe/wireless_modem_normal.json diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 8e970ea2b..ff0dccd70 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -7,13 +7,13 @@ # Minecraft # MC version is specified in gradle.properties, as we need that in settings.gradle. # Remember to update corresponding versions in fabric.mod.json/neoforge.mods.toml -fabric-api = "0.100.3+1.21" +fabric-api = "0.100.7+1.21" fabric-loader = "0.15.11" -neoForge = "21.0.42-beta" +neoForge = "21.0.143" neoForgeSpi = "8.0.1" mixin = "0.8.5" -parchment = "2024.06.16" -parchmentMc = "1.20.6" +parchment = "2024.07.28" +parchmentMc = "1.21" yarn = "1.21+build.1" # Core dependencies (these versions are tied to the version Minecraft uses) diff --git a/projects/forge/src/generated/resources/data/computercraft/recipe/wireless_modem_normal.json b/projects/common/src/generated/resources/data/computercraft/recipe/wireless_modem_normal.json similarity index 100% rename from projects/forge/src/generated/resources/data/computercraft/recipe/wireless_modem_normal.json rename to projects/common/src/generated/resources/data/computercraft/recipe/wireless_modem_normal.json diff --git a/projects/common/src/main/java/dan200/computercraft/mixin/ItemStackComponentizationFixMixin.java b/projects/common/src/main/java/dan200/computercraft/mixin/ItemStackComponentizationFixMixin.java index 16984f6cf..f3a92b1cd 100644 --- a/projects/common/src/main/java/dan200/computercraft/mixin/ItemStackComponentizationFixMixin.java +++ b/projects/common/src/main/java/dan200/computercraft/mixin/ItemStackComponentizationFixMixin.java @@ -31,7 +31,7 @@ abstract class ItemStackComponentizationFixMixin extends DataFix { } @Inject(method = "fixItemStack", at = @At("TAIL")) - @SuppressWarnings("UnusedMethod") + @SuppressWarnings("unused") private static void fixItemStack(ItemStackComponentizationFix.ItemStackData data, Dynamic ops, CallbackInfo ci) { ComponentizationFixers.fixItemComponents(data, ops); } diff --git a/projects/common/src/main/java/dan200/computercraft/shared/config/AddressRuleConfig.java b/projects/common/src/main/java/dan200/computercraft/shared/config/AddressRuleConfig.java index 5ee6ce442..3cc27039a 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/config/AddressRuleConfig.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/config/AddressRuleConfig.java @@ -69,6 +69,13 @@ class AddressRuleConfig { ); } + public static UnmodifiableConfig newRule() { + return makeRule(config -> { + config.add("host", "example.com"); + config.add("action", Action.DENY.name().toLowerCase(Locale.ROOT)); + }); + } + private static UnmodifiableConfig makeRule(Consumer setup) { var config = InMemoryCommentedFormat.defaultInstance().createConfig(LinkedHashMap::new); setup.accept(config); diff --git a/projects/common/src/main/java/dan200/computercraft/shared/config/ConfigFile.java b/projects/common/src/main/java/dan200/computercraft/shared/config/ConfigFile.java index 7a55c8284..5fe5f01d2 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/config/ConfigFile.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/config/ConfigFile.java @@ -126,7 +126,7 @@ public interface ConfigFile { public abstract ConfigFile.Value defineInRange(String path, int defaultValue, int min, int max); - public abstract ConfigFile.Value> defineList(String path, List defaultValue, Predicate elementValidator); + public abstract ConfigFile.Value> defineList(String path, List defaultValue, Supplier newValue, Predicate elementValidator); public abstract > ConfigFile.Value defineEnum(String path, V defaultValue); diff --git a/projects/common/src/main/java/dan200/computercraft/shared/config/ConfigSpec.java b/projects/common/src/main/java/dan200/computercraft/shared/config/ConfigSpec.java index 0be520ba5..1d28130e4 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/config/ConfigSpec.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/config/ConfigSpec.java @@ -145,7 +145,7 @@ public final class ConfigSpec { or a single method (computercraft:inventory#pushItems). """) .worldRestart() - .defineList("disabled_generic_methods", List.of(), x -> x instanceof String); + .defineList("disabled_generic_methods", List.of(), () -> "", x -> x instanceof String); } { @@ -214,7 +214,7 @@ public final class ConfigSpec { - "max_websocket_message" (optional): The maximum size (in bytes) that a computer can send or receive in one websocket packet. - "use_proxy" (optional): Enable use of the HTTP/SOCKS proxy if it is configured.""") - .defineList("rules", AddressRuleConfig.defaultRules(), x -> x instanceof UnmodifiableConfig); + .defineList("rules", AddressRuleConfig.defaultRules(), AddressRuleConfig::newRule, x -> x instanceof UnmodifiableConfig); httpMaxRequests = builder .comment(""" diff --git a/projects/common/src/main/java/dan200/computercraft/shared/recipe/CustomShapedRecipe.java b/projects/common/src/main/java/dan200/computercraft/shared/recipe/CustomShapedRecipe.java index fb8d54316..68854ce42 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/recipe/CustomShapedRecipe.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/recipe/CustomShapedRecipe.java @@ -15,17 +15,17 @@ import java.util.function.Function; * A custom version of {@link ShapedRecipe}, which can be converted to and from a {@link ShapedRecipeSpec}. */ public abstract class CustomShapedRecipe extends ShapedRecipe { - private final ShapedRecipePattern pattern; + private final ShapedRecipePattern shapedPattern; private final ItemStack result; public CustomShapedRecipe(ShapedRecipeSpec recipe) { super(recipe.properties().group(), recipe.properties().category(), recipe.pattern(), recipe.result(), recipe.properties().showNotification()); - this.pattern = recipe.pattern(); + this.shapedPattern = recipe.pattern(); this.result = recipe.result(); } public final ShapedRecipeSpec toSpec() { - return new ShapedRecipeSpec(RecipeProperties.of(this), pattern, result); + return new ShapedRecipeSpec(RecipeProperties.of(this), shapedPattern, result); } @Override diff --git a/projects/fabric/src/generated/resources/data/computercraft/recipe/wireless_modem_normal.json b/projects/fabric/src/generated/resources/data/computercraft/recipe/wireless_modem_normal.json deleted file mode 100644 index f22a0d925..000000000 --- a/projects/fabric/src/generated/resources/data/computercraft/recipe/wireless_modem_normal.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "minecraft:crafting_shaped", - "category": "redstone", - "key": {"#": {"item": "minecraft:stone"}, "E": {"item": "minecraft:ender_pearl"}}, - "pattern": ["###", "#E#", "###"], - "result": {"count": 1, "id": "computercraft:wireless_modem_normal"} -} diff --git a/projects/fabric/src/main/java/dan200/computercraft/shared/ComputerCraft.java b/projects/fabric/src/main/java/dan200/computercraft/shared/ComputerCraft.java index 0a4a08331..dc10ecff0 100644 --- a/projects/fabric/src/main/java/dan200/computercraft/shared/ComputerCraft.java +++ b/projects/fabric/src/main/java/dan200/computercraft/shared/ComputerCraft.java @@ -36,7 +36,7 @@ import net.fabricmc.fabric.api.event.registry.DynamicRegistries; import net.fabricmc.fabric.api.event.registry.FabricRegistryBuilder; import net.fabricmc.fabric.api.event.registry.RegistryAttribute; import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents; -import net.fabricmc.fabric.api.loot.v2.LootTableEvents; +import net.fabricmc.fabric.api.loot.v3.LootTableEvents; import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener; @@ -122,7 +122,7 @@ public class ComputerCraft { PlayerBlockBreakEvents.BEFORE.register(FabricCommonHooks::onBlockDestroy); UseBlockCallback.EVENT.register(FabricCommonHooks::useOnBlock); - LootTableEvents.MODIFY.register((id, tableBuilder, source) -> { + LootTableEvents.MODIFY.register((id, tableBuilder, source, registries) -> { var pool = CommonHooks.getExtraLootPool(id); if (pool != null) tableBuilder.withPool(pool); }); diff --git a/projects/fabric/src/main/java/dan200/computercraft/shared/platform/FabricConfigFile.java b/projects/fabric/src/main/java/dan200/computercraft/shared/platform/FabricConfigFile.java index 3158bc81a..5dc569fa4 100644 --- a/projects/fabric/src/main/java/dan200/computercraft/shared/platform/FabricConfigFile.java +++ b/projects/fabric/src/main/java/dan200/computercraft/shared/platform/FabricConfigFile.java @@ -23,6 +23,7 @@ import java.nio.file.Path; import java.util.Arrays; import java.util.List; import java.util.function.Predicate; +import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -203,7 +204,7 @@ public class FabricConfigFile implements ConfigFile { } @Override - public Value> defineList(String path, List defaultValue, Predicate elementValidator) { + public Value> defineList(String path, List defaultValue, Supplier newValue, Predicate elementValidator) { var fullPath = getFullPath(path); spec.defineList(fullPath, defaultValue, elementValidator); return defineValue(fullPath, takeComment(), defaultValue, Config::getOrElse); diff --git a/projects/fabric/src/main/java/dan200/computercraft/shared/platform/PlatformHelperImpl.java b/projects/fabric/src/main/java/dan200/computercraft/shared/platform/PlatformHelperImpl.java index 1136a29cc..a1ab7b742 100644 --- a/projects/fabric/src/main/java/dan200/computercraft/shared/platform/PlatformHelperImpl.java +++ b/projects/fabric/src/main/java/dan200/computercraft/shared/platform/PlatformHelperImpl.java @@ -148,7 +148,7 @@ public class PlatformHelperImpl implements PlatformHelper { Ingredient.of(ConventionalItemTags.STORAGE_BLOCKS_GOLD), Ingredient.of(ConventionalItemTags.IRON_INGOTS), Ingredient.of(ConventionalItemTags.DYES), - Ingredient.of(Items.ENDER_PEARL), + Ingredient.of(ConventionalItemTags.ENDER_PEARLS), Ingredient.of(ConventionalItemTags.WOODEN_CHESTS) ); } diff --git a/projects/fabric/src/main/resources/fabric.mod.json b/projects/fabric/src/main/resources/fabric.mod.json index b76fe9dbf..5399348e1 100644 --- a/projects/fabric/src/main/resources/fabric.mod.json +++ b/projects/fabric/src/main/resources/fabric.mod.json @@ -46,7 +46,7 @@ ], "depends": { "fabricloader": ">=0.15.10", - "fabric-api": ">=0.100.3", + "fabric-api": ">=0.100.5", "minecraft": "=1.21" }, "accessWidener": "computercraft.accesswidener" diff --git a/projects/forge/src/main/java/dan200/computercraft/ComputerCraft.java b/projects/forge/src/main/java/dan200/computercraft/ComputerCraft.java index bf3887d4f..ffdedb8ac 100644 --- a/projects/forge/src/main/java/dan200/computercraft/ComputerCraft.java +++ b/projects/forge/src/main/java/dan200/computercraft/ComputerCraft.java @@ -4,7 +4,6 @@ package dan200.computercraft; -import com.electronwill.nightconfig.core.file.FileConfig; import dan200.computercraft.api.ComputerCraftAPI; import dan200.computercraft.api.ForgeComputerCraftAPI; import dan200.computercraft.api.detail.ForgeDetailRegistries; @@ -171,8 +170,7 @@ public final class ComputerCraft { private static void syncConfig(ModConfig config) { if (!config.getModId().equals(ComputerCraftAPI.MOD_ID)) return; - var path = config.getConfigData() instanceof FileConfig fileConfig ? fileConfig.getNioPath() : null; - + var path = config.getFullPath(); if (config.getType() == ModConfig.Type.SERVER && ((ForgeConfigFile) ConfigSpec.serverSpec).spec().isLoaded()) { ConfigSpec.syncServer(path); } else if (config.getType() == ModConfig.Type.CLIENT) { diff --git a/projects/forge/src/main/java/dan200/computercraft/shared/platform/ForgeConfigFile.java b/projects/forge/src/main/java/dan200/computercraft/shared/platform/ForgeConfigFile.java index 17b3b4ffe..05788eb61 100644 --- a/projects/forge/src/main/java/dan200/computercraft/shared/platform/ForgeConfigFile.java +++ b/projects/forge/src/main/java/dan200/computercraft/shared/platform/ForgeConfigFile.java @@ -11,7 +11,9 @@ import net.neoforged.neoforge.common.ModConfigSpec; import javax.annotation.Nullable; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.function.Predicate; +import java.util.function.Supplier; import java.util.stream.Stream; /** @@ -105,9 +107,9 @@ public final class ForgeConfigFile implements ConfigFile { } @Override - public ConfigFile.Value> defineList(String path, List defaultValue, Predicate elementValidator) { + public ConfigFile.Value> defineList(String path, List defaultValue, Supplier newValue, Predicate elementValidator) { translation(path); - return defineValue(builder.defineList(path, defaultValue, elementValidator)); + return defineValue(builder.defineList(path, defaultValue, newValue, elementValidator)); } @Override @@ -168,12 +170,12 @@ public final class ForgeConfigFile implements ConfigFile { @Override public String translationKey() { - return spec().getTranslationKey(); + return Objects.requireNonNull(spec().getTranslationKey(), "No comment for value"); } @Override public String comment() { - return spec().getComment(); + return Objects.requireNonNull(spec().getComment(), "No comment for value"); } } }