警棍、大锤、子弹添加命中音效

This commit is contained in:
Atsuishio 2025-05-22 19:44:22 +08:00 committed by Light_Quanta
parent 7726b67db1
commit 6d8f59659f
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
4 changed files with 44 additions and 4 deletions

View file

@ -482,6 +482,10 @@ public class ProjectileEntity extends Projectile implements IEntityWithComplexSp
entity = part.getParent();
}
if (entity instanceof LivingEntity living) {
living.level().playSound(null, living.getOnPos(), ModSounds.MELEE_HIT.get(), SoundSource.PLAYERS, 1, (float) ((2 * org.joml.Math.random() - 1) * 0.1f + 1.0f));
}
if (beast && entity instanceof LivingEntity living) {
Beast.beastKill(this.shooter, living);
return;

View file

@ -147,10 +147,7 @@ public class ModItems {
.durability(1200)
));
public static final DeferredHolder<Item, Hammer> HAMMER = ITEMS.register("hammer", Hammer::new);
public static final DeferredHolder<Item, SwordItem> T_BATON = ITEMS.register("t_baton", () -> new SwordItem(ModItemTier.STEEL, new Item.Properties()
.attributes(SwordItem.createAttributes(ModItemTier.STEEL, 3, -2))
.durability(1115)
));
public static final DeferredHolder<Item, TBaton> T_BATON = ITEMS.register("t_baton", TBaton::new);
public static final DeferredHolder<Item, ElectricBaton> ELECTRIC_BATON = ITEMS.register("electric_baton", ElectricBaton::new);
public static final DeferredHolder<Item, Crowbar> CROWBAR = ITEMS.register("crowbar", Crowbar::new);
public static final DeferredHolder<Item, Defuser> DEFUSER = ITEMS.register("defuser", Defuser::new);

View file

@ -1,6 +1,9 @@
package com.atsuishio.superbwarfare.item;
import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModSounds;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.SwordItem;
@ -10,6 +13,8 @@ import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.event.entity.player.PlayerEvent;
import org.jetbrains.annotations.NotNull;
import javax.annotation.ParametersAreNonnullByDefault;
@EventBusSubscriber(bus = EventBusSubscriber.Bus.GAME)
public class Hammer extends SwordItem {
@ -40,6 +45,13 @@ public class Hammer extends SwordItem {
return true;
}
@Override
@ParametersAreNonnullByDefault
public boolean hurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker) {
attacker.level().playSound(null, target.getOnPos(), ModSounds.MELEE_HIT.get(), SoundSource.PLAYERS, 1, (float) ((2 * org.joml.Math.random() - 1) * 0.1f + 1.0f));
return super.hurtEnemy(stack, target, attacker);
}
@SubscribeEvent
public static void onItemCrafted(PlayerEvent.ItemCraftedEvent event) {
var item = event.getCrafting();

View file

@ -0,0 +1,27 @@
package com.atsuishio.superbwarfare.item;
import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.tiers.ModItemTier;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.SwordItem;
import javax.annotation.ParametersAreNonnullByDefault;
public class TBaton extends SwordItem {
public TBaton() {
super(ModItemTier.STEEL, new Properties()
.durability(1115)
.attributes(SwordItem.createAttributes(ModItemTier.STEEL, 3, -2))
);
}
@Override
@ParametersAreNonnullByDefault
public boolean hurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker) {
attacker.level().playSound(null, target.getOnPos(), ModSounds.MELEE_HIT.get(), SoundSource.PLAYERS, 1, (float) ((2 * org.joml.Math.random() - 1) * 0.1f + 1));
return super.hurtEnemy(stack, target, attacker);
}
}