添加子弹命中方块时的音效
This commit is contained in:
parent
d8a28dc884
commit
f205338449
2 changed files with 8 additions and 50 deletions
|
@ -1,8 +1,6 @@
|
||||||
package net.mcreator.superbwarfare.entity;
|
package net.mcreator.superbwarfare.entity;
|
||||||
|
|
||||||
import net.mcreator.superbwarfare.ModUtils;
|
import net.mcreator.superbwarfare.ModUtils;
|
||||||
import net.mcreator.superbwarfare.headshot.BoundingBoxManager;
|
|
||||||
import net.mcreator.superbwarfare.headshot.IHeadshotBox;
|
|
||||||
import net.mcreator.superbwarfare.init.ModDamageTypes;
|
import net.mcreator.superbwarfare.init.ModDamageTypes;
|
||||||
import net.mcreator.superbwarfare.init.ModEntities;
|
import net.mcreator.superbwarfare.init.ModEntities;
|
||||||
import net.mcreator.superbwarfare.init.ModItems;
|
import net.mcreator.superbwarfare.init.ModItems;
|
||||||
|
@ -24,16 +22,12 @@ import net.minecraft.world.entity.projectile.ThrowableItemProjectile;
|
||||||
import net.minecraft.world.item.Item;
|
import net.minecraft.world.item.Item;
|
||||||
import net.minecraft.world.level.Explosion;
|
import net.minecraft.world.level.Explosion;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.phys.AABB;
|
|
||||||
import net.minecraft.world.phys.BlockHitResult;
|
import net.minecraft.world.phys.BlockHitResult;
|
||||||
import net.minecraft.world.phys.EntityHitResult;
|
import net.minecraft.world.phys.EntityHitResult;
|
||||||
import net.minecraft.world.phys.Vec3;
|
|
||||||
import net.minecraftforge.network.NetworkHooks;
|
import net.minecraftforge.network.NetworkHooks;
|
||||||
import net.minecraftforge.network.PacketDistributor;
|
import net.minecraftforge.network.PacketDistributor;
|
||||||
import net.minecraftforge.network.PlayMessages;
|
import net.minecraftforge.network.PlayMessages;
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class GunGrenadeEntity extends ThrowableItemProjectile {
|
public class GunGrenadeEntity extends ThrowableItemProjectile {
|
||||||
|
|
||||||
private int monsterMultiplier = 0;
|
private int monsterMultiplier = 0;
|
||||||
|
@ -88,52 +82,11 @@ public class GunGrenadeEntity extends ThrowableItemProjectile {
|
||||||
entity.invulnerableTime = 0;
|
entity.invulnerableTime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
AABB boundingBox = entity.getBoundingBox();
|
|
||||||
Vec3 startVec = this.position();
|
|
||||||
Vec3 endVec = startVec.add(this.getDeltaMovement());
|
|
||||||
Vec3 hitPos = boundingBox.clip(startVec, endVec).orElse(null);
|
|
||||||
/* Check for headshot */
|
|
||||||
boolean headshot = false;
|
|
||||||
if (entity instanceof LivingEntity) {
|
|
||||||
IHeadshotBox<LivingEntity> headshotBox = (IHeadshotBox<LivingEntity>) BoundingBoxManager.getHeadshotBoxes(entity.getType());
|
|
||||||
if (headshotBox != null) {
|
|
||||||
AABB box = headshotBox.getHeadshotBox((LivingEntity) entity);
|
|
||||||
if (box != null) {
|
|
||||||
box = box.move(boundingBox.getCenter().x, boundingBox.minY, boundingBox.getCenter().z);
|
|
||||||
Optional<Vec3> headshotHitPos = box.clip(startVec, endVec);
|
|
||||||
if (headshotHitPos.isEmpty()) {
|
|
||||||
box = box.inflate(0.2, 0.2, 0.2);
|
|
||||||
headshotHitPos = box.clip(startVec, endVec);
|
|
||||||
}
|
|
||||||
if (headshotHitPos.isPresent() && (hitPos == null || headshotHitPos.get().distanceTo(hitPos) < 0.55)) {
|
|
||||||
headshot = true;
|
|
||||||
}
|
|
||||||
if (headshot) {
|
|
||||||
if (this.getOwner() instanceof LivingEntity living) {
|
|
||||||
if (!living.level().isClientSide() && living instanceof ServerPlayer player) {
|
|
||||||
living.level().playSound(null, living.getX(), living.getY(), living.getZ(), ModSounds.HEADSHOT.get(), SoundSource.VOICE, 1f, 1f);
|
|
||||||
|
|
||||||
ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> player), new ClientIndicatorMessage(1, 5));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (headshot) {
|
|
||||||
if (entity instanceof Monster monster) {
|
|
||||||
monster.hurt(ModDamageTypes.causeGunFireHeadshotDamage(this.level().registryAccess(), this, this.getOwner()), this.damage * 2f * damageMultiplier);
|
|
||||||
} else {
|
|
||||||
entity.hurt(ModDamageTypes.causeGunFireHeadshotDamage(this.level().registryAccess(), this, this.getOwner()), this.damage * 2f);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (entity instanceof Monster monster) {
|
if (entity instanceof Monster monster) {
|
||||||
monster.hurt(ModDamageTypes.causeGunFireHeadshotDamage(this.level().registryAccess(), this, this.getOwner()), this.damage * damageMultiplier);
|
monster.hurt(ModDamageTypes.causeGunFireHeadshotDamage(this.level().registryAccess(), this, this.getOwner()), this.damage * damageMultiplier);
|
||||||
} else {
|
} else {
|
||||||
entity.hurt(ModDamageTypes.causeGunFireHeadshotDamage(this.level().registryAccess(), this, this.getOwner()), this.damage);
|
entity.hurt(ModDamageTypes.causeGunFireHeadshotDamage(this.level().registryAccess(), this, this.getOwner()), this.damage);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (this.tickCount > 0) {
|
if (this.tickCount > 0) {
|
||||||
if (this.level() instanceof ServerLevel) {
|
if (this.level() instanceof ServerLevel) {
|
||||||
|
|
|
@ -24,6 +24,7 @@ import net.minecraft.network.syncher.EntityDataSerializers;
|
||||||
import net.minecraft.network.syncher.SynchedEntityData;
|
import net.minecraft.network.syncher.SynchedEntityData;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.minecraft.sounds.SoundEvent;
|
||||||
import net.minecraft.sounds.SoundSource;
|
import net.minecraft.sounds.SoundSource;
|
||||||
import net.minecraft.util.Mth;
|
import net.minecraft.util.Mth;
|
||||||
import net.minecraft.world.effect.MobEffectInstance;
|
import net.minecraft.world.effect.MobEffectInstance;
|
||||||
|
@ -322,6 +323,10 @@ public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnDa
|
||||||
if (blockHitResult.getType() == HitResult.Type.MISS) {
|
if (blockHitResult.getType() == HitResult.Type.MISS) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
BlockPos resultPos = blockHitResult.getBlockPos();
|
||||||
|
BlockState state = this.level().getBlockState(resultPos);
|
||||||
|
SoundEvent event = state.getBlock().getSoundType(state, this.level(), resultPos, this).getBreakSound();
|
||||||
|
this.level().playSound(null, result.getLocation().x, result.getLocation().y, result.getLocation().z, event, SoundSource.AMBIENT, 1.0F, 1.0F);
|
||||||
Vec3 hitVec = result.getLocation();
|
Vec3 hitVec = result.getLocation();
|
||||||
this.onHitBlock(hitVec);
|
this.onHitBlock(hitVec);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue