From f205338449f677800034b24454aa329a82561fed Mon Sep 17 00:00:00 2001 From: Atsuihsio <842960157@qq.com> Date: Mon, 5 Aug 2024 21:02:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AD=90=E5=BC=B9=E5=91=BD?= =?UTF-8?q?=E4=B8=AD=E6=96=B9=E5=9D=97=E6=97=B6=E7=9A=84=E9=9F=B3=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/GunGrenadeEntity.java | 53 ++----------------- .../entity/ProjectileEntity.java | 5 ++ 2 files changed, 8 insertions(+), 50 deletions(-) diff --git a/src/main/java/net/mcreator/superbwarfare/entity/GunGrenadeEntity.java b/src/main/java/net/mcreator/superbwarfare/entity/GunGrenadeEntity.java index c891fc743..fd67a554e 100644 --- a/src/main/java/net/mcreator/superbwarfare/entity/GunGrenadeEntity.java +++ b/src/main/java/net/mcreator/superbwarfare/entity/GunGrenadeEntity.java @@ -1,8 +1,6 @@ package net.mcreator.superbwarfare.entity; 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.ModEntities; 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.level.Explosion; import net.minecraft.world.level.Level; -import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.EntityHitResult; -import net.minecraft.world.phys.Vec3; import net.minecraftforge.network.NetworkHooks; import net.minecraftforge.network.PacketDistributor; import net.minecraftforge.network.PlayMessages; -import java.util.Optional; - public class GunGrenadeEntity extends ThrowableItemProjectile { private int monsterMultiplier = 0; @@ -88,51 +82,10 @@ public class GunGrenadeEntity extends ThrowableItemProjectile { 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 headshotBox = (IHeadshotBox) 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 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); - } + if (entity instanceof Monster monster) { + monster.hurt(ModDamageTypes.causeGunFireHeadshotDamage(this.level().registryAccess(), this, this.getOwner()), this.damage * damageMultiplier); } else { - if (entity instanceof Monster monster) { - monster.hurt(ModDamageTypes.causeGunFireHeadshotDamage(this.level().registryAccess(), this, this.getOwner()), this.damage * damageMultiplier); - } 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) { diff --git a/src/main/java/net/mcreator/superbwarfare/entity/ProjectileEntity.java b/src/main/java/net/mcreator/superbwarfare/entity/ProjectileEntity.java index d1007e8c3..467b2e064 100644 --- a/src/main/java/net/mcreator/superbwarfare/entity/ProjectileEntity.java +++ b/src/main/java/net/mcreator/superbwarfare/entity/ProjectileEntity.java @@ -24,6 +24,7 @@ import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundSource; import net.minecraft.util.Mth; import net.minecraft.world.effect.MobEffectInstance; @@ -322,6 +323,10 @@ public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnDa if (blockHitResult.getType() == HitResult.Type.MISS) { 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(); this.onHitBlock(hitVec); }