From aef4992cf5abdf69f9dd94206b45984e5af7ea34 Mon Sep 17 00:00:00 2001 From: HypherionMC Date: Mon, 25 Sep 2023 20:18:35 +0200 Subject: [PATCH] Port forge and finally fix build scripts --- .idea/misc.xml | 2 +- Common/build.gradle | 33 ++++++++--- Common/gradle.properties | 2 + .../client/gui/config/CraterConfigScreen.java | 2 +- .../client/gui/config/widgets/Option.java | 2 +- .../client/registry/ClientRegistry.java | 16 ++--- .../core/platform/ClientPlatform.java | 6 +- .../core/platform/CommonPlatform.java | 2 +- .../mixin/events/client/ClientLevelMixin.java | 1 - .../mixin/events/client/MinecraftMixin.java | 6 +- Common/src/main/resources/craterlib.aw | 1 - Fabric/build.gradle | 50 ++++++---------- .../client/FabricClientPlatform.java | 10 +--- .../impl/FabricClientNetworkHelper.java | 1 - Forge/build.gradle | 44 +++++--------- .../craterlib/client/ForgeClientHelper.java | 9 +-- .../craterlib/common/ForgeCommonHelper.java | 5 +- .../network/ForgeNetworkHandler.java | 58 +++++++++++++------ build.gradle | 36 ++++++++++-- gradle.properties | 7 ++- gradle/wrapper/gradle-wrapper.properties | 2 +- settings.gradle | 2 +- 22 files changed, 156 insertions(+), 141 deletions(-) create mode 100644 Common/gradle.properties diff --git a/.idea/misc.xml b/.idea/misc.xml index 121ee87..a37520a 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -12,7 +12,7 @@ - + \ No newline at end of file diff --git a/Common/build.gradle b/Common/build.gradle index 2015d82..1179fa2 100644 --- a/Common/build.gradle +++ b/Common/build.gradle @@ -1,24 +1,27 @@ plugins { - id 'java' - id 'fabric-loom' version '0.12-SNAPSHOT' - id 'maven-publish' - id 'com.github.johnrengelman.shadow' version '7.0.0' + id 'org.quiltmc.loom' version '1.3.+' } +apply plugin: 'com.github.johnrengelman.shadow' +apply plugin: 'maven-publish' + archivesBaseName = "${mod_name}-common-${minecraft_version}" loom { - shareCaches() accessWidenerPath = project.file("src/main/resources/craterlib.aw") - remapArchives = false mixin { useLegacyMixinAp = false } + runConfigs.configureEach { + ideConfigGenerated = false + } } dependencies { minecraft "com.mojang:minecraft:${minecraft_version}" mappings loom.officialMojangMappings() + modImplementation "org.quiltmc:quilt-loader:0.19.4" + compileOnly group: 'org.spongepowered', name: 'mixin', version: '0.8.5' implementation "com.hypherionmc:rpcsdk:1.0" } @@ -31,19 +34,31 @@ processResources { } } +/** + * Shadowjar Config + */ shadowJar { + exclude 'mappings/*' dependencies { include(dependency("me.hypherionmc.moon-config:core:${moon_config}")) include(dependency("me.hypherionmc.moon-config:toml:${moon_config}")) relocate 'me.hypherionmc.moonconfig', 'shadow.hypherionmc.moonconfig' } - setArchiveClassifier('') + setArchiveClassifier('dev-shadow') } -build.dependsOn shadowJar -reg.configureJarTask(shadowJar) +remapJar { + input.set shadowJar.archiveFile + dependsOn shadowJar + setArchiveClassifier(null) +} +//reg.configureJarTask(shadowJar) + +/** + * Publishing Config + */ publishing { publications { mavenJava(MavenPublication) { diff --git a/Common/gradle.properties b/Common/gradle.properties new file mode 100644 index 0000000..a0f6acd --- /dev/null +++ b/Common/gradle.properties @@ -0,0 +1,2 @@ +# We don't need the common jar to be remapped +fabric.loom.dontRemap = true \ No newline at end of file diff --git a/Common/src/main/java/com/hypherionmc/craterlib/client/gui/config/CraterConfigScreen.java b/Common/src/main/java/com/hypherionmc/craterlib/client/gui/config/CraterConfigScreen.java index 3d26274..98927ee 100644 --- a/Common/src/main/java/com/hypherionmc/craterlib/client/gui/config/CraterConfigScreen.java +++ b/Common/src/main/java/com/hypherionmc/craterlib/client/gui/config/CraterConfigScreen.java @@ -19,9 +19,9 @@ import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.joml.Matrix4f; -import javax.annotation.Nullable; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.math.BigDecimal; diff --git a/Common/src/main/java/com/hypherionmc/craterlib/client/gui/config/widgets/Option.java b/Common/src/main/java/com/hypherionmc/craterlib/client/gui/config/widgets/Option.java index 3dcf275..b7266bb 100644 --- a/Common/src/main/java/com/hypherionmc/craterlib/client/gui/config/widgets/Option.java +++ b/Common/src/main/java/com/hypherionmc/craterlib/client/gui/config/widgets/Option.java @@ -6,8 +6,8 @@ import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.events.AbstractContainerEventHandler; import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.network.chat.Component; +import org.jetbrains.annotations.Nullable; -import javax.annotation.Nullable; import java.util.ArrayList; import java.util.List; import java.util.Objects; diff --git a/Common/src/main/java/com/hypherionmc/craterlib/client/registry/ClientRegistry.java b/Common/src/main/java/com/hypherionmc/craterlib/client/registry/ClientRegistry.java index 3aee6c3..548a5eb 100644 --- a/Common/src/main/java/com/hypherionmc/craterlib/client/registry/ClientRegistry.java +++ b/Common/src/main/java/com/hypherionmc/craterlib/client/registry/ClientRegistry.java @@ -1,15 +1,7 @@ package com.hypherionmc.craterlib.client.registry; -import com.hypherionmc.craterlib.api.rendering.DyableBlock; -import com.hypherionmc.craterlib.api.rendering.ItemDyable; -import com.hypherionmc.craterlib.client.rendering.ItemColorHandler; import com.hypherionmc.craterlib.core.platform.ClientPlatform; -import com.hypherionmc.craterlib.core.systems.reg.RegistrationProvider; -import net.minecraft.client.color.block.BlockColors; -import net.minecraft.client.color.item.ItemColors; import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; -import net.minecraft.world.item.Item; -import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import org.jetbrains.annotations.NotNull; @@ -26,13 +18,13 @@ public class ClientRegistry { * @param colors Existing block colors obtained from {@link com.hypherionmc.craterlib.api.event.client.ColorRegistrationEvent} * @param blocks The blocks registered for the module */ - public static void registerBlockColors(@NotNull BlockColors colors, @NotNull RegistrationProvider blocks) { + /*public static void registerBlockColors(@NotNull BlockColors colors, @NotNull RegistrationProvider blocks) { blocks.getEntries().forEach(blockRegistryObject -> { if (blockRegistryObject.get() instanceof DyableBlock dyableBlock) { colors.register(dyableBlock.dyeHandler(), (Block) dyableBlock); } }); - } + }*/ /** * Register Item Color Handlers @@ -40,13 +32,13 @@ public class ClientRegistry { * @param colors Existing item colors obtained from {@link com.hypherionmc.craterlib.api.event.client.ColorRegistrationEvent} * @param items The items registered for the module */ - public static void registerItemColors(@NotNull ItemColors colors, @NotNull RegistrationProvider items) { + /*public static void registerItemColors(@NotNull ItemColors colors, @NotNull RegistrationProvider items) { items.getEntries().forEach(itemRegistryObject -> { if (itemRegistryObject.get() instanceof ItemDyable itemDyable) { colors.register(new ItemColorHandler(), (Item) itemDyable); } }); - } + }*/ /** * Register a {@link net.minecraft.client.renderer.blockentity.BlockEntityRenderer} for a BlockEntity diff --git a/Common/src/main/java/com/hypherionmc/craterlib/core/platform/ClientPlatform.java b/Common/src/main/java/com/hypherionmc/craterlib/core/platform/ClientPlatform.java index f536a7b..fcf44ca 100644 --- a/Common/src/main/java/com/hypherionmc/craterlib/core/platform/ClientPlatform.java +++ b/Common/src/main/java/com/hypherionmc/craterlib/core/platform/ClientPlatform.java @@ -1,20 +1,16 @@ package com.hypherionmc.craterlib.core.platform; import com.hypherionmc.craterlib.common.item.BlockItemDyable; -import com.hypherionmc.craterlib.core.systems.reg.RegistryObject; import com.hypherionmc.craterlib.util.ServiceUtil; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; import net.minecraft.network.Connection; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import org.jetbrains.annotations.NotNull; -import java.util.Collection; - /** * @author HypherionSA */ @@ -24,7 +20,7 @@ public interface ClientPlatform { void registerItemProperty(@NotNull BlockItemDyable item, @NotNull String property); - void registerCustomRenderTypes(@NotNull Collection> blocks); + //void registerCustomRenderTypes(@NotNull Collection> blocks); Minecraft getClientInstance(); diff --git a/Common/src/main/java/com/hypherionmc/craterlib/core/platform/CommonPlatform.java b/Common/src/main/java/com/hypherionmc/craterlib/core/platform/CommonPlatform.java index d147ed5..5e53938 100644 --- a/Common/src/main/java/com/hypherionmc/craterlib/core/platform/CommonPlatform.java +++ b/Common/src/main/java/com/hypherionmc/craterlib/core/platform/CommonPlatform.java @@ -13,8 +13,8 @@ import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.inventory.MenuType; import net.minecraft.world.level.block.entity.BlockEntity; import org.apache.commons.lang3.function.TriFunction; +import org.jetbrains.annotations.Nullable; -import javax.annotation.Nullable; import java.util.Optional; import java.util.function.Consumer; diff --git a/Common/src/main/java/com/hypherionmc/craterlib/mixin/events/client/ClientLevelMixin.java b/Common/src/main/java/com/hypherionmc/craterlib/mixin/events/client/ClientLevelMixin.java index 83c016d..44805fc 100644 --- a/Common/src/main/java/com/hypherionmc/craterlib/mixin/events/client/ClientLevelMixin.java +++ b/Common/src/main/java/com/hypherionmc/craterlib/mixin/events/client/ClientLevelMixin.java @@ -3,7 +3,6 @@ package com.hypherionmc.craterlib.mixin.events.client; import com.hypherionmc.craterlib.api.event.client.CraterSinglePlayerEvent; import com.hypherionmc.craterlib.core.event.CraterEventBus; import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.client.player.AbstractClientPlayer; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import org.spongepowered.asm.mixin.Mixin; diff --git a/Common/src/main/java/com/hypherionmc/craterlib/mixin/events/client/MinecraftMixin.java b/Common/src/main/java/com/hypherionmc/craterlib/mixin/events/client/MinecraftMixin.java index f8de1d2..b9b8596 100644 --- a/Common/src/main/java/com/hypherionmc/craterlib/mixin/events/client/MinecraftMixin.java +++ b/Common/src/main/java/com/hypherionmc/craterlib/mixin/events/client/MinecraftMixin.java @@ -4,18 +4,18 @@ import com.hypherionmc.craterlib.api.event.client.ScreenEvent; import com.hypherionmc.craterlib.core.event.CraterEventBus; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.Screen; +import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import javax.annotation.Nullable; - @Mixin(Minecraft.class) public class MinecraftMixin { - @Shadow @Nullable public Screen screen; + @Shadow @Nullable + public Screen screen; @Inject(method = "setScreen", at = @At(value = "TAIL")) private void injectScreenOpeningEvent(Screen screen, CallbackInfo ci) { diff --git a/Common/src/main/resources/craterlib.aw b/Common/src/main/resources/craterlib.aw index 54b896c..d7b5c4c 100644 --- a/Common/src/main/resources/craterlib.aw +++ b/Common/src/main/resources/craterlib.aw @@ -1,4 +1,3 @@ accessWidener v1 named -accessible class net/minecraft/client/renderer/LevelRenderer$RenderChunkInfo accessible method net/minecraft/client/renderer/item/ItemProperties register (Lnet/minecraft/world/item/Item;Lnet/minecraft/resources/ResourceLocation;Lnet/minecraft/client/renderer/item/ClampedItemPropertyFunction;)V diff --git a/Fabric/build.gradle b/Fabric/build.gradle index 82760d9..94f8972 100644 --- a/Fabric/build.gradle +++ b/Fabric/build.gradle @@ -1,16 +1,16 @@ plugins { - id 'fabric-loom' version '0.12-SNAPSHOT' - id 'maven-publish' + id 'fabric-loom' version '1.3-SNAPSHOT' id 'idea' - id 'com.github.johnrengelman.shadow' version '7.0.0' - id "me.hypherionmc.modutils.modpublisher" version "1.0.+" } +apply plugin: 'me.hypherionmc.modutils.modpublisher' +apply plugin: 'com.github.johnrengelman.shadow' +apply plugin: 'maven-publish' + archivesBaseName = "${mod_name}-fabric-${minecraft_version}" configurations { shade - implementation.extendsFrom shade } dependencies { @@ -30,7 +30,6 @@ dependencies { } loom { - shareCaches() accessWidenerPath = project(":Common").file("src/main/resources/craterlib.aw") runs { client { @@ -48,7 +47,6 @@ loom { } } - processResources { from project(":Common").sourceSets.main.resources inputs.property "version", project.version @@ -72,23 +70,28 @@ jar { } } +/** + * Shadowjar Config + */ shadowJar { - from sourceSets.main.output - configurations = [project.configurations.shade] dependencies { relocate 'me.hypherionmc.moonconfig', 'shadow.hypherionmc.moonconfig' } + setArchiveClassifier("dev-shadow") } remapJar { - dependsOn(shadowJar) - shouldRunAfter(shadowJar) - input.set shadowJar.archiveFile.get() + input.set shadowJar.archiveFile + dependsOn shadowJar + setArchiveClassifier(null) } -reg.configureJarTask(shadowJar) +//reg.configureJarTask(shadowJar) +/** + * Publishing Config + */ publishing { publications { mavenJava(MavenPublication) { @@ -125,24 +128,6 @@ publishing { } } -task delDevJar { - doLast { - def tree = fileTree('build/libs') - tree.include '**/*-dev.jar' - tree.include '**/*-all.jar' - tree.each { it.delete() } - } -} -build.finalizedBy delDevJar - -task copyAllArtifacts(type: Copy) { - from "$buildDir/libs" - into "$rootDir/artifacts" - include("*.jar") -} - -build.finalizedBy(copyAllArtifacts) - publisher { apiKeys { modrinth = System.getenv("MODRINTH_TOKEN") @@ -168,4 +153,5 @@ publisher { } } -publishMod.dependsOn(build) \ No newline at end of file +publishMod.dependsOn(build) + diff --git a/Fabric/src/main/java/com/hypherionmc/craterlib/client/FabricClientPlatform.java b/Fabric/src/main/java/com/hypherionmc/craterlib/client/FabricClientPlatform.java index a540589..a113a7b 100644 --- a/Fabric/src/main/java/com/hypherionmc/craterlib/client/FabricClientPlatform.java +++ b/Fabric/src/main/java/com/hypherionmc/craterlib/client/FabricClientPlatform.java @@ -1,12 +1,9 @@ package com.hypherionmc.craterlib.client; -import com.hypherionmc.craterlib.api.rendering.CustomRenderType; import com.hypherionmc.craterlib.common.item.BlockItemDyable; import com.hypherionmc.craterlib.core.platform.ClientPlatform; -import com.hypherionmc.craterlib.core.systems.reg.RegistryObject; import com.hypherionmc.craterlib.util.ColorPropertyFunction; import net.fabricmc.api.EnvType; -import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; @@ -16,13 +13,10 @@ import net.minecraft.network.Connection; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import org.jetbrains.annotations.NotNull; -import java.util.Collection; - /** * @author HypherionSA */ @@ -35,14 +29,14 @@ public class FabricClientPlatform implements ClientPlatform { } } - @Override + /*@Override public void registerCustomRenderTypes(Collection> blocks) { blocks.forEach(blk -> { if (blk.get() instanceof CustomRenderType type) { BlockRenderLayerMap.INSTANCE.putBlock(blk.get(), type.getCustomRenderType()); } }); - } + }*/ @Override public Minecraft getClientInstance() { diff --git a/Fabric/src/main/java/com/hypherionmc/craterlib/network/impl/FabricClientNetworkHelper.java b/Fabric/src/main/java/com/hypherionmc/craterlib/network/impl/FabricClientNetworkHelper.java index ba9ddc5..9e0eaf8 100644 --- a/Fabric/src/main/java/com/hypherionmc/craterlib/network/impl/FabricClientNetworkHelper.java +++ b/Fabric/src/main/java/com/hypherionmc/craterlib/network/impl/FabricClientNetworkHelper.java @@ -1,7 +1,6 @@ package com.hypherionmc.craterlib.network.impl; import com.hypherionmc.craterlib.core.network.CraterPacket; -import com.hypherionmc.craterlib.network.FabricNetworkHelper; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.fabricmc.fabric.api.networking.v1.PacketSender; import net.minecraft.client.Minecraft; diff --git a/Forge/build.gradle b/Forge/build.gradle index a5d5eda..3a61dc0 100644 --- a/Forge/build.gradle +++ b/Forge/build.gradle @@ -1,22 +1,10 @@ -buildscript { - repositories { - maven { url = 'https://mcentral.firstdark.dev/releases' } - mavenCentral() - } - dependencies { - classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1.+', changing: true - classpath 'org.spongepowered:mixingradle:0.7-SNAPSHOT' - } -} -plugins { - id 'com.github.johnrengelman.shadow' version '7.0.0' - id "me.hypherionmc.modutils.modpublisher" version "1.0.+" -} apply plugin: 'java' apply plugin: 'net.minecraftforge.gradle' apply plugin: 'eclipse' apply plugin: 'org.spongepowered.mixin' apply plugin: 'maven-publish' +apply plugin: 'me.hypherionmc.modutils.modpublisher' +apply plugin: 'com.github.johnrengelman.shadow' archivesBaseName = "${mod_name}-forge-${minecraft_version}" @@ -31,8 +19,6 @@ minecraft { mappings channel: 'official', version: minecraft_version if (project.hasProperty('forge_ats_enabled') && project.findProperty('forge_ats_enabled').toBoolean()) { - // This location is hardcoded in Forge and can not be changed. - // https://github.com/MinecraftForge/MinecraftForge/blob/be1698bb1554f9c8fa2f58e32b9ab70bc4385e60/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModFile.java#L123 accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') project.logger.debug('Forge Access Transformers are enabled for this project.') } @@ -109,23 +95,28 @@ processResources { } } +/** + * Shadowjar Config + */ shadowJar { configurations = [project.configurations.shade] dependencies { relocate 'me.hypherionmc.moonconfig', 'shadow.hypherionmc.moonconfig' } - - classifier = '' + setArchiveClassifier('') } +assemble.dependsOn(shadowJar) + reobf { shadowJar {} } -build.dependsOn reobfShadowJar -reg.configureJarTask(shadowJar) -jar.finalizedBy('reobfJar') +//reg.configureJarTask(shadowJar) +/** + * Publishing Config + */ publishing { publications { mavenJava(MavenPublication) { @@ -156,14 +147,6 @@ publishing { } } -task copyAllArtifacts(type: Copy) { - from "$buildDir/libs" - into "$rootDir/artifacts" - include("*.jar") -} - -build.finalizedBy(copyAllArtifacts) - publisher { apiKeys { modrinth = System.getenv("MODRINTH_TOKEN") @@ -181,4 +164,5 @@ publisher { artifact = jar } -publishMod.dependsOn(build) \ No newline at end of file +publishMod.dependsOn(build) +jar.finalizedBy('reobfJar') \ No newline at end of file diff --git a/Forge/src/main/java/com/hypherionmc/craterlib/client/ForgeClientHelper.java b/Forge/src/main/java/com/hypherionmc/craterlib/client/ForgeClientHelper.java index f7996ce..ce9cd23 100644 --- a/Forge/src/main/java/com/hypherionmc/craterlib/client/ForgeClientHelper.java +++ b/Forge/src/main/java/com/hypherionmc/craterlib/client/ForgeClientHelper.java @@ -1,12 +1,9 @@ package com.hypherionmc.craterlib.client; -import com.hypherionmc.craterlib.api.rendering.CustomRenderType; import com.hypherionmc.craterlib.common.item.BlockItemDyable; import com.hypherionmc.craterlib.core.platform.ClientPlatform; -import com.hypherionmc.craterlib.core.systems.reg.RegistryObject; import com.hypherionmc.craterlib.util.ColorPropertyFunction; import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.ItemBlockRenderTypes; import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; import net.minecraft.client.renderer.blockentity.BlockEntityRenderers; import net.minecraft.client.renderer.item.ItemProperties; @@ -14,12 +11,10 @@ import net.minecraft.network.Connection; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraftforge.fml.loading.FMLEnvironment; -import java.util.Collection; import java.util.Objects; /** @@ -37,14 +32,14 @@ public class ForgeClientHelper implements ClientPlatform { } } - @Override + /*@Override public void registerCustomRenderTypes(Collection> blocks) { blocks.forEach(blk -> { if (blk.get() instanceof CustomRenderType type) { ItemBlockRenderTypes.setRenderLayer(blk.get(), type.getCustomRenderType()); } }); - } + }*/ @Override public Minecraft getClientInstance() { diff --git a/Forge/src/main/java/com/hypherionmc/craterlib/common/ForgeCommonHelper.java b/Forge/src/main/java/com/hypherionmc/craterlib/common/ForgeCommonHelper.java index 1594b70..9b2b4ce 100644 --- a/Forge/src/main/java/com/hypherionmc/craterlib/common/ForgeCommonHelper.java +++ b/Forge/src/main/java/com/hypherionmc/craterlib/common/ForgeCommonHelper.java @@ -21,7 +21,6 @@ import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.common.extensions.IForgeMenuType; -import net.minecraftforge.network.NetworkHooks; import net.minecraftforge.server.ServerLifecycleHooks; import org.apache.commons.lang3.function.TriFunction; import org.jetbrains.annotations.Nullable; @@ -54,9 +53,9 @@ public class ForgeCommonHelper implements CommonPlatform { @Override public void openMenu(ServerPlayer player, MenuProvider menu, @Nullable Consumer initialData) { if (initialData != null) { - NetworkHooks.openScreen(player, menu, initialData); + player.openMenu(menu, initialData); } else { - NetworkHooks.openScreen(player, menu, player.getOnPos()); + player.openMenu(menu, player.getOnPos()); } } diff --git a/Forge/src/main/java/com/hypherionmc/craterlib/network/ForgeNetworkHandler.java b/Forge/src/main/java/com/hypherionmc/craterlib/network/ForgeNetworkHandler.java index 0ffeec8..72f3f1a 100644 --- a/Forge/src/main/java/com/hypherionmc/craterlib/network/ForgeNetworkHandler.java +++ b/Forge/src/main/java/com/hypherionmc/craterlib/network/ForgeNetworkHandler.java @@ -5,17 +5,21 @@ import com.hypherionmc.craterlib.core.network.CraterNetworkHandler; import com.hypherionmc.craterlib.core.network.CraterPacket; import com.hypherionmc.craterlib.core.network.PacketDirection; import com.hypherionmc.craterlib.core.platform.ClientPlatform; +import io.netty.buffer.Unpooled; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.protocol.Packet; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Player; import net.minecraftforge.common.util.LogicalSidedProvider; +import net.minecraftforge.event.network.CustomPayloadEvent; import net.minecraftforge.fml.LogicalSide; +import net.minecraftforge.network.Channel; +import net.minecraftforge.network.ChannelBuilder; import net.minecraftforge.network.NetworkDirection; -import net.minecraftforge.network.NetworkEvent; -import net.minecraftforge.network.NetworkRegistry; -import net.minecraftforge.network.simple.SimpleChannel; +import net.minecraftforge.network.SimpleChannel; +import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.BiConsumer; @@ -29,7 +33,6 @@ import java.util.function.Supplier; public class ForgeNetworkHandler implements CraterNetworkHandler { private static final Map NETWORK_HANDLERS = Maps.newConcurrentMap(); - private static final String PROTOCOL = Integer.toString(1); private final SimpleChannel channel; @@ -39,6 +42,8 @@ public class ForgeNetworkHandler implements CraterNetworkHandler { private final AtomicInteger packetID = new AtomicInteger(); + private HashMap, Integer> packetMap = new LinkedHashMap<>(); + private ForgeNetworkHandler(SimpleChannel channel, boolean clientRequired, boolean serverRequired) { this.channel = channel; this.clientRequired = clientRequired; @@ -54,37 +59,47 @@ public class ForgeNetworkHandler implements CraterNetworkHandler { return packet; }; - BiConsumer> handler = (packet, sup) -> { - NetworkEvent.Context context = sup.get(); + BiConsumer handler = (packet, sup) -> { LogicalSide expectedSide = getSideFromDirection(packetDirection); - LogicalSide currentSide = context.getDirection().getReceptionSide(); + LogicalSide currentSide = sup.getDirection().getReceptionSide(); if (expectedSide != currentSide) { throw new IllegalStateException(String.format("Received message on wrong side, expected %s, was %s", expectedSide, currentSide)); } - context.enqueueWork(() -> { + sup.enqueueWork(() -> { Player player; if (packetDirection == PacketDirection.TO_CLIENT) { player = ClientPlatform.INSTANCE.getClientPlayer(); } else { - player = context.getSender(); + player = sup.getSender(); } packet.handle(player, LogicalSidedProvider.WORKQUEUE.get(expectedSide)); }); - context.setPacketHandled(true); + sup.setPacketHandled(true); }; - this.channel.registerMessage(this.packetID.getAndIncrement(), (Class) clazz, encoder, decoder, handler); + + int id = packetID.getAndIncrement(); + packetMap.put(clazz, id); + + this.channel + .messageBuilder((Class) clazz, id) + .encoder(encoder) + .decoder(decoder) + .consumerNetworkThread(handler) + .add(); } @Override public Packet toServerBound(CraterPacket packet) { - return this.channel.toVanillaPacket(packet, NetworkDirection.PLAY_TO_SERVER); + return NetworkDirection.PLAY_TO_SERVER.buildPacket(toBuffer(packet), channel.getName()).getThis(); + //return this.channel.toVanillaPacket(packet, NetworkDirection.PLAY_TO_SERVER); } @Override public Packet toClientBound(CraterPacket packet) { - return this.channel.toVanillaPacket(packet, NetworkDirection.PLAY_TO_CLIENT); + return NetworkDirection.PLAY_TO_CLIENT.buildPacket(toBuffer(packet), channel.getName()).getThis(); + //return this.channel.toVanillaPacket(packet, NetworkDirection.PLAY_TO_CLIENT); } @Override @@ -100,15 +115,24 @@ public class ForgeNetworkHandler implements CraterNetworkHandler { } private static SimpleChannel buildSimpleChannel(String modId, boolean clientAcceptsVanillaOrMissing, boolean serverAcceptsVanillaOrMissing) { - return NetworkRegistry.ChannelBuilder + return ChannelBuilder .named(new ResourceLocation(modId, "crater_network")) - .networkProtocolVersion(() -> PROTOCOL) - .clientAcceptedVersions(clientAcceptsVanillaOrMissing ? NetworkRegistry.acceptMissingOr(PROTOCOL) : PROTOCOL::equals) - .serverAcceptedVersions(serverAcceptsVanillaOrMissing ? NetworkRegistry.acceptMissingOr(PROTOCOL) : PROTOCOL::equals) + .networkProtocolVersion(1) + .clientAcceptedVersions(clientAcceptsVanillaOrMissing ? Channel.VersionTest.ACCEPT_MISSING : Channel.VersionTest.exact(1)) + .serverAcceptedVersions(serverAcceptsVanillaOrMissing ? Channel.VersionTest.ACCEPT_MISSING : Channel.VersionTest.exact(1)) .simpleChannel(); } private LogicalSide getSideFromDirection(PacketDirection direction) { return direction == PacketDirection.TO_CLIENT ? LogicalSide.CLIENT : LogicalSide.SERVER; } + + protected FriendlyByteBuf toBuffer(CraterPacket message) { + var msg = packetMap.get(message.getClass()); + + var ret = new FriendlyByteBuf(Unpooled.buffer()); + ret.writeVarInt(msg); + message.write(ret); + return ret; + } } diff --git a/build.gradle b/build.gradle index 7818c0a..e00f6c9 100644 --- a/build.gradle +++ b/build.gradle @@ -1,17 +1,21 @@ plugins { id 'java' - id 'com.matyrobbrt.mc.registrationutils' version '1.20-1.1.0' + //id 'com.matyrobbrt.mc.registrationutils' version '1.20.1-1.0.0' id 'maven-publish' + id 'net.minecraftforge.gradle' version '[6.0,6.2)' apply false + id 'org.spongepowered.mixin' version '0.7-SNAPSHOT' apply false + id 'com.github.johnrengelman.shadow' version '7.0.0' apply false + id "me.hypherionmc.modutils.modpublisher" version "1.0.+" apply false } -registrationUtils { +/*registrationUtils { group 'com.hypherionmc.craterlib.core.systems.reg' projects { Common { type 'common'; project ':Common' } Fabric { type 'fabric'; project ':Fabric' } - //Forge { type 'forge'; project ':Forge' } + Forge { type 'forge'; project ':Forge' } } -} +}*/ ext { release = project.properties['release'] ?: false @@ -38,6 +42,8 @@ subprojects { //java.withJavadocJar() jar { + archiveClassifier = 'slim' + manifest { attributes([ 'Specification-Title' : mod_name, @@ -86,6 +92,28 @@ subprojects { clean { delete "$rootDir/artifacts" } + + if (project.name !== 'Common') { + task delDevJar { + doLast { + def tree = fileTree('build/libs') + tree.include '**/*-dev.jar' + tree.include '**/*-dev-shadow.jar' + tree.include '**/*-all.jar' + tree.include '**/*-slim.jar' + tree.each { it.delete() } + } + } + build.finalizedBy delDevJar + + task copyAllArtifacts(type: Copy) { + from "$buildDir/libs" + into "$rootDir/artifacts" + include("*.jar") + } + + build.finalizedBy(copyAllArtifacts) + } } // Standalone or Module JARS diff --git a/gradle.properties b/gradle.properties index 6e3c935..a862705 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,6 @@ +# Gradle +fabric.loom.multiProjectOptimisation = true + # Project version_major=1 version_minor=0 @@ -11,7 +14,7 @@ common_client_run_name=Common Client common_server_run_name=Common Server # Forge -forge_version=46.0.1 +forge_version=48.0.6 forge_ats_enabled=true # Fabric @@ -28,7 +31,7 @@ org.gradle.jvmargs=-Xmx3G org.gradle.daemon=false # Dependencies -mod_menu_version=7.0.0-beta.2 +mod_menu_version=8.0.0-beta.2 moon_config=1.0.9 # Publishing diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 59bc51a..fae0804 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/settings.gradle b/settings.gradle index 3d51941..9664f24 100644 --- a/settings.gradle +++ b/settings.gradle @@ -11,4 +11,4 @@ pluginManagement { } rootProject.name = 'CraterLib' -include("Common", "Fabric"/*, "Forge"*/) +include("Common", "Fabric", "Forge")