diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0ee4cc8..4f295c7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,19 +12,19 @@ jobs: matrix: # Use these Java versions java: [ - 17, # Current Java LTS & minimum supported by Minecraft + 21 # Current Java LTS & minimum supported by Minecraft ] 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 + uses: gradle/actions/wrapper-validation@v3 - name: Setup JDK ${{ matrix.java }} - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: ${{ matrix.java }} - distribution: 'microsoft' + distribution: 'temurin' - name: Make gradle wrapper executable run: chmod +x ./gradlew - name: Build diff --git a/build.gradle b/build.gradle index 22881ec..e63409c 100644 --- a/build.gradle +++ b/build.gradle @@ -1,10 +1,10 @@ plugins { - id 'fabric-loom' version '1.5-SNAPSHOT' + id 'fabric-loom' version '1.6-SNAPSHOT' 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 @@ -37,8 +37,8 @@ processResources { } tasks.withType(JavaCompile).configureEach { - // Minecraft 1.18 upwards uses Java 17. - it.options.release = 17 + // Minecraft 1.20.5 upwards uses Java 21. + it.options.release = 21 } java { diff --git a/gradle.properties b/gradle.properties index f68b6c5..6d61d9b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,14 +4,14 @@ org.gradle.parallel=true # Fabric Properties # check these on https://fabricmc.net/develop - minecraft_version=1.20.2 - yarn_mappings=1.20.2+build.4 - loader_version=0.15.6 + minecraft_version=1.20.5-pre1 + yarn_mappings=1.20.5-pre1+build.5 + loader_version=0.15.9 # Dependencies - fabric_version=0.89.1+1.20.2 + fabric_version=0.96.15+1.20.5 # Mod Properties - mod_version = 1.0.0 + mod_version = 1.0.1 maven_group = com.lx862 archives_base_name = gcaps \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 3499ded..509c4a2 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/com/lx862/mozccaps/Main.java b/src/main/java/com/lx862/mozccaps/Main.java index 5b0cc0b..a49a86b 100644 --- a/src/main/java/com/lx862/mozccaps/Main.java +++ b/src/main/java/com/lx862/mozccaps/Main.java @@ -1,23 +1,25 @@ package com.lx862.mozccaps; -import com.lx862.mozccaps.armor.CapArmorMaterial; +import com.lx862.mozccaps.armor.CapModel; import com.lx862.mozccaps.network.Networking; import net.fabricmc.api.ModInitializer; -import net.fabricmc.fabric.api.item.v1.FabricItemSettings; import net.minecraft.item.ArmorItem; import net.minecraft.item.Item; import net.minecraft.registry.Registries; import net.minecraft.registry.Registry; +import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.util.Identifier; public class Main implements ModInitializer { - public static final Item CAPS = new ArmorItem(new CapArmorMaterial(), ArmorItem.Type.HELMET, new FabricItemSettings()); - public static final Item CAPS_STRAPPED = new ArmorItem(new CapArmorMaterial(), ArmorItem.Type.HELMET, new FabricItemSettings()); + public static final Item CAPS = new ArmorItem(RegistryEntry.of(CapModel.ARMOR_MATERIAL), ArmorItem.Type.HELMET, new Item.Settings()); + public static final Item CAPS_STRAPPED = new ArmorItem(RegistryEntry.of(CapModel.ARMOR_MATERIAL), ArmorItem.Type.HELMET, new Item.Settings()); @Override public void onInitialize() { + Registry.register(Registries.ARMOR_MATERIAL, new Identifier("mozc_caps", "armor_material"), CapModel.ARMOR_MATERIAL); Registry.register(Registries.ITEM, new Identifier("mozc_caps", "caps"), CAPS); Registry.register(Registries.ITEM, new Identifier("mozc_caps", "caps_strapped"), CAPS_STRAPPED); - Networking.registerReceiverServer(); + + Networking.registerServer(); } } \ No newline at end of file diff --git a/src/main/java/com/lx862/mozccaps/MainClient.java b/src/main/java/com/lx862/mozccaps/MainClient.java index e82596c..64f8c47 100644 --- a/src/main/java/com/lx862/mozccaps/MainClient.java +++ b/src/main/java/com/lx862/mozccaps/MainClient.java @@ -31,7 +31,7 @@ public void onInitializeClient() { HudRenderCallback.EVENT.register(HudRenderer::draw); ClientTickEvents.START_CLIENT_TICK.register(this::handleInput); - Networking.registerReceiverClient(); + Networking.registerClient(); WorldRenderEvents.BEFORE_ENTITIES.register(context -> { updateCapPressedAnimation(context.tickDelta()); diff --git a/src/main/java/com/lx862/mozccaps/armor/CapArmorMaterial.java b/src/main/java/com/lx862/mozccaps/armor/CapArmorMaterial.java deleted file mode 100644 index 0d443e3..0000000 --- a/src/main/java/com/lx862/mozccaps/armor/CapArmorMaterial.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.lx862.mozccaps.armor; - -import com.lx862.mozccaps.Main; -import net.minecraft.item.ArmorItem; -import net.minecraft.item.ArmorMaterial; -import net.minecraft.recipe.Ingredient; -import net.minecraft.sound.SoundEvent; -import net.minecraft.sound.SoundEvents; - -public class CapArmorMaterial implements ArmorMaterial { - private static final int[] BASE_DURABILITY = new int[] {13, 15, 16, 11}; - private static final int[] PROTECTION_VALUES = new int[] {1, 2, 3, 2}; - @Override - public int getDurability(ArmorItem.Type type) { - return BASE_DURABILITY[type.getEquipmentSlot().getEntitySlotId()] * 5; - } - - @Override - public int getProtection(ArmorItem.Type type) { - return PROTECTION_VALUES[type.getEquipmentSlot().getEntitySlotId()]; - } - - @Override - public int getEnchantability() { - return 15; - } - - @Override - public SoundEvent getEquipSound() { - return SoundEvents.ITEM_ARMOR_EQUIP_LEATHER; - } - - @Override - public Ingredient getRepairIngredient() { - return Ingredient.ofItems(Main.CAPS); - } - - @Override - public String getName() { - return "mozc_caps"; - } - - @Override - public float getToughness() { - return 0; - } - - @Override - public float getKnockbackResistance() { - return 0; - } -} diff --git a/src/main/java/com/lx862/mozccaps/armor/CapModel.java b/src/main/java/com/lx862/mozccaps/armor/CapModel.java index 267c0c7..4bd8da0 100644 --- a/src/main/java/com/lx862/mozccaps/armor/CapModel.java +++ b/src/main/java/com/lx862/mozccaps/armor/CapModel.java @@ -1,9 +1,27 @@ package com.lx862.mozccaps.armor; +import com.lx862.mozccaps.Main; import net.minecraft.client.model.*; +import net.minecraft.item.ArmorItem; +import net.minecraft.item.ArmorMaterial; +import net.minecraft.recipe.Ingredient; +import net.minecraft.sound.SoundEvents; +import net.minecraft.util.Util; + +import java.util.EnumMap; public class CapModel { + public static ArmorMaterial ARMOR_MATERIAL = new ArmorMaterial(Util.make(new EnumMap(ArmorItem.Type.class), map -> { + map.put(ArmorItem.Type.BODY, 1); + }), + 15, + SoundEvents.ITEM_ARMOR_EQUIP_LEATHER, + () -> Ingredient.ofItems(Main.CAPS), + null, + 0, + 0); + /* Code generated from Blockbench */ public static TexturedModelData getTexturedModelData() { ModelData modelData = new ModelData(); diff --git a/src/main/java/com/lx862/mozccaps/network/Networking.java b/src/main/java/com/lx862/mozccaps/network/Networking.java index d5c371a..5fe9755 100644 --- a/src/main/java/com/lx862/mozccaps/network/Networking.java +++ b/src/main/java/com/lx862/mozccaps/network/Networking.java @@ -3,33 +3,36 @@ import com.lx862.mozccaps.MainClient; 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.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.network.PacketByteBuf; -import net.minecraft.util.Identifier; +import net.minecraft.server.MinecraftServer; import java.util.UUID; public class Networking { - public static final Identifier PLAYER_TYPED = new Identifier("mozc_caps", "player_typed"); + public static void registerClient() { + PayloadTypeRegistry.playS2C().register(PlayerTypePayload.PACKET_ID, PlayerTypePayload.PACKET_CODEC); - public static void registerReceiverClient() { - ClientPlayNetworking.registerGlobalReceiver(PLAYER_TYPED, (client, handler, buf, responseSender) -> { - UUID playerTyped = buf.readUuid(); + ClientPlayNetworking.registerGlobalReceiver(PlayerTypePayload.PACKET_ID, (payload, context) -> { + UUID playerTyped = payload.getPlayerUuid(); MainClient.keyPressedList.put(playerTyped, 0.0); }); } - public static void registerReceiverServer() { - ServerPlayNetworking.registerGlobalReceiver(PLAYER_TYPED, (server, player, handler, buf, responseSender) -> { - UUID playerUuid = buf.readUuid(); - server.execute(() -> { - // Rebroadcast key pressed event to all player - server.getPlayerManager().getPlayerList().forEach(p -> { - PacketByteBuf buf2 = PacketByteBufs.create(); - buf2.writeUuid(playerUuid); - ServerPlayNetworking.send(p, PLAYER_TYPED, buf2); - }); + public static void registerServer() { + PayloadTypeRegistry.playC2S().register(PlayerTypePayload.PACKET_ID, PlayerTypePayload.PACKET_CODEC); + + ServerPlayNetworking.registerGlobalReceiver(PlayerTypePayload.PACKET_ID, (payload, context) -> { + UUID playerUuid = payload.getPlayerUuid(); + + MinecraftServer server = context.player().getServer(); + if(server == null) return; + + // Rebroadcast key pressed event to all player + server.getPlayerManager().getPlayerList().forEach(p -> { + ServerPlayNetworking.send(p, new PlayerTypePayload(playerUuid)); }); }); } @@ -37,6 +40,6 @@ public static void registerReceiverServer() { public static void sendKeyPressedClient(PlayerEntity player) { PacketByteBuf buf = PacketByteBufs.create(); buf.writeUuid(player.getUuid()); - ClientPlayNetworking.send(PLAYER_TYPED, buf); + ClientPlayNetworking.send(new PlayerTypePayload(player.getUuid())); } } diff --git a/src/main/java/com/lx862/mozccaps/network/PlayerTypePayload.java b/src/main/java/com/lx862/mozccaps/network/PlayerTypePayload.java new file mode 100644 index 0000000..a658404 --- /dev/null +++ b/src/main/java/com/lx862/mozccaps/network/PlayerTypePayload.java @@ -0,0 +1,23 @@ +package com.lx862.mozccaps.network; + +import net.minecraft.network.RegistryByteBuf; +import net.minecraft.network.codec.PacketCodec; +import net.minecraft.network.packet.CustomPayload; +import net.minecraft.util.Identifier; +import net.minecraft.util.Uuids; + +import java.util.UUID; + +public record PlayerTypePayload(UUID player) implements CustomPayload { + public static final CustomPayload.Id PACKET_ID = new CustomPayload.Id<>(new Identifier("mozc_caps", "player_typed")); + public static final PacketCodec PACKET_CODEC = Uuids.PACKET_CODEC.xmap(PlayerTypePayload::new, PlayerTypePayload::player).cast(); + + @Override + public Id getId() { + return PACKET_ID; + } + + public UUID getPlayerUuid() { + return player; + } +} diff --git a/src/main/java/com/lx862/mozccaps/render/HudRenderer.java b/src/main/java/com/lx862/mozccaps/render/HudRenderer.java index 8e5a4f9..9cb5adc 100644 --- a/src/main/java/com/lx862/mozccaps/render/HudRenderer.java +++ b/src/main/java/com/lx862/mozccaps/render/HudRenderer.java @@ -1,10 +1,10 @@ package com.lx862.mozccaps.render; import com.lx862.mozccaps.AtamaInput; -import com.lx862.mozccaps.Main; import com.lx862.mozccaps.MainClient; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.Text; public class HudRenderer { @@ -43,10 +43,10 @@ private static void drawTextField(MinecraftClient minecraft, DrawContext drawCon } private static void drawText(DrawContext drawContext, MinecraftClient minecraft, Text string, int x, int y, int color, boolean shadow) { - drawContext.drawText(minecraft.textRenderer, string, PADDING + x, y, color, shadow); + drawContext.drawTextWithShadow(minecraft.textRenderer, string, PADDING + x, y, color); } private static void drawTextRightAligned(DrawContext drawContext, MinecraftClient minecraft, Text string, int x, int y, int color, boolean shadow) { - drawText(drawContext, minecraft, string, minecraft.getWindow().getScaledWidth() - PADDING - PADDING - x - minecraft.textRenderer.getWidth(string), y, color, shadow); + drawContext.drawTextWithShadow(minecraft.textRenderer, string, minecraft.getWindow().getScaledWidth() - PADDING - PADDING - x - minecraft.textRenderer.getWidth(string), y, color); } } diff --git a/src/main/resources/data/mozc_caps/recipes/caps.json b/src/main/resources/data/mozc_caps/recipes/caps.json index 00f572e..16d1a0e 100644 --- a/src/main/resources/data/mozc_caps/recipes/caps.json +++ b/src/main/resources/data/mozc_caps/recipes/caps.json @@ -14,7 +14,7 @@ } }, "result": { - "item": "mozc_caps:caps", + "id": "mozc_caps:caps", "count": 1 } } \ No newline at end of file diff --git a/src/main/resources/data/mozc_caps/recipes/caps_strapped.json b/src/main/resources/data/mozc_caps/recipes/caps_strapped.json index 7cde8e8..4f623a6 100644 --- a/src/main/resources/data/mozc_caps/recipes/caps_strapped.json +++ b/src/main/resources/data/mozc_caps/recipes/caps_strapped.json @@ -14,7 +14,7 @@ } }, "result": { - "item": "mozc_caps:caps_strapped", + "id": "mozc_caps:caps_strapped", "count": 1 } } \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 77bb8d5..0dfaf49 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -33,6 +33,6 @@ "depends": { "fabricloader": "*", "fabric-api": "*", - "minecraft": "~1.20" + "minecraft": ">1.20.4" } }