Skip to content

Commit

Permalink
Update to 1.20.5-pre1
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenny-Hui committed Apr 14, 2024
1 parent 633e561 commit 2d0d7f8
Show file tree
Hide file tree
Showing 14 changed files with 90 additions and 96 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
12 changes: 7 additions & 5 deletions src/main/java/com/lx862/mozccaps/Main.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/lx862/mozccaps/MainClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
52 changes: 0 additions & 52 deletions src/main/java/com/lx862/mozccaps/armor/CapArmorMaterial.java

This file was deleted.

18 changes: 18 additions & 0 deletions src/main/java/com/lx862/mozccaps/armor/CapModel.java
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
35 changes: 19 additions & 16 deletions src/main/java/com/lx862/mozccaps/network/Networking.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,43 @@
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));
});
});
}

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()));
}
}
23 changes: 23 additions & 0 deletions src/main/java/com/lx862/mozccaps/network/PlayerTypePayload.java
Original file line number Diff line number Diff line change
@@ -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<PlayerTypePayload> PACKET_ID = new CustomPayload.Id<>(new Identifier("mozc_caps", "player_typed"));
public static final PacketCodec<RegistryByteBuf, PlayerTypePayload> PACKET_CODEC = Uuids.PACKET_CODEC.xmap(PlayerTypePayload::new, PlayerTypePayload::player).cast();

@Override
public Id<? extends CustomPayload> getId() {
return PACKET_ID;
}

public UUID getPlayerUuid() {
return player;
}
}
6 changes: 3 additions & 3 deletions src/main/java/com/lx862/mozccaps/render/HudRenderer.java
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion src/main/resources/data/mozc_caps/recipes/caps.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
},
"result": {
"item": "mozc_caps:caps",
"id": "mozc_caps:caps",
"count": 1
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
},
"result": {
"item": "mozc_caps:caps_strapped",
"id": "mozc_caps:caps_strapped",
"count": 1
}
}
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
"depends": {
"fabricloader": "*",
"fabric-api": "*",
"minecraft": "~1.20"
"minecraft": ">1.20.4"
}
}

0 comments on commit 2d0d7f8

Please sign in to comment.