Skip to content

Commit 9295603

Browse files
committed
初步搭建技能使用冷却
1 parent ca89260 commit 9295603

File tree

8 files changed

+91
-22
lines changed

8 files changed

+91
-22
lines changed

src/main/java/xyz/lisbammisakait/RelightTheThreePointStrategyClient.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ public void onInitializeClient() {
4141
private void useSkill(MinecraftClient client,int slot) {
4242
PlayerInventory inventory = client.player.getInventory();
4343
ItemStack skillStack = inventory.getStack(slot);
44+
//
4445
if (skillStack.isEmpty()||!(skillStack.getItem() instanceof Skillable)) {
4546
RelightTheThreePointStrategy.LOGGER.info("并非技能物品");
4647
return;
4748
}
4849
Skillable skill = (Skillable) skillStack.getItem();
49-
skill.useSkill(client);
50+
skill.castSkill(client);
5051
}
5152
}

src/main/java/xyz/lisbammisakait/item/ModItems.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import net.minecraft.registry.RegistryKeys;
1313
import net.minecraft.text.Text;
1414
import net.minecraft.util.Identifier;
15+
import xyz.lisbammisakait.skill.LiuBeiASkill;
1516
import xyz.lisbammisakait.skill.TieJiTaChuanSkill;
1617
import xyz.lisbammisakait.RelightTheThreePointStrategy;
1718
import xyz.lisbammisakait.skill.YinFengLaiXiangSkill;
@@ -55,6 +56,8 @@ public class ModItems {
5556
public static final RegistryKey<Item> TIEJITACHUAN_KEY = RegistryKey.of(RegistryKeys.ITEM, Identifier.of(RelightTheThreePointStrategy.MOD_ID, "tiejitachuan"));
5657
public static final Item TIEJITACHUAN = register(new TieJiTaChuanSkill( new Item.Settings().registryKey(TIEJITACHUAN_KEY)), TIEJITACHUAN_KEY);
5758

59+
public static final RegistryKey<Item> LIUBEIASKILL_KEY = RegistryKey.of(RegistryKeys.ITEM, Identifier.of(RelightTheThreePointStrategy.MOD_ID, "longnudiwei"));
60+
public static final Item LIUBEIASKILL = register(new LiuBeiASkill( new Item.Settings().registryKey(LIUBEIASKILL_KEY)), LIUBEIASKILL_KEY);
5861
public static Item register(Item item, RegistryKey<Item> registryKey) {
5962
// Register the item.
6063
Item registeredItem = Registry.register(Registries.ITEM, registryKey.getValue(), item);
@@ -75,6 +78,7 @@ public static void registerToSkillGroups() {
7578
ItemGroupEvents.modifyEntriesEvent(SKILL_GROUP_KEY).register(itemGroup -> {
7679
itemGroup.add(ModItems.YINFENGLAIXIANG);
7780
itemGroup.add(ModItems.TIEJITACHUAN);
81+
itemGroup.add(ModItems.LIUBEIASKILL);
7882
});
7983
}
8084
//注册武器
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package xyz.lisbammisakait.skill;
2+
3+
import net.minecraft.client.MinecraftClient;
4+
import net.minecraft.client.network.ClientPlayerEntity;
5+
import net.minecraft.entity.Entity;
6+
import net.minecraft.entity.effect.StatusEffectInstance;
7+
import net.minecraft.entity.effect.StatusEffects;
8+
import net.minecraft.entity.player.PlayerEntity;
9+
import net.minecraft.item.Item;
10+
import net.minecraft.item.ItemStack;
11+
import net.minecraft.item.tooltip.TooltipType;
12+
import net.minecraft.server.world.ServerWorld;
13+
import net.minecraft.text.Text;
14+
import net.minecraft.util.ActionResult;
15+
import net.minecraft.util.math.Box;
16+
import net.minecraft.util.math.Vec3d;
17+
import xyz.lisbammisakait.RelightTheThreePointStrategy;
18+
import xyz.lisbammisakait.RelightTheThreePointStrategyClient;
19+
import xyz.lisbammisakait.item.FeilongduofengItem;
20+
21+
import java.util.List;
22+
23+
public class LiuBeiASkill extends Item implements Skillable {
24+
private final int EFFECT_DURATION = 10;
25+
private final int EFFECT_AMPLIFIER = 1;
26+
private final int RECOVERHEALTH = 5;
27+
private final int RANGE = 5;
28+
private final int COOLDOWN = 30;
29+
30+
public LiuBeiASkill(Settings settings) {
31+
super(settings);
32+
}
33+
34+
@Override
35+
public void castSkill(MinecraftClient client) {
36+
ClientPlayerEntity user = client.player;
37+
if (user.getItemCooldownManager().isCoolingDown(stack)) {
38+
// 如果物品正在冷却中,返回失败
39+
return ;
40+
}
41+
42+
ServerWorld serverWorld = client.getServer().getWorld(user.getEntityWorld().getRegistryKey());
43+
//回血
44+
float currentHealth = user.getHealth();
45+
float maxHealth = user.getMaxHealth();
46+
if (currentHealth < maxHealth) {
47+
user.setHealth(Math.min(currentHealth + RECOVERHEALTH, maxHealth));
48+
}
49+
RelightTheThreePointStrategy.LOGGER.info("给自己添加生命回复效果");
50+
List<PlayerEntity> nearbyPlayers = getNearbyPlayers(user, serverWorld, RANGE);
51+
for (PlayerEntity nearbyPlayer : nearbyPlayers) {
52+
// if (!nearbyPlayer.equals(user)) {
53+
// 给范围内的其他玩家添加生命回复效果
54+
RelightTheThreePointStrategy.LOGGER.info("给玩家添加生命回复效果");
55+
nearbyPlayer.addStatusEffect(new StatusEffectInstance(StatusEffects.REGENERATION, EFFECT_DURATION*20, EFFECT_AMPLIFIER));
56+
// }
57+
}
58+
59+
}
60+
@Override
61+
public void appendTooltip(ItemStack stack, TooltipContext context, List<Text> tooltip, TooltipType type) {
62+
tooltip.add(Text.translatable("itemskill.relight-the-three-point-strategy.longnudiwei"));
63+
}
64+
public List<PlayerEntity> getNearbyPlayers(PlayerEntity player, ServerWorld world,int range) {
65+
Vec3d pos = player.getPos();
66+
// 创建一个以玩家为中心的检测范围盒子
67+
Box box = new Box(
68+
pos.getX() - range, pos.getY() - range, pos.getZ() - range,
69+
pos.getX() + range, pos.getY() + range, pos.getZ() + range
70+
);
71+
// 获取范围内的所有玩家
72+
List<PlayerEntity> nearbyPlayers = world.getEntitiesByClass(PlayerEntity.class, box, Entity::isAlive);
73+
RelightTheThreePointStrategy.LOGGER.info(nearbyPlayers.toString());
74+
return nearbyPlayers;
75+
}
76+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package xyz.lisbammisakait.skill;
22

33
import net.minecraft.client.MinecraftClient;
4-
//所有技能类请实现此接口
4+
55
public interface Skillable {
6-
public void useSkill(MinecraftClient client);
6+
public void castSkill(MinecraftClient client);
77
}
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
package xyz.lisbammisakait.skill;
22

3-
import net.minecraft.client.MinecraftClient;
43
import net.minecraft.item.Item;
54
import net.minecraft.item.ItemStack;
65
import net.minecraft.item.tooltip.TooltipType;
76
import net.minecraft.text.Text;
87
import net.minecraft.util.Formatting;
9-
import xyz.lisbammisakait.RelightTheThreePointStrategy;
108

119
import java.util.List;
1210

13-
public class TieJiTaChuanSkill extends Item implements Skillable {
11+
public class TieJiTaChuanSkill extends Item {
1412
public TieJiTaChuanSkill(Settings settings) {
1513
super(settings);
1614
}
@@ -20,8 +18,5 @@ public void appendTooltip(ItemStack stack, TooltipContext context, List<Text> to
2018
tooltip.add(Text.translatable("skill.relight-the-three-point-strategy.tiejitachuan").formatted(Formatting.GOLD));
2119
}
2220

23-
@Override
24-
public void useSkill(MinecraftClient client) {
25-
RelightTheThreePointStrategy.LOGGER.info("使用了铁骑踏穿技能");
26-
}
21+
2722
}
Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
package xyz.lisbammisakait.skill;
22

3-
import net.minecraft.client.MinecraftClient;
4-
import net.minecraft.entity.boss.dragon.phase.StrafePlayerPhase;
53
import net.minecraft.item.Item;
64
import net.minecraft.item.ItemStack;
75
import net.minecraft.item.tooltip.TooltipType;
86
import net.minecraft.text.Text;
9-
import xyz.lisbammisakait.RelightTheThreePointStrategy;
107
import xyz.lisbammisakait.item.FeilongduofengItem;
118

129
import java.util.List;
1310

14-
public class YinFengLaiXiangSkill extends Item implements Skillable{
11+
public class YinFengLaiXiangSkill extends Item {
1512
public YinFengLaiXiangSkill(Settings settings) {
1613
super(settings);
1714
}
@@ -21,8 +18,4 @@ public void appendTooltip(ItemStack stack, TooltipContext context, List<Text> to
2118
tooltip.add(Text.translatable("skill.relight-the-three-point-strategy.yinfenglaixiang", FeilongduofengItem.PROBABILITY,FeilongduofengItem.FIRETIME));
2219
}
2320

24-
@Override
25-
public void useSkill(MinecraftClient client) {
26-
RelightTheThreePointStrategy.LOGGER.info("使用了引风来翔技能");
27-
}
2821
}

src/main/resources/assets/relight-the-three-point-strategy/lang/en_us.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@
44
"item.relight-the-three-point-strategy.tiejitachuan":"TieJiTachuan",
55
"item.relight-the-three-point-strategy.yinfenglaixiang": "YinFengLaiXiang",
66
"item.relight-the-three-point-strategy.shenweihutouzhanjinqiang": "ShenWeiHuTouZhanJinQiang",
7+
"item.relight-the-three-point-strategy.longnudiwei": "LongNuDiWei",
78
"key.RelightTheThreePointStrategy.SkillA": "SkillA",
89
"key.RelightTheThreePointStrategy.SkillB": "SkillB",
910
"category.RelightTheThreePointStrategy.SkillGroup": "Skill Group",
1011
"item.relight-the-three-point-strategy.hutouzhanjinqiang.remaining-cooldown-time": "Remaining Cooldown Time: %1$s s",
1112
"skillGroup.RelightTheThreePointStrategy": "Skill",
1213
"rttpsGroup.RelightTheThreePointStrategy": "Weapon",
13-
"key.RelightTheThreePointStrategy.SkillA": "SkillA",
14-
"key.RelightTheThreePointStrategy.SkillB": "SkillB",
15-
"category.RelightTheThreePointStrategy.SkillGroup": "Skill Group",
1614
"skill.relight-the-three-point-strategy.tiejitachuan": "§a[Passive] §fWhen you hold a weapon, you gain a speed - up effect. When you perform a basic attack, you dash 3 blocks towards the target.",
1715
"skill.relight-the-three-point-strategy.yinfenglaixiang": "§a[Passive] §fEach of your basic attacks has a %1$s%% chance to apply a knockback effect and a %2$s - second burn effect.",
18-
"itemskill.relight-the-three-point-strategy.hutouzhanjinqiang": "§6[Active][%1$ss] §fRight - click to strengthen the weapon, increasing its damage and speed - up effect until the next basic attack."
16+
"itemskill.relight-the-three-point-strategy.hutouzhanjinqiang": "§6[Active][%1$ss] §fRight - click to strengthen the weapon, increasing its damage and speed - up effect until the next basic attack.",
17+
"itemskill.relight-the-three-point-strategy.longnudiwei": ""
1918
}

src/main/resources/assets/relight-the-three-point-strategy/lang/zh_cn.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"--------------------------------------------": "--------------------------------",
1919
"item.relight-the-three-point-strategy.tiejitachuan":"铁骑踏川",
2020
"item.relight-the-three-point-strategy.yinfenglaixiang": "引凤来翔",
21+
"item.relight-the-three-point-strategy.longnudiwei": "龙怒帝威",
2122
"---------------------------------------------": "---------------------------------",
2223
"-------------------------------------技能描述": "-----------------------------------",
2324
"----------------------------------------------": "--------------------------------",

0 commit comments

Comments
 (0)