Skip to content

Commit a21fe39

Browse files
committed
初提交
1 parent 00c88a3 commit a21fe39

File tree

9 files changed

+80
-12
lines changed

9 files changed

+80
-12
lines changed

src/main/java/xyz/lisbammisakait/RelightTheThreePointStrategy.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
import net.fabricmc.api.ModInitializer;
44

5+
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
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.ItemStack;
510
import org.slf4j.Logger;
611
import org.slf4j.LoggerFactory;
712
import xyz.lisbammisakait.item.ModItems;
@@ -20,6 +25,19 @@ public void onInitialize() {
2025
// However, some things (like resources) may still be uninitialized.
2126
// Proceed with mild caution.
2227
ModItems.initialize();
28+
29+
// 注册服务器tick事件
30+
ServerTickEvents.END_SERVER_TICK.register(server -> {
31+
for (PlayerEntity player : server.getPlayerManager().getPlayerList()) {
32+
ItemStack mainHandStack = player.getMainHandStack();
33+
ItemStack offHandStack = player.getOffHandStack();
34+
// 如果玩家的主手或副手拿着虎头湛金枪
35+
if (mainHandStack.getItem() == ModItems.HUTOUZHANJINQIANG || offHandStack.getItem() == ModItems.HUTOUZHANJINQIANG) {
36+
// 为玩家添加加速效果
37+
player.addStatusEffect(new StatusEffectInstance(StatusEffects.SPEED, 2, 1));
38+
}
39+
}
40+
});
2341
LOGGER.info("Hello Fabric world!");
2442
}
2543
}

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

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,30 @@
88
import net.minecraft.world.World;
99
import xyz.lisbammisakait.RelightTheThreePointStrategy;
1010

11+
import java.util.Random;
12+
1113
public class FeilongduofengItem extends SwordItem {
1214
public FeilongduofengItem(ToolMaterial material, float attackDamage, float attackSpeed, Settings settings) {
1315
super(material, attackDamage, attackSpeed, settings);
1416
}
1517
@Override
1618
public boolean postHit(net.minecraft.item.ItemStack stack, net.minecraft.entity.LivingEntity target, net.minecraft.entity.LivingEntity attacker) {
17-
target.setFireTicks(100);
18-
double motionX = attacker.getRotationVector().x;
19-
double motionZ = attacker.getRotationVector().z;
20-
21-
// 计算击退强度,这里假设一个简单的强度值
22-
double knockbackStrength = 0.4;
19+
Random random = new Random();
20+
// 生成一个 0 到 9 之间的随机整数
21+
int randomNumber = random.nextInt(10);
22+
// 判断随机数是否为 0
23+
if (randomNumber<10) {
24+
// 给目标添加火焰效果
25+
target.setFireTicks(60);
26+
double motionX = attacker.getRotationVector().x;
27+
double motionZ = attacker.getRotationVector().z;
28+
// 计算击退强度,这里假设一个简单的强度值
29+
double knockbackStrength = 1;
30+
// 给目标添加击退效果
31+
//target.addVelocity(motionX * knockbackStrength, 0.5, motionZ * knockbackStrength);
32+
target.takeKnockback(knockbackStrength, -motionX, -motionZ);
33+
}
2334

24-
// 给目标添加击退效果
25-
target.addVelocity(-motionX * knockbackStrength, 0.2, -motionZ * knockbackStrength);
2635
return super.postHit(stack, target, attacker);
2736
}
2837

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package xyz.lisbammisakait.item;
2+
3+
import net.minecraft.entity.LivingEntity;
4+
import net.minecraft.item.ItemStack;
5+
import net.minecraft.item.SwordItem;
6+
import net.minecraft.item.ToolMaterial;
7+
import net.minecraft.world.World;
8+
import xyz.lisbammisakait.RelightTheThreePointStrategy;
9+
10+
public class HutouzhanjinqiangItem extends SwordItem {
11+
public HutouzhanjinqiangItem(ToolMaterial material, float attackDamage, float attackSpeed, Settings settings) {
12+
super(material, attackDamage, attackSpeed, settings);
13+
14+
}
15+
16+
17+
18+
19+
20+
21+
}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,25 @@ public class ModItems {
2121
// final RegistryKey<Item> registryKey = RegistryKey.of(RegistryKeys.ITEM, Identifier.of(RelightTheThreePointStrategy.MOD_ID, path));
2222
// return Items.register(registryKey, factory, settings);
2323
// }
24-
public static final RegistryKey<Item> FEILONGDUOFENG_KEY = RegistryKey.of(RegistryKeys.ITEM, Identifier.of(RelightTheThreePointStrategy.MOD_ID, "feilongduofeng"));
24+
//注册飞龙夺凤
25+
public static final RegistryKey<Item> FEILONGDUOFENG_KEY = RegistryKey.of(RegistryKeys.ITEM, Identifier.of(RelightTheThreePointStrategy.MOD_ID, "feilongduofeng"));
2526
public static final Item FEILONGDUOFENG = register(new FeilongduofengItem(ToolMaterial.GOLD, 1f, 1f, new Item.Settings().registryKey(FEILONGDUOFENG_KEY)), FEILONGDUOFENG_KEY);
27+
//注册虎头湛金枪
28+
public static final RegistryKey<Item> HUTOUZHANJINQIANG_KEY = RegistryKey.of(RegistryKeys.ITEM, Identifier.of(RelightTheThreePointStrategy.MOD_ID, "hutouzhanjinqiang"));
29+
public static final Item HUTOUZHANJINQIANG = register(new HutouzhanjinqiangItem(ToolMaterial.GOLD, 1f, 1f, new Item.Settings().registryKey(HUTOUZHANJINQIANG_KEY)), HUTOUZHANJINQIANG_KEY);
30+
2631
public static Item register(Item item, RegistryKey<Item> registryKey) {
2732
// Register the item.
2833
Item registeredItem = Registry.register(Registries.ITEM, registryKey.getValue(), item);
29-
3034
// Return the registered item!
3135
return registeredItem;
3236
}
3337

38+
3439
public static void registerToVanillaItemGroups() {
3540
ItemGroupEvents.modifyEntriesEvent(ItemGroups.COMBAT).register(content -> {
3641
content.add(FEILONGDUOFENG);
42+
content.add(HUTOUZHANJINQIANG);
3743
});
3844
}
3945
public static void initialize() {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"model": {
3+
"type": "minecraft:model",
4+
"model": "relight-the-three-point-strategy:item/hutouzhanjinqiang"
5+
}
6+
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"item.relight-the-three-point-strategy.feilongduofeng": "feilongduofeng"
2+
"item.relight-the-three-point-strategy.feilongduofeng": "feilongduofeng",
3+
"item.relight-the-three-point-strategy.hutouzhanjinqiang": "hutouzhanjinqiang"
34
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"item.relight-the-three-point-strategy.feilongduofeng": "飞龙夺凤"
2+
"item.relight-the-three-point-strategy.feilongduofeng": "飞龙夺凤",
3+
"item.relight-the-three-point-strategy.hutouzhanjinqiang": "虎头湛金枪"
34
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"parent": "item/handheld",
3+
"textures": {
4+
"layer0": "relight-the-three-point-strategy:item/hutouzhanjinqiang"
5+
}
6+
}
461 Bytes
Loading

0 commit comments

Comments
 (0)