diff --git a/.github/workflows/build_current.yml b/.github/workflows/build_current.yml index 706dbe54..243bc5e0 100644 --- a/.github/workflows/build_current.yml +++ b/.github/workflows/build_current.yml @@ -15,30 +15,6 @@ permissions: actions: write jobs: - clear-cache: - name: "Clear Cache" - runs-on: ubuntu-latest - if: | - github.event.inputs.clear_cache == 'true' - steps: - - name: Clear cache - uses: actions/github-script@v6 - with: - script: | - console.log("About to clear") - const caches = await github.rest.actions.getActionsCacheList({ - owner: context.repo.owner, - repo: context.repo.repo, - }) - for (const cache of caches.data.actions_caches) { - console.log(cache) - github.rest.actions.deleteActionsCacheById({ - owner: context.repo.owner, - repo: context.repo.repo, - cache_id: cache.id, - }) - } - console.log("Clear completed") build: name: "Build" runs-on: ubuntu-latest @@ -69,7 +45,7 @@ jobs: name: "${{ env.archives_base_name }}-${{ env.mod_version }}" path: | build/**/**/libs/ - !build/**/temp/ + !build/*/libs/ !build/**/craftedcore/libs/ !build/libs/ !**/*-dev.jar diff --git a/.github/workflows/clear_cache.yml b/.github/workflows/clear_cache.yml index fe0987e0..e434bdf2 100644 --- a/.github/workflows/clear_cache.yml +++ b/.github/workflows/clear_cache.yml @@ -11,8 +11,6 @@ jobs: clear-cache: name: "Clear Cache" runs-on: ubuntu-latest - if: | - github.event.inputs.clear_cache == 'true' steps: - name: Clear cache uses: actions/github-script@v6 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index fcc72454..03984891 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,10 +11,6 @@ on: - "master" workflow_dispatch: inputs: - clear_cache: - description: 'Clear Cache' - required: false - default: 'true' release: description: 'Release' required: false @@ -29,30 +25,6 @@ permissions: actions: write jobs: - clear-cache: - name: "Clear Cache" - runs-on: ubuntu-latest - if: | - github.event.inputs.clear_cache == 'true' - steps: - - name: Clear cache - uses: actions/github-script@v6 - with: - script: | - console.log("About to clear") - const caches = await github.rest.actions.getActionsCacheList({ - owner: context.repo.owner, - repo: context.repo.repo, - }) - for (const cache of caches.data.actions_caches) { - console.log(cache) - github.rest.actions.deleteActionsCacheById({ - owner: context.repo.owner, - repo: context.repo.repo, - cache_id: cache.id, - }) - } - console.log("Clear completed") release: name: "Release" runs-on: ubuntu-latest @@ -72,16 +44,31 @@ jobs: - name: Setup Gradle uses: gradle/actions/setup-gradle@v3 - - name: Extract Artifact Type + - name: Extract Artifact Type, Archive Base Name & Mod Version run: | cat $GITHUB_WORKSPACE/gradle.properties | grep ^artifact_type= >> $GITHUB_ENV + cat $GITHUB_WORKSPACE/gradle.properties | grep ^archives_base_name= >> $GITHUB_ENV + cat $GITHUB_WORKSPACE/gradle.properties | grep ^mod_version= >> $GITHUB_ENV - - name: Publish to Maven, Modrinth & CurseForge - run: ./gradlew publish modrinth curseforge --parallel + - name: Build + Publish to Maven, Modrinth & CurseForge + run: ./gradlew check build publish modrinth curseforge --parallel env: MAVEN_PASS: ${{ secrets.MAVEN_PASS }} CURSEFORGE_TOKEN: ${{ secrets.CURSEFORGE_TOKEN }} MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }} + - uses: actions/upload-artifact@v4 + with: + name: "${{ env.archives_base_name }}-${{ env.mod_version }}" + path: | + build/**/**/libs/ + !build/*/libs/ + !build/**/craftedcore/libs/ + !build/libs/ + !**/*-dev.jar + !**/*-shadow.jar + !**/*-transformProduction*.jar + !**/testmod*/ + - name: Extract Changelog for GitHub run: ./gradlew extractNewestChangelog --parallel @@ -89,26 +76,24 @@ jobs: run: | cat $GITHUB_WORKSPACE/gradle.properties | grep ^archives_base_name= >> $GITHUB_ENV cat $GITHUB_WORKSPACE/gradle.properties | grep ^mod_version= >> $GITHUB_ENV - - name: Create GitHub Tag - if: | - ${{ env.artifact_type }} == 'release' - uses: EndBug/latest-tag@latest + - name: Download artifact + id: download-artifact + uses: dawidd6/action-download-artifact@v6 with: - ref: "${{ env.$mod_version }}" + skip_unpack: true - name: Create GitHub Release if: | ${{ env.artifact_type }} == 'release' uses: softprops/action-gh-release@v2 with: - tag_name: "${{ env.$mod_version }}" + tag_name: "${{ env.mod_version }}" files: | - fabric/build/libs/${{ env.archives_base_name }}-${{ env.mod_version }}-fabric.jar, - forge/build/libs/${{ env.archives_base_name }}-${{ env.mod_version }}-forge.jar, - neoforge/build/libs/${{ env.archives_base_name }}-${{ env.mod_version }}-neoforge.jar + build/**/fabric/build/libs/${{ env.archives_base_name }}-${{ env.mod_version }}-*-fabric.jar, + build/**/forge/build/libs/${{ env.archives_base_name }}-${{ env.mod_version }}-*-forge.jar, + build/**/neoforge/build/libs/${{ env.archives_base_name }}-${{ env.mod_version }}-*-neoforge.jar body_path: ${{ github.workspace }}/extracted.CHANGELOG.md discord_message: name: "Send Discord Release Message" - needs: build runs-on: ubuntu-latest if: | github.event.inputs.discord_message == 'true' diff --git a/CHANGELOG.md b/CHANGELOG.md index 62fe1763..40eda030 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +craftedcore 5 +================ + +- **rework multi-version structure** +- fix crash on NeoForge 1.20.4 with Server + craftedcore 4.3.1 ================ diff --git a/build.gradle b/build.gradle index 9bd997fa..0bdca8d4 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { } dependencies { classpath group: 'com.diluv.schoomp', name: 'Schoomp', version: '1.2.6+' - classpath "dev.tocraft:preprocessor:0.79-SNAPSHOT" + classpath "dev.tocraft:preprocessor:0.91-SNAPSHOT" } } @@ -100,107 +100,11 @@ allprojects { options.release.set Integer.parseInt(project.props.java) } - ext { - // Original by Flemmli97 - releaseChangelog = { int versions -> - try { - String changelog = "" - int match = 0 - String previousIT = "" - project.file("CHANGELOG.md").eachLine { - if (it.contains("================")) { - match++ - //changelog += previousIT - } - if (match <= versions) { - changelog += previousIT + "\n" - } - previousIT = it - return - } - return changelog + "\n\n" - } catch (exception) { - return "${project.archives_base_name} ${project.mod_version}\n==========\nThere was an error generating the changelog" + exception.getLocalizedMessage() - } - } - } - java { withSourcesJar() } } -//Splits the changelog into multiple parts if they get bigger than discords embed field size (1024) -static def discordChangelog() { - def changelog = releaseChangelog(1) - List res = new ArrayList() - if (changelog.size() < 1024) { - res.add(changelog) - return res - } - String temp = "" - changelog.split("\n" as Closure).each { - it = it + "\n" - if ((temp.size() + it.size()) >= 1024) { - res.add(temp) - temp = it - } else - temp += it - } - res.add(temp) - return res -} - -// based on the code by Flemmli97 -tasks.register('discordRelease') { - doLast { - try { - def webhook = new Webhook(System.getenv("DISCORD_WEB_HOOK"), "${project.name} Upload") - - def message = new Message() - message.setUsername("Mod Release") - def content = "${project.name} ${project.mod_version} has been released!" - if (project.hasProperty("ping_role")) { - content = "<@&${project.getProperty("ping_role")}> " + content - } - message.setContent(content) - message.setAvatarUrl("https://avatars.githubusercontent.com/u/38883321") - - def embed = new Embed() - - def changelog = discordChangelog() - if (changelog.size() == 1) - embed.addField('Change Log', "```md\n${changelog.get(0) ?: 'Unavailable :('}```", false) - else - changelog.forEach { - embed.addField("Change Log", "```md\n${it}```", false) - } - embed.setColor(0xFF8000) - message.addEmbed(embed) - - webhook.sendMessage(message) - } - - catch (IOException ignored) { - println 'Failed to push to the Discord webhook.' - } - println "Send Changelog to Discord." - } -} - -tasks.register('extractNewestChangelog') { - String fileName = "extracted.CHANGELOG.md"; - // delete file if exists - delete fileName - doLast { - // write changelog - FileWriter fw = new FileWriter(fileName); - fw.write(releaseChangelog(1)); - fw.close() - println "Extracted newest Changelog to \"extracted.CHANGELOG.md\"" - } -} - ext { mod_meta = [ minecraft: project.name, diff --git a/common/src/main/java/tocraft/craftedcore/CraftedCore.java b/common/src/main/java/tocraft/craftedcore/CraftedCore.java index 9516a1c1..882f6bef 100644 --- a/common/src/main/java/tocraft/craftedcore/CraftedCore.java +++ b/common/src/main/java/tocraft/craftedcore/CraftedCore.java @@ -23,9 +23,9 @@ public void initialize() { MixinExtrasBootstrap.init(); //#if MC>=1205 - //$$ // register Network Types - //$$ ModernNetworking.registerType(ConfigLoader.CONFIG_SYNC); - //$$ ModernNetworking.registerType(PlayerDataSynchronizer.PLAYER_DATA_SYNC_ID); + // register Network Types + ModernNetworking.registerType(ConfigLoader.CONFIG_SYNC); + ModernNetworking.registerType(PlayerDataSynchronizer.PLAYER_DATA_SYNC_ID); //#endif // cache patreons in an extra thread to prevent longer loading times while connecting diff --git a/common/src/main/java/tocraft/craftedcore/event/client/RenderEvents.java b/common/src/main/java/tocraft/craftedcore/event/client/RenderEvents.java index abe74f89..58efa95c 100644 --- a/common/src/main/java/tocraft/craftedcore/event/client/RenderEvents.java +++ b/common/src/main/java/tocraft/craftedcore/event/client/RenderEvents.java @@ -4,10 +4,10 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; //#if MC>=1210 -//$$ import net.minecraft.client.DeltaTracker; +import net.minecraft.client.DeltaTracker; //#endif //#if MC>1194 -//$$ import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.GuiGraphics; //#endif import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.player.Player; @@ -28,11 +28,11 @@ public final class RenderEvents { @FunctionalInterface public interface HUDRendering { //#if MC>=1210 - //$$ void render(GuiGraphics graphics, DeltaTracker tickCounter); + void render(GuiGraphics graphics, DeltaTracker tickCounter); //#elseif MC>1194 //$$ void render(GuiGraphics graphics, float deltaTick); //#else - void render(PoseStack poseStack, float tickDelta); + //$$ void render(PoseStack poseStack, float tickDelta); //#endif } @@ -40,9 +40,9 @@ public interface HUDRendering { @FunctionalInterface public interface OverlayRendering { //#if MC>1194 - //$$ InteractionResult render(@Nullable GuiGraphics graphics, Player player); + InteractionResult render(@Nullable GuiGraphics graphics, Player player); //#else - InteractionResult render(@Nullable PoseStack poseStack, Player player); + //$$ InteractionResult render(@Nullable PoseStack poseStack, Player player); //#endif } } diff --git a/common/src/main/java/tocraft/craftedcore/event/common/CommandEvents.java b/common/src/main/java/tocraft/craftedcore/event/common/CommandEvents.java index 8efe819f..717ef94f 100644 --- a/common/src/main/java/tocraft/craftedcore/event/common/CommandEvents.java +++ b/common/src/main/java/tocraft/craftedcore/event/common/CommandEvents.java @@ -2,7 +2,7 @@ import com.mojang.brigadier.CommandDispatcher; //#if MC>1182 -//$$ import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandBuildContext; //#endif import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; @@ -16,9 +16,9 @@ public final class CommandEvents { @FunctionalInterface public interface CommandRegistration { //#if MC>1182 - //$$ void register(CommandDispatcher dispatcher, CommandBuildContext registry, Commands.CommandSelection selection); + void register(CommandDispatcher dispatcher, CommandBuildContext registry, Commands.CommandSelection selection); //#else - void register(CommandDispatcher dispatcher, Commands.CommandSelection selection); + //$$ void register(CommandDispatcher dispatcher, Commands.CommandSelection selection); //#endif } } diff --git a/common/src/main/java/tocraft/craftedcore/event/common/PlayerEvents.java b/common/src/main/java/tocraft/craftedcore/event/common/PlayerEvents.java index ae1c93bf..8d8960b3 100644 --- a/common/src/main/java/tocraft/craftedcore/event/common/PlayerEvents.java +++ b/common/src/main/java/tocraft/craftedcore/event/common/PlayerEvents.java @@ -1,7 +1,7 @@ package tocraft.craftedcore.event.common; //#if MC>1201 -//$$ import net.minecraft.advancements.AdvancementHolder; +import net.minecraft.advancements.AdvancementHolder; //#endif import net.minecraft.advancements.Advancement; import net.minecraft.core.BlockPos; @@ -53,18 +53,18 @@ public interface PlayerRespawn { @FunctionalInterface public interface AwardAdvancement { //#if MC>1201 - //$$ void award(ServerPlayer player, AdvancementHolder advancement, String criterionKey); + void award(ServerPlayer player, AdvancementHolder advancement, String criterionKey); //#else - void award(ServerPlayer player, Advancement advancement, String criterionKey); + //$$ void award(ServerPlayer player, Advancement advancement, String criterionKey); //#endif } @FunctionalInterface public interface RevokeAdvancement { //#if MC>1201 - //$$ void revoke(ServerPlayer player, AdvancementHolder advancement, String criterionKey); + void revoke(ServerPlayer player, AdvancementHolder advancement, String criterionKey); //#else - void revoke(ServerPlayer player, Advancement advancement, String criterionKey); + //$$ void revoke(ServerPlayer player, Advancement advancement, String criterionKey); //#endif } diff --git a/common/src/main/java/tocraft/craftedcore/gui/TimerOverlayRenderer.java b/common/src/main/java/tocraft/craftedcore/gui/TimerOverlayRenderer.java index 901499a4..2071e6bd 100644 --- a/common/src/main/java/tocraft/craftedcore/gui/TimerOverlayRenderer.java +++ b/common/src/main/java/tocraft/craftedcore/gui/TimerOverlayRenderer.java @@ -4,7 +4,7 @@ import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.Minecraft; //#if MC>1194 -//$$ import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.GuiGraphics; //#endif import net.minecraft.client.gui.screens.ChatScreen; import net.minecraft.world.item.Item; @@ -19,9 +19,9 @@ public class TimerOverlayRenderer { private static int fadingProgress = 0; //#if MC>1194 - //$$ public static void register(GuiGraphics graphics, int currentCooldown, int maxCooldown, Item item) { + public static void register(GuiGraphics graphics, int currentCooldown, int maxCooldown, Item item) { //#else - public static void register(PoseStack graphics, int currentCooldown, int maxCooldown, Item item) { + //$$ public static void register(PoseStack graphics, int currentCooldown, int maxCooldown, Item item) { //#endif Minecraft client = Minecraft.getInstance(); @@ -50,9 +50,9 @@ public static void register(PoseStack graphics, int currentCooldown, int maxCool int height = Minecraft.getInstance().getWindow().getGuiScaledHeight(); //#if MC>1194 - //$$ graphics.pose().pushPose(); + graphics.pose().pushPose(); //#else - graphics.pushPose(); + //$$ graphics.pushPose(); //#endif if (cooldownScale != 1) { RenderSystem.enableScissor( @@ -68,26 +68,26 @@ public static void register(PoseStack graphics, int currentCooldown, int maxCool float scale = 1f + (float) Math.sin(fadeScalar * 1.5 * Math.PI) - .25f; scale = Math.max(scale, 0); //#if MC>1194 - //$$ graphics.pose().scale(scale, scale, scale); + graphics.pose().scale(scale, scale, scale); //#else - graphics.scale(scale, scale, scale); + //$$ graphics.scale(scale, scale, scale); //#endif } ItemStack stack = new ItemStack(item); //#if MC>1194 - //$$ graphics.renderItem(stack, (int) (width * .95f), (int) (height * .92f)); + graphics.renderItem(stack, (int) (width * .95f), (int) (height * .92f)); //#elseif MC>1182 //$$ Minecraft.getInstance().getItemRenderer().renderGuiItem(graphics, stack, (int) (width * .95f), (int) (height * .92f)); //#else - Minecraft.getInstance().getItemRenderer().renderGuiItem(stack, (int) (width * .95f), (int) (height * .92f)); + //$$ Minecraft.getInstance().getItemRenderer().renderGuiItem(stack, (int) (width * .95f), (int) (height * .92f)); //#endif RenderSystem.disableScissor(); //#if MC>1194 - //$$ graphics.pose().popPose(); + graphics.pose().popPose(); //#else - graphics.popPose(); + //$$ graphics.popPose(); //#endif } } diff --git a/common/src/main/java/tocraft/craftedcore/mixin/PlayerAdvancementsMixin.java b/common/src/main/java/tocraft/craftedcore/mixin/PlayerAdvancementsMixin.java index 7df06fb5..c017e40d 100644 --- a/common/src/main/java/tocraft/craftedcore/mixin/PlayerAdvancementsMixin.java +++ b/common/src/main/java/tocraft/craftedcore/mixin/PlayerAdvancementsMixin.java @@ -2,7 +2,7 @@ import net.minecraft.advancements.Advancement; //#if MC>1201 -//$$ import net.minecraft.advancements.AdvancementHolder; +import net.minecraft.advancements.AdvancementHolder; //#endif import net.minecraft.server.PlayerAdvancements; import net.minecraft.server.level.ServerPlayer; @@ -20,18 +20,18 @@ public class PlayerAdvancementsMixin { @Inject(method = "award", at = @At(value = "INVOKE", target = "Lnet/minecraft/advancements/AdvancementRewards;grant(Lnet/minecraft/server/level/ServerPlayer;)V")) //#if MC>1201 - //$$ private void afterAward(AdvancementHolder advancement, String criterionKey, CallbackInfoReturnable cir) { + private void afterAward(AdvancementHolder advancement, String criterionKey, CallbackInfoReturnable cir) { //#else - private void afterAward(Advancement advancement, String criterionKey, CallbackInfoReturnable cir) { + //$$ private void afterAward(Advancement advancement, String criterionKey, CallbackInfoReturnable cir) { //#endif PlayerEvents.AWARD_ADVANCEMENT.invoke().award(this.player, advancement, criterionKey); } @Inject(method = "revoke", at = @At(value = "RETURN")) //#if MC>1201 - //$$ private void afterRevoke(AdvancementHolder advancement, String criterionKey, CallbackInfoReturnable cir) { + private void afterRevoke(AdvancementHolder advancement, String criterionKey, CallbackInfoReturnable cir) { //#else - private void afterRevoke(Advancement advancement, String criterionKey, CallbackInfoReturnable cir) { + //$$ private void afterRevoke(Advancement advancement, String criterionKey, CallbackInfoReturnable cir) { //#endif PlayerEvents.REVOKE_ADVANCEMENT.invoke().revoke(this.player, advancement, criterionKey); } diff --git a/common/src/main/java/tocraft/craftedcore/mixin/PlayerListMixin.java b/common/src/main/java/tocraft/craftedcore/mixin/PlayerListMixin.java index ed93cfa6..808714e3 100644 --- a/common/src/main/java/tocraft/craftedcore/mixin/PlayerListMixin.java +++ b/common/src/main/java/tocraft/craftedcore/mixin/PlayerListMixin.java @@ -3,7 +3,7 @@ import net.minecraft.network.Connection; import net.minecraft.server.level.ServerPlayer; //#if MC>1201 -//$$ import net.minecraft.server.network.CommonListenerCookie; +import net.minecraft.server.network.CommonListenerCookie; //#endif import net.minecraft.server.players.PlayerList; import org.spongepowered.asm.mixin.Mixin; @@ -26,9 +26,9 @@ private ServerPlayer endResourceReload(ServerPlayer player) { @Inject(method = "placeNewPlayer", at = @At("RETURN")) //#if MC>1201 - //$$ private void placeNewPlayer(Connection connection, ServerPlayer serverPlayer, CommonListenerCookie commonListenerCookie, CallbackInfo ci) { + private void placeNewPlayer(Connection connection, ServerPlayer serverPlayer, CommonListenerCookie commonListenerCookie, CallbackInfo ci) { //#else - private void placeNewPlayer(Connection connection, ServerPlayer serverPlayer, CallbackInfo ci) { + //$$ private void placeNewPlayer(Connection connection, ServerPlayer serverPlayer, CallbackInfo ci) { //#endif PlayerEvents.PLAYER_JOIN.invoke().join(serverPlayer); ResourceEvents.DATA_PACK_SYNC.invoke().onSync(serverPlayer); diff --git a/common/src/main/java/tocraft/craftedcore/mixin/client/ClientPacketListenerMixin.java b/common/src/main/java/tocraft/craftedcore/mixin/client/ClientPacketListenerMixin.java index ae31d9e9..a947b840 100644 --- a/common/src/main/java/tocraft/craftedcore/mixin/client/ClientPacketListenerMixin.java +++ b/common/src/main/java/tocraft/craftedcore/mixin/client/ClientPacketListenerMixin.java @@ -4,9 +4,9 @@ import net.fabricmc.api.Environment; import net.minecraft.client.Minecraft; //#if MC>1201 -//$$ import net.minecraft.client.multiplayer.ClientCommonPacketListenerImpl; -//$$ import net.minecraft.client.multiplayer.CommonListenerCookie; -//$$ import net.minecraft.network.Connection; +import net.minecraft.client.multiplayer.ClientCommonPacketListenerImpl; +import net.minecraft.client.multiplayer.CommonListenerCookie; +import net.minecraft.network.Connection; //#endif import net.minecraft.client.multiplayer.ClientPacketListener; import net.minecraft.client.player.LocalPlayer; @@ -25,21 +25,21 @@ @Environment(EnvType.CLIENT) @Mixin(ClientPacketListener.class) //#if MC>1201 -//$$ public abstract class ClientPacketListenerMixin extends ClientCommonPacketListenerImpl { -//$$ protected ClientPacketListenerMixin(Minecraft minecraft, Connection connection, CommonListenerCookie commonListenerCookie) { -//$$ super(minecraft, connection, commonListenerCookie); -//$$ } +public abstract class ClientPacketListenerMixin extends ClientCommonPacketListenerImpl { + protected ClientPacketListenerMixin(Minecraft minecraft, Connection connection, CommonListenerCookie commonListenerCookie) { + super(minecraft, connection, commonListenerCookie); + } //#else -public abstract class ClientPacketListenerMixin { +//$$ public abstract class ClientPacketListenerMixin { //#endif @Unique private LocalPlayer craftedcore$oldPlayer = null; //#if MC<=1201 - @Shadow - @Final - private Minecraft minecraft; + //$$ @Shadow + //$$ @Final + //$$ private Minecraft minecraft; //#endif @Inject(method = "handleLogin", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Options;setServerRenderDistance(I)V", shift = At.Shift.AFTER)) @@ -54,9 +54,9 @@ private void handleRespawnPre(ClientboundRespawnPacket packet, CallbackInfo ci) @Inject(method = "handleRespawn", at = @At(value = "INVOKE", //#if MC>1201 - //$$ target = "Lnet/minecraft/client/multiplayer/ClientLevel;addEntity(Lnet/minecraft/world/entity/Entity;)V")) + target = "Lnet/minecraft/client/multiplayer/ClientLevel;addEntity(Lnet/minecraft/world/entity/Entity;)V")) //#else - target = "Lnet/minecraft/client/multiplayer/ClientLevel;addPlayer(ILnet/minecraft/client/player/AbstractClientPlayer;)V")) + //$$ target = "Lnet/minecraft/client/multiplayer/ClientLevel;addPlayer(ILnet/minecraft/client/player/AbstractClientPlayer;)V")) //#endif private void handleRespawn(ClientboundRespawnPacket packet, CallbackInfo ci) { ClientPlayerEvents.CLIENT_PLAYER_RESPAWN.invoke().respawn(this.craftedcore$oldPlayer, minecraft.player); diff --git a/common/src/main/java/tocraft/craftedcore/mixin/client/MinecraftMixin.java b/common/src/main/java/tocraft/craftedcore/mixin/client/MinecraftMixin.java index 4eb0001d..fcea96b7 100644 --- a/common/src/main/java/tocraft/craftedcore/mixin/client/MinecraftMixin.java +++ b/common/src/main/java/tocraft/craftedcore/mixin/client/MinecraftMixin.java @@ -18,9 +18,9 @@ public abstract class MinecraftMixin { @Inject(method = "crash", at = @At("HEAD")) //#if MC>1202 - //$$ private static void onCrash(Minecraft minecraft, File gameDirectory, CrashReport report, CallbackInfo ci) { + private static void onCrash(Minecraft minecraft, File gameDirectory, CrashReport report, CallbackInfo ci) { //#else - private static void onCrash(CrashReport report, CallbackInfo ci) { + //$$ private static void onCrash(CrashReport report, CallbackInfo ci) { //#endif StringBuilder crashReportBuilder = new StringBuilder(); TraceUtils.printMixinTrace(report.getException().getStackTrace(), crashReportBuilder); diff --git a/common/src/main/java/tocraft/craftedcore/network/ModernNetworking.java b/common/src/main/java/tocraft/craftedcore/network/ModernNetworking.java index 85305bf2..fe388eee 100644 --- a/common/src/main/java/tocraft/craftedcore/network/ModernNetworking.java +++ b/common/src/main/java/tocraft/craftedcore/network/ModernNetworking.java @@ -8,15 +8,18 @@ import net.minecraft.client.multiplayer.ClientPacketListener; import net.minecraft.nbt.CompoundTag; //#if MC>=1205 -//$$ import net.minecraft.network.RegistryFriendlyByteBuf; -//$$ import net.minecraft.network.codec.StreamCodec; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.codec.StreamCodec; //#endif import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.protocol.Packet; //#if MC>1201 -//$$ import net.minecraft.network.protocol.common.custom.CustomPacketPayload; -//$$ import java.util.Map; -//$$ import java.util.HashMap; +import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket; +import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import java.util.Map; +import java.util.HashMap; +import org.jetbrains.annotations.NotNull; //#endif import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerPlayer; @@ -26,7 +29,7 @@ @SuppressWarnings("unused") public class ModernNetworking { //#if MC>=1205 - //$$ private static final Map> TYPES = new HashMap<>(); + private static final Map> TYPES = new HashMap<>(); //#endif @ExpectPlatform @@ -35,30 +38,26 @@ public static void registerReceiver(Side side, ResourceLocation id, Receiver rec } //#if MC>=1205 - //$$ @ExpectPlatform - //$$ public static void registerType(ResourceLocation id) { - //$$ throw new AssertionError(); - //$$ } - //$$ - //$$ public static CustomPacketPayload.Type getType(ResourceLocation id) { - //$$ if (!TYPES.containsKey(id)) { - //$$ TYPES.put(id, new CustomPacketPayload.Type<>(id)); - //$$ } - //$$ return TYPES.get(id); - //$$ } + @ExpectPlatform + public static void registerType(ResourceLocation id) { + throw new AssertionError(); + } + + public static CustomPacketPayload.Type getType(ResourceLocation id) { + if (!TYPES.containsKey(id)) { + TYPES.put(id, new CustomPacketPayload.Type<>(id)); + } + return TYPES.get(id); + } //#endif public static void sendToPlayer(ServerPlayer player, ResourceLocation packetId, CompoundTag data) { - //#if MC>1201 - //$$ FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer()); - //$$ buf.writeResourceLocation(packetId); - //$$ buf.writeNbt(data); - //$$ player.connection.send(toPacket(Side.S2C, packetId, buf)); + //#if MC>=1205 + player.connection.send(toPacket(Side.S2C, new PacketPayload(packetId, data))); + //#elseif MC>1201 + //$$ player.connection.send(toPacket(Side.S2C, packetId, data)); //#else - FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer()); - buf.writeResourceLocation(packetId); - buf.writeNbt(data.copy()); - player.connection.send(toPacket(Side.S2C, packetId, buf)); + //$$ player.connection.send(toPacket(Side.S2C, packetId, data)); //#endif } @@ -73,25 +72,29 @@ public static void sendToServer(ResourceLocation packetId, CompoundTag data) { ClientPacketListener connection = Minecraft.getInstance().getConnection(); if (connection != null) { - //#if MC>1201 - //$$ FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer()); - //$$ buf.writeResourceLocation(packetId); - //$$ buf.writeNbt(data); - //$$ connection.send(toPacket(Side.C2S, packetId, buf)); + //#if MC>=1205 + connection.send(toPacket(Side.C2S, new PacketPayload(packetId, data))); + //#elseif MC>1201 + //$$ connection.send(toPacket(Side.C2S, packetId, data)); //#else - FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer()); - buf.writeResourceLocation(packetId); - buf.writeNbt(data.copy()); - connection.send(toPacket(Side.C2S, packetId, buf)); + //$$ connection.send(toPacket(Side.C2S, packetId, data)); //#endif } } + //#if MC>=1205 @ExpectPlatform @ApiStatus.Internal - public static Packet toPacket(ModernNetworking.Side side, ResourceLocation id, FriendlyByteBuf buf) { + public static Packet toPacket(ModernNetworking.Side side, CustomPacketPayload payload) { throw new AssertionError(); } + //#else + //$$ @ExpectPlatform + //$$ @ApiStatus.Internal + //$$ public static Packet toPacket(ModernNetworking.Side side, ResourceLocation id, CompoundTag data) { + //$$ throw new AssertionError(); + //$$ } + //#endif @FunctionalInterface public interface Receiver { @@ -115,11 +118,11 @@ public enum Env { } //#if MC>1201 - //$$ @ApiStatus.Internal - //$$ public record PacketPayload(ResourceLocation id, - //$$ CompoundTag nbt) implements CustomPacketPayload { + @ApiStatus.Internal + public record PacketPayload(ResourceLocation id, + CompoundTag nbt) implements CustomPacketPayload { //#if MC>=1205 - //$$ public void write(RegistryFriendlyByteBuf buf) { + public void write(RegistryFriendlyByteBuf buf) { //#else //$$ public PacketPayload(FriendlyByteBuf buf) { //$$ this(buf.readResourceLocation(), buf.readNbt()); @@ -127,35 +130,35 @@ public enum Env { //$$ //$$ public void write(FriendlyByteBuf buf) { //#endif - //$$ buf.writeResourceLocation(id); - //$$ buf.writeNbt(nbt); - //$$ } - //$$ + buf.writeResourceLocation(id); + buf.writeNbt(nbt); + } + //#if MC>=1205 - //$$ - //$$ public PacketPayload(RegistryFriendlyByteBuf buf) { - //$$ this(buf.readResourceLocation(), buf.readNbt()); - //$$ } - //$$ @Override - //$$ public @NotNull Type type() { - //$$ return getType(id); - //$$ } - //$$ - //$$ public static StreamCodec streamCodec() { - //$$ return new StreamCodec<>() { - //$$ @Override - //$$ public @NotNull PacketPayload decode(@NotNull RegistryFriendlyByteBuf buf) { - //$$ return new PacketPayload(buf); - //$$ } - //$$ - //$$ @Override - //$$ public void encode(@NotNull RegistryFriendlyByteBuf buf, @NotNull PacketPayload payload) { - //$$ buf.writeResourceLocation(payload.id); - //$$ buf.writeNbt(payload.nbt); - //$$ } - //$$ }; - //$$ } + + public PacketPayload(RegistryFriendlyByteBuf buf) { + this(buf.readResourceLocation(), buf.readNbt()); + } + @Override + public @NotNull Type type() { + return getType(id); + } + + public static StreamCodec streamCodec() { + return new StreamCodec<>() { + @Override + public @NotNull PacketPayload decode(@NotNull RegistryFriendlyByteBuf buf) { + return new PacketPayload(buf); + } + + @Override + public void encode(@NotNull RegistryFriendlyByteBuf buf, @NotNull PacketPayload payload) { + buf.writeResourceLocation(payload.id); + buf.writeNbt(payload.nbt); + } + }; + } //#endif - //$$ } + } //#endif } diff --git a/common/src/main/java/tocraft/craftedcore/patched/CBlockPos.java b/common/src/main/java/tocraft/craftedcore/patched/CBlockPos.java new file mode 100644 index 00000000..ca8300c3 --- /dev/null +++ b/common/src/main/java/tocraft/craftedcore/patched/CBlockPos.java @@ -0,0 +1,17 @@ +package tocraft.craftedcore.patched; + +import net.minecraft.core.BlockPos; +import net.minecraft.world.phys.Vec3; + +@SuppressWarnings("unused") +public class CBlockPos { + //#if MC>1182 + public static BlockPos containing(Vec3 vec3) { + return BlockPos.containing(vec3); + } + //#else + //$$ public static BlockPos containing(Vec3 vec3) { + //$$ return new BlockPos(vec3); + //$$ } + //#endif +} diff --git a/common/src/main/java/tocraft/craftedcore/patched/CCommandSourceStack.java b/common/src/main/java/tocraft/craftedcore/patched/CCommandSourceStack.java new file mode 100644 index 00000000..c75792a3 --- /dev/null +++ b/common/src/main/java/tocraft/craftedcore/patched/CCommandSourceStack.java @@ -0,0 +1,15 @@ +package tocraft.craftedcore.patched; + +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.network.chat.Component; + +@SuppressWarnings("unused") +public class CCommandSourceStack { + public static void sendSuccess(CommandSourceStack source, Component text, boolean bl) { + //#if MC>=1201 + source.sendSuccess(() -> text, bl); + //#else + //$$ source.sendSuccess(text, bl); + //#endif + } +} diff --git a/common/src/main/java/tocraft/craftedcore/patched/CEntity.java b/common/src/main/java/tocraft/craftedcore/patched/CEntity.java index c05dc1ad..ab282d0a 100644 --- a/common/src/main/java/tocraft/craftedcore/patched/CEntity.java +++ b/common/src/main/java/tocraft/craftedcore/patched/CEntity.java @@ -6,17 +6,17 @@ public class CEntity { public static Level level(Entity entity) { //#if MC>1194 - //$$ return entity.level(); + return entity.level(); //#else - return entity.level; + //$$ return entity.level; //#endif } public static boolean isOnGround(Entity entity) { //#if MC>1194 - //$$ return entity.onGround(); + return entity.onGround(); //#else - return entity.isOnGround(); + //$$ return entity.isOnGround(); //#endif } } diff --git a/common/src/main/java/tocraft/craftedcore/patched/CEntitySummonArgument.java b/common/src/main/java/tocraft/craftedcore/patched/CEntitySummonArgument.java new file mode 100644 index 00000000..5c404e75 --- /dev/null +++ b/common/src/main/java/tocraft/craftedcore/patched/CEntitySummonArgument.java @@ -0,0 +1,38 @@ +package tocraft.craftedcore.patched; + +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.commands.CommandSourceStack; + +//#if MC>1182 +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.arguments.ResourceArgument; +import net.minecraft.world.entity.EntityType; +import net.minecraft.core.Registry; +//#else +//$$ import net.minecraft.commands.arguments.EntitySummonArgument; +//$$ import org.jetbrains.annotations.Nullable; +//#endif + +@SuppressWarnings("unused") +public class CEntitySummonArgument { + //#if MC>1182 + public static ResourceArgument> id(CommandBuildContext ctx) { + //noinspection unchecked + return ResourceArgument.resource(ctx, (((Registry>) CRegistries.getRegistry(Identifier.parse("entity_type"))).key())); + } + + public static ResourceLocation getEntityTypeId(CommandContext context, String string) throws CommandSyntaxException { + return EntityType.getKey(ResourceArgument.getSummonableEntityType(context, string).value()); + } + //#else + //$$ public static EntitySummonArgument id(@SuppressWarnings("unused") @Nullable Object somethingNull) { + //$$ return EntitySummonArgument.id(); + //$$ } + //$$ + //$$ public static ResourceLocation getEntityTypeId(CommandContext context, String string) throws CommandSyntaxException { + //$$ return EntitySummonArgument.getSummonableEntity(context, string); + //$$ } + //#endif +} diff --git a/common/src/main/java/tocraft/craftedcore/patched/CRegistries.java b/common/src/main/java/tocraft/craftedcore/patched/CRegistries.java index 4cee0d0c..cfe50bc2 100644 --- a/common/src/main/java/tocraft/craftedcore/patched/CRegistries.java +++ b/common/src/main/java/tocraft/craftedcore/patched/CRegistries.java @@ -3,18 +3,18 @@ import net.minecraft.core.Registry; import net.minecraft.resources.ResourceLocation; //#if MC>1182 -//$$ import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.core.registries.BuiltInRegistries; //#endif @SuppressWarnings({"unused", "unchecked"}) public class CRegistries { //#if MC>1182 - //$$ public static Registry getRegistry(ResourceLocation id) { - //$$ return (Registry) BuiltInRegistries.REGISTRY.get(id); - //$$ } - //#else public static Registry getRegistry(ResourceLocation id) { - return Registry.REGISTRY.get(id); + return BuiltInRegistries.REGISTRY.get(id); } + //#else + //$$ public static Registry getRegistry(ResourceLocation id) { + //$$ return Registry.REGISTRY.get(id); + //$$ } //#endif } diff --git a/common/src/main/java/tocraft/craftedcore/patched/Identifier.java b/common/src/main/java/tocraft/craftedcore/patched/Identifier.java index 604b31ab..31e3694b 100644 --- a/common/src/main/java/tocraft/craftedcore/patched/Identifier.java +++ b/common/src/main/java/tocraft/craftedcore/patched/Identifier.java @@ -5,17 +5,17 @@ public class Identifier { public static ResourceLocation parse(String namespace, String path) { //#if MC>=1210 - //$$ return ResourceLocation.fromNamespaceAndPath(namespace, path); + return ResourceLocation.fromNamespaceAndPath(namespace, path); //#else - return new ResourceLocation(namespace, path); + //$$ return new ResourceLocation(namespace, path); //#endif } public static ResourceLocation parse(String key) { //#if MC>=1210 - //$$ return ResourceLocation.parse(key); + return ResourceLocation.parse(key); //#else - return new ResourceLocation(key); + //$$ return new ResourceLocation(key); //#endif } } diff --git a/common/src/main/java/tocraft/craftedcore/patched/TComponent.java b/common/src/main/java/tocraft/craftedcore/patched/TComponent.java index 4eef6d47..a5c94acb 100644 --- a/common/src/main/java/tocraft/craftedcore/patched/TComponent.java +++ b/common/src/main/java/tocraft/craftedcore/patched/TComponent.java @@ -2,26 +2,26 @@ import net.minecraft.network.chat.MutableComponent; //#if MC>1182 -//$$ import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.Component; //#else -import net.minecraft.network.chat.TextComponent; -import net.minecraft.network.chat.TranslatableComponent; +//$$ import net.minecraft.network.chat.TextComponent; +//$$ import net.minecraft.network.chat.TranslatableComponent; //#endif public class TComponent { public static MutableComponent literal(String text) { //#if MC>1182 - //$$ return Component.literal(text); + return Component.literal(text); //#else - return new TextComponent(text); + //$$ return new TextComponent(text); //#endif } public static MutableComponent translatable(String text, Object... objects) { //#if MC>1182 - //$$ return Component.translatable(text, objects); + return Component.translatable(text, objects); //#else - return new TranslatableComponent(text, objects); + //$$ return new TranslatableComponent(text, objects); //#endif } } diff --git a/common/src/main/java/tocraft/craftedcore/patched/client/CGraphics.java b/common/src/main/java/tocraft/craftedcore/patched/client/CGraphics.java index bab3f6e6..5736c802 100644 --- a/common/src/main/java/tocraft/craftedcore/patched/client/CGraphics.java +++ b/common/src/main/java/tocraft/craftedcore/patched/client/CGraphics.java @@ -3,18 +3,19 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.resources.ResourceLocation; + //#if MC>1194 -//$$ import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.GuiGraphics; //#else -import com.mojang.blaze3d.systems.RenderSystem; -import net.minecraft.client.gui.GuiComponent; -import net.minecraft.client.renderer.GameRenderer; -import net.minecraft.util.FastColor; -import com.mojang.blaze3d.vertex.*; +//$$ import com.mojang.blaze3d.systems.RenderSystem; +//$$ import net.minecraft.client.gui.GuiComponent; +//$$ import net.minecraft.client.renderer.GameRenderer; +//$$ import net.minecraft.util.FastColor; +//$$ import com.mojang.blaze3d.vertex.*; //#if MC>1182 //$$ import org.joml.Matrix4f; //#else -import com.mojang.math.Matrix4f; +//$$ import com.mojang.math.Matrix4f; //#endif //#endif @@ -22,57 +23,57 @@ @Environment(EnvType.CLIENT) public class CGraphics { //#if MC>1194 - //$$ public static void blit(GuiGraphics graphics, ResourceLocation texture, int i, int j, int k, int l, float f, float g, int m, int n, int o, int p) { - //$$ graphics.blit(texture, i, j, k, l, m, n, o, p); - //$$ } - //$$ - //$$ public static void fillTransparent(GuiGraphics graphics, int x1, int y1, int x2, int y2) { - //$$ fillGradient(graphics, x1, y2, x2, y2, -1072689136, -804253680); - //$$ } - //$$ - //$$ public static void fillGradient(GuiGraphics graphics, int x1, int y1, int x2, int y2, int colorFrom, int colorTo) { - //$$ graphics.fillGradient(x1, y1, x2, y2, colorFrom, colorTo); - //$$ } - //$$ - //#else - public static void blit(PoseStack graphics, ResourceLocation texture, int i, int j, int k, int l, float f, float g, int m, int n, int o, int p) { - RenderSystem.setShaderTexture(0, texture); - GuiComponent.blit(graphics, i, j, k, l, m, n, o, p); + public static void blit(GuiGraphics graphics, ResourceLocation texture, int i, int j, int k, int l, float f, float g, int m, int n, int o, int p) { + graphics.blit(texture, i, j, k, l, f, g, m, n, o, p); } - public static void fillTransparent(PoseStack graphics, int x1, int y1, int x2, int y2) { - fillGradient(graphics, x1, y2, x2, y2, -1072689136, -804253680); + public static void fillTransparent(GuiGraphics graphics, int x1, int y1, int x2, int y2) { + fillGradient(graphics, x1, y1, x2, y2, -1072689136, -804253680); } - public static void fillGradient(PoseStack poseStack, int x1, int y1, int x2, int y2, int colorFrom, int colorTo) { - fillGradient(poseStack, x1, y1, x2, y2, colorFrom, colorTo, 0); + public static void fillGradient(GuiGraphics graphics, int x1, int y1, int x2, int y2, int colorFrom, int colorTo) { + graphics.fillGradient(x1, y1, x2, y2, colorFrom, colorTo); } - @SuppressWarnings("SameParameterValue") - private static void fillGradient(PoseStack poseStack, int x1, int y1, int x2, int y2, int colorFrom, int colorTo, int blitOffset) { - RenderSystem.enableBlend(); - RenderSystem.setShader(GameRenderer::getPositionColorShader); - Tesselator tesselator = Tesselator.getInstance(); - BufferBuilder bufferBuilder = tesselator.getBuilder(); - bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); - fillGradient(poseStack.last().pose(), bufferBuilder, x1, y1, x2, y2, blitOffset, colorFrom, colorTo); - tesselator.end(); - RenderSystem.disableBlend(); - } - - private static void fillGradient(Matrix4f matrix, BufferBuilder builder, int x1, int y1, int x2, int y2, int blitOffset, int colorA, int colorB) { - float f = (float) FastColor.ARGB32.alpha(colorA) / 255.0F; - float g = (float) FastColor.ARGB32.red(colorA) / 255.0F; - float h = (float) FastColor.ARGB32.green(colorA) / 255.0F; - float i = (float) FastColor.ARGB32.blue(colorA) / 255.0F; - float j = (float) FastColor.ARGB32.alpha(colorB) / 255.0F; - float k = (float) FastColor.ARGB32.red(colorB) / 255.0F; - float l = (float) FastColor.ARGB32.green(colorB) / 255.0F; - float m = (float) FastColor.ARGB32.blue(colorB) / 255.0F; - builder.vertex(matrix, (float) x1, (float) y1, (float) blitOffset).color(g, h, i, f).endVertex(); - builder.vertex(matrix, (float) x1, (float) y2, (float) blitOffset).color(k, l, m, j).endVertex(); - builder.vertex(matrix, (float) x2, (float) y2, (float) blitOffset).color(k, l, m, j).endVertex(); - builder.vertex(matrix, (float) x2, (float) y1, (float) blitOffset).color(g, h, i, f).endVertex(); - } + //#else + //$$ public static void blit(PoseStack graphics, ResourceLocation texture, int i, int j, int k, int l, float f, float g, int m, int n, int o, int p) { + //$$ RenderSystem.setShaderTexture(0, texture); + //$$ GuiComponent.blit(graphics, i, j, k, l, f, g, m, n, o, p); + //$$ } + //$$ + //$$ public static void fillTransparent(PoseStack graphics, int x1, int y1, int x2, int y2) { + //$$ fillGradient(graphics, x1, y1, x2, y2, -1072689136, -804253680); + //$$ } + //$$ + //$$ public static void fillGradient(PoseStack poseStack, int x1, int y1, int x2, int y2, int colorFrom, int colorTo) { + //$$ fillGradient(poseStack, x1, y1, x2, y2, colorFrom, colorTo, 0); + //$$ } + //$$ + //$$ @SuppressWarnings("SameParameterValue") + //$$ private static void fillGradient(PoseStack poseStack, int x1, int y1, int x2, int y2, int colorFrom, int colorTo, int blitOffset) { + //$$ RenderSystem.enableBlend(); + //$$ RenderSystem.setShader(GameRenderer::getPositionColorShader); + //$$ Tesselator tesselator = Tesselator.getInstance(); + //$$ BufferBuilder bufferBuilder = tesselator.getBuilder(); + //$$ bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); + //$$ fillGradient(poseStack.last().pose(), bufferBuilder, x1, y1, x2, y2, blitOffset, colorFrom, colorTo); + //$$ tesselator.end(); + //$$ RenderSystem.disableBlend(); + //$$ } + //$$ + //$$ private static void fillGradient(Matrix4f matrix, BufferBuilder builder, int x1, int y1, int x2, int y2, int blitOffset, int colorA, int colorB) { + //$$ float f = (float) FastColor.ARGB32.alpha(colorA) / 255.0F; + //$$ float g = (float) FastColor.ARGB32.red(colorA) / 255.0F; + //$$ float h = (float) FastColor.ARGB32.green(colorA) / 255.0F; + //$$ float i = (float) FastColor.ARGB32.blue(colorA) / 255.0F; + //$$ float j = (float) FastColor.ARGB32.alpha(colorB) / 255.0F; + //$$ float k = (float) FastColor.ARGB32.red(colorB) / 255.0F; + //$$ float l = (float) FastColor.ARGB32.green(colorB) / 255.0F; + //$$ float m = (float) FastColor.ARGB32.blue(colorB) / 255.0F; + //$$ builder.vertex(matrix, (float) x1, (float) y1, (float) blitOffset).color(g, h, i, f).endVertex(); + //$$ builder.vertex(matrix, (float) x1, (float) y2, (float) blitOffset).color(k, l, m, j).endVertex(); + //$$ builder.vertex(matrix, (float) x2, (float) y2, (float) blitOffset).color(k, l, m, j).endVertex(); + //$$ builder.vertex(matrix, (float) x2, (float) y1, (float) blitOffset).color(g, h, i, f).endVertex(); + //$$ } //#endif } diff --git a/common/src/main/java/tocraft/craftedcore/patched/client/CMinecraft.java b/common/src/main/java/tocraft/craftedcore/patched/client/CMinecraft.java index e4d373b4..974ddc76 100644 --- a/common/src/main/java/tocraft/craftedcore/patched/client/CMinecraft.java +++ b/common/src/main/java/tocraft/craftedcore/patched/client/CMinecraft.java @@ -5,7 +5,7 @@ import net.minecraft.client.Minecraft; //#if MC<=1182 -import com.mojang.util.UUIDTypeAdapter; +//$$ import com.mojang.util.UUIDTypeAdapter; //#endif import java.util.UUID; @@ -15,9 +15,9 @@ public class CMinecraft { public static UUID getLocalPlayerUUID() { //#if MC>1182 - //$$ return Minecraft.getInstance().getUser().getProfileId(); + return Minecraft.getInstance().getUser().getProfileId(); //#else - return UUIDTypeAdapter.fromString(Minecraft.getInstance().getUser().getUuid()); + //$$ return UUIDTypeAdapter.fromString(Minecraft.getInstance().getUser().getUuid()); //#endif } diff --git a/common/src/main/java/tocraft/craftedcore/platform/VersionChecker.java b/common/src/main/java/tocraft/craftedcore/platform/VersionChecker.java index 56bddda4..681bd95c 100644 --- a/common/src/main/java/tocraft/craftedcore/platform/VersionChecker.java +++ b/common/src/main/java/tocraft/craftedcore/platform/VersionChecker.java @@ -42,11 +42,11 @@ public class VersionChecker { private static void sendUpdateMessage(Player player, Component modName, Version newestVersion) { CraftedCore.LOGGER.warn(TComponent.translatable("craftedcore.update", modName.getString(), newestVersion).getString()); //#if MC>1202 - //$$ player.sendSystemMessage(TComponent.literal(Component.translatable("craftedcore.update", modName, newestVersion).getString()).withColor(new Color(255, 255, 0).getRGB())); + player.sendSystemMessage(TComponent.literal(Component.translatable("craftedcore.update", modName, newestVersion).getString()).withColor(new Color(255, 255, 0).getRGB())); //#elseif MC>1182 //$$ player.sendSystemMessage(TComponent.literal(TComponent.translatable("craftedcore.update", modName, newestVersion.toString()).getString()).withStyle(Style.EMPTY.withColor(new Color(255, 255, 0).getRGB()))); //#else - player.displayClientMessage(TComponent.literal(TComponent.translatable("craftedcore.update", modName, newestVersion.toString()).getString()).withStyle(Style.EMPTY.withColor(new Color(255, 255, 0).getRGB())), false); + //$$ player.displayClientMessage(TComponent.literal(TComponent.translatable("craftedcore.update", modName, newestVersion.toString()).getString()).withStyle(Style.EMPTY.withColor(new Color(255, 255, 0).getRGB())), false); //#endif } diff --git a/common/src/main/java/tocraft/craftedcore/registration/SynchronizedReloadListenerRegistry.java b/common/src/main/java/tocraft/craftedcore/registration/SynchronizedReloadListenerRegistry.java index 6a31ab31..98180fa9 100644 --- a/common/src/main/java/tocraft/craftedcore/registration/SynchronizedReloadListenerRegistry.java +++ b/common/src/main/java/tocraft/craftedcore/registration/SynchronizedReloadListenerRegistry.java @@ -33,8 +33,8 @@ public static void register(SynchronizedJsonReloadListener reloadListener, Resou //#if MC>=1205 - //$$ // register Network packet - //$$ ModernNetworking.registerType(reloadListener.RELOAD_SYNC); + // register Network packet + ModernNetworking.registerType(reloadListener.RELOAD_SYNC); //#endif onRegister(reloadListener, id); diff --git a/common/src/main/java/tocraft/craftedcore/util/Maths.java b/common/src/main/java/tocraft/craftedcore/util/Maths.java index 0bd19d1f..24921aeb 100644 --- a/common/src/main/java/tocraft/craftedcore/util/Maths.java +++ b/common/src/main/java/tocraft/craftedcore/util/Maths.java @@ -1,11 +1,11 @@ package tocraft.craftedcore.util; //#if MC>1182 -//$$ import org.joml.Quaternionf; -//$$ import org.joml.Vector3f; +import org.joml.Quaternionf; +import org.joml.Vector3f; //#else -import com.mojang.math.Quaternion; -import com.mojang.math.Vector3f; +//$$ import com.mojang.math.Quaternion; +//$$ import com.mojang.math.Vector3f; //#endif @SuppressWarnings("unused") @@ -23,12 +23,12 @@ public static Vector3f POSITIVE_Z() { } //#if MC>1182 - //$$ public static Quaternionf getDegreesQuaternion(Vector3f axis, float angle) { - //$$ return new Quaternionf().fromAxisAngleDeg(axis, angle); - //$$ } - //#else - public static Quaternion getDegreesQuaternion(Vector3f axis, float angle) { - return axis.rotation(angle); + public static Quaternionf getDegreesQuaternion(Vector3f axis, float angle) { + return new Quaternionf().fromAxisAngleDeg(axis, angle); } + //#else + //$$ public static Quaternion getDegreesQuaternion(Vector3f axis, float angle) { + //$$ return axis.rotation(angle); + //$$ } //#endif } diff --git a/fabric/src/main/java/tocraft/craftedcore/fabric/CraftedCoreFabricEventHandler.java b/fabric/src/main/java/tocraft/craftedcore/fabric/CraftedCoreFabricEventHandler.java index af12c6b3..9b497e87 100644 --- a/fabric/src/main/java/tocraft/craftedcore/fabric/CraftedCoreFabricEventHandler.java +++ b/fabric/src/main/java/tocraft/craftedcore/fabric/CraftedCoreFabricEventHandler.java @@ -1,10 +1,10 @@ package tocraft.craftedcore.fabric; //#if MC>1182 -//$$ import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; +import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; //#else -import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback; -import net.minecraft.commands.Commands; +//$$ import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback; +//$$ import net.minecraft.commands.Commands; //#endif import net.fabricmc.fabric.api.entity.event.v1.EntitySleepEvents; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerWorldEvents; @@ -17,9 +17,9 @@ public class CraftedCoreFabricEventHandler { public static void initialize() { EntitySleepEvents.ALLOW_SLEEP_TIME.register((player, sleepingPos, vanillaResult) -> PlayerEvents.ALLOW_SLEEP_TIME.invoke().allowSleepTime(player, sleepingPos, vanillaResult)); //#if MC>1182 - //$$ CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> CommandEvents.REGISTRATION.invoke().register(dispatcher, registryAccess, environment)); + CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> CommandEvents.REGISTRATION.invoke().register(dispatcher, registryAccess, environment)); //#else - CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> CommandEvents.REGISTRATION.invoke().register(dispatcher, dedicated ? Commands.CommandSelection.DEDICATED : Commands.CommandSelection.INTEGRATED)); + //$$ CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> CommandEvents.REGISTRATION.invoke().register(dispatcher, dedicated ? Commands.CommandSelection.DEDICATED : Commands.CommandSelection.INTEGRATED)); //#endif ServerWorldEvents.LOAD.register((server, world) -> ServerLevelEvents.LEVEL_LOAD.invoke().call(world)); ServerWorldEvents.UNLOAD.register((server, world) -> ServerLevelEvents.LEVEL_UNLOAD.invoke().call(world)); diff --git a/fabric/src/main/java/tocraft/craftedcore/fabric/mixin/client/GuiMixin.java b/fabric/src/main/java/tocraft/craftedcore/fabric/mixin/client/GuiMixin.java index 1a02a991..71ad9555 100644 --- a/fabric/src/main/java/tocraft/craftedcore/fabric/mixin/client/GuiMixin.java +++ b/fabric/src/main/java/tocraft/craftedcore/fabric/mixin/client/GuiMixin.java @@ -7,9 +7,9 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; //#if MC>1194 -//$$ import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.GuiGraphics; //#else - +//$$ //#endif import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.player.Player; @@ -30,9 +30,9 @@ public abstract class GuiMixin { @Inject(method = "renderPlayerHealth", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;isEyeInFluid(Lnet/minecraft/tags/TagKey;)Z"), cancellable = true) //#if MC>1194 - //$$ private void shouldRenderBreath(GuiGraphics guiGraphics, CallbackInfo ci) { + private void shouldRenderBreath(GuiGraphics guiGraphics, CallbackInfo ci) { //#else - private void shouldRenderBreath(PoseStack guiGraphics, CallbackInfo ci) { + //$$ private void shouldRenderBreath(PoseStack guiGraphics, CallbackInfo ci) { //#endif InteractionResult result = RenderEvents.RENDER_BREATH.invoke().render(guiGraphics, this.getCameraPlayer()); if (result == InteractionResult.FAIL) { @@ -42,9 +42,9 @@ private void shouldRenderBreath(PoseStack guiGraphics, CallbackInfo ci) { @Inject(method = "renderHearts", at = @At(value = "HEAD"), cancellable = true) //#if MC>1194 - //$$ private void shouldRenderHealth(GuiGraphics guiGraphics, Player player, int x, int y, int height, int offsetHeartIndex, float maxHealth, int currentHealth, int displayHealth, int absorptionAmount, boolean renderHighlight, CallbackInfo ci) { + private void shouldRenderHealth(GuiGraphics guiGraphics, Player player, int x, int y, int height, int offsetHeartIndex, float maxHealth, int currentHealth, int displayHealth, int absorptionAmount, boolean renderHighlight, CallbackInfo ci) { //#else - private void shouldRenderHealth(PoseStack guiGraphics, Player player, int x, int y, int height, int offsetHeartIndex, float maxHealth, int currentHealth, int displayHealth, int absorptionAmount, boolean renderHighlight, CallbackInfo ci) { + //$$ private void shouldRenderHealth(PoseStack guiGraphics, Player player, int x, int y, int height, int offsetHeartIndex, float maxHealth, int currentHealth, int displayHealth, int absorptionAmount, boolean renderHighlight, CallbackInfo ci) { //#endif InteractionResult result = RenderEvents.RENDER_HEALTH.invoke().render(guiGraphics, player); if (result == InteractionResult.FAIL) { @@ -53,29 +53,29 @@ private void shouldRenderHealth(PoseStack guiGraphics, Player player, int x, int } //#if MC>=1205 - //$$ @Inject(method = "renderFood", at = @At(value = "HEAD"), cancellable = true) - //$$ private void shouldRenderFood(GuiGraphics guiGraphics, Player player, int y, int x, CallbackInfo ci) { - //$$ InteractionResult result = RenderEvents.RENDER_FOOD.invoke().render(guiGraphics, player); - //$$ if (result == InteractionResult.FAIL) { - //$$ ci.cancel(); - //$$ } - //$$ } - //#else - @ModifyExpressionValue(method = "renderPlayerHealth", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/Gui;getVehicleMaxHearts(Lnet/minecraft/world/entity/LivingEntity;)I")) - private int shouldRenderFood(int health) { - InteractionResult result = RenderEvents.RENDER_FOOD.invoke().render(null, Minecraft.getInstance().player); + @Inject(method = "renderFood", at = @At(value = "HEAD"), cancellable = true) + private void shouldRenderFood(GuiGraphics guiGraphics, Player player, int y, int x, CallbackInfo ci) { + InteractionResult result = RenderEvents.RENDER_FOOD.invoke().render(guiGraphics, player); if (result == InteractionResult.FAIL) { - return -1; + ci.cancel(); } - return health; } + //#else + //$$ @ModifyExpressionValue(method = "renderPlayerHealth", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/Gui;getVehicleMaxHearts(Lnet/minecraft/world/entity/LivingEntity;)I")) + //$$ private int shouldRenderFood(int health) { + //$$ InteractionResult result = RenderEvents.RENDER_FOOD.invoke().render(null, Minecraft.getInstance().player); + //$$ if (result == InteractionResult.FAIL) { + //$$ return -1; + //$$ } + //$$ return health; + //$$ } //#endif @Inject(method = "renderVehicleHealth", at = @At(value = "HEAD"), cancellable = true) //#if MC>1194 - //$$ private void shouldRenderMountHealth(GuiGraphics guiGraphics, CallbackInfo ci) { + private void shouldRenderMountHealth(GuiGraphics guiGraphics, CallbackInfo ci) { //#else - private void shouldRenderMountHealth(PoseStack guiGraphics, CallbackInfo ci) { + //$$ private void shouldRenderMountHealth(PoseStack guiGraphics, CallbackInfo ci) { //#endif InteractionResult result = RenderEvents.RENDER_MOUNT_HEALTH.invoke().render(guiGraphics, this.getCameraPlayer()); if (result == InteractionResult.FAIL) { diff --git a/fabric/src/main/java/tocraft/craftedcore/fabric/mixin/client/MinecraftClientMixin.java b/fabric/src/main/java/tocraft/craftedcore/fabric/mixin/client/MinecraftClientMixin.java index c4b9bacf..203d857e 100644 --- a/fabric/src/main/java/tocraft/craftedcore/fabric/mixin/client/MinecraftClientMixin.java +++ b/fabric/src/main/java/tocraft/craftedcore/fabric/mixin/client/MinecraftClientMixin.java @@ -15,9 +15,9 @@ @Mixin(Minecraft.class) public abstract class MinecraftClientMixin { //#if MC>=1205 - //$$ @Inject(method = "disconnect(Lnet/minecraft/client/gui/screens/Screen;Z)V", - //$$ at = @At(value = "INVOKE", target = "Lnet/minecraft/client/GameNarrator;clear()V")) - //$$ private void onDisconnect(Screen screen, boolean retainDownloadedPacks, CallbackInfo ci) { + @Inject(method = "disconnect(Lnet/minecraft/client/gui/screens/Screen;Z)V", + at = @At(value = "INVOKE", target = "Lnet/minecraft/client/GameNarrator;clear()V")) + private void onDisconnect(Screen screen, boolean retainDownloadedPacks, CallbackInfo ci) { //#elseif MC>1201 //$$ @Inject(method = "disconnect(Lnet/minecraft/client/gui/screens/Screen;)V", //$$ at = @At(value = "INVOKE", target = "Lnet/minecraft/client/GameNarrator;clear()V")) @@ -27,9 +27,9 @@ public abstract class MinecraftClientMixin { //$$ at = @At(value = "INVOKE", target = "Lnet/minecraft/client/GameNarrator;clear()V")) //$$ private void onDisconnect(Screen nextScreen, CallbackInfo ci) { //#else - @Inject(method = "clearLevel(Lnet/minecraft/client/gui/screens/Screen;)V", - at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/chat/NarratorChatListener;clear()V")) - private void onDisconnect(Screen nextScreen, CallbackInfo ci) { + //$$ @Inject(method = "clearLevel(Lnet/minecraft/client/gui/screens/Screen;)V", + //$$ at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/chat/NarratorChatListener;clear()V")) + //$$ private void onDisconnect(Screen nextScreen, CallbackInfo ci) { //#endif ClientPlayerEvents.CLIENT_PLAYER_QUIT.invoke().quit(Minecraft.getInstance().player); } diff --git a/fabric/src/main/java/tocraft/craftedcore/network/fabric/ModernNetworkingImpl.java b/fabric/src/main/java/tocraft/craftedcore/network/fabric/ModernNetworkingImpl.java index 0ad92fcb..941838c3 100644 --- a/fabric/src/main/java/tocraft/craftedcore/network/fabric/ModernNetworkingImpl.java +++ b/fabric/src/main/java/tocraft/craftedcore/network/fabric/ModernNetworkingImpl.java @@ -1,166 +1,170 @@ package tocraft.craftedcore.network.fabric; //#if MC>=1205 +import net.fabricmc.api.EnvType; +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; +import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry; +import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; +import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.protocol.Packet; +import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket; +import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.player.Player; +import org.jetbrains.annotations.ApiStatus; +import tocraft.craftedcore.network.ModernNetworking; +import tocraft.craftedcore.network.ModernNetworking.PacketPayload; + +import static tocraft.craftedcore.network.ModernNetworking.getType; + +@SuppressWarnings({"unused", "resource"}) +public class ModernNetworkingImpl { + public static void registerReceiver(ModernNetworking.Side side, ResourceLocation id, ModernNetworking.Receiver receiver) { + if (side == ModernNetworking.Side.C2S) { + PayloadTypeRegistry.playC2S().register(getType(id), PacketPayload.streamCodec()); + ServerPlayNetworking.registerGlobalReceiver(getType(id), (payload, context) -> receiver.receive(new ModernNetworking.Context() { + @Override + public Player getPlayer() { + return context.player(); + } + + @Override + public ModernNetworking.Env getEnv() { + return ModernNetworking.Env.SERVER; + } + + @Override + public void queue(Runnable runnable) { + context.player().server.execute(runnable); + } + }, payload.nbt())); + } else if (side == ModernNetworking.Side.S2C) { + PayloadTypeRegistry.playS2C().register(getType(id), PacketPayload.streamCodec()); + ClientPlayNetworking.registerGlobalReceiver(getType(id), (payload, context) -> receiver.receive(new ModernNetworking.Context() { + @Override + public Player getPlayer() { + return context.player(); + } + + @Override + public ModernNetworking.Env getEnv() { + return ModernNetworking.Env.CLIENT; + } + + @Override + public void queue(Runnable runnable) { + context.client().execute(runnable); + } + }, payload.nbt())); + } + } + + public static void registerType(ResourceLocation id) { + if (FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER) { + ModernNetworking.getType(id); + PayloadTypeRegistry.playS2C().register(getType(id), PacketPayload.streamCodec()); + } + } + + @ApiStatus.Internal + public static Packet toPacket(ModernNetworking.Side side, CustomPacketPayload payload) { + if (side == ModernNetworking.Side.C2S) { + return new ServerboundCustomPayloadPacket(payload); + } else { + return new ClientboundCustomPayloadPacket(payload); + } + } +} +//#else +//$$ +//$$ import io.netty.buffer.Unpooled; //$$ import net.fabricmc.api.EnvType; +//$$ import net.fabricmc.api.Environment; //$$ import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; -//$$ import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry; //$$ import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; -//$$ import net.fabricmc.loader.api.FabricLoader; //$$ import net.minecraft.nbt.CompoundTag; //$$ import net.minecraft.network.FriendlyByteBuf; //$$ import net.minecraft.network.protocol.Packet; +//#if MC>1201 //$$ import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket; //$$ import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket; -//$$ import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +//#else +//$$ import net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket; +//$$ import net.minecraft.network.protocol.game.ServerboundCustomPayloadPacket; +//$$ import net.minecraft.network.FriendlyByteBuf; +//#endif //$$ import net.minecraft.resources.ResourceLocation; //$$ import net.minecraft.world.entity.player.Player; //$$ import org.jetbrains.annotations.ApiStatus; //$$ import tocraft.craftedcore.network.ModernNetworking; -//$$ import tocraft.craftedcore.network.ModernNetworking.PacketPayload; -//$$ -//$$ import static tocraft.craftedcore.network.ModernNetworking.getType; //$$ //$$ @SuppressWarnings({"unused", "resource"}) //$$ public class ModernNetworkingImpl { //$$ public static void registerReceiver(ModernNetworking.Side side, ResourceLocation id, ModernNetworking.Receiver receiver) { //$$ if (side == ModernNetworking.Side.C2S) { -//$$ PayloadTypeRegistry.playC2S().register(getType(id), PacketPayload.streamCodec()); -//$$ ServerPlayNetworking.registerGlobalReceiver(getType(id), (payload, context) -> receiver.receive(new ModernNetworking.Context() { -//$$ @Override -//$$ public Player getPlayer() { -//$$ return context.player(); -//$$ } +//$$ ServerPlayNetworking.registerGlobalReceiver(id, (server, player, handler, buf, responseSender) -> { +//$$ CompoundTag data = buf.readNbt(); +//$$ receiver.receive(new ModernNetworking.Context() { +//$$ @Override +//$$ public Player getPlayer() { +//$$ return player; +//$$ } //$$ -//$$ @Override -//$$ public ModernNetworking.Env getEnv() { -//$$ return ModernNetworking.Env.SERVER; -//$$ } +//$$ @Override +//$$ public ModernNetworking.Env getEnv() { +//$$ return ModernNetworking.Env.SERVER; +//$$ } //$$ -//$$ @Override -//$$ public void queue(Runnable runnable) { -//$$ context.player().server.execute(runnable); -//$$ } -//$$ }, payload.nbt())); +//$$ @Override +//$$ public void queue(Runnable runnable) { +//$$ server.execute(runnable); +//$$ } +//$$ }, data); +//$$ }); //$$ } else if (side == ModernNetworking.Side.S2C) { -//$$ PayloadTypeRegistry.playS2C().register(getType(id), PacketPayload.streamCodec()); -//$$ ClientPlayNetworking.registerGlobalReceiver(getType(id), (payload, context) -> receiver.receive(new ModernNetworking.Context() { -//$$ @Override -//$$ public Player getPlayer() { -//$$ return context.player(); -//$$ } +//$$ ClientPlayNetworking.registerGlobalReceiver(id, (client, handler, buf, responseSender) -> { +//$$ CompoundTag data = buf.readNbt(); +//$$ receiver.receive(new ModernNetworking.Context() { +//$$ @Override +//$$ public Player getPlayer() { +//$$ return client.player; +//$$ } //$$ -//$$ @Override -//$$ public ModernNetworking.Env getEnv() { -//$$ return ModernNetworking.Env.CLIENT; -//$$ } +//$$ @Override +//$$ public ModernNetworking.Env getEnv() { +//$$ return ModernNetworking.Env.CLIENT; +//$$ } //$$ -//$$ @Override -//$$ public void queue(Runnable runnable) { -//$$ context.client().execute(runnable); -//$$ } -//$$ }, payload.nbt())); +//$$ @Override +//$$ public void queue(Runnable runnable) { +//$$ client.execute(runnable); +//$$ } +//$$ }, data); +//$$ }); //$$ } //$$ } //$$ -//$$ public static void registerType(ResourceLocation id) { -//$$ if (FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER) { -//$$ ModernNetworking.getType(id); -//$$ PayloadTypeRegistry.playS2C().register(getType(id), PacketPayload.streamCodec()); -//$$ } +//$$ @ApiStatus.Internal +//$$ public static Packet toPacket(ModernNetworking.Side side, ResourceLocation id, CompoundTag data) { +//$$ FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer()); +//$$ buf.writeResourceLocation(id); +//$$ buf.writeNbt(data); +//$$ return switch (side) { +//$$ case C2S -> toC2SPacket(id, buf); +//$$ case S2C -> toS2CPacket(id, buf); +//$$ }; //$$ } //$$ -//$$ @ApiStatus.Internal -//$$ public static Packet toPacket(ModernNetworking.Side side, CustomPacketPayload payload) { -//$$ if (side == ModernNetworking.Side.C2S) { -//$$ return new ServerboundCustomPayloadPacket(payload); -//$$ } else { -//$$ return new ClientboundCustomPayloadPacket(payload); -//$$ } +//$$ @Environment(EnvType.CLIENT) +//$$ private static Packet toC2SPacket(ResourceLocation id, FriendlyByteBuf buf) { +//$$ return new ServerboundCustomPayloadPacket(buf); +//$$ } +//$$ +//$$ private static Packet toS2CPacket(ResourceLocation id, FriendlyByteBuf buf) { +//$$ return new ClientboundCustomPayloadPacket(buf); //$$ } //$$ } -//#else - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; -import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.network.protocol.Packet; -//#if MC>1201 -//$$ import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket; -//$$ import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket; -//#else -import net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket; -import net.minecraft.network.protocol.game.ServerboundCustomPayloadPacket; -import net.minecraft.network.FriendlyByteBuf; -//#endif -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.entity.player.Player; -import org.jetbrains.annotations.ApiStatus; -import tocraft.craftedcore.network.ModernNetworking; - -@SuppressWarnings({"unused", "resource"}) -public class ModernNetworkingImpl { - public static void registerReceiver(ModernNetworking.Side side, ResourceLocation id, ModernNetworking.Receiver receiver) { - if (side == ModernNetworking.Side.C2S) { - ServerPlayNetworking.registerGlobalReceiver(id, (server, player, handler, buf, responseSender) -> { - CompoundTag data = buf.readNbt(); - receiver.receive(new ModernNetworking.Context() { - @Override - public Player getPlayer() { - return player; - } - - @Override - public ModernNetworking.Env getEnv() { - return ModernNetworking.Env.SERVER; - } - - @Override - public void queue(Runnable runnable) { - server.execute(runnable); - } - }, data); - }); - } else if (side == ModernNetworking.Side.S2C) { - ClientPlayNetworking.registerGlobalReceiver(id, (client, handler, buf, responseSender) -> { - CompoundTag data = buf.readNbt(); - receiver.receive(new ModernNetworking.Context() { - @Override - public Player getPlayer() { - return client.player; - } - - @Override - public ModernNetworking.Env getEnv() { - return ModernNetworking.Env.CLIENT; - } - - @Override - public void queue(Runnable runnable) { - client.execute(runnable); - } - }, data); - }); - } - } - - @ApiStatus.Internal - public static Packet toPacket(ModernNetworking.Side side, ResourceLocation id, FriendlyByteBuf buf) { - return switch (side) { - case C2S -> toC2SPacket(id, buf); - case S2C -> toS2CPacket(id, buf); - }; - } - - @Environment(EnvType.CLIENT) - private static Packet toC2SPacket(ResourceLocation id, FriendlyByteBuf buf) { - return new ServerboundCustomPayloadPacket(buf); - } - - private static Packet toS2CPacket(ResourceLocation id, FriendlyByteBuf buf) { - return new ClientboundCustomPayloadPacket(buf); - } -} //#endif diff --git a/forge/src/main/java/tocraft/craftedcore/forge/CraftedCoreForgeEventHandler.java b/forge/src/main/java/tocraft/craftedcore/forge/CraftedCoreForgeEventHandler.java index 900c8b12..590e5d1c 100644 --- a/forge/src/main/java/tocraft/craftedcore/forge/CraftedCoreForgeEventHandler.java +++ b/forge/src/main/java/tocraft/craftedcore/forge/CraftedCoreForgeEventHandler.java @@ -8,16 +8,16 @@ import net.minecraftforge.event.AddReloadListenerEvent; import net.minecraftforge.event.RegisterCommandsEvent; //#if MC>1194 -//$$ import net.minecraftforge.event.entity.living.LivingBreatheEvent; +import net.minecraftforge.event.entity.living.LivingBreatheEvent; //#endif import net.minecraftforge.event.entity.living.LivingDeathEvent; import net.minecraftforge.event.entity.player.SleepingTimeCheckEvent; //#if MC>1182 -//$$ import net.minecraftforge.event.level.LevelEvent; -//$$ import net.minecraftforge.event.level.SleepFinishedTimeEvent; +import net.minecraftforge.event.level.LevelEvent; +import net.minecraftforge.event.level.SleepFinishedTimeEvent; //#else -import net.minecraftforge.event.world.WorldEvent; -import net.minecraftforge.event.world.SleepFinishedTimeEvent; +//$$ import net.minecraftforge.event.world.WorldEvent; +//$$ import net.minecraftforge.event.world.SleepFinishedTimeEvent; //#endif import net.minecraftforge.eventbus.api.Event; import net.minecraftforge.eventbus.api.SubscribeEvent; @@ -59,9 +59,9 @@ public void allowSleepTime(SleepingTimeCheckEvent event) { @SubscribeEvent public void sleepFinishedTime(SleepFinishedTimeEvent event) { //#if MC>1182 - //$$ LevelAccessor level = event.getLevel(); + LevelAccessor level = event.getLevel(); //#else - LevelAccessor level = event.getWorld(); + //$$ LevelAccessor level = event.getWorld(); //#endif long newTimeIn = PlayerEvents.SLEEP_FINISHED_TIME.invoke().setTimeAddition((ServerLevel) level, event.getNewTime()); event.setTimeAddition(newTimeIn); @@ -70,46 +70,46 @@ public void sleepFinishedTime(SleepFinishedTimeEvent event) { @SubscribeEvent public void registerCommands(RegisterCommandsEvent event) { //#if MC>1182 - //$$ CommandEvents.REGISTRATION.invoke().register(event.getDispatcher(), event.getBuildContext(), event.getCommandSelection()); + CommandEvents.REGISTRATION.invoke().register(event.getDispatcher(), event.getBuildContext(), event.getCommandSelection()); //#else - CommandEvents.REGISTRATION.invoke().register(event.getDispatcher(), event.getEnvironment()); + //$$ CommandEvents.REGISTRATION.invoke().register(event.getDispatcher(), event.getEnvironment()); //#endif } //#if MC>1182 - //$$ @SubscribeEvent - //$$ public void serverLoad(LevelEvent.Load event) { - //$$ if (event.getLevel() instanceof ServerLevel serverLevel) { - //$$ ServerLevelEvents.LEVEL_LOAD.invoke().call(serverLevel); - //$$ } - //$$ } - //$$ - //$$ @SubscribeEvent - //$$ public void serverUnload(LevelEvent.Unload event) { - //$$ if (event.getLevel() instanceof ServerLevel serverLevel) { - //$$ ServerLevelEvents.LEVEL_UNLOAD.invoke().call(serverLevel); - //$$ } - //$$ } - //#else @SubscribeEvent - public void serverLoad(WorldEvent.Load event) { - if (event.getWorld() instanceof ServerLevel serverLevel) { + public void serverLoad(LevelEvent.Load event) { + if (event.getLevel() instanceof ServerLevel serverLevel) { ServerLevelEvents.LEVEL_LOAD.invoke().call(serverLevel); } } @SubscribeEvent - public void serverUnload(WorldEvent.Unload event) { - if (event.getWorld() instanceof ServerLevel serverLevel) { + public void serverUnload(LevelEvent.Unload event) { + if (event.getLevel() instanceof ServerLevel serverLevel) { ServerLevelEvents.LEVEL_UNLOAD.invoke().call(serverLevel); } } + //#else + //$$ @SubscribeEvent + //$$ public void serverLoad(WorldEvent.Load event) { + //$$ if (event.getWorld() instanceof ServerLevel serverLevel) { + //$$ ServerLevelEvents.LEVEL_LOAD.invoke().call(serverLevel); + //$$ } + //$$ } + //$$ + //$$ @SubscribeEvent + //$$ public void serverUnload(WorldEvent.Unload event) { + //$$ if (event.getWorld() instanceof ServerLevel serverLevel) { + //$$ ServerLevelEvents.LEVEL_UNLOAD.invoke().call(serverLevel); + //$$ } + //$$ } //#endif //#if MC>1194 - //$$ @SubscribeEvent - //$$ public void livingBreathe(LivingBreatheEvent event) { - //$$ event.setCanBreathe(EntityEvents.LIVING_BREATHE.invoke().breathe(event.getEntity(), event.canBreathe())); - //$$ } + @SubscribeEvent + public void livingBreathe(LivingBreatheEvent event) { + event.setCanBreathe(EntityEvents.LIVING_BREATHE.invoke().breathe(event.getEntity(), event.canBreathe())); + } //#endif } diff --git a/forge/src/main/java/tocraft/craftedcore/forge/client/CraftedCoreForgeEventHandlerClient.java b/forge/src/main/java/tocraft/craftedcore/forge/client/CraftedCoreForgeEventHandlerClient.java index 84c6e6d3..44346865 100644 --- a/forge/src/main/java/tocraft/craftedcore/forge/client/CraftedCoreForgeEventHandlerClient.java +++ b/forge/src/main/java/tocraft/craftedcore/forge/client/CraftedCoreForgeEventHandlerClient.java @@ -6,17 +6,17 @@ import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.client.event.ClientPlayerNetworkEvent; //#if MC>1194 -//$$ import net.minecraftforge.client.event.CustomizeGuiOverlayEvent; +import net.minecraftforge.client.event.CustomizeGuiOverlayEvent; //#elseif MC>1182 //$$ import net.minecraftforge.client.event.RenderGuiEvent; //#else -import net.minecraftforge.client.event.RenderGameOverlayEvent; +//$$ import net.minecraftforge.client.event.RenderGameOverlayEvent; //#endif //#if MC>1182 -//$$ import net.minecraftforge.client.event.RenderGuiOverlayEvent; +import net.minecraftforge.client.event.RenderGuiOverlayEvent; //#else -import net.minecraftforge.client.gui.OverlayRegistry; -import com.mojang.blaze3d.vertex.PoseStack; +//$$ import net.minecraftforge.client.gui.OverlayRegistry; +//$$ import com.mojang.blaze3d.vertex.PoseStack; //#endif import net.minecraftforge.event.TickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; @@ -29,17 +29,17 @@ public class CraftedCoreForgeEventHandlerClient { @SubscribeEvent //#if MC>1194 - //$$ public void event(CustomizeGuiOverlayEvent event) { - //$$ RenderEvents.HUD_RENDERING.invoke().render(event.getGuiGraphics(), event.getPartialTick()); - //$$ } + public void event(CustomizeGuiOverlayEvent event) { + RenderEvents.HUD_RENDERING.invoke().render(event.getGuiGraphics(), event.getPartialTick()); + } //#elseif MC>1182 //$$ public void event(RenderGuiEvent.Post event) { //$$ RenderEvents.HUD_RENDERING.invoke().render(event.getPoseStack(), event.getPartialTick()); //$$ } //#else - public void event(RenderGameOverlayEvent.Post event) { - RenderEvents.HUD_RENDERING.invoke().render(event.getMatrixStack(), event.getPartialTicks()); - } + //$$ public void event(RenderGameOverlayEvent.Post event) { + //$$ RenderEvents.HUD_RENDERING.invoke().render(event.getMatrixStack(), event.getPartialTicks()); + //$$ } //#endif @SubscribeEvent @@ -53,25 +53,25 @@ public void event(TickEvent.ClientTickEvent event) { @SubscribeEvent //#if MC>1182 - //$$ public void event(RenderGuiOverlayEvent.Pre event) { + public void event(RenderGuiOverlayEvent.Pre event) { //#else - public void event(RenderGameOverlayEvent.PreLayer event) { + //$$ public void event(RenderGameOverlayEvent.PreLayer event) { //#endif //#if MC>1194 - //$$ var graphics = event.getGuiGraphics(); + var graphics = event.getGuiGraphics(); //#elseif MC>1182 //$$ var graphics = event.getPoseStack(); //#else - var graphics = event.getMatrixStack(); + //$$ var graphics = event.getMatrixStack(); //#endif //#if MC>1182 - //$$ switch (event.getOverlay().id().getPath()) { - //$$ case "player_health" -> { + switch (event.getOverlay().id().getPath()) { + case "player_health" -> { //#else - OverlayRegistry.OverlayEntry overlayEntry = OverlayRegistry.getEntry(event.getOverlay()); - if (overlayEntry != null) - switch (overlayEntry.getDisplayName()) { - case "Player Health" -> { + //$$ OverlayRegistry.OverlayEntry overlayEntry = OverlayRegistry.getEntry(event.getOverlay()); + //$$ if (overlayEntry != null) + //$$ switch (overlayEntry.getDisplayName()) { + //$$ case "Player Health" -> { //#endif InteractionResult result = RenderEvents.RENDER_HEALTH.invoke().render(graphics, Minecraft.getInstance().player); if (result == InteractionResult.FAIL) { @@ -79,9 +79,9 @@ public void event(RenderGameOverlayEvent.PreLayer event) { } } //#if MC>1182 - //$$ case "food_level" -> { + case "food_level" -> { //#else - case "Food Level" -> { + //$$ case "Food Level" -> { //#endif InteractionResult result = RenderEvents.RENDER_FOOD.invoke().render(graphics, Minecraft.getInstance().player); if (result == InteractionResult.FAIL) { @@ -89,9 +89,9 @@ public void event(RenderGameOverlayEvent.PreLayer event) { } } //#if MC>1182 - //$$ case "air_level" -> { + case "air_level" -> { //#else - case "Air Level" -> { + //$$ case "Air Level" -> { //#endif InteractionResult result = RenderEvents.RENDER_BREATH.invoke().render(graphics, Minecraft.getInstance().player); if (result == InteractionResult.FAIL) { @@ -99,9 +99,9 @@ public void event(RenderGameOverlayEvent.PreLayer event) { } } //#if MC>1182 - //$$ case "vehicle_health" -> { + case "vehicle_health" -> { //#else - case "Mount Health" -> { + //$$ case "Mount Health" -> { //#endif InteractionResult result = RenderEvents.RENDER_MOUNT_HEALTH.invoke().render(graphics, Minecraft.getInstance().player); if (result == InteractionResult.FAIL) { @@ -112,9 +112,9 @@ public void event(RenderGameOverlayEvent.PreLayer event) { } @SubscribeEvent //#if MC>1182 - //$$ public void event(ClientPlayerNetworkEvent.LoggingOut event) { + public void event(ClientPlayerNetworkEvent.LoggingOut event) { //#else - public void event(ClientPlayerNetworkEvent.LoggedOutEvent event) { + //$$ public void event(ClientPlayerNetworkEvent.LoggedOutEvent event) { //#endif ClientPlayerEvents.CLIENT_PLAYER_QUIT.invoke().quit(event.getPlayer()); } diff --git a/forge/src/main/java/tocraft/craftedcore/forge/mixin/LivingBreatheMixin.java b/forge/src/main/java/tocraft/craftedcore/forge/mixin/LivingBreatheMixin.java index d1080fe1..4922907a 100644 --- a/forge/src/main/java/tocraft/craftedcore/forge/mixin/LivingBreatheMixin.java +++ b/forge/src/main/java/tocraft/craftedcore/forge/mixin/LivingBreatheMixin.java @@ -1,72 +1,72 @@ //#if MC<=1182 -package tocraft.craftedcore.forge.mixin; - -import net.minecraft.core.BlockPos; -import net.minecraft.tags.FluidTags; -import net.minecraft.world.damagesource.DamageSource; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EntityType; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Blocks; -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 org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import tocraft.craftedcore.event.common.EntityEvents; - -// I have no idea, why this is so complicated for Forge... -@SuppressWarnings({"UnreachableCode", "DataFlowIssue", "unused"}) -@Mixin(LivingEntity.class) -public abstract class LivingBreatheMixin extends Entity { - public LivingBreatheMixin(EntityType entityType, Level level) { - super(entityType, level); - } - - @Shadow - public abstract boolean isAlive(); - - @Shadow - protected abstract int increaseAirSupply(int currentAir); - - @Shadow - protected abstract int decreaseAirSupply(int currentAir); - - @Inject(method = "increaseAirSupply", at = @At("RETURN"), cancellable = true) - private void onIncreaseAirSupply(int currentAir, CallbackInfoReturnable cir) { - if (!EntityEvents.LIVING_BREATHE.invoke().breathe((LivingEntity) (Object) this, true)) { - cir.setReturnValue(currentAir); - } - } - - @Inject(method = "decreaseAirSupply", at = @At("RETURN"), cancellable = true) - private void onDecreaseAirSupply(int currentAir, CallbackInfoReturnable cir) { - if (EntityEvents.LIVING_BREATHE.invoke().breathe((LivingEntity) (Object) this, false)) { - cir.setReturnValue(currentAir); - } - } - - @Inject(method = "baseTick", at = @At("HEAD")) - private void breathe(CallbackInfo ci) { - boolean isInWater = this.isEyeInFluid(FluidTags.WATER) && !this.level.getBlockState(new BlockPos(this.getX(), this.getEyeY(), this.getZ())).is(Blocks.BUBBLE_COLUMN); - int air = this.getAirSupply(); - boolean canBreathe = EntityEvents.LIVING_BREATHE.invoke().breathe((LivingEntity) (Object) this, !isInWater); - - if (this.isAlive()) { - if (!isInWater && !canBreathe) { - this.setAirSupply(this.decreaseAirSupply(air)); - - // Air has run out, start drowning - if (this.getAirSupply() == -20) { - this.setAirSupply(0); - this.hurt(DamageSource.DRY_OUT, 2.0F); - } - } else if (canBreathe && isInWater) { - this.setAirSupply(this.increaseAirSupply(air)); - } - } - } -} +//$$ package tocraft.craftedcore.forge.mixin; +//$$ +//$$ import net.minecraft.core.BlockPos; +//$$ import net.minecraft.tags.FluidTags; +//$$ import net.minecraft.world.damagesource.DamageSource; +//$$ import net.minecraft.world.entity.Entity; +//$$ import net.minecraft.world.entity.EntityType; +//$$ import net.minecraft.world.entity.LivingEntity; +//$$ import net.minecraft.world.level.Level; +//$$ import net.minecraft.world.level.block.Blocks; +//$$ 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 org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +//$$ import tocraft.craftedcore.event.common.EntityEvents; +//$$ +//$$ // I have no idea, why this is so complicated for Forge... +//$$ @SuppressWarnings({"UnreachableCode", "DataFlowIssue", "unused"}) +//$$ @Mixin(LivingEntity.class) +//$$ public abstract class LivingBreatheMixin extends Entity { +//$$ public LivingBreatheMixin(EntityType entityType, Level level) { +//$$ super(entityType, level); +//$$ } +//$$ +//$$ @Shadow +//$$ public abstract boolean isAlive(); +//$$ +//$$ @Shadow +//$$ protected abstract int increaseAirSupply(int currentAir); +//$$ +//$$ @Shadow +//$$ protected abstract int decreaseAirSupply(int currentAir); +//$$ +//$$ @Inject(method = "increaseAirSupply", at = @At("RETURN"), cancellable = true) +//$$ private void onIncreaseAirSupply(int currentAir, CallbackInfoReturnable cir) { +//$$ if (!EntityEvents.LIVING_BREATHE.invoke().breathe((LivingEntity) (Object) this, true)) { +//$$ cir.setReturnValue(currentAir); +//$$ } +//$$ } +//$$ +//$$ @Inject(method = "decreaseAirSupply", at = @At("RETURN"), cancellable = true) +//$$ private void onDecreaseAirSupply(int currentAir, CallbackInfoReturnable cir) { +//$$ if (EntityEvents.LIVING_BREATHE.invoke().breathe((LivingEntity) (Object) this, false)) { +//$$ cir.setReturnValue(currentAir); +//$$ } +//$$ } +//$$ +//$$ @Inject(method = "baseTick", at = @At("HEAD")) +//$$ private void breathe(CallbackInfo ci) { +//$$ boolean isInWater = this.isEyeInFluid(FluidTags.WATER) && !this.level.getBlockState(new BlockPos(this.getX(), this.getEyeY(), this.getZ())).is(Blocks.BUBBLE_COLUMN); +//$$ int air = this.getAirSupply(); +//$$ boolean canBreathe = EntityEvents.LIVING_BREATHE.invoke().breathe((LivingEntity) (Object) this, !isInWater); +//$$ +//$$ if (this.isAlive()) { +//$$ if (!isInWater && !canBreathe) { +//$$ this.setAirSupply(this.decreaseAirSupply(air)); +//$$ +//$$ // Air has run out, start drowning +//$$ if (this.getAirSupply() == -20) { +//$$ this.setAirSupply(0); +//$$ this.hurt(DamageSource.DRY_OUT, 2.0F); +//$$ } +//$$ } else if (canBreathe && isInWater) { +//$$ this.setAirSupply(this.increaseAirSupply(air)); +//$$ } +//$$ } +//$$ } +//$$ } //#endif diff --git a/forge/src/main/java/tocraft/craftedcore/network/forge/ModernNetworkingImpl.java b/forge/src/main/java/tocraft/craftedcore/network/forge/ModernNetworkingImpl.java index 755b7db0..0d27c014 100644 --- a/forge/src/main/java/tocraft/craftedcore/network/forge/ModernNetworkingImpl.java +++ b/forge/src/main/java/tocraft/craftedcore/network/forge/ModernNetworkingImpl.java @@ -1,5 +1,6 @@ package tocraft.craftedcore.network.forge; +import io.netty.buffer.Unpooled; import net.minecraft.client.Minecraft; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.FriendlyByteBuf; @@ -11,14 +12,14 @@ import net.minecraftforge.fml.LogicalSide; import net.minecraftforge.network.NetworkDirection; //#if MC>1201 -//$$ import net.minecraftforge.network.ChannelBuilder; -//$$ import net.minecraftforge.network.EventNetworkChannel; -//$$ import net.minecraftforge.event.network.CustomPayloadEvent; +import net.minecraftforge.network.ChannelBuilder; +import net.minecraftforge.network.EventNetworkChannel; +import net.minecraftforge.event.network.CustomPayloadEvent; //#else -import net.minecraftforge.network.NetworkEvent; -import net.minecraftforge.network.NetworkRegistry; -import net.minecraftforge.network.event.EventNetworkChannel; -import org.apache.commons.lang3.tuple.Pair; +//$$ import net.minecraftforge.network.NetworkEvent; +//$$ import net.minecraftforge.network.NetworkRegistry; +//$$ import net.minecraftforge.network.event.EventNetworkChannel; +//$$ import org.apache.commons.lang3.tuple.Pair; //#endif import org.jetbrains.annotations.ApiStatus; import tocraft.craftedcore.CraftedCore; @@ -31,9 +32,9 @@ public class ModernNetworkingImpl { private static final ResourceLocation CHANNEL_ID = CraftedCore.id("network"); //#if MC>1201 - //$$ private static final EventNetworkChannel CHANNEL = ChannelBuilder.named(CHANNEL_ID).acceptedVersions((status, version) -> true).optional().eventNetworkChannel(); + private static final EventNetworkChannel CHANNEL = ChannelBuilder.named(CHANNEL_ID).acceptedVersions((status, version) -> true).optional().eventNetworkChannel(); //#else - private static final EventNetworkChannel CHANNEL = NetworkRegistry.newEventChannel(CHANNEL_ID, () -> "1", version -> true, version -> true); + //$$ private static final EventNetworkChannel CHANNEL = NetworkRegistry.newEventChannel(CHANNEL_ID, () -> "1", version -> true, version -> true); //#endif private static final Map C2S_RECEIVER = new HashMap<>(); private static final Map S2C_RECEIVER = new HashMap<>(); @@ -42,9 +43,9 @@ public static void initialize() { CHANNEL.addListener(event -> { FriendlyByteBuf buf = event.getPayload(); //#if MC>1201 - //$$ CustomPayloadEvent.Context source = event.getSource(); + CustomPayloadEvent.Context source = event.getSource(); //#else - NetworkEvent.Context source = event.getSource().get(); + //$$ NetworkEvent.Context source = event.getSource().get(); //#endif if (buf == null || source.getPacketHandled()) return; ResourceLocation packetId = buf.readResourceLocation(); @@ -87,12 +88,15 @@ public static void registerReceiver(ModernNetworking.Side side, ResourceLocation } @ApiStatus.Internal - public static Packet toPacket(ModernNetworking.Side side, ResourceLocation id, FriendlyByteBuf buf) { + public static Packet toPacket(ModernNetworking.Side side, ResourceLocation id, CompoundTag data) { + FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer()); + buf.writeResourceLocation(id); + buf.writeNbt(data); NetworkDirection direction = side == ModernNetworking.Side.C2S ? NetworkDirection.PLAY_TO_SERVER : NetworkDirection.PLAY_TO_CLIENT; //#if MC>1201 - //$$ return direction.buildPacket(buf, CHANNEL_ID).getThis(); + return direction.buildPacket(buf, CHANNEL_ID).getThis(); //#else - return direction.buildPacket(Pair.of(buf, 0), CHANNEL_ID).getThis(); + //$$ return direction.buildPacket(Pair.of(buf, 0), CHANNEL_ID).getThis(); //#endif } } diff --git a/forge/src/main/resources/pack.mcmeta b/forge/src/main/resources/pack.mcmeta index f0c6fd3e..a913aa26 100644 --- a/forge/src/main/resources/pack.mcmeta +++ b/forge/src/main/resources/pack.mcmeta @@ -3,4 +3,4 @@ "description": "CraftedCore", "pack_format": 6 } -} \ No newline at end of file +} diff --git a/neoforge/src/main/java/tocraft/craftedcore/neoforge/CraftedCoreNeoForge.java b/neoforge/src/main/java/tocraft/craftedcore/neoforge/CraftedCoreNeoForge.java index a10d2e13..7d9b4c30 100644 --- a/neoforge/src/main/java/tocraft/craftedcore/neoforge/CraftedCoreNeoForge.java +++ b/neoforge/src/main/java/tocraft/craftedcore/neoforge/CraftedCoreNeoForge.java @@ -27,8 +27,8 @@ public CraftedCoreNeoForge(IEventBus bus) { //#if MC==1204 //$$ ModernNetworkingImpl.initialize(bus); - //#else - ModernNetworkingImpl.initialize(); + //#elseif MC<1205 + //$$ ModernNetworkingImpl.initialize(); //#endif } diff --git a/neoforge/src/main/java/tocraft/craftedcore/network/neoforge/ModernNetworkingImpl.java b/neoforge/src/main/java/tocraft/craftedcore/network/neoforge/ModernNetworkingImpl.java index 1c8d3b08..eddd6d0b 100644 --- a/neoforge/src/main/java/tocraft/craftedcore/network/neoforge/ModernNetworkingImpl.java +++ b/neoforge/src/main/java/tocraft/craftedcore/network/neoforge/ModernNetworkingImpl.java @@ -79,20 +79,23 @@ public static Packet toPacket(ModernNetworking.Side side, CustomPacketPayload } } } -//#elseif MC>1202 +//#elseif MC>1203 //$$ //$$ import io.netty.buffer.Unpooled; //$$ import net.minecraft.client.Minecraft; +//$$ import net.minecraft.nbt.CompoundTag; //$$ import net.minecraft.network.FriendlyByteBuf; //$$ import net.minecraft.network.protocol.Packet; //$$ import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket; //$$ import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket; +//$$ import net.minecraft.network.protocol.common.custom.CustomPacketPayload; //$$ import net.minecraft.resources.ResourceLocation; //$$ import net.minecraft.world.entity.player.Player; //$$ import net.neoforged.bus.api.IEventBus; //$$ import net.neoforged.neoforge.network.event.RegisterPayloadHandlerEvent; //$$ import net.neoforged.neoforge.network.registration.IPayloadRegistrar; //$$ import org.jetbrains.annotations.ApiStatus; +//$$ import org.jetbrains.annotations.NotNull; //$$ import tocraft.craftedcore.CraftedCore; //$$ import tocraft.craftedcore.network.ModernNetworking; //$$ @@ -109,8 +112,8 @@ public static Packet toPacket(ModernNetworking.Side side, CustomPacketPayload //$$ eventBus.addListener(RegisterPayloadHandlerEvent.class, event -> { //$$ IPayloadRegistrar registrar = event.registrar(CraftedCore.MODID).optional(); //$$ -//$$ registrar.play(CHANNEL_ID, ModernNetworking.PacketPayload::new, builder -> { -//$$ builder.server((arg, context) -> C2S.get(arg.id()).receive(new ModernNetworking.Context() { +//$$ registrar.play(CHANNEL_ID, NeoPacketPayload::new, builder -> { +//$$ builder.server((arg, context) -> C2S.get(arg.packetId()).receive(new ModernNetworking.Context() { //$$ @Override //$$ public Player getPlayer() { //$$ return context.player().orElse(null); @@ -125,9 +128,9 @@ public static Packet toPacket(ModernNetworking.Side side, CustomPacketPayload //$$ public void queue(Runnable runnable) { //$$ context.workHandler().execute(runnable); //$$ } -//$$ }, arg.nbt())); +//$$ }, arg.data())); //$$ -//$$ builder.client((arg, context) -> S2C.get(arg.id()).receive(new ModernNetworking.Context() { +//$$ builder.client((arg, context) -> S2C.get(arg.packetId()).receive(new ModernNetworking.Context() { //$$ @Override //$$ public Player getPlayer() { //$$ return Minecraft.getInstance().player; @@ -142,11 +145,28 @@ public static Packet toPacket(ModernNetworking.Side side, CustomPacketPayload //$$ public void queue(Runnable runnable) { //$$ context.workHandler().execute(runnable); //$$ } -//$$ }, arg.nbt())); +//$$ }, arg.data())); //$$ }); //$$ }); //$$ } //$$ +//$$ private record NeoPacketPayload(ResourceLocation packetId, CompoundTag data) implements CustomPacketPayload { +//$$ public NeoPacketPayload(FriendlyByteBuf buf) { +//$$ this(buf.readResourceLocation(), buf.readNbt()); +//$$ } +//$$ +//$$ @Override +//$$ public void write(FriendlyByteBuf buf) { +//$$ buf.writeResourceLocation(packetId); +//$$ buf.writeNbt(data); +//$$ } +//$$ +//$$ @Override +//$$ public @NotNull ResourceLocation id() { +//$$ return CHANNEL_ID; +//$$ } +//$$ } +//$$ //$$ public static void registerReceiver(ModernNetworking.Side side, ResourceLocation id, ModernNetworking.Receiver //$$ receiver) { //$$ switch (side) { @@ -156,15 +176,12 @@ public static Packet toPacket(ModernNetworking.Side side, CustomPacketPayload //$$ } //$$ //$$ @ApiStatus.Internal -//$$ public static Packet toPacket(ModernNetworking.Side side, ResourceLocation id, FriendlyByteBuf buf) { - //$$ FriendlyByteBuf packet = new FriendlyByteBuf(Unpooled.buffer()); - //$$ packet.writeResourceLocation(CHANNEL_ID); - //$$ packet.writeResourceLocation(id); - //$$ packet.writeNbt(buf.readNbt()); - //$$ return switch (side) { - //$$ case C2S -> new ServerboundCustomPayloadPacket(packet); - //$$ case S2C -> new ClientboundCustomPayloadPacket(packet); - //$$ }; +//$$ public static Packet toPacket(ModernNetworking.Side side, ResourceLocation id, CompoundTag data) { +//$$ NeoPacketPayload packet = new NeoPacketPayload(id, data); +//$$ return switch (side) { +//$$ case C2S -> new ServerboundCustomPayloadPacket(packet); +//$$ case S2C -> new ClientboundCustomPayloadPacket(packet); +//$$ }; //$$ } //$$ } //#else diff --git a/neoforge/src/main/resources/pack.mcmeta b/neoforge/src/main/resources/pack.mcmeta index f0c6fd3e..a913aa26 100644 --- a/neoforge/src/main/resources/pack.mcmeta +++ b/neoforge/src/main/resources/pack.mcmeta @@ -3,4 +3,4 @@ "description": "CraftedCore", "pack_format": 6 } -} \ No newline at end of file +} diff --git a/root.gradle.kts b/root.gradle.kts index c41ad706..3a6dc5ec 100644 --- a/root.gradle.kts +++ b/root.gradle.kts @@ -1,6 +1,128 @@ -apply(from = "https://raw.githubusercontent.com/ToCraft/GradleMaster/v2/root.gradle.kts") +import com.diluv.schoomp.Webhook +import com.diluv.schoomp.message.Message +import com.diluv.schoomp.message.embed.Embed +import java.io.FileWriter +import java.io.IOException + +buildscript { + repositories { + mavenCentral() + gradlePluginPortal() + } + dependencies { + classpath("com.diluv.schoomp:Schoomp:1.2.6") + } +} plugins { id("architectury-plugin") version "3.4-SNAPSHOT" id("dev.architectury.loom") version "1.7-SNAPSHOT" apply false -} \ No newline at end of file +} + +allprojects { + repositories { + // Add repositories to retrieve artifacts from in here. + // You should only use this when depending on other mods because + // Loom adds the essential maven repositories to download Minecraft and libraries from automatically. + // See https://docs.gradle.org/current/userguide/declaring_repositories.html + // for more information about repositories. + maven("https://maven.parchmentmc.org") + maven("https://maven.neoforged.net/releases/") + } +} + +ext { + set("releaseChangelog", releaseChangelog(1)) +} + +fun releaseChangelog(versions : Int): String { + try { + var changelog = "" + var match = 0 + var previousIT = "" + rootProject.file("CHANGELOG.md").forEachLine { + if (it.contains("================")) { + match++ + } + if (match <= versions) { + changelog += previousIT + "\n" + } + previousIT = it + return@forEachLine + } + return changelog + "\n\n" + } catch (exception : Exception) { + return "${rootProject.properties["archives_base_name"]} ${rootProject.properties["mod_version"]}\n==========\nThere was an error generating the changelog" + exception.localizedMessage + } +} + +//Splits the changelog into multiple parts if they get bigger than discords embed field size (1024) +fun discordChangelog(): List { + val changelog = releaseChangelog(1) + val res = mutableListOf() + if (changelog.length < 1024) { + res.add(changelog) + return res + } + var temp = "" + changelog.split("\n").forEach { + var it2 = it + "\n" + if ((temp.length + it2.length) >= 1024) { + res.add(temp) + temp = it2 + } else + temp += it2 + } + res.add(temp) + return res +} + +// based on the code by Flemmli97 +tasks.register("discordRelease") { + doLast { + try { + val webhook = Webhook(System.getenv("DISCORD_WEB_HOOK"), "${project.name} Upload") + + val message = Message() + message.setUsername("Mod Release") + var content = "${project.name} ${rootProject.properties["mod_version"]} has been released!" + if (rootProject.hasProperty("ping_role")) { + content = "<@&${rootProject.properties["ping_role"]}> " + content + } + message.setContent(content) + message.setAvatarUrl("https://avatars.githubusercontent.com/u/38883321") + + val embed = Embed() + + val changelog = discordChangelog() + if (changelog.size == 1) + embed.addField("Change Log", "```md\n${changelog[0]}```", false) + else + changelog.forEach { + embed.addField("Change Log", "```md\n${it}```", false) + } + embed.setColor(0xFF8000) + message.addEmbed(embed) + + webhook.sendMessage(message) + } + + catch (ignored : IOException) { + println("Failed to push to the Discord webhook.") + } + println("Send Changelog to Discord.") + } +} + +tasks.register("extractNewestChangelog") { + val fileName = "extracted.CHANGELOG.md"; + // delete file if exists + delete(fileName) + doLast { + // write changelog + val fw = FileWriter(fileName); + fw.write(releaseChangelog(1)); + fw.close() + println("Extracted newest Changelog to \"extracted.CHANGELOG.md\"") + } +} diff --git a/settings.gradle.kts b/settings.gradle.kts index 4f70492f..6291d57c 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -10,7 +10,7 @@ pluginManagement { } // set to only use one minecraft version -val minecraft = "1.18.2" +val minecraft = "" file("props").listFiles()?.forEach { var forcedVersion : String? = startParameter.projectProperties["minecraft"] @@ -46,7 +46,7 @@ file("props").listFiles()?.forEach { } } - var version = it.name.replace(".properties", "") + val version = it.name.replace(".properties", "") include(":$version") project(":$version").apply { projectDir = file("versions/$version") diff --git a/testmod-forge/src/main/resources/pack.mcmeta b/testmod-forge/src/main/resources/pack.mcmeta index 4924b303..50a33322 100644 --- a/testmod-forge/src/main/resources/pack.mcmeta +++ b/testmod-forge/src/main/resources/pack.mcmeta @@ -3,4 +3,4 @@ "description": "TestMod", "pack_format": 6 } -} \ No newline at end of file +} diff --git a/testmod-neoforge/src/main/resources/pack.mcmeta b/testmod-neoforge/src/main/resources/pack.mcmeta index 4924b303..50a33322 100644 --- a/testmod-neoforge/src/main/resources/pack.mcmeta +++ b/testmod-neoforge/src/main/resources/pack.mcmeta @@ -3,4 +3,4 @@ "description": "TestMod", "pack_format": 6 } -} \ No newline at end of file +}