Skip to content

Commit cbe1059

Browse files
committed
Refactor BoatFlyClient logic and key bindings to adapt to Fabric1.21.9+
Update 1.21.10
1 parent bd66ffc commit cbe1059

File tree

6 files changed

+27
-52
lines changed

6 files changed

+27
-52
lines changed

gradle.properties

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ org.gradle.parallel=true
44

55
# Fabric Properties
66
# check these on https://fabricmc.net/develop
7-
minecraft_version=1.21.8
8-
yarn_mappings=1.21.8+build.1
9-
loader_version=0.17.2
7+
minecraft_version=1.21.10
8+
yarn_mappings=1.21.10+build.3
9+
loader_version=0.18.1
1010
loom_version=1.13-SNAPSHOT
1111

1212
# Fabric API
13-
fabric_version=0.130.0+1.21.8
13+
fabric_version=0.138.0+1.21.10
1414

1515
# Mod Properties
16-
mod_version=6.1.1
16+
mod_version=6.1.2
1717
maven_group=com.boatfly
1818
archives_base_name=boatfly

src/client/java/com/boatfly/BoatFlyClient.java

Lines changed: 17 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import net.minecraft.client.MinecraftClient;
1212
import net.minecraft.client.option.KeyBinding;
1313
import net.minecraft.client.util.InputUtil;
14+
import net.minecraft.util.Identifier;
1415
import net.minecraft.entity.Entity;
1516
import net.minecraft.text.Text;
1617
import net.minecraft.util.math.Vec3d;
@@ -37,34 +38,33 @@ public class BoatFlyClient implements ClientModInitializer {
3738
private static final double JUMP_VELOCITY = 0.3;
3839
private static final double MIN_SPEED = 0.0;
3940

41+
private static final KeyBinding.Category KEY_CATEGORY = new KeyBinding.Category(Identifier.of(MOD_ID, "main"));
42+
4043
@Override
4144
public void onInitializeClient() {
4245
// 註冊按鍵綁定
4346
boatFlightKey = KeyBindingHelper.registerKeyBinding(new KeyBinding(
4447
"key." + MOD_ID + ".toggle_fly",
4548
InputUtil.Type.KEYSYM,
4649
GLFW.GLFW_KEY_B,
47-
"category." + MOD_ID + ".main"
50+
KEY_CATEGORY
4851
));
49-
5052
increaseSpeedKey = KeyBindingHelper.registerKeyBinding(new KeyBinding(
5153
"key." + MOD_ID + ".increase_speed",
5254
InputUtil.Type.KEYSYM,
5355
GLFW.GLFW_KEY_I,
54-
"category." + MOD_ID + ".main"
56+
KEY_CATEGORY
5557
));
56-
5758
decreaseSpeedKey = KeyBindingHelper.registerKeyBinding(new KeyBinding(
5859
"key." + MOD_ID + ".decrease_speed",
5960
InputUtil.Type.KEYSYM,
6061
GLFW.GLFW_KEY_O,
61-
"category." + MOD_ID + ".main"
62+
KEY_CATEGORY
6263
));
6364

64-
// 註冊客戶端 Tick 事件監聽器
65+
// 註冊用戶端 Tick 事件監聽器
6566
ClientTickEvents.END_CLIENT_TICK.register(this::onClientTick);
66-
67-
// 註冊客戶端指令 (使用 Fabric API v2)
67+
// 註冊用戶端指令 (使用 Fabric API v2)
6868
ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> {
6969
LiteralArgumentBuilder<FabricClientCommandSource> command = ClientCommandManager.literal("boatspeed")
7070
.then(ClientCommandManager.argument("speed", FloatArgumentType.floatArg((float) MIN_SPEED))
@@ -79,10 +79,6 @@ public void onInitializeClient() {
7979
});
8080
}
8181

82-
/**
83-
* 在每個客戶端 tick 結束時調用此方法,處理所有邏輯。
84-
* @param client MinecraftClient 實例
85-
*/
8682
private void onClientTick(MinecraftClient client) {
8783
// 確保玩家實例存在,否則不執行
8884
if (client.player == null) return;
@@ -92,43 +88,32 @@ private void onClientTick(MinecraftClient client) {
9288
isBoatFlyEnabled = !isBoatFlyEnabled;
9389
if (isBoatFlyEnabled) {
9490
changeSpeed(DEFAULT_SPEED);
95-
if (client.player != null) {
96-
client.player.sendMessage(Text.translatable("message." + MOD_ID + ".fly_enabled", String.format("%.2f", currentBoatVelocity)), false);
97-
}
91+
client.player.sendMessage(Text.translatable("message." + MOD_ID + ".fly_enabled", String.format("%.2f", currentBoatVelocity)), false);
9892
} else {
99-
if (client.player != null) {
100-
client.player.sendMessage(Text.translatable("message." + MOD_ID + ".fly_disabled"), false);
101-
}
93+
client.player.sendMessage(Text.translatable("message." + MOD_ID + ".fly_disabled"), false);
10294
}
10395
}
10496

10597
// 若功能未啟用,直接返回
106-
if (!isBoatFlyEnabled) {
107-
return;
108-
}
98+
if (!isBoatFlyEnabled) return;
10999

110100
// 處理增加速度按鍵
111101
if (increaseSpeedKey.wasPressed()) {
112102
changeSpeed(currentBoatVelocity + SPEED_INCREMENT);
113-
if (client.player != null) {
114-
client.player.sendMessage(Text.translatable("message." + MOD_ID + ".speed_changed", String.format("%.2f", currentBoatVelocity)), false);
115-
}
103+
client.player.sendMessage(Text.translatable("message." + MOD_ID + ".speed_changed", String.format("%.2f", currentBoatVelocity)), false);
116104
}
117105

118106
// 處理降低速度按鍵
119107
if (decreaseSpeedKey.wasPressed()) {
120108
if (currentBoatVelocity > MIN_SPEED) {
121109
changeSpeed(currentBoatVelocity + SPEED_DECREMENT);
122-
if (client.player != null) {
123-
client.player.sendMessage(Text.translatable("message." + MOD_ID + ".speed_changed", String.format("%.2f", currentBoatVelocity)), false);
124-
}
110+
client.player.sendMessage(Text.translatable("message." + MOD_ID + ".speed_changed", String.format("%.2f", currentBoatVelocity)), false);
125111
}
126112
}
127-
128-
if (client.player == null || !client.player.hasVehicle()) {
129-
return;
130-
}
113+
114+
if (!client.player.hasVehicle()) return;
131115
Entity vehicle = client.player.getVehicle();
116+
if (vehicle == null) return;
132117

133118
// 處理跳躍鍵 (控制垂直向上速度)
134119
if (client.options.jumpKey.isPressed()) {
@@ -144,22 +129,12 @@ private void onClientTick(MinecraftClient client) {
144129
}
145130
}
146131

147-
/**
148-
* 改變船的速度設定值,並計算相應的速度乘數。
149-
* @param newSpeed 新的目標速度(單位:blocks/s)
150-
*/
151132
private void changeSpeed(double newSpeed) {
152133
currentBoatVelocity = Math.max(MIN_SPEED, newSpeed);
153134
boatSpeedMultiplier = calculateMultiplier(currentBoatVelocity);
154-
155135
LOGGER.info("Boat speed set to {} b/s, multiplier is {}.", String.format("%.2f", currentBoatVelocity), String.format("%.5f", boatSpeedMultiplier));
156136
}
157137

158-
/**
159-
* 根據目標速度計算一個內部乘數。
160-
* @param velocity 目標速度
161-
* @return 計算出的速度乘數
162-
*/
163138
private double calculateMultiplier(double velocity) {
164139
// f(v) = (-5.33893 * (ln(v - 8 + 11.9072))^(-3.31832) + 1.26253)^(0.470998)
165140
if (velocity <= 0) return 0;
@@ -173,4 +148,4 @@ private double calculateMultiplier(double velocity) {
173148

174149
return Math.pow(base, 0.470998);
175150
}
176-
}
151+
}

src/main/resources/assets/boatfly/lang/en_us.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"category.boatfly.main": "Boat Fly",
2+
"key.category.boatfly.main": "Boat Fly",
33
"key.boatfly.toggle_fly": "Toggle Boat Fly",
44
"key.boatfly.increase_speed": "Increase Boat Speed",
55
"key.boatfly.decrease_speed": "Decrease Boat Speed",

src/main/resources/assets/boatfly/lang/zh_cn.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"category.boatfly.main": "Boat Fly",
2+
"key.category.boatfly.main": "Boat Fly",
33
"key.boatfly.toggle_fly": "切换船只飞行",
44
"key.boatfly.increase_speed": "增加船只速度",
55
"key.boatfly.decrease_speed": "降低船只速度",

src/main/resources/assets/boatfly/lang/zh_tw.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"category.boatfly.main": "Boat Fly",
2+
"key.category.boatfly.main": "Boat Fly",
33
"key.boatfly.toggle_fly": "切換船隻飛行",
44
"key.boatfly.increase_speed": "增加船隻速度",
55
"key.boatfly.decrease_speed": "降低船隻速度",

src/main/resources/fabric.mod.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"schemaVersion": 1,
33
"id": "boatfly",
44
"version": "${version}",
5-
"name": "Boat Fly",
5+
"name": "BoatFly",
66
"description": "Allows you to Fly in a Boat and Change the speed of the boat",
77
"authors": [
88
"Eric Gilerson",
@@ -26,7 +26,7 @@
2626
],
2727
"depends": {
2828
"fabricloader": ">=0.17.0",
29-
"minecraft": ">=1.21.8",
29+
"minecraft": ">=1.21.9",
3030
"java": ">=21",
3131
"fabric-api": "*"
3232
},

0 commit comments

Comments
 (0)