diff --git a/.reuse/dep5 b/.reuse/dep5 index 076b49c8c..46aff91f9 100644 --- a/.reuse/dep5 +++ b/.reuse/dep5 @@ -37,6 +37,7 @@ Files: projects/fabric/src/testMod/resources/computercraft-gametest.fabric.mixins.json projects/fabric/src/testMod/resources/fabric.mod.json projects/forge/src/client/resources/computercraft-client.forge.mixins.json + projects/forge/src/main/resources/computercraft.forge.mixins.json projects/web/src/frontend/mount/.settings projects/web/src/frontend/mount/example.nfp projects/web/src/frontend/mount/example.nft diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 16a88ad5b..841cbe91d 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -6,7 +6,7 @@ # Minecraft # MC version is specified in gradle.properties, as we need that in settings.gradle. -# Remember to update corresponding versions in fabric.mod.json/mods.toml +# Remember to update corresponding versions in fabric.mod.json/neoforge.mods.toml fabric-api = "0.97.6+1.20.5" fabric-loader = "0.15.10" neoForge = "20.5.0-beta" diff --git a/projects/common/src/main/java/dan200/computercraft/mixin/V3818_3Mixin.java b/projects/common/src/main/java/dan200/computercraft/mixin/V3818_3Mixin.java deleted file mode 100644 index 8156a3b6f..000000000 --- a/projects/common/src/main/java/dan200/computercraft/mixin/V3818_3Mixin.java +++ /dev/null @@ -1,57 +0,0 @@ -// SPDX-FileCopyrightText: 2024 The CC: Tweaked Developers -// -// SPDX-License-Identifier: MPL-2.0 - -package dan200.computercraft.mixin; - -import com.llamalad7.mixinextras.injector.ModifyReturnValue; -import com.mojang.datafixers.DSL; -import com.mojang.datafixers.schemas.Schema; -import com.mojang.datafixers.types.templates.TypeTemplate; -import com.mojang.datafixers.util.Pair; -import dan200.computercraft.impl.UpgradeManager; -import dan200.computercraft.shared.ModRegistry.DataComponents; -import net.minecraft.util.datafix.fixes.References; -import net.minecraft.util.datafix.schemas.V3818_3; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; - -import java.util.Arrays; -import java.util.stream.Stream; - -/** - * Add our custom data components to the datafixer system. - * - * @see UpgradeManager#codec() - * @see DataComponents#POCKET_UPGRADE - * @see DataComponents#LEFT_TURTLE_UPGRADE - * @see DataComponents#RIGHT_TURTLE_UPGRADE - * @see ItemStackComponentizationFixMixin - */ -@Mixin(V3818_3.class) -class V3818_3Mixin { - @ModifyReturnValue( - method = "method_57277", - at = @At("TAIL") - ) - @SuppressWarnings("UnusedMethod") - private static TypeTemplate addExtraTypes(TypeTemplate type, Schema schema) { - // Create a codec for UpgradeData - var upgradeData = DSL.optionalFields("components", References.DATA_COMPONENTS.in(schema)); - - return extraOptionalFields(type, - Pair.of("computercraft:pocket_upgrade", upgradeData), - Pair.of("computercraft:left_turtle_upgrade", upgradeData), - Pair.of("computercraft:right_turtle_upgrade", upgradeData) - ); - } - - @SafeVarargs - @SuppressWarnings("varargs") - private static TypeTemplate extraOptionalFields(TypeTemplate base, Pair... fields) { - return DSL.and(Stream.concat( - Arrays.stream(fields).map(entry -> DSL.optional(DSL.field(entry.getFirst(), entry.getSecond()))), - Stream.of(base) - ).toList()); - } -} diff --git a/projects/common/src/main/java/dan200/computercraft/shared/util/ComponentizationFixers.java b/projects/common/src/main/java/dan200/computercraft/shared/util/ComponentizationFixers.java index e1ed34cf2..3f673c041 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/util/ComponentizationFixers.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/util/ComponentizationFixers.java @@ -7,14 +7,19 @@ package dan200.computercraft.shared.util; import com.mojang.datafixers.DSL; import com.mojang.datafixers.Typed; import com.mojang.datafixers.schemas.Schema; +import com.mojang.datafixers.types.templates.TypeTemplate; +import com.mojang.datafixers.util.Pair; import com.mojang.serialization.Dynamic; import com.mojang.serialization.OptionalDynamic; import dan200.computercraft.api.upgrades.UpgradeData; +import dan200.computercraft.impl.UpgradeManager; +import dan200.computercraft.shared.ModRegistry; import dan200.computercraft.shared.media.items.PrintoutData; import net.minecraft.util.datafix.fixes.ItemStackComponentizationFix; import net.minecraft.util.datafix.fixes.References; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Set; import java.util.function.Function; @@ -178,4 +183,35 @@ public class ComponentizationFixers { return newUpgrade; } + + /** + * Add our custom data components to the datafixer system. + * + * @param type The existing component type definition. + * @param schema The current schema. + * @return The new component type definition. + * @see UpgradeManager#codec() + * @see ModRegistry.DataComponents#POCKET_UPGRADE + * @see ModRegistry.DataComponents#LEFT_TURTLE_UPGRADE + * @see ModRegistry.DataComponents#RIGHT_TURTLE_UPGRADE + */ + public static TypeTemplate addExtraTypes(TypeTemplate type, Schema schema) { + // Create a codec for UpgradeData + var upgradeData = DSL.optionalFields("components", References.DATA_COMPONENTS.in(schema)); + + return extraOptionalFields(type, + Pair.of("computercraft:pocket_upgrade", upgradeData), + Pair.of("computercraft:left_turtle_upgrade", upgradeData), + Pair.of("computercraft:right_turtle_upgrade", upgradeData) + ); + } + + @SafeVarargs + @SuppressWarnings("varargs") + private static TypeTemplate extraOptionalFields(TypeTemplate base, Pair... fields) { + return DSL.and(Stream.concat( + Arrays.stream(fields).map(entry -> DSL.optional(DSL.field(entry.getFirst(), entry.getSecond()))), + Stream.of(base) + ).toList()); + } } diff --git a/projects/common/src/main/resources/computercraft.mixins.json b/projects/common/src/main/resources/computercraft.mixins.json index 941fe0857..84cd67612 100644 --- a/projects/common/src/main/resources/computercraft.mixins.json +++ b/projects/common/src/main/resources/computercraft.mixins.json @@ -2,14 +2,12 @@ "required": true, "package": "dan200.computercraft.mixin", "minVersion": "0.8", - "compatibilityLevel": "JAVA_17", + "compatibilityLevel": "JAVA_21", "injectors": { "defaultRequire": 1 }, "mixins": [ - "V1460Mixin", - "V3818_3Mixin", - "ItemStackComponentizationFixMixin" - ], - "refmap": "computercraft.refmap.json" + "ItemStackComponentizationFixMixin", + "V1460Mixin" + ] } diff --git a/projects/common/src/testMod/resources/computercraft-gametest.mixins.json b/projects/common/src/testMod/resources/computercraft-gametest.mixins.json index a4c662e82..803991da5 100644 --- a/projects/common/src/testMod/resources/computercraft-gametest.mixins.json +++ b/projects/common/src/testMod/resources/computercraft-gametest.mixins.json @@ -2,7 +2,7 @@ "required": true, "package": "dan200.computercraft.mixin.gametest", "minVersion": "0.8", - "compatibilityLevel": "JAVA_17", + "compatibilityLevel": "JAVA_21", "injectors": { "defaultRequire": 1 }, diff --git a/projects/fabric/src/client/resources/computercraft-client.fabric.mixins.json b/projects/fabric/src/client/resources/computercraft-client.fabric.mixins.json index f5e51cbe2..a39cbc195 100644 --- a/projects/fabric/src/client/resources/computercraft-client.fabric.mixins.json +++ b/projects/fabric/src/client/resources/computercraft-client.fabric.mixins.json @@ -2,7 +2,7 @@ "required": true, "package": "dan200.computercraft.mixin.client", "minVersion": "0.8", - "compatibilityLevel": "JAVA_17", + "compatibilityLevel": "JAVA_21", "injectors": { "defaultRequire": 1 }, diff --git a/projects/fabric/src/main/java/dan200/computercraft/mixin/V3818_3Mixin.java b/projects/fabric/src/main/java/dan200/computercraft/mixin/V3818_3Mixin.java new file mode 100644 index 000000000..26b7806db --- /dev/null +++ b/projects/fabric/src/main/java/dan200/computercraft/mixin/V3818_3Mixin.java @@ -0,0 +1,27 @@ +// SPDX-FileCopyrightText: 2024 The CC: Tweaked Developers +// +// SPDX-License-Identifier: MPL-2.0 + +package dan200.computercraft.mixin; + +import com.llamalad7.mixinextras.injector.ModifyReturnValue; +import com.mojang.datafixers.schemas.Schema; +import com.mojang.datafixers.types.templates.TypeTemplate; +import dan200.computercraft.shared.util.ComponentizationFixers; +import net.minecraft.util.datafix.schemas.V3818_3; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +/** + * Add our custom data components to the datafixer system. + *

+ * This mixin is identical between Fabric and NeoForge aside from using a different method name. + */ +@Mixin(V3818_3.class) +class V3818_3Mixin { + @ModifyReturnValue(method = "method_57277", at = @At("TAIL")) + @SuppressWarnings("UnusedMethod") + private static TypeTemplate addExtraTypes(TypeTemplate type, Schema schema) { + return ComponentizationFixers.addExtraTypes(type, schema); + } +} 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 c2d358ccc..3dee3c96f 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 @@ -169,12 +169,12 @@ public class PlatformHelperImpl implements PlatformHelper { public RecipeIngredients getRecipeIngredients() { return new RecipeIngredients( Ingredient.of(ConventionalItemTags.REDSTONE_DUSTS), - Ingredient.of(Items.STRING), + Ingredient.of(ConventionalItemTags.STRINGS), Ingredient.of(Items.LEATHER), - Ingredient.of(Items.STONE), + Ingredient.of(ConventionalItemTags.STONES), Ingredient.of(ConventionalItemTags.GLASS_PANES), Ingredient.of(ConventionalItemTags.GOLD_INGOTS), - Ingredient.of(Items.GOLD_BLOCK), + Ingredient.of(ConventionalItemTags.STORAGE_BLOCKS_GOLD), Ingredient.of(ConventionalItemTags.IRON_INGOTS), Ingredient.of(ConventionalItemTags.DYES), Ingredient.of(Items.ENDER_PEARL), diff --git a/projects/fabric/src/main/resources/computercraft.fabric.mixins.json b/projects/fabric/src/main/resources/computercraft.fabric.mixins.json index b572263d1..91dc2e26b 100644 --- a/projects/fabric/src/main/resources/computercraft.fabric.mixins.json +++ b/projects/fabric/src/main/resources/computercraft.fabric.mixins.json @@ -2,7 +2,7 @@ "required": true, "package": "dan200.computercraft.mixin", "minVersion": "0.8", - "compatibilityLevel": "JAVA_17", + "compatibilityLevel": "JAVA_21", "injectors": { "defaultRequire": 1 }, @@ -15,6 +15,7 @@ "PlayerChunkSenderMixin", "ServerLevelMixin", "TagEntryAccessor", - "TagsProviderMixin" + "TagsProviderMixin", + "V3818_3Mixin" ] } diff --git a/projects/forge/build.gradle.kts b/projects/forge/build.gradle.kts index 7eafe4a32..35888337d 100644 --- a/projects/forge/build.gradle.kts +++ b/projects/forge/build.gradle.kts @@ -155,7 +155,7 @@ tasks.processResources { inputs.property("modVersion", modVersion) inputs.property("neoVersion", libs.versions.neoForge.get()) - filesMatching("META-INF/mods.toml") { + filesMatching("META-INF/neoforge.mods.toml") { expand(mapOf("neoVersion" to libs.versions.neoForge.get(), "file" to mapOf("jarVersion" to modVersion))) } } diff --git a/projects/forge/src/client/resources/computercraft-client.forge.mixins.json b/projects/forge/src/client/resources/computercraft-client.forge.mixins.json index b80be74ac..b1976873d 100644 --- a/projects/forge/src/client/resources/computercraft-client.forge.mixins.json +++ b/projects/forge/src/client/resources/computercraft-client.forge.mixins.json @@ -2,13 +2,12 @@ "required": true, "package": "dan200.computercraft.mixin.client", "minVersion": "0.8", - "compatibilityLevel": "JAVA_17", + "compatibilityLevel": "JAVA_21", "injectors": { "defaultRequire": 1 }, "client": [ "BlockRenderDispatcherMixin", "ClientPacketListenerMixin" - ], - "refmap": "client-computercraft.refmap.json" + ] } diff --git a/projects/forge/src/main/java/dan200/computercraft/data/Generators.java b/projects/forge/src/main/java/dan200/computercraft/data/Generators.java index e52c9de35..5cbfac1d6 100644 --- a/projects/forge/src/main/java/dan200/computercraft/data/Generators.java +++ b/projects/forge/src/main/java/dan200/computercraft/data/Generators.java @@ -55,7 +55,7 @@ public class Generators { @Override public T add(BiFunction, T> factory) { - return generator.addProvider(p -> factory.apply(p, registries)); + return generator.addProvider(p -> new PrettyDataProvider<>(factory.apply(p, registries))).provider(); } @Override diff --git a/projects/forge/src/main/java/dan200/computercraft/mixin/V3818_3Mixin.java b/projects/forge/src/main/java/dan200/computercraft/mixin/V3818_3Mixin.java new file mode 100644 index 000000000..710f5c056 --- /dev/null +++ b/projects/forge/src/main/java/dan200/computercraft/mixin/V3818_3Mixin.java @@ -0,0 +1,27 @@ +// SPDX-FileCopyrightText: 2024 The CC: Tweaked Developers +// +// SPDX-License-Identifier: MPL-2.0 + +package dan200.computercraft.mixin; + +import com.llamalad7.mixinextras.injector.ModifyReturnValue; +import com.mojang.datafixers.schemas.Schema; +import com.mojang.datafixers.types.templates.TypeTemplate; +import dan200.computercraft.shared.util.ComponentizationFixers; +import net.minecraft.util.datafix.schemas.V3818_3; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +/** + * Add our custom data components to the datafixer system. + *

+ * This mixin is identical between Fabric and NeoForge aside from using a different method name. + */ +@Mixin(V3818_3.class) +class V3818_3Mixin { + @ModifyReturnValue(method = "lambda$registerTypes$0", at = @At("TAIL")) + @SuppressWarnings("UnusedMethod") + private static TypeTemplate addExtraTypes(TypeTemplate type, Schema schema) { + return ComponentizationFixers.addExtraTypes(type, schema); + } +} diff --git a/projects/forge/src/main/resources/META-INF/mods.toml b/projects/forge/src/main/resources/META-INF/neoforge.mods.toml similarity index 94% rename from projects/forge/src/main/resources/META-INF/mods.toml rename to projects/forge/src/main/resources/META-INF/neoforge.mods.toml index 511f14437..f4712babe 100644 --- a/projects/forge/src/main/resources/META-INF/mods.toml +++ b/projects/forge/src/main/resources/META-INF/neoforge.mods.toml @@ -33,5 +33,8 @@ CC: Tweaked is a fork of ComputerCraft, adding programmable computers, turtles a [[mixins]] config = "computercraft.mixins.json" +[[mixins]] +config = "computercraft.forge.mixins.json" + [[mixins]] config = "computercraft-client.forge.mixins.json" diff --git a/projects/forge/src/main/resources/computercraft.forge.mixins.json b/projects/forge/src/main/resources/computercraft.forge.mixins.json new file mode 100644 index 000000000..d6200c770 --- /dev/null +++ b/projects/forge/src/main/resources/computercraft.forge.mixins.json @@ -0,0 +1,12 @@ +{ + "required": true, + "package": "dan200.computercraft.mixin", + "minVersion": "0.8", + "compatibilityLevel": "JAVA_21", + "injectors": { + "defaultRequire": 1 + }, + "mixins": [ + "V3818_3Mixin" + ] +} diff --git a/projects/forge/src/testMod/resources/META-INF/mods.toml b/projects/forge/src/testMod/resources/META-INF/neoforge.mods.toml similarity index 100% rename from projects/forge/src/testMod/resources/META-INF/mods.toml rename to projects/forge/src/testMod/resources/META-INF/neoforge.mods.toml