添加起爆器音效,允许C4贴在投掷者身上

This commit is contained in:
Atsuihsio 2025-03-21 15:17:43 +08:00
parent a5332a6cac
commit b3fe6f24ad
7 changed files with 34 additions and 9 deletions

View file

@ -279,7 +279,7 @@ public class C4Entity extends Projectile implements GeoEntity {
protected void onHitEntity(EntityHitResult pResult) { protected void onHitEntity(EntityHitResult pResult) {
super.onHitEntity(pResult); super.onHitEntity(pResult);
Entity entity = pResult.getEntity(); Entity entity = pResult.getEntity();
if (entity == this.getOwner() || entity == this.getVehicle()) return; if (entity == this.getVehicle()) return;
this.entityData.set(TARGET_UUID, entity.getStringUUID()); this.entityData.set(TARGET_UUID, entity.getStringUUID());
this.onEntity = true; this.onEntity = true;
this.setDeltaMovement(this.getDeltaMovement().multiply(0, 0, 0)); this.setDeltaMovement(this.getDeltaMovement().multiply(0, 0, 0));

View file

@ -425,5 +425,7 @@ public class ModSounds {
public static final RegistryObject<SoundEvent> TURRET_TURN = REGISTRY.register("turret_turn", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("turret_turn"))); public static final RegistryObject<SoundEvent> TURRET_TURN = REGISTRY.register("turret_turn", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("turret_turn")));
public static final RegistryObject<SoundEvent> C4_BEEP = REGISTRY.register("c4_beep", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("c4_beep"))); public static final RegistryObject<SoundEvent> C4_BEEP = REGISTRY.register("c4_beep", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("c4_beep")));
public static final RegistryObject<SoundEvent> C4_FINAL = REGISTRY.register("c4_final", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("c4_final"))); public static final RegistryObject<SoundEvent> C4_FINAL = REGISTRY.register("c4_final", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("c4_final")));
public static final RegistryObject<SoundEvent> C4_THROW = REGISTRY.register("c4_throw", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("c4_throw")));
public static final RegistryObject<SoundEvent> C4_DETONATOR_CLICK = REGISTRY.register("c4_detonator_click", () -> SoundEvent.createVariableRangeEvent(ModUtils.loc("c4_detonator_click")));
} }

View file

@ -2,8 +2,10 @@ package com.atsuishio.superbwarfare.item;
import com.atsuishio.superbwarfare.client.TooltipTool; import com.atsuishio.superbwarfare.client.TooltipTool;
import com.atsuishio.superbwarfare.entity.C4Entity; import com.atsuishio.superbwarfare.entity.C4Entity;
import com.atsuishio.superbwarfare.tools.EntityFindUtil; import com.atsuishio.superbwarfare.init.ModSounds;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
@ -25,11 +27,6 @@ public class C4Bomb extends Item {
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) { public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) {
ItemStack stack = player.getItemInHand(hand); ItemStack stack = player.getItemInHand(hand);
if (player.serializeNBT().contains("C4UUID") && player.serializeNBT().hasUUID("C4UUID")) {
if (EntityFindUtil.findEntity(player.level(), player.serializeNBT().getUUID("C4UUID").toString()) != null) {
return InteractionResultHolder.pass(stack);
}
}
if (!level.isClientSide) { if (!level.isClientSide) {
C4Entity entity = new C4Entity(player, level); C4Entity entity = new C4Entity(player, level);
entity.setPos(player.getX() + 0.25 * player.getLookAngle().x, player.getEyeY() - 0.2f + 0.25 * player.getLookAngle().y, player.getZ() + 0.25 * player.getLookAngle().z); entity.setPos(player.getX() + 0.25 * player.getLookAngle().x, player.getEyeY() - 0.2f + 0.25 * player.getLookAngle().y, player.getZ() + 0.25 * player.getLookAngle().z);
@ -39,6 +36,10 @@ public class C4Bomb extends Item {
level.addFreshEntity(entity); level.addFreshEntity(entity);
} }
if (player instanceof ServerPlayer serverPlayer) {
serverPlayer.level().playSound(null, serverPlayer.getOnPos(), ModSounds.C4_THROW.get(), SoundSource.PLAYERS, 1, 1);
}
player.getCooldowns().addCooldown(this, 20); player.getCooldowns().addCooldown(this, 20);
if (!player.getAbilities().instabuild) { if (!player.getAbilities().instabuild) {

View file

@ -1,7 +1,10 @@
package com.atsuishio.superbwarfare.item; package com.atsuishio.superbwarfare.item;
import com.atsuishio.superbwarfare.entity.C4Entity; import com.atsuishio.superbwarfare.entity.C4Entity;
import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.tools.EntityFindUtil; import com.atsuishio.superbwarfare.tools.EntityFindUtil;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
@ -28,16 +31,19 @@ public Detonator() {
ItemStack stack = player.getItemInHand(hand); ItemStack stack = player.getItemInHand(hand);
player.getCooldowns().addCooldown(stack.getItem(), 10); player.getCooldowns().addCooldown(stack.getItem(), 10);
if (player instanceof ServerPlayer serverPlayer) {
serverPlayer.level().playSound(null, serverPlayer.getOnPos(), ModSounds.C4_DETONATOR_CLICK.get(), SoundSource.PLAYERS, 1, 1);
}
releaseUsing(stack, player.level(), player, 1); releaseUsing(stack, player.level(), player, 1);
List<Entity> entities = getC4(player, player.level()); List<Entity> entities = getC4(player, player.level());
for (var e : entities) { for (var e : entities) {
if (e instanceof C4Entity c4) { if (e instanceof C4Entity c4) {
c4.explode(); c4.explode();
} }
} }
return super.use(world, player, hand); return InteractionResultHolder.consume(stack);
} }
} }

View file

@ -2931,5 +2931,21 @@
"stream": false "stream": false
} }
] ]
},
"c4_throw": {
"sounds": [
{
"name": "superbwarfare:c4/c4_throw",
"stream": false
}
]
},
"c4_detonator_click": {
"sounds": [
{
"name": "superbwarfare:c4/c4_detonator_click",
"stream": false
}
]
} }
} }