diff --git a/src/main/java/com/atsuishio/superbwarfare/client/screens/KillMessageOverlay.java b/src/main/java/com/atsuishio/superbwarfare/client/screens/KillMessageOverlay.java index 7b427596d..c0ead8e1c 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/screens/KillMessageOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/screens/KillMessageOverlay.java @@ -276,7 +276,7 @@ public class KillMessageOverlay { icon = BURN; } else if (record.damageType == ModDamageTypes.DRONE_HIT) { icon = DRONE; - } else if (record.damageType == ModDamageTypes.LASER) { + } else if (record.damageType == ModDamageTypes.LASER || record.damageType == ModDamageTypes.LASER_HEADSHOT) { icon = LASER; } else { icon = GENERIC; diff --git a/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java b/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java index a1d7ab0e8..f0855870a 100644 --- a/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java @@ -368,7 +368,7 @@ public class ClientEventHandler { && (!player.isAlliedTo(lookingEntity) || lookingEntity.getTeam() == null || lookingEntity.getTeam().getName().equals("TDM")); if (canAttack) { - ModUtils.PACKET_HANDLER.sendToServer(new LaserShootMessage(1, lookingEntity.getUUID())); + ModUtils.PACKET_HANDLER.sendToServer(new LaserShootMessage(1, lookingEntity.getUUID(), TraceTool.laserHeadshot)); } } } diff --git a/src/main/java/com/atsuishio/superbwarfare/init/ModDamageTypes.java b/src/main/java/com/atsuishio/superbwarfare/init/ModDamageTypes.java index b0fc3fdfd..6c653e65c 100644 --- a/src/main/java/com/atsuishio/superbwarfare/init/ModDamageTypes.java +++ b/src/main/java/com/atsuishio/superbwarfare/init/ModDamageTypes.java @@ -29,6 +29,7 @@ public class ModDamageTypes { public static final ResourceKey CUSTOM_EXPLOSION = ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation(ModUtils.MODID, "custom_explosion")); public static final ResourceKey DRONE_HIT = ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation(ModUtils.MODID, "drone_hit")); public static final ResourceKey LASER = ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation(ModUtils.MODID, "laser")); + public static final ResourceKey LASER_HEADSHOT = ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation(ModUtils.MODID, "laser_headshot")); public static DamageSource causeGunFireDamage(RegistryAccess registryAccess, @Nullable Entity directEntity, @Nullable Entity attacker) { return new DamageMessages(registryAccess.registry(Registries.DAMAGE_TYPE).get().getHolderOrThrow(GUN_FIRE), directEntity, attacker); @@ -78,6 +79,10 @@ public class ModDamageTypes { return new DamageMessages(registryAccess.registry(Registries.DAMAGE_TYPE).get().getHolderOrThrow(LASER), directEntity, attacker); } + public static DamageSource causeLaserHeadshotDamage(RegistryAccess registryAccess, @Nullable Entity directEntity, @Nullable Entity attacker) { + return new DamageMessages(registryAccess.registry(Registries.DAMAGE_TYPE).get().getHolderOrThrow(LASER_HEADSHOT), directEntity, attacker); + } + private static class DamageMessages extends DamageSource { public DamageMessages(Holder.Reference typeReference) { super(typeReference); diff --git a/src/main/java/com/atsuishio/superbwarfare/item/BeamTest.java b/src/main/java/com/atsuishio/superbwarfare/item/BeamTest.java index 75bb9e4c3..4cb761f53 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/BeamTest.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/BeamTest.java @@ -118,7 +118,7 @@ public class BeamTest extends Item { && (!player.isAlliedTo(lookingEntity) || lookingEntity.getTeam() == null || lookingEntity.getTeam().getName().equals("TDM")); if (canAttack) { - ModUtils.PACKET_HANDLER.sendToServer(new LaserShootMessage(45, lookingEntity.getUUID())); + ModUtils.PACKET_HANDLER.sendToServer(new LaserShootMessage(45 , lookingEntity.getUUID(), TraceTool.laserHeadshot)); } } diff --git a/src/main/java/com/atsuishio/superbwarfare/mixins/LivingEntityMixin.java b/src/main/java/com/atsuishio/superbwarfare/mixins/LivingEntityMixin.java index 7f83fa753..845e27a4b 100644 --- a/src/main/java/com/atsuishio/superbwarfare/mixins/LivingEntityMixin.java +++ b/src/main/java/com/atsuishio/superbwarfare/mixins/LivingEntityMixin.java @@ -28,7 +28,7 @@ public class LivingEntityMixin { || this.target$source.is(ModDamageTypes.GUN_FIRE_HEADSHOT_ABSOLUTE) || this.target$source.is(ModDamageTypes.BURN)) { return 0.05 * original; } - if (this.target$source.is(ModDamageTypes.LASER)) { + if (this.target$source.is(ModDamageTypes.LASER) || this.target$source.is(ModDamageTypes.LASER_HEADSHOT)) { return -original; } return original; diff --git a/src/main/java/com/atsuishio/superbwarfare/network/message/LaserShootMessage.java b/src/main/java/com/atsuishio/superbwarfare/network/message/LaserShootMessage.java index 80163bd17..7d859df1c 100644 --- a/src/main/java/com/atsuishio/superbwarfare/network/message/LaserShootMessage.java +++ b/src/main/java/com/atsuishio/superbwarfare/network/message/LaserShootMessage.java @@ -8,7 +8,6 @@ import net.minecraft.network.FriendlyByteBuf; import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundSource; import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.Level; import net.minecraftforge.network.NetworkEvent; import net.minecraftforge.network.PacketDistributor; @@ -18,34 +17,36 @@ import java.util.function.Supplier; public class LaserShootMessage { private final double damage; - private final UUID uuid; + private final boolean headshot; - public LaserShootMessage(double damage, UUID uuid) { + public LaserShootMessage(double damage, UUID uuid, boolean headshot) { this.damage = damage; this.uuid = uuid; + this.headshot = headshot; } public static LaserShootMessage decode(FriendlyByteBuf buffer) { - return new LaserShootMessage(buffer.readDouble(), buffer.readUUID()); + return new LaserShootMessage(buffer.readDouble(), buffer.readUUID(), buffer.readBoolean()); } public static void encode(LaserShootMessage message, FriendlyByteBuf buffer) { buffer.writeDouble(message.damage); buffer.writeUUID(message.uuid); + buffer.writeBoolean(message.headshot); } public static void handler(LaserShootMessage message, Supplier contextSupplier) { NetworkEvent.Context context = contextSupplier.get(); context.enqueueWork(() -> { if (context.getSender() != null) { - pressAction(context.getSender(), message.damage, message.uuid); + pressAction(context.getSender(), message.damage, message.uuid, message.headshot); } }); context.setPacketHandled(true); } - public static void pressAction(Player player, double damage, UUID uuid) { + public static void pressAction(ServerPlayer player, double damage, UUID uuid, boolean headshot) { Level level = player.level(); if (!level.isLoaded(player.blockPosition())) { @@ -55,12 +56,16 @@ public class LaserShootMessage { Entity entity = EntityFindUtil.findEntity(level, String.valueOf(uuid)); if (entity != null) { - entity.hurt(ModDamageTypes.causeLaserDamage(level.registryAccess(), player, player), (float) damage); - entity.invulnerableTime = 0; - if (player instanceof ServerPlayer serverPlayer) { + if (headshot) { + entity.hurt(ModDamageTypes.causeLaserHeadshotDamage(level.registryAccess(), player, player), (float) (2 * damage)); + player.level().playSound(null, player.blockPosition(), ModSounds.HEADSHOT.get(), SoundSource.VOICE, 0.1f, 1); + ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> player), new ClientIndicatorMessage(1, 5)); + } else { + entity.hurt(ModDamageTypes.causeLaserDamage(level.registryAccess(), player, player), (float) damage); player.level().playSound(null, player.blockPosition(), ModSounds.INDICATION.get(), SoundSource.VOICE, 0.1f, 1); - ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> serverPlayer), new ClientIndicatorMessage(0, 5)); + ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> player), new ClientIndicatorMessage(0, 5)); } + entity.invulnerableTime = 0; } } } diff --git a/src/main/java/com/atsuishio/superbwarfare/tools/DamageTypeTool.java b/src/main/java/com/atsuishio/superbwarfare/tools/DamageTypeTool.java index 0c8e41f9a..a99535d2f 100644 --- a/src/main/java/com/atsuishio/superbwarfare/tools/DamageTypeTool.java +++ b/src/main/java/com/atsuishio/superbwarfare/tools/DamageTypeTool.java @@ -10,7 +10,8 @@ public class DamageTypeTool { public static boolean isGunDamage(DamageSource source) { return source.is(ModDamageTypes.GUN_FIRE) || source.is(ModDamageTypes.GUN_FIRE_HEADSHOT) || source.is(ModDamageTypes.GUN_FIRE_ABSOLUTE) || source.is(ModDamageTypes.GUN_FIRE_HEADSHOT_ABSOLUTE) - || source.is(ModDamageTypes.SHOCK)|| source.is(ModDamageTypes.BURN); + || source.is(ModDamageTypes.SHOCK) || source.is(ModDamageTypes.BURN) + || source.is(ModDamageTypes.LASER) || source.is(ModDamageTypes.LASER_HEADSHOT); } public static boolean isGunDamage(ResourceKey damageType) { @@ -23,14 +24,18 @@ public class DamageTypeTool { } public static boolean isGunFireDamage(DamageSource source) { - return source.is(ModDamageTypes.GUN_FIRE) || source.is(ModDamageTypes.GUN_FIRE_ABSOLUTE); + return source.is(ModDamageTypes.GUN_FIRE) || source.is(ModDamageTypes.GUN_FIRE_ABSOLUTE) + || source.is(ModDamageTypes.SHOCK) || source.is(ModDamageTypes.BURN) + || source.is(ModDamageTypes.LASER) || source.is(ModDamageTypes.LASER_HEADSHOT); } public static boolean isModDamage(DamageSource source) { return source.is(ModDamageTypes.GUN_FIRE_ABSOLUTE) || source.is(ModDamageTypes.GUN_FIRE_HEADSHOT_ABSOLUTE) || source.is(ModDamageTypes.GUN_FIRE) || source.is(ModDamageTypes.GUN_FIRE_HEADSHOT) || source.is(ModDamageTypes.MINE) || source.is(ModDamageTypes.SHOCK) - || source.is(ModDamageTypes.PROJECTILE_BOOM) || source.is(ModDamageTypes.CANNON_FIRE); + || source.is(ModDamageTypes.PROJECTILE_BOOM) || source.is(ModDamageTypes.CANNON_FIRE) + || source.is(ModDamageTypes.BURN) + || source.is(ModDamageTypes.LASER) || source.is(ModDamageTypes.LASER_HEADSHOT); } } diff --git a/src/main/java/com/atsuishio/superbwarfare/tools/TraceTool.java b/src/main/java/com/atsuishio/superbwarfare/tools/TraceTool.java index ac81ea61a..1b817022f 100644 --- a/src/main/java/com/atsuishio/superbwarfare/tools/TraceTool.java +++ b/src/main/java/com/atsuishio/superbwarfare/tools/TraceTool.java @@ -3,6 +3,7 @@ package com.atsuishio.superbwarfare.tools; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.projectile.ProjectileUtil; import net.minecraft.world.level.ClipContext; import net.minecraft.world.level.block.state.BlockState; @@ -10,6 +11,8 @@ import net.minecraft.world.phys.*; public class TraceTool { + public static boolean laserHeadshot = false; + public static Entity findLookingEntity(Entity player, double entityReach) { double distance = entityReach * entityReach; Vec3 eyePos = player.getEyePosition(1.0f); @@ -74,12 +77,17 @@ public class TraceTool { } else if (distanceToTarget < distance) { hitResult = entityhitresult; } - } - if (hitResult.getType() == HitResult.Type.ENTITY) { - if (((EntityHitResult) hitResult).getEntity().isAlive()) { + Vec3 hitVec = entityhitresult.getLocation(); + if (hitResult.getType() == HitResult.Type.ENTITY && ((EntityHitResult) hitResult).getEntity().isAlive()) { + if (((EntityHitResult) hitResult).getEntity() instanceof LivingEntity living) { + laserHeadshot = living.getEyeY() - 0.4 < hitVec.y && hitVec.y < living.getEyeY() + 0.5; + } else { + laserHeadshot = false; + } return ((EntityHitResult) hitResult).getEntity(); } } + return null; } diff --git a/src/main/resources/assets/superbwarfare/lang/en_us.json b/src/main/resources/assets/superbwarfare/lang/en_us.json index 66d378475..ce6bb01d1 100644 --- a/src/main/resources/assets/superbwarfare/lang/en_us.json +++ b/src/main/resources/assets/superbwarfare/lang/en_us.json @@ -329,6 +329,9 @@ "death.attack.laser": "%1$s被激光射穿了", "death.attack.laser.entity": "%1$s被%2$s用激光射穿了", "death.attack.laser.item": "%1$s被%2$s用%3$s激光射穿了", + "death.attack.laser_headshot": "%1$s的脑子被激光洞穿了", + "death.attack.laser_headshot.entity": "%1$s被%2$s用激光射穿了脑袋", + "death.attack.laser_headshot.item": "%1$s的脑子被%2$s用%3$s发射的激光洞穿了", "gui.superbwarfare.mortar_gui.button_set": "Confirm", diff --git a/src/main/resources/assets/superbwarfare/lang/zh_cn.json b/src/main/resources/assets/superbwarfare/lang/zh_cn.json index 82331b094..ae734ab02 100644 --- a/src/main/resources/assets/superbwarfare/lang/zh_cn.json +++ b/src/main/resources/assets/superbwarfare/lang/zh_cn.json @@ -329,6 +329,9 @@ "death.attack.laser": "%1$s被激光射穿了", "death.attack.laser.entity": "%1$s被%2$s用激光射穿了", "death.attack.laser.item": "%1$s被%2$s用%3$s激光射穿了", + "death.attack.laser_headshot": "%1$s的脑子被激光洞穿了", + "death.attack.laser_headshot.entity": "%1$s被%2$s用激光射穿了脑袋", + "death.attack.laser_headshot.item": "%1$s的脑子被%2$s用%3$s发射的激光洞穿了", "gui.superbwarfare.mortar_gui.button_set": "确认", diff --git a/src/main/resources/assets/superbwarfare/textures/screens/damage_types/175009bmw9wyyk1k99tk9m.png b/src/main/resources/assets/superbwarfare/textures/screens/damage_types/175009bmw9wyyk1k99tk9m.png deleted file mode 100644 index e35ce7ea4..000000000 Binary files a/src/main/resources/assets/superbwarfare/textures/screens/damage_types/175009bmw9wyyk1k99tk9m.png and /dev/null differ diff --git a/src/main/resources/assets/superbwarfare/textures/screens/damage_types/laser.png b/src/main/resources/assets/superbwarfare/textures/screens/damage_types/laser.png index 366bf1f27..e35ce7ea4 100644 Binary files a/src/main/resources/assets/superbwarfare/textures/screens/damage_types/laser.png and b/src/main/resources/assets/superbwarfare/textures/screens/damage_types/laser.png differ diff --git a/src/main/resources/data/minecraft/tags/damage_type/always_hurts_ender_dragons.json b/src/main/resources/data/minecraft/tags/damage_type/always_hurts_ender_dragons.json index c2900aaa3..7d451fda9 100644 --- a/src/main/resources/data/minecraft/tags/damage_type/always_hurts_ender_dragons.json +++ b/src/main/resources/data/minecraft/tags/damage_type/always_hurts_ender_dragons.json @@ -5,5 +5,6 @@ "superbwarfare:custom_explosion", "superbwarfare:cannon_fire", "superbwarfare:laser" + "superbwarfare:laser_headshot" ] } \ No newline at end of file diff --git a/src/main/resources/data/minecraft/tags/damage_type/bypasses_armor.json b/src/main/resources/data/minecraft/tags/damage_type/bypasses_armor.json index b48123bc5..5f9f89b25 100644 --- a/src/main/resources/data/minecraft/tags/damage_type/bypasses_armor.json +++ b/src/main/resources/data/minecraft/tags/damage_type/bypasses_armor.json @@ -6,5 +6,6 @@ "superbwarfare:shock", "superbwarfare:cannon_fire", "superbwarfare:laser" + "superbwarfare:laser_headshot" ] } \ No newline at end of file diff --git a/src/main/resources/data/minecraft/tags/damage_type/bypasses_effects.json b/src/main/resources/data/minecraft/tags/damage_type/bypasses_effects.json index b48123bc5..5f9f89b25 100644 --- a/src/main/resources/data/minecraft/tags/damage_type/bypasses_effects.json +++ b/src/main/resources/data/minecraft/tags/damage_type/bypasses_effects.json @@ -6,5 +6,6 @@ "superbwarfare:shock", "superbwarfare:cannon_fire", "superbwarfare:laser" + "superbwarfare:laser_headshot" ] } \ No newline at end of file diff --git a/src/main/resources/data/minecraft/tags/damage_type/bypasses_enchantments.json b/src/main/resources/data/minecraft/tags/damage_type/bypasses_enchantments.json index b48123bc5..5f9f89b25 100644 --- a/src/main/resources/data/minecraft/tags/damage_type/bypasses_enchantments.json +++ b/src/main/resources/data/minecraft/tags/damage_type/bypasses_enchantments.json @@ -6,5 +6,6 @@ "superbwarfare:shock", "superbwarfare:cannon_fire", "superbwarfare:laser" + "superbwarfare:laser_headshot" ] } \ No newline at end of file diff --git a/src/main/resources/data/minecraft/tags/damage_type/bypasses_resistance.json b/src/main/resources/data/minecraft/tags/damage_type/bypasses_resistance.json index b48123bc5..5f9f89b25 100644 --- a/src/main/resources/data/minecraft/tags/damage_type/bypasses_resistance.json +++ b/src/main/resources/data/minecraft/tags/damage_type/bypasses_resistance.json @@ -6,5 +6,6 @@ "superbwarfare:shock", "superbwarfare:cannon_fire", "superbwarfare:laser" + "superbwarfare:laser_headshot" ] } \ No newline at end of file diff --git a/src/main/resources/data/minecraft/tags/damage_type/no_knockback.json b/src/main/resources/data/minecraft/tags/damage_type/no_knockback.json index 2ea504609..2eab58b25 100644 --- a/src/main/resources/data/minecraft/tags/damage_type/no_knockback.json +++ b/src/main/resources/data/minecraft/tags/damage_type/no_knockback.json @@ -4,5 +4,6 @@ "superbwarfare:projectile_boom", "superbwarfare:custom_explosion", "superbwarfare:laser" + "superbwarfare:laser_headshot" ] } \ No newline at end of file diff --git a/src/main/resources/data/superbwarfare/damage_type/laser_headshot.json b/src/main/resources/data/superbwarfare/damage_type/laser_headshot.json new file mode 100644 index 000000000..e833c0419 --- /dev/null +++ b/src/main/resources/data/superbwarfare/damage_type/laser_headshot.json @@ -0,0 +1,5 @@ +{ + "exhaustion": 0, + "message_id": "laser_headshot", + "scaling": "never" +} \ No newline at end of file diff --git a/src/main/resources/data/superbwarfare/guns/javelin.json b/src/main/resources/data/superbwarfare/guns/javelin.json index 3b453fbc1..cbe9f8662 100644 --- a/src/main/resources/data/superbwarfare/guns/javelin.json +++ b/src/main/resources/data/superbwarfare/guns/javelin.json @@ -5,7 +5,7 @@ "mag": 1, "weight": 10, "EmptyReloadTime": 78, - "damage": 500, - "ExplosionDamage": 140, + "damage": 300, + "ExplosionDamage": 100, "ExplosionRadius": 6 } \ No newline at end of file diff --git a/src/main/resources/data/superbwarfare/guns/rpg.json b/src/main/resources/data/superbwarfare/guns/rpg.json index 9c6e75957..216c97499 100644 --- a/src/main/resources/data/superbwarfare/guns/rpg.json +++ b/src/main/resources/data/superbwarfare/guns/rpg.json @@ -2,8 +2,8 @@ "spread": 5, "recoil_x": 0.008, "recoil_y": 0.018, - "damage": 400, - "ExplosionDamage": 200, + "damage": 200, + "ExplosionDamage": 150, "ExplosionRadius": 10, "velocity": 4, "mag": 1,