Skip to content

Commit

Permalink
fix send message wrong. version 0.1 completed
Browse files Browse the repository at this point in the history
  • Loading branch information
YOM667 committed Jan 1, 2023
1 parent 8d7704c commit 584af5a
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 12 deletions.
44 changes: 43 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,45 @@
# IngotFly
在生存模式下,你可以飞行,但你需要花费一些宝石或锭

在生存模式下,你可以飞行,但你需要花费一些宝石或锭.

这是一个超级简单超级小的fabric模组,由**MPT**团队制作

[MPT 官网](https://www.minept.top/)
## rule
用 H 按键打开一个菜单(UI用的是Minecraft自带的UI,所以比较丑),里面显示铁锭、金锭、铜锭、绿宝石、钻石和下界合金锭,并且其名字使用红字表示消耗一个这样的矿物可飞行多长时间

飞行时间:

铁锭:3秒

金锭:5秒

铜锭:5秒

绿宝石:12秒

钻石:30秒

下界合金锭:2分钟

在成功换取飞行时间后,出现一声获取经验的钉声,在聊天栏中显示:换取成功!您的飞行时间还剩(飞行时间)秒~

在飞行时间快结束的时候在聊天栏发出警告:快降落!飞行时间快到了!还剩(飞行时间)秒!

## Installing

通过在releases中获取jar包

拖动到模组文件夹并在游戏内加载模组

## Bug

暂时未发现bug

## TIP

写这个模组只是为了实现别人的需求

并不是为了水 commit 和 装逼

如果你觉得我的代码很 shit 或者有需要改进的地方 请给我的 qq 发送消息 1055965862
3 changes: 2 additions & 1 deletion src/main/java/top/mpt/ingotfly/ingotfly/IngotFly.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,12 @@ public void registerEvent(){
world.playSound(null, player.getBlockPos(), SoundEvents.ENTITY_PLAYER_LEVELUP, SoundCategory.MUSIC, 1f, 1f);
//允许玩家飞行
player.getAbilities().allowFlying = true;
Util.sendMessage("chat.text.capability");
//计时器开始计时
TimeTask task = new TimeTask(entry.getValue(), player);
new Timer().schedule(task, 0, 1000);
} else {
Util.sendMessage("玩家已经在飞行或可以飞行,无法再次使用道具!");
Util.sendMessage("chat.text.flying");
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/top/mpt/ingotfly/ingotfly/TimeTask.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package top.mpt.ingotfly.ingotfly;

import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.text.Text;

import java.util.TimerTask;

Expand All @@ -18,9 +19,11 @@ public TimeTask(Long time, PlayerEntity player) {

@Override
public void run() {
if(time<=3L) Util.sendMessage("距离飞行时间结束还有"+time+"秒");
if(time<=3L) {
Util.sendSuccessiveMessage("chat.text.fall"," " + time + " ","text.ingot_fly.time");
}
if(time == 0L) {
Util.sendMessage("飞行时间已结束");
Util.sendMessage(Text.translatable("chat.text.end"));
player.getAbilities().allowFlying = false;
player.getAbilities().flying = false;
this.cancel();
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/top/mpt/ingotfly/ingotfly/Util.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package top.mpt.ingotfly.ingotfly;

import net.minecraft.client.MinecraftClient;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;

import java.util.Arrays;
Expand All @@ -9,12 +10,17 @@
* @author You_M
*/
public class Util {
public static void sendMessage(Object message){
public static void sendMessage(Text message){
if (MinecraftClient.getInstance().player != null) {
MinecraftClient.getInstance().player.sendMessage(Text.of(message.toString()));
MinecraftClient.getInstance().player.sendMessage(message);
}
}
public static void sendMessage(Object ...message){
Arrays.stream(message).forEach(Util::sendMessage);
public static void sendMessage(String message){
sendMessage(Text.translatable(message));
}
public static void sendSuccessiveMessage(Object ...messages){
MutableText text = Text.translatable("");
Arrays.stream(messages).forEach(message-> text.append(Text.translatable(String.valueOf(message))));
sendMessage(text);
}
}
6 changes: 5 additions & 1 deletion src/main/resources/assets/ingot_fly/lang/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
"key.ingot_fly.gui": "open ingotFly GUI",
"gui.ingot_fly.title": "ingotFly GUI",
"text.ingot_fly.message": "spend a ingot to get",
"text.ingot_fly.time": "second"
"text.ingot_fly.time": "second",
"chat.text.fall": "Come down! Flight time is coming! Remaining",
"chat.text.end": "End of flight time",
"chat.text.flying": "The player is already flying or can fly, and cannot use the prop again!",
"chat.text.capability": "Successfully acquired flight capability"
}
10 changes: 7 additions & 3 deletions src/main/resources/assets/ingot_fly/lang/zh_CN.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"key.ingot_fly.gui": "打开 ingotFly 界面",
"gui.ingot_fly.title": "ingotFly 界面",
"key.ingot_fly.gui": "打开 IngotFly 界面",
"gui.ingot_fly.title": "IngotFly 界面",
"text.ingot_fly.message": "花费一个锭获取",
"text.ingot_fly.time": ""
"text.ingot_fly.time": "",
"chat.text.fall": "快降落!飞行时间快到了!还剩",
"chat.text.end": "飞行时间结束",
"chat.text.flying": "玩家已经在飞行或可以飞行,无法再次使用道具!",
"chat.text.capability": "获取飞行能力成功"
}

0 comments on commit 584af5a

Please sign in to comment.