From ccef3e374cb4493fc702673056204d53c04a5098 Mon Sep 17 00:00:00 2001 From: iceBear67 Date: Sun, 14 Jul 2024 20:09:31 +0800 Subject: [PATCH] add hint to speed meter --- .../sfcraft/mixin/server/PlayerEntityMixin.java | 6 +----- .../sfcraft/module/ElytraSpeedMeterModule.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/ib67/sfcraft/mixin/server/PlayerEntityMixin.java b/src/main/java/io/ib67/sfcraft/mixin/server/PlayerEntityMixin.java index d34acb5..492f93f 100644 --- a/src/main/java/io/ib67/sfcraft/mixin/server/PlayerEntityMixin.java +++ b/src/main/java/io/ib67/sfcraft/mixin/server/PlayerEntityMixin.java @@ -11,7 +11,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(PlayerEntity.class) public abstract class PlayerEntityMixin { - private static final int THRESHLD_OF_ELYTRA_FLY = 2; @Unique private long flyTime; @@ -19,10 +18,7 @@ public abstract class PlayerEntityMixin { public void tickMovement(CallbackInfo ci) { var eb = ((EntityBridge) $this()); if (eb.sfcraft$getFlag(EntityBridge.sfcraft$getFlyingFlagIndex())) { - flyTime++; - if (flyTime > 20 * THRESHLD_OF_ELYTRA_FLY) { // todo config - SFCallbacks.PLAYER_FLYING.invoker().onFlyingTick($this(), flyTime - 20*THRESHLD_OF_ELYTRA_FLY, true); - } + SFCallbacks.PLAYER_FLYING.invoker().onFlyingTick($this(), flyTime++, true); } else { if (flyTime != 0) { SFCallbacks.PLAYER_FLYING.invoker().onFlyingTick($this(), flyTime, false); diff --git a/src/main/java/io/ib67/sfcraft/module/ElytraSpeedMeterModule.java b/src/main/java/io/ib67/sfcraft/module/ElytraSpeedMeterModule.java index 6e0707a..16a4796 100644 --- a/src/main/java/io/ib67/sfcraft/module/ElytraSpeedMeterModule.java +++ b/src/main/java/io/ib67/sfcraft/module/ElytraSpeedMeterModule.java @@ -14,6 +14,7 @@ import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.Text; import net.minecraft.util.Colors; import net.minecraft.util.math.BlockPos; +import org.spongepowered.asm.mixin.Unique; import java.awt.*; import java.text.DecimalFormat; @@ -21,8 +22,10 @@ import java.text.DecimalFormat; public class ElytraSpeedMeterModule extends ServerModule { private static final int BAR_LEN = 20; private static final int MAX_NORMAL_SPEED = 6; + private static final int THRESHLD_OF_ELYTRA_FLY = 8; private static final Color BAR_LEFT = new Color(85, 85, 255); private static final Color BAR_RIGHT = new Color(255, 87, 51); + private static final Text KEEP_FLYING = Text.literal("... 保持飞行以启动仪表盘 ...").withColor(Colors.LIGHT_GRAY); private static final Text[] ELYTRA_DURABILITY = new Text[100]; private static final Text[] PROGRESS_BARS = new Text[BAR_LEN]; private static final Text[] Y_METER = new Text[256]; @@ -57,6 +60,12 @@ public class ElytraSpeedMeterModule extends ServerModule { } private void onFlying(PlayerEntity player, long f, boolean b) { + if (f < THRESHLD_OF_ELYTRA_FLY * 20) { + if (f > THRESHLD_OF_ELYTRA_FLY * 15) { + player.sendMessage(KEEP_FLYING,true); + } + return; + } if (b) { var text = Text.literal(""); text.append(generateYMeter(f, player)); @@ -65,6 +74,11 @@ public class ElytraSpeedMeterModule extends ServerModule { player.sendMessage(text, true); } else { clean((ServerPlayerEntity) player); + if (f > THRESHLD_OF_ELYTRA_FLY * 20) { + player.sendMessage(Text.literal("!! LANDED !!").withColor(Colors.GREEN), true); + }else{ + player.sendMessage(Text.empty(),true); + } } }