diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c74c3aa..f682e1d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,20 +11,20 @@ jobs: runs-on: ubuntu-latest steps: - name: checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: validate gradle wrapper uses: gradle/wrapper-validation-action@v1 - - name: setup jdk 17 - uses: actions/setup-java@v3 + - name: setup jdk 21 + uses: actions/setup-java@v4 with: distribution: adopt - java-version: 17 + java-version: 21 - name: make gradle wrapper executable run: chmod +x ./gradlew - name: build run: ./gradlew build - name: capture build artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: Artifacts path: build/libs/ diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 997df6d..a96e070 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -8,13 +8,13 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - - name: Set up JDK 17 - uses: actions/setup-java@v2 + - name: Set up JDK 21 + uses: actions/setup-java@v4 with: distribution: adopt - java-version: 17 + java-version: 21 - name: Grant execute permission for gradlew run: chmod +x gradlew @@ -35,12 +35,12 @@ jobs: runs-on: ubuntu-latest needs: build steps: - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: name: fabric path: download - - uses: Kir-Antipov/mc-publish@v3.3 + - uses: Kir-Antipov/mc-publish@995edadc13559a8b28d0b7e6571229f067ec7659 with: modrinth-id: EjH4M3L1 modrinth-token: ${{ secrets.MODRINTH_TOKEN }} @@ -48,12 +48,11 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} loaders: | fabric - quilt game-versions: | - 1.20.1 + 1.20.6 modrinth-dependencies: | fabric-api | depends - java: 17 + java: 21 version: ${{ github.event.release.tag_name }}-fabric name: ${{ github.event.release.tag_name }}-fabric files: download/!(*-@(dev|dev-shadow)).jar \ No newline at end of file diff --git a/build.gradle b/build.gradle index 13614ab..3bb05f9 100644 --- a/build.gradle +++ b/build.gradle @@ -1,10 +1,10 @@ plugins { - id 'fabric-loom' version '1.1-SNAPSHOT' + id 'fabric-loom' version '1.6.9' id 'maven-publish' } -sourceCompatibility = JavaVersion.VERSION_17 -targetCompatibility = JavaVersion.VERSION_17 +sourceCompatibility = JavaVersion.VERSION_21 +targetCompatibility = JavaVersion.VERSION_21 archivesBaseName = project.archives_base_name version = project.mod_version @@ -47,7 +47,7 @@ processResources { tasks.withType(JavaCompile).configureEach { // Minecraft 1.18 (1.18-pre2) upwards uses Java 17. - it.options.release = 17 + it.options.release = 21 } java { diff --git a/gradle.properties b/gradle.properties index b6b84c0..f5c099c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,8 +3,9 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/develop - minecraft_version=1.20.1 - loader_version=0.14.21 + minecraft_version=1.20.6 + yarn_mappings=1.20.6+build.3 + loader_version=0.15.11 # Mod Properties mod_version = 1.0.0 @@ -12,4 +13,4 @@ org.gradle.jvmargs=-Xmx1G archives_base_name = pressalttomeow # Dependencies - fabric_version=0.83.1+1.20.1 + fabric_version=0.99.0+1.20.6 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 41dfb87..a996aab 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ +#Thu May 23 18:27:20 TRT 2024 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/de/mari_023/pressalttomeow/MeowPayload.java b/src/main/java/de/mari_023/pressalttomeow/MeowPayload.java new file mode 100644 index 0000000..9298131 --- /dev/null +++ b/src/main/java/de/mari_023/pressalttomeow/MeowPayload.java @@ -0,0 +1,18 @@ +package de.mari_023.pressalttomeow; + +import io.netty.buffer.ByteBuf; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.NotNull; + +public class MeowPayload implements CustomPacketPayload { + public static Type TYPE = new Type<>(new ResourceLocation("pressalttomeow", "m")); + public static StreamCodec CODEC = StreamCodec.of((buffer, value) -> { + }, (buffer) -> new MeowPayload()); + + @Override + public @NotNull Type type() { + return MeowPayload.TYPE; + } +} diff --git a/src/main/java/de/mari_023/pressalttomeow/PressAltToMeow.java b/src/main/java/de/mari_023/pressalttomeow/PressAltToMeow.java index 2dfda85..87063ab 100644 --- a/src/main/java/de/mari_023/pressalttomeow/PressAltToMeow.java +++ b/src/main/java/de/mari_023/pressalttomeow/PressAltToMeow.java @@ -2,8 +2,10 @@ import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; +import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry; import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; +import net.minecraft.network.codec.StreamCodec; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundEvent; @@ -15,19 +17,21 @@ import java.util.WeakHashMap; public class PressAltToMeow implements ModInitializer { - public static final ResourceLocation NETWORK_CHANNEL = new ResourceLocation("pressalttomeow", "m"); private static final WeakHashMap LAST_MEOW = new WeakHashMap<>(); private static final Random RANDOM = new Random(); @Override public void onInitialize() { - ServerPlayNetworking.registerGlobalReceiver(NETWORK_CHANNEL, (server, player, handler, buf, packetSender) -> server.execute(() -> { + PayloadTypeRegistry.playC2S().register(MeowPayload.TYPE, MeowPayload.CODEC); + PayloadTypeRegistry.playS2C().register(MeowPayload.TYPE, MeowPayload.CODEC); + ServerPlayNetworking.registerGlobalReceiver(MeowPayload.TYPE, (payload, context) -> context.player().getServer().execute(() -> { + var player = context.player(); if (!player.isSpectator() && (!LAST_MEOW.containsKey(player) || System.currentTimeMillis() - LAST_MEOW.get(player) > 1000)) { playSound(player, defaultSounds()); LAST_MEOW.put(player, System.currentTimeMillis()); } })); - ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> ServerPlayNetworking.send(handler.player, PressAltToMeow.NETWORK_CHANNEL, PacketByteBufs.create())); + ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> ServerPlayNetworking.send(handler.player, new MeowPayload())); } private static void playSound(ServerPlayer player, SoundEvent soundEvent) { diff --git a/src/main/java/de/mari_023/pressalttomeow/client/PressAltToMeowClient.java b/src/main/java/de/mari_023/pressalttomeow/client/PressAltToMeowClient.java index 6f8fc61..020bfaf 100644 --- a/src/main/java/de/mari_023/pressalttomeow/client/PressAltToMeowClient.java +++ b/src/main/java/de/mari_023/pressalttomeow/client/PressAltToMeowClient.java @@ -1,14 +1,17 @@ package de.mari_023.pressalttomeow.client; import com.mojang.blaze3d.platform.InputConstants; +import de.mari_023.pressalttomeow.MeowPayload; import de.mari_023.pressalttomeow.PressAltToMeow; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; +import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry; import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; +import net.minecraft.network.codec.StreamCodec; import net.minecraft.sounds.SoundSource; import org.lwjgl.glfw.GLFW; @@ -23,13 +26,13 @@ public void onInitializeClient() { ClientTickEvents.END_CLIENT_TICK.register(client -> { while (keyBinding.consumeClick()) { if (System.currentTimeMillis() - LAST_MEOW > 1000) { - if (isOnServer) ClientPlayNetworking.send(PressAltToMeow.NETWORK_CHANNEL, PacketByteBufs.create()); + if (isOnServer) ClientPlayNetworking.send(new MeowPayload()); else meow(); LAST_MEOW = System.currentTimeMillis(); } } }); - ClientPlayNetworking.registerGlobalReceiver(PressAltToMeow.NETWORK_CHANNEL, (client, handler, buf, packetSender) -> isOnServer = true); + ClientPlayNetworking.registerGlobalReceiver(MeowPayload.TYPE, (payload, context) -> isOnServer = true); } private void meow() { diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 3004796..3624928 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -29,8 +29,8 @@ "depends": { "fabric": "*", "minecraft": [ - "~1.20" + ">=1.20.5" ], - "java": ">=17" + "java": ">=21" } }