From da129a8edc65f654554ab61dbf37fc3754144cda Mon Sep 17 00:00:00 2001 From: Luke Bemish Date: Sat, 6 Jan 2024 16:30:03 -0600 Subject: [PATCH] Update to 1.20.4; use new networking API on neoforge and switch around system on fabric --- build.gradle | 58 +++++++++- common/build.gradle | 2 + .../impl/ModifiedOreBlock.java | 8 +- .../impl/network/AckOresPayload.java | 19 ++++ .../SyncOresPayload.java} | 32 ++---- common/src/main/resources/mods.groovy | 16 +++ fabriquilt/build.gradle | 5 - .../ExcavatedVariantsClientFabriQuilt.java | 20 ++-- .../ExcavatedVariantsFabriQuilt.java | 36 ++++--- gradle.properties | 2 + gradle/libs.versions.toml | 42 ++++---- .../neoforge/ExcavatedVariantsNeoForge.java | 100 +++++++++++++++--- .../neoforge/mixin/ModifiedOreBlockMixin.java | 7 +- settings.gradle | 43 +++++++- version.properties | 2 +- 15 files changed, 293 insertions(+), 99 deletions(-) create mode 100644 common/src/main/java/dev/lukebemish/excavatedvariants/impl/network/AckOresPayload.java rename common/src/main/java/dev/lukebemish/excavatedvariants/impl/{S2CConfigAgreementPacket.java => network/SyncOresPayload.java} (60%) diff --git a/build.gradle b/build.gradle index 1b30ac04..7810e2bf 100644 --- a/build.gradle +++ b/build.gradle @@ -8,10 +8,60 @@ plugins { managedVersioning { versionFile.set rootProject.file('version.properties') metadataVersion.set libs.versions.minecraft - if (System.getenv('PR_NUMBER')) { - suffix.set("pr${System.getenv('PR_NUMBER')}") - } else if (System.getenv('SNAPSHOT_MAVEN_URL')) { - suffix.set('SNAPSHOT') + versionPRs() + versionSnapshots() + + gitHubActions { + snapshot { + prettyName.set 'Snapshot' + workflowDispatch.set(true) + onBranches.add '1.*' + gradleJob { + buildCache() + name.set 'build' + gradlew 'Build', 'checkLicenses', 'build' + gradlew 'Publish', 'publish' + mavenSnapshot('github') + } + } + release { + prettyName.set 'Release' + workflowDispatch.set(true) + gradleJob { + buildCache() + name.set 'build' + step { + setupGitUser() + } + readOnly.set false + gradlew 'Tag Release', 'tagRelease' + gradlew 'Build', 'checkLicenses', 'build' + step { + run.set 'git push && git push --tags' + } + gradlew 'Publish', 'publish', 'modrinth', 'curseforge' + mavenRelease('github') + modPublishing() + } + } + build_pr { + prettyName.set 'Build PR' + pullRequest.set(true) + gradleJob { + name.set 'build' + gradlew 'Build', 'checkLicenses', 'build' + gradlew 'Publish', 'publish' + pullRequestArtifact() + } + } + publish_pr { + prettyName.set 'Publish PR' + publishPullRequestAction( + 'github', + 'dev/lukebemish/dynamicassetgenerator/dynamicassetgenerator-*', + 'Build PR' + ) + } } } diff --git a/common/build.gradle b/common/build.gradle index 6d93747f..afe2e041 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -35,6 +35,8 @@ dependencies { compileOnly libs.dynassetgen.common compileOnly libs.defaultresources.common + + compileOnly libs.mixinextras.common } artifacts { diff --git a/common/src/main/java/dev/lukebemish/excavatedvariants/impl/ModifiedOreBlock.java b/common/src/main/java/dev/lukebemish/excavatedvariants/impl/ModifiedOreBlock.java index 38a7109a..14c4db46 100644 --- a/common/src/main/java/dev/lukebemish/excavatedvariants/impl/ModifiedOreBlock.java +++ b/common/src/main/java/dev/lukebemish/excavatedvariants/impl/ModifiedOreBlock.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Luke Bemish and contributors + * Copyright (C) 2023-2024 Luke Bemish and contributors * SPDX-License-Identifier: LGPL-3.0-or-later */ @@ -68,7 +68,7 @@ public class ModifiedOreBlock extends DropExperienceBlock { private Property[] props; public ModifiedOreBlock(ExcavatedVariants.VariantFuture future) { - super(copyProperties(future), getXpProvider(future)); + super(getXpProvider(future), copyProperties(future)); this.ore = future.ore; this.stone = future.stone; this.flags = Set.copyOf(future.flags); @@ -119,8 +119,8 @@ private static Properties copyProperties(ExcavatedVariants.VariantFuture future) Block stoneTarget = future.foundStone; BlockBehaviour.Properties outProperties; if (target != null && stoneTarget != null) { - Properties properties = Properties.copy(stoneTarget); - Properties oreProperties = Properties.copy(target); + Properties properties = Properties.ofFullCopy(stoneTarget); + Properties oreProperties = Properties.ofFullCopy(target); properties.requiresCorrectToolForDrops(); BlockPropertiesMixin newProperties = (BlockPropertiesMixin) properties; BlockPropertiesMixin oreProps = (BlockPropertiesMixin) oreProperties; diff --git a/common/src/main/java/dev/lukebemish/excavatedvariants/impl/network/AckOresPayload.java b/common/src/main/java/dev/lukebemish/excavatedvariants/impl/network/AckOresPayload.java new file mode 100644 index 00000000..25e472e5 --- /dev/null +++ b/common/src/main/java/dev/lukebemish/excavatedvariants/impl/network/AckOresPayload.java @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2024 Luke Bemish and contributors + * SPDX-License-Identifier: LGPL-3.0-or-later + */ + +package dev.lukebemish.excavatedvariants.impl.network; + +import dev.lukebemish.excavatedvariants.impl.ExcavatedVariants; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.resources.ResourceLocation; + +public record AckOresPayload() { + public static final ResourceLocation ID = ExcavatedVariants.id("ack_ores"); + public static AckOresPayload decode(FriendlyByteBuf buffer) { + return new AckOresPayload(); + } + + public void encode(FriendlyByteBuf buffer) {} +} diff --git a/common/src/main/java/dev/lukebemish/excavatedvariants/impl/S2CConfigAgreementPacket.java b/common/src/main/java/dev/lukebemish/excavatedvariants/impl/network/SyncOresPayload.java similarity index 60% rename from common/src/main/java/dev/lukebemish/excavatedvariants/impl/S2CConfigAgreementPacket.java rename to common/src/main/java/dev/lukebemish/excavatedvariants/impl/network/SyncOresPayload.java index bca55a76..64735458 100644 --- a/common/src/main/java/dev/lukebemish/excavatedvariants/impl/S2CConfigAgreementPacket.java +++ b/common/src/main/java/dev/lukebemish/excavatedvariants/impl/network/SyncOresPayload.java @@ -1,13 +1,13 @@ /* - * Copyright (C) 2023 Luke Bemish and contributors + * Copyright (C) 2023-2024 Luke Bemish and contributors * SPDX-License-Identifier: LGPL-3.0-or-later */ -package dev.lukebemish.excavatedvariants.impl; +package dev.lukebemish.excavatedvariants.impl.network; +import dev.lukebemish.excavatedvariants.impl.ExcavatedVariants; import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.network.chat.Component; -import net.minecraft.network.protocol.login.ClientboundLoginDisconnectPacket; +import net.minecraft.resources.ResourceLocation; import java.util.ArrayList; import java.util.HashSet; @@ -15,21 +15,17 @@ import java.util.function.Consumer; import java.util.stream.Collectors; -public record S2CConfigAgreementPacket(Set blocks) { +public record SyncOresPayload(Set blocks) { + public static final ResourceLocation ID = ExcavatedVariants.id("sync_ores"); - public static S2CConfigAgreementPacket decoder(FriendlyByteBuf buffer) { + public static SyncOresPayload decode(FriendlyByteBuf buffer) { ArrayList blocks = new ArrayList<>(); int i = buffer.readInt(); for (int j = 0; j < i; j++) blocks.add(buffer.readUtf()); - return new S2CConfigAgreementPacket(new HashSet<>(blocks)); + return new SyncOresPayload(new HashSet<>(blocks)); } - private static String ellipsis(String str, @SuppressWarnings("SameParameterValue") int length) { - if (str.length() <= length) return str; - else return str.substring(0, length - 3) + "..."; - } - - public void encoder(FriendlyByteBuf buffer) { + public void encode(FriendlyByteBuf buffer) { buffer.writeInt(blocks.size()); blocks.forEach(buffer::writeUtf); } @@ -47,19 +43,13 @@ public void consumeMessage(Consumer disconnecter) { if (!clientOnly.isEmpty()) { String clientOnlyStr = String.join("\n ", clientOnly.stream().toList()); ExcavatedVariants.LOGGER.error("Client contains ore variants not present on server:\n {}", clientOnlyStr); - disconnect += "\nMissing on server: " + ellipsis(clientOnly.toString(), 50); + disconnect += "\nSee log for details"; } if (!serverOnly.isEmpty()) { String serverOnlyStr = String.join("\n ", serverOnly.stream().toList()); ExcavatedVariants.LOGGER.error("Server contains ore variants not present on client:\n {}", serverOnlyStr); - disconnect += "\nMissing on client: " + ellipsis(serverOnly.toString(), 50); + disconnect += "\nSee log for details"; } disconnecter.accept(disconnect); } - - public static final class ExcavatedVariantsDisconnectPacket extends ClientboundLoginDisconnectPacket { - public ExcavatedVariantsDisconnectPacket(String reason) { - super(Component.literal(reason)); - } - } } diff --git a/common/src/main/resources/mods.groovy b/common/src/main/resources/mods.groovy index faa6a69e..dcebdc98 100644 --- a/common/src/main/resources/mods.groovy +++ b/common/src/main/resources/mods.groovy @@ -1,3 +1,5 @@ +import modsdotgroovy.Dependency + /* * Copyright (C) 2023 Luke Bemish and contributors * SPDX-License-Identifier: LGPL-3.0-or-later @@ -54,6 +56,20 @@ ModsDotGroovy.make { } } + onForge { + dependencies = dependencies.collect { dep -> + new Dependency() { + @Override + Map asForgeMap() { + def map = dep.asForgeMap() + map.remove('mandatory') + map.put('type', this.mandatory ? 'required' : 'optional') + return map + } + } + } + } + entrypoints { entrypoint 'main', [ 'dev.lukebemish.excavatedvariants.impl.fabriquilt.fabric.ExcavatedVariantsFabric', diff --git a/fabriquilt/build.gradle b/fabriquilt/build.gradle index b4d27828..e803a347 100644 --- a/fabriquilt/build.gradle +++ b/fabriquilt/build.gradle @@ -26,15 +26,10 @@ dependencies { include libs.defaultresources.fabriquilt compileOnly libs.quilt.loader - - modImplementation libs.mixinextras.fabric - include libs.mixinextras.fabric - annotationProcessor libs.mixinextras.fabric } loom { mixin { - useLegacyMixinAp = true defaultRefmapName.set("${mod_id}.refmap.json") } runs { diff --git a/fabriquilt/src/main/java/dev/lukebemish/excavatedvariants/impl/fabriquilt/ExcavatedVariantsClientFabriQuilt.java b/fabriquilt/src/main/java/dev/lukebemish/excavatedvariants/impl/fabriquilt/ExcavatedVariantsClientFabriQuilt.java index af210dfd..93b2ec3d 100644 --- a/fabriquilt/src/main/java/dev/lukebemish/excavatedvariants/impl/fabriquilt/ExcavatedVariantsClientFabriQuilt.java +++ b/fabriquilt/src/main/java/dev/lukebemish/excavatedvariants/impl/fabriquilt/ExcavatedVariantsClientFabriQuilt.java @@ -1,26 +1,22 @@ /* - * Copyright (C) 2023 Luke Bemish and contributors + * Copyright (C) 2023-2024 Luke Bemish and contributors * SPDX-License-Identifier: LGPL-3.0-or-later */ package dev.lukebemish.excavatedvariants.impl.fabriquilt; -import dev.lukebemish.excavatedvariants.impl.S2CConfigAgreementPacket; +import dev.lukebemish.excavatedvariants.impl.network.SyncOresPayload; import net.fabricmc.api.ClientModInitializer; -import net.fabricmc.fabric.api.client.networking.v1.ClientLoginNetworking; -import net.minecraft.network.FriendlyByteBuf; - -import java.util.concurrent.CompletableFuture; +import net.fabricmc.fabric.api.client.networking.v1.ClientConfigurationNetworking; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.common.ClientboundDisconnectPacket; public class ExcavatedVariantsClientFabriQuilt implements ClientModInitializer { @Override public void onInitializeClient() { - ClientLoginNetworking.registerGlobalReceiver(ExcavatedVariantsFabriQuilt.S2C_CONFIG_AGREEMENT_PACKET, ((client, handler, buf, listenerAdder) -> { - S2CConfigAgreementPacket msg = S2CConfigAgreementPacket.decoder(buf); - msg.consumeMessage(string -> handler.handleDisconnect(new S2CConfigAgreementPacket.ExcavatedVariantsDisconnectPacket(string))); - CompletableFuture future = new CompletableFuture<>(); - future.complete(null); - return future; + ClientConfigurationNetworking.registerGlobalReceiver(SyncOresPayload.ID, ((client, handler, buf, listenerAdder) -> { + SyncOresPayload msg = SyncOresPayload.decode(buf); + msg.consumeMessage(string -> handler.handleDisconnect(new ClientboundDisconnectPacket(Component.literal(string)))); })); } } diff --git a/fabriquilt/src/main/java/dev/lukebemish/excavatedvariants/impl/fabriquilt/ExcavatedVariantsFabriQuilt.java b/fabriquilt/src/main/java/dev/lukebemish/excavatedvariants/impl/fabriquilt/ExcavatedVariantsFabriQuilt.java index 3332b359..42c61bfc 100644 --- a/fabriquilt/src/main/java/dev/lukebemish/excavatedvariants/impl/fabriquilt/ExcavatedVariantsFabriQuilt.java +++ b/fabriquilt/src/main/java/dev/lukebemish/excavatedvariants/impl/fabriquilt/ExcavatedVariantsFabriQuilt.java @@ -1,24 +1,24 @@ /* - * Copyright (C) 2023 Luke Bemish and contributors + * Copyright (C) 2023-2024 Luke Bemish and contributors * SPDX-License-Identifier: LGPL-3.0-or-later */ package dev.lukebemish.excavatedvariants.impl.fabriquilt; import dev.lukebemish.excavatedvariants.impl.*; +import dev.lukebemish.excavatedvariants.impl.network.SyncOresPayload; import dev.lukebemish.excavatedvariants.impl.worldgen.OreFinderUtil; import dev.lukebemish.excavatedvariants.impl.worldgen.OreReplacer; import net.fabricmc.api.EnvType; import net.fabricmc.fabric.api.biome.v1.BiomeModifications; import net.fabricmc.fabric.api.biome.v1.ModificationPhase; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; -import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; -import net.fabricmc.fabric.api.networking.v1.ServerLoginConnectionEvents; -import net.fabricmc.fabric.api.networking.v1.ServerLoginNetworking; +import net.fabricmc.fabric.api.networking.v1.*; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.core.Registry; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.Registries; +import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.levelgen.GenerationStep; @@ -27,8 +27,6 @@ import java.util.stream.Collectors; public class ExcavatedVariantsFabriQuilt { - public static final ResourceLocation S2C_CONFIG_AGREEMENT_PACKET = new ResourceLocation(ExcavatedVariants.MOD_ID, "config_agreement"); - public static void onInitialize() { ExcavatedVariants.init(); if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) { @@ -51,17 +49,11 @@ public static void onInitialize() { HyleCompat.init(); }*/ - ServerLoginConnectionEvents.QUERY_START.register((handler, server, sender, synchronizer) -> { - var packet = new S2CConfigAgreementPacket(ExcavatedVariants.COMPLETE_VARIANTS.stream().map(v -> v.fullId).collect(Collectors.toSet())); - var buf = PacketByteBufs.create(); - packet.encoder(buf); - sender.sendPacket(sender.createPacket(S2C_CONFIG_AGREEMENT_PACKET, buf)); + ServerConfigurationConnectionEvents.CONFIGURE.register((handler, server) -> { + var packet = new SyncOresPayload(ExcavatedVariants.COMPLETE_VARIANTS.stream().map(v -> v.fullId).collect(Collectors.toSet())); + ServerConfigurationNetworking.send(handler, new SyncFabricPacket(packet)); }); - ServerLoginNetworking.registerGlobalReceiver(S2C_CONFIG_AGREEMENT_PACKET, ((server, handler, understood, buf, synchronizer, responseSender) -> { - //Do I need to do anything here? - })); - Registry.register(BuiltInRegistries.FEATURE, new ResourceLocation(ExcavatedVariants.MOD_ID, "ore_replacer"), new OreReplacer()); } @@ -70,4 +62,18 @@ public static void cleanup() { RegistriesImpl.registerRegistries(); ExcavatedVariants.initPostRegister(); } + + public record SyncFabricPacket(SyncOresPayload payload) implements FabricPacket { + public static PacketType TYPE = PacketType.create(SyncOresPayload.ID, buf -> new SyncFabricPacket(SyncOresPayload.decode(buf))); + + @Override + public void write(FriendlyByteBuf buf) { + payload.encode(buf); + } + + @Override + public PacketType getType() { + return TYPE; + } + } } diff --git a/gradle.properties b/gradle.properties index 9e1f1b48..1c52eab1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,5 +12,7 @@ artifact_id=excavatedvariants # Gradle org.gradle.jvmargs=-Xmx3G org.gradle.daemon=false +org.gradle.parallel=true +org.gradle.caching=true release_type=release diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index f0f576f3..9034eca8 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,33 +1,33 @@ [versions] -minecraft = "1.20.2" -parchment_minecraft = "1.20.1" -parchment_mappings = "2023.08.20" +minecraft = "1.20.4" +parchment_minecraft = "1.20.2" +parchment_mappings = "2023.12.10" -neoforge = "20.2.64-beta" +neoforge = "20.4.80-beta" -quilt_loader = "0.21.2" +fabric_loader = "0.15.3" +fabric_api = "0.92.1+1.20.4" -fabric_loader = "0.14.24" -fabric_api = "0.90.4+1.20.2" +quilt_loader = "0.21.2" mdg_plugin = "1.4.3" mdg_dsl = "1.5.1" autoservice = "1.1.1" -dynassetgen = "5.0.0" -defaultresources = "3.0.2" +architectury_loom = "1.4.373" +quilt_licenser = "2.0.1" -mixinextras = "0.2.1" +dynassetgen = "5.1.1" +defaultresources = "3.2.0" -architectury_loom = "1.4.367" -quilt_licenser = "2.0.1" +mixinextras = "0.3.2" -jetbrains_annotations = "24.0.1" +jetbrains_annotations = "24.1.0" jspecify = "0.3.0" minotaur = "2.8.3" -managedversioning = "1.0.0" +managedversioning = "1.2.3" [libraries] minecraft = { module = "com.mojang:minecraft", version.ref = "minecraft" } @@ -44,15 +44,15 @@ jspecify = { module = "org.jspecify:jspecify", version.ref = "jspecify" } autoservice = { module = "com.google.auto.service:auto-service", version.ref = "autoservice" } -dynassetgen_common = { module = "dev.lukebemish.dynamicassetgenerator:dynamicassetgenerator-common-1.20.2", version.ref = "dynassetgen" } -dynassetgen_fabriquilt = { module = "dev.lukebemish.dynamicassetgenerator:dynamicassetgenerator-fabriquilt-1.20.2", version.ref = "dynassetgen" } -dynassetgen_neoforge = { module = "dev.lukebemish.dynamicassetgenerator:dynamicassetgenerator-neoforge-1.20.2", version.ref = "dynassetgen" } +dynassetgen_common = { module = "dev.lukebemish.dynamicassetgenerator:dynamicassetgenerator-common-1.20.4", version.ref = "dynassetgen" } +dynassetgen_fabriquilt = { module = "dev.lukebemish.dynamicassetgenerator:dynamicassetgenerator-fabriquilt-1.20.4", version.ref = "dynassetgen" } +dynassetgen_neoforge = { module = "dev.lukebemish.dynamicassetgenerator:dynamicassetgenerator-neoforge-1.20.4", version.ref = "dynassetgen" } -defaultresources_common = { module = "dev.lukebemish.defaultresources:defaultresources-common-1.20.2", version.ref = "defaultresources" } -defaultresources_fabriquilt = { module = "dev.lukebemish.defaultresources:defaultresources-fabriquilt-1.20.2", version.ref = "defaultresources" } -defaultresources_neoforge = { module = "dev.lukebemish.defaultresources:defaultresources-neoforge-1.20.2", version.ref = "defaultresources" } +defaultresources_common = { module = "dev.lukebemish.defaultresources:defaultresources-common-1.20.4", version.ref = "defaultresources" } +defaultresources_fabriquilt = { module = "dev.lukebemish.defaultresources:defaultresources-fabriquilt-1.20.4", version.ref = "defaultresources" } +defaultresources_neoforge = { module = "dev.lukebemish.defaultresources:defaultresources-neoforge-1.20.4", version.ref = "defaultresources" } -mixinextras_fabric = { module = "io.github.llamalad7:mixinextras-fabric", version.ref = "mixinextras" } +mixinextras_common = { module = "io.github.llamalad7:mixinextras-common", version.ref = "mixinextras" } [plugins] diff --git a/neoforge/src/main/java/dev/lukebemish/excavatedvariants/impl/neoforge/ExcavatedVariantsNeoForge.java b/neoforge/src/main/java/dev/lukebemish/excavatedvariants/impl/neoforge/ExcavatedVariantsNeoForge.java index 34d56424..38abcff3 100644 --- a/neoforge/src/main/java/dev/lukebemish/excavatedvariants/impl/neoforge/ExcavatedVariantsNeoForge.java +++ b/neoforge/src/main/java/dev/lukebemish/excavatedvariants/impl/neoforge/ExcavatedVariantsNeoForge.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Luke Bemish and contributors + * Copyright (C) 2023-2024 Luke Bemish and contributors * SPDX-License-Identifier: LGPL-3.0-or-later */ @@ -11,10 +11,16 @@ import dev.lukebemish.excavatedvariants.impl.ExcavatedVariants; import dev.lukebemish.excavatedvariants.impl.ExcavatedVariantsClient; import dev.lukebemish.excavatedvariants.impl.RegistriesImpl; +import dev.lukebemish.excavatedvariants.impl.network.AckOresPayload; +import dev.lukebemish.excavatedvariants.impl.network.SyncOresPayload; import dev.lukebemish.excavatedvariants.impl.worldgen.OreReplacer; import net.minecraft.core.Holder; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.Registries; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.Item; import net.minecraft.world.level.levelgen.feature.Feature; @@ -23,13 +29,20 @@ import net.neoforged.bus.api.IEventBus; import net.neoforged.fml.common.Mod; import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent; -import net.neoforged.fml.javafmlmod.FMLJavaModLoadingContext; import net.neoforged.fml.loading.FMLLoader; import net.neoforged.neoforge.common.NeoForge; import net.neoforged.neoforge.common.world.BiomeModifier; +import net.neoforged.neoforge.network.configuration.ICustomConfigurationTask; +import net.neoforged.neoforge.network.event.OnGameConfigurationEvent; +import net.neoforged.neoforge.network.event.RegisterPayloadHandlerEvent; +import net.neoforged.neoforge.network.handling.ConfigurationPayloadContext; import net.neoforged.neoforge.registries.DeferredRegister; import net.neoforged.neoforge.registries.NeoForgeRegistries; import net.neoforged.neoforge.registries.RegisterEvent; +import org.apache.commons.lang3.mutable.MutableBoolean; + +import java.util.function.Consumer; +import java.util.stream.Collectors; @Mod(ExcavatedVariants.MOD_ID) public class ExcavatedVariantsNeoForge { @@ -43,14 +56,15 @@ public class ExcavatedVariantsNeoForge { ).apply(i, AddFeatureLateModifier::new)) ); - public ExcavatedVariantsNeoForge() { - IEventBus modbus = FMLJavaModLoadingContext.get().getModEventBus(); + public ExcavatedVariantsNeoForge(IEventBus modbus) { ExcavatedVariants.init(); if (FMLLoader.getDist() == Dist.CLIENT) { ExcavatedVariantsClient.init(); } modbus.addListener(ExcavatedVariantsNeoForge::commonSetup); modbus.addListener(ExcavatedVariantsNeoForge::registerListener); + modbus.addListener(ExcavatedVariantsNeoForge::onRegisterPayloads); + modbus.addListener(ExcavatedVariantsNeoForge::onCollectConfigTasks); TO_REGISTER.register(modbus); BIOME_MODIFIERS.register(modbus); FEATURES.register(modbus); @@ -61,14 +75,6 @@ public ExcavatedVariantsNeoForge() { }); //ModList.get().getModContainerById("hyle").ifPresent(container -> MinecraftForge.EVENT_BUS.register(new HyleCompat())); - // TODO: Reimplement network checks, hopefully with new API - /* - EVPacketHandler.INSTANCE.registerMessage(0, S2CConfigAgreementPacket.class, S2CConfigAgreementPacket::encoder, S2CConfigAgreementPacket::decoder, (msg, c) -> { - c.enqueueWork(() -> msg.consumeMessage(string -> c.getNetworkManager().disconnect(Component.literal(string)))); - c.setPacketHandled(true); - }); - */ - FEATURES.register("ore_replacer", OreReplacer::new); } @@ -86,4 +92,74 @@ public static void registerListener(RegisterEvent event) { event.register(Registries.ITEM, helper -> ExcavatedVariants.initPostRegister()); } + + public static void onRegisterPayloads(final RegisterPayloadHandlerEvent event) { + event.registrar(ExcavatedVariants.MOD_ID) + .configuration( + SyncOresPayload.ID, + buf -> new SyncPayload(SyncOresPayload.decode(buf)), + handler -> handler.client(OresConfigTask::handleSync) + ) + .configuration( + AckOresPayload.ID, + buf -> new AckPayload(AckOresPayload.decode(buf)), + handler -> handler.server((payload, ctx) -> ctx.taskCompletedHandler().onTaskCompleted(OresConfigTask.TYPE)) + ); + } + + private record SyncPayload(SyncOresPayload payload) implements CustomPacketPayload { + @Override + public void write(FriendlyByteBuf buffer) { + payload.encode(buffer); + } + + @Override + public ResourceLocation id() { + return SyncOresPayload.ID; + } + } + + private record AckPayload(AckOresPayload payload) implements CustomPacketPayload { + @Override + public void write(FriendlyByteBuf buffer) { + payload.encode(buffer); + } + + @Override + public ResourceLocation id() { + return AckOresPayload.ID; + } + } + + private static final class OresConfigTask implements ICustomConfigurationTask { + public static final Type TYPE = new Type(ExcavatedVariants.id("ores")); + @Override + public void run(Consumer sender) { + var payload = new SyncOresPayload(ExcavatedVariants.COMPLETE_VARIANTS.stream().map(v -> v.fullId).collect(Collectors.toSet())); + sender.accept(new SyncPayload(payload)); + } + + @Override + public Type type() { + return TYPE; + } + + public static void handleSync(SyncPayload payload, ConfigurationPayloadContext ctx) { + MutableBoolean disconnect = new MutableBoolean(false); + payload.payload().consumeMessage(string -> { + disconnect.setTrue(); + ctx.packetHandler().disconnect(Component.literal(string)); + }); + + if (!disconnect.isTrue()) { + ctx.replyHandler().send(new AckPayload(new AckOresPayload())); + } + } + } + + public static void onCollectConfigTasks(final OnGameConfigurationEvent event) { + if (!event.getListener().getConnection().isMemoryConnection()) { + event.register(new OresConfigTask()); + } + } } diff --git a/neoforge/src/main/java/dev/lukebemish/excavatedvariants/impl/neoforge/mixin/ModifiedOreBlockMixin.java b/neoforge/src/main/java/dev/lukebemish/excavatedvariants/impl/neoforge/mixin/ModifiedOreBlockMixin.java index 151f4e1f..a31d41a1 100644 --- a/neoforge/src/main/java/dev/lukebemish/excavatedvariants/impl/neoforge/mixin/ModifiedOreBlockMixin.java +++ b/neoforge/src/main/java/dev/lukebemish/excavatedvariants/impl/neoforge/mixin/ModifiedOreBlockMixin.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Luke Bemish and contributors + * Copyright (C) 2023-2024 Luke Bemish and contributors * SPDX-License-Identifier: LGPL-3.0-or-later */ @@ -8,6 +8,7 @@ import dev.lukebemish.excavatedvariants.impl.ModifiedOreBlock; import net.minecraft.core.BlockPos; import net.minecraft.util.RandomSource; +import net.minecraft.util.valueproviders.IntProvider; import net.minecraft.world.level.LevelReader; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.DropExperienceBlock; @@ -28,8 +29,8 @@ public abstract class ModifiedOreBlockMixin extends DropExperienceBlock implemen @Final protected boolean delegateSpecialDrops; - public ModifiedOreBlockMixin(Properties pProperties) { - super(pProperties); + public ModifiedOreBlockMixin(IntProvider arg, Properties pProperties) { + super(arg, pProperties); throw new IllegalStateException(); } diff --git a/settings.gradle b/settings.gradle index ba35ec8c..fa77a82f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -36,7 +36,48 @@ pluginManagement { } plugins { - id 'org.gradle.toolchains.foojay-resolver-convention' version '0.6.0' + id 'com.gradle.enterprise' version '3.16.1' + id 'org.gradle.toolchains.foojay-resolver-convention' version '0.7.0' +} + +gradleEnterprise { + if (System.getenv('CI') != null) { + buildScan { + publishAlways() + termsOfServiceUrl = "https://gradle.com/terms-of-service" + termsOfServiceAgree = "yes" + } + } +} + +buildCache { + if (providers.gradleProperty('buildCacheUrl').orNull) { + remote(HttpBuildCache) { + url = providers.gradleProperty('buildCacheUrl').orNull + credentials { + username = providers.gradleProperty('buildCacheUser').orNull + password = providers.gradleProperty('buildCachePassword').orNull + } + if (providers.gradleProperty('buildCachePush').orNull) { + push = true + } else { + push = false + } + } + } else if (System.getenv('BUILD_CACHE_URL')) { + remote(HttpBuildCache) { + url = System.getenv('BUILD_CACHE_URL') + credentials { + username = System.getenv('BUILD_CACHE_USER') + password = System.getenv('BUILD_CACHE_PASSWORD') + } + if (System.getenv('BUILD_CACHE_PUSH') || System.getenv('CI')) { + push = true + } else { + push = false + } + } + } } rootProject.name = 'excavatedvariants' diff --git a/version.properties b/version.properties index 183ded64..6658340d 100644 --- a/version.properties +++ b/version.properties @@ -1 +1 @@ -version=4.0.3 +version=4.1.0